Project stORM: an ORM for SQLite

+David Chandler Android Developer Advocate http://turbomanage.com

Thursday, May 2, 13

simple template-based Object Relational Mapping

V E R P

W E I

Thursday, May 2, 13

13 .why hand-coded SQL. ugh SQLite already has obj-like wrappers - ContentValues (insert. May 2. update) Cursor (query) many apps just require a place to stuff some objects existing ORMs use reflection or require up-front modeling Thursday.

May 2. @Entity seamless code gen with JDT easy to debug minimal performance overhead Thursday. 13 .goals easy convention over configuration annotation-driven - @Database.

May 2. 13 .non-goals kitchen sink model all relations absolute max performance Thursday.

jar to libs/ 2. 13 . add storm-apt.setup 1. add storm-api.jar to annotation factory classpath Thursday. May 2.

annotate with @Database Create POJOs. May 2...use Extend DatabaseHelper.insert/get/query. annotate with @Entity Generates - DbFactory EntityTable EntityDao new EntityDao(ctx). Thursday. 13 .

eq(.listAll() dao. 13 .filter().eq(COL.listAllByExample(T exampleObj) dao.insertMany(Iterable<T> objs) T dao. val).deleteAll() List<T> dao.update(T obj) dao. May 2.insert(T obj) dao.get(long id) dao.use dao.exec() Thursday..).delete(long id) / dao..

13 long id (default) or annotate another field with @Id column name is _id (for CursorAdapter) .dao COLNAME == fieldName. May 2.conventions generated package names - +.toUpperCase() transient fields are not persisted id Thursday.db. +.

supported types all primitives & wrappers - boolean. 13 . byte[]. double. byte. enum. short. String byte[] have affinity BLOB boolean. float. May 2. byte. char. long. char have affinity INTEGER roll-your-own extend TypeConverter<J. int.S> annotate with @Converter Thursday.

getByExample(T obj) - throws TooManyResultsException insertMany uses 1 transaction column name enum in Table class - filter(). “David”). red squigglies from APT Thursday.nice List<T> dao.listByExample(T obj) T dao.. May 2.FIRSTNAME. 13 ..eq(Columns.

.. May 2. 13 .restore.csv dao.getDatabaseHelper(ctx) dbHelper.backupAllTablesToCsv() dbHelper.FromCsv() exact type conversions - blobs are Base64 encoded doubles saved as raw hex values file named dbName.vn.TableName+? Thursday.

upgrade() and/or override TableHelper.onUpgrade(.) for each .. 13 dropped cols disappear new cols get default values renaming not yet supported UPGRADE override DatabaseHelper.UpgradeStrategy DROP_CREATE BACKUP_RESTORE (csv) Thursday. May 2..

query(String where. May 2. 13 planned: .eq() Thursday. String[] args) .orderId could: orderDao.get() can’t compare doubles or blobs with FilterBuilder.items have: item.limits no relations (yet) - want: order.getItems() leaning toward Ref<Order>. val.eq(COL. delta) alt: dao.

13 . version singleton instance of DatabaseHelper getTableHelpers() Thursday. May 2.dbFactory static db name.

13 .dao extends SQLiteDao<T> - most of the code lives in the base class points to DatabaseFactory points to TableHelper Thursday. May 2.

May 2.table all SQL all getX() / bindX() Cursor --> obj --> ContentValues obj --> String[] (for csv) Thursday. 13 .

impl how to support incremental compilation? - anno processing happens in rounds full src not available in every round stormEnv file under . Project | Clean Freemarker templates in impl/src/res watch the Error Log view Thursday.apt_generated if in doubt. May 2. 13 .

@Id for custom id col @Column(name=”custom”) Thursday. May 2. 13 . etc.future limited relations (@Key. Ref<T>) more filter methods gt(). lt().

com Thursday.src storm-gen. 13 .googlecode. May 2.

Sign up to vote on this title
UsefulNot useful