Академический Документы
Профессиональный Документы
Культура Документы
Thursday, May 2, 13
V E R P
W E I
Thursday, May 2, 13
why
hand-coded SQL, ugh SQLite already has obj-like wrappers
many apps just require a place to stuff some objects existing ORMs use reflection or require up-front modeling
Thursday, May 2, 13
goals
easy convention over configuration annotation-driven
Thursday, May 2, 13
non-goals
kitchen sink model all relations absolute max performance
Thursday, May 2, 13
setup
1. add storm-api.jar to libs/ 2. add storm-apt.jar to annotation factory classpath
Thursday, May 2, 13
use
Extend DatabaseHelper, annotate with @Database Create POJOs, annotate with @Entity Generates
new EntityDao(ctx).insert/get/query...
Thursday, May 2, 13
use
dao.insert(T obj) dao.insertMany(Iterable<T> objs) T dao.get(long id) dao.update(T obj) dao.delete(long id) / dao.deleteAll() List<T> dao.listAll() dao.listAllByExample(T exampleObj) dao.filter().eq(COL, val).eq(...).exec()
Thursday, May 2, 13
conventions
generated package names
+.db, +.dao
Thursday, May 2, 13
long id (default) or annotate another field with @Id column name is _id (for CursorAdapter)
supported types
all primitives & wrappers
boolean, byte, byte[], char, double, enum, float, int, long, short, String byte[] have affinity BLOB boolean, byte, char have affinity INTEGER
roll-your-own
extend TypeConverter<J,S> annotate with @Converter
Thursday, May 2, 13
nice
List<T> dao.listByExample(T obj) T dao.getByExample(T obj)
throws TooManyResultsException
filter().eq(Columns.FIRSTNAME, David)...
Thursday, May 2, 13
csv
dao.getDatabaseHelper(ctx) dbHelper.backupAllTablesToCsv() dbHelper.restore...FromCsv() exact type conversions
Thursday, May 2, 13
UpgradeStrategy
DROP_CREATE BACKUP_RESTORE (csv)
Thursday, May 2, 13
dropped cols disappear new cols get default values renaming not yet supported
UPGRADE
override DatabaseHelper.upgrade() and/or override TableHelper.onUpgrade(...) for each
limits
no relations (yet)
Thursday, May 2, 13
dbFactory
static db name, version singleton instance of DatabaseHelper getTableHelpers()
Thursday, May 2, 13
dao
extends SQLiteDao<T>
Thursday, May 2, 13
table
all SQL all getX() / bindX() Cursor --> obj --> ContentValues obj --> String[] (for csv)
Thursday, May 2, 13
impl
how to support incremental compilation?
anno processing happens in rounds full src not available in every round stormEnv file under .apt_generated if in doubt, Project | Clean
Thursday, May 2, 13
future
limited relations (@Key, Ref<T>) more filter methods gt(), lt(), etc. @Id for custom id col @Column(name=custom)
Thursday, May 2, 13
src
storm-gen.googlecode.com
Thursday, May 2, 13