Saving Data on Android



Download 19,28 Mb.
Pdf ko'rish
bet150/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   146   147   148   149   150   151   152   153   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

single transaction
. This is specially useful when you want to query multiple 
tables like in the case of your one to many relation between the 
questions
 table 
and the 
answers
 table.
3. Finally, you are creating a select statement to retrieve all the questions from your 
questions
 table. Notice that this method is returning a list of your 
QuestionAndAllAnswers
 class so Room will immediately take the answers 
associated with each question and store them inside the properties of your class.
And that's it! Those are all the DAO definitions you will need.
For this app, you won't be doing any updates to the data; therefore, you didn't use 
the 
@Update
 annotation. With 
@Update
, the implementation of the annotated 
method will simply update its parameters in the database if they already exist or 
wont create any if they don't. But since you're using the 
OnConflictStrategy.REPLACE
 when inserting data anyways, you have a way to 
update the data, after all.
Now, to provide the 
QuizDao
 for usage, you simply need to add a function to 
QuizDatabase
. Open up 
QuizDatabase.kt
, and add the following code within:
abstract
 
fun
 
quizDao
()
: QuizDao
Your code should now look like this:
@Database( 
    entities = [(Question::class)
, (Answer::
class
)], 
    
version = 1
 

abstract
 
class
 
QuizDatabase
 : 
RoomDatabase
() { 
 
    
abstract
 
fun
 
quizDao
()
: QuizDao 
}
Now, when you need to access the 
QuizDao
 and its functions, you simply have to 
retrieve it from the 
QuizDatabase
 instance you create on app startup.
Saving Data on Android
Chapter 8: The DAO Pattern
raywenderlich.com
136



Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   146   147   148   149   150   151   152   153   ...   292




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish