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. 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ΛϦϯΫΫΤϦʔͰར༻Մೳ
  2. 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();
  3. 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()); } } });
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 24.

    Better Kotlin support (#4701) • RealmͷKotlinαϙʔτͷͨΊͷΞΠσΟΞืू • KClass, KPropertyΛαϙʔτ͢ΔͨΊͷ֦ுؔ਺ •

    @NotNull, @NullableΞϊςʔγϣϯ෇༩ʹΑΔ਌࿨ੑ޲্ • Ϟσϧఆٛʹ࢖ΘΕͨඇNullܕΛ@Requiredѻ͍ʹ my@realm.io Any idea?