Added some sections to the manual

This commit is contained in:
Lukas Eder 2011-09-21 18:08:20 +00:00
parent 4abcf0059e
commit 6095d5c1c4
9 changed files with 381 additions and 353 deletions

View File

@ -142,7 +142,7 @@ a:hover {
}
#navigation {
padding-top: 1em;
padding-top: 1.3em;
padding-left: 3em;
padding-right: 3em;

View File

@ -7,7 +7,9 @@ function printH1() {
print "Nested SELECT using the EXISTS operator";
}
function getSlogan() {
return "";
return "The EXISTS operator is a bit different from all other SQL
elements, as it cannot really be applied to any object in a DSL.
";
}
function printContent() {
global $root;
@ -16,7 +18,78 @@ function printContent() {
<tr>
<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 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 using the IN operator">previous</a> : <a href="<?=$root?>/manual/DSL/NESTED/" title="Next section: Other types of nested SELECT">next</a></td>
</tr>
</table><br><table cellpadding="0" cellspacing="0" border="0" width="100%">
</table>
<h2>The EXISTS operator for use in semi-joins or anti-joins</h2>
<p>The EXISTS operator is rather independent and can stand any place
where there may be a new condition: </p>
<ul>
<li>It may be placed right after a WHERE keyword </li>
<li>It may be the right-hand-side of a boolean operator</li>
<li>It may be placed right after a ON or HAVING keyword (although, this is less likely to be done...) </li>
</ul>
<p>This is reflected by the fact that an EXISTS clause is usually
created directly from the Factory. While this is more verbose than all
the other SQL constructs, there is no other way, when static QueryPart
creation is not an option (for now). Here is how it's done in the
Factory: </p>
<pre class="prettyprint lang-java">
Condition exists(Select&lt;?&gt; query);
Condition notExists(Select&lt;?&gt; query);</pre>
<p>When you create such a Condition, it can then be connected to any
other condition using AND, OR operators (see also the manual's section
on
<a href="" title="jOOQ Manual reference: ">Conditions</a>). Because of this verbosity, there are also quite a few
convenience methods, where they might be useful. For instance in the
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/Condition.java" title="Internal API reference: org.jooq.Condition">org.jooq.Condition</a> itself: </p>
<pre class="prettyprint lang-java">
Condition andExists(Select&lt;?&gt; select);
Condition andNotExists(Select&lt;?&gt; select);
Condition orExists(Select&lt;?&gt; select);
Condition orNotExists(Select&lt;?&gt; select);</pre>
<p>Or in the <a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/SelectWhereStep.java" title="Internal API reference: org.jooq.SelectWhereStep">org.jooq.SelectWhereStep</a>:</p>
<pre class="prettyprint lang-java">
SelectConditionStep whereExists(Select&lt;?&gt; select);
SelectConditionStep whereNotExists(Select&lt;?&gt; select);</pre>
<p>Or in the <a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/SelectConditionStep.java" title="Internal API reference: org.jooq.SelectConditionStep">org.jooq.SelectConditionStep</a>: </p>
<pre class="prettyprint lang-java">
SelectConditionStep andExists(Select&lt;?&gt; select);
SelectConditionStep andNotExists(Select&lt;?&gt; select);
SelectConditionStep orExists(Select&lt;?&gt; select);
SelectConditionStep orNotExists(Select&lt;?&gt; select);</pre>
<p>An example of how to use it is quickly given. Get all authors that haven't written any books: </p>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" class="left">
<pre class="prettyprint lang-sql">
SELECT *
FROM T_AUTHOR
WHERE NOT EXISTS (SELECT 1
FROM T_BOOK
WHERE T_BOOK.AUTHOR_ID = T_AUTHOR.ID)</pre>
</td><td width="50%" class="right">
<pre class="prettyprint lang-java">
create.select()
.from(T_AUTHOR)
.whereNotExists(create.select(1)
.from(T_BOOK)
.where(TBook.AUTHOR_ID.equal(T_AUTHOR.ID)));</pre>
</td>
</tr>
</table>
<br><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. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/EXISTS/">Nested SELECT 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 using the IN operator">previous</a> : <a href="<?=$root?>/manual/DSL/NESTED/" title="Next section: Other types of nested SELECT">next</a></td>
</tr>

View File

@ -20,7 +20,7 @@ function printContent() {
<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 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 using the EXISTS operator">next</a></td>
</tr>
</table>
<h2>The IN operator for use in semi-joins</h2>
<h2>The IN operator for use in semi-joins or anti-joins</h2>
<p>
In addition to a list of constant values, the IN operator in
<a href="https://github.com/lukaseder/jOOQ/blob/master/jOOQ/src/main/java/org/jooq/Field.java" title="Internal API reference: org.jooq.Field">org.jooq.Field</a>
@ -37,11 +37,9 @@ function printContent() {
course, this is possible with a plain JOIN as well, but let's say we
want to use the IN operator. Then you have two possibilities: </p>
<table cellpadding="0" cellspacing="0" width="100%">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="left" width="50%">
<td width="50%" class="left">
<pre class="prettyprint lang-sql">
SELECT *
FROM T_BOOK
@ -55,8 +53,7 @@ SELECT T_BOOK.*
FROM T_BOOK
JOIN T_AUTHOR ON (T_BOOK.AUTHOR_ID = T_AUTHOR.ID
AND T_AUTHOR.BORN = 1920)</pre>
</td>
<td class="right" width="50%">
</td><td width="50%" class="right">
<pre class="prettyprint lang-java">
create.select()
.from(T_BOOK)
@ -71,10 +68,8 @@ create.select(T_BOOK.getFields())
.join(T_AUTHOR).on(TBook.AUTHOR_ID.equal(TAuthor.ID)
.and(TAuthor.BORN.equal(1920)));</pre>
</td>
</tr>
</table>
</table>
<br><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. Where SQL meets Java</a> : <a href="<?=$root?>/manual/DSL/IN/">Nested SELECT 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 using the EXISTS operator">next</a></td>

View File

@ -25,18 +25,9 @@ function printContent() {
</p>
<p>Here is an example to show you what that means. When you want to write a query like this in SQL: </p>
<table cellpadding="0" cellspacing="0" width="100%">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%">Here is an example to show you what that means. When you want to write a query like this in SQL: </td>
<td width="50%">Then, using jOOQ's DSL API, you can write the same query as such: </td>
</tr>
<tr>
<td class="left" width="50%">
<td width="50%" class="left">
<pre class="prettyprint lang-sql">
-- Select all books by authors born after 1920,
-- named "Paulo" from a catalogue:
@ -46,8 +37,7 @@ SELECT *
WHERE a.year_of_birth &gt; 1920
AND a.first_name = 'Paulo'
ORDER BY b.title</pre>
</td>
<td class="right" width="50%">
</td><td width="50%" class="right">
<pre class="prettyprint lang-java">
Result&lt;Record&gt; result =
create.select()
@ -58,9 +48,7 @@ create.select()
.orderBy(TBook.TITLE)
.fetch();</pre>
</td>
</tr>
</table>
<p>You couldn't come much closer to SQL itself in Java, without re-writing the compiler. </p>

View File

@ -47,8 +47,7 @@ public void toSQL(RenderContext context);
// variable binding to them in the correct order, passing the bind context.
//
// Every QueryPart must ensure, that it starts binding its variables at context.nextIndex().
public void bind(BindContext context) throws SQLException;
</pre>
public void bind(BindContext context) throws SQLException;</pre>
<p>The above contract may be a bit tricky to understand at first. The
best thing is to check out jOOQ source code and have a look at a

View File

@ -84,18 +84,9 @@ function printContent() {
</ul>
<h3>Example: SQL query and DSL query</h3>
<table cellpadding="0" cellspacing="0" width="100%">
<table width="100%" cellpadding="0" cellspacing="0">
<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%">
<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:
@ -108,8 +99,7 @@ SELECT *
WHERE a.year_of_birth &gt; 1920
AND a.first_name = 'Paulo'
ORDER BY b.title</pre>
</td>
<td class="right" width="50%">
</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);
@ -123,9 +113,7 @@ Result&lt;Record&gt; result = create.select()
.and(FIRST_NAME.equal("Paulo")))
.orderBy(TITLE).fetch();</pre>
</td>
</tr>
</table>
<p>
@ -194,27 +182,16 @@ q.addOrderBy(TBook.TITLE);</pre>
The INSERT VALUES and the INSERT SELECT syntax</p>
<h3>Example: SQL query and DSL query</h3>
<table cellpadding="0" cellspacing="0" width="100%">
<table width="100%" cellpadding="0" cellspacing="0">
<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%">
<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&ouml;blin');</pre>
</td>
<td class="right" width="50%">
</td><td width="50%" class="right">
<pre class="prettyprint lang-java">
create.insertInto(T_AUTHOR,
TAuthor.ID, TAuthor.FIRST_NAME, TAuthor.LAST_NAME)
@ -222,9 +199,7 @@ create.insertInto(T_AUTHOR,
.values(101, "Alfred", "D&ouml;blin")
.execute();</pre>
</td>
</tr>
</table>
<p>The DSL syntax tries to stay close to actual SQL. In detail,
@ -340,27 +315,16 @@ i.execute();</pre>
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%">
<table width="100%" cellpadding="0" cellspacing="0">
<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%">
<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 class="right" width="50%">
</td><td width="50%" class="right">
<pre class="prettyprint lang-java">
create.update(T_AUTHOR)
.set(TAuthor.FIRST_NAME, "Hermann")
@ -368,9 +332,7 @@ create.update(T_AUTHOR)
.where(TAuthor.ID.equal(3))
.execute();</pre>
</td>
</tr>
</table>
<h3>Example: Non-DSL Query</h3>
@ -389,33 +351,20 @@ u.execute();</pre>
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%">
<table width="100%" cellpadding="0" cellspacing="0">
<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%">
<td width="50%" class="left">
<pre class="prettyprint lang-sql">
DELETE T_AUTHOR
WHERE ID = 100;</pre>
</td>
<td class="right" width="50%">
</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>
@ -442,11 +391,9 @@ d.execute();</pre>
not supported. Here is an example:
</p>
<table cellpadding="0" cellspacing="0" width="100%">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="left" width="50%">
<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.
@ -456,9 +403,7 @@ 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%">
</td><td width="50%" class="right">
<pre class="prettyprint lang-java">
create.mergeInto(T_AUTHOR)
.using(create().selectOne())
@ -469,9 +414,7 @@ create.mergeInto(T_AUTHOR)
.values("Hitchcock")
.execute();</pre>
</td>
</tr>
</table>
@ -479,20 +422,15 @@ create.mergeInto(T_AUTHOR)
<p>
The syntax is trivial:
</p>
<table cellpadding="0" cellspacing="0" width="100%">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="left" width="50%">
<td width="50%" class="left">
<pre class="prettyprint lang-sql">TRUNCATE TABLE T_AUTHOR;</pre>
</td>
<td class="right" width="50%">
</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>

View File

@ -76,7 +76,7 @@ void refreshUsing(TableField&lt;R, ?&gt;... keys);</pre>
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">
<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");

View File

@ -275,6 +275,33 @@ function printContent() {
</xsl:choose>
</a>
</xsl:when>
<xsl:when test="name(.) = 'java'">
<pre class="prettyprint lang-java">
<xsl:value-of select="text()"/>
</pre>
</xsl:when>
<xsl:when test="name(.) = 'sql'">
<pre class="prettyprint lang-sql">
<xsl:value-of select="text()"/>
</pre>
</xsl:when>
<xsl:when test="name(.) = 'xml'">
<pre class="prettyprint lang-xml">
<xsl:value-of select="text()"/>
</pre>
</xsl:when>
<xsl:when test="name(.) = 'code-pair'">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%" class="left">
<xsl:apply-templates select="sql" mode="content"/>
</td>
<td width="50%" class="right">
<xsl:apply-templates select="java" mode="content"/>
</td>
</tr>
</table>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="content"/>

File diff suppressed because it is too large Load Diff