Project stORM is an ORM library for SQLite on Android that aims to provide an easy and convention-based way to map objects to database tables. It uses annotation processing to generate database helper classes and data access objects (DAOs) that allow storing and querying objects with minimal boilerplate code or performance overhead. The library supports basic CRUD operations on objects as well as filtering and sorting but does not currently support object relationships or complex queries.
4. why
SQLite already has obj-like wrappers
- ContentValues (insert, update)
- Cursor (query)
many apps just require a place to stuff
some objects
existing ORMs use reflection or require
up-front modeling
9. use
Extend DatabaseHelper, annotate with
@Database
Create POJOs, annotate with @Entity
Generates
- DbFactory
- EntityTable
- EntityDao
new EntityDao(ctx).insert/get/query...
10. use (like Objectify)
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() or load().list()
dao.listAllByExample(T exampleObj)
dao.load().eq(COL, val).eq(...).exec()
11. conventions
generated package names
- +.db, +.dao
COLNAME ==
fieldName.toUpperCase()
transient fields are not persisted
id
- long id (default)
- or annotate another field with @Id
- column name is _id (for CursorAdapter)
12. 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
13. nice
List<T> dao.listByExample(T obj)
T dao.getByExample(T obj)
- throws TooManyResultsException
insertMany uses 1 transaction
column name enum in Table class
- filter().eq(Columns.FIRSTNAME, “David”)...
red squigglies from APT
21. impl
how to support incremental
compilation?
- anno processing happens in rounds
- full src not available in every round
- stormEnv file under .apt_generated (ADT)
- or build/generated/apt/debug (AS)
- if in doubt, del stormEnv & Project | Clean
Freemarker templates in impl/src/res
watch the Error Log view
22. working with APT
Start gradle daemon
Connect a remote debugger to it
Initiate your build (including APT
processing)
In IntelliJ, use Rebuild to force APT run
http://turbomanage.wordpress.com/
2014/06/09/debug-an-annotation-
processor-with-intellij-and-gradle/
27. R
androidannotations.org
Mark Murphy’s Busy Coder’s Guide to
Android Development
Google I/O sessions
+Android Developers
turbomanage.com (my blog)
google.com/+DavidMichaelChandler
square.github.com (event bus, DI, etc.)