SlideShare a Scribd company logo
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Get Back in Control of your SQL
SQL and Java could work
together so much better if
we only let them.
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Me – @lukaseder
SQL is a device whose mystery
is only exceeded by its power!
- Founder and CEO at Data Geekery
- Oracle Java Champion
- JUG.ch Board Member
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Let’s talk about
SQL
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
SQL is Powerful!
My Reaction when I
forget the WHERE
clause on my DELETE
statement…
With autocommit
active
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
SQL and Java – in theory
Java SQL
In this metaphor, electricity is the data (SQL) that
flows into your appliance / application (Java)
one jack one plug
Copyright (c) 2009-2015 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
Images from: http://en.wikipedia.org/wiki/AC_power_plugs_and_sockets. License: public domain
one jack lots of plugs
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
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-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
JDBC – the naked truth
01: PreparedStatement stmt = connection.prepareStatement(
02: "SELECT p.text txt" +
03: (isAccount ? ", NVL(a.type, ?) " : "") +
04: "FROM products p " +
05: (isAccount ? " INNER JOIN accounts a USING (prod_id) " : "") +
06: " WHERE p.cust_id = ? AND p.value < ?" +
07: (isAccount ? " AND a.type LIKE '%" + type + "%'" : ""));
08: stmt.setInt(1, defaultType);
09: stmt.setInt(2, custID);
10: stmt.setBigDecimal(3, BigDecimal.ZERO);
11: ResultSet rs = stmt.executeQuery();
12:
13: while (rs.next()) {
14: Clob clob = rs.getClob("TEXT");
15: System.out.println(clob.getSubString(1, (int) clob.length()));
16: }
17:
18: rs.close();
19: stmt.close();
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
JDBC – the naked truth
01: PreparedStatement stmt = connection.prepareStatement( //
02: "SELECT p.text txt" + //
03: (isAccount ? ", NVL(a.type, ?) " : "") + //
04: "FROM products p " + // Syntax error when isAccount == false
05: (isAccount ? " INNER JOIN accounts a USING (prod_id) " : "") + //
06: " WHERE p.cust_id = ? AND p.value < ?" + //
07: (isAccount ? " AND a.type LIKE '%" + type + "%'" : "")); // Syntax error and SQL injection possible
08: stmt.setInt(1, defaultType); // Wrong bind index
09: stmt.setInt(2, custID); //
10: stmt.setBigDecimal(3, BigDecimal.ZERO); //
11: ResultSet rs = stmt.executeQuery(); //
12:
13: while (rs.next()) { //
14: Clob clob = rs.getClob("TEXT"); // Wrong column name
15: System.out.println(clob.getSubString(1, (int) clob.length())); // ojdbc6: clob.free() should be called
16: } //
17:
18: rs.close(); // close() not really in finally block
19: stmt.close(); //
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
What JDBC means for developers
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.
With JDBC, your developers have to do a lot of
manual, error-prone (dangerous) and inefficient work
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
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-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
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-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
EJB 2.0 – the naked truth
<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-…>
</persistence>
o_O
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
EJB 2.0
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
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-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
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-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
EJB 3.0 – Yep, annotations!
@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-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
JPA 3.0 Preview – Annotatiomania™
@SeveralAndThenNothing @MaybeThisDoesSomething
@TweakThisWithThat(
tweak = {
@TweakID(name = "id", preferredValue = 1839),
@TweakID(name = "test", preferredValue = 839),
@TweakID(name = "test.old", preferredValue = 34),
},
inCaseOf = {
@ConditionalXMLFiltering(run = 5),
}
)
@OneToMany @OneToManyMore @AnyOne @AnyBody @DoesThisEvenMeanAnything @DoesAnyoneEvenReadThis
@ManyToMany @Many @AnnotationsTotallyRock @DeclarativeProgrammingRules @NoMoreExplicitAlgorithms
@Fetch @FetchMany @FetchWithDiscriminator(name = "no_name")
@JoinTable(joinColumns = {
@JoinColumn(name = "customer_id", referencedColumnName = "id")
})
@PrefetchJoinWithDiscriminator @JustTrollingYouKnow @LOL
@IfJoiningAvoidHashJoins @ButUseHashJoinsWhenMoreThan(records = 1000)
@XmlDataTransformable @SpringPrefechAdapter
private Collection employees;
Might not be true
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
What’s next?
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Ask the industry experts
www.annotatiomania.com
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Albert Einstein
I don’t know with
what annotations
JPA III will ship,
but JPA IV will
ship with sticks
and stones
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
JPA 4.0 Preview
var employees;
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
What JPA means for developers…
Images from Wikimedia. License: public domain. High voltage power lines by Simon Koopmann. License: CC-BY SA 3.0
With JPA, your developers use a huge framework with
lots of complexity that can get hard to manage
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
… when developers actually wanted this
Java SQL
one jack one plug
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Note, we’re talking about SQL. Not Persistence…
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Note, we’re talking about SQL. Not Persistence…
FYI: Gavin King: Creator of Hibernate!
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
NoSQL?
…
… so, should we maybe abandon SQL?
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Big Data? What is it?
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Source: www.itproportal.com
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Seriously, MongoDB?
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
NoSQL? Who said it?
Our service ran at 99.99 percent
uptime in the first quarter of 2009,
runs more than 200 million
transactions a day, and has subsecond
response time; and we are constantly
making advances to deliver it even
faster.
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
NoSQL? Marc Benioff – salesforce.com
Our service ran at 99.99 percent
uptime in the first quarter of 2009,
runs more than 200 million
transactions a day, and has subsecond
response time; and we are constantly
making advances to deliver it even
faster.
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
NoSQL? Marc Benioff – salesforce.com
He’s talking about
salesforce.com’s
Oracle database.
He “invented” the
cloud
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
NoSQL? Who said it?
• 300 TB of data files for production
DBs in total
• LHC logging database ~140TB,
expected growth up to ~70 TB /
year
• 13 Production experiments'
database ~120 TB in total
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
NoSQL? Collecting LHC data with Oracle Exadata
• 300 TB of data files for production
DBs in total
• LHC logging database ~140TB,
expected growth up to ~70 TB /
year
• 13 Production experiments'
database ~120 TB in total
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
NoSQL? Stack Overflow on 1 SQL Server Instance
http://stackexchange.com/performance
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
NoSQL for Big Data?
- You’re giving up on ACID
- You’re giving up on type safety
- You’re giving up on standards
- You’re giving up on tooling
- You’re giving up on relational algebra
- You haven’t asked operations
- You don’t actually have «Big Data»
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
NoSQL for Big Data?
- You’re giving up on ACID
- You’re giving up on type safety
- You’re giving up on standards
- You’re giving up on tooling
- You’re giving up on relational algebra
- You haven’t asked operations
- You don’t actually have «Big Data»
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Seen at the O’Reilly Strata Conf:
History of NoSQL by Mark Madsen. Picture published by Edd Wilder-James
NoSQL? No, SQL!
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
So, let’s talk about
SQL
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
NoSQL? No, SQL!
So, let’s talk about
SQL
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Let’s calculate a running total
| ID | VALUE_DATE | AMOUNT |
|------|------------|--------|
| 9997 | 2014-03-18 | 99.17 |
| 9981 | 2014-03-16 | 71.44 |
| 9979 | 2014-03-16 | -94.60 |
| 9977 | 2014-03-16 | -6.96 |
| 9971 | 2014-03-15 | -65.95 |
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Let’s calculate a running total
| ID | VALUE_DATE | AMOUNT | BALANCE |
|------|------------|--------|------------|
| 9997 | 2014-03-18 | 99.17 | 19985.81 |
| 9981 | 2014-03-16 | 71.44 | 19886.64 |
| 9979 | 2014-03-16 | -94.60 | 19815.20 |
| 9977 | 2014-03-16 | -6.96 | 19909.80 |
| 9971 | 2014-03-15 | -65.95 | 19916.76 |
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Let’s calculate a running total
| ID | VALUE_DATE | AMOUNT | BALANCE |
|------|------------|--------|------------|
| 9997 | 2014-03-18 | +99.17 =19985.81 |
| 9981 | 2014-03-16 | 71.44 | +19886.64 |
| 9979 | 2014-03-16 | -94.60 | 19815.20 |
| 9977 | 2014-03-16 | -6.96 | 19909.80 |
| 9971 | 2014-03-15 | -65.95 | 19916.76 |
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Let’s calculate a running total
| ID | VALUE_DATE | AMOUNT | BALANCE |
|------|------------|--------|------------|
| 9997 | 2014-03-18 | 99.17 | 19985.81 |
| 9981 | 2014-03-16 | +71.44 =19886.64 |
| 9979 | 2014-03-16 | -94.60 | +19815.20 |
| 9977 | 2014-03-16 | -6.96 | 19909.80 |
| 9971 | 2014-03-15 | -65.95 | 19916.76 |
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Let’s calculate a running total
| ID | VALUE_DATE | AMOUNT | BALANCE |
|------|------------|--------|------------|
| 9997 | 2014-03-18 | 99.17 | 19985.81 |
| 9981 | 2014-03-16 | +71.44 =19886.64 | n
| 9979 | 2014-03-16 | -94.60 | +19815.20 | n+1
| 9977 | 2014-03-16 | -6.96 | 19909.80 |
| 9971 | 2014-03-15 | -65.95 | 19916.76 |BALANCE(ROWn) = BALANCE(ROWn+1) + AMOUNT(ROWn)
BALANCE(ROWn+1) = BALANCE(ROWn) – AMOUNT(ROWn)
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
SELECT
t.*,
t.current_balance - NVL(
SUM(t.amount) OVER (
PARTITION BY t.account_id
ORDER BY t.value_date DESC,
t.id DESC
ROWS BETWEEN UNBOUNDED PRECEDING
AND 1 PRECEDING
),
0) AS balance
FROM v_transactions t
WHERE t.account_id = 1
ORDER BY t.value_date DESC,
t.id DESC
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
SUM(t.amount) OVER (
PARTITION BY t.account_id
ORDER BY t.value_date DESC,
t.id DESC
ROWS BETWEEN UNBOUNDED PRECEDING
AND 1 PRECEDING
)
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
SUM(t.amount) OVER (
PARTITION BY t.account_id
ORDER BY t.value_date DESC,
t.id DESC
ROWS BETWEEN UNBOUNDED PRECEDING
AND 1 PRECEDING
)
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
SUM(t.amount) OVER (
PARTITION BY t.account_id
ORDER BY t.value_date DESC,
t.id DESC
ROWS BETWEEN UNBOUNDED PRECEDING
AND 1 PRECEDING
)
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
SUM(t.amount) OVER (
PARTITION BY t.account_id
ORDER BY t.value_date DESC,
t.id DESC
ROWS BETWEEN UNBOUNDED PRECEDING
AND 1 PRECEDING
)
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
| ID | VALUE_DATE | AMOUNT | BALANCE |
|------|------------|--------|------------|
| 9997 | 2014-03-18 -(99.17)| +19985.81 |
| 9981 | 2014-03-16 -(71.44)| 19886.64 |
| 9979 | 2014-03-16 -(-94.60)| 19815.20 |
| 9977 | 2014-03-16 | -6.96 | =19909.80 |
| 9971 | 2014-03-15 | -65.95 | 19916.76 |
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
We can help
www.jooq.org/training
SQL Wizardry?
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
More SQL Calculations
| TEXT | VOTES | RANK | PERCENT |
|-------------|-------|------------|---------|
| jOOQ | 1383 | 1 | 32 % |
| Hibernate | 1029 | 2 | 23 % |
| EclipseLink | 881 | 3 | 20 % |
| JDBC | 533 | 4 | 12 % |
| Spring JDBC | 451 | 5 | 10 % |
Data may not be accurate…
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
More SQL Calculations
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-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
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-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
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-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
What jOOQ means for developers
Java SQL
one jack all plugs
jOOQ
one adaptor
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-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
What jOOQ means for developers
Java SQL
one jack all plugs
jOOQ
one adaptor
Images from Wikimedia. License: public domain. Travel converter by Cephira. License: CC-BY SA 3.0
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Code generation
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Code generation
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Code generation
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Use the generated code
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Auto completion on columns
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Type checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Type checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Type checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Type checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Type checking with Java 8
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Type checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Type checking – Opt out if you want
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Type checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Type checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Type checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Standardisation – Oracle
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Standardisation – SQL Server
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Standardisation – SQLite
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Standardisation
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Standardisation – PostgreSQL
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Standardisation – Oracle 11g
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Standardisation – DB2
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Syntax checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Syntax checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Syntax checking
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Active Records
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Active Records
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – But of course, DML too
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Stored Procedures
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Stored Procedures
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Examples – Stored Procedures
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
Marc Benioff from salesforce
All companies
benefit when they
can afford to focus
on innovation
rather than
infrastructure
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
A vision of a better SQL application
- Database first
- Performance
- Type safe JDBC
- Code Generation
- Active Records
- Stored Procedures
- SQL Transformation
- SQL Standardisation
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
«jOOQ» 10% discount code
A book recommendation
Markus Winand from
Use-The-Index-Luke.com
ROI north of 83’174%
Achieve proper indexing and
performance in popular RDBMS
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
«jOOQ» 20% discount code
A book recommendation (in the making)
Vlad Mihalcea from
vladmihalcea.com
JDBC, JPA, jOOQ
Performance, Scaling
https://leanpub.com/high-performance-java-persistence/c/jOOQ
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
And a shameless tool recommendation
Open source databases:
- Free / Apache license
Commercial databases:
- Commercial license
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
1. Everything is a table – Compare it to
Java 8
TABLE : Stream<Tuple<..>>
SELECT : map()
DISTINCT : distinct()
JOIN : flatMap()
WHERE / HAVING : filter()
GROUP BY : collect()
ORDER BY : sorted()
UNION ALL : concat()
See:
http://blog.jooq.org/2015/08/13/common-sql-clauses-and-their-equivalents-in-java-8-streams/
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
1. Everything is a table – Compare it to
Java 8
Better Streams:
https://github.com/jOOQ/jOOL
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Seq.seq(persons)
.collect(
count(),
max(Person::getAge),
min(Person::getHeight),
avg(Person::getWeight)
);
// (3, Optional[35],
// Optional[1.69], Optional[70.0])
Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0
Intro SQL and Java jOOQ Examples
That’s it folks
More free Java / SQL knowledge on:
• Blog: http://blog.jooq.org
• Twitter: @JavaOOQ / @lukaseder
• Newsletter: http://www.jooq.org

More Related Content

PPTX
Move from J2EE to Java EE
PPT
Have You Seen Java EE Lately?
PDF
What's coming in Java EE 8
PDF
Java EE 8 - An instant snapshot
PDF
Java EE Revisits GoF Design Patterns
PDF
Java EE 7 - Overview and Status
PDF
Finally, EE Security API JSR 375
PDF
Java EE 8: On the Horizon
Move from J2EE to Java EE
Have You Seen Java EE Lately?
What's coming in Java EE 8
Java EE 8 - An instant snapshot
Java EE Revisits GoF Design Patterns
Java EE 7 - Overview and Status
Finally, EE Security API JSR 375
Java EE 8: On the Horizon

What's hot (15)

PDF
EJB and CDI - Alignment and Strategy
PPTX
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
PPT
JavaScript Frameworks and Java EE – A Great Match
PPT
Testing Java EE Applications Using Arquillian
PPT
What's New in WebLogic 12.1.3 and Beyond
PDF
Java EE 7 overview
PPT
GlassFish BOF
PPT
Java EE and Spring Side-by-Side
PDF
Java EE 8 Recipes
PPTX
Geecon 2017 Anatomy of Java Vulnerabilities
PPT
The Anatomy of Java Vulnerabilities (Devoxx UK 2017)
PPTX
Construindo aplicações com HTML5, WebSockets, e Java EE 7
PPTX
Java ee 8 + security overview
PPTX
Top 50 java ee 7 best practices [con5669]
PDF
JavaOne 2011: Migrating Spring Applications to Java EE 6
EJB and CDI - Alignment and Strategy
HTTP/2 comes to Java. What Servlet 4.0 means to you. DevNexus 2015
JavaScript Frameworks and Java EE – A Great Match
Testing Java EE Applications Using Arquillian
What's New in WebLogic 12.1.3 and Beyond
Java EE 7 overview
GlassFish BOF
Java EE and Spring Side-by-Side
Java EE 8 Recipes
Geecon 2017 Anatomy of Java Vulnerabilities
The Anatomy of Java Vulnerabilities (Devoxx UK 2017)
Construindo aplicações com HTML5, WebSockets, e Java EE 7
Java ee 8 + security overview
Top 50 java ee 7 best practices [con5669]
JavaOne 2011: Migrating Spring Applications to Java EE 6
Ad

Viewers also liked (8)

DOCX
Ip project work test your knowledge
PPTX
Modul Kelas Programming : Java MySQL
PPTX
DOCX
informatics practices practical file
PPTX
PPT FOR ONLINE HOTEL MANAGEMENT
PPT
Investigatory Project
DOC
Ip project
PPT
Tic tac toe c++ project presentation
Ip project work test your knowledge
Modul Kelas Programming : Java MySQL
informatics practices practical file
PPT FOR ONLINE HOTEL MANAGEMENT
Investigatory Project
Ip project
Tic tac toe c++ project presentation
Ad

Similar to Best Way to Write SQL in Java (20)

PDF
Get Back in Control of Your SQL - #33rdDegree
PDF
The Awesome jOOQ JavaOne Talk
PDF
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
PDF
The jOOQ Talk at the JUG-HH in Hamburg, Jan 14, 2014
PDF
The vJUG talk about jOOQ: Get Back in Control of Your SQL
PDF
jOOQ at Topconf 2013
PDF
Get Back in Control of Your SQL with jOOQ at #Java2Days
PDF
Get Back in Control of your SQL
PDF
2000 lines of java or 50 lines of sql the choice is yours - Lukas Eder
PPTX
Java Database Connectivity (JDBC) ppt by Aamir Rafique.pptx
PDF
Presentation for java data base connectivity
PDF
Introduction to jOOQ
PPTX
Database Programming Techniques
PPT
Jdbc oracle
PPTX
Jdbc presentation
PDF
Java OOP Programming language (Part 8) - Java Database JDBC
PPT
JDBC Connectivity Model
PDF
PPTX
Lecture 1. java database connectivity
Get Back in Control of Your SQL - #33rdDegree
The Awesome jOOQ JavaOne Talk
Get Back in Control of your SQL with jOOQ - GeekOut by ZeroTurnaround
The jOOQ Talk at the JUG-HH in Hamburg, Jan 14, 2014
The vJUG talk about jOOQ: Get Back in Control of Your SQL
jOOQ at Topconf 2013
Get Back in Control of Your SQL with jOOQ at #Java2Days
Get Back in Control of your SQL
2000 lines of java or 50 lines of sql the choice is yours - Lukas Eder
Java Database Connectivity (JDBC) ppt by Aamir Rafique.pptx
Presentation for java data base connectivity
Introduction to jOOQ
Database Programming Techniques
Jdbc oracle
Jdbc presentation
Java OOP Programming language (Part 8) - Java Database JDBC
JDBC Connectivity Model
Lecture 1. java database connectivity

More from Gerger (13)

PDF
Source Control for the Oracle Database
PDF
Big Data for Oracle Professionals
PDF
Apache Spark, the Next Generation Cluster Computing
PDF
Version control for PL/SQL
PDF
Gitora, Version Control for PL/SQL
PDF
Gitora, Version Control for PL/SQL
PDF
PostgreSQL for Oracle Developers and DBA's
PDF
Shaping Optimizer's Search Space
PDF
Gitora, Version Control for PL/SQL
PDF
Monitoring Oracle Database Instances with Zabbix
PDF
Introducing ProHuddle
PDF
Use Cases of Row Pattern Matching in Oracle 12c
PDF
Introducing Gitora,the version control tool for PL/SQL
Source Control for the Oracle Database
Big Data for Oracle Professionals
Apache Spark, the Next Generation Cluster Computing
Version control for PL/SQL
Gitora, Version Control for PL/SQL
Gitora, Version Control for PL/SQL
PostgreSQL for Oracle Developers and DBA's
Shaping Optimizer's Search Space
Gitora, Version Control for PL/SQL
Monitoring Oracle Database Instances with Zabbix
Introducing ProHuddle
Use Cases of Row Pattern Matching in Oracle 12c
Introducing Gitora,the version control tool for PL/SQL

Recently uploaded (20)

PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
L1 - Introduction to python Backend.pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
medical staffing services at VALiNTRY
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
System and Network Administration Chapter 2
PPT
Introduction Database Management System for Course Database
PPTX
assetexplorer- product-overview - presentation
PPTX
history of c programming in notes for students .pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PTS Company Brochure 2025 (1).pdf.......
VVF-Customer-Presentation2025-Ver1.9.pptx
L1 - Introduction to python Backend.pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Softaken Excel to vCard Converter Software.pdf
Digital Systems & Binary Numbers (comprehensive )
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Upgrade and Innovation Strategies for SAP ERP Customers
medical staffing services at VALiNTRY
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
System and Network Administration Chapter 2
Introduction Database Management System for Course Database
assetexplorer- product-overview - presentation
history of c programming in notes for students .pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Wondershare Filmora 15 Crack With Activation Key [2025

Best Way to Write SQL in Java

  • 1. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Get Back in Control of your SQL SQL and Java could work together so much better if we only let them.
  • 2. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Me – @lukaseder SQL is a device whose mystery is only exceeded by its power! - Founder and CEO at Data Geekery - Oracle Java Champion - JUG.ch Board Member
  • 3. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Let’s talk about SQL
  • 4. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples SQL is Powerful! My Reaction when I forget the WHERE clause on my DELETE statement… With autocommit active
  • 5. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples SQL and Java – in theory Java SQL In this metaphor, electricity is the data (SQL) that flows into your appliance / application (Java) one jack one plug
  • 6. Copyright (c) 2009-2015 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 Images from: http://en.wikipedia.org/wiki/AC_power_plugs_and_sockets. License: public domain one jack lots of plugs
  • 7. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples 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")); }
  • 8. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples JDBC – the naked truth 01: PreparedStatement stmt = connection.prepareStatement( 02: "SELECT p.text txt" + 03: (isAccount ? ", NVL(a.type, ?) " : "") + 04: "FROM products p " + 05: (isAccount ? " INNER JOIN accounts a USING (prod_id) " : "") + 06: " WHERE p.cust_id = ? AND p.value < ?" + 07: (isAccount ? " AND a.type LIKE '%" + type + "%'" : "")); 08: stmt.setInt(1, defaultType); 09: stmt.setInt(2, custID); 10: stmt.setBigDecimal(3, BigDecimal.ZERO); 11: ResultSet rs = stmt.executeQuery(); 12: 13: while (rs.next()) { 14: Clob clob = rs.getClob("TEXT"); 15: System.out.println(clob.getSubString(1, (int) clob.length())); 16: } 17: 18: rs.close(); 19: stmt.close();
  • 9. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples JDBC – the naked truth 01: PreparedStatement stmt = connection.prepareStatement( // 02: "SELECT p.text txt" + // 03: (isAccount ? ", NVL(a.type, ?) " : "") + // 04: "FROM products p " + // Syntax error when isAccount == false 05: (isAccount ? " INNER JOIN accounts a USING (prod_id) " : "") + // 06: " WHERE p.cust_id = ? AND p.value < ?" + // 07: (isAccount ? " AND a.type LIKE '%" + type + "%'" : "")); // Syntax error and SQL injection possible 08: stmt.setInt(1, defaultType); // Wrong bind index 09: stmt.setInt(2, custID); // 10: stmt.setBigDecimal(3, BigDecimal.ZERO); // 11: ResultSet rs = stmt.executeQuery(); // 12: 13: while (rs.next()) { // 14: Clob clob = rs.getClob("TEXT"); // Wrong column name 15: System.out.println(clob.getSubString(1, (int) clob.length())); // ojdbc6: clob.free() should be called 16: } // 17: 18: rs.close(); // close() not really in finally block 19: stmt.close(); //
  • 10. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples What JDBC means for developers 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. With JDBC, your developers have to do a lot of manual, error-prone (dangerous) and inefficient work
  • 11. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples 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); }
  • 12. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples 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>
  • 13. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples EJB 2.0 – the naked truth <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-…> </persistence> o_O
  • 14. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples EJB 2.0
  • 15. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples 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();
  • 16. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples 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() { /* … */ }
  • 17. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples EJB 3.0 – Yep, annotations! @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
  • 18. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples JPA 3.0 Preview – Annotatiomania™ @SeveralAndThenNothing @MaybeThisDoesSomething @TweakThisWithThat( tweak = { @TweakID(name = "id", preferredValue = 1839), @TweakID(name = "test", preferredValue = 839), @TweakID(name = "test.old", preferredValue = 34), }, inCaseOf = { @ConditionalXMLFiltering(run = 5), } ) @OneToMany @OneToManyMore @AnyOne @AnyBody @DoesThisEvenMeanAnything @DoesAnyoneEvenReadThis @ManyToMany @Many @AnnotationsTotallyRock @DeclarativeProgrammingRules @NoMoreExplicitAlgorithms @Fetch @FetchMany @FetchWithDiscriminator(name = "no_name") @JoinTable(joinColumns = { @JoinColumn(name = "customer_id", referencedColumnName = "id") }) @PrefetchJoinWithDiscriminator @JustTrollingYouKnow @LOL @IfJoiningAvoidHashJoins @ButUseHashJoinsWhenMoreThan(records = 1000) @XmlDataTransformable @SpringPrefechAdapter private Collection employees; Might not be true
  • 19. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples What’s next?
  • 20. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Ask the industry experts www.annotatiomania.com
  • 21. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Albert Einstein I don’t know with what annotations JPA III will ship, but JPA IV will ship with sticks and stones
  • 22. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples JPA 4.0 Preview var employees;
  • 23. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples What JPA means for developers… Images from Wikimedia. License: public domain. High voltage power lines by Simon Koopmann. License: CC-BY SA 3.0 With JPA, your developers use a huge framework with lots of complexity that can get hard to manage
  • 24. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples … when developers actually wanted this Java SQL one jack one plug
  • 25. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Note, we’re talking about SQL. Not Persistence…
  • 26. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Note, we’re talking about SQL. Not Persistence… FYI: Gavin King: Creator of Hibernate!
  • 27. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples NoSQL? … … so, should we maybe abandon SQL?
  • 28. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Big Data? What is it?
  • 29. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples
  • 30. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Source: www.itproportal.com
  • 31. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Seriously, MongoDB?
  • 32. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples NoSQL? Who said it? Our service ran at 99.99 percent uptime in the first quarter of 2009, runs more than 200 million transactions a day, and has subsecond response time; and we are constantly making advances to deliver it even faster.
  • 33. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples NoSQL? Marc Benioff – salesforce.com Our service ran at 99.99 percent uptime in the first quarter of 2009, runs more than 200 million transactions a day, and has subsecond response time; and we are constantly making advances to deliver it even faster.
  • 34. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples NoSQL? Marc Benioff – salesforce.com He’s talking about salesforce.com’s Oracle database. He “invented” the cloud
  • 35. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples NoSQL? Who said it? • 300 TB of data files for production DBs in total • LHC logging database ~140TB, expected growth up to ~70 TB / year • 13 Production experiments' database ~120 TB in total
  • 36. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples NoSQL? Collecting LHC data with Oracle Exadata • 300 TB of data files for production DBs in total • LHC logging database ~140TB, expected growth up to ~70 TB / year • 13 Production experiments' database ~120 TB in total
  • 37. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples NoSQL? Stack Overflow on 1 SQL Server Instance http://stackexchange.com/performance
  • 38. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples NoSQL for Big Data? - You’re giving up on ACID - You’re giving up on type safety - You’re giving up on standards - You’re giving up on tooling - You’re giving up on relational algebra - You haven’t asked operations - You don’t actually have «Big Data»
  • 39. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples NoSQL for Big Data? - You’re giving up on ACID - You’re giving up on type safety - You’re giving up on standards - You’re giving up on tooling - You’re giving up on relational algebra - You haven’t asked operations - You don’t actually have «Big Data»
  • 40. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Seen at the O’Reilly Strata Conf: History of NoSQL by Mark Madsen. Picture published by Edd Wilder-James NoSQL? No, SQL!
  • 41. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples So, let’s talk about SQL
  • 42. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples NoSQL? No, SQL! So, let’s talk about SQL
  • 43. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Let’s calculate a running total | ID | VALUE_DATE | AMOUNT | |------|------------|--------| | 9997 | 2014-03-18 | 99.17 | | 9981 | 2014-03-16 | 71.44 | | 9979 | 2014-03-16 | -94.60 | | 9977 | 2014-03-16 | -6.96 | | 9971 | 2014-03-15 | -65.95 |
  • 44. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Let’s calculate a running total | ID | VALUE_DATE | AMOUNT | BALANCE | |------|------------|--------|------------| | 9997 | 2014-03-18 | 99.17 | 19985.81 | | 9981 | 2014-03-16 | 71.44 | 19886.64 | | 9979 | 2014-03-16 | -94.60 | 19815.20 | | 9977 | 2014-03-16 | -6.96 | 19909.80 | | 9971 | 2014-03-15 | -65.95 | 19916.76 |
  • 45. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Let’s calculate a running total | ID | VALUE_DATE | AMOUNT | BALANCE | |------|------------|--------|------------| | 9997 | 2014-03-18 | +99.17 =19985.81 | | 9981 | 2014-03-16 | 71.44 | +19886.64 | | 9979 | 2014-03-16 | -94.60 | 19815.20 | | 9977 | 2014-03-16 | -6.96 | 19909.80 | | 9971 | 2014-03-15 | -65.95 | 19916.76 |
  • 46. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Let’s calculate a running total | ID | VALUE_DATE | AMOUNT | BALANCE | |------|------------|--------|------------| | 9997 | 2014-03-18 | 99.17 | 19985.81 | | 9981 | 2014-03-16 | +71.44 =19886.64 | | 9979 | 2014-03-16 | -94.60 | +19815.20 | | 9977 | 2014-03-16 | -6.96 | 19909.80 | | 9971 | 2014-03-15 | -65.95 | 19916.76 |
  • 47. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Let’s calculate a running total | ID | VALUE_DATE | AMOUNT | BALANCE | |------|------------|--------|------------| | 9997 | 2014-03-18 | 99.17 | 19985.81 | | 9981 | 2014-03-16 | +71.44 =19886.64 | n | 9979 | 2014-03-16 | -94.60 | +19815.20 | n+1 | 9977 | 2014-03-16 | -6.96 | 19909.80 | | 9971 | 2014-03-15 | -65.95 | 19916.76 |BALANCE(ROWn) = BALANCE(ROWn+1) + AMOUNT(ROWn) BALANCE(ROWn+1) = BALANCE(ROWn) – AMOUNT(ROWn)
  • 48. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SELECT t.*, t.current_balance - NVL( SUM(t.amount) OVER ( PARTITION BY t.account_id ORDER BY t.value_date DESC, t.id DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING ), 0) AS balance FROM v_transactions t WHERE t.account_id = 1 ORDER BY t.value_date DESC, t.id DESC
  • 49. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SUM(t.amount) OVER ( PARTITION BY t.account_id ORDER BY t.value_date DESC, t.id DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING )
  • 50. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SUM(t.amount) OVER ( PARTITION BY t.account_id ORDER BY t.value_date DESC, t.id DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING )
  • 51. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SUM(t.amount) OVER ( PARTITION BY t.account_id ORDER BY t.value_date DESC, t.id DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING )
  • 52. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SUM(t.amount) OVER ( PARTITION BY t.account_id ORDER BY t.value_date DESC, t.id DESC ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING )
  • 53. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples | ID | VALUE_DATE | AMOUNT | BALANCE | |------|------------|--------|------------| | 9997 | 2014-03-18 -(99.17)| +19985.81 | | 9981 | 2014-03-16 -(71.44)| 19886.64 | | 9979 | 2014-03-16 -(-94.60)| 19815.20 | | 9977 | 2014-03-16 | -6.96 | =19909.80 | | 9971 | 2014-03-15 | -65.95 | 19916.76 |
  • 54. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples We can help www.jooq.org/training SQL Wizardry?
  • 55. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples More SQL Calculations | TEXT | VOTES | RANK | PERCENT | |-------------|-------|------------|---------| | jOOQ | 1383 | 1 | 32 % | | Hibernate | 1029 | 2 | 23 % | | EclipseLink | 881 | 3 | 20 % | | JDBC | 533 | 4 | 12 % | | Spring JDBC | 451 | 5 | 10 % | Data may not be accurate…
  • 56. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples More SQL Calculations 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
  • 57. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples 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());
  • 58. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples 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)
  • 59. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples What jOOQ means for developers Java SQL one jack all plugs jOOQ one adaptor 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
  • 60. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples What jOOQ means for developers Java SQL one jack all plugs jOOQ one adaptor Images from Wikimedia. License: public domain. Travel converter by Cephira. License: CC-BY SA 3.0
  • 61. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples
  • 62. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples
  • 63. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Code generation
  • 64. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Code generation
  • 65. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Code generation
  • 66. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Use the generated code
  • 67. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Auto completion on columns
  • 68. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Type checking
  • 69. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Type checking
  • 70. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Type checking
  • 71. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Type checking
  • 72. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Type checking with Java 8
  • 73. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Type checking
  • 74. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Type checking – Opt out if you want
  • 75. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Type checking
  • 76. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Type checking
  • 77. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Type checking
  • 78. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Standardisation – Oracle
  • 79. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Standardisation – SQL Server
  • 80. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Standardisation – SQLite
  • 81. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Standardisation
  • 82. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Standardisation – PostgreSQL
  • 83. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Standardisation – Oracle 11g
  • 84. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Standardisation – DB2
  • 85. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Syntax checking
  • 86. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Syntax checking
  • 87. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Syntax checking
  • 88. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Active Records
  • 89. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Active Records
  • 90. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – But of course, DML too
  • 91. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Stored Procedures
  • 92. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Stored Procedures
  • 93. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Examples – Stored Procedures
  • 94. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples Marc Benioff from salesforce All companies benefit when they can afford to focus on innovation rather than infrastructure
  • 95. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples A vision of a better SQL application - Database first - Performance - Type safe JDBC - Code Generation - Active Records - Stored Procedures - SQL Transformation - SQL Standardisation
  • 96. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples «jOOQ» 10% discount code A book recommendation Markus Winand from Use-The-Index-Luke.com ROI north of 83’174% Achieve proper indexing and performance in popular RDBMS
  • 97. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples «jOOQ» 20% discount code A book recommendation (in the making) Vlad Mihalcea from vladmihalcea.com JDBC, JPA, jOOQ Performance, Scaling https://leanpub.com/high-performance-java-persistence/c/jOOQ
  • 98. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples And a shameless tool recommendation Open source databases: - Free / Apache license Commercial databases: - Commercial license
  • 99. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples 1. Everything is a table – Compare it to Java 8 TABLE : Stream<Tuple<..>> SELECT : map() DISTINCT : distinct() JOIN : flatMap() WHERE / HAVING : filter() GROUP BY : collect() ORDER BY : sorted() UNION ALL : concat() See: http://blog.jooq.org/2015/08/13/common-sql-clauses-and-their-equivalents-in-java-8-streams/
  • 100. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples 1. Everything is a table – Compare it to Java 8 Better Streams: https://github.com/jOOQ/jOOL
  • 101. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Seq.seq(persons) .collect( count(), max(Person::getAge), min(Person::getHeight), avg(Person::getWeight) ); // (3, Optional[35], // Optional[1.69], Optional[70.0])
  • 102. Copyright (c) 2009-2015 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 Intro SQL and Java jOOQ Examples That’s it folks More free Java / SQL knowledge on: • Blog: http://blog.jooq.org • Twitter: @JavaOOQ / @lukaseder • Newsletter: http://www.jooq.org