3

GitHub - doytowin/doyto-query: DoytoQuery - A Java implementation for the modern...

 1 year ago
source link: https://github.com/doytowin/doyto-query
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

  1. We can define a query object mapping query statements.

  2. We can define an entity object and cooperate with the query object to complete the CRUD operations of single-table.

  3. Data Manipulation Language can be classified into three categories, corresponding to three different interfaces:
    1. CRUD for business tables: DataAccess
    2. CRD for association tables: AssociationService
    3. 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 = "t_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

architecture-0.3.x

Versions

Module Snapshot Release
doyto-query-geo
doyto-query-api
doyto-query-common
doyto-query-memory
doyto-query-sql
doyto-query-jdbc
doyto-query-mongodb
doyto-query-web-common
doyto-query-web
doyto-query-dialect

Related resources

License

This project is under the Apache Licence v2.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK