1. Sumario

Object-Relational Mapping (ORM)

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

Example using 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

Example Select
new SelectBuilder()
    .column("name")
    .column("age")
    .from("Employee")
    .where("dept = 'engineering'")
    .where("salary > 100000")
    .toString();
Example with integrate with JdbcTemplate
PreparedStatementCreator psc =
    new UpdateCreator("Employee")
        .setValue("name", "Bob")
        .whereEquals("id", 42);

new JdbcTemplate(dataSource).update(psc);

7. SQLJ (Proprietary)

Implementations

  • Oracle (Reference Implementation)

  • IBM

Sites

Example with SQLJ
#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

Example with sqlbuilder
// 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.

Example with 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

Example Ebean
List<Person> boys =
    Ebean.find(Person.class)
    .where()
        .eq("gender", "M")
        .le("age", 18)
    .orderBy("firstName")
    .findList();

14. jOOQ

Sites

Example jOOQ
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

Example 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.

  • https://goldmansachs.github.io/reladomo/

  • 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)

Example invoke liquidbase from cli
liquibase --changeLogFile=dbchangelog_gen.sql --logLevel=debug generateChangeLog
Example liquidbase configuration
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
liquibase.properties
url=jdbc:mysql://localhost:3306/unicenta
username=root
password=root
driver=com.mysql.cj.jdbc.Driver
outputChangeLogFile=src/main/resources/liquibase/liquibase-outputChangeLog.xml
Maven plugin
<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…​