Skip to content

doytowin/doyto-query

Repository files navigation

License Sonar Stats Code Lines Coverage Status

DoytoQuery - The First Implementation of Object SQL Mapping for Java Applications Over Relational Databases

Introduction

DoytoQuery is a powerful and easy-to-use Object/Query-Language Mapping (OQM) framework for Java applications over relational databases. Unlike object-relational mapping (ORM), which attempts to map the object model and the relational model directly, OQM introduces query languages as an intermediary between the object-oriented application systems and the database management system to map objects to query statements.

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.
  • Supported Databases
    • MySQL
    • Oracle
    • SQL Server
    • PostgreSQL
    • SQLite
    • HSQLDB
    • 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 demo for more details.

Architecture for 0.3.x and newer

architecture-0.3.x

Versions

Module Snapshot Release
doyto-query-api api-snapshots-img api-release-img
doyto-query-geo geo-snapshots-img geo-release-img
doyto-query-common common-snapshots-img common-release-img
doyto-query-memory memory-snapshots-img memory-release-img
doyto-query-sql sql-snapshots-img sql-release-img
doyto-query-jdbc jdbc-snapshots-img jdbc-release-img
doyto-query-web-common web-common-snapshots-img web-common-release-img
doyto-query-web web-snapshots-img web-release-img
doyto-query-dialect dialect-snapshots-img dialect-release-img

Related Resources

License

This project is under the Apache Licence v2.