QuickDAO 4.0 released, Java ORM framework

QuickDAO4.0 version is officially released. Compared to version 3.0, the architecture has been redesigned, the code structure is clearer, and the external interface has not changed much. If you are a user of version 3.0, you can see the migration tutorial on the homepage of QuickDAO3.0 warehouse.

QuickDAO4

QuickDAO is a simple, easy-to-use and convenient Java ORM framework. It has the following advantages:

  • Only need to inject a DAO to complete the initialization operation
  • Automatic table creation, automatic new database fields
  • API level supports foreign key related queries, and supports complex foreign key related queries
  • Built-in database dialect support
  • Entity class annotations, support custom field names, types, whether to create an index, and establish foreign key associations

Support database

  • MySQL (above 5.0)
  • SQLite
  • H2
  • Postgre (9.0.0 and above)
  • SQL Server (2012 version and above)

Quick start

1 Import QuickDAO

QuickDAO is based on JDBC. To improve efficiency, it only supports database connection pools by default.

  • Import commons-dbcp (or other DataSource implementation)
  • Import the latest version of QuickDAO
<dependency>  
<groupId>commons-dbcp</groupId>  
<artifactId>commons-dbcp</artifactId>  
<version>1.4</version>  
</dependency>  
<dependency>  
<groupId>cn.schoolwow</groupId>  
<artifactId>QuickDAO</artifactId>  
<version>4.0</version>  
</dependency>  

2 Configure QuickDAO

BasicDataSource mysqlDataSource = new BasicDataSource();  
mysqlDataSource.setDriverClassName("com.mysql.jdbc.Driver");  
mysqlDataSource.setUrl("jdbc:mysql://127.0.0.1:3306/quickdao");  
mysqlDataSource.setUsername("root");  
mysqlDataSource.setPassword("123456");  
//指定实体所在包名  
cn.schoolwow.quickdao.dao.DAO dao = QuickDAO.newInstance()  
.dataSource(mysqlDataSource)  
.packageName("cn.schoolwow.quickdao.entity")  
.build();  
//之后所有的操作使用dao对象完成  

3 use QuickDAO

  • Query by id

User user = dao.fetch(User.class,1);

  • Query based on a single attribute

User user = dao.fetch(User.class,"username","quickdao");

  • Insert object

dao.insert(user);

  • Update object

dao.update(user);

  • Save the object (update if it exists, insert if it doesn't exist)

dao.save(user);

  • Delete according to id

dao.delete(User.class,1);

  • Delete based on attribute value

dao.delete(User.class,"username","quickdao");

  • Complex query
List<User> userList = dao.query(User.class)  
.addQuery("name","quickdao")  
.addNotNullQuery("password")  
.page(1,10)  
.orderBy("id")  
.execute()  
.getList();  
  • Foreign key association query
List<User> userList = dao.query(User.class)  
.joinTable(Address.class,"addressId","id")  
.addQuery("name","BeiJing")  
.done()  
.addQuery("name","quickdao")  
.page(1,10)  
.orderBy("id")  
.compositField()  
.execute()  
.getList();  

Detailed documentation

Click here to visit

Guess you like

Origin www.oschina.net/news/124850/quickdao-4-0-released