Java Database Access
- 1. Sumario
- 2. JAVA ORM
- 3. Java Especificações
- 4. JPA
- 5. Spring JdbcTemplate
- 6. SQL Builder Utilities
- 7. SQLJ (Proprietary)
- 8. sqlbuilder
- 9. Squiggle SQL Builder
- 10. Amazom Carbonado (Java ORM)
- 11. Jinq
- 12. JDBI
- 13. Ebean
- 14. jOOQ
- 15. Speedment
- 16. Reladomo ORM
- 17. Feedzai PulseDB
- 18. Obevo (Schema Management, Migration)
- 19. Liquibase (Schema Migration)
- 20. PostgreSQL Advanced Features
- 21. Reactive Relational Database Connectivity (R2DBC)
- 22. Asynchronous Database Access API (ADBA)
- 23. Reference
1. Sumario
Object-Relational Mapping (ORM)
2. JAVA ORM
-
ORM Lite
-
Spring JdbcTemplate
-
Squiggle SQL Builder
-
sqlbuilder
-
SQLJ
3. Java Especificações
-
JDO API (JSR0012, JSR0243)
-
JPA (PA 2.2+
pkg:maven/javax.persistence/javax.persistence.api/2.2
4. JPA
TODO ..
5. Spring JdbcTemplate
PreparedStatementCreator psc =
new ParameterizedPreparedStatementCreator()
.setSql("update Employee set name = :name where id = :id")
.setParameter("name", "Bob")
.setParameter("id", 42);
new JdbcTemplate(dataSource).update(psc);
6. SQL Builder Utilities
-
compile 'ca.krasnay:sqlbuilder:1.2'
-
Can be use with Spring JdbcTemplate
new SelectBuilder()
.column("name")
.column("age")
.from("Employee")
.where("dept = 'engineering'")
.where("salary > 100000")
.toString();
PreparedStatementCreator psc =
new UpdateCreator("Employee")
.setValue("name", "Bob")
.whereEquals("id", 42);
new JdbcTemplate(dataSource).update(psc);
7. SQLJ (Proprietary)
-
https://www.mojohaus.org/sqlj-maven-plugin/
-
org.codehaus.mojo:sqlj-maven-plugin:1.4-SNAPSHOT:sqlj
-
Implementations
-
Oracle (Reference Implementation)
-
IBM
Sites
-
https://www.infoworld.com/article/2076416/sqlj—the—open-sesame—of-java-database-applications.html
-
https://www.ibm.com/docs/en/radfws/9.6.1?topic=applications-introduction-sqlj
-
https://www.ibm.com/docs/en/developer-for-zos/9.5.1?topic=support-what-is-sqlj
-
http://kursinfo.himolde.no/in-kurs/in135/Oracle9i/901_doc/java.901/a90212/overview.htm
#sql iterator SeatCursor(Integer row, Integer col, String type, int status);
Integer status = ?;
SeatCursor sc;
#sql sc = {
select rownum, colnum from seats where status <= :status
};
while(sc.next())
{
#sql { insert into categ values(:(sc.row()), :(sc.col())) };
}
sc.close();
8. sqlbuilder
-
Last Published: 2020-09-10| Version: 3.0.1
// assuming these objects have already been created
Table table1, table2;
Column t1Col1, t1Col2, t2Col1;
Join joinOfT1AndT2;
String selectQuery =
(new SelectQuery())
.addColumns(t1Col1, t1Col2, t2Col1)
.addJoin(SelectQuery.JoinType.INNER_JOIN, joinOfT1AndT2)
.addOrderings(t1Col1)
.validate().toString();
9. Squiggle SQL Builder
Squiggle is a little Java library for dynamically generating SQL SELECT statements.
-
joe.truemesh.com/squiggle/
SelectQuery select = new SelectQuery();
Table people = new Table("people");
select.addColumn(people, "firstname"); select.addColumn(people, "lastname");
select.addOrder(people, "age", Order.DESCENDING);
10. Amazom Carbonado (Java ORM)
11. Jinq
JINQ: Easy Database Queries for Java 8
LINQ-style queries for Java 8
Sites
13. Ebean
List<Person> boys =
Ebean.find(Person.class)
.where()
.eq("gender", "M")
.le("age", 18)
.orderBy("firstName")
.findList();
14. jOOQ
Sites
List<EmployeeDTO> records = create
.select(EMPLOYEE.LASTNAME, EMPLOYEE.FIRSTNAME, EMPLOYEE.SALARY)
.from(EMPLOYEE)
.where(EMPLOYEE.SALARY.between(80000, 100000))
.fetchInto(EmployeeDTO.class);
15. Speedment
-
Speedment is a Stream ORM Java Toolkit and Runtime
Sites
Speedment Edition (Licenses)
-
Speedment Open Source (OSS) - This site covers the Speedment Open Source project available under the Apache 2 license.
-
Speedment Stream - The same great features as Speedment OSS with support for commercial databases (i.e. Oracle, MS SQL Server, DB2, AS400). Learn more at speedment.com/stream.
-
Speedment HyperStream - An extension av Speedment Stream which also includes hypersonic query performance enabled by a unique in-JVM-memory management model. Learn more at speedment.com/hyperStream.
Speedment Open Source
-
MySQL
-
MariaDB
-
PostgreSQL
-
SQLite
JPAStreamer
List<Film> list = films.stream()
.filter(Film.RATING.equal("PG-13"))
.sorted(Film.LENGTH)
.collect(toList());
16. Reladomo ORM
-
Reladomo is an enterprise grade object-relational mapping framework for Java.
-
Support: Sybase (ASE & IQ), DB2, Oracle, Postgres, MS-SQL, H2, Derby, "generic" …
Mapping
-
TODO…
17. Feedzai PulseDB
PulseDB is a database-mapping software library written in Java, it provides a transparent access and manipulation to a great variety of database implementations. PDB provides a DSL that covers most of SQL functionalities and allows to easily integrate persistence into your projects and modules.
18. Obevo (Schema Management, Migration)
Get Your Database SDLC under Control
Obevo is a database deployment tool that handles enterprise scale schemas and complexity
Sites
19. Liquibase (Schema Migration)
liquibase --changeLogFile=dbchangelog_gen.sql --logLevel=debug generateChangeLog
liquibase –driver=org.postgresql.Driver \
–classpath=myFiles\postgresql-9.4.1212.jre7.jar \
–changeLogFile=myFiles/db.changelog-1.0.xml \
–url=”jdbc:postgresql://localhost:5432/MYDATABASE” \
–username=postgres \
–password=postgres \
generateChangeLog
url=jdbc:mysql://localhost:3306/unicenta
username=root
password=root
driver=com.mysql.cj.jdbc.Driver
outputChangeLogFile=src/main/resources/liquibase/liquibase-outputChangeLog.xml
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<propertyFile>src/main/resources/liquibase/liquibase.properties</propertyFile>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
mvn liquibase:generateChangeLog
20. PostgreSQL Advanced Features
-
UDT
21. Reactive Relational Database Connectivity (R2DBC)
TODO…