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

Realm Japan meetup #23_Java

358791a9c91e7615ffe62c7c6e02e470?s=47 zaki50
June 28, 2017

Realm Japan meetup #23_Java

358791a9c91e7615ffe62c7c6e02e470?s=128

zaki50

June 28, 2017
Tweet

Transcript

  1. Realm meetup #23 my@realm.io

  2. #realm_jp my@realm.io

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

  4. Recent Updates my@realm.io

  5. Realm Java 3.4.0 (was 3.3.1) my@realm.io

  6. 3.4·Ͱόάमਖ਼(RMD) • setRequired()Ͱbyte[]ܕͷϑΟʔϧυΛnon-nullʹมߋ͢Δࡍɺbyte[0]ʹม׵͞ ΕΔ΂͖΋ͷ͕byte[1]ʹͳ͍ͬͯͨόάΛमਖ਼ • ϓϥΠϚϦΩʔʹࢦఆ͞Ε͍ͯΔϑΟʔϧυʹରͯ͠setRequired()Ͱnon-nullʹ มߋ͢ΔࡍɺnullͷϑΟʔϧυ͕ଘࡏͨ͠Βྫ֎Λεϩʔ͢ΔΑ͏ʹमਖ਼ • ೝূΤϥʔൃੜ࣌ʹΫϥογϡ͢ΔόάΛमਖ਼(#4726) •

    αʔόʔಉظ༗ޮ࣌Ͱ΋ɺϩʔΧϧͷσʔλϕʔεͷ҉߸ԽʹରԠ(#4561) • AdminϢʔβʔ͕αʔόʔʹ઀ଓͰ͖ͳ͍όάΛमਖ਼(#4750) • αʔόʔ઀ଓʹࣦഊͨ͠ͱ͖ʹਖ਼͘͠ϦτϥΠ͞Εͳ͍όάΛमਖ਼(#4750) my@realm.io
  7. Realm Java 3.4৽ػೳ • ΫΤϦʔதͰͷٯํ޲ͷؔ࿈Λαϙʔτͱਖ਼ࣜAPI΁ͷঢ֨⭐ • ಉظͷਐḿঢ়گͷ௨஌Λड͚औΔAPIΛ௥Ճ(#4104) ⭐ • ݱࡏͷಉظঢ়ଶΛऔಘ͢ΔAPIΛ௥Ճ⭐

    • Realm.getDefaultConfiguration()ͷ௥Ճ • RealmSchema.close()ͱRealmObjectSchema.close() Λ deprecated my@realm.io
  8. ٯํ޲ͷؔ࿈ʹର͢ΔΫΤϦʔ my@realm.io public class Person extends RealmObject {
 public String

    name;
 public Dog dog;
 } 
 public class Dog extends RealmObject {
 public String name;
 public int age; @LinkingObjects("dog") public RealmResults<Person> owners;
 } Person owner; owner = realm.where(Dog.class).equalTo("owners.name", "Jane").findFirst; ͜ͷΦϒδΣΫτΛdogϑΟʔϧυ͔Β ࢀর͍ͯ͠ΔશͯͷPersonΦϒδΣΫτ ownersΛϦϯΫΫΤϦʔͰར༻Մೳ
  9. ݱࡏͷಉظঢ়ଶΛऔಘ͢ΔAPI my@realm.io public enum State { WAITING_FOR_ACCESS_TOKEN, // ΞΫηετʔΫϯऔಘத ACTIVE,

    // ΞΫηετʔΫϯ͋Γ DYING, // ϩάΞ΢τॲཧத INACTIVE, // ϩάΠϯલɺϩάΠϯޙ ERROR // Τϥʔ } SyncSession session = SyncManager.getSession(config); SyncState state = session.getState();
  10. ಉظͷਐḿΛड͚औΔϦεφʔ my@realm.io SyncSession session = SyncManager.getSession(config); showProgressBar(); session.addUploadProgressListener(ProgressMode.CURRENT_CHANGES, new ProgressListener()

    { @Override public void onChange(Progress progress) { if (progress.isTransferComplete()) { hideProgressBar(); session.removeProgressListener(this); } else { updateProgressBar(progress.getFractionTransferred()); } } });
  11. ಉظͷਐḿΛड͚औΔϦεφʔ my@realm.io SyncSession session = SyncManager.getSession(config); session.addDownloadProgressListener(ProgressMode.INDEFINITELY, new ProgressListener() {

    @Override public void onChange(Progress progress) { showDownloadingChanges(!progress.isTransferComplete()); } });
  12. Realm Java 4.0ʹ޲͚ͯ my@realm.io

  13. master-4.0 ϒϥϯν my@realm.io • Realm Java 4.0Ͱఏڙ͞ΕΔඇޓ׵ͳมߋΛؚΉϒϥϯν • ౰໘͸ɺmaster͔Β3.x͕ɺmaster-4.0͔Β4.x͕ϦϦʔε͞ΕΔ༧ఆ •

    ͠͹Β͘͸̎όʔδϣϯΛฒߦͯ͠ϝϯςφϯε͍͖ͯ͠·͢ • snapshotϦϦʔε΋̎όʔδϣϯฒߦͯ͠ߦ͍·͢ • Breaking Change Wishlist for 4.0 (#4785)Ͱඇޓ׵มߋͷ༧ఆΛ؅ཧ • ͦΕͧΕͷϒϥϯνʹೖͬͨมߋ͸ɺҎԼͷΑ͏ʹࣗಈϚʔδ͞Ε·͢ releases → master → master-4.0
  14. Realm Java with Kotlin my@realm.io

  15. ηοτΞοϓ my@realm.io apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin:

    'kotlin-android-extensions' // RealmͷϓϥάΠϯ͕KotlinΛೝࣝͰ͖ΔΑ͏ʹɺKotlin pluginΑΓ΋ޙͰapply apply plugin: 'realm-android' android { ... } app/build.gradle
  16. Kotlinαϙʔτͱ͸ʁ • RealmͷΞϊςʔγϣϯϓϩηοαΛkapt configurationʹొ࿥ my@realm.io dependencies { annotationProcessor 'io.realm:realm-annotations-processor:3.4.0' }

    // ཁ͢Δʹ↑ͷ͔ΘΓʹ↓ dependencies { kapt 'io.realm:realm-annotations-processor:3.4.0' }
  17. KotlinͰͷϞσϧఆٛ open class User : RealmObject() { @PrimaryKey var id:

    Long = 0 var name: String = "" var description: Sting? = null } Or open class User( @PrimaryKey var id: Long = 0, var name: String = "", var description: String? = null ) : RealmObject() {} my@realm.io
  18. SAMม׵ͷ׆༻ realm.executeTransaction(new Realm.Transaction() { @Override public void execute(Realm realm) {

    final Person p = realm.createObject(Person.class); p.name = "Jane"; } }); realm.executeTransaction { val person = realm.createObject(Person::class.java) person.name = "Jane" } my@realm.io Java Kotlin
  19. useͰϦιʔε؅ཧ Realm.getDefaultInstance().use { it.executeTransaction { val person = realm.createObject(Person::class.java) person.name

    = "Jane" } } my@realm.io
  20. KClass༻ͷ֦ுؔ਺Λఆٛ fun <T : RealmModel> Realm.createObject(klass : KClass<T>) : T

    { return this.createObject(klass.java) } realm.executeTransaction { val person = realm.createObject(Person::class) person.name = "Jane" } my@realm.io
  21. KClass༻ͷ֦ுؔ਺Λఆٛ fun <T : RealmModel> Realm.where(klass : KClass<T>) : RealmQuery<T>

    { return this.where(klass.java) } val query = realm.where(Person::class) my@realm.io
  22. KProperty༻ͷ֦ுؔ਺Λఆٛ fun <T : RealmModel> RealmQuery<T>.equalTo(property : KProperty<Int?>, value: Int)

    : RealmQuery<T> { return this.equalTo(property.name, value) } fun <T : RealmModel> RealmQuery<T>.equalTo(property : KProperty<String?>, value: String) : RealmQuery<T> { return this.equalTo(property.name, value) } val persons = realm.where(Person::class).equalTo(Person::age, 25) val persons = realm.where(Person::class).equalTo(Person::age, "25") // Τϥʔ my@realm.io
  23. KProperty༻ͷ֦ுؔ਺Λఆٛ fun <T : RealmModel> RealmQuery<T>.group(body: RealmQuery<T>.() -> Unit) :

    RealmQuery<T> { beginGroup() body() return endGroup() } val persons = realm.where(Person::class) .group { equalTo(Person::age, 25).or().equalTo(Person::age, 30) } .beginsWith(Person::name, "J") my@realm.io
  24. Better Kotlin support (#4701) • RealmͷKotlinαϙʔτͷͨΊͷΞΠσΟΞืू • KClass, KPropertyΛαϙʔτ͢ΔͨΊͷ֦ுؔ਺ •

    @NotNull, @NullableΞϊςʔγϣϯ෇༩ʹΑΔ਌࿨ੑ޲্ • Ϟσϧఆٛʹ࢖ΘΕͨඇNullܕΛ@Requiredѻ͍ʹ my@realm.io Any idea?
  25. Ξϯέʔτͷճ౴Λ͓ئ͍͠·͢ jp@realm.io http://bit.ly/RealmJP_23