Skip to content
ORM - Relational database persistence for domain models, written in Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper
src
.gitignore
README.md
build.gradle
docker-compose.yml
gradlew
gradlew.bat
settings.gradle

README.md

Base

A java ORM library for SQL databases

Providers:

  • MySQL
  • PostgresSQL (planned)
  • SQLite (planned)
  • Oracle (planned)
  • SQL Server (planned)

Database manipulations

  • Create
  • Truncate
  • Drop
  • Select
  • Insert
  • Update
  • Delete

Installation

1.) Import library:


	compile 'com.shocknode:base:0.0.1'

2.) Import driver into project via Maven, Gradle, etc:

MySQL


	compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'

Usage

MySQL:

1.)

//Optional base class including ID, UUID, date time updated, date time created

public abstract class Entity {

    @PrimaryKey
    @AutoIncrement
    @Unique
    @Size(11)
    @NotNull
    @TransientUpdate @TransientInsert
    private Long id;

    @TransientUpdate
    @Unique
    @NotNull
    @Size(36)
    private UUID uuid;

    @NotNull
    @TransientUpdate @TransientInsert
    @Default("CURRENT_TIMESTAMP") @OnUpdate("CURRENT_TIMESTAMP")
    private LocalDateTime dateTimeUpdated;

    @NotNull
    @TransientUpdate @TransientInsert
    @Default("CURRENT_TIMESTAMP")
    private LocalDateTime dateTimeCreated;
    
    protected Entity(Long id, UUID uuid, LocalDateTime dateTimeUpdated, LocalDateTime dateTimeCreated){
        this.id = id;
        this.uuid = uuid;
        this.dateTimeUpdated = dateTimeUpdated;
        this.dateTimeCreated = dateTimeCreated;
    }

    protected Entity(){
        this.id = 0L;
        this.uuid = UUID.randomUUID();
        this.dateTimeCreated = this.dateTimeUpdated = LocalDateTime.now();
    }

    public Long getId() {
        return id;
    }
    public UUID getUuid() {
        return uuid;
    }
    public LocalDateTime getDateTimeUpdated() {
        return dateTimeUpdated;
    }
    public LocalDateTime getDateTimeCreated() {
        return dateTimeCreated;
    }
    
}
public class Employee extends Entity {

    @NotNull
    private Double pay;

    @NotNull
    private String payType;

    public Employee() {
        super();
        
        this.pay = 0.00;
        this.payType = "hourly";
        
    }

    public Double getPay() {
        return pay;
    }

    public void setPay(Double pay) {
        this.pay = pay;
    }

    public String getPayType() {
        return payType;
    }

    public void setPayType(String payType) {
        this.payType = payType;
    }

}


2.)

    MySQL mysql = new MySQL(
            new ConnectionBuilder()
                .host("localhost")
                .port(3306)
                .user("lead")
                .password("real")
                .database("base")
                .build()
    );

3.)

        
        Statement<Employee> statement = builder.insert(employee);
        
        // INSERT INTO Employee (uuid,pay,payType) VALUES (?,?,?)
        System.out.println(statement.getQueryString());

        connect();
        mysql.update(statement);

Stuff used to make this:

You can’t perform that action at this time.