Slide 1

Slide 1 text

Realm meetup ্ా [email protected]

Slide 2

Slide 2 text

#realm_jp [email protected]

Slide 3

Slide 3 text

Makoto Yamazaki Realm Inc. / uPhyca Inc. [email protected]

Slide 4

Slide 4 text

What is Realm? [email protected]

Slide 5

Slide 5 text

ٌغ؎ٕرغ؎أ㼔欽ח倜׃ֻ⡲׵׸׋ر٦ةك٦أ  0CKFDUJWF$䎃剢։  +BWB䎃剢։  4XJGU䎃剢։ ٌغ؎ٕ欽鷿ח剑黝⻉ׁ׸גְ׷  鹼䒀ٗ٦س  ئٗ؝ؾ٦  ط؎ذ؍ـ٥ؙٔٝ Realm [email protected]

Slide 6

Slide 6 text

Realm ˖ ؙٗأفٓحزؿؓ٦ي ˖ J04"OESPJE ˖ +BWB 4XJGU 0CKFDUJWF$ $ +BWB4DSJQU ˖ ؔ٦فٝا٦أ ˖ 杝荈%#ؒٝآٝ42-JUF׾⢪׏גְזְ [email protected]

Slide 7

Slide 7 text

Realmͷಛ௕ 넝鸞ז⹛⡲ 农〾⻉׾垥彊鄲⪒ 湫䠬涸דءٝفٕז"1* ♨㻝ז؟ه٦ز傈劤铂0, [email protected]

Slide 8

Slide 8 text

public class Article extends RealmObject { @PrimaryKey private int id; @Required private String title; private String contents; private Date creationDate; private Date modificationDate; private User user; private RealmList comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ [email protected]

Slide 9

Slide 9 text

class Article: Object { dynamic var id: Int = 0 dynamic var title: String = "" dynamic var contents: String = "" dynamic var creationDate: NSDate = NSDate() dynamic var modificationDate: NSDate = NSDate() dynamic var user: User? = nil let comments = List() } Ϟσϧʢςʔϒϧʣఆٛ (iOS) [email protected]

Slide 10

Slide 10 text

public class Article extends RealmObject { @PrimaryKey private int id; @Required private String title; private String contents; private Date creationDate; private Date modificationDate; private User user; private RealmList comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ RealmObjectΫϥεΛܧঝ [email protected]

Slide 11

Slide 11 text

public class Article extends RealmObject { @PrimaryKey private int id; @Required private String title; private String contents; private Date creationDate; private Date modificationDate; private User user; private RealmList comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ ΧϥϜͱσʔλܕ [email protected]

Slide 12

Slide 12 text

public class Article extends RealmObject { @PrimaryKey private int id; @Required private String title; private String contents; private Date creationDate; private Date modificationDate; private User user; private RealmList comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ nullͷՄʗෆՄ [email protected]

Slide 13

Slide 13 text

public class Article extends RealmObject { @PrimaryKey private int id; @Required private String title; private String contents; private Date creationDate; private Date modificationDate; private User user; private RealmList comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ ̍ର̍ͷؔ࿈ [email protected]

Slide 14

Slide 14 text

public class Article extends RealmObject { @PrimaryKey private int id; @Required private String title; private String contents; private Date creationDate; private Date modificationDate; private User user; private RealmList comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ ̍ରଟͷؔ࿈ [email protected]

Slide 15

Slide 15 text

public final class RealmList extends java.util.AbstractList implements io.realm.OrderedRealmCollection { ....
 } Ϟσϧʢςʔϒϧʣఆٛ RealmListΫϥε [email protected]

Slide 16

Slide 16 text

byte/Byte short/Short int/Integer long/Long boolean/Boolean float/Float double/Double String Date byte[] モデルクラス RealmList<モデルクラス> Ϟσϧʢςʔϒϧʣఆٛ ΧϥϜʹ࢖༻Ͱ͖Δܕ [email protected]

Slide 17

Slide 17 text

Article article = new Article(); article.setId(1);
 article.setTitle("Realm meetup");
 
 Realm realm = Realm.getDefaultInstance();
 try {
 realm.executeTransaction(realm -> { realm.insert(article);
 });
 } finally {
 realm.close();
 } σʔλͷอଘ [email protected]

Slide 18

Slide 18 text

Article article = new Article(); article.setId(1);
 article.setTitle("Realm meetup");
 
 Realm realm = Realm.getDefaultInstance();
 try {
 realm.executeTransaction(realm -> { realm.insert(person);
 });
 } finally {
 realm.close();
 } σʔλͷอଘ ϞσϧΦϒδΣΫτͷ࡞੒ [email protected]

Slide 19

Slide 19 text

Article article = new Article(); article.setId(1);
 article.setTitle("Realm meetup");
 
 Realm realm = Realm.getDefaultInstance();
 try {
 realm.executeTransaction(realm -> { realm.insert(person);
 });
 } finally {
 realm.close();
 } σʔλͷอଘ RealmΠϯελϯεͷऔಘ [email protected]

Slide 20

Slide 20 text

Article article = new Article(); article.setId(1);
 article.setTitle("Realm meetup");
 
 Realm realm = Realm.getDefaultInstance();
 try {
 realm.executeTransaction(realm -> { realm.insert(person);
 });
 } finally {
 realm.close();
 } σʔλͷอଘ ςʔϒϧ΁ૠೖ [email protected]

Slide 21

Slide 21 text

Realm realm = Realm.getDefaultInstance();
 try { RealmResults articles = realm.where(Article.class) .beginsWith("title", "Realm") .findAllSorted("creationDate", Sort.DESCENDING); } finally {
 realm.close();
 } ΫΤϦ [email protected]

Slide 22

Slide 22 text

Realm realm = Realm.getDefaultInstance();
 try { RealmResults articles = realm.where(Article.class) .beginsWith("title", "Realm") .findAllSorted("creationDate", Sort.DESCENDING); } finally {
 realm.close();
 } ΫΤϦ RealmΠϯελϯεͷऔಘ [email protected]

Slide 23

Slide 23 text

Realm realm = Realm.getDefaultInstance();
 try { RealmResults articles = realm.where(Article.class) .beginsWith("title", "Realm") .findAllSorted("creationDate", Sort.DESCENDING); } finally {
 realm.close();
 } ΫΤϦ ৚݅ͷࢦఆͱ݁Ռͷऔಘ [email protected]

Slide 24

Slide 24 text

Realm realm = Realm.getDefaultInstance();
 try { RealmResults articles = realm.where(Article.class) .equalTo("user.name", "Tim") .lessThan("user.age", 30) .findAllSorted("creationDate", Sort.DESCENDING); } finally {
 realm.close();
 } ϦϯΫΫΤϦ [email protected]

Slide 25

Slide 25 text

Realm realm = Realm.getDefaultInstance();
 try { RealmResults articles = realm.where(Article.class) .contains("comments.message", "Ueda") .contains("comments.message", "meetup") .findAllSorted("creationDate", Sort.DESCENDING); } finally {
 realm.close();
 } ϦϯΫΫΤϦ ஫ҙʂ [email protected]

Slide 26

Slide 26 text

realm.where(Foo.class).equalTo(FooFields.AGE, 20); realm.where(Foo.class).equalTo("age", 20) http://bit.ly/RealmField realm.where(Foo::class.java).equalTo(Foo::age.name, 20); Kotlinͷਓ͸ݩʑҎԼͷΑ͏ʹॻ͚ΔͷͰෆཁͰ͢ Realm Field Names Helper [email protected]

Slide 27

Slide 27 text

ΫΤϦϝιου isNull/isNotNull isEmpty/isNotEmpty equalTo/notEqualTo greaterThan greaterThanOrEqualTo lessThan lessThanOrEqualTo between contains beginsWith endsWith in and or not beginGroup endGroup [email protected]

Slide 28

Slide 28 text

ूܭϝιου sum average min max maximumDate minimumDate count [email protected]

Slide 29

Slide 29 text

Realm realm = Realm.getDefaultInstance();
 try {
 RealmResults articles = ...; Article article = articles.first(); article.isManaged(); // true Log.d("realm", article.getTitle()); Log.d("realm", article.getUser().getName()); Log.d("realm", article.getComments().get(0).getMessage()); } finally {
 realm.close();
 } σʔλͷಡΈग़͠ [email protected]

Slide 30

Slide 30 text

RealmResults articles = ...; articles.addChangeListener(results -> { // ArticleΫϥεʹ͍ͭͯมߋɾ௥Ճɾ࡟আͷࡍʹݺ͹ΕΔ }); Article article = articles.first(); article.addChangeListener(obj -> { // ArticleΫϥεʹ͍ͭͯมߋɾ௥Ճɾ࡟আͷࡍʹݺ͹ΕΔ }); มߋ௨஌ [email protected]

Slide 31

Slide 31 text

࣮ࡍͷ࢖͍ํ [email protected]

Slide 32

Slide 32 text

࣮ࡍͷ࢖͍ํ Activityฤ public class ArticleActivity extends AppCompatActivity {
 private Realm realm;
 private Article article;
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_article);
 int id = getIntent().getIntExtra("id", 0);
 realm = Realm.getDefaultInstance(); article = realm.where(Article.class).equalTo("id", id);
 } @Override
 public void onDestroy() {
 super.onDestroy(); realm.close(); } } [email protected]

Slide 33

Slide 33 text

࣮ࡍͷ࢖͍ํ Fragmentฤ public class ArticleFragment extends Fragment {
 private Realm realm;
 private Article article;
 @Override
 public View onCreateView(...) { super.onCreateView(...); realm = Realm.getDefaultInstance(); int id = getIntent().getIntExtra("id", 0);
 article = realm.where(Article.class).equalTo("id", id); // Viewの作成
 } @Override
 public void onDestroyView() {
 super.onDestroyView(); realm.close(); } } [email protected]

Slide 34

Slide 34 text

࣮ࡍͷ࢖͍ํ ඇLooperεϨουฤ public class MyThread extends Thread {
 @Override
 public void run() { while(true) { // なんらかの処理 //結果を保存 Realm realm = Realm.getDefaultInstance(); try {
 realm.executeTransaction(realm -> { realm.insert(person);
 });
 } finally {
 realm.close();
 } } } } [email protected]

Slide 35

Slide 35 text

࣮ࡍͷ࢖͍ํ ඇLooperεϨουฤ public class MyThread extends Thread {
 @Override
 public void run() { Realm realm = Realm.getDefaultInstance(); try { RealmResults articles = ...;
 while(true) { realm.waitForChange(); //articlesを読み出して必要な処理を実行 } } finally {
 realm.close();
 } } } [email protected]

Slide 36

Slide 36 text

public class MyApplication extends Application {
 @Override
 public void onCreate() {
 super.onCreate(); 
 Realm.init(this);
 }
 }
 શମͷॳظԽ [email protected]

Slide 37

Slide 37 text

ॏཁ֓೦ [email protected]

Slide 38

Slide 38 text

unmanaged/managed Article unmanagedArticle = new Article(); unmanagedArticle.isManaged(); // false unmanagedArticle.setTitle("meetup"); // OK RealmResults articles = ...; final Article managedArticle = articles.first(); managedArticle.isManaged(); // true managedArticle.setTitle("meetup"); // τϥϯβΫγϣϯΤϥʔ realm.executeTransaction(realm -> { managedArticle.setTitle("meetup"); // OK });
 [email protected]

Slide 39

Slide 39 text

εϨουͷѻ͍ RealmΠϯελϯεͱ͔ͦ͜Βऔಘͨ͠ϥΠϒͳΦϒδΣΫτ͸ εϨουؒͰͷड͚౉͠Λߦͬͯ͸͍͚ͳ͍ʂʂ [email protected]

Slide 40

Slide 40 text

Slide 41

Slide 41 text

byte[] key = new byte[64];
 new SecureRandom().nextBytes(key);
 final RealmConfiguration config = new RealmConfiguration.Builder()
 .encryptionKey(key)
 .build();
 
 final Realm realm = Realm.getInstance(config);
 ҉߸Խ [email protected]

Slide 42

Slide 42 text

byte[] key = new byte[64];
 new SecureRandom().nextBytes(key);
 final RealmConfiguration config = new RealmConfiguration.Builder()
 .encryptionKey(key)
 .build();
 
 final Realm realm = Realm.getInstance(config);
 ҉߸Խ 伴͸64όΠτ [email protected]

Slide 43

Slide 43 text

byte[] key = new byte[64];
 new SecureRandom().nextBytes(key);
 final RealmConfiguration config = new RealmConfiguration.Builder()
 .encryptionKey(key)
 .build();
 
 final Realm realm = Realm.getInstance(config);
 ҉߸Խ 伴ͷੜ੒ͷҰྫ [email protected]

Slide 44

Slide 44 text

byte[] key = new byte[64];
 new SecureRandom().nextBytes(key);
 final RealmConfiguration config = new RealmConfiguration.Builder()
 .encryptionKey(key)
 .build();
 
 final Realm realm = Realm.getInstance(config);
 ҉߸Խ 伴Ληοτͨ͠ઃఆ৘ใͷ࡞੒ [email protected]

Slide 45

Slide 45 text

byte[] key = new byte[64];
 new SecureRandom().nextBytes(key);
 final RealmConfiguration config = new RealmConfiguration.Builder()
 .encryptionKey(key)
 .build();
 
 final Realm realm = Realm.getInstance(config);
 ҉߸Խ RealmΠϯελϯεͷऔಘ [email protected]

Slide 46

Slide 46 text

˖ إٝءذ؍ـז䞔㜠ך⥂㶷 խ⦐➂䞔㜠ծ،ؕؐٝزز٦ؙٝזו ˖ 衼⡲埄זוד⥂隊ׁ׸׋ر٦ة ҉߸Խ [email protected]

Slide 47

Slide 47 text

Realm Mobile Platform [email protected] [email protected]

Slide 48

Slide 48 text

What is Realm Mobile Platform? [email protected]

Slide 49

Slide 49 text

Realm Mobile Database ˖ 42-JUFך➿剏הז׷ٌغ؎ٕرغ؎أ㼔欽ך ر٦ةك٦أ ˖ ؙٗأفٓحزؿؓ٦ي ˖ J04"OESPJE ˖ +BWB 4XJGU 0CKFDUJWF$ $ +BWB4DSJQU ˖ ؔ٦فٝا٦أ [email protected]

Slide 50

Slide 50 text

Realm Mobile Platform [email protected]

Slide 51

Slide 51 text

Realm Mobile Platform Realm Mobile Database [email protected]

Slide 52

Slide 52 text

Realm Mobile Platform Realm Mobile Database Data Sync ٔ،ٕة؎يず劍 [email protected]

Slide 53

Slide 53 text

Realm Mobile Platform Realm Mobile Database Data Sync User Identify ٔ،ٕة؎يず劍 ِ٦ؠ٦陎ⴽ [email protected]

Slide 54

Slide 54 text

Realm Mobile Platform Realm Mobile Database Data Sync Access Control User Identify ٔ،ٕة؎يず劍 ِ٦ؠ٦陎ⴽ ر٦ةⰟ剣 [email protected]

Slide 55

Slide 55 text

Realm Mobile Platform Realm Mobile Database Data Sync Access Control User Identify Event Handling ٔ،ٕة؎يず劍 ِ٦ؠ٦陎ⴽ ر٦ةⰟ剣 ؽآطأٗآحؙ [email protected]

Slide 56

Slide 56 text

Realm Mobile Platform Realm Mobile Database [email protected]

Slide 57

Slide 57 text

Slide 58

Slide 58 text

࢖ͬͯΈΔ [email protected]

Slide 59

Slide 59 text

ηοτΞοϓ [email protected]

Slide 60

Slide 60 text

Realm Object ServerΛىಈ͢Δ [email protected]

Slide 61

Slide 61 text

AdminΞΧ΢ϯτΛ࡞Δ [email protected]

Slide 62

Slide 62 text

ηοτΞοϓ [email protected]

Slide 63

Slide 63 text

ηοτΞοϓ [email protected]

Slide 64

Slide 64 text

μογϡϘʔυ [email protected]

Slide 65

Slide 65 text

μογϡϘʔυ [email protected]

Slide 66

Slide 66 text

Object Server্ͷσʔλΛݟΔ [email protected]

Slide 67

Slide 67 text

Realm Browser [email protected]

Slide 68

Slide 68 text

جຊతͳ࢖͍ํ [email protected]

Slide 69

Slide 69 text

ΞΫηετʔΫϯʢmacOSʣ [email protected]

Slide 70

Slide 70 text

ΞΫηετʔΫϯʢCentOSʣ # cd /etc/realm/ # ls admin_token.base64 configuration.yml token- signature.key token-signature.pub # cat admin_token.base64 ewoJImlkZW50a... [email protected]

Slide 71

Slide 71 text

جຊతͳ࢖͍ํ(Android) ηοτΞοϓ realm { syncEnabled = true } appͷbuild.gradeʹ [email protected]

Slide 72

Slide 72 text

جຊతͳ࢖͍ํ(Android) ೝূ Credentials creds = Credentials.usernamePassword(username, password, true);
 User.loginAsync(creds, "https://realm.example.com:9443/auth", new User.Callback() {
 @Override
 public void onSuccess(User user) { // ログイン成功時の処理 }
 
 @Override
 public void onError(ObjectServerError error) {
 // エラー処理
 }
 } ); [email protected]

Slide 73

Slide 73 text

جຊతͳ࢖͍ํ(Android) RealmΠϯελϯεͷऔಘ // ユーザーとURLから設定を作成
 SyncConfiguration config = new SyncConfiguration.Builder(user,
 "realm://realm.example.com/~/userRealm").build();
 
 // 同期されるRealm
 Realm realm = Realm.getInstance(config); [email protected]

Slide 74

Slide 74 text

جຊతͳ࢖͍ํ(iOS) User.authenticate(with: Credential.usernamePassword(username: "username", password: "password", actions: []), server: URL(string: "http://128.199.141.202:9080")!, onCompletion: { user, error in guard let user = user else { fatalError(String(describing: error)) } let configuration = Realm.Configuration( syncConfiguration: (user, URL(string: "realm://128.199.141.202:9080/~/realmtasks")!) ) self.realm = try! Realm(configuration: configuration) }) [email protected]

Slide 75

Slide 75 text

FacebookϩάΠϯ [email protected]

Slide 76

Slide 76 text

FacebookϩάΠϯ facebookAuth = new FacebookAuth(loginButton) {
 @Override
 public void onRegistrationComplete(LoginResult loginResult) {
 SyncCredentials credentials = SyncCredentials.facebook( loginResult.getAccessToken().getToken());
 SyncUser.loginAsync(credentials, AUTH_URL, LoginActivity.this);
 }
 };
 [email protected]

Slide 77

Slide 77 text

FacebookϩάΠϯ developers.facebook.com/docs/facebook-login/ android [email protected]

Slide 78

Slide 78 text

Typical Application Data Flow Native object JSON Native object SQL Native object JSON Native object SQLite/CoreData SQLite/CoreData [email protected]

Slide 79

Slide 79 text

w/ Realm Mobile Platform [email protected]

Slide 80

Slide 80 text

Data Sync ر٦ةず劍 [email protected]

Slide 81

Slide 81 text

User Identify ر٦ةず劍 ِ٦ؠ٦陎ⴽ [email protected]

Slide 82

Slide 82 text

Access Control ر٦ةず劍 ِ٦ؠ٦陎ⴽ ،ؙإأ؝ٝزٗ٦ٕ [email protected]

Slide 83

Slide 83 text

Event Handling ؎كٝزعٝسؚٔٝ [email protected]

Slide 84

Slide 84 text

ΠϕϯτϋϯυϦϯά var Realm = require('realm'); var filter_callback = function(realm_name) { ... }; var change_notification_callback = function(realm_name, realm) { var channels = realm.objects('Channel'); for (var i = 0; i < channels.length; ++i) { var channel = channels[i]; ... } }; Realm.setGlobalSyncListener(local_root_dir, server_base_url, access_token, filter_callback, change_notification_callback); [email protected]

Slide 85

Slide 85 text

Slide 86

Slide 86 text

Realm Mobile Platform ˖ .PCJMF%BUBCBTF ˖ ⿽倯ぢךر٦ةず劍 ˖ ٔ،ٕة؎ي ˖ ء٦يٖأ ˖ ؝ٝؿؙٔزך荈⹛鍑寸 ˖ ِ٦ؠ٦陎ⴽ ˖ ؎كٝزعٝسؚٔٝ • αʔόʔϓογϡ • σʔλڞ༗ • ΞΫηείϯτϩʔϧ [email protected]

Slide 87

Slide 87 text

ίϯϑϦΫτͷղܾ • جຊ͸ޙউͪ • ಉ͡ΞΠςϜʹผͷมߋΛՃ͑ͨ৔߹ɺޙʹىͬͨ͜มߋ͕࠾༻ ͞Ε·͢ɻ • ಉ͡ΠϯσοΫε΁ͷૠೖ͸࣌ؒॱʹͳΔ • ࡟আ͸͢΂ͯʹউͭ • ͋ΔΞΠςϜ͕࡟আ͞ΕͯɺผͷσόΠεͰ͸ಉ͡ΞΠςϜΛมߋ ͨ͠ɺͱ͍͏৔߹͸ɺ࡟আ͚͕ͩى͜Γ·͢ɻ [email protected]

Slide 88

Slide 88 text

Demo github.com/realm/RealmTasks [email protected]

Slide 89

Slide 89 text

Recent Updates [email protected]

Slide 90

Slide 90 text

Recent Updates • Realm Objective-C/Swift 2.0.3 • Realm Java 2.2.0 • Realm React Native 0.14.0 • Realm Xamarin 0.78 [email protected]

Slide 91

Slide 91 text

Where to find us • $ Realm Japan User Group: facebook.com/groups/realmjp • $ Twitter: twitter.com/realmJapan • GitHub: github.com/realm • $ StackOverflow: ja.stackoverflow.com/questions/tagged/realm • $ Email: [email protected] • $ Slack: slack.realm.io/ [email protected]

Slide 92

Slide 92 text

Realm Japan User Group Facebook [email protected]

Slide 93

Slide 93 text

Support Chat Slack http://slack.realm.io/ [email protected]

Slide 94

Slide 94 text

Ξϯέʔτ http://bit.ly/RealmJP_Ueda [email protected]

Slide 95

Slide 95 text

Questions? Makoto Yamazaki [email protected] www.realm.io/jp @zaki50 [email protected]