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

Realm Japan meetup #23_Java

zaki50
June 28, 2017

Realm Japan meetup #23_Java

zaki50

June 28, 2017
Tweet

More Decks by zaki50

Other Decks in Technology

Transcript

  1. ٯํ޲ͷؔ࿈ʹର͢ΔΫΤϦʔ [email protected] 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. ݱࡏͷಉظঢ়ଶΛऔಘ͢ΔAPI [email protected] public enum State { WAITING_FOR_ACCESS_TOKEN, // ΞΫηετʔΫϯऔಘத ACTIVE,

    // ΞΫηετʔΫϯ͋Γ DYING, // ϩάΞ΢τॲཧத INACTIVE, // ϩάΠϯલɺϩάΠϯޙ ERROR // Τϥʔ } SyncSession session = SyncManager.getSession(config); SyncState state = session.getState();
  3. ಉظͷਐḿΛड͚औΔϦεφʔ [email protected] 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. master-4.0 ϒϥϯν [email protected] • 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. ηοτΞοϓ [email protected] 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. 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() {} [email protected]
  7. 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" } [email protected] Java Kotlin
  8. 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" } [email protected]
  9. KClass༻ͷ֦ுؔ਺Λఆٛ fun <T : RealmModel> Realm.where(klass : KClass<T>) : RealmQuery<T>

    { return this.where(klass.java) } val query = realm.where(Person::class) [email protected]
  10. 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") // Τϥʔ [email protected]
  11. 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") [email protected]
  12. Better Kotlin support (#4701) • RealmͷKotlinαϙʔτͷͨΊͷΞΠσΟΞืू • KClass, KPropertyΛαϙʔτ͢ΔͨΊͷ֦ுؔ਺ •

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