Slide 1

Slide 1 text

Realm meetup #23 [email protected]

Slide 2

Slide 2 text

#realm_jp [email protected]

Slide 3

Slide 3 text

Makoto Yamazaki Realm Inc. / uPhyca Inc. [email protected]

Slide 4

Slide 4 text

Recent Updates [email protected]

Slide 5

Slide 5 text

Realm Java 3.4.0 (was 3.3.1) [email protected]

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

ٯํ޲ͷؔ࿈ʹର͢ΔΫΤϦʔ [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ΛϦϯΫΫΤϦʔͰར༻Մೳ

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Realm Java 4.0ʹ޲͚ͯ [email protected]

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Realm Java with Kotlin [email protected]

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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' }

Slide 17

Slide 17 text

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]

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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]

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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]

Slide 23

Slide 23 text

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]

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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