Skip to content

Latest commit

 

History

History
154 lines (121 loc) · 3.48 KB

README.asciidoc

File metadata and controls

154 lines (121 loc) · 3.48 KB

Lightsleep

Lightsleep is a lightweight Object-Relational (O/R) mapping library and is available in Java 8 or later.

Features

  • It has API using features added in Java 8 (functional interface and Optional class).

  • It is easy to understand intuitively because method names used in SQL construction are the same as SQL reserved words.

  • It is applicable because J2EE is unnecessary: there is no library that depends on Java Runtime and JDBC driver other than.

  • It does not need a definition file for mapping tables and Java classes with XML files.

  • Learning is easy because the library is compact.

  • Connectable to various DBMS simultaneously.

  • Various connection pool libraries can be used simultaneously.

  • You can select from various logging libraries when outputting internal logs.

Supported DBMSs

  • Db2

  • MariaDB

  • MySQL

  • Oracle Database

  • PostgreSQL

  • SQLite

  • Microsoft SQL Server

  • DBMSs that conforms to the standard SQL

Description example of dependency in build.gradle

build.gradle
repositories {
    jcenter()
}

dependencies {
    compile 'org.lightsleep:lightsleep:4.0.0'
}

Definition example of entity class used in Lightsleep

Contact.java
package org.lightsleep.example.java.entity;
import java.sql.Date;
import java.sql.Timestamp;
import org.lightsleep.entity.*;

public class Contact {
    @Key
    public int       id;
    public String    lastName;
    public String    firstName;
    public LocalDate birthday;

    @Insert("0") @Update("{updateCount}+1")
    public int updateCount;

    @Insert("CURRENT_TIMESTAMP") @NonUpdate
    public LocalDateTime createdTime;

    @Insert("CURRENT_TIMESTAMP") @Update("CURRENT_TIMESTAMP")
    public LocalDateTime updatedTime;
}
Contact.groovy
package org.lightsleep.example.groovy.entity
import java.sql.Date
import java.sql.Timestamp
import org.lightsleep.entity.*

class Contact {
    @Key
    int       id
    String    lastName
    String    firstName
    LocalDate birthday

    @Insert('0') @Update('{updateCount}+1')
    int updateCount

    @Insert('CURRENT_TIMESTAMP') @NonUpdate
    Timestamp createdTime

    @Insert('CURRENT_TIMESTAMP') @Update('CURRENT_TIMESTAMP')
    Timestamp updatedTime
}

Examples of using Lightsleep

Java Example
var contacts = new ArrayList<Contact>();
Transaction.execute(conn ->
    new Sql<>(Contact.class)
        .where("{lastName}={}", "Apple")
        .or   ("{lastName}={}", "Orange")
        .orderBy("{lastName}")
        .orderBy("{firstName}")
        .connection(conn)
        .select(contacts::add)
);
Groovy Example
List<Contact> contacts = []
Transaction.execute {
    new Sql<>(Contact)
        .where('{lastName}={}', 'Apple')
        .or   ('{lastName}={}', 'Orange')
        .orderBy('{lastName}')
        .orderBy('{firstName}')
        .connection(it)
        .select({contacts << it})
}
Generated SQL
SELECT id, firstName, lastName, birthday, updateCount, createdTime, updatedTime
  FROM Contact
  WHERE lastName='Apple' OR lastName='Orange'
  ORDER BY lastName ASC, firstName ASC

License

The MIT License (MIT)

© 2015 Masato Kokubo