SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
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. Slides licensed under CC BY SA 3.0
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. Slides licensed under CC BY SA 3.0

jOOQ

Examples
Intro

SQL and Java

jOOQ

Examples

SQL and Java – in theory

Java

one jack

SQL

one plug

In this metaphor, electricity is the data (SQL) that
flows into your appliance / application (Java)
Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro

SQL and Java

jOOQ

Examples

SQL and Java – in practice

Java

SQL

one jack

lots of plugs

Images from: http://en.wikipedia.org/wiki/AC_power_plugs_and_sockets. License: public domain

Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
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. Slides licensed under CC BY SA 3.0

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. Slides licensed under CC BY SA 3.0

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());
}

//
// Wrong column name
// ojdbc6: clob.free() should be called
//

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

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

Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro

SQL and Java

jOOQ

Examples

What JDBC means for developers

With JDBC, your developers have to do a lot of
manual, error-prone (dangerous) and inefficient work
Images from Flickr. To the left by: Matthew Straubmuller, Greg Grossmeier. License: CC BY SA 2.0. Electric Engineers to the right copyright by Marco Sarli, all rights reserved.

Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
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. Slides licensed under CC BY SA 3.0

jOOQ

Examples
Intro

SQL and Java

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. Slides licensed under CC BY SA 3.0

jOOQ

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. Slides licensed under CC BY SA 3.0

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. Slides licensed under CC BY SA 3.0

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. Slides licensed under CC BY SA 3.0

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. Slides licensed under CC BY SA 3.0

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. Slides licensed under CC BY SA 3.0

Examples
Intro

SQL and Java

jOOQ

Examples

EJB 3.0 – Annotatiomania™

@OneToMany(mappedBy = "destCustomerId")
@ManyToMany
@Fetch(FetchMode.SUBSELECT)
@JoinTable(
name = "customer_dealer_map",
joinColumns = {
@JoinColumn(name = "customer_id", referencedColumnName = "id")
},
inverseJoinColumns = {
@JoinColumn(name = "dealer_id", referencedColumnName = "id")
}
)
private Collection dealers;
Found at http://stackoverflow.com/q/17491912/521799
Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro

SQL and Java

jOOQ

Examples

JPA 3.0 Preview – Annotatiomania™

@OneToMany @OneToManyMore @AnyOne @AnyBody
@ManyToMany @Many
@Fetch @FetchMany @FetchWithDiscriminator(name = "no_name")
@JoinTable(joinColumns = {
@JoinColumn(name = "customer_id", referencedColumnName = "id")
})
@PrefetchJoinWithDiscriminator
@IfJoiningAvoidHashJoins @ButUseHashJoinsWhenMoreThan(records = 1000)
@XmlDataTransformable @SpringPrefechAdapter
private Collection employees;

Might not be true
Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro

SQL and Java

jOOQ

Examples

What JPA means for developers…

With JPA, your developers use a huge framework with
lots of complexity that can get hard to manage
Images from Wikimedia. License: public domain. High voltage power lines by Simon Koopmann. License: CC-BY SA 3.0

Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro

SQL and Java

jOOQ

Examples

… when developers actually wanted this

Java

one jack

Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0

SQL

one plug
Intro

SQL and Java

NoSQL?

…
… so, should we maybe abandon SQL?
Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0

jOOQ

Examples
Intro

SQL and Java

jOOQ

NoSQL? Nope!

Seen at the O’Reilly Strata Conf:
History of NoSQL by Mark Madsen. Picture published by Edd Dumbill
Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0

Examples
Intro

SQL and Java

jOOQ

Examples

SQL is so much more

|
TEXT | VOTES |
RANK | PERCENT |
|-------------|-------|------------|---------|
|
Hibernate | 1383 |
1 |
32 % |
|
jOOQ | 1029 |
2 |
23 % |
| EclipseLink |
881 |
3 |
20 % |
|
JDBC |
533 |
4 |
12 % |
| Spring JDBC |
451 |
5 |
10 % |
Data may not be accurate…

Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
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. Slides licensed under CC BY SA 3.0

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. Slides licensed under CC BY SA 3.0

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. Slides licensed under CC BY SA 3.0

Examples
Intro

SQL and Java

jOOQ

Examples

What jOOQ means for developers

Java

jOOQ

SQL

one jack
one adaptor
all plugs
With jOOQ, Java plugs into SQL intuitively, letting
your developers focus on business-logic again.
Images from Wikimedia. License: public domain. Travel converter by Cephira. License: CC-BY SA 3.0

Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro

SQL and Java

Examples

Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0

jOOQ

Examples

Más contenido relacionado

La actualidad más candente

Naive application development
Naive application developmentNaive application development
Naive application developmentShaka Huang
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개Reagan Hwang
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklum Ukraine
 
Ajax Performance
Ajax PerformanceAjax Performance
Ajax Performancekaven yan
 
Css2011 Ruo Ando
Css2011 Ruo AndoCss2011 Ruo Ando
Css2011 Ruo AndoRuo Ando
 
"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
 

La actualidad más candente (9)

Data binding w Androidzie
Data binding w AndroidzieData binding w Androidzie
Data binding w Androidzie
 
Android data binding
Android data bindingAndroid data binding
Android data binding
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
Naive application development
Naive application developmentNaive application development
Naive application development
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForce
 
Ajax Performance
Ajax PerformanceAjax Performance
Ajax Performance
 
Css2011 Ruo Ando
Css2011 Ruo AndoCss2011 Ruo Ando
Css2011 Ruo Ando
 
"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...
 

Destacado

Farrah before and after
Farrah before and afterFarrah before and after
Farrah before and afterErin Reynolds
 
Task 8b Experimentation
Task 8b ExperimentationTask 8b Experimentation
Task 8b ExperimentationPrincessnoob
 
«Обслуговування та ремонт автомобілів і двигунів»
«Обслуговування та ремонт автомобілів і двигунів»«Обслуговування та ремонт автомобілів і двигунів»
«Обслуговування та ремонт автомобілів і двигунів»Oleksandr Ponedilnyk
 
Останній дзвоник 2016
Останній  дзвоник 2016Останній  дзвоник 2016
Останній дзвоник 2016Oleksandr Ponedilnyk
 
Why Your Developers Need jOOQ
Why Your Developers Need jOOQWhy Your Developers Need jOOQ
Why Your Developers Need jOOQDataGeekery
 
Advertising campaigns for bernado - Blog post
Advertising campaigns for bernado - Blog post Advertising campaigns for bernado - Blog post
Advertising campaigns for bernado - Blog post Princessnoob
 
Trade policies argentina
Trade policies   argentinaTrade policies   argentina
Trade policies argentinaAbhishek Singh
 
«Організація перевезень і управління на автомобільному транспорті»
«Організація перевезень і управління на автомобільному транспорті»«Організація перевезень і управління на автомобільному транспорті»
«Організація перевезень і управління на автомобільному транспорті»Oleksandr Ponedilnyk
 
виховна година веселка твого щастя
виховна година веселка твого щастявиховна година веселка твого щастя
виховна година веселка твого щастяOleksandr Ponedilnyk
 
Advertisement campaign -
Advertisement campaign - Advertisement campaign -
Advertisement campaign - Princessnoob
 
Представлення 1 курс КПЕК ЛНТУ
Представлення 1 курс КПЕК ЛНТУПредставлення 1 курс КПЕК ЛНТУ
Представлення 1 курс КПЕК ЛНТУOleksandr Ponedilnyk
 
ГБОУДОД ДДТ "Оранианбаум"
ГБОУДОД ДДТ "Оранианбаум"ГБОУДОД ДДТ "Оранианбаум"
ГБОУДОД ДДТ "Оранианбаум"darowska
 
NoSQL? No, SQL! - SQL, the underestimated "Big Data" technology
NoSQL? No, SQL! - SQL, the underestimated "Big Data" technologyNoSQL? No, SQL! - SQL, the underestimated "Big Data" technology
NoSQL? No, SQL! - SQL, the underestimated "Big Data" technologyDataGeekery
 

Destacado (17)

Табір живчик
Табір живчикТабір живчик
Табір живчик
 
Farrah before and after
Farrah before and afterFarrah before and after
Farrah before and after
 
Task 8b Experimentation
Task 8b ExperimentationTask 8b Experimentation
Task 8b Experimentation
 
«Обслуговування та ремонт автомобілів і двигунів»
«Обслуговування та ремонт автомобілів і двигунів»«Обслуговування та ремонт автомобілів і двигунів»
«Обслуговування та ремонт автомобілів і двигунів»
 
Останній дзвоник 2016
Останній  дзвоник 2016Останній  дзвоник 2016
Останній дзвоник 2016
 
853 nama bayi_muslim
853 nama bayi_muslim853 nama bayi_muslim
853 nama bayi_muslim
 
Why Your Developers Need jOOQ
Why Your Developers Need jOOQWhy Your Developers Need jOOQ
Why Your Developers Need jOOQ
 
Advertising campaigns for bernado - Blog post
Advertising campaigns for bernado - Blog post Advertising campaigns for bernado - Blog post
Advertising campaigns for bernado - Blog post
 
Trade policies argentina
Trade policies   argentinaTrade policies   argentina
Trade policies argentina
 
«Організація перевезень і управління на автомобільному транспорті»
«Організація перевезень і управління на автомобільному транспорті»«Організація перевезень і управління на автомобільному транспорті»
«Організація перевезень і управління на автомобільному транспорті»
 
виховна година веселка твого щастя
виховна година веселка твого щастявиховна година веселка твого щастя
виховна година веселка твого щастя
 
КПЕК ЛНТУ Body Master
КПЕК ЛНТУ Body MasterКПЕК ЛНТУ Body Master
КПЕК ЛНТУ Body Master
 
1вересня 2016
1вересня 20161вересня 2016
1вересня 2016
 
Advertisement campaign -
Advertisement campaign - Advertisement campaign -
Advertisement campaign -
 
Представлення 1 курс КПЕК ЛНТУ
Представлення 1 курс КПЕК ЛНТУПредставлення 1 курс КПЕК ЛНТУ
Представлення 1 курс КПЕК ЛНТУ
 
ГБОУДОД ДДТ "Оранианбаум"
ГБОУДОД ДДТ "Оранианбаум"ГБОУДОД ДДТ "Оранианбаум"
ГБОУДОД ДДТ "Оранианбаум"
 
NoSQL? No, SQL! - SQL, the underestimated "Big Data" technology
NoSQL? No, SQL! - SQL, the underestimated "Big Data" technologyNoSQL? No, SQL! - SQL, the underestimated "Big Data" technology
NoSQL? No, SQL! - SQL, the underestimated "Big Data" technology
 

Similar a The jOOQ Talk at the JUG-HH in Hamburg, Jan 14, 2014

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
 
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
 
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
 
NoSQL? No, SQL! – How to Calculate Running Totals - Our Talk at the JUGS Bern
NoSQL? No, SQL! – How to Calculate Running Totals - Our Talk at the JUGS BernNoSQL? No, SQL! – How to Calculate Running Totals - Our Talk at the JUGS Bern
NoSQL? No, SQL! – How to Calculate Running Totals - Our Talk at the JUGS BernDataGeekery
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + SpringBryan Hsueh
 
Java EE 7 - Novidades e Mudanças
Java EE 7 - Novidades e MudançasJava EE 7 - Novidades e Mudanças
Java EE 7 - Novidades e MudançasBruno Borges
 
As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0Bruno Borges
 
Startup eng-camp 3
Startup eng-camp 3Startup eng-camp 3
Startup eng-camp 3Jollen Chen
 
Going Offline with Gears And GWT
Going Offline with Gears And GWTGoing Offline with Gears And GWT
Going Offline with Gears And GWTtom.peck
 
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishJava API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishArun Gupta
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Startedguest1af57e
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Jonas Follesø
 
A little bit about code injection in WebApplication Frameworks (CVE-2018-1466...
A little bit about code injection in WebApplication Frameworks (CVE-2018-1466...A little bit about code injection in WebApplication Frameworks (CVE-2018-1466...
A little bit about code injection in WebApplication Frameworks (CVE-2018-1466...ufpb
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax Wrajivmordani
 
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)Shing Wai Chan
 
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta jaxconf
 
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun GuptaGetting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun GuptaCodemotion
 
Ingesting streaming data for analysis in apache ignite (stream sets theme)
Ingesting streaming data for analysis in apache ignite (stream sets theme)Ingesting streaming data for analysis in apache ignite (stream sets theme)
Ingesting streaming data for analysis in apache ignite (stream sets theme)Tom Diederich
 

Similar a The jOOQ Talk at the JUG-HH in Hamburg, Jan 14, 2014 (20)

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
 
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
 
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
 
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
 
NoSQL? No, SQL! – How to Calculate Running Totals - Our Talk at the JUGS Bern
NoSQL? No, SQL! – How to Calculate Running Totals - Our Talk at the JUGS BernNoSQL? No, SQL! – How to Calculate Running Totals - Our Talk at the JUGS Bern
NoSQL? No, SQL! – How to Calculate Running Totals - Our Talk at the JUGS Bern
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
 
Java EE 7 - Novidades e Mudanças
Java EE 7 - Novidades e MudançasJava EE 7 - Novidades e Mudanças
Java EE 7 - Novidades e Mudanças
 
As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0As novidades do Java EE 7: do HTML5 ao JMS 2.0
As novidades do Java EE 7: do HTML5 ao JMS 2.0
 
Startup eng-camp 3
Startup eng-camp 3Startup eng-camp 3
Startup eng-camp 3
 
Going Offline with Gears And GWT
Going Offline with Gears And GWTGoing Offline with Gears And GWT
Going Offline with Gears And GWT
 
Java API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFishJava API for WebSocket 1.0: Java EE 7 and GlassFish
Java API for WebSocket 1.0: Java EE 7 and GlassFish
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Started
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008
 
TDC 2016 - Arquitetura Java - Spring Cloud
TDC 2016 - Arquitetura Java - Spring CloudTDC 2016 - Arquitetura Java - Spring Cloud
TDC 2016 - Arquitetura Java - Spring Cloud
 
A little bit about code injection in WebApplication Frameworks (CVE-2018-1466...
A little bit about code injection in WebApplication Frameworks (CVE-2018-1466...A little bit about code injection in WebApplication Frameworks (CVE-2018-1466...
A little bit about code injection in WebApplication Frameworks (CVE-2018-1466...
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax W
 
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
JavaOne Shanghai 2013 - Servlet 3.1 (JSR 340)
 
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta Getting started with Websocket and Server-sent Events using Java - Arun Gupta
Getting started with Websocket and Server-sent Events using Java - Arun Gupta
 
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun GuptaGetting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
Getting Started with WebSocket and Server-Sent Events using Java by Arun Gupta
 
Ingesting streaming data for analysis in apache ignite (stream sets theme)
Ingesting streaming data for analysis in apache ignite (stream sets theme)Ingesting streaming data for analysis in apache ignite (stream sets theme)
Ingesting streaming data for analysis in apache ignite (stream sets theme)
 

Último

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Último (20)

Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

The jOOQ Talk at the JUG-HH in Hamburg, Jan 14, 2014

  • 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. Slides licensed under CC BY SA 3.0
  • 2. 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. Slides licensed under CC BY SA 3.0 jOOQ Examples
  • 3. Intro SQL and Java jOOQ Examples SQL and Java – in theory Java one jack SQL one plug In this metaphor, electricity is the data (SQL) that flows into your appliance / application (Java) Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
  • 4. Intro SQL and Java jOOQ Examples SQL and Java – in practice Java SQL one jack lots of plugs Images from: http://en.wikipedia.org/wiki/AC_power_plugs_and_sockets. License: public domain Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
  • 5. 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. Slides licensed under CC BY SA 3.0 Examples
  • 6. 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. Slides licensed under CC BY SA 3.0 jOOQ Examples
  • 7. 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()); } // // Wrong column name // ojdbc6: clob.free() should be called // rs.close(); stmt.close(); // close() not really in finally block // Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
  • 8. Intro SQL and Java jOOQ Examples What JDBC means for developers With JDBC, your developers have to do a lot of manual, error-prone (dangerous) and inefficient work Images from Flickr. To the left by: Matthew Straubmuller, Greg Grossmeier. License: CC BY SA 2.0. Electric Engineers to the right copyright by Marco Sarli, all rights reserved. Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
  • 9. 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. Slides licensed under CC BY SA 3.0 jOOQ Examples
  • 10. Intro SQL and Java 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. Slides licensed under CC BY SA 3.0 jOOQ Examples
  • 11. 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. Slides licensed under CC BY SA 3.0 jOOQ Examples
  • 12. 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. Slides licensed under CC BY SA 3.0 jOOQ Examples
  • 13. 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. Slides licensed under CC BY SA 3.0 Examples
  • 14. 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. Slides licensed under CC BY SA 3.0 Examples
  • 15. 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. Slides licensed under CC BY SA 3.0 Examples
  • 16. Intro SQL and Java jOOQ Examples EJB 3.0 – Annotatiomania™ @OneToMany(mappedBy = "destCustomerId") @ManyToMany @Fetch(FetchMode.SUBSELECT) @JoinTable( name = "customer_dealer_map", joinColumns = { @JoinColumn(name = "customer_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "dealer_id", referencedColumnName = "id") } ) private Collection dealers; Found at http://stackoverflow.com/q/17491912/521799 Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
  • 17. Intro SQL and Java jOOQ Examples JPA 3.0 Preview – Annotatiomania™ @OneToMany @OneToManyMore @AnyOne @AnyBody @ManyToMany @Many @Fetch @FetchMany @FetchWithDiscriminator(name = "no_name") @JoinTable(joinColumns = { @JoinColumn(name = "customer_id", referencedColumnName = "id") }) @PrefetchJoinWithDiscriminator @IfJoiningAvoidHashJoins @ButUseHashJoinsWhenMoreThan(records = 1000) @XmlDataTransformable @SpringPrefechAdapter private Collection employees; Might not be true Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
  • 18. Intro SQL and Java jOOQ Examples What JPA means for developers… With JPA, your developers use a huge framework with lots of complexity that can get hard to manage Images from Wikimedia. License: public domain. High voltage power lines by Simon Koopmann. License: CC-BY SA 3.0 Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
  • 19. Intro SQL and Java jOOQ Examples … when developers actually wanted this Java one jack Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SQL one plug
  • 20. Intro SQL and Java NoSQL? … … so, should we maybe abandon SQL? Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 jOOQ Examples
  • 21. Intro SQL and Java jOOQ NoSQL? Nope! Seen at the O’Reilly Strata Conf: History of NoSQL by Mark Madsen. Picture published by Edd Dumbill Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Examples
  • 22. Intro SQL and Java jOOQ Examples SQL is so much more | TEXT | VOTES | RANK | PERCENT | |-------------|-------|------------|---------| | Hibernate | 1383 | 1 | 32 % | | jOOQ | 1029 | 2 | 23 % | | EclipseLink | 881 | 3 | 20 % | | JDBC | 533 | 4 | 12 % | | Spring JDBC | 451 | 5 | 10 % | Data may not be accurate… Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
  • 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. Slides licensed under CC BY SA 3.0 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. Slides licensed under CC BY SA 3.0 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. Slides licensed under CC BY SA 3.0 Examples
  • 26. Intro SQL and Java jOOQ Examples What jOOQ means for developers Java jOOQ SQL one jack one adaptor all plugs With jOOQ, Java plugs into SQL intuitively, letting your developers focus on business-logic again. Images from Wikimedia. License: public domain. Travel converter by Cephira. License: CC-BY SA 3.0 Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
  • 27. Intro SQL and Java Examples Copyright (c) 2009-2013 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 jOOQ Examples