Save 37% off PRO during our Black Friday Sale! »

Realm Meetup 名古屋 #1 (Java)

358791a9c91e7615ffe62c7c6e02e470?s=47 zaki50
October 21, 2016

Realm Meetup 名古屋 #1 (Java)

358791a9c91e7615ffe62c7c6e02e470?s=128

zaki50

October 21, 2016
Tweet

Transcript

  1. Realm meetup ໊ݹ԰ my@realm.io

  2. #realm_jp my@realm.io

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

  4. Realm Java ิ଍ my@realm.io

  5. Realm Javaͷྫ(Ϟσϧఆٛ) my@realm.io public class Person extends RealmObject {
 @PrimaryKey


    private long id;
 private String name;
 private Cat cat;
 private RealmList<Dog> dogs;
 
 // getter, setter
 }
  6. Realm Javaͷྫ(Ϟσϧఆٛ) my@realm.io @RealmClass
 public class Person implements RealmModel {


    @PrimaryKey
 public long id;
 public String name;
 public Cat cat;
 public RealmList<Dog> dogs;
 }
  7. Realm Javaͷྫ(࡞੒) my@realm.io final Person person = new Person();
 person.name

    = "Tim";
 
 final Realm realm = Realm.getDefaultInstance();
 try {
 realm.executeTransaction(new Realm.Transaction() {
 @Override
 public void execute(Realm realm) {
 realm.insert(person);
 }
 });
 } finally {
 realm.close();
 }
  8. Realm Javaͷྫ(࡞੒) my@realm.io final Realm realm = Realm.getDefaultInstance();
 try {


    realm.executeTransaction(new Realm.Transaction() {
 @Override
 public void execute(Realm realm) {
 final Person person = realm.createObject(Person.class);
 person.name = "Tim";
 }
 });
 } finally {
 realm.close();
 }
  9. Realm Javaͷྫ (ListAdapter) my@realm.io public class PersonAdapter extends RealmBaseAdapter<Person> {


    public PersonAdapter(@NonNull Context context,
 @Nullable OrderedRealmCollection<Person> data) {
 super(context, data);
 }
 
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
 if (convertView == null) {
 convertView = inflater.inflate(android.R.layout.simple_list_item_2, parent, false);
 }
 final Person item = getItem(position);
 ((TextView) convertView.findViewById(android.R.id.text1)).setText(item.name);
 ((TextView) convertView.findViewById(android.R.id.text2)).setText(item.cat.name);
 return convertView;
 }
 } final RealmResults<Person> allPerson = realm.where(Person.class).findAll();
 listView.setAdapter(new PersonAdapter(this, allPerson));
  10. Realm CoreΛ׬શެ։ my@realm.io

  11. Realm CoreϓϩδΣΫτ my@realm.io https://github.com/realm/realm-core

  12. Ϗϧυํ๏ my@realm.io how-to-build.md ࢀর • Ubuntu 10.04, 12.04, 13.04, 13.10,

    14.04 • Linux Mint 15, 16, 17, 17.1 • Fedora 17, 18, 19, 20 • Amazon Linux 2012.09 • OS X 10.10 and 10.11
  13. Ϗϧυํ๏ my@realm.io how-to-build.md ࢀর # ڞ௨ $ sh build.sh config

    $ sh build.sh build $ sh build.sh test # iOS $ sh build.sh build-ios # watchOS $ sh build.sh build-watchos # tvOS $ sh build.sh build-tvos # Android $ sh build.sh build-android
  14. ϑΝΠϧߏ੒ my@realm.io src/realm test/ doc/ ओʹݟΔ΂͖͸ҎԼͷσΟϨΫτϦ

  15. ϔομϑΝΠϧ my@realm.io /// The Table class is non-polymorphic, that is,

    it has no virtual
 /// functions. This is important because it ensures that there is no run-time
 /// distinction between a Table instance and an instance of any variation of
 /// BasicTable<T>, and this, in turn, makes it valid to cast a pointer from
 /// Table to BasicTable<T> even when the instance is constructed as a Table. Of
 /// course, this also assumes that BasicTable<> is non-polymorphic, has no
 /// destructor, and adds no extra data members.
 ///
 /// FIXME: Table assignment (from any group to any group) could be made aliasing
 /// safe as follows: Start by cloning source table into target allocator. On
 /// success, assign, and then deallocate any previous structure at the target.
 ///
 /// FIXME: It might be desirable to have a 'table move' feature between two
 /// places inside the same group (say from a subtable or a mixed column to group
 /// level). This could be done in a very efficient manner.
 ///
 /// FIXME: When compiling in debug mode, all public non-static table functions
 /// should REALM_ASSERT(is_attached()).
 class Table {
 public:
 /// Construct a new freestanding top-level table with static
 /// lifetime.
 ///
 /// This constructor should be used only when placing a table
 /// instance on the stack, and it is then the responsibility of
 /// the application that there are no objects of type TableRef or
 /// ConstTableRef that refer to it, or to any of its subtables,
 /// when it goes out of scope. To create a top-level table with
 /// dynamic lifetime, use Table::create() instead.
 Table(Allocator& = Allocator::get_default());
 
 /// Construct a copy of the specified table as a new freestanding
 /// top-level table with static lifetime.
 ///
 /// This constructor should be used only when placing a table
 /// instance on the stack, and it is then the responsibility of
 /// the application that there are no objects of type TableRef or
 /// ConstTableRef that refer to it, or to any of its subtables,
 /// when it goes out of scope. To create a top-level table with
 /// dynamic lifetime, use Table::copy() instead.
 Table(const Table&, Allocator& = Allocator::get_default());
 ͓קΊϔομϑΝΠϧ group.hpp group_shared.hpp table.hpp string_data.hpp index_string.hpp query_expression.hpp
  16. star & PR͓଴͍ͪͯ͠·͢ my@realm.io CONTRIBUTING.md doc/development/coding_style_guide.cpp

  17. Recent Updates my@realm.io

  18. Realm Java 2.0.2 my@realm.io

  19. Realm Java 2.0.0(৽ػೳ) • Realm Mobile PlatformରԠʂʂʂʢϕʔλʣ • άϩʔόϧॳظԽϝιουRealm.init(Context)Λಋೖ •

    ॳظԽϝιουҎ֎Ͱ͸Context͕ෆཁʹ • RealmLogΫϥεʹΑΔϩά੍ޚ • ϞσϧΫϥεͰΦϒδΣΫτͷॳظ஋ΛఆٛՄೳʹ • isManaged()ϝιουΛ௥Ճ my@realm.io
  20. Realm Java 2.0.0(όάमਖ਼) • ϞσϧΫϥεͷίϯετϥΫλ಺ͰɺଞͷϞσϧΫϥεͷϑΟʔϧυΞ Ϋηε͕ਖ਼͘͠ಈ࡞͠ͳ͍όάΛमਖ਼(#3361) • ϞσϧͷίϯετϥΫλ͔Βsetter/getterΛݺͿͱNPE͕ൃੜ͢Δόά Λमਖ਼(#2536) •

    ଞͷϓϩδΣΫτͰॻ͖׵͑ࡁΈͷϞσϧΫϥεΛ࠶౓ॻ͖׵͑Α͏͠ ͯΤϥʔ͕ൃੜ͢ΔόάΛमਖ਼(#3469) my@realm.io
  21. Realm Java 2.0.0(ඇޓ׵ͷมߋ1) • ϑΝΠϧͷϑΥʔϚοτ͕มߋʹͳ͍ͬͯ·͢(ࣗಈతʹม׵) • ͸͡ΊʹඞͣRealm.init(Context)ΛݺΜͰ͍ͩ͘͞(Application౳Ͱ) • Ҿ͖਺ʹContextΛऔΔίϯετϥΫλ/ϝιου͸Context͕ͳ͍΋ͷΛ࢖ͬͯͩ͘ ͍͞

    • ΞϯϚωʔδυͳRealmObjectͷisValid()͸ৗʹtrueΛฦ͢Α͏ʹͳΓ·ͨ͠(ଞͷϓ ϥοτϑΥʔϜͱͷޓ׵ੑ) • armeabiͷόΠφϦΛ࡟আ͠·ͨ͠(෮׆ͷՄೳੑ͋Γ #3508) • IncompatibleLockFileException ͱRealmIOExcpetion ͕ഇࢭ͞ΕɺRealmFileException Ͱஔ͖׵͑ΒΕ·ͨ͠ my@realm.io
  22. Realm Java 2.0.0(ඇޓ׵ͷมߋ2) • ϓϥΠϚϦΩʔ͕ఆٛ͞ΕͨΫϥεΛRealm.createObject()Ͱ࡞੒͢Δ৔ ߹ɺRealm.createObject(Class)Ͱ͸ͳ͘Realm.createObject(Class,Object) Λ࢖͍ͬͯͩ͘͞ • JSON͔ΒΠϯϙʔτ͢ΔࡍɺϓϥΠϚϦΩʔ͕ఆٛ͞Ε͍ͯΔʹ΋ؔΘ ΒͣJSON

    ্ʹଘࡏ͠ͳ͍৔߹͸ྫ֎͕εϩʔ͞Ε·͢ • ϓϥΠϚϦΩʔͷ஋͸มߋෆՄʹͳΓ·ͨ͠ • Realm.create*FromJson()͸ɺϞσϧΫϥεͷϑΟʔϧυ΍ίϯετϥΫλ Ͱఆٛ͞Εͨॳظ஋Λ൓ө͢ΔΑ͏ʹͳΓ·ͨ͠ my@realm.io
  23. Realm Mobile PlatformରԠ my@realm.io realm { syncEnabled = true }

    appͷbuild.gradeʹ ৄࡉ͸ bit.ly/RMP_JAVA
  24. Realm Mobile PlatformରԠ my@realm.io 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) {
 // エラー処理
 }
 } );
  25. Realm Mobile PlatformରԠ my@realm.io // ユーザーとURLから設定を作成
 SyncConfiguration config = new

    SyncConfiguration.Builder(user,
 "realm://realm.example.com/~/userRealm").build();
 
 // 同期されるRealm
 Realm realm = Realm.getInstance(config);
  26. Realm Mobile PlatformରԠ my@realm.io https://github.com/realm/RealmTasks ͷ RealmTasks Android ʹαϯϓϧ͕͋Γ·͢

  27. Realm Mobile PlatformରԠ my@realm.io ࠓޙͷ༧ఆ

  28. Realm Mobile PlatformରԠ my@realm.io • Ϋϥε໊मਖ਼(Sync prefix) (#3630) • Download

    Realm API࣮૷ • Permission API࣮૷ (#3627) • άϩʔόϧϩάΞ΢τ (#3642) • fine-grained notification
  29. Realm.init(Context)ͷಋೖ my@realm.io public class MyApplication extends Application {
 @Override
 public

    void onCreate() {
 super.onCreate();
 
 Realm.init(this);
 
 // その他の初期化
 }
 }
  30. RealmLogΫϥε my@realm.io // すべてのロガーを削除 RealmLog.clear(); // 独自のロガーを追加
 RealmLog.add(new AndroidLogger(Log.DEBUG));

  31. ϞσϧΫϥεͷॳظ஋ my@realm.io public class User extends RealmObject {
 @PrimaryKey
 @Required


    public String id = UUID.randomUUID().toString();
 public String name;
 public int age;
 
 public User() {
 this.name = "unknown";
 }
 } String id = UUID.randomUUID().toString();
 User user = realm.createObject(User.class, id);
 print(user.id); // createObjectに渡したidの値
 print(user.name); // "unknown"
  32. ϞσϧΫϥεͷॳظ஋ my@realm.io public class Owner extends RealmObject {
 public String

    name;
 public User user = new User();
 } Owner owner = realm.createObject(Owner.class);
 print(owner.user.id); // モデルクラスが生成したランダムなID
  33. ίϯετϥΫλབྷΈͷόάमਖ਼ my@realm.io public class User extends RealmObject {
 public String

    name;
 public int age;
 
 public User() {}
 
 public User(User user) {
 this.name = user.name; 
 setAge(20);
 }
 
 public void setAge(int age) {
 this.age = age;
 }
 } NullPointerException user͕Ϛωʔδυͷ৔߹ৗʹ0
  34. Realm Java 2.0.1(όάमਖ਼) • syncEnabled falseͷࡍʹෆཁͳINTERNETύʔϛογϣϯΛཁٻ͢Δ όά (#3505) • syncEnabled

    falseͷࡍʹωοτϫʔΫͷ઀ଓঢ়ଶ͕มΘΔͱΫϥο γϡ͢Δόά (#3505) • distinctAsync͕ɺࢦఆ͞ΕͨΫΤϦͷ৚݅Λແࢹ͢Δόά (#3537) • ಛఆͷ؀ڥͰϏϧυ࣌ʹConcurrentModificationException͕ൃੜ͢Δ όά(#3501) my@realm.io
  35. Realm Java 2.0.2(όάमਖ਼) • Java7؀ڥͰϏϧυΤϥʔ͕ൃੜ͢Δόά (3563) my@realm.io

  36. Realm Java 2.0.3(༧ఆ) • ProGuardઃఆͷߋ৽ (#3596) • Realm Object Serverͱͷ௨৴࣌ʹΤϥʔ͕ൃੜͨ͠৔߹ʹਖ਼͘͠ϩ

    άϋϯυϥʔ͕ݺ͹Εͳ͍όά (#3597) • ֎෦ετϨʔδͳͲɺnamed pipeϑΝΠϧ͕࡞੒Ͱ͖ͳ͍৔ॴʹ σʔλϕʔεϑΝΠϧΛஔ͘ͱΫϥογϡ͢Δόά (#3140) my@realm.io
  37. jp@realm.io 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
  38. Ξϯέʔτͷճ౴Λ͓ئ͍͠·͢ jp@realm.io http://bit.ly/RealmJP_Nagoya