Slide 1

Slide 1 text

Room2.1 DatabaseView ͋Δ͋Δ ͋Δ͋ΔLTʙ ͓ਖ਼݄ͩΑʂAndroid & iOS߹ಉ େLTେձ ʙ Vol.10

Slide 2

Slide 2 text

ࣗݾ঺հ • Koji Wakamiya • Studyplus, inc. • @koji-1009 (Github) • @D_R_1009 (Twitter, Hatena, etc…)

Slide 3

Slide 3 text

DatabaseView ࢖ͬͯ·͔͢ʁ

Slide 4

Slide 4 text

DatabaseViewʹ͍ͭͯʢ͓͞Β͍ʣ • Room 2.1Ͱ௥Ճ͞Εͨػೳ • Inner/Outer joinΛRoomͰ࣮ݱ • ςʔϒϧΛ͋Δ΂͖ܗʹ෼ׂ͠ දࣔ(View)ʹ߹ΘͤͯσʔλΛ߹੒͢Δ͜ͱ͕Ͱ͖Δ

Slide 5

Slide 5 text

ෳ਺ͷςʔϒϧͱForeignKey • ؔ࿈ͷ͋Δෳ਺ͷςʔϒϧΛѻ͏͜ͱʹͳΔͨΊ ForeignKeyΛར༻͢Δ͜ͱ͕͋Δ • ؔ࿈෇͚Λߦ͏͜ͱͰɺத৺ͱͳΔrowΛ࡟আͨ࣌͠ʹ ଞͷςʔϒϧͷrow΋࡟আ͢ΔͳͲͷߟྀΛߦ͏

Slide 6

Slide 6 text

OnConflictStrategy.REPLACEͰ σʔλ͕ফ͑ͪΌ͏ࣄ݅

Slide 7

Slide 7 text

OnConflictStrategy • InsetॲཧதʹConflict͕ൃੜ(row͕طʹଘࡏ)ͨ࣌͠ ͲͷΑ͏ͳѻ͍Λ͢Δ͔ΛܾΊΔ͜ͱ͕Ͱ͖Δ • DBͷར༻༻్΍໨తʹ߹Θͤͯར༻͢ΔStrategy͕มΘΔ

Slide 8

Slide 8 text

OnConflictStrategy • ABORT (default) • OnConflict strategy constant to abort the transaction. • REPLACE • OnConflict strategy constant to replace the old data and continue the transaction. • Ignore • OnConflict strategy constant to ignore the conflict.

Slide 9

Slide 9 text

ࣄ݅ঢ়گ • ΞΠςϜςʔϒϧͱΞΠςϜฒͼॱςʔϒϧ͕ଘࡏ • ΞΠςϜ͸ΞϓϦىಈ࣌ʹαʔόʔͱಉظ • @InsertͱOnConflictStrategy.REPLACEͰશσʔλߋ৽ • ฒͼॱͷσʔλ͸ΞϓϦ಺ʹ͔͠ଘࡏ͠ͳ͍ͨΊอ࣋

Slide 10

Slide 10 text

ࣄ݅ঢ়گ • αʔόʔͱΞϓϦ಺DBΛಉظ(ϦϑϨογϡ)͢Δͱ ΞΠςϜϦετ͕දࣔ͞Εͳ͘ͳΔ • ௐ΂ͯΈΔͱʮΞΠςϜʯͷσʔλ͸͋Δ͕ ʮΞΠςϜฒͼॱʯ͕ଘࡏ͠ͳ͘ͳ͍ͬͯΔ • Inner JoinͷͨΊDatabaseView͕ੜ੒͞Ε͍ͯͳ͍……ʁ

Slide 11

Slide 11 text

Ͳ͏ͯ͠σʔλফ͑ͪΌ͏Μ……

Slide 12

Slide 12 text

REPLACEʹΑΔUpdateॲཧ • REPLACE͸࣮࣭తʹUpdateॲཧʢͩͱࢥ͍ͬͯͨʣ • Conflictൃੜ͠ͳ͍ → ৽نrow࡞੒ॲཧ • Conflictൃੜ͢Δ → طଘrowߋ৽ॲཧ

Slide 13

Slide 13 text

REPLACEʹΑΔUpdateॲཧ • REPLACE͸࣮࣭తʹUpdateॲཧʢͰ͸ͳ͍ʣ • Conflictൃੜ͠ͳ͍ → ৽نrow࡞੒ॲཧ • Conflictൃੜ͢Δ → طଘrowߋ৽ॲཧ طଘrow࡟আॲཧ + ৽نrow௥Ճॲཧ

Slide 14

Slide 14 text

REPLACEʹΑΔUpdateॲཧ • طଘrowͷ࡟আ + ForeignKeyʹΑΔؔ࿈෇͚ʹΑΓ ʮΞΠςϜʯͷ࡟আͰʮΞΠςϜฒͼॱʯ͕࡟আ͞Ε͍ͯͨ • @InsertͰ͸ͳ͘@UpdateΛར༻͠ͳ͚Ε͹ͳΒͳ͔ͬͨ • ௥Ճͱߋ৽ॲཧΛϝιουͰ੾Γ෼͚Δ͜ͱͰ ͜ͱͳ͖ΛಘΔ͜ͱ͕Ͱ͖ͨ

Slide 15

Slide 15 text

υΩϡϝϯτ͸ͪΌΜͱಡΉ ʢ͋ͱɺԣண͠ͳ͍ʣ

Slide 16

Slide 16 text

Thanks!