Active Record pattern in Java

·

2 min read

ObjectiveSql ’s mission is to provide the most intuitive and convenient approach to access various databases, without configuration, without coding relevant to JDBC&ORM. It is an abstraction and encapsulation of java in relation database domain logic.

ObjectiveSql-based programming is the best practice in ActiveRecord pattern in Java, which incorporates both behavior and data and avoids meaningless Interface declaration of Java. Thus, ObjectiveSql-based programming will change the way to build an application base on relation database especially in the WEB development.

Features

Defining a domain model, which carries the query and persistence capabilities by itself, no configuration, no no-implementational Interface Validating the Java Bean with Jakarta Bean Validation integrated to ObjectiveSql Database transactions simply add an Annotation to the method Add Queryable annotation to field, which can be queried by static method queryByFieldName

Defining domain models

@DomainModel
public class Member {
    private String no;

    @Queryable
    private String name;
    private Integer gender;
    private String mobile;
    private String otherInfo;

    @Relation(relationType = RelationType.HAS_MANY)
    private List<Order> orders;
}

Query methods generated automatically

Member member = Member.queryByPrimaryKey(11);
Member member = Member.queryFirst("id = ?", 11);
List<Member> members = Member.query("id > ?", 8);
List<Member> members = Member.queryAll();
int count = Member.count("id > ?", 10);

With only minimal codes, You can access database with active record pattern