Lightsleep is a lightweight Object-Relational (O/R) mapping library and is available in Java 8 or later.
-
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.
-
Db2
-
MariaDB
-
MySQL
-
Oracle Database
-
PostgreSQL
-
SQLite
-
Microsoft SQL Server
-
DBMSs that conforms to the standard SQL
repositories {
jcenter()
}
dependencies {
compile 'org.lightsleep:lightsleep:4.0.0'
}
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;
}
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
}
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)
);
List<Contact> contacts = []
Transaction.execute {
new Sql<>(Contact)
.where('{lastName}={}', 'Apple')
.or ('{lastName}={}', 'Orange')
.orderBy('{lastName}')
.orderBy('{firstName}')
.connection(it)
.select({contacts << it})
}
SELECT id, firstName, lastName, birthday, updateCount, createdTime, updatedTime
FROM Contact
WHERE lastName='Apple' OR lastName='Orange'
ORDER BY lastName ASC, firstName ASC