SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
Get Back in Control of your SQL
SQL and Java could work
together so much better if
we only let them.

Copyright (c) 2009-2013 by Data Geekery GmbH.
Intro

SQL and Java

jOOQ

Examples

About me

Java, SQL, PL/SQL
2001-2006 MSc Computer Science EPFL
2006-2009 Ergon Informatik AG, Zürich
2009-2013 Crealogix E-Banking AG, Zürich
2013 Adobe Systems Inc, Basel
2013
Data Geekery GmbH, Zürich
Copyright (c) 2009-2013 by Data Geekery GmbH.
Intro

SQL and Java

About my motivation

SQL dominates database systems
SQL seems «low level» and «dusty»
SQL can do so much more
SQL should be «sexy» again

Copyright (c) 2009-2013 by Data Geekery GmbH.

jOOQ

Examples
Intro

About today

History of SQL in Java
Persistence in Java today
jOOQ
jOOQ Examples

Copyright (c) 2009-2013 by Data Geekery GmbH.

SQL and Java

jOOQ

Examples
Intro

SQL and Java

jOOQ

SQL and Java - never ending story

JDBC
EJB 2.0 with EntityBeans
Hibernate / TopLink
EJB 3.0 with JPA 2.x
iBATIS / JDO / SpringData / 1’000 others

Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

SQL and Java

jOOQ

JDBC

PreparedStatement stmt = connection.prepareStatement(
"SELECT text FROM products WHERE cust_id = ? AND value < ?");
stmt.setInt(1, custID);
stmt.setBigDecimal(2, BigDecimal.ZERO);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
System.out.println(rs.getString("TEXT"));
}

Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

SQL and Java

JDBC – the naked truth

01:
02:
03:
04:
05:
06:
07:
08:
09:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:

PreparedStatement stmt = connection.prepareStatement(
"SELECT p.text txt" +
(isAccount ? ", NVL(a.type, ?) " : "") +
"FROM products p " +
(isAccount ? " INNER JOIN accounts a USING (prod_id) " : "") +
" WHERE p.cust_id = ? AND p.value < ?" +
(isAccount ? " AND a.type LIKE '%" + type + "%'" : "");
stmt.setInt(1, defaultType);
stmt.setInt(2, custID);
stmt.setBigDecimal(3, BigDecimal.ZERO);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
Clob clob = rs.getClob("TEXT");
System.out.println(clob.getSubString(1, (int) clob.length());
}
rs.close();
stmt.close();

Copyright (c) 2009-2013 by Data Geekery GmbH.

jOOQ

Examples
Intro

SQL and Java

jOOQ

Examples

JDBC – the naked truth

01:
02:
03:
04:
05:
06:
07:
08:
09:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:

PreparedStatement stmt = connection.prepareStatement(
//
"SELECT p.text txt" +
//
(isAccount ? ", NVL(a.type, ?) " : "") +
//
"FROM products p " +
// Syntax error when isAccount == false
(isAccount ? " INNER JOIN accounts a USING (prod_id) " : "") + //
" WHERE p.cust_id = ? AND p.value < ?" +
//
(isAccount ? " AND a.type LIKE '%" + type + "%'" : "");
// Syntax error and SQL injection possible
stmt.setInt(1, defaultType);
// Wrong bind index
stmt.setInt(2, custID);
//
stmt.setBigDecimal(3, BigDecimal.ZERO);
//
ResultSet rs = stmt.executeQuery();
//
while (rs.next()) {
Clob clob = rs.getClob("TEXT");
System.out.println(clob.getSubString(1, (int) clob.length());
}

//
// ojdbc6: clob.free() should be called
//
//

rs.close();
stmt.close();

// close() not really in finally block
//

Copyright (c) 2009-2013 by Data Geekery GmbH.
Intro

SQL and Java

jOOQ

Examples

JDBC – pros and cons

JDBC Pros
No restrictions (procedures, UDTs, vendor-specific features)
Simple
Fast

JDBC Cons
String-based
No syntax checking
Lots of code, flat / indexed variables
Repetitive
Vendor lock-in
Copyright (c) 2009-2013 by Data Geekery GmbH.
Intro

SQL and Java

EJB 2.0 EntityBeans

public interface CustomerRequest extends EJBObject {
BigInteger getId();
String getText();
void setText(String text);
@Override
void remove();
}
public interface CustomerRequestHome extends EJBHome {
CustomerRequest create(BigInteger id);
CustomerRequest find(BigInteger id);
}

Copyright (c) 2009-2013 by Data Geekery GmbH.

jOOQ

Examples
Intro

EJB 2.0 – the naked truth

<weblogic-enterprise-bean>
<ejb-name>com.example.CustomerRequestHome</ejb-name>
<entity-descriptor>
<pool>
<max-beans-in-free-pool>100</max-beans-in-free-pool>
</pool>
<entity-cache>
<max-beans-in-cache>500</max-beans-in-cache>
<idle-timeout-seconds>10</idle-timeout-seconds>
<concurrency-strategy>Database</concurrency-strategy>
</entity-cache>
<persistence>
<delay-updates-until-end-of-tx>True</delay-updates-until-end-of-tx>
</persistence>
<entity-clustering>
<home-is-clusterable>False</home-is-clusterable>
<home-load-algorithm>round-robin</home-load-algorithm>
</entity-clustering>
</entity-descriptor>
<transaction-descriptor/>
<enable-call-by-reference>True</enable-call-by-reference>
<jndi-name>com.example.CustomerRequestHome</jndi-name>
</weblogic-enterprise-bean>

Copyright (c) 2009-2013 by Data Geekery GmbH.

SQL and Java

jOOQ

Examples
Intro

SQL and Java

jOOQ

EJB 2.0 – pros and cons

EJB 2.0 Pros
Intuitive client code (create(), remove(), store())
Powerful (transactions, caching, etc.)

EJB 2.0 Cons
Not intuitive implementation (Home, conventions)
Lots of configuration
XDoclet
Checked Exceptions (FinderException, CreateException)
Repetitive (except with a code generator)
Domain Model depends on container
Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

SQL and Java

Hibernate – ORM

Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(new Event("Conference", new Date());
session.save(new Event("After Party", new Date());
List result = session.createQuery("from Event").list();
for (Event event : (List<Event>) result) {
System.out.println("Event : " + event.getTitle());
}
session.getTransaction().commit();
session.close();

Copyright (c) 2009-2013 by Data Geekery GmbH.

jOOQ

Examples
Intro

SQL and Java

Hibernate – «navigation»

List result = session.createQuery("from Event").list();
for (Event event : (List<Event>) result) {
System.out.println("Participants of " + event);
for (Person person : event.getParticipants()) {
Company company = person.getCompany();
System.out.println(person + " (" + company + ")");

}
}

Copyright (c) 2009-2013 by Data Geekery GmbH.

jOOQ

Examples
Intro

SQL and Java

jOOQ

Hibernate – the naked truth

<hibernate-mapping package="org.hibernate.tutorial.hbm">
<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
<set name="participants" inverse="true">
<key column="eventId"/>
<one-to-many entity-name="Person"/>
</set>
</class>
</hibernate-mapping>

Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

Hibernate – pros and cons

Hibernate Pros
Very intuitive client code (POJOs)
POJO code generator
Objects can be «navigated»
Hibernate implements JPA

Hibernate Cons
Hard to configure
Caching is complex
HQL is limited. SQL can do more.
ORM impedance mismatch
Copyright (c) 2009-2013 by Data Geekery GmbH.

SQL and Java

jOOQ

Examples
Intro

SQL and Java

jOOQ

JPA and EJB 3.0

EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
em.persist(new Event("Conference", new Date());
em.persist(new Event("After Party", new Date());
List result = em.createQuery("from Event").getResultList();
for (Event event : (List<Event>) result) {
System.out.println("Event : " + event.getTitle());
}
em.getTransaction().commit();
em.close();

Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

SQL and Java

jOOQ

EJB 3.0 – the naked truth

@Entity @Table(name = "EVENTS")
public class Event {
private Long id;
private String title;
private Date date;
@Id @GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
public Long getId() { /* … */ }
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "EVENT_DATE")
public Date getDate() { /* … */ }

Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

SQL and Java

jOOQ

Examples

Criteria – the naked truth

EntityManager em= ...
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Person> criteria = builder.createQuery(Person.class);
Root<Person> person = criteria.from(Person.class);
Predicate condition = builder.gt(person.get(Person_.age), 20);
criteria.where(condition);
TypedQuery<Person> query = em.createQuery(query);
List<Person> result = query.getResultList();

Copyright (c) 2009-2013 by Data Geekery GmbH.
Intro

SQL and Java

jOOQ

JPA – pros and cons

JPA Facts
Hibernate HQL => JPQL
Hibernate XML mapping => annotations
Hibernate Sessions => EntityManager

JPA Pros
Next standard after EJB 2.0
Good implementations, such as Hibernate, EclipseLink

JPA Cons
CriteriaQuery
Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

SQL and Java

jOOQ

What else is there?

iBATIS / MyBatis
XML based. SQL is externalised
Active, but seems to be at the end of its hype cycle

JDO
Has JDOQL (similar to HQL, JPQL)
Supports also NoSQL stores
Is pretty dead

Spring JDBC, Apache DbUtils, etc
Ease *some* of the JDBC pain
Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

SQL and Java

jOOQ

Examples

SQL is so much more

|
TEXT | VOTES |
RANK | PERCENT |
|-------------|-------|------------|---------|
|
Hibernate |
138 |
1 |
32 % |
|
jOOQ |
102 |
2 |
23 % |
| EclipseLink |
88 |
3 |
20 % |
|
JDBC |
53 |
4 |
12 % |
| Spring JDBC |
45 |
5 |
10 % |

Copyright (c) 2009-2013 by Data Geekery GmbH.
Intro

SQL and Java

jOOQ

SQL is so much more

SELECT

p.text,
p.votes,
DENSE_RANK() OVER (ORDER BY p.votes DESC) AS "rank",
LPAD(
(p.votes * 100 / SUM(p.votes) OVER ()) || ' %',
4, ' '
) AS "percent"
FROM
poll_options p
WHERE
p.poll_id = 12
ORDER BY p.votes DESC

Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

SQL and Java

jOOQ

The same with jOOQ

select (p.TEXT,
p.VOTES,
denseRank().over().orderBy(p.VOTES.desc()).as("rank"),
lpad(
p.VOTES.mul(100).div(sum(p.VOTES).over()).concat(" %"),
4, " "
).as("percent"))
.from
(POLL_OPTIONS.as("p"))
.where (p.POLL_ID.eq(12))
.orderBy(p.VOTES.desc());

Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

SQL and Java

jOOQ

The same with jOOQ in Scala (!)

select (p.TEXT,
p.VOTES,
denseRank() over() orderBy(p.VOTES desc) as "rank",
lpad(
(p.VOTES * 100) / (sum(p.VOTES) over()) || " %",
4, " "
) as "percent")
from
(POLL_OPTIONS as "p")
where
(p.POLL_ID === 12)
orderBy (p.VOTES desc)

Copyright (c) 2009-2013 by Data Geekery GmbH.

Examples
Intro

SQL and Java

jOOQ

Examples

Support
Access
CUBRID
DB2
Derby
Firebird
H2
HSQLDB
Ingres
Copyright (c) 2009-2013 by Data Geekery GmbH.

MariaDB
MySQL
Oracle
Postgres
SQL Server
SQLite
Sybase ASE
Sybase SQL Anywhere
Intro

Examples

Copyright (c) 2009-2013 by Data Geekery GmbH.

SQL and Java

jOOQ

Examples

Contenu connexe

Tendances

How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...Lukas Eder
 
This isn't Richard Stallman's Open Source anymore
This isn't Richard Stallman's Open Source anymoreThis isn't Richard Stallman's Open Source anymore
This isn't Richard Stallman's Open Source anymoreLukas Eder
 
10 Reasons Why we Love Some APIs and Why we Hate Some Others
10 Reasons Why we Love Some APIs and Why we Hate Some Others10 Reasons Why we Love Some APIs and Why we Hate Some Others
10 Reasons Why we Love Some APIs and Why we Hate Some OthersLukas Eder
 
Eddystone Beacons - Physical Web - Giving a URL to All Objects
Eddystone Beacons - Physical Web - Giving a URL to All ObjectsEddystone Beacons - Physical Web - Giving a URL to All Objects
Eddystone Beacons - Physical Web - Giving a URL to All ObjectsJeff Prestes
 
Java Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJava Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJoshua Long
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개Reagan Hwang
 
Extending spring
Extending springExtending spring
Extending springJoshua Long
 
JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldRobert Nyman
 
"Reactive Programming in Java" at Froscon 2017 by Vadym Kazulkin/Rodion Alukh...
"Reactive Programming in Java" at Froscon 2017 by Vadym Kazulkin/Rodion Alukh..."Reactive Programming in Java" at Froscon 2017 by Vadym Kazulkin/Rodion Alukh...
"Reactive Programming in Java" at Froscon 2017 by Vadym Kazulkin/Rodion Alukh...Vadym Kazulkin
 
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 SederhanaPraktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 SederhanaMuhammad Yusuf
 
Naive application development
Naive application developmentNaive application development
Naive application developmentShaka Huang
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + SpringBryan Hsueh
 
Java Puzzle
Java PuzzleJava Puzzle
Java PuzzleSFilipp
 
There's more than web
There's more than webThere's more than web
There's more than webMatt Evans
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon Berlin
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developersPavel Lahoda
 
What makes a good bug report?
What makes a good bug report?What makes a good bug report?
What makes a good bug report?Rahul Premraj
 

Tendances (20)

How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
How Modern SQL Databases Come up with Algorithms that You Would Have Never Dr...
 
This isn't Richard Stallman's Open Source anymore
This isn't Richard Stallman's Open Source anymoreThis isn't Richard Stallman's Open Source anymore
This isn't Richard Stallman's Open Source anymore
 
10 Reasons Why we Love Some APIs and Why we Hate Some Others
10 Reasons Why we Love Some APIs and Why we Hate Some Others10 Reasons Why we Love Some APIs and Why we Hate Some Others
10 Reasons Why we Love Some APIs and Why we Hate Some Others
 
Eddystone Beacons - Physical Web - Giving a URL to All Objects
Eddystone Beacons - Physical Web - Giving a URL to All ObjectsEddystone Beacons - Physical Web - Giving a URL to All Objects
Eddystone Beacons - Physical Web - Giving a URL to All Objects
 
Java Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJava Configuration Deep Dive with Spring
Java Configuration Deep Dive with Spring
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
 
Extending spring
Extending springExtending spring
Extending spring
 
JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New World
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
"Reactive Programming in Java" at Froscon 2017 by Vadym Kazulkin/Rodion Alukh...
"Reactive Programming in Java" at Froscon 2017 by Vadym Kazulkin/Rodion Alukh..."Reactive Programming in Java" at Froscon 2017 by Vadym Kazulkin/Rodion Alukh...
"Reactive Programming in Java" at Froscon 2017 by Vadym Kazulkin/Rodion Alukh...
 
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 SederhanaPraktik Pengembangan Konten E-Learning HTML5 Sederhana
Praktik Pengembangan Konten E-Learning HTML5 Sederhana
 
Naive application development
Naive application developmentNaive application development
Naive application development
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
 
There's more than web
There's more than webThere's more than web
There's more than web
 
Java puzzles
Java puzzlesJava puzzles
Java puzzles
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 
What makes a good bug report?
What makes a good bug report?What makes a good bug report?
What makes a good bug report?
 

En vedette

An Introduction to jOOQ
An Introduction to jOOQAn Introduction to jOOQ
An Introduction to jOOQSteve Pember
 
TDC2016SP - JooQ: SQL orientado a objetos.
TDC2016SP - JooQ: SQL orientado a objetos.TDC2016SP - JooQ: SQL orientado a objetos.
TDC2016SP - JooQ: SQL orientado a objetos.tdc-globalcode
 
openEHR: NHS Code4Health RippleOSI and EtherCis
openEHR: NHS Code4Health RippleOSI and EtherCisopenEHR: NHS Code4Health RippleOSI and EtherCis
openEHR: NHS Code4Health RippleOSI and EtherCisIan McNicoll
 
ORM is an Offensive Anti-Pattern
ORM is an Offensive Anti-PatternORM is an Offensive Anti-Pattern
ORM is an Offensive Anti-PatternYegor Bugayenko
 
An introduction to Reactive applications, Reactive Streams, and options for t...
An introduction to Reactive applications, Reactive Streams, and options for t...An introduction to Reactive applications, Reactive Streams, and options for t...
An introduction to Reactive applications, Reactive Streams, and options for t...Steve Pember
 
jooqってなんて読むの? から始めるO/RマッパーとSpringBootの世界
jooqってなんて読むの? から始めるO/RマッパーとSpringBootの世界jooqってなんて読むの? から始めるO/RマッパーとSpringBootの世界
jooqってなんて読むの? から始めるO/RマッパーとSpringBootの世界Y Watanabe
 
Reactive Streams and the Wide World of Groovy
Reactive Streams and the Wide World of GroovyReactive Streams and the Wide World of Groovy
Reactive Streams and the Wide World of GroovySteve Pember
 
openEHR Technical Workshop Intro MIE 2016
openEHR Technical Workshop Intro MIE 2016openEHR Technical Workshop Intro MIE 2016
openEHR Technical Workshop Intro MIE 2016Ian McNicoll
 

En vedette (8)

An Introduction to jOOQ
An Introduction to jOOQAn Introduction to jOOQ
An Introduction to jOOQ
 
TDC2016SP - JooQ: SQL orientado a objetos.
TDC2016SP - JooQ: SQL orientado a objetos.TDC2016SP - JooQ: SQL orientado a objetos.
TDC2016SP - JooQ: SQL orientado a objetos.
 
openEHR: NHS Code4Health RippleOSI and EtherCis
openEHR: NHS Code4Health RippleOSI and EtherCisopenEHR: NHS Code4Health RippleOSI and EtherCis
openEHR: NHS Code4Health RippleOSI and EtherCis
 
ORM is an Offensive Anti-Pattern
ORM is an Offensive Anti-PatternORM is an Offensive Anti-Pattern
ORM is an Offensive Anti-Pattern
 
An introduction to Reactive applications, Reactive Streams, and options for t...
An introduction to Reactive applications, Reactive Streams, and options for t...An introduction to Reactive applications, Reactive Streams, and options for t...
An introduction to Reactive applications, Reactive Streams, and options for t...
 
jooqってなんて読むの? から始めるO/RマッパーとSpringBootの世界
jooqってなんて読むの? から始めるO/RマッパーとSpringBootの世界jooqってなんて読むの? から始めるO/RマッパーとSpringBootの世界
jooqってなんて読むの? から始めるO/RマッパーとSpringBootの世界
 
Reactive Streams and the Wide World of Groovy
Reactive Streams and the Wide World of GroovyReactive Streams and the Wide World of Groovy
Reactive Streams and the Wide World of Groovy
 
openEHR Technical Workshop Intro MIE 2016
openEHR Technical Workshop Intro MIE 2016openEHR Technical Workshop Intro MIE 2016
openEHR Technical Workshop Intro MIE 2016
 

Similaire à jOOQ at Topconf 2013

Best Way to Write SQL in Java
Best Way to Write SQL in JavaBest Way to Write SQL in Java
Best Way to Write SQL in JavaGerger
 
Going Offline with Gears And GWT
Going Offline with Gears And GWTGoing Offline with Gears And GWT
Going Offline with Gears And GWTtom.peck
 
닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기YoungSu Son
 
10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were Possible10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were PossibleLukas Eder
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Arun Gupta
 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...jaxLondonConference
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklum Ukraine
 
Bkbiet day2 & 3
Bkbiet day2 & 3Bkbiet day2 & 3
Bkbiet day2 & 3mihirio
 
Java one 2010
Java one 2010Java one 2010
Java one 2010scdn
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
2000 lines of java or 50 lines of sql the choice is yours - Lukas Eder
2000 lines of java or 50 lines of sql the choice is yours - Lukas Eder2000 lines of java or 50 lines of sql the choice is yours - Lukas Eder
2000 lines of java or 50 lines of sql the choice is yours - Lukas EderJAXLondon_Conference
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecturepostrational
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCpootsbook
 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Databasejitendral
 
Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Tugdual Grall
 

Similaire à jOOQ at Topconf 2013 (20)

Get Back in Control of your SQL
Get Back in Control of your SQLGet Back in Control of your SQL
Get Back in Control of your SQL
 
Best Way to Write SQL in Java
Best Way to Write SQL in JavaBest Way to Write SQL in Java
Best Way to Write SQL in Java
 
Going Offline with Gears And GWT
Going Offline with Gears And GWTGoing Offline with Gears And GWT
Going Offline with Gears And GWT
 
닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기
 
10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were Possible10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were Possible
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5
 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForce
 
Jdbc
JdbcJdbc
Jdbc
 
Bkbiet day2 & 3
Bkbiet day2 & 3Bkbiet day2 & 3
Bkbiet day2 & 3
 
Java one 2010
Java one 2010Java one 2010
Java one 2010
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
2000 lines of java or 50 lines of sql the choice is yours - Lukas Eder
2000 lines of java or 50 lines of sql the choice is yours - Lukas Eder2000 lines of java or 50 lines of sql the choice is yours - Lukas Eder
2000 lines of java or 50 lines of sql the choice is yours - Lukas Eder
 
Lecture17
Lecture17Lecture17
Lecture17
 
Scalable web application architecture
Scalable web application architectureScalable web application architecture
Scalable web application architecture
 
Advance java
Advance javaAdvance java
Advance java
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Database
 
Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007
 

Dernier

Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 

Dernier (20)

Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 

jOOQ at Topconf 2013

  • 1. Get Back in Control of your SQL SQL and Java could work together so much better if we only let them. Copyright (c) 2009-2013 by Data Geekery GmbH.
  • 2. Intro SQL and Java jOOQ Examples About me Java, SQL, PL/SQL 2001-2006 MSc Computer Science EPFL 2006-2009 Ergon Informatik AG, Zürich 2009-2013 Crealogix E-Banking AG, Zürich 2013 Adobe Systems Inc, Basel 2013 Data Geekery GmbH, Zürich Copyright (c) 2009-2013 by Data Geekery GmbH.
  • 3. Intro SQL and Java About my motivation SQL dominates database systems SQL seems «low level» and «dusty» SQL can do so much more SQL should be «sexy» again Copyright (c) 2009-2013 by Data Geekery GmbH. jOOQ Examples
  • 4. Intro About today History of SQL in Java Persistence in Java today jOOQ jOOQ Examples Copyright (c) 2009-2013 by Data Geekery GmbH. SQL and Java jOOQ Examples
  • 5. Intro SQL and Java jOOQ SQL and Java - never ending story JDBC EJB 2.0 with EntityBeans Hibernate / TopLink EJB 3.0 with JPA 2.x iBATIS / JDO / SpringData / 1’000 others Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 6. Intro SQL and Java jOOQ JDBC PreparedStatement stmt = connection.prepareStatement( "SELECT text FROM products WHERE cust_id = ? AND value < ?"); stmt.setInt(1, custID); stmt.setBigDecimal(2, BigDecimal.ZERO); ResultSet rs = stmt.executeQuery(); while (rs.next()) { System.out.println(rs.getString("TEXT")); } Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 7. Intro SQL and Java JDBC – the naked truth 01: 02: 03: 04: 05: 06: 07: 08: 09: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: PreparedStatement stmt = connection.prepareStatement( "SELECT p.text txt" + (isAccount ? ", NVL(a.type, ?) " : "") + "FROM products p " + (isAccount ? " INNER JOIN accounts a USING (prod_id) " : "") + " WHERE p.cust_id = ? AND p.value < ?" + (isAccount ? " AND a.type LIKE '%" + type + "%'" : ""); stmt.setInt(1, defaultType); stmt.setInt(2, custID); stmt.setBigDecimal(3, BigDecimal.ZERO); ResultSet rs = stmt.executeQuery(); while (rs.next()) { Clob clob = rs.getClob("TEXT"); System.out.println(clob.getSubString(1, (int) clob.length()); } rs.close(); stmt.close(); Copyright (c) 2009-2013 by Data Geekery GmbH. jOOQ Examples
  • 8. Intro SQL and Java jOOQ Examples JDBC – the naked truth 01: 02: 03: 04: 05: 06: 07: 08: 09: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: PreparedStatement stmt = connection.prepareStatement( // "SELECT p.text txt" + // (isAccount ? ", NVL(a.type, ?) " : "") + // "FROM products p " + // Syntax error when isAccount == false (isAccount ? " INNER JOIN accounts a USING (prod_id) " : "") + // " WHERE p.cust_id = ? AND p.value < ?" + // (isAccount ? " AND a.type LIKE '%" + type + "%'" : ""); // Syntax error and SQL injection possible stmt.setInt(1, defaultType); // Wrong bind index stmt.setInt(2, custID); // stmt.setBigDecimal(3, BigDecimal.ZERO); // ResultSet rs = stmt.executeQuery(); // while (rs.next()) { Clob clob = rs.getClob("TEXT"); System.out.println(clob.getSubString(1, (int) clob.length()); } // // ojdbc6: clob.free() should be called // // rs.close(); stmt.close(); // close() not really in finally block // Copyright (c) 2009-2013 by Data Geekery GmbH.
  • 9. Intro SQL and Java jOOQ Examples JDBC – pros and cons JDBC Pros No restrictions (procedures, UDTs, vendor-specific features) Simple Fast JDBC Cons String-based No syntax checking Lots of code, flat / indexed variables Repetitive Vendor lock-in Copyright (c) 2009-2013 by Data Geekery GmbH.
  • 10. Intro SQL and Java EJB 2.0 EntityBeans public interface CustomerRequest extends EJBObject { BigInteger getId(); String getText(); void setText(String text); @Override void remove(); } public interface CustomerRequestHome extends EJBHome { CustomerRequest create(BigInteger id); CustomerRequest find(BigInteger id); } Copyright (c) 2009-2013 by Data Geekery GmbH. jOOQ Examples
  • 11. Intro EJB 2.0 – the naked truth <weblogic-enterprise-bean> <ejb-name>com.example.CustomerRequestHome</ejb-name> <entity-descriptor> <pool> <max-beans-in-free-pool>100</max-beans-in-free-pool> </pool> <entity-cache> <max-beans-in-cache>500</max-beans-in-cache> <idle-timeout-seconds>10</idle-timeout-seconds> <concurrency-strategy>Database</concurrency-strategy> </entity-cache> <persistence> <delay-updates-until-end-of-tx>True</delay-updates-until-end-of-tx> </persistence> <entity-clustering> <home-is-clusterable>False</home-is-clusterable> <home-load-algorithm>round-robin</home-load-algorithm> </entity-clustering> </entity-descriptor> <transaction-descriptor/> <enable-call-by-reference>True</enable-call-by-reference> <jndi-name>com.example.CustomerRequestHome</jndi-name> </weblogic-enterprise-bean> Copyright (c) 2009-2013 by Data Geekery GmbH. SQL and Java jOOQ Examples
  • 12. Intro SQL and Java jOOQ EJB 2.0 – pros and cons EJB 2.0 Pros Intuitive client code (create(), remove(), store()) Powerful (transactions, caching, etc.) EJB 2.0 Cons Not intuitive implementation (Home, conventions) Lots of configuration XDoclet Checked Exceptions (FinderException, CreateException) Repetitive (except with a code generator) Domain Model depends on container Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 13. Intro SQL and Java Hibernate – ORM Session session = sessionFactory.openSession(); session.beginTransaction(); session.save(new Event("Conference", new Date()); session.save(new Event("After Party", new Date()); List result = session.createQuery("from Event").list(); for (Event event : (List<Event>) result) { System.out.println("Event : " + event.getTitle()); } session.getTransaction().commit(); session.close(); Copyright (c) 2009-2013 by Data Geekery GmbH. jOOQ Examples
  • 14. Intro SQL and Java Hibernate – «navigation» List result = session.createQuery("from Event").list(); for (Event event : (List<Event>) result) { System.out.println("Participants of " + event); for (Person person : event.getParticipants()) { Company company = person.getCompany(); System.out.println(person + " (" + company + ")"); } } Copyright (c) 2009-2013 by Data Geekery GmbH. jOOQ Examples
  • 15. Intro SQL and Java jOOQ Hibernate – the naked truth <hibernate-mapping package="org.hibernate.tutorial.hbm"> <class name="Event" table="EVENTS"> <id name="id" column="EVENT_ID"> <generator class="increment"/> </id> <property name="date" type="timestamp" column="EVENT_DATE"/> <property name="title"/> <set name="participants" inverse="true"> <key column="eventId"/> <one-to-many entity-name="Person"/> </set> </class> </hibernate-mapping> Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 16. Intro Hibernate – pros and cons Hibernate Pros Very intuitive client code (POJOs) POJO code generator Objects can be «navigated» Hibernate implements JPA Hibernate Cons Hard to configure Caching is complex HQL is limited. SQL can do more. ORM impedance mismatch Copyright (c) 2009-2013 by Data Geekery GmbH. SQL and Java jOOQ Examples
  • 17. Intro SQL and Java jOOQ JPA and EJB 3.0 EntityManager em = factory.createEntityManager(); em.getTransaction().begin(); em.persist(new Event("Conference", new Date()); em.persist(new Event("After Party", new Date()); List result = em.createQuery("from Event").getResultList(); for (Event event : (List<Event>) result) { System.out.println("Event : " + event.getTitle()); } em.getTransaction().commit(); em.close(); Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 18. Intro SQL and Java jOOQ EJB 3.0 – the naked truth @Entity @Table(name = "EVENTS") public class Event { private Long id; private String title; private Date date; @Id @GeneratedValue(generator = "increment") @GenericGenerator(name = "increment", strategy = "increment") public Long getId() { /* … */ } @Temporal(TemporalType.TIMESTAMP) @Column(name = "EVENT_DATE") public Date getDate() { /* … */ } Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 19. Intro SQL and Java jOOQ Examples Criteria – the naked truth EntityManager em= ... CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Person> criteria = builder.createQuery(Person.class); Root<Person> person = criteria.from(Person.class); Predicate condition = builder.gt(person.get(Person_.age), 20); criteria.where(condition); TypedQuery<Person> query = em.createQuery(query); List<Person> result = query.getResultList(); Copyright (c) 2009-2013 by Data Geekery GmbH.
  • 20. Intro SQL and Java jOOQ JPA – pros and cons JPA Facts Hibernate HQL => JPQL Hibernate XML mapping => annotations Hibernate Sessions => EntityManager JPA Pros Next standard after EJB 2.0 Good implementations, such as Hibernate, EclipseLink JPA Cons CriteriaQuery Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 21. Intro SQL and Java jOOQ What else is there? iBATIS / MyBatis XML based. SQL is externalised Active, but seems to be at the end of its hype cycle JDO Has JDOQL (similar to HQL, JPQL) Supports also NoSQL stores Is pretty dead Spring JDBC, Apache DbUtils, etc Ease *some* of the JDBC pain Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 22. Intro SQL and Java jOOQ Examples SQL is so much more | TEXT | VOTES | RANK | PERCENT | |-------------|-------|------------|---------| | Hibernate | 138 | 1 | 32 % | | jOOQ | 102 | 2 | 23 % | | EclipseLink | 88 | 3 | 20 % | | JDBC | 53 | 4 | 12 % | | Spring JDBC | 45 | 5 | 10 % | Copyright (c) 2009-2013 by Data Geekery GmbH.
  • 23. Intro SQL and Java jOOQ SQL is so much more SELECT p.text, p.votes, DENSE_RANK() OVER (ORDER BY p.votes DESC) AS "rank", LPAD( (p.votes * 100 / SUM(p.votes) OVER ()) || ' %', 4, ' ' ) AS "percent" FROM poll_options p WHERE p.poll_id = 12 ORDER BY p.votes DESC Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 24. Intro SQL and Java jOOQ The same with jOOQ select (p.TEXT, p.VOTES, denseRank().over().orderBy(p.VOTES.desc()).as("rank"), lpad( p.VOTES.mul(100).div(sum(p.VOTES).over()).concat(" %"), 4, " " ).as("percent")) .from (POLL_OPTIONS.as("p")) .where (p.POLL_ID.eq(12)) .orderBy(p.VOTES.desc()); Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 25. Intro SQL and Java jOOQ The same with jOOQ in Scala (!) select (p.TEXT, p.VOTES, denseRank() over() orderBy(p.VOTES desc) as "rank", lpad( (p.VOTES * 100) / (sum(p.VOTES) over()) || " %", 4, " " ) as "percent") from (POLL_OPTIONS as "p") where (p.POLL_ID === 12) orderBy (p.VOTES desc) Copyright (c) 2009-2013 by Data Geekery GmbH. Examples
  • 26. Intro SQL and Java jOOQ Examples Support Access CUBRID DB2 Derby Firebird H2 HSQLDB Ingres Copyright (c) 2009-2013 by Data Geekery GmbH. MariaDB MySQL Oracle Postgres SQL Server SQLite Sybase ASE Sybase SQL Anywhere
  • 27. Intro Examples Copyright (c) 2009-2013 by Data Geekery GmbH. SQL and Java jOOQ Examples