SlideShare ist ein Scribd-Unternehmen logo
1 von 57
Downloaden Sie, um offline zu lesen
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0GetBack in ControlofyourSQLSQL andJava couldworktogetherso muchbetterifweonlyletthem.
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0IntroSQL andJava jOOQ ExamplesMe –@lukaseder 
SQL is a device whose mystery is only exceeded by its power! 
-Founder and CEO at Data Geekery 
-SQL Aficionado 
-Java Aficionado
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0IntroSQL andJava jOOQ ExamplesLegal Disclaimer 
THE FOLLOWING IS COMMUNICATED TO YOU SOLELY FOR ENTERTAINMENT PURPOSES. NO ONE SANE WOULD BELIEVE A GUY WHO CLAIMS HE IS A SQL AFICIONADO OR WORSE WHO CLAIMS THAT SQL IS ANYTHING NEAR BEAUTIFUL. IF YOU STILL FIND THE FOLLOWING INTERESTING AND IF YOU BASE YOUR PURCHASING DECISIONS UPON THAT, YOU DEFINITELY NEED PROFESSIONAL HELP. WE ACTUALLY PROVIDE SUCH HELP.
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesSQL andJava –in theory 
Java 
SQL 
In thismetaphor, electricityisthedata(SQL) thatflowsintoyourappliance/ application(Java) 
onejack 
oneplug
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesSQL andJava –in practice 
Java 
SQL 
Images from: http://en.wikipedia.org/wiki/AC_power_plugs_and_sockets.License: public domain 
onejack 
lots ofplugs
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesJDBC 
PreparedStatementstmt= connection.prepareStatement( 
"SELECT textFROM productsWHERE cust_id= ? AND value< ?"); 
stmt.setInt(1, custID); 
stmt.setBigDecimal(2, BigDecimal.ZERO); 
ResultSetrs= stmt.executeQuery(); 
while(rs.next()) { 
System.out.println(rs.getString("TEXT")); 
}
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesJDBC –thenakedtruth 
01: PreparedStatementstmt= connection.prepareStatement( 
02:"SELECT p.texttxt" + 
03:(isAccount? ", NVL(a.type, ?) " :"") + 
04:"FROM productsp " + 
05:(isAccount? " INNER JOIN accountsa USING (prod_id) ": "") + 
06:" WHERE p.cust_id= ? AND p.value< ?"+ 
07:(isAccount? "AND a.typeLIKE '%"+ type + "%'": ""); 
08: stmt.setInt(1, defaultType); 
09: stmt.setInt(2, custID); 
10: stmt.setBigDecimal(3, BigDecimal.ZERO); 
11: ResultSetrs= stmt.executeQuery(); 
12: 
13: while(rs.next()) { 
14:Clobclob= rs.getClob("TEXT"); 
15:System.out.println(clob.getSubString(1, (int) clob.length()); 
16: } 
17: 
18: rs.close(); 
19: stmt.close();
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesJDBC –thenakedtruth 
01: PreparedStatementstmt= connection.prepareStatement( // 
02:"SELECT p.texttxt" + // 
03:(isAccount? ", NVL(a.type, ?) " :"") + // 
04:"FROM productsp " + // Syntax errorwhenisAccount== false 
05:(isAccount? " INNER JOIN accountsa USING (prod_id) " : "") + // 
06:" WHERE p.cust_id= ? AND p.value< ?"+ // 
07:(isAccount? "AND a.typeLIKE '%"+ type + "%'": ""); // Syntax errorandSQL injectionpossible 
08: stmt.setInt(1, defaultType); // Wrongbind index 
09: stmt.setInt(2, custID); // 
10: stmt.setBigDecimal(3, BigDecimal.ZERO); // 
11: ResultSetrs= stmt.executeQuery(); // 
12: 
13: while(rs.next()) { // 
14:Clobclob= rs.getClob("TEXT"); // Wrongcolumnname 
15:System.out.println(clob.getSubString(1, (int) clob.length());// ojdbc6: clob.free() shouldbecalled 
16: } // 
17: 
18: rs.close(); // close() not reallyin finallyblock 
19: stmt.close(); //
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesWhatJDBC meansfordevelopers 
Images fromFlickr. Totheleftby: Matthew Straubmuller, Greg Grossmeier. License:CC BY SA 2.0. Electric Engineers to the right copyright by Marco Sarli, all rights reserved. 
WithJDBC, yourdevelopershavetodo a lotofmanual, error-prone(dangerous) andinefficientwork
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 2.0 EntityBeans 
publicinterfaceCustomerRequestextendsEJBObject{ 
BigIntegergetId(); 
String getText(); 
voidsetText(String text); 
@Override 
voidremove(); 
} 
publicinterfaceCustomerRequestHomeextendsEJBHome{ 
CustomerRequestcreate(BigIntegerid); 
CustomerRequestfind(BigIntegerid); 
}
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 2.0 –thenakedtruth 
<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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 2.0 –thenakedtruth 
<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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 2.0
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesJPA andEJB 3.0 
EntityManagerem= factory.createEntityManager(); 
em.getTransaction().begin(); 
em.persist(newEvent("Conference", newDate()); 
em.persist(newEvent("After Party", newDate()); 
List result= em.createQuery("fromEvent").getResultList(); 
for(Event event: (List<Event>) result) { 
System.out.println("Event : "+ event.getTitle()); 
} 
em.getTransaction().commit(); 
em.close();
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 3.0 –thenakedtruth 
@Entity @Table(name = "EVENTS") 
public classEvent { 
privateLong id; 
privateString title; 
privateDate date; 
@Id @GeneratedValue(generator = "increment") 
@GenericGenerator(name = "increment", strategy = "increment") 
publicLong getId() { /* … */ } 
@Temporal(TemporalType.TIMESTAMP) 
@Column(name = "EVENT_DATE") 
publicDate getDate() { /* … */ }
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 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") 
} 
) 
privateCollection dealers; 
Found at http://stackoverflow.com/q/17491912/521799
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesJPA 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 
privateCollection employees; 
Might not be true
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesWhat’s next?
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesWhatJPA meansfordevelopers… 
Images fromWikimedia. License: publicdomain. High voltagepower linesbySimon Koopmann. License: CC-BY SA 3.0 
WithJPA, yourdevelopersusea hugeframeworkwithlots ofcomplexitythatcangethardtomanage
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ Examples… whendevelopersactuallywantedthis 
Java 
SQL 
onejack 
oneplug
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNote, we’retalkingaboutSQL. Not Persistence…
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNote, we’retalkingaboutSQL. Not Persistence… 
FYI: Gavin King: CreatorofHibernate!
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? 
… 
… so, shouldwemaybeabandonSQL?
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? 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 subsecondresponse time; and we are constantly making advances to deliver it even faster.
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? 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 subsecondresponse time; and we are constantly making advances to deliver it even faster.
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? Marc Benioff–salesforce.com 
He’s talking about salesforce.com’sOracle database. 
He “invented” the cloud
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? 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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? CERN, collecting LHC data 
•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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQLfor Big Data? 
-You’re giving up on ACID 
-You’re giving up on type safety 
-You’regivingupon standards 
-You’regivingupon tooling 
-You’regivingupon relational algebra 
-Youhaven’taskedoperations 
-Youdon’tactuallyhave«Big Data»
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQLfor Big Data? 
-You’re giving up on ACID 
-You’re giving up on type safety 
-You’regivingupon standards 
-You’regivingupon tooling 
-You’regivingupon relational algebra 
-Youhaven’taskedoperations 
-Youdon’tactuallyhave«Big Data»
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ Examples 
Seen at the O’Reilly Strata Conf: 
History of NoSQLbyMark Madsen. Picture published byEddDumbillNoSQL? No, SQL!
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesLet’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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesLet’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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesLet’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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesLet’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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesLet’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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 
SELECT 
t.*, 
t.current_balance-NVL( 
SUM(t.amount) OVER( 
PARTITIONBYt.account_id 
ORDERBYt.value_dateDESC, 
t.id DESC 
ROWSBETWEENUNBOUNDEDPRECEDING 
AND1 PRECEDING 
), 
0) ASbalance 
FROM v_transactionst 
WHERE t.account_id= 1 
ORDERBY t.value_dateDESC, 
t.id DESC
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 
SUM(t.amount) OVER( 
PARTITIONBYt.account_id 
ORDERBYt.value_dateDESC, 
t.id DESC 
ROWSBETWEENUNBOUNDEDPRECEDING 
AND1 PRECEDING 
)
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 
SUM(t.amount) OVER( 
PARTITIONBYt.account_id 
ORDERBYt.value_dateDESC, 
t.id DESC 
ROWSBETWEENUNBOUNDEDPRECEDING 
AND1 PRECEDING 
)
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 
SUM(t.amount) OVER( 
PARTITIONBYt.account_id 
ORDERBYt.value_dateDESC, 
t.id DESC 
ROWSBETWEENUNBOUNDEDPRECEDING 
AND1 PRECEDING 
)
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 
SUM(t.amount) OVER( 
PARTITIONBYt.account_id 
ORDERBYt.value_dateDESC, 
t.id DESC 
ROWSBETWEENUNBOUNDEDPRECEDING 
AND1 PRECEDING 
)
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 
SUM(t.amount) OVER( 
PARTITIONBYt.account_id 
ORDERBYt.value_dateDESC, 
t.id DESC 
ROWSBETWEENUNBOUNDEDPRECEDING 
AND1 PRECEDING 
)
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava 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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesDon’t you think that’s beautiful? 
Stockholm Syndrome: 
WeloveCOBOLSQL
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesWinston Churchill 
SQL is the worst form of database querying, except for all the other forms.
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesMore SQL Calculations 
| 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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesMore SQL Calculations 
SELECT p.text, 
p.votes, 
DENSE_RANK()OVER (ORDER BY p.votesDESC)AS "rank", 
LPAD( 
(p.votes* 100 /SUM(p.votes)OVER ())||' %', 
4, ' ' 
)AS "percent" 
FROM poll_optionsp 
WHERE p.poll_id= 12 
ORDER BY p.votesDESC
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesThe same withjOOQ 
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-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesThe same withjOOQ in Scala (!) 
select (p.TEXT, 
p.VOTES, 
denseRank() over() orderBy(p.VOTESdesc) 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.VOTESdesc)
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesWhatjOOQmeansfordevelopers 
Java 
SQL 
onejack 
all plugs 
jOOQ 
oneadaptor 
WithjOOQ, Java plugsintoSQL intuitively, lettingyourdevelopersfocuson business-logicagain. 
Images fromWikimedia. License: publicdomain. Travel converterbyCephira. License: CC-BY SA 3.0
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesJust to be sure you get the message 
jOOQis the best way to write SQL in Java
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesExamples
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamples 
Who saidit? 
All companiesbenefitwhentheycanaffordtofocuson innovationratherthaninfrastructure
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamples 
Marc Benioff: 
All companiesbenefitwhentheycanaffordtofocuson innovationratherthaninfrastructure
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamples 
«jOOQ» 10% discountcodeAnd a shameless book recommendation 
Markus Winand fromUse-The-Index-Luke.com 
ROI north of 83’174% 
Achieve proper indexing and performance in popular RDBMS
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesAnd a shameless tool recommendation 
Open source databases: 
-Free / Apache license 
Commercial databases: 
-Commercial license
Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamples 
That’s it folks 
More freeJava / SQL knowledgeon: 
•Blog: http://blog.jooq.org 
•Twitter: @JavaOOQ/ @lukaseder 
•Newsletter: http://www.jooq.org

Weitere ähnliche Inhalte

Was ist angesagt?

CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForce
Ciklum Ukraine
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
Reagan Hwang
 
There's more than web
There's more than webThere's more than web
There's more than web
Matt Evans
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
Jollen Chen
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
SFilipp
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
Droidcon Berlin
 

Was ist angesagt? (20)

This isn't Richard Stallman's Open Source anymore
This isn't Richard Stallman's Open Source anymoreThis isn't Richard Stallman's Open Source anymore
This isn't Richard Stallman's Open Source anymore
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
10 Reasons Why we Love Some APIs and Why we Hate Some Others
10 Reasons Why we Love Some APIs and Why we Hate Some Others10 Reasons Why we Love Some APIs and Why we Hate Some Others
10 Reasons Why we Love Some APIs and Why we Hate Some Others
 
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
 
Getting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with ThymeleafGetting start Java EE Action-Based MVC with Thymeleaf
Getting start Java EE Action-Based MVC with Thymeleaf
 
Eddystone Beacons - Physical Web - Giving a URL to All Objects
Eddystone Beacons - Physical Web - Giving a URL to All ObjectsEddystone Beacons - Physical Web - Giving a URL to All Objects
Eddystone Beacons - Physical Web - Giving a URL to All Objects
 
JIOWA Code Generation Framework & Template Engine
JIOWA Code Generation Framework & Template EngineJIOWA Code Generation Framework & Template Engine
JIOWA Code Generation Framework & Template Engine
 
Physical web
Physical webPhysical web
Physical web
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForce
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
 
Questioning the status quo
Questioning the status quoQuestioning the status quo
Questioning the status quo
 
There's more than web
There's more than webThere's more than web
There's more than web
 
Css2011 Ruo Ando
Css2011 Ruo AndoCss2011 Ruo Ando
Css2011 Ruo Ando
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
課程名稱:八屏一雲時代來臨 教你HTML5六小時打通(3)
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
 
Struts 2 + Spring
Struts 2 + SpringStruts 2 + Spring
Struts 2 + Spring
 
Vaadin 8 with Spring Framework
Vaadin 8 with Spring FrameworkVaadin 8 with Spring Framework
Vaadin 8 with Spring Framework
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 

Ähnlich wie The Awesome jOOQ JavaOne Talk

iPhone/iPad Development with Titanium
iPhone/iPad Development with TitaniumiPhone/iPad Development with Titanium
iPhone/iPad Development with Titanium
Axway Appcelerator
 
Startup eng-camp 3
Startup eng-camp 3Startup eng-camp 3
Startup eng-camp 3
Jollen Chen
 

Ähnlich wie The Awesome jOOQ JavaOne Talk (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
 
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
 
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
 
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
 
Why Your Developers Need jOOQ
Why Your Developers Need jOOQWhy Your Developers Need jOOQ
Why Your Developers Need jOOQ
 
iPhone/iPad Development with Titanium
iPhone/iPad Development with TitaniumiPhone/iPad Development with Titanium
iPhone/iPad Development with Titanium
 
Appcelerator iPhone/iPad Dev Con 2010 San Diego, CA
Appcelerator iPhone/iPad Dev Con 2010 San Diego, CAAppcelerator iPhone/iPad Dev Con 2010 San Diego, CA
Appcelerator iPhone/iPad Dev Con 2010 San Diego, CA
 
Startup eng-camp 3
Startup eng-camp 3Startup eng-camp 3
Startup eng-camp 3
 
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...
 
Power ai image-pipeline
Power ai image-pipelinePower ai image-pipeline
Power ai image-pipeline
 
Microsoft, java and you!
Microsoft, java and you!Microsoft, java and you!
Microsoft, java and you!
 
Walking Through Spring Cloud Data Flow
Walking Through Spring Cloud Data FlowWalking Through Spring Cloud Data Flow
Walking Through Spring Cloud Data Flow
 
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
 
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Webbeyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
beyond tellerrand: Mobile Apps with JavaScript – There's More Than Web
 
Serverless and IoT
Serverless and IoTServerless and IoT
Serverless and IoT
 
닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기
 
Deep Learning on Amazon Sagemaker (July 2019)
Deep Learning on Amazon Sagemaker (July 2019)Deep Learning on Amazon Sagemaker (July 2019)
Deep Learning on Amazon Sagemaker (July 2019)
 
Choose Your Own Adventure with JHipster & Kubernetes - Utah JUG 2020
Choose Your Own Adventure with JHipster & Kubernetes - Utah JUG 2020Choose Your Own Adventure with JHipster & Kubernetes - Utah JUG 2020
Choose Your Own Adventure with JHipster & Kubernetes - Utah JUG 2020
 
Security Theatre - Benelux
Security Theatre - BeneluxSecurity Theatre - Benelux
Security Theatre - Benelux
 
How To Build a Multi-Field Search Page For Your XPages Application
How To Build a Multi-Field Search Page For Your XPages ApplicationHow To Build a Multi-Field Search Page For Your XPages Application
How To Build a Multi-Field Search Page For Your XPages Application
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Kürzlich hochgeladen (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

The Awesome jOOQ JavaOne Talk

  • 1. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0GetBack in ControlofyourSQLSQL andJava couldworktogetherso muchbetterifweonlyletthem.
  • 2. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0IntroSQL andJava jOOQ ExamplesMe –@lukaseder SQL is a device whose mystery is only exceeded by its power! -Founder and CEO at Data Geekery -SQL Aficionado -Java Aficionado
  • 3. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0IntroSQL andJava jOOQ ExamplesLegal Disclaimer THE FOLLOWING IS COMMUNICATED TO YOU SOLELY FOR ENTERTAINMENT PURPOSES. NO ONE SANE WOULD BELIEVE A GUY WHO CLAIMS HE IS A SQL AFICIONADO OR WORSE WHO CLAIMS THAT SQL IS ANYTHING NEAR BEAUTIFUL. IF YOU STILL FIND THE FOLLOWING INTERESTING AND IF YOU BASE YOUR PURCHASING DECISIONS UPON THAT, YOU DEFINITELY NEED PROFESSIONAL HELP. WE ACTUALLY PROVIDE SUCH HELP.
  • 4. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesSQL andJava –in theory Java SQL In thismetaphor, electricityisthedata(SQL) thatflowsintoyourappliance/ application(Java) onejack oneplug
  • 5. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesSQL andJava –in practice Java SQL Images from: http://en.wikipedia.org/wiki/AC_power_plugs_and_sockets.License: public domain onejack lots ofplugs
  • 6. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesJDBC PreparedStatementstmt= connection.prepareStatement( "SELECT textFROM productsWHERE cust_id= ? AND value< ?"); stmt.setInt(1, custID); stmt.setBigDecimal(2, BigDecimal.ZERO); ResultSetrs= stmt.executeQuery(); while(rs.next()) { System.out.println(rs.getString("TEXT")); }
  • 7. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesJDBC –thenakedtruth 01: PreparedStatementstmt= connection.prepareStatement( 02:"SELECT p.texttxt" + 03:(isAccount? ", NVL(a.type, ?) " :"") + 04:"FROM productsp " + 05:(isAccount? " INNER JOIN accountsa USING (prod_id) ": "") + 06:" WHERE p.cust_id= ? AND p.value< ?"+ 07:(isAccount? "AND a.typeLIKE '%"+ type + "%'": ""); 08: stmt.setInt(1, defaultType); 09: stmt.setInt(2, custID); 10: stmt.setBigDecimal(3, BigDecimal.ZERO); 11: ResultSetrs= stmt.executeQuery(); 12: 13: while(rs.next()) { 14:Clobclob= rs.getClob("TEXT"); 15:System.out.println(clob.getSubString(1, (int) clob.length()); 16: } 17: 18: rs.close(); 19: stmt.close();
  • 8. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesJDBC –thenakedtruth 01: PreparedStatementstmt= connection.prepareStatement( // 02:"SELECT p.texttxt" + // 03:(isAccount? ", NVL(a.type, ?) " :"") + // 04:"FROM productsp " + // Syntax errorwhenisAccount== false 05:(isAccount? " INNER JOIN accountsa USING (prod_id) " : "") + // 06:" WHERE p.cust_id= ? AND p.value< ?"+ // 07:(isAccount? "AND a.typeLIKE '%"+ type + "%'": ""); // Syntax errorandSQL injectionpossible 08: stmt.setInt(1, defaultType); // Wrongbind index 09: stmt.setInt(2, custID); // 10: stmt.setBigDecimal(3, BigDecimal.ZERO); // 11: ResultSetrs= stmt.executeQuery(); // 12: 13: while(rs.next()) { // 14:Clobclob= rs.getClob("TEXT"); // Wrongcolumnname 15:System.out.println(clob.getSubString(1, (int) clob.length());// ojdbc6: clob.free() shouldbecalled 16: } // 17: 18: rs.close(); // close() not reallyin finallyblock 19: stmt.close(); //
  • 9. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesWhatJDBC meansfordevelopers Images fromFlickr. Totheleftby: Matthew Straubmuller, Greg Grossmeier. License:CC BY SA 2.0. Electric Engineers to the right copyright by Marco Sarli, all rights reserved. WithJDBC, yourdevelopershavetodo a lotofmanual, error-prone(dangerous) andinefficientwork
  • 10. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 2.0 EntityBeans publicinterfaceCustomerRequestextendsEJBObject{ BigIntegergetId(); String getText(); voidsetText(String text); @Override voidremove(); } publicinterfaceCustomerRequestHomeextendsEJBHome{ CustomerRequestcreate(BigIntegerid); CustomerRequestfind(BigIntegerid); }
  • 11. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 2.0 –thenakedtruth <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>
  • 12. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 2.0 –thenakedtruth <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
  • 13. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 2.0
  • 14. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesJPA andEJB 3.0 EntityManagerem= factory.createEntityManager(); em.getTransaction().begin(); em.persist(newEvent("Conference", newDate()); em.persist(newEvent("After Party", newDate()); List result= em.createQuery("fromEvent").getResultList(); for(Event event: (List<Event>) result) { System.out.println("Event : "+ event.getTitle()); } em.getTransaction().commit(); em.close();
  • 15. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 3.0 –thenakedtruth @Entity @Table(name = "EVENTS") public classEvent { privateLong id; privateString title; privateDate date; @Id @GeneratedValue(generator = "increment") @GenericGenerator(name = "increment", strategy = "increment") publicLong getId() { /* … */ } @Temporal(TemporalType.TIMESTAMP) @Column(name = "EVENT_DATE") publicDate getDate() { /* … */ }
  • 16. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesEJB 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") } ) privateCollection dealers; Found at http://stackoverflow.com/q/17491912/521799
  • 17. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesJPA 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 privateCollection employees; Might not be true
  • 18. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesWhat’s next?
  • 19. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesWhatJPA meansfordevelopers… Images fromWikimedia. License: publicdomain. High voltagepower linesbySimon Koopmann. License: CC-BY SA 3.0 WithJPA, yourdevelopersusea hugeframeworkwithlots ofcomplexitythatcangethardtomanage
  • 20. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ Examples… whendevelopersactuallywantedthis Java SQL onejack oneplug
  • 21. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNote, we’retalkingaboutSQL. Not Persistence…
  • 22. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNote, we’retalkingaboutSQL. Not Persistence… FYI: Gavin King: CreatorofHibernate!
  • 23. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? … … so, shouldwemaybeabandonSQL?
  • 24. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? 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 subsecondresponse time; and we are constantly making advances to deliver it even faster.
  • 25. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? 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 subsecondresponse time; and we are constantly making advances to deliver it even faster.
  • 26. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? Marc Benioff–salesforce.com He’s talking about salesforce.com’sOracle database. He “invented” the cloud
  • 27. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? 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
  • 28. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQL? CERN, collecting LHC data •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
  • 29. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQLfor Big Data? -You’re giving up on ACID -You’re giving up on type safety -You’regivingupon standards -You’regivingupon tooling -You’regivingupon relational algebra -Youhaven’taskedoperations -Youdon’tactuallyhave«Big Data»
  • 30. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesNoSQLfor Big Data? -You’re giving up on ACID -You’re giving up on type safety -You’regivingupon standards -You’regivingupon tooling -You’regivingupon relational algebra -Youhaven’taskedoperations -Youdon’tactuallyhave«Big Data»
  • 31. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ Examples Seen at the O’Reilly Strata Conf: History of NoSQLbyMark Madsen. Picture published byEddDumbillNoSQL? No, SQL!
  • 32. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesLet’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 |
  • 33. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesLet’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 |
  • 34. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesLet’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 |
  • 35. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesLet’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 |
  • 36. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesLet’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)
  • 37. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SELECT t.*, t.current_balance-NVL( SUM(t.amount) OVER( PARTITIONBYt.account_id ORDERBYt.value_dateDESC, t.id DESC ROWSBETWEENUNBOUNDEDPRECEDING AND1 PRECEDING ), 0) ASbalance FROM v_transactionst WHERE t.account_id= 1 ORDERBY t.value_dateDESC, t.id DESC
  • 38. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SUM(t.amount) OVER( PARTITIONBYt.account_id ORDERBYt.value_dateDESC, t.id DESC ROWSBETWEENUNBOUNDEDPRECEDING AND1 PRECEDING )
  • 39. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SUM(t.amount) OVER( PARTITIONBYt.account_id ORDERBYt.value_dateDESC, t.id DESC ROWSBETWEENUNBOUNDEDPRECEDING AND1 PRECEDING )
  • 40. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SUM(t.amount) OVER( PARTITIONBYt.account_id ORDERBYt.value_dateDESC, t.id DESC ROWSBETWEENUNBOUNDEDPRECEDING AND1 PRECEDING )
  • 41. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SUM(t.amount) OVER( PARTITIONBYt.account_id ORDERBYt.value_dateDESC, t.id DESC ROWSBETWEENUNBOUNDEDPRECEDING AND1 PRECEDING )
  • 42. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0 SUM(t.amount) OVER( PARTITIONBYt.account_id ORDERBYt.value_dateDESC, t.id DESC ROWSBETWEENUNBOUNDEDPRECEDING AND1 PRECEDING )
  • 43. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava 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 |
  • 44. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesDon’t you think that’s beautiful? Stockholm Syndrome: WeloveCOBOLSQL
  • 45. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesWinston Churchill SQL is the worst form of database querying, except for all the other forms.
  • 46. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesMore SQL Calculations | 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…
  • 47. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesMore SQL Calculations SELECT p.text, p.votes, DENSE_RANK()OVER (ORDER BY p.votesDESC)AS "rank", LPAD( (p.votes* 100 /SUM(p.votes)OVER ())||' %', 4, ' ' )AS "percent" FROM poll_optionsp WHERE p.poll_id= 12 ORDER BY p.votesDESC
  • 48. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesThe same withjOOQ 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());
  • 49. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesThe same withjOOQ in Scala (!) select (p.TEXT, p.VOTES, denseRank() over() orderBy(p.VOTESdesc) 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.VOTESdesc)
  • 50. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesWhatjOOQmeansfordevelopers Java SQL onejack all plugs jOOQ oneadaptor WithjOOQ, Java plugsintoSQL intuitively, lettingyourdevelopersfocuson business-logicagain. Images fromWikimedia. License: publicdomain. Travel converterbyCephira. License: CC-BY SA 3.0
  • 51. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesJust to be sure you get the message jOOQis the best way to write SQL in Java
  • 52. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQ ExamplesExamples
  • 53. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamples Who saidit? All companiesbenefitwhentheycanaffordtofocuson innovationratherthaninfrastructure
  • 54. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamples Marc Benioff: All companiesbenefitwhentheycanaffordtofocuson innovationratherthaninfrastructure
  • 55. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamples «jOOQ» 10% discountcodeAnd a shameless book recommendation Markus Winand fromUse-The-Index-Luke.com ROI north of 83’174% Achieve proper indexing and performance in popular RDBMS
  • 56. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamplesAnd a shameless tool recommendation Open source databases: -Free / Apache license Commercial databases: -Commercial license
  • 57. Copyright (c) 2009-2014 by Data Geekery GmbH. Slides licensed under CC BY SA 3.0Intro SQL andJava jOOQExamples That’s it folks More freeJava / SQL knowledgeon: •Blog: http://blog.jooq.org •Twitter: @JavaOOQ/ @lukaseder •Newsletter: http://www.jooq.org