OrmLite - Lightweight Java ORM Supports Android and SQLite

OrmLite - Lightweight Java ORM Supports Android and SQLite

Object Relational Mapping Lite (ORM Lite) provides some lightweight functionality for persisting Java objects to SQL databases while avoiding the complexity and overhead of more standard ORM packages. It supports a number of SQL databases using JDBC and also supports Sqlite with native calls to Android OS database APIs. Documentation about how to configure ORMLite for Android specifically is available in the manual.

Please contact me with any feedback or questions about Android support. See the home page for more details.

  • ORMLite home page
  • Collection of example projects and classes for Android developers
  • Download files: local repository central maven repository SourceForge files
  • Documentation:
    • Getting Started HTML PDF
    • Javadocs: core jdbc android
    • Code Examples
    • Change log file
    • Open source license (ISC)
    • SQL Data Types
  • Support:
    • Google Groups mailing lists: users android users developers
    • Bug tracking site
    • Stackoverflow questions
    • SourceForge project page
  • Source control (SVN): core (browse) jdbc (browse) android (browse)

ORMLite provides the following features:

  • Setup your classes by simply adding Java annotations.
  • Powerful abstract Database Access Object (DAO) classes.
  • Flexible QueryBuilder to easily construct simple and complex queries.
  • Supports MySQL, Postgres, Microsoft SQL Server, H2, Derby, HSQLDB, and Sqlite and can be extended to additional databases relatively easily.
  • Provisional support for DB2, Oracle, ODBC, and Netezza. Contact the author if your database type is not supported.
  • Handles "compiled" SQL statements for repetitive query tasks.
  • Supports "foreign" objects with the class field being the object but an id stored in the database table.
  • Basic support for database transactions.
  • Auto generates SQL to create and drop database tables.
  • Spring configuration support for DOAs and class configurations.
  • Support for configuring of tables and fields without annotations.

Use Annotations to Mark Classes to be Persisted

To use the package you add the @DatabaseTable annotation to the top of each class and a @DatabaseField annotation to each of the fields in the class that are to be persisted to the database. For example:

@DatabaseTable(tableName = "accounts") public class Account { @DatabaseField(id = true) private String name; @DatabaseField(canBeNull = false) private String password; ... Account() { // all persisted classes must define a no-arg constructor with at least package visibility } ... }

Classes can also be configured with javax.persistence annotations, Java calls, or Spring wiring. For more details, see the online documentation.

Sample Code Example

The ORMLite Android code includes base activity, service, and tab classes to help create and manage your database connections and DAOs. The following is a quick code example to give you a taste on how to use the package.

// you get the SQLiteOpenHelper from your Android Activity ConnectionSource connectionSource = new AndroidConnectionSource(sqliteOpenHelper); // instantiate the DAO to handle Account with String id Dao<Account,String> accountDao = BaseDaoImpl.createDao(connectionSource, Account.class); // if you need to create the 'accounts' table make this call TableUtils.createTable(connectionSource, Account.class); // create an instance of Account String name = "Jim Smith"; Account account = new Account(name, "_secret"); // persist the account object to the database // it should return 1 for the 1 row inserted if (accountDao.create(account) != 1) { throw new Exception("Failure adding account"); } // retrieve the account Account account2 = accountDao.queryForId(name); // show its password System.out.println("Account: " + account2.getPassword()); // close the connection source connectionSource.close();

This web page and associated content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.
This page should be W3C Valid XHTML and should work with most browsers.
http://ormlite.com/sqlite_java_android_orm.shtml

FreeSpamProtection ORMLite Java ORM Android ORM EV For Sale, Lexington, MA Thornburgh 80th Birthday Event

Your host: (none) 114.112.45.175:30944

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)中解决Viewpage调用notifyD
  2. 发现自己喜欢了移动端开发--Android
  3. Android之预览PDF文件
  4. 如何通过日志来调试Web App
  5. Android 官方命令深入分析
  6. 2.2.3帧布局
  7. Android(安卓)studio如何指定使用自己生
  8. android面试题(一)
  9. Android屏幕适配;知识点+攻略+面试要点
  10. android 使用crt/cer/pem格式的公钥证书