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. Makoto Yamazaki
    Realm Inc. / uPhyca Inc.
    [email protected]

    View full-size slide

  2. Realm Java 3.4.0
    (was 3.3.1)
    [email protected]

    View full-size slide

  3. 3.4·Ͱόάमਖ਼(RMD)
    • setRequired()Ͱbyte[]ܕͷϑΟʔϧυΛnon-nullʹมߋ͢Δࡍɺbyte[0]ʹม׵͞
    ΕΔ΂͖΋ͷ͕byte[1]ʹͳ͍ͬͯͨόάΛमਖ਼
    • ϓϥΠϚϦΩʔʹࢦఆ͞Ε͍ͯΔϑΟʔϧυʹରͯ͠setRequired()Ͱnon-nullʹ
    มߋ͢ΔࡍɺnullͷϑΟʔϧυ͕ଘࡏͨ͠Βྫ֎Λεϩʔ͢ΔΑ͏ʹमਖ਼
    • ೝূΤϥʔൃੜ࣌ʹΫϥογϡ͢ΔόάΛमਖ਼(#4726)
    • αʔόʔಉظ༗ޮ࣌Ͱ΋ɺϩʔΧϧͷσʔλϕʔεͷ҉߸ԽʹରԠ(#4561)
    • AdminϢʔβʔ͕αʔόʔʹ઀ଓͰ͖ͳ͍όάΛमਖ਼(#4750)
    • αʔόʔ઀ଓʹࣦഊͨ͠ͱ͖ʹਖ਼͘͠ϦτϥΠ͞Εͳ͍όάΛमਖ਼(#4750)
    [email protected]

    View full-size slide

  4. Realm Java 3.4৽ػೳ
    • ΫΤϦʔதͰͷٯํ޲ͷؔ࿈Λαϙʔτͱਖ਼ࣜAPI΁ͷঢ֨⭐
    • ಉظͷਐḿঢ়گͷ௨஌Λड͚औΔAPIΛ௥Ճ(#4104) ⭐
    • ݱࡏͷಉظঢ়ଶΛऔಘ͢ΔAPIΛ௥Ճ⭐
    • Realm.getDefaultConfiguration()ͷ௥Ճ
    • RealmSchema.close()ͱRealmObjectSchema.close() Λ deprecated
    [email protected]

    View full-size slide

  5. ٯํ޲ͷؔ࿈ʹର͢ΔΫΤϦʔ
    [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 owners;

    }
    Person owner;
    owner = realm.where(Dog.class).equalTo("owners.name", "Jane").findFirst;
    ͜ͷΦϒδΣΫτΛdogϑΟʔϧυ͔Β
    ࢀর͍ͯ͠ΔશͯͷPersonΦϒδΣΫτ
    ownersΛϦϯΫΫΤϦʔͰར༻Մೳ

    View full-size slide

  6. ݱࡏͷಉظঢ়ଶΛऔಘ͢ΔAPI
    [email protected]
    public enum State {
    WAITING_FOR_ACCESS_TOKEN, // ΞΫηετʔΫϯऔಘத
    ACTIVE, // ΞΫηετʔΫϯ͋Γ
    DYING, // ϩάΞ΢τॲཧத
    INACTIVE, // ϩάΠϯલɺϩάΠϯޙ
    ERROR // Τϥʔ
    }
    SyncSession session = SyncManager.getSession(config);
    SyncState state = session.getState();

    View full-size slide

  7. ಉظͷਐḿΛड͚औΔϦεφʔ
    [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());
    }
    }
    });

    View full-size slide

  8. ಉظͷਐḿΛड͚औΔϦεφʔ
    [email protected]
    SyncSession session = SyncManager.getSession(config);
    session.addDownloadProgressListener(ProgressMode.INDEFINITELY,
    new ProgressListener() {
    @Override
    public void onChange(Progress progress) {
    showDownloadingChanges(!progress.isTransferComplete());
    }
    });

    View full-size slide

  9. 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

    View full-size slide

  10. ηοτΞοϓ
    [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

    View full-size slide

  11. Kotlinαϙʔτͱ͸ʁ
    • RealmͷΞϊςʔγϣϯϓϩηοαΛkapt configurationʹొ࿥
    [email protected]
    dependencies {
    annotationProcessor 'io.realm:realm-annotations-processor:3.4.0'
    }
    // ཁ͢Δʹ↑ͷ͔ΘΓʹ↓
    dependencies {
    kapt 'io.realm:realm-annotations-processor:3.4.0'
    }

    View full-size slide

  12. 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]

    View full-size slide

  13. 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

    View full-size slide

  14. useͰϦιʔε؅ཧ
    Realm.getDefaultInstance().use {
    it.executeTransaction {
    val person = realm.createObject(Person::class.java)
    person.name = "Jane"
    }
    }
    [email protected]

    View full-size slide

  15. KClass༻ͷ֦ுؔ਺Λఆٛ
    fun Realm.createObject(klass : KClass) : T {
    return this.createObject(klass.java)
    }
    realm.executeTransaction {
    val person = realm.createObject(Person::class)
    person.name = "Jane"
    }
    [email protected]

    View full-size slide

  16. KClass༻ͷ֦ுؔ਺Λఆٛ
    fun Realm.where(klass : KClass) : RealmQuery {
    return this.where(klass.java)
    }
    val query = realm.where(Person::class)
    [email protected]

    View full-size slide

  17. KProperty༻ͷ֦ுؔ਺Λఆٛ
    fun RealmQuery.equalTo(property : KProperty,
    value: Int) : RealmQuery {
    return this.equalTo(property.name, value)
    }
    fun RealmQuery.equalTo(property : KProperty,
    value: String) : RealmQuery {
    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]

    View full-size slide

  18. KProperty༻ͷ֦ுؔ਺Λఆٛ
    fun RealmQuery.group(body: RealmQuery.() -> Unit)
    : RealmQuery {
    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]

    View full-size slide

  19. Better Kotlin support (#4701)
    • RealmͷKotlinαϙʔτͷͨΊͷΞΠσΟΞืू
    • KClass, KPropertyΛαϙʔτ͢ΔͨΊͷ֦ுؔ਺
    • @NotNull, @NullableΞϊςʔγϣϯ෇༩ʹΑΔ਌࿨ੑ޲্
    • Ϟσϧఆٛʹ࢖ΘΕͨඇNullܕΛ@Requiredѻ͍ʹ
    [email protected]
    Any idea?

    View full-size slide

  20. Ξϯέʔτͷճ౴Λ͓ئ͍͠·͢
    [email protected]
    http://bit.ly/RealmJP_23

    View full-size slide