Saving Data on Android



Download 19,28 Mb.
Pdf ko'rish
bet109/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   105   106   107   108   109   110   111   112   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

Object Rela/onal Mappers
Before using Room properly in your projects, you first need to learn what Room is.
Room is a data persistence library commonly known as 
O
bject 
R
elational 
M
apper or 
ORM
. ORMs are tools that allow you to retrieve, delete, save and update the contents 
of a relational database using the programming language of your choice.
ORMs are implemented as libraries or frameworks that provide an additional layer of 
abstraction called the data layer which allows you to better interact with your 
database using a syntax similar to the object-oriented world.
To better understand how ORMs work, imagine that you have a 
Movie
 class with 
three properties: An 
id
, a 
name
 and a 
release_date
.
This is a class diagram that represents the 
Movie
 class. Just like most object-oriented 
languages, each of these properties has a certain data type such as 
Int

String
 or 
Date
With the help of an ORM, this 
Movie
 class can easily be used to create a new table in 
your database. In an ORM, classes represent a table inside your database and each 
property a column. For example, our previous 
Movie
 class would be translated into a 
table like this:
Each of the columns would also have the data type that best represents the original 
data type of the original property. For example, a 
String
 would be translated as a 
varchar
 and an 
Integer
 as an 
Int
.
Saving Data on Android
Chapter 5: Room Architecture
raywenderlich.com
93


The way to create new records inside the tables differs from each implementation. 
For instance, some ORMs automatically create new entries each time a new instance 
of the class is created. Other ORMs such as Room use Data Access Objects or DAOs to 
query your tables.
This is a simple example of how you would use a DAO in Room to create new 
Movie
 
records in the previously mentioned table:
movieDao.insert(Movie(
1

"Harry Potter"

"10-11-05"
)) 
movieDao.insert(Movie(
2

"The Simpsons"

"03-10-02"
)) 
movieDao.insert(Movie(
3

"Avengers"

"08-01-10"
))
And your table now look like this:
Easy, right?
Note
: Room can autogenerate the primary key, in this case, 
ID
. You will learn 
how to do that in a later chapter.
Now, let's take a look at how Room and Google's architecture components work and 
interact with each other.

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   105   106   107   108   109   110   111   112   ...   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