Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Realm Japan meetup Ueda

358791a9c91e7615ffe62c7c6e02e470?s=47 zaki50
November 12, 2016

Realm Japan meetup Ueda

358791a9c91e7615ffe62c7c6e02e470?s=128

zaki50

November 12, 2016
Tweet

Transcript

  1. Realm meetup ্ా zaki@realm.io

  2. #realm_jp zaki@realm.io

  3. Makoto Yamazaki Realm Inc. / uPhyca Inc. zaki@realm.io

  4. What is Realm? zaki@realm.io

  5. ٌغ؎ٕرغ؎أ㼔欽ח倜׃ֻ⡲׵׸׋ر٦ةك٦أ  0CKFDUJWF$䎃剢։  +BWB䎃剢։  4XJGU䎃剢։ ٌغ؎ٕ欽鷿ח剑黝⻉ׁ׸גְ׷  鹼䒀ٗ٦س

     ئٗ؝ؾ٦  ط؎ذ؍ـ٥ؙٔٝ Realm zaki@realm.io
  6. Realm ˖ ؙٗأفٓحزؿؓ٦ي ˖ J04"OESPJE ˖ +BWB 4XJGU 0CKFDUJWF$ $

    +BWB4DSJQU ˖ ؔ٦فٝا٦أ ˖ 杝荈%#ؒٝآٝ42-JUF׾⢪׏גְזְ zaki@realm.io
  7. Realmͷಛ௕ 넝鸞ז⹛⡲ 农〾⻉׾垥彊鄲⪒ 湫䠬涸דءٝفٕז"1* ♨㻝ז؟ه٦ز傈劤铂0, zaki@realm.io

  8. 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<Comment> comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ zaki@realm.io
  9. 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<Comment>() } Ϟσϧʢςʔϒϧʣఆٛ (iOS) zaki@realm.io
  10. 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<Comment> comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ RealmObjectΫϥεΛܧঝ zaki@realm.io
  11. 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<Comment> comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ ΧϥϜͱσʔλܕ zaki@realm.io
  12. 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<Comment> comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ nullͷՄʗෆՄ zaki@realm.io
  13. 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<Comment> comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ ̍ର̍ͷؔ࿈ zaki@realm.io
  14. 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<Comment> comments; // getter, setter } Ϟσϧʢςʔϒϧʣఆٛ ̍ରଟͷؔ࿈ zaki@realm.io
  15. public final class RealmList<E extends RealmModel> extends java.util.AbstractList<E> implements io.realm.OrderedRealmCollection<E>

    { ....
 } Ϟσϧʢςʔϒϧʣఆٛ RealmListΫϥε zaki@realm.io
  16. byte/Byte short/Short int/Integer long/Long boolean/Boolean float/Float double/Double String Date byte[]

    モデルクラス RealmList<モデルクラス> Ϟσϧʢςʔϒϧʣఆٛ ΧϥϜʹ࢖༻Ͱ͖Δܕ zaki@realm.io
  17. 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();
 } σʔλͷอଘ zaki@realm.io
  18. 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();
 } σʔλͷอଘ ϞσϧΦϒδΣΫτͷ࡞੒ zaki@realm.io
  19. 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Πϯελϯεͷऔಘ zaki@realm.io
  20. 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();
 } σʔλͷอଘ ςʔϒϧ΁ૠೖ zaki@realm.io
  21. Realm realm = Realm.getDefaultInstance();
 try { RealmResults<Article> articles = realm.where(Article.class)

    .beginsWith("title", "Realm") .findAllSorted("creationDate", Sort.DESCENDING); } finally {
 realm.close();
 } ΫΤϦ zaki@realm.io
  22. Realm realm = Realm.getDefaultInstance();
 try { RealmResults<Article> articles = realm.where(Article.class)

    .beginsWith("title", "Realm") .findAllSorted("creationDate", Sort.DESCENDING); } finally {
 realm.close();
 } ΫΤϦ RealmΠϯελϯεͷऔಘ zaki@realm.io
  23. Realm realm = Realm.getDefaultInstance();
 try { RealmResults<Article> articles = realm.where(Article.class)

    .beginsWith("title", "Realm") .findAllSorted("creationDate", Sort.DESCENDING); } finally {
 realm.close();
 } ΫΤϦ ৚݅ͷࢦఆͱ݁Ռͷऔಘ zaki@realm.io
  24. Realm realm = Realm.getDefaultInstance();
 try { RealmResults<Article> articles = realm.where(Article.class)

    .equalTo("user.name", "Tim") .lessThan("user.age", 30) .findAllSorted("creationDate", Sort.DESCENDING); } finally {
 realm.close();
 } ϦϯΫΫΤϦ zaki@realm.io
  25. Realm realm = Realm.getDefaultInstance();
 try { RealmResults<Article> articles = realm.where(Article.class)

    .contains("comments.message", "Ueda") .contains("comments.message", "meetup") .findAllSorted("creationDate", Sort.DESCENDING); } finally {
 realm.close();
 } ϦϯΫΫΤϦ ஫ҙʂ zaki@realm.io
  26. 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 zaki@realm.io
  27. ΫΤϦϝιου isNull/isNotNull isEmpty/isNotEmpty equalTo/notEqualTo greaterThan greaterThanOrEqualTo lessThan lessThanOrEqualTo between contains

    beginsWith endsWith in and or not beginGroup endGroup zaki@realm.io
  28. ूܭϝιου sum average min max maximumDate minimumDate count zaki@realm.io

  29. Realm realm = Realm.getDefaultInstance();
 try {
 RealmResults<Article> 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();
 } σʔλͷಡΈग़͠ zaki@realm.io
  30. RealmResults<Article> articles = ...; articles.addChangeListener(results -> { // ArticleΫϥεʹ͍ͭͯมߋɾ௥Ճɾ࡟আͷࡍʹݺ͹ΕΔ });

    Article article = articles.first(); article.addChangeListener(obj -> { // ArticleΫϥεʹ͍ͭͯมߋɾ௥Ճɾ࡟আͷࡍʹݺ͹ΕΔ }); มߋ௨஌ zaki@realm.io
  31. ࣮ࡍͷ࢖͍ํ zaki@realm.io

  32. ࣮ࡍͷ࢖͍ํ 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(); } } zaki@realm.io
  33. ࣮ࡍͷ࢖͍ํ 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(); } } zaki@realm.io
  34. ࣮ࡍͷ࢖͍ํ ඇ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();
 } } } } zaki@realm.io
  35. ࣮ࡍͷ࢖͍ํ ඇLooperεϨουฤ public class MyThread extends Thread {
 @Override
 public

    void run() { Realm realm = Realm.getDefaultInstance(); try { RealmResults<Article> articles = ...;
 while(true) { realm.waitForChange(); //articlesを読み出して必要な処理を実行 } } finally {
 realm.close();
 } } } zaki@realm.io
  36. public class MyApplication extends Application {
 @Override
 public void onCreate()

    {
 super.onCreate(); 
 Realm.init(this);
 }
 }
 શମͷॳظԽ zaki@realm.io
  37. ॏཁ֓೦ zaki@realm.io

  38. unmanaged/managed Article unmanagedArticle = new Article(); unmanagedArticle.isManaged(); // false unmanagedArticle.setTitle("meetup");

    // OK RealmResults<Article> articles = ...; final Article managedArticle = articles.first(); managedArticle.isManaged(); // true managedArticle.setTitle("meetup"); // τϥϯβΫγϣϯΤϥʔ realm.executeTransaction(realm -> { managedArticle.setTitle("meetup"); // OK });
 zaki@realm.io
  39. εϨουͷѻ͍ RealmΠϯελϯεͱ͔ͦ͜Βऔಘͨ͠ϥΠϒͳΦϒδΣΫτ͸ εϨουؒͰͷड͚౉͠Λߦͬͯ͸͍͚ͳ͍ʂʂ zaki@realm.io

  40. ҉߸Խ zaki@realm.io

  41. byte[] key = new byte[64];
 new SecureRandom().nextBytes(key);
 final RealmConfiguration config

    = new RealmConfiguration.Builder()
 .encryptionKey(key)
 .build();
 
 final Realm realm = Realm.getInstance(config);
 ҉߸Խ zaki@realm.io
  42. 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όΠτ zaki@realm.io
  43. byte[] key = new byte[64];
 new SecureRandom().nextBytes(key);
 final RealmConfiguration config

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

    = new RealmConfiguration.Builder()
 .encryptionKey(key)
 .build();
 
 final Realm realm = Realm.getInstance(config);
 ҉߸Խ 伴Ληοτͨ͠ઃఆ৘ใͷ࡞੒ zaki@realm.io
  45. 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Πϯελϯεͷऔಘ zaki@realm.io
  46. ˖ إٝءذ؍ـז䞔㜠ך⥂㶷 խ⦐➂䞔㜠ծ،ؕؐٝزز٦ؙٝזו ˖ 衼⡲埄זוד⥂隊ׁ׸׋ر٦ة ҉߸Խ zaki@realm.io

  47. Realm Mobile Platform kk@realm.io zaki@realm.io

  48. What is Realm Mobile Platform? zaki@realm.io

  49. Realm Mobile Database ˖ 42-JUFך➿剏הז׷ٌغ؎ٕرغ؎أ㼔欽ך ر٦ةك٦أ ˖ ؙٗأفٓحزؿؓ٦ي ˖ J04"OESPJE

    ˖ +BWB 4XJGU 0CKFDUJWF$ $ +BWB4DSJQU ˖ ؔ٦فٝا٦أ zaki@realm.io
  50. Realm Mobile Platform zaki@realm.io

  51. Realm Mobile Platform Realm Mobile Database zaki@realm.io

  52. Realm Mobile Platform Realm Mobile Database Data Sync ٔ،ٕة؎يず劍 zaki@realm.io

  53. Realm Mobile Platform Realm Mobile Database Data Sync User Identify

    ٔ،ٕة؎يず劍 ِ٦ؠ٦陎ⴽ zaki@realm.io
  54. Realm Mobile Platform Realm Mobile Database Data Sync Access Control

    User Identify ٔ،ٕة؎يず劍 ِ٦ؠ٦陎ⴽ ر٦ةⰟ剣 zaki@realm.io
  55. Realm Mobile Platform Realm Mobile Database Data Sync Access Control

    User Identify Event Handling ٔ،ٕة؎يず劍 ِ٦ؠ٦陎ⴽ ر٦ةⰟ剣 ؽآطأٗآحؙ zaki@realm.io
  56. Realm Mobile Platform Realm Mobile Database zaki@realm.io

  57. Demo zaki@realm.io

  58. ࢖ͬͯΈΔ zaki@realm.io

  59. ηοτΞοϓ zaki@realm.io

  60. Realm Object ServerΛىಈ͢Δ zaki@realm.io

  61. AdminΞΧ΢ϯτΛ࡞Δ zaki@realm.io

  62. ηοτΞοϓ zaki@realm.io

  63. ηοτΞοϓ zaki@realm.io

  64. μογϡϘʔυ zaki@realm.io

  65. μογϡϘʔυ zaki@realm.io

  66. Object Server্ͷσʔλΛݟΔ zaki@realm.io

  67. Realm Browser zaki@realm.io

  68. جຊతͳ࢖͍ํ zaki@realm.io

  69. ΞΫηετʔΫϯʢmacOSʣ zaki@realm.io

  70. ΞΫηετʔΫϯʢCentOSʣ # cd /etc/realm/ # ls admin_token.base64 configuration.yml token- signature.key

    token-signature.pub # cat admin_token.base64 ewoJImlkZW50a... zaki@realm.io
  71. جຊతͳ࢖͍ํ(Android) ηοτΞοϓ realm { syncEnabled = true } appͷbuild.gradeʹ zaki@realm.io

  72. جຊతͳ࢖͍ํ(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) {
 // エラー処理
 }
 } ); zaki@realm.io
  73. جຊతͳ࢖͍ํ(Android) RealmΠϯελϯεͷऔಘ // ユーザーとURLから設定を作成
 SyncConfiguration config = new SyncConfiguration.Builder(user,
 "realm://realm.example.com/~/userRealm").build();


    
 // 同期されるRealm
 Realm realm = Realm.getInstance(config); zaki@realm.io
  74. جຊతͳ࢖͍ํ(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) }) zaki@realm.io
  75. FacebookϩάΠϯ zaki@realm.io

  76. 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);
 }
 };
 zaki@realm.io
  77. FacebookϩάΠϯ developers.facebook.com/docs/facebook-login/ android zaki@realm.io

  78. Typical Application Data Flow Native object JSON Native object SQL

    Native object JSON Native object SQLite/CoreData SQLite/CoreData zaki@realm.io
  79. w/ Realm Mobile Platform zaki@realm.io

  80. Data Sync ر٦ةず劍 zaki@realm.io

  81. User Identify ر٦ةず劍 ِ٦ؠ٦陎ⴽ zaki@realm.io

  82. Access Control ر٦ةず劍 ِ٦ؠ٦陎ⴽ ،ؙإأ؝ٝزٗ٦ٕ zaki@realm.io

  83. Event Handling ؎كٝزعٝسؚٔٝ zaki@realm.io

  84. ΠϕϯτϋϯυϦϯά 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); zaki@realm.io
  85. zaki@realm.io

  86. Realm Mobile Platform ˖ .PCJMF%BUBCBTF ˖ ⿽倯ぢךر٦ةず劍 ˖ ٔ،ٕة؎ي ˖

    ء٦يٖأ ˖ ؝ٝؿؙٔزך荈⹛鍑寸 ˖ ِ٦ؠ٦陎ⴽ ˖ ؎كٝزعٝسؚٔٝ • αʔόʔϓογϡ • σʔλڞ༗ • ΞΫηείϯτϩʔϧ zaki@realm.io
  87. ίϯϑϦΫτͷղܾ • جຊ͸ޙউͪ • ಉ͡ΞΠςϜʹผͷมߋΛՃ͑ͨ৔߹ɺޙʹىͬͨ͜มߋ͕࠾༻ ͞Ε·͢ɻ • ಉ͡ΠϯσοΫε΁ͷૠೖ͸࣌ؒॱʹͳΔ • ࡟আ͸͢΂ͯʹউͭ

    • ͋ΔΞΠςϜ͕࡟আ͞ΕͯɺผͷσόΠεͰ͸ಉ͡ΞΠςϜΛมߋ ͨ͠ɺͱ͍͏৔߹͸ɺ࡟আ͚͕ͩى͜Γ·͢ɻ zaki@realm.io
  88. Demo github.com/realm/RealmTasks zaki@realm.io

  89. Recent Updates zaki@realm.io

  90. Recent Updates • Realm Objective-C/Swift 2.0.3 • Realm Java 2.2.0

    • Realm React Native 0.14.0 • Realm Xamarin 0.78 zaki@realm.io
  91. 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: help@realm.io • $ Slack: slack.realm.io/ zaki@realm.io
  92. Realm Japan User Group Facebook zaki@realm.io

  93. Support Chat Slack http://slack.realm.io/ zaki@realm.io

  94. Ξϯέʔτ http://bit.ly/RealmJP_Ueda zaki@realm.io

  95. Questions? Makoto Yamazaki zaki@realm.io www.realm.io/jp @zaki50 zaki@realm.io