Added some sections to the manual
This commit is contained in:
parent
4cc15e7dda
commit
441fd4c7a4
@ -1,5 +1,5 @@
|
||||
body {
|
||||
font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;
|
||||
font-family: 'Lucida Grande',Helvetica,Arial,sans-serif;;
|
||||
font-weight: normal;
|
||||
text-shadow: 0 1px 0 #FFFFFF;
|
||||
font-size: 15px;
|
||||
@ -33,19 +33,19 @@ h1, h2, h3, h4, h5, h6 {
|
||||
|
||||
h1 {
|
||||
font-size: 4em;
|
||||
text-shadow: 0 1px 1px #666666;
|
||||
text-shadow: 0 1px 1px #444;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 2.5em;
|
||||
text-shadow: 0 1px 1px #666666;
|
||||
text-shadow: 0 1px 1px #444;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.3em;
|
||||
text-shadow: 0 1px 0 #666666;
|
||||
text-shadow: 0 1px 0 #444;
|
||||
}
|
||||
|
||||
pre {
|
||||
@ -72,7 +72,7 @@ p {
|
||||
|
||||
p.slogan {
|
||||
padding-left: 2em;
|
||||
color: #888888;
|
||||
color: #444;
|
||||
font-family: 'Georgia',Serif;
|
||||
font-style: italic;
|
||||
height: 2.5em;
|
||||
@ -129,19 +129,50 @@ a:hover {
|
||||
background-color: #FFFFFF;
|
||||
margin: 0 auto;
|
||||
position: relative;
|
||||
width: 980px;
|
||||
width: 1050px;
|
||||
|
||||
padding-top: 1em;
|
||||
padding-left: 3em;
|
||||
padding-right: 3em;
|
||||
border-width: 0;
|
||||
border-style: solid;
|
||||
border-color: #882222;
|
||||
box-shadow: 0 0 20px #aa6633;
|
||||
box-shadow: 0 0 30px #aa6633;
|
||||
}
|
||||
|
||||
#content {
|
||||
padding-top: 1em;
|
||||
padding-left: 3em;
|
||||
padding-right: 3em;
|
||||
|
||||
background: #fadccb;
|
||||
background: -webkit-gradient(linear, left, right, from(#f6cab9), to(#ffeedd));
|
||||
background: -moz-linear-gradient(left, #f6cab9, #ffeedd);
|
||||
background: gradient(linear, left, right, from(#f6cab9), to(#ffeedd));
|
||||
|
||||
}
|
||||
|
||||
#navigation {
|
||||
padding-top: 1em;
|
||||
padding-left: 3em;
|
||||
padding-right: 3em;
|
||||
|
||||
height: 40px;
|
||||
background: #444;
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(#555), to(#333));
|
||||
background: -moz-linear-gradient(top, #555, #333);
|
||||
background: gradient(linear, left top, left bottom, from(#555), to(#333));
|
||||
}
|
||||
|
||||
#navigation a,
|
||||
#navigation a:link,
|
||||
#navigation a:visited,
|
||||
#navigation a:hover,
|
||||
#navigation a:active {
|
||||
color: #ddcccc;
|
||||
text-decoration: none;
|
||||
text-shadow: 0 1px 1px #666666;
|
||||
}
|
||||
|
||||
#navigation a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
div.navigation-item-left {
|
||||
|
||||
@ -13,25 +13,6 @@
|
||||
<body onload="prettyPrint()">
|
||||
<div id="wrapper">
|
||||
<div class="block">
|
||||
<div id="tweets">
|
||||
<div class="tweet-item-left">
|
||||
<a href="http://twitter.com/share" class="twitter-share-button" data-text="jOOQ - A nice database abstraction library for Java" data-count="horizontal" data-via="lukaseder">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
|
||||
</div>
|
||||
<div class="tweet-item-left">
|
||||
<g:plusone size="medium"></g:plusone>
|
||||
</div>
|
||||
<div class="tweet-item-left">
|
||||
<div id="fb-root"></div>
|
||||
<script>(function(d, s, id) {
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) {return;}
|
||||
js = d.createElement(s); js.id = id;
|
||||
js.src = "//connect.facebook.net/en_US/all.js#appId=232666253447462&xfbml=1";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));</script>
|
||||
<div class="fb-like" data-send="false" data-layout="button_count" data-width="450" data-show-faces="true" data-font="verdana"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="navigation">
|
||||
<div class="navigation-item-left">
|
||||
<a href="<?=$root?>/" title="jOOQ Home Page">Home</a>
|
||||
@ -43,7 +24,7 @@
|
||||
<a href="<?=$root?>/manual" title="jOOQ User Manual">Manual</a>
|
||||
</div>
|
||||
<div class="navigation-item-left">
|
||||
<a href="http://jooq.sourceforge.net/javadoc/latest/" title="jOOQ Main Javadoc">Javadoc</a>
|
||||
<a href="<?=$root?>/javadoc/latest/" title="jOOQ Main Javadoc">Javadoc</a>
|
||||
</div>
|
||||
<div class="navigation-item-left">
|
||||
<a href="<?=$root?>/notes.php" title="jOOQ Release Notes">Release Notes</a>
|
||||
@ -62,26 +43,47 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td width="700" valign="top">
|
||||
<h1><?php printH1(); ?></h1></td>
|
||||
<td align="right" valign="top"><img src="<?=$root?>/img/logo.png" alt="jOOQ Logo"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
$slogan = getSlogan();
|
||||
|
||||
if ($slogan != '') {
|
||||
print '<p class="slogan">' . $slogan . '</p>';
|
||||
}
|
||||
|
||||
printContent();
|
||||
?>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
<div id="content">
|
||||
<div id="tweets">
|
||||
<div class="tweet-item-left">
|
||||
<a href="http://twitter.com/share" class="twitter-share-button" data-text="jOOQ - A nice database abstraction library for Java" data-count="horizontal" data-via="lukaseder">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
|
||||
</div>
|
||||
<div class="tweet-item-left">
|
||||
<g:plusone size="medium"></g:plusone>
|
||||
</div>
|
||||
<div class="tweet-item-left">
|
||||
<div id="fb-root"></div>
|
||||
<script>(function(d, s, id) {
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) {return;}
|
||||
js = d.createElement(s); js.id = id;
|
||||
js.src = "//connect.facebook.net/en_US/all.js#appId=232666253447462&xfbml=1";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));</script>
|
||||
<div class="fb-like" data-send="false" data-layout="button_count" data-width="450" data-show-faces="true" data-font="verdana"></div>
|
||||
</div>
|
||||
</div>
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td width="700" valign="top">
|
||||
<h1><?php printH1(); ?></h1></td>
|
||||
<td align="right" valign="top"><img src="<?=$root?>/img/logo.png" alt="jOOQ Logo"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
$slogan = getSlogan();
|
||||
|
||||
if ($slogan != '') {
|
||||
print '<p class="slogan">' . $slogan . '</p>';
|
||||
}
|
||||
|
||||
printContent();
|
||||
?>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 42 KiB |
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/ALIAS/">Aliased tables and fields</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/CONDITION/" title="Previous section: Conditions">previous</a> : <a href="<?=$root?>/manual/DSL/IN/" title="Next section: Nested select statements using the IN operator">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/ALIAS/">Aliased tables and fields</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/CONDITION/" title="Previous section: Conditions">previous</a> : <a href="<?=$root?>/manual/DSL/IN/" title="Next section: Nested select statements using the IN operator">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/ARITHMETIC/">Arithmetic operations</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/PROCEDURES/" title="Previous section: Stored procedures and functions">previous</a> : <a href="<?=$root?>/manual/DSL/CASE/" title="Next section: The CASE clause">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/ARITHMETIC/">Arithmetic operations</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/PROCEDURES/" title="Previous section: Stored procedures and functions">previous</a> : <a href="<?=$root?>/manual/DSL/CASE/" title="Next section: The CASE clause">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/CASE/">The CASE clause</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/ARITHMETIC/" title="Previous section: Arithmetic operations">previous</a> : <a href="<?=$root?>/manual/DSL/CAST/" title="Next section: Type casting">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/CASE/">The CASE clause</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/ARITHMETIC/" title="Previous section: Arithmetic operations">previous</a> : <a href="<?=$root?>/manual/DSL/CAST/" title="Next section: Type casting">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/CAST/">Type casting</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/CASE/" title="Previous section: The CASE clause">previous</a> : <a href="<?=$root?>/manual/DSL/SQL/" title="Next section: When it's just much easier: Plain SQL">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/CAST/">Type casting</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/CASE/" title="Previous section: The CASE clause">previous</a> : <a href="<?=$root?>/manual/DSL/SQL/" title="Next section: When it's just much easier: Plain SQL">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/CONDITION/">Conditions</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/SELECT/" title="Previous section: Complete SELECT syntax">previous</a> : <a href="<?=$root?>/manual/DSL/ALIAS/" title="Next section: Aliased tables and fields">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/CONDITION/">Conditions</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/SELECT/" title="Previous section: Complete SELECT syntax">previous</a> : <a href="<?=$root?>/manual/DSL/ALIAS/" title="Next section: Aliased tables and fields">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/EXISTS/">Nested select statements using the EXISTS operator</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/IN/" title="Previous section: Nested select statements using the IN operator">previous</a> : <a href="<?=$root?>/manual/DSL/NESTED/" title="Next section: Other types of nested selects">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/EXISTS/">Nested select statements using the EXISTS operator</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/IN/" title="Previous section: Nested select statements using the IN operator">previous</a> : <a href="<?=$root?>/manual/DSL/NESTED/" title="Next section: Other types of nested selects">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/FUNCTIONS/">Functions, aggregate operators, and window functions</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/UNION/" title="Previous section: UNION and other set operations">previous</a> : <a href="<?=$root?>/manual/DSL/PROCEDURES/" title="Next section: Stored procedures and functions">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/FUNCTIONS/">Functions, aggregate operators, and window functions</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/UNION/" title="Previous section: UNION and other set operations">previous</a> : <a href="<?=$root?>/manual/DSL/PROCEDURES/" title="Next section: Stored procedures and functions">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/IN/">Nested select statements using the IN operator</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/ALIAS/" title="Previous section: Aliased tables and fields">previous</a> : <a href="<?=$root?>/manual/DSL/EXISTS/" title="Next section: Nested select statements using the EXISTS operator">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/IN/">Nested select statements using the IN operator</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/ALIAS/" title="Previous section: Aliased tables and fields">previous</a> : <a href="<?=$root?>/manual/DSL/EXISTS/" title="Next section: Nested select statements using the EXISTS operator">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/NESTED/">Other types of nested selects</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/EXISTS/" title="Previous section: Nested select statements using the EXISTS operator">previous</a> : <a href="<?=$root?>/manual/DSL/UNION/" title="Next section: UNION and other set operations">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/NESTED/">Other types of nested selects</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/EXISTS/" title="Previous section: Nested select statements using the EXISTS operator">previous</a> : <a href="<?=$root?>/manual/DSL/UNION/" title="Next section: UNION and other set operations">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/PROCEDURES/">Stored procedures and functions</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/FUNCTIONS/" title="Previous section: Functions, aggregate operators, and window functions">previous</a> : <a href="<?=$root?>/manual/DSL/ARITHMETIC/" title="Next section: Arithmetic operations">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/PROCEDURES/">Stored procedures and functions</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/FUNCTIONS/" title="Previous section: Functions, aggregate operators, and window functions">previous</a> : <a href="<?=$root?>/manual/DSL/ARITHMETIC/" title="Next section: Arithmetic operations">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/SELECT/">Complete SELECT syntax</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/" title="Previous section: DSL or fluent API">previous</a> : <a href="<?=$root?>/manual/DSL/CONDITION/" title="Next section: Conditions">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/SELECT/">Complete SELECT syntax</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/" title="Previous section: DSL or fluent API. Where SQL meets Java">previous</a> : <a href="<?=$root?>/manual/DSL/CONDITION/" title="Next section: Conditions">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/SQL/">When it's just much easier: Plain SQL</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/CAST/" title="Previous section: Type casting">previous</a> : <a href="<?=$root?>/manual/ADVANCED/" title="Next section: Advanced topics">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/SQL/">When it's just much easier: Plain SQL</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/CAST/" title="Previous section: Type casting">previous</a> : <a href="<?=$root?>/manual/ADVANCED/" title="Next section: Advanced topics">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a> : <a href="<?=$root?>/manual/DSL/UNION/">UNION and other set operations</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/NESTED/" title="Previous section: Other types of nested selects">previous</a> : <a href="<?=$root?>/manual/DSL/FUNCTIONS/" title="Next section: Functions, aggregate operators, and window functions">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/UNION/">UNION and other set operations</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/DSL/NESTED/" title="Previous section: Other types of nested selects">previous</a> : <a href="<?=$root?>/manual/DSL/FUNCTIONS/" title="Next section: Functions, aggregate operators, and window functions">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
// Please do not edit this content manually
|
||||
require '../../frame.php';
|
||||
function printH1() {
|
||||
print "DSL or fluent API";
|
||||
print "DSL or fluent API. Where SQL meets Java";
|
||||
}
|
||||
function getSlogan() {
|
||||
return "";
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/META/SEQUENCE/" title="Previous section: Sequences">previous</a> : <a href="<?=$root?>/manual/DSL/SELECT/" title="Next section: Complete SELECT syntax">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/DSL/">DSL or fluent API. Where SQL meets Java</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/META/SEQUENCE/" title="Previous section: Sequences">previous</a> : <a href="<?=$root?>/manual/DSL/SELECT/" title="Next section: Complete SELECT syntax">next</a></td>
|
||||
</tr>
|
||||
</table><h3>Table of contents</h3><ol>
|
||||
<li>
|
||||
|
||||
@ -4,20 +4,499 @@
|
||||
// Please do not edit this content manually
|
||||
require '../../../frame.php';
|
||||
function printH1() {
|
||||
print "Query and its subtypes";
|
||||
print "The Query and its various subtypes";
|
||||
}
|
||||
function getSlogan() {
|
||||
return "";
|
||||
return "
|
||||
The Query type hierarchy is what you use to execute queries. It has the
|
||||
following subtypes for each kind of operation
|
||||
";
|
||||
}
|
||||
function printContent() {
|
||||
global $root;
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/JOOQ/">jOOQ classes and their usage</a> : <a href="<?=$root?>/manual/JOOQ/Query/">Query and its subtypes</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/JOOQ/UpdatableRecord/" title="Previous section: Updatable Records">previous</a> : <a href="<?=$root?>/manual/JOOQ/ResultQuery/" title="Next section: ResultQuery and various ways of fetching data">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/JOOQ/">jOOQ classes and their usage</a> : <a href="<?=$root?>/manual/JOOQ/Query/">The Query and its various subtypes</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/JOOQ/UpdatableRecord/" title="Previous section: Updatable Records">previous</a> : <a href="<?=$root?>/manual/JOOQ/ResultQuery/" title="Next section: ResultQuery and various ways of fetching data">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</table>
|
||||
<h2>SELECT statements</h2>
|
||||
<p>
|
||||
There are essentially two ways of creating SELECT statements in jOOQ.
|
||||
For historical reasons, you can create
|
||||
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/SimpleSelectQuery.java" title="Internal API reference: org.jooq.SimpleSelectQuery">org.jooq.SimpleSelectQuery</a> or
|
||||
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/SelectQuery.java" title="Internal API reference: org.jooq.SelectQuery">org.jooq.SelectQuery</a>
|
||||
objects and add additional query clauses, such as
|
||||
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/Condition.java" title="Internal API reference: org.jooq.Condition">Conditions</a> or
|
||||
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/SortField.java" title="Internal API reference: org.jooq.SortField">SortFields</a> to it.
|
||||
Since jOOQ 1.3, there is also the possibility to
|
||||
create SELECT statements using jOOQ's
|
||||
<a href="<?=$root?>/manual/DSL/" title="jOOQ Manual reference: DSL or fluent API. Where SQL meets Java">DSL API</a> in a much more intuitive
|
||||
and SQL-like way.
|
||||
</p>
|
||||
<p>Use the DSL API when: </p>
|
||||
<ul>
|
||||
|
||||
<li>You want your code to look like SQL</li>
|
||||
|
||||
<li>You want your IDE to help you with auto-completion (you will not be able to write select .. order by .. where .. join or any of that stuff) </li>
|
||||
|
||||
</ul>
|
||||
<p>Use the regular API when: </p>
|
||||
<ul>
|
||||
|
||||
<li>You want to create your query step-by-step, creating query parts one-by-one</li>
|
||||
|
||||
<li>You need to assemble your query from various places, passing the query around, adding new conditions and joins on the way </li>
|
||||
|
||||
</ul>
|
||||
<p>In any case, all API's will construct the same underlying
|
||||
implementation object, and in many cases, you can combine the two
|
||||
approaches. Let's check out the various SELECT statement types: </p>
|
||||
|
||||
<ul>
|
||||
|
||||
<li>
|
||||
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/Select.java" title="Internal API reference: org.jooq.Select">org.jooq.Select</a>:
|
||||
This Query subtype stands for a general type of SELECT statement.
|
||||
It is also the main Select type for the
|
||||
<a href="<?=$root?>/manual/DSL/" title="jOOQ Manual reference: DSL or fluent API. Where SQL meets Java">DSL API</a>. When executed, this object
|
||||
will hold a <a href="<?=$root?>/manual/JOOQ/Result/" title="jOOQ Manual reference: Results and Records">Result containing the resulting Records</a>.
|
||||
This type is further subtyped for the various uses of a SELECT statement as such:</li>
|
||||
|
||||
<li>
|
||||
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/SimpleSelectQuery.java" title="Internal API reference: org.jooq.SimpleSelectQuery">org.jooq.SimpleSelectQuery</a>:
|
||||
This Query will allow for selecting from single physical Tables only.
|
||||
It therefore has access to the Table's generic type parameter
|
||||
<R extends Record> and will provide a matching Result<R>.
|
||||
This is especially useful if <R> is a subtype of
|
||||
<a href="<?=$root?>/manual/JOOQ/UpdatableRecord/" title="jOOQ Manual reference: Updatable Records">UpdatableRecord</a>.
|
||||
Then you will be able to perform updates on your result set immediately.</li>
|
||||
|
||||
<li>
|
||||
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/SelectQuery.java" title="Internal API reference: org.jooq.SelectQuery">org.jooq.SelectQuery</a>:
|
||||
This Query will allow for selecting a subset of Fields from several
|
||||
Tables. Because the results of such a query are considered of an anonymous
|
||||
or ad-hoc type, this Query will bind <R> to the general type Record
|
||||
itself. The purpose of this Query type is to allow for full SQL support,
|
||||
including SELECT, JOIN and GROUP BY clauses. </li>
|
||||
|
||||
</ul>
|
||||
|
||||
<h3>Example: SQL query and DSL query</h3>
|
||||
<table cellpadding="0" cellspacing="0" width="100%">
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="left" width="50%">A sample SQL statement</td>
|
||||
<td class="right" width="50%">...and its equivalent in jOOQ's DSL API</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="left" width="50%">
|
||||
<pre class="prettyprint lang-sql">
|
||||
-- Select all books by authors born after 1920, named "Paulo"
|
||||
-- from a catalogue consisting of authors and books:
|
||||
|
||||
|
||||
SELECT *
|
||||
FROM t_author a
|
||||
JOIN t_book b
|
||||
ON a.id = b.author_id
|
||||
WHERE a.year_of_birth > 1920
|
||||
AND a.first_name = 'Paulo'
|
||||
ORDER BY b.title</pre>
|
||||
</td>
|
||||
<td class="right" width="50%">
|
||||
<pre class="prettyprint lang-java">
|
||||
// Instanciate your factory using a JDBC connection.
|
||||
Factory create = new Factory(connection, SQLDialect.ORACLE);
|
||||
|
||||
// Execute the query "on a single line"
|
||||
Result<Record> result = create.select()
|
||||
.from(T_AUTHOR)
|
||||
.join(T_BOOK)
|
||||
.on(ID.equal(AUTHOR_ID))
|
||||
.where(YEAR_OF_BIRTH.greaterThan(1920)
|
||||
.and(FIRST_NAME.equal("Paulo")))
|
||||
.orderBy(TITLE).fetch();</pre>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<p>
|
||||
In the above example, some generated artefacts are used for querying.
|
||||
In this case, T_AUTHOR and T_BOOK are instances of types
|
||||
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ-test/src/org/jooq/test/oracle/generatedclasses/tables/TAuthor.java" title="Internal API reference: org.jooq.test.oracle.generatedclasses.tables.TAuthor">TAuthor</a> and
|
||||
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ-test/src/org/jooq/test/oracle/generatedclasses/tables/TBook.java" title="Internal API reference: org.jooq.test.oracle.generatedclasses.tables.TBook">TBook</a> respectively.
|
||||
Their full qualification would read TAuthor.T_AUTHOR and TBook.T_BOOK, but in many cases,
|
||||
it's useful to static import elements involved with queries, in order to decrease verbosity.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Apart from the singleton Table instances TAuthor.T_AUTHOR and
|
||||
TBook.T_BOOK, these generated classes also contain one static member
|
||||
for every physical field, such as TAuthor.ID or TBook.TAUTHOR_ID, etc.
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
|
||||
<li>For more information about code generation, check out the manual's section about
|
||||
<a href="<?=$root?>/manual/META/" title="jOOQ Manual reference: Meta model code generation">Meta model source code generation</a>.</li>
|
||||
|
||||
<li>For more DSL examples, please consider the manual's section about the
|
||||
<a href="<?=$root?>/manual/DSL/" title="jOOQ Manual reference: DSL or fluent API. Where SQL meets Java">DSL API</a>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<h3>Example: Non-DSL query</h3>
|
||||
<p>
|
||||
If you choose not to use the DSL API (for instance, because you don't
|
||||
want to add Query parts in the order SQL expects them), you can use
|
||||
this syntax:
|
||||
</p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Re-use the factory to create a SelectQuery. This example will not make use of static imports...
|
||||
SelectQuery q = create.selectQuery();
|
||||
q.addFrom(TAuthor.T_AUTHOR);
|
||||
|
||||
// This example shows some "mixed" API usage, where the JOIN is added with the standard API, and the
|
||||
// Condition is created using the DSL API
|
||||
q.addJoin(TBook.T_BOOK, TAuthor.ID.equal(TBook.AUTHOR_ID));
|
||||
|
||||
// The AND operator between Conditions is implicit here
|
||||
q.addConditions(TAuthor.YEAR_OF_BIRTH.greaterThan(1920));
|
||||
q.addConditions(TAuthor.FIRST_NAME.equal("Paulo"));
|
||||
q.addOrderBy(TBook.TITLE);</pre>
|
||||
|
||||
<h3>Fetching data</h3>
|
||||
<p>
|
||||
The <a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/Select.java" title="Internal API reference: org.jooq.Select">org.jooq.Select</a> interface extends
|
||||
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/ResultQuery.java" title="Internal API reference: org.jooq.ResultQuery">org.jooq.ResultQuery</a>,
|
||||
which provides a range of methods to fetch data from the database.
|
||||
Once you have constructed your SELECT query (see examples above), you
|
||||
may choose to either simply execute() it, or use a variety of convenience
|
||||
fetchXXX() methods.
|
||||
</p>
|
||||
<p>
|
||||
See the manual's
|
||||
<a href="<?=$root?>/manual/JOOQ/ResultQuery/" title="jOOQ Manual reference: ResultQuery and various ways of fetching data">section on the ResultQuery</a>
|
||||
for more details.
|
||||
</p>
|
||||
|
||||
|
||||
<h2>INSERT Statements</h2>
|
||||
<p>jOOQ supports two modes for INSERT statements.
|
||||
The INSERT VALUES and the INSERT SELECT syntax</p>
|
||||
|
||||
<h3>Example: SQL query and DSL query</h3>
|
||||
<table cellpadding="0" cellspacing="0" width="100%">
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="left" width="50%">A typical INSERT query looks like this</td>
|
||||
<td class="right" width="50%">...and how it's done with jOOQ</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="left" width="50%">
|
||||
<pre class="prettyprint lang-sql">
|
||||
INSERT INTO T_AUTHOR
|
||||
(ID, FIRST_NAME, LAST_NAME)
|
||||
VALUES
|
||||
(100, 'Hermann', 'Hesse'),
|
||||
(101, 'Alfred', 'Döblin');</pre>
|
||||
|
||||
</td>
|
||||
<td class="right" width="50%">
|
||||
<pre class="prettyprint lang-java">
|
||||
create.insertInto(T_AUTHOR,
|
||||
TAuthor.ID, TAuthor.FIRST_NAME, TAuthor.LAST_NAME)
|
||||
.values(100, "Hermann", "Hesse")
|
||||
.values(101, "Alfred", "Döblin")
|
||||
.execute();</pre>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<p>The DSL syntax tries to stay close to actual SQL. In detail,
|
||||
however, Java is limited in its possibilities. That's why the
|
||||
.values() clause is repeated for every record. Some RDBMS support
|
||||
inserting several records at the same time. This is also supported in
|
||||
jOOQ, and simulated using INSERT INTO .. SELECT .. UNION ALL SELECT ..
|
||||
clauses for those RDBMS that don't support this syntax.
|
||||
</p>
|
||||
<p>Note: Just like in SQL itself, you can have syntax errors when you
|
||||
don't have matching numbers of fields/values. Also, you can run into
|
||||
runtime problems, if your field/value types don't match. </p>
|
||||
|
||||
<h3>Example: DSL Query, alternative syntax</h3>
|
||||
<p>MySQL (and some other RDBMS) allow for using an UPDATE-like syntax
|
||||
for INSERT statements. This is also supported in jOOQ, should you
|
||||
prefer that syntax. The above INSERT statement can also be expressed
|
||||
as follows: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
create.insertInto(T_AUTHOR)
|
||||
.set(TAuthor.ID, 100)
|
||||
.set(TAuthor.FIRST_NAME, "Hermann")
|
||||
.set(TAuthor.LAST_NAME, "Hesse")
|
||||
.newRecord()
|
||||
.set(TAuthor.ID, 101)
|
||||
.set(TAuthor.FIRST_NAME, "Alfred")
|
||||
.set(TAuthor.LAST_NAME, "Döblin")
|
||||
.execute();</pre>
|
||||
<p>As you can see, this syntax is a bit more verbose, but also more
|
||||
type-safe, as every field can be matched with its value.</p>
|
||||
|
||||
<h3>Example: ON DUPLICATE KEY UPDATE clause</h3>
|
||||
<p>The MySQL database supports a very convenient way to INSERT or
|
||||
UPDATE a record. This is a non-standard extension to the SQL syntax,
|
||||
which is supported by jOOQ and simulated in other RDBMS, where this is
|
||||
possible. Here is an example how to use the ON DUPLICATE KEY UPDATE
|
||||
clause: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Add a new author called "Koontz" with ID 3.
|
||||
// If that ID is already present, update the author's name
|
||||
create.insertInto(T_AUTHOR, TAuthor.ID, TAuthor.LAST_NAME)
|
||||
.values(3, "Koontz")
|
||||
.onDuplicateKeyUpdate()
|
||||
.set(TAuthor.LAST_NAME, "Koontz")
|
||||
.execute();</pre>
|
||||
|
||||
<h3>Example: INSERT .. RETURNING clause</h3>
|
||||
<p>The Postgres database has native support for an INSERT .. RETURNING
|
||||
clause. This is a very powerful concept that is simulated for all
|
||||
other dialects using JDBC's
|
||||
<a href="http://download.oracle.com/javase/6/docs/api/java/sql/Statement.html#getGeneratedKeys()" title="External API reference: java.sql.Statement">getGeneratedKeys()</a>
|
||||
method. Take this example:</p>
|
||||
|
||||
<pre class="prettyprint lang-java">
|
||||
// Add another author, with a generated ID
|
||||
Record<?> record =
|
||||
create.insertInto(T_AUTHOR, TAuthor.FIRST_NAME, TAuthor.LAST_NAME)
|
||||
.values("Charlotte", "Roche")
|
||||
.returning(TAuthor.ID)
|
||||
.fetchOne();
|
||||
|
||||
System.out.println(record.getValue(TAuthor.ID));
|
||||
|
||||
// For some RDBMS, this also works when inserting several values
|
||||
Result<?> result =
|
||||
create.insertInto(T_AUTHOR, TAuthor.FIRST_NAME, TAuthor.LAST_NAME)
|
||||
.values("Johann Wolfgang", "von Goethe")
|
||||
.values("Friedrich", "Schiller")
|
||||
// You can request any field. Also trigger-generated values
|
||||
.returning(TAuthor.ID, TAuthor.CREATION_DATE)
|
||||
.fetch();</pre>
|
||||
|
||||
<h3>Example: Non-DSL Query</h3>
|
||||
<p>You can always use the more verbose regular syntax of the InsertQuery, if you need more control: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Insert a new author into the T_AUTHOR table
|
||||
InsertQuery<TAuthorRecord> i = create.insertQuery(T_AUTHOR);
|
||||
i.addValue(TAuthor.ID, 100);
|
||||
i.addValue(TAuthor.FIRST_NAME, "Hermann");
|
||||
i.addValue(TAuthor.LAST_NAME, "Hesse");
|
||||
|
||||
i.newRecord();
|
||||
i.addValue(TAuthor.ID, 101);
|
||||
i.addValue(TAuthor.FIRST_NAME, "Alfred");
|
||||
i.addValue(TAuthor.LAST_NAME, "Döblin");
|
||||
i.execute();</pre>
|
||||
|
||||
<h3>Example: INSERT Query combined with SELECT statements</h3>
|
||||
<p>The InsertQuery.addValue() method is overloaded, such that you can
|
||||
also provide a Field, potentially containing an expression: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Insert a new author into the T_AUTHOR table
|
||||
InsertQuery<TAuthorRecord> i = create.insertQuery(T_AUTHOR);
|
||||
i.addValue(TAuthor.ID, create.select(TAuthor.ID.max().add(1)).from(T_AUTHOR).asField())
|
||||
i.addValue(TAuthor.FIRST_NAME, "Hermann");
|
||||
i.addValue(TAuthor.LAST_NAME, "Hesse");
|
||||
i.execute();</pre>
|
||||
<p>Note that especially MySQL (and some other RDBMS) has some
|
||||
limitations regarding that syntax. You may not be able to
|
||||
select from the same table you're inserting into</p>
|
||||
|
||||
<h3>Example: INSERT SELECT syntax support</h3>
|
||||
<p>In some occasions, you may prefer the INSERT SELECT syntax, for instance, when
|
||||
you copy records from one table to another: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
Insert i = create.insertInto(T_AUTHOR_ARCHIVE,
|
||||
create.selectFrom(T_AUTHOR).where(TAuthor.DECEASED.equal(1)));
|
||||
i.execute();</pre>
|
||||
|
||||
|
||||
<h2>UPDATE Statements</h2>
|
||||
<p>UPDATE statements are only possible on single tables. Support for
|
||||
multi-table updates will be implemented in the near future. </p>
|
||||
|
||||
<h3>Example: SQL query and DSL query</h3>
|
||||
<table cellpadding="0" cellspacing="0" width="100%">
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="left" width="50%">A typical UPDATE query looks like this</td>
|
||||
<td class="right" width="50%">...and how it's done with jOOQ</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="left" width="50%">
|
||||
<pre class="prettyprint lang-sql">
|
||||
|
||||
UPDATE T_AUTHOR
|
||||
SET FIRST_NAME = 'Hermann',
|
||||
LAST_NAME = 'Hesse'
|
||||
WHERE ID = 3;</pre>
|
||||
|
||||
</td>
|
||||
<td class="right" width="50%">
|
||||
<pre class="prettyprint lang-java">
|
||||
create.update(T_AUTHOR)
|
||||
.set(TAuthor.FIRST_NAME, "Hermann")
|
||||
.set(TAuthor.LAST_NAME, "Hesse")
|
||||
.where(TAuthor.ID.equal(3))
|
||||
.execute();</pre>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<h3>Example: Non-DSL Query</h3>
|
||||
<p>Using the <a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/UpdateQuery.java" title="Internal API reference: org.jooq.UpdateQuery">org.jooq.UpdateQuery</a> class,
|
||||
this is how you could express an UPDATE statement:</p>
|
||||
<pre class="prettyprint lang-java">
|
||||
UpdateQuery<TAuthorRecord> u = create.updateQuery(T_AUTHOR);
|
||||
u.addValue(TAuthor.FIRST_NAME, "Hermann");
|
||||
u.addValue(TAuthor.FIRST_NAME, "Hesse");
|
||||
u.addConditions(TAuthor.ID.equal(3));
|
||||
u.execute();</pre>
|
||||
|
||||
|
||||
<h2>DELETE Statements</h2>
|
||||
<p>DELETE statements are only possible on single tables. Support for
|
||||
multi-table deletes will be implemented in the near future. </p>
|
||||
|
||||
<h3>Example: SQL query and DSL query</h3>
|
||||
<table cellpadding="0" cellspacing="0" width="100%">
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="left" width="50%">A typical DELETE query looks like this</td>
|
||||
<td class="right" width="50%">...and how it's done with jOOQ</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="left" width="50%">
|
||||
<pre class="prettyprint lang-sql">
|
||||
|
||||
DELETE T_AUTHOR
|
||||
WHERE ID = 100;</pre>
|
||||
|
||||
</td>
|
||||
<td class="right" width="50%">
|
||||
<pre class="prettyprint lang-java">
|
||||
create.delete(T_AUTHOR)
|
||||
.where(TAuthor.ID.equal(100))
|
||||
.execute();</pre>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<h3>Example: Non-DSL Query</h3>
|
||||
<p>Using the <a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/DeleteQuery.java" title="Internal API reference: org.jooq.DeleteQuery">org.jooq.DeleteQuery</a> class,
|
||||
this is how you could express a DELETE statement: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
DeleteQuery<TAuthorRecord> d = create.deleteQuery(T_AUTHOR);
|
||||
d.addConditions(TAuthor.ID.equal(100));
|
||||
d.execute();</pre>
|
||||
|
||||
|
||||
<h2>MERGE Statement</h2>
|
||||
<p>
|
||||
The MERGE statement is one of the most advanced standardised SQL
|
||||
constructs, which is supported by DB2, HSQLDB, Oracle, SQL Server and
|
||||
Sybase (MySQL has the similar INSERT .. ON DUPLICATE KEY UPDATE
|
||||
construct. H2's MERGE variant is currently not supported.)
|
||||
</p>
|
||||
<p>
|
||||
The point of the standard MERGE statement is to take a TARGET table, and
|
||||
merge (INSERT, UPDATE) data from a SOURCE table into it. DB2, Oracle,
|
||||
SQL Server and Sybase also allow for DELETING some data and for adding
|
||||
many additional clauses. Those non-standard extensions are currently
|
||||
not supported. Here is an example:
|
||||
</p>
|
||||
|
||||
<table cellpadding="0" cellspacing="0" width="100%">
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="left" width="50%">
|
||||
<pre class="prettyprint lang-sql">
|
||||
-- Check if there is already an author called 'Hitchcock'
|
||||
-- If there is, rename him to John. If there isn't add him.
|
||||
|
||||
MERGE INTO T_AUTHOR
|
||||
USING (SELECT 1 FROM DUAL)
|
||||
ON (LAST_NAME = 'Hitchcock')
|
||||
WHEN MATCHED THEN UPDATE SET FIRST_NAME = 'John'
|
||||
WHEN NOT MATCHED THEN INSERT (LAST_NAME) VALUES ('Hitchcock')</pre>
|
||||
|
||||
</td>
|
||||
<td class="right" width="50%">
|
||||
<pre class="prettyprint lang-java">
|
||||
create.mergeInto(T_AUTHOR)
|
||||
.using(create().selectOne())
|
||||
.on(TAuthor.LAST_NAME.equal("Hitchcock"))
|
||||
.whenMatchedThenUpdate()
|
||||
.set(TAuthor.FIRST_NAME, "John")
|
||||
.whenNotMatchedThenInsert(TAuthor.LAST_NAME)
|
||||
.values("Hitchcock")
|
||||
.execute();</pre>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
<h2>TRUNCATE Statement</h2>
|
||||
<p>
|
||||
The syntax is trivial:
|
||||
</p>
|
||||
<table cellpadding="0" cellspacing="0" width="100%">
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="left" width="50%">
|
||||
<pre class="prettyprint lang-sql">TRUNCATE TABLE T_AUTHOR;</pre>
|
||||
|
||||
</td>
|
||||
<td class="right" width="50%">
|
||||
<pre class="prettyprint lang-java">create.truncate(T_AUTHOR).execute();</pre>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<p>This is not supported by Ingres and SQLite. jOOQ will execute a DELETE FROM
|
||||
T_AUTHOR statement instead. </p>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/JOOQ/">jOOQ classes and their usage</a> : <a href="<?=$root?>/manual/JOOQ/ResultQuery/">ResultQuery and various ways of fetching data</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/JOOQ/Query/" title="Previous section: Query and its subtypes">previous</a> : <a href="<?=$root?>/manual/JOOQ/QueryPart/" title="Next section: QueryParts and the global architecture">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/JOOQ/">jOOQ classes and their usage</a> : <a href="<?=$root?>/manual/JOOQ/ResultQuery/">ResultQuery and various ways of fetching data</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/JOOQ/Query/" title="Previous section: The Query and its various subtypes">previous</a> : <a href="<?=$root?>/manual/JOOQ/QueryPart/" title="Next section: QueryParts and the global architecture">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -118,7 +118,7 @@ function printContent() {
|
||||
</p>
|
||||
<p>
|
||||
See some details about how to create these queries in the
|
||||
<a href="<?=$root?>/manual/JOOQ/Query/" title="jOOQ Manual reference: Query and its subtypes">Query section</a> of the manual
|
||||
<a href="<?=$root?>/manual/JOOQ/Query/" title="jOOQ Manual reference: The Query and its various subtypes">Query section</a> of the manual
|
||||
</p>
|
||||
|
||||
<h2>TableFields</h2>
|
||||
|
||||
@ -7,17 +7,88 @@ function printH1() {
|
||||
print "Updatable Records";
|
||||
}
|
||||
function getSlogan() {
|
||||
return "";
|
||||
return "
|
||||
UpdatableRecords are a specific subtype of TableRecord that have
|
||||
primary key information associated with them.
|
||||
";
|
||||
}
|
||||
function printContent() {
|
||||
global $root;
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/JOOQ/">jOOQ classes and their usage</a> : <a href="<?=$root?>/manual/JOOQ/UpdatableRecord/">Updatable Records</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/JOOQ/Result/" title="Previous section: Results and Records">previous</a> : <a href="<?=$root?>/manual/JOOQ/Query/" title="Next section: Query and its subtypes">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/JOOQ/">jOOQ classes and their usage</a> : <a href="<?=$root?>/manual/JOOQ/UpdatableRecord/">Updatable Records</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/JOOQ/Result/" title="Previous section: Results and Records">previous</a> : <a href="<?=$root?>/manual/JOOQ/Query/" title="Next section: The Query and its various subtypes">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</table>
|
||||
<h2>CRUD Operations</h2>
|
||||
<p>As of jOOQ 1.5, the UpdatableRecord essentially contains three additional
|
||||
methods <a href="http://de.wikipedia.org/wiki/CRUD">CRUD</a>
|
||||
(Create Read Update Delete) operations: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Store any changes made to this record to the database.
|
||||
// The record executes an INSERT if the PRIMARY KEY is NULL or has been changed. Otherwise, an UPDATE is performed.
|
||||
int store();
|
||||
|
||||
// Deletes the record from the database.
|
||||
int delete();
|
||||
|
||||
// Reflects changes made in the database to this Record
|
||||
void refresh();</pre>
|
||||
<p>An example lifecycle of a book can be implemented as such:</p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Create a new record and insert it into the database
|
||||
TBookRecord book = create.newRecord(T_BOOK);
|
||||
book.setTitle("My first book");
|
||||
book.store();
|
||||
|
||||
// Update it with new values
|
||||
book.setPublishedIn(2010);
|
||||
book.store();
|
||||
|
||||
// Delete it
|
||||
book.delete();</pre>
|
||||
<p>These operations are very simple utilities. They do not
|
||||
reflect the functionality offered by <a href="http://www.hibernate.org/">Hibernate</a>
|
||||
or other persistence managers. </p>
|
||||
|
||||
<h2>Performing CRUD on non-updatable records</h2>
|
||||
<p>
|
||||
If the jOOQ code-generator cannot detect any PRIMARY KEY, or UNIQUE KEY
|
||||
on your tables, then the generated artefacts implement TableRecord,
|
||||
instead of UpdatableRecord. A TableRecord can perform the same CRUD
|
||||
operations as we have seen before, if you provide it with the necessary
|
||||
key fields. The API looks like this:
|
||||
</p>
|
||||
|
||||
<pre class="prettyprint lang-java">
|
||||
// INSERT or UPDATE the record using the provided keys
|
||||
int storeUsing(TableField<R, ?>... keys)
|
||||
|
||||
// DELETE a record using the provided keys
|
||||
int deleteUsing(TableField<R, ?>... keys);
|
||||
|
||||
// Reflects changes made in the database to this Record
|
||||
void refreshUsing(TableField<R, ?>... keys);</pre>
|
||||
|
||||
<p>
|
||||
This is useful if your RDBMS does not support referential constraints (e.g. MySQL's
|
||||
<a href="http://en.wikipedia.org/wiki/MyISAM">MyISAM</a>), or if you want to
|
||||
store records to an unconstrained view. An example lifecycle of a book without
|
||||
any keys can then be implemented as such:
|
||||
</p>
|
||||
<pre class="prettyprint lang-lava">
|
||||
// Create a new record and insert it into the database
|
||||
TBookRecord book = create.newRecord(T_BOOK);
|
||||
book.setTitle("My first book");
|
||||
book.storeUsing(TBook.ID);
|
||||
|
||||
// Update it with new values
|
||||
book.setPublishedIn(2010);
|
||||
book.storeUsing(TBook.ID);
|
||||
|
||||
// Delete it
|
||||
book.deleteUsing(TBook.ID);</pre>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ function printContent() {
|
||||
<p>
|
||||
This section is about the main jOOQ classes and the global
|
||||
architecture. Most of the time, however, you will be using the
|
||||
<a href="<?=$root?>/manual/DSL/" title="jOOQ Manual reference: DSL or fluent API">DSL or fluent API</a>
|
||||
<a href="<?=$root?>/manual/DSL/" title="jOOQ Manual reference: DSL or fluent API. Where SQL meets Java">DSL or fluent API. Where SQL meets Java</a>
|
||||
in order to create queries
|
||||
the way you're used to in SQL
|
||||
</p>
|
||||
@ -60,7 +60,7 @@ function printContent() {
|
||||
<a href="<?=$root?>/manual/JOOQ/UpdatableRecord/" title="Updatable Records">Updatable Records</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="<?=$root?>/manual/JOOQ/Query/" title="Query and its subtypes">Query and its subtypes</a>
|
||||
<a href="<?=$root?>/manual/JOOQ/Query/" title="The Query and its various subtypes">The Query and its various subtypes</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="<?=$root?>/manual/JOOQ/ResultQuery/" title="ResultQuery and various ways of fetching data">ResultQuery and various ways of fetching data</a>
|
||||
|
||||
@ -14,7 +14,7 @@ function printContent() {
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/META/">Meta model code generation</a> : <a href="<?=$root?>/manual/META/SEQUENCE/">Sequences</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/META/UDT/" title="Previous section: UDT's including ARRAY and ENUM types">previous</a> : <a href="<?=$root?>/manual/DSL/" title="Next section: DSL or fluent API">next</a></td>
|
||||
<td align="left" valign="top"><a href="<?=$root?>/manual/">The jOOQ User Manual</a> : <a href="<?=$root?>/manual/META/">Meta model code generation</a> : <a href="<?=$root?>/manual/META/SEQUENCE/">Sequences</a></td><td align="right" valign="top" style="white-space: nowrap"><a href="<?=$root?>/manual/META/UDT/" title="Previous section: UDT's including ARRAY and ENUM types">previous</a> : <a href="<?=$root?>/manual/DSL/" title="Next section: DSL or fluent API. Where SQL meets Java">next</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
@ -58,7 +58,7 @@ function printContent() {
|
||||
|
||||
<li>
|
||||
|
||||
<a href="<?=$root?>/manual/DSL/" title="jOOQ Manual reference: DSL or fluent API">DSL or fluent API</a>
|
||||
<a href="<?=$root?>/manual/DSL/" title="jOOQ Manual reference: DSL or fluent API. Where SQL meets Java">DSL or fluent API. Where SQL meets Java</a>
|
||||
|
||||
<p>
|
||||
See these chapters to learn about how to use jOOQ in every day's work. The
|
||||
@ -99,7 +99,7 @@ function printContent() {
|
||||
<a href="<?=$root?>/manual/JOOQ/UpdatableRecord/" title="Updatable Records">Updatable Records</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="<?=$root?>/manual/JOOQ/Query/" title="Query and its subtypes">Query and its subtypes</a>
|
||||
<a href="<?=$root?>/manual/JOOQ/Query/" title="The Query and its various subtypes">The Query and its various subtypes</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="<?=$root?>/manual/JOOQ/ResultQuery/" title="ResultQuery and various ways of fetching data">ResultQuery and various ways of fetching data</a>
|
||||
@ -139,7 +139,7 @@ function printContent() {
|
||||
</ol>
|
||||
</li>
|
||||
<li>
|
||||
<a href="<?=$root?>/manual/DSL/" title="DSL or fluent API">DSL or fluent API</a>
|
||||
<a href="<?=$root?>/manual/DSL/" title="DSL or fluent API. Where SQL meets Java">DSL or fluent API. Where SQL meets Java</a>
|
||||
<ol>
|
||||
<li>
|
||||
<a href="<?=$root?>/manual/DSL/SELECT/" title="Complete SELECT syntax">Complete SELECT syntax</a>
|
||||
|
||||
@ -187,6 +187,7 @@ function printContent() {
|
||||
<xsl:choose>
|
||||
<xsl:when test="@id">
|
||||
<xsl:apply-templates select="//section[@id = $id]" mode="href"/>
|
||||
<xsl:value-of select="@anchor"/>
|
||||
|
||||
<xsl:if test="not(//section[@id = $id])">
|
||||
<xsl:message>
|
||||
@ -196,16 +197,25 @@ function printContent() {
|
||||
</xsl:if>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="@class and starts-with(@class, 'org.jooq.test')">
|
||||
<xsl:text>https://github.com/lukaseder/jOOQ/blob/master/jOOQ-test/src/</xsl:text>
|
||||
<xsl:value-of select="translate(@class, '.', '/')"/>
|
||||
<xsl:text>.java</xsl:text>
|
||||
<xsl:value-of select="@anchor"/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="@class and starts-with(@class, 'org.jooq')">
|
||||
<xsl:text>https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/</xsl:text>
|
||||
<xsl:value-of select="translate(@class, '.', '/')"/>
|
||||
<xsl:text>.java</xsl:text>
|
||||
<xsl:value-of select="@anchor"/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:when test="@class and starts-with(@class, 'java')">
|
||||
<xsl:text>http://download.oracle.com/javase/6/docs/api/</xsl:text>
|
||||
<xsl:value-of select="translate(@class, '.', '/')"/>
|
||||
<xsl:text>.html</xsl:text>
|
||||
<xsl:value-of select="@anchor"/>
|
||||
</xsl:when>
|
||||
|
||||
<xsl:otherwise>
|
||||
|
||||
@ -478,10 +478,495 @@ BigDecimal getValueAsBigDecimal(int fieldIndex);
|
||||
|
||||
<section id="UpdatableRecord">
|
||||
<title>Updatable Records</title>
|
||||
<slogan>
|
||||
UpdatableRecords are a specific subtype of TableRecord that have
|
||||
primary key information associated with them.
|
||||
</slogan>
|
||||
<content>
|
||||
<h2>CRUD Operations</h2>
|
||||
<p>As of jOOQ 1.5, the UpdatableRecord essentially contains three additional
|
||||
methods <a href="http://de.wikipedia.org/wiki/CRUD">CRUD</a>
|
||||
(Create Read Update Delete) operations: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Store any changes made to this record to the database.
|
||||
// The record executes an INSERT if the PRIMARY KEY is NULL or has been changed. Otherwise, an UPDATE is performed.
|
||||
int store();
|
||||
|
||||
// Deletes the record from the database.
|
||||
int delete();
|
||||
|
||||
// Reflects changes made in the database to this Record
|
||||
void refresh();</pre>
|
||||
<p>An example lifecycle of a book can be implemented as such:</p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Create a new record and insert it into the database
|
||||
TBookRecord book = create.newRecord(T_BOOK);
|
||||
book.setTitle("My first book");
|
||||
book.store();
|
||||
|
||||
// Update it with new values
|
||||
book.setPublishedIn(2010);
|
||||
book.store();
|
||||
|
||||
// Delete it
|
||||
book.delete();</pre>
|
||||
<p>These operations are very simple utilities. They do not
|
||||
reflect the functionality offered by <a href="http://www.hibernate.org/">Hibernate</a>
|
||||
or other persistence managers. </p>
|
||||
|
||||
<h2>Performing CRUD on non-updatable records</h2>
|
||||
<p>
|
||||
If the jOOQ code-generator cannot detect any PRIMARY KEY, or UNIQUE KEY
|
||||
on your tables, then the generated artefacts implement TableRecord,
|
||||
instead of UpdatableRecord. A TableRecord can perform the same CRUD
|
||||
operations as we have seen before, if you provide it with the necessary
|
||||
key fields. The API looks like this:
|
||||
</p>
|
||||
|
||||
<pre class="prettyprint lang-java">
|
||||
// INSERT or UPDATE the record using the provided keys
|
||||
int storeUsing(TableField<R, ?>... keys)
|
||||
|
||||
// DELETE a record using the provided keys
|
||||
int deleteUsing(TableField<R, ?>... keys);
|
||||
|
||||
// Reflects changes made in the database to this Record
|
||||
void refreshUsing(TableField<R, ?>... keys);</pre>
|
||||
|
||||
<p>
|
||||
This is useful if your RDBMS does not support referential constraints (e.g. MySQL's
|
||||
<a href="http://en.wikipedia.org/wiki/MyISAM">MyISAM</a>), or if you want to
|
||||
store records to an unconstrained view. An example lifecycle of a book without
|
||||
any keys can then be implemented as such:
|
||||
</p>
|
||||
<pre class="prettyprint lang-lava">
|
||||
// Create a new record and insert it into the database
|
||||
TBookRecord book = create.newRecord(T_BOOK);
|
||||
book.setTitle("My first book");
|
||||
book.storeUsing(TBook.ID);
|
||||
|
||||
// Update it with new values
|
||||
book.setPublishedIn(2010);
|
||||
book.storeUsing(TBook.ID);
|
||||
|
||||
// Delete it
|
||||
book.deleteUsing(TBook.ID);</pre>
|
||||
</content>
|
||||
</section>
|
||||
|
||||
|
||||
<section id="Query">
|
||||
<title>Query and its subtypes</title>
|
||||
<title>The Query and its various subtypes</title>
|
||||
<slogan>
|
||||
The Query type hierarchy is what you use to execute queries. It has the
|
||||
following subtypes for each kind of operation
|
||||
</slogan>
|
||||
<content>
|
||||
<h2>SELECT statements</h2>
|
||||
<p>
|
||||
There are essentially two ways of creating SELECT statements in jOOQ.
|
||||
For historical reasons, you can create
|
||||
<reference class="org.jooq.SimpleSelectQuery"/> or
|
||||
<reference class="org.jooq.SelectQuery"/>
|
||||
objects and add additional query clauses, such as
|
||||
<reference class="org.jooq.Condition" title="Conditions"/> or
|
||||
<reference class="org.jooq.SortField" title="SortFields"/> to it.
|
||||
Since jOOQ 1.3, there is also the possibility to
|
||||
create SELECT statements using jOOQ's
|
||||
<reference id="DSL" title="DSL API"/> in a much more intuitive
|
||||
and SQL-like way.
|
||||
</p>
|
||||
<p>Use the DSL API when: </p>
|
||||
<ul>
|
||||
<li>You want your code to look like SQL</li>
|
||||
<li>You want your IDE to help you with auto-completion (you will not be able to write select .. order by .. where .. join or any of that stuff) </li>
|
||||
</ul>
|
||||
<p>Use the regular API when: </p>
|
||||
<ul>
|
||||
<li>You want to create your query step-by-step, creating query parts one-by-one</li>
|
||||
<li>You need to assemble your query from various places, passing the query around, adding new conditions and joins on the way </li>
|
||||
</ul>
|
||||
<p>In any case, all API's will construct the same underlying
|
||||
implementation object, and in many cases, you can combine the two
|
||||
approaches. Let's check out the various SELECT statement types: </p>
|
||||
|
||||
<ul>
|
||||
<li><reference class="org.jooq.Select"/>:
|
||||
This Query subtype stands for a general type of SELECT statement.
|
||||
It is also the main Select type for the
|
||||
<reference id="DSL" title="DSL API"/>. When executed, this object
|
||||
will hold a <reference id="Result" title="Result containing the resulting Records"/>.
|
||||
This type is further subtyped for the various uses of a SELECT statement as such:</li>
|
||||
<li><reference class="org.jooq.SimpleSelectQuery"/>:
|
||||
This Query will allow for selecting from single physical Tables only.
|
||||
It therefore has access to the Table's generic type parameter
|
||||
<R extends Record> and will provide a matching Result<R>.
|
||||
This is especially useful if <R> is a subtype of
|
||||
<reference id="UpdatableRecord" title="UpdatableRecord"/>.
|
||||
Then you will be able to perform updates on your result set immediately.</li>
|
||||
<li><reference class="org.jooq.SelectQuery"/>:
|
||||
This Query will allow for selecting a subset of Fields from several
|
||||
Tables. Because the results of such a query are considered of an anonymous
|
||||
or ad-hoc type, this Query will bind <R> to the general type Record
|
||||
itself. The purpose of this Query type is to allow for full SQL support,
|
||||
including SELECT, JOIN and GROUP BY clauses. </li>
|
||||
</ul>
|
||||
|
||||
<h3>Example: SQL query and DSL query</h3>
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td width="50%" class="left">A sample SQL statement</td>
|
||||
<td width="50%" class="right">...and its equivalent in jOOQ's DSL API</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="50%" class="left"><pre class="prettyprint lang-sql">
|
||||
-- Select all books by authors born after 1920, named "Paulo"
|
||||
-- from a catalogue consisting of authors and books:
|
||||
|
||||
|
||||
SELECT *
|
||||
FROM t_author a
|
||||
JOIN t_book b
|
||||
ON a.id = b.author_id
|
||||
WHERE a.year_of_birth > 1920
|
||||
AND a.first_name = 'Paulo'
|
||||
ORDER BY b.title</pre></td>
|
||||
<td width="50%" class="right"><pre class="prettyprint lang-java">
|
||||
// Instanciate your factory using a JDBC connection.
|
||||
Factory create = new Factory(connection, SQLDialect.ORACLE);
|
||||
|
||||
// Execute the query "on a single line"
|
||||
Result<Record> result = create.select()
|
||||
.from(T_AUTHOR)
|
||||
.join(T_BOOK)
|
||||
.on(ID.equal(AUTHOR_ID))
|
||||
.where(YEAR_OF_BIRTH.greaterThan(1920)
|
||||
.and(FIRST_NAME.equal("Paulo")))
|
||||
.orderBy(TITLE).fetch();</pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
In the above example, some generated artefacts are used for querying.
|
||||
In this case, T_AUTHOR and T_BOOK are instances of types
|
||||
<reference class="org.jooq.test.oracle.generatedclasses.tables.TAuthor" title="TAuthor"/> and
|
||||
<reference class="org.jooq.test.oracle.generatedclasses.tables.TBook" title="TBook"/> respectively.
|
||||
Their full qualification would read TAuthor.T_AUTHOR and TBook.T_BOOK, but in many cases,
|
||||
it's useful to static import elements involved with queries, in order to decrease verbosity.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Apart from the singleton Table instances TAuthor.T_AUTHOR and
|
||||
TBook.T_BOOK, these generated classes also contain one static member
|
||||
for every physical field, such as TAuthor.ID or TBook.TAUTHOR_ID, etc.
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li>For more information about code generation, check out the manual's section about
|
||||
<reference id="META" title="Meta model source code generation"/>.</li>
|
||||
<li>For more DSL examples, please consider the manual's section about the
|
||||
<reference id="DSL" title="DSL API"/>.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Example: Non-DSL query</h3>
|
||||
<p>
|
||||
If you choose not to use the DSL API (for instance, because you don't
|
||||
want to add Query parts in the order SQL expects them), you can use
|
||||
this syntax:
|
||||
</p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Re-use the factory to create a SelectQuery. This example will not make use of static imports...
|
||||
SelectQuery q = create.selectQuery();
|
||||
q.addFrom(TAuthor.T_AUTHOR);
|
||||
|
||||
// This example shows some "mixed" API usage, where the JOIN is added with the standard API, and the
|
||||
// Condition is created using the DSL API
|
||||
q.addJoin(TBook.T_BOOK, TAuthor.ID.equal(TBook.AUTHOR_ID));
|
||||
|
||||
// The AND operator between Conditions is implicit here
|
||||
q.addConditions(TAuthor.YEAR_OF_BIRTH.greaterThan(1920));
|
||||
q.addConditions(TAuthor.FIRST_NAME.equal("Paulo"));
|
||||
q.addOrderBy(TBook.TITLE);</pre>
|
||||
|
||||
<h3>Fetching data</h3>
|
||||
<p>
|
||||
The <reference class="org.jooq.Select"/> interface extends
|
||||
<reference class="org.jooq.ResultQuery"/>,
|
||||
which provides a range of methods to fetch data from the database.
|
||||
Once you have constructed your SELECT query (see examples above), you
|
||||
may choose to either simply execute() it, or use a variety of convenience
|
||||
fetchXXX() methods.
|
||||
</p>
|
||||
<p>
|
||||
See the manual's
|
||||
<reference id="ResultQuery" title="section on the ResultQuery"/>
|
||||
for more details.
|
||||
</p>
|
||||
|
||||
|
||||
<h2>INSERT Statements</h2>
|
||||
<p>jOOQ supports two modes for INSERT statements.
|
||||
The INSERT VALUES and the INSERT SELECT syntax</p>
|
||||
|
||||
<h3>Example: SQL query and DSL query</h3>
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td width="50%" class="left">A typical INSERT query looks like this</td>
|
||||
<td width="50%" class="right">...and how it's done with jOOQ</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="50%" class="left"><pre class="prettyprint lang-sql">
|
||||
INSERT INTO T_AUTHOR
|
||||
(ID, FIRST_NAME, LAST_NAME)
|
||||
VALUES
|
||||
(100, 'Hermann', 'Hesse'),
|
||||
(101, 'Alfred', 'Döblin');</pre>
|
||||
</td>
|
||||
<td width="50%" class="right"><pre class="prettyprint lang-java">
|
||||
create.insertInto(T_AUTHOR,
|
||||
TAuthor.ID, TAuthor.FIRST_NAME, TAuthor.LAST_NAME)
|
||||
.values(100, "Hermann", "Hesse")
|
||||
.values(101, "Alfred", "Döblin")
|
||||
.execute();</pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>The DSL syntax tries to stay close to actual SQL. In detail,
|
||||
however, Java is limited in its possibilities. That's why the
|
||||
.values() clause is repeated for every record. Some RDBMS support
|
||||
inserting several records at the same time. This is also supported in
|
||||
jOOQ, and simulated using INSERT INTO .. SELECT .. UNION ALL SELECT ..
|
||||
clauses for those RDBMS that don't support this syntax.
|
||||
</p>
|
||||
<p>Note: Just like in SQL itself, you can have syntax errors when you
|
||||
don't have matching numbers of fields/values. Also, you can run into
|
||||
runtime problems, if your field/value types don't match. </p>
|
||||
|
||||
<h3>Example: DSL Query, alternative syntax</h3>
|
||||
<p>MySQL (and some other RDBMS) allow for using an UPDATE-like syntax
|
||||
for INSERT statements. This is also supported in jOOQ, should you
|
||||
prefer that syntax. The above INSERT statement can also be expressed
|
||||
as follows: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
create.insertInto(T_AUTHOR)
|
||||
.set(TAuthor.ID, 100)
|
||||
.set(TAuthor.FIRST_NAME, "Hermann")
|
||||
.set(TAuthor.LAST_NAME, "Hesse")
|
||||
.newRecord()
|
||||
.set(TAuthor.ID, 101)
|
||||
.set(TAuthor.FIRST_NAME, "Alfred")
|
||||
.set(TAuthor.LAST_NAME, "Döblin")
|
||||
.execute();</pre>
|
||||
<p>As you can see, this syntax is a bit more verbose, but also more
|
||||
type-safe, as every field can be matched with its value.</p>
|
||||
|
||||
<h3>Example: ON DUPLICATE KEY UPDATE clause</h3>
|
||||
<p>The MySQL database supports a very convenient way to INSERT or
|
||||
UPDATE a record. This is a non-standard extension to the SQL syntax,
|
||||
which is supported by jOOQ and simulated in other RDBMS, where this is
|
||||
possible. Here is an example how to use the ON DUPLICATE KEY UPDATE
|
||||
clause: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Add a new author called "Koontz" with ID 3.
|
||||
// If that ID is already present, update the author's name
|
||||
create.insertInto(T_AUTHOR, TAuthor.ID, TAuthor.LAST_NAME)
|
||||
.values(3, "Koontz")
|
||||
.onDuplicateKeyUpdate()
|
||||
.set(TAuthor.LAST_NAME, "Koontz")
|
||||
.execute();</pre>
|
||||
|
||||
<h3>Example: INSERT .. RETURNING clause</h3>
|
||||
<p>The Postgres database has native support for an INSERT .. RETURNING
|
||||
clause. This is a very powerful concept that is simulated for all
|
||||
other dialects using JDBC's
|
||||
<reference class="java.sql.Statement" anchor="#getGeneratedKeys()" title="getGeneratedKeys()"/>
|
||||
method. Take this example:</p>
|
||||
|
||||
<pre class="prettyprint lang-java">
|
||||
// Add another author, with a generated ID
|
||||
Record<?> record =
|
||||
create.insertInto(T_AUTHOR, TAuthor.FIRST_NAME, TAuthor.LAST_NAME)
|
||||
.values("Charlotte", "Roche")
|
||||
.returning(TAuthor.ID)
|
||||
.fetchOne();
|
||||
|
||||
System.out.println(record.getValue(TAuthor.ID));
|
||||
|
||||
// For some RDBMS, this also works when inserting several values
|
||||
Result<?> result =
|
||||
create.insertInto(T_AUTHOR, TAuthor.FIRST_NAME, TAuthor.LAST_NAME)
|
||||
.values("Johann Wolfgang", "von Goethe")
|
||||
.values("Friedrich", "Schiller")
|
||||
// You can request any field. Also trigger-generated values
|
||||
.returning(TAuthor.ID, TAuthor.CREATION_DATE)
|
||||
.fetch();</pre>
|
||||
|
||||
<h3>Example: Non-DSL Query</h3>
|
||||
<p>You can always use the more verbose regular syntax of the InsertQuery, if you need more control: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Insert a new author into the T_AUTHOR table
|
||||
InsertQuery<TAuthorRecord> i = create.insertQuery(T_AUTHOR);
|
||||
i.addValue(TAuthor.ID, 100);
|
||||
i.addValue(TAuthor.FIRST_NAME, "Hermann");
|
||||
i.addValue(TAuthor.LAST_NAME, "Hesse");
|
||||
|
||||
i.newRecord();
|
||||
i.addValue(TAuthor.ID, 101);
|
||||
i.addValue(TAuthor.FIRST_NAME, "Alfred");
|
||||
i.addValue(TAuthor.LAST_NAME, "Döblin");
|
||||
i.execute();</pre>
|
||||
|
||||
<h3>Example: INSERT Query combined with SELECT statements</h3>
|
||||
<p>The InsertQuery.addValue() method is overloaded, such that you can
|
||||
also provide a Field, potentially containing an expression: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
// Insert a new author into the T_AUTHOR table
|
||||
InsertQuery<TAuthorRecord> i = create.insertQuery(T_AUTHOR);
|
||||
i.addValue(TAuthor.ID, create.select(TAuthor.ID.max().add(1)).from(T_AUTHOR).asField())
|
||||
i.addValue(TAuthor.FIRST_NAME, "Hermann");
|
||||
i.addValue(TAuthor.LAST_NAME, "Hesse");
|
||||
i.execute();</pre>
|
||||
<p>Note that especially MySQL (and some other RDBMS) has some
|
||||
limitations regarding that syntax. You may not be able to
|
||||
select from the same table you're inserting into</p>
|
||||
|
||||
<h3>Example: INSERT SELECT syntax support</h3>
|
||||
<p>In some occasions, you may prefer the INSERT SELECT syntax, for instance, when
|
||||
you copy records from one table to another: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
Insert i = create.insertInto(T_AUTHOR_ARCHIVE,
|
||||
create.selectFrom(T_AUTHOR).where(TAuthor.DECEASED.equal(1)));
|
||||
i.execute();</pre>
|
||||
|
||||
|
||||
<h2>UPDATE Statements</h2>
|
||||
<p>UPDATE statements are only possible on single tables. Support for
|
||||
multi-table updates will be implemented in the near future. </p>
|
||||
|
||||
<h3>Example: SQL query and DSL query</h3>
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td width="50%" class="left">A typical UPDATE query looks like this</td>
|
||||
<td width="50%" class="right">...and how it's done with jOOQ</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="50%" class="left"><pre class="prettyprint lang-sql">
|
||||
|
||||
UPDATE T_AUTHOR
|
||||
SET FIRST_NAME = 'Hermann',
|
||||
LAST_NAME = 'Hesse'
|
||||
WHERE ID = 3;</pre>
|
||||
</td>
|
||||
<td width="50%" class="right"><pre class="prettyprint lang-java">
|
||||
create.update(T_AUTHOR)
|
||||
.set(TAuthor.FIRST_NAME, "Hermann")
|
||||
.set(TAuthor.LAST_NAME, "Hesse")
|
||||
.where(TAuthor.ID.equal(3))
|
||||
.execute();</pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h3>Example: Non-DSL Query</h3>
|
||||
<p>Using the <reference class="org.jooq.UpdateQuery"/> class,
|
||||
this is how you could express an UPDATE statement:</p>
|
||||
<pre class="prettyprint lang-java">
|
||||
UpdateQuery<TAuthorRecord> u = create.updateQuery(T_AUTHOR);
|
||||
u.addValue(TAuthor.FIRST_NAME, "Hermann");
|
||||
u.addValue(TAuthor.FIRST_NAME, "Hesse");
|
||||
u.addConditions(TAuthor.ID.equal(3));
|
||||
u.execute();</pre>
|
||||
|
||||
|
||||
<h2>DELETE Statements</h2>
|
||||
<p>DELETE statements are only possible on single tables. Support for
|
||||
multi-table deletes will be implemented in the near future. </p>
|
||||
|
||||
<h3>Example: SQL query and DSL query</h3>
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td width="50%" class="left">A typical DELETE query looks like this</td>
|
||||
<td width="50%" class="right">...and how it's done with jOOQ</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="50%" class="left"><pre class="prettyprint lang-sql">
|
||||
|
||||
DELETE T_AUTHOR
|
||||
WHERE ID = 100;</pre>
|
||||
</td>
|
||||
<td width="50%" class="right"><pre class="prettyprint lang-java">
|
||||
create.delete(T_AUTHOR)
|
||||
.where(TAuthor.ID.equal(100))
|
||||
.execute();</pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h3>Example: Non-DSL Query</h3>
|
||||
<p>Using the <reference class="org.jooq.DeleteQuery"/> class,
|
||||
this is how you could express a DELETE statement: </p>
|
||||
<pre class="prettyprint lang-java">
|
||||
DeleteQuery<TAuthorRecord> d = create.deleteQuery(T_AUTHOR);
|
||||
d.addConditions(TAuthor.ID.equal(100));
|
||||
d.execute();</pre>
|
||||
|
||||
|
||||
<h2>MERGE Statement</h2>
|
||||
<p>
|
||||
The MERGE statement is one of the most advanced standardised SQL
|
||||
constructs, which is supported by DB2, HSQLDB, Oracle, SQL Server and
|
||||
Sybase (MySQL has the similar INSERT .. ON DUPLICATE KEY UPDATE
|
||||
construct. H2's MERGE variant is currently not supported.)
|
||||
</p>
|
||||
<p>
|
||||
The point of the standard MERGE statement is to take a TARGET table, and
|
||||
merge (INSERT, UPDATE) data from a SOURCE table into it. DB2, Oracle,
|
||||
SQL Server and Sybase also allow for DELETING some data and for adding
|
||||
many additional clauses. Those non-standard extensions are currently
|
||||
not supported. Here is an example:
|
||||
</p>
|
||||
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td width="50%" class="left"><pre class="prettyprint lang-sql">
|
||||
-- Check if there is already an author called 'Hitchcock'
|
||||
-- If there is, rename him to John. If there isn't add him.
|
||||
|
||||
MERGE INTO T_AUTHOR
|
||||
USING (SELECT 1 FROM DUAL)
|
||||
ON (LAST_NAME = 'Hitchcock')
|
||||
WHEN MATCHED THEN UPDATE SET FIRST_NAME = 'John'
|
||||
WHEN NOT MATCHED THEN INSERT (LAST_NAME) VALUES ('Hitchcock')</pre>
|
||||
</td>
|
||||
<td width="50%" class="right"><pre class="prettyprint lang-java">
|
||||
create.mergeInto(T_AUTHOR)
|
||||
.using(create().selectOne())
|
||||
.on(TAuthor.LAST_NAME.equal("Hitchcock"))
|
||||
.whenMatchedThenUpdate()
|
||||
.set(TAuthor.FIRST_NAME, "John")
|
||||
.whenNotMatchedThenInsert(TAuthor.LAST_NAME)
|
||||
.values("Hitchcock")
|
||||
.execute();</pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<h2>TRUNCATE Statement</h2>
|
||||
<p>
|
||||
The syntax is trivial:
|
||||
</p>
|
||||
<table width="100%" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td width="50%" class="left"><pre class="prettyprint lang-sql">TRUNCATE TABLE T_AUTHOR;</pre>
|
||||
</td>
|
||||
<td width="50%" class="right"><pre class="prettyprint lang-java">create.truncate(T_AUTHOR).execute();</pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>This is not supported by Ingres and SQLite. jOOQ will execute a DELETE FROM
|
||||
T_AUTHOR statement instead. </p>
|
||||
</content>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<section id="ResultQuery">
|
||||
<title>ResultQuery and various ways of fetching data</title>
|
||||
</section>
|
||||
@ -520,7 +1005,7 @@ BigDecimal getValueAsBigDecimal(int fieldIndex);
|
||||
</sections>
|
||||
</section>
|
||||
<section id="DSL">
|
||||
<title>DSL or fluent API</title>
|
||||
<title>DSL or fluent API. Where SQL meets Java</title>
|
||||
<sections>
|
||||
<section id="SELECT">
|
||||
<title>Complete SELECT syntax</title>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user