DoytoQuery - The best and the last ORM framework in Java.
Introduction
DoytoQuery is a powerful and easy-to-use ORM framework in Java. It comes out from an idea which is mapping a query object directly to a WHERE clause in SQL to query database. With the development of DoytoQuery, the idea formed a new ORM theory.
The Modern ORM Theory
- We can define a query object mapping query statements.
- For SQL, see QueryBuilderTest
- For MongoDB, see MongoFilterBuilderTest
- We can define an entity object and cooperate with the query object to complete the CRUD operations of single-table.
- For SQL, see CrudBuilderTest
- For MongoDB, see MongoDataAccessTest
- Data Manipulation Language can be classified into three categories, corresponding to three different interfaces:
- CRUD for business tables: DataAccess
- CRD for association tables: AssociationService
- Aggregate/Relational query: DataQueryClient
Features
- Data Access Layer
- CRUD operations for single/sharding table.
- CRD operations for associative table.
- Query with related entities and views.
- Service Layer
- CRUD methods.
- Second-Level Cache.
- UserId Injection.
- EntityAspect Extensions.
- Controller Layer
- Support RESTFul API.
- ErrorCode Pre-definition.
- Exception Assertion.
- Exception Handler.
- JsonResponse Wrapper.
- Request/Entity/Response Transition.
- Group Validation.
- Seamless integration with Spring WebMvc.
- Support for relational databases and MongoDB.
Quick Usage
For a UserEntity
defined as follows:
@Getter
@Setter
@Entity(name = "user")
public class UserEntity extends AbstractPersistable<Long> {
private String username;
private String email;
private Boolean valid;
}
we can define a query object to query data from database as follows:
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class UserQuery extends PageQuery {
private String username;
private String emailLike;
private Boolean valid;
}
and invoke the DataAccess#query(Q)
method like this:
@Service
public class UserService extends AbstractCrudService<UserEntity, Long, UserQuery> {
public List<UserEntity> findValidGmailUsers() {
UserQuery userQuery = UserQuery.builder().emailLike("@gmail.com").valid(true).pageSize(10).build();
// Executed SQL: SELECT username, email, valid, id FROM t_user WHERE email LIKE ? AND valid = ? LIMIT 10 OFFSET 0
// Parameters : %@gmail.com%(java.lang.String), true(java.lang.Boolean)
return dataAccess.query(userQuery);
}
}
Please refer to the tests for more usages.
Architecture for 0.3.x and newer
Versions
Related resources
-
Github
-
Projects
-
Documentation
License
This project is under the Apache Licence v2.