Java輕量級ORM持久層框架:ORMLite

jopen 13年前發布 | 50K 次閱讀 ORM 持久層框架

ORMLite是一個輕量級的Java對象關系映射持久層框架。支持包括 MySQL、Postgres、Microsoft SQL Server、H2、Derby、HSQLDB和Sqlite等在內的數據庫。提供靈活的QueryBuilder來構建復雜的數據查詢。強大的抽象 DAO類,只需5行代碼便能夠自動生成SQL來創建和刪除數據庫表格。
RMLite易于使用并提供了以下特性:

  • 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.
  • Supports native calls to Android SQLite database APIs

示例代碼:

public class AccountApp {

    public static void main(String[] args) throws Exception {

        // this uses h2 by default but change to match your database

        String databaseUrl = "jdbc:h2:mem:account";

        // create a connection source to our database

        ConnectionSource connectionSource = new JdbcConnectionSource(databaseUrl);

        // instantiate the dao

        AccountDaoImpl accountDao = new AccountDaoImpl(connectionSource);

        // if you need to create the 'accounts' table make this call

        TableUtils.createTable(connectionSource, Account.class);

項目主頁:http://www.baiduhome.net/lib/view/home/1357891151200

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!