+ All Categories
Home > Software > FiiPractic 2015 - Adroid Pro - Day 5 - SQL Day

FiiPractic 2015 - Adroid Pro - Day 5 - SQL Day

Date post: 13-Jan-2017
Category:
Upload: diaconu-andrei-tudor
View: 111 times
Download: 2 times
Share this document with a friend
21
Android Pro SQL Day
Transcript

Android ProSQL Day

– Test Android

“Avem o aplicatie de TODO si vrem sa persistam datele. Cum preferi sa faci acest

lucru?”

Helper extend SQLiteOpenHelper - creaza baza de date - migreaza baza de date - getWritableDatabase - getReadableDatabase

SQLiteDatabase - operatii CRUD - insert() - query() - update() - delete() - …

DataSource - metode specializate aplicate pe SQLiteDatabase - folosit in activitate

Google “Vogella SQL Tutorial”

Alternative?

ORMLite

- Java, nu numai Android - Adnotari - Boilerplate - Foarte permisiv

Helper extends OrmLiteSqliteOpenHelper - creare si migrare - TableUtils.createTable - TableUtils.dropTable

//connectionSourcenew AndroidConnectionSource(sqliteOpenHelper);

//toDoDaoBaseDaoImpl.createDao(connectionSource, ToDo.class);

//List<ToDo>List<ToDo> toDo = toDoDao.queryForAll(name);

@DatabaseTable(tableName = "todos")class ToDo{ @DatabaseField(canBeNull = false) private String text;}

Google “ORMLite Sample”. Este foarte mult boilerplate pe care nu aveti cum sa il invatati altfel

greenDAO

- Cod generat - Scriem cod pentru codul generat - Foarte rapid - Boilerplate

Generam cod

Schema schema = new Schema(1, “my.name.space”);Entity todos = schema.addEntity("Project");todos.addStringProperty(“text").notNull();

new DaoGenerator().generateAll(schema, "../../../Example/src-gen")

DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "todos-db", null);

db = helper.getWritableDatabase();daoMaster = new DaoMaster(db);daoSession = daoMaster.newSession();todoDao = daoSession.getNoteDao();

…todoDao.insert(todo);

sugarORM

- fara boilerplate - relatii automate - extrem de simplu - Application + Manifest

public class ToDo extends SugarRecord<ToDo> { String text;

public ToDo() { }

public ToDo(String text) { this.text = text; }}

ToDo unu = new ToDo(context, “unu”);unu.save();

Alte optiuni, poate chiar mai bune

- ActiveAndroid - Ollie - Realm - Schematic

Work

Daca folositi SQL pe Android pentru prima oara, folositi SQL normal, fara nimic. Va ajuta sa intelegeti.

Level 1: - Aplicatie de TODO cu ADD, REMOVE.

Level 2: - Adaptorul listei sa utilizeze un cursor

Level 3: - Faceti o legatura one-to-many intre todo si persoane. Un todo

poate avea mai multe persoane. - Sa nu aveti nimic costisitor pe threadul UI

Realm special: Faceti ca interogarile sa se intample pe alt thread.


Recommended