Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
stORM preview               +David Chandler               Android Developer Advocate               http://turbomanage.comT...
simple         template-based         Object                                 I E W         Relational                     ...
why                    hand-coded SQL, ugh                    SQLite already has obj-like wrappers                   - Con...
goals                    easy                    convention over configuration                    annotation-driven       ...
non-goals                    kitchen sink                    model all relations                    absolute max performan...
setup             1. add storm-api.jar to libs/             2. add storm-apt.jar to annotation factory                clas...
use                    Extend DatabaseHelper, annotate with                    @Database                    POJOs implemen...
use                    dao.insert(T obj)                    dao.insertMany(Iterable<T> objs)                    T dao.get(...
conventions                    COLNAME == fieldName.toUpperCase()                    id                   - long id (requi...
supported types                    all primitives & wrappers                   - boolean, byte, byte[], char, double, enum...
nice                    List<T> dao.listByExample(T obj)                    T dao.getByExample(T obj)                   - ...
csv                    dao.getDatabaseHelper(ctx)                    dbHelper.backupAllTablesToCsv()                    db...
UpgradeStrategy                    DROP_CREATE                    BACKUP_RESTORE (csv)                   - dropped cols di...
limits                    no relations (yet)                    can’t compare doubles or blobs with                    Fil...
dbFactory                    static db name, version                    singleton instance of DatabaseHelper              ...
dao                    extends SQLiteDao<T>                   - most of the code lives in the base class                  ...
table                    all SQL                    all getX() / bindX()                    Cursor --> obj --> ContentValu...
impl                    how to support incremental                    compilation?                   -       anno processi...
future                    limited relations (@Key)                    more filter methods gt(), lt(), etc.                ...
src                           drfibonacci.googlecode.comTuesday, November 13, 12
native http                    Apache HttpClient                    HttpUrlConnection                    google-api-java-c...
basic-http-client                    just the basics                    sync api w/ smart error handling                  ...
src                           basic-http-client.googlecode.comTuesday, November 13, 12
R                    developer.android.com                    Common Tasks                    Google I/O sessions         ...
Nächste SlideShare
Wird geladen in …5
×

StORM preview

737 Aufrufe

Veröffentlicht am

Introducing a new ORM for Android SQLite.

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

StORM preview

  1. 1. stORM preview +David Chandler Android Developer Advocate http://turbomanage.comTuesday, November 13, 12
  2. 2. simple template-based Object I E W Relational R E V Mapping PTuesday, November 13, 12
  3. 3. why hand-coded SQL, ugh 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 modelingTuesday, November 13, 12
  4. 4. goals easy convention over configuration annotation-driven - @Database, @Entity - seamless code gen with JDT easy to debug minimal performance overheadTuesday, November 13, 12
  5. 5. non-goals kitchen sink model all relations absolute max performanceTuesday, November 13, 12
  6. 6. setup 1. add storm-api.jar to libs/ 2. add storm-apt.jar to annotation factory classpathTuesday, November 13, 12
  7. 7. use Extend DatabaseHelper, annotate with @Database POJOs implement Persistable, annotate with @Entity Generates - DbFactory - EntityTable - EntityDao new EntityDao(ctx).insert/get/query...Tuesday, November 13, 12
  8. 8. 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()Tuesday, November 13, 12
  9. 9. conventions COLNAME == fieldName.toUpperCase() id - long id (required) - column name is _IDTuesday, November 13, 12
  10. 10. 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 @ConverterTuesday, November 13, 12
  11. 11. 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 APTTuesday, November 13, 12
  12. 12. csv dao.getDatabaseHelper(ctx) dbHelper.backupAllTablesToCsv() dbHelper.restore...FromCsv() exact type conversions - blobs are Base64 encoded - doubles saved as raw hex values file named dbName.vn.TableNameTuesday, November 13, 12
  13. 13. UpgradeStrategy DROP_CREATE BACKUP_RESTORE (csv) - dropped cols disappear - new cols get default values - renaming not yet supported UPGRADE - override DatabaseHelper.upgrade() and/or - override TableHelper.onUpgrade(...) for eachTuesday, November 13, 12
  14. 14. limits no relations (yet) can’t compare doubles or blobs with FilterBuilder.eq() - likely add .eq(COL, val, delta) - or dao.query(String where, String[] args)Tuesday, November 13, 12
  15. 15. dbFactory static db name, version singleton instance of DatabaseHelper getTableHelpers()Tuesday, November 13, 12
  16. 16. dao extends SQLiteDao<T> - most of the code lives in the base class points to DatabaseFactory points to TableHelperTuesday, November 13, 12
  17. 17. table all SQL all getX() / bindX() Cursor --> obj --> ContentValues obj --> String[] (for csv)Tuesday, November 13, 12
  18. 18. impl how to support incremental compilation? - anno processing happens in rounds - full src not available in every round - stormEnv file under .apt_generated - TypeConverters aren’t there yet - if in doubt, Project | Clean Freemarker templates in impl/src/res watch the Error Log viewTuesday, November 13, 12
  19. 19. future limited relations (@Key) more filter methods gt(), lt(), etc. @Id for custom id col @Column(name=”custom”) part of ADT?Tuesday, November 13, 12
  20. 20. src drfibonacci.googlecode.comTuesday, November 13, 12
  21. 21. native http Apache HttpClient HttpUrlConnection google-api-java-client google-http-java-client basic-http-clientTuesday, November 13, 12
  22. 22. basic-http-client just the basics sync api w/ smart error handling async api - automatically wraps in AsyncTask - auto retry / backoff extensible - RequestLogger - RequestHandlerTuesday, November 13, 12
  23. 23. src basic-http-client.googlecode.comTuesday, November 13, 12
  24. 24. R developer.android.com Common Tasks Google I/O sessions +Android Developers turbomanage.com (my blog)Tuesday, November 13, 12

×