[#2195] Remove the standalone tutorial, link to the manual

This commit is contained in:
Lukas Eder 2013-04-12 14:26:52 +02:00
parent 2b59ed047f
commit c5e6c032fb
4 changed files with 23 additions and 381 deletions

5
jOOQ-website/conf.php Normal file
View File

@ -0,0 +1,5 @@
<?php
$root = "";
$minorVersion = "3.0";
$version = $minorVersion . ".0-RC2";
?>

View File

@ -1,8 +1,5 @@
<?php
$root = "";
$minorVersion = "3.0";
$version = $minorVersion . ".0-RC2";
require 'conf.php';
function manualHeader($isSingle, $forVersion) {
global $minorVersion;
$singleSuffix = ($isSingle ? '-single-page' : '');

View File

@ -6,6 +6,13 @@ function getH1() {
function getActiveMenu() {
return "learn";
}
function printStep($step) {
global $root;
global $minorVersion;
global $version;
echo $root . '/doc/' . $minorVersion . '/manual/getting-started/tutorials/jooq-in-7-steps/jooq-in-7-steps-step' . $step;
}
function printContent() {
global $root;
global $minorVersion;
@ -17,17 +24,17 @@ function printContent() {
<td valign="top" width="50%">
<h2>Getting started</h2>
<p>
Your simplest entry point is probably to get <a href="tutorial.php">the tutorial</a>
Your simplest entry point is probably to get the tutorial
running. It shows how to use jOOQ and its code generator with a simple MySQL database
</p>
<ul>
<li><a href="tutorial.php#step0">Preparation: Download jOOQ and your SQL driver</a></li>
<li><a href="tutorial.php#step1">Step 1: Create a SQL database and a table</a></li>
<li><a href="tutorial.php#step2">Step 2: Generate classes</a></li>
<li><a href="tutorial.php#step3">Step 3: Write a main class and establish a MySQL connection</a></li>
<li><a href="tutorial.php#step4">Step 4: Write a query using jOOQ's DSL</a></li>
<li><a href="tutorial.php#step5">Step 5: Iterate over results</a></li>
<li><a href="tutorial.php#step6">Step 6: Explore!</a></li>
<li><a href="<?=printStep(1)?>">Preparation: Download jOOQ and your SQL driver</a></li>
<li><a href="<?=printStep(2)?>">Step 1: Create a SQL database and a table</a></li>
<li><a href="<?=printStep(3)?>">Step 2: Generate classes</a></li>
<li><a href="<?=printStep(4)?>">Step 3: Write a main class and establish a MySQL connection</a></li>
<li><a href="<?=printStep(5)?>">Step 4: Write a query using jOOQ's DSL</a></li>
<li><a href="<?=printStep(6)?>">Step 5: Iterate over results</a></li>
<li><a href="<?=printStep(7)?>">Step 6: Explore!</a></li>
</ul>
</td>

View File

@ -1,371 +1,4 @@
<?php
require 'frame.php';
function getH1() {
echo 'Tutorial: Getting started with jOOQ';
}
function getActiveMenu() {
return "learn";
}
function printContent() {
global $root;
global $minorVersion;
global $version;
?>
<h2 id="intro"><a href="#intro" name="intro">#</a> Introduction</h2>
<p>
Download and run jOOQ in 6 easy steps:
</p>
<ul>
<li><a href="#step0">Preparation: Download jOOQ and your SQL driver</a></li>
<li><a href="#step1">Step 1: Create a SQL database and a table</a></li>
<li><a href="#step2">Step 2: Generate classes</a></li>
<li><a href="#step3">Step 3: Write a main class and establish a MySQL connection</a></li>
<li><a href="#step4">Step 4: Write a query using jOOQ's DSL</a></li>
<li><a href="#step5">Step 5: Iterate over results</a></li>
<li><a href="#step6">Step 6: Explore!</a></li>
</ul>
<h2 id="step0"><a href="#step0" name="step0">#</a> Preparation: Download jOOQ and your SQL driver</h2>
<p>
If you haven't already downloaded them, download jOOQ:<br/>
<a href="https://sourceforge.net/projects/jooq/files/Release/" target="_blank" title="jOOQ download">https://sourceforge.net/projects/jooq/files/Release/</a>
</p>
<p>
Alternatively, you can create a Maven dependency:
</p>
<pre class="prettyprint lang-xml">
&lt;dependency&gt;
&lt;groupId&gt;org.jooq&lt;/groupId&gt;
&lt;!-- artefacts are jooq, jooq-meta, jooq-codegen --&gt;
&lt;artifactId&gt;jooq&lt;/artifactId&gt;
&lt;version&gt;<?=$version?>&lt;/version&gt;
&lt;/dependency&gt;
</pre>
<p>
For this example, we'll be using MySQL. If you haven't already downloaded MySQL Connector/J, download it here:<br/>
<a href="http://dev.mysql.com/downloads/connector/j/" target="_blank" title="MySQL JDBC driver">http://dev.mysql.com/downloads/connector/j/</a>
</p>
<p>
If you don't have a MySQL instance up and running yet, get
<a href="http://www.apachefriends.org/en/xampp.html" title="XAMPP">XAMPP</a>
now! XAMPP is a simple installation bundle for Apache, MySQL, PHP and Perl
</p>
<h2 id="step1"><a href="#step1" name="step1">#</a> Step 1: Create a SQL database and a table</h2>
<p>
We're going to create a database called "guestbook" and a corresponding "posts" table. Connect to MySQL via your command line client and type the following:
</p>
<pre class="prettyprint lang-sql">
CREATE DATABASE guestbook;
CREATE TABLE `posts` (
`id` bigint(20) NOT NULL,
`body` varchar(255) DEFAULT NULL,
`timestamp` datetime DEFAULT NULL,
`title` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
);
</pre>
<h2 id="step2"><a href="#step2" name="step2">#</a> Step 2: Generate classes</h2>
<p>
In this step, we're going to use jOOQ's command line tools to generate classes that
map to the Posts table we just created. More detailed information about how to
set up the jOOQ code generator can be found here:<br/>
<a href="http://www.jooq.org/doc/<?=$minorVersion?>/manual/code-generation/codegen-configuration" target="_blank" title="jOOQ manual pages about setting up the code generator">http://www.jooq.org/doc/<?=$minorVersion?>/manual/code-generation/codegen-configuration</a>
</p>
<p>
The easiest way to generate a schema is to copy the jOOQ jar files (there should be 3)
and the MySQL Connector jar file to a temporary directory. Then, create a guestbook.xml
that looks like this:
</p>
<pre class="prettyprint lang-xml">
&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?>
&lt;configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.0.0.xsd">
&lt;!-- Configure the database connection here -->
&lt;jdbc>
&lt;driver>com.mysql.jdbc.Driver&lt;/driver>
&lt;url>jdbc:mysql://localhost:3306/guestbook&lt;/url>
&lt;user>root&lt;/user>
&lt;password>&lt;/password>
&lt;/jdbc>
&lt;generator>
&lt;!-- The default code generator. You can override this one, to generate your own code style
Defaults to org.jooq.util.DefaultGenerator -->
&lt;name>org.jooq.util.DefaultGenerator&lt;/name>
&lt;database>
&lt;!-- The database type. The format here is:
org.util.[database].[database]Database -->
&lt;name>org.jooq.util.mysql.MySQLDatabase&lt;/name>
&lt;!-- The database schema (or in the absence of schema support, in your RDBMS this
can be the owner, user, database name) to be generated -->
&lt;inputSchema>guestbook&lt;/inputSchema>
&lt;!-- All elements that are generated from your schema (A Java regular expression. Use the pipe to separate several expressions)
Watch out for case-sensitivity. Depending on your database, this might be important! -->
&lt;includes>.*&lt;/includes>
&lt;!-- All elements that are excluded from your schema (A Java regular expression. Use the pipe to separate several expressions).
Excludes match before includes -->
&lt;excludes>&lt;/excludes>
&lt;/database>
&lt;target>
&lt;!-- The destination package of your generated classes (within the destination directory) -->
&lt;packageName>test.generated&lt;/packageName>
&lt;!-- The destination directory of your generated classes -->
&lt;directory>C:/workspace/MySQLTest/src&lt;/directory>
&lt;/target>
&lt;/generator>
&lt;/configuration>
</pre>
<p>
Replace the username with whatever user has the appropriate privileges.
You'll want to look at the other values and replace as necessary.
Here are the two interesting properties:
</p>
<p>
<code>generator.target.package</code> - set this to the parent package you want
to create for the generated classes. The setting of <code>test.generated</code>
will cause the <code>test.generated.Posts</code> and
<code>test.generated.PostsRecord</code> to be created
</p>
<p>
<code>generator.target.directory</code> - the directory to output to.
</p>
<p>
Once you have the JAR files and guestbook.xml in your temp directory, type this
(use colons instead of semi-colons on UNIX/Linux systems):
</p>
<pre>
java -classpath jooq-<?=$version?>.jar;jooq-meta-<?=$version?>.jar;jooq-codegen-<?=$version?>.jar;mysql-connector-java-5.1.18-bin.jar;. org.jooq.util.GenerationTool /guestbook.xml
</pre>
<p>
Note the prefix slash before guestbook.properies.
Even though it's in our working directory, we need to prepend a slash, as it is
loaded from the classpath.
Replace the filenames with your filenames.
In this example, jOOQ <?=$version?> is being used.
If everything has worked, you should see this in your console output:
</p>
<pre>
Nov 1, 2011 7:25:06 PM org.jooq.impl.JooqLogger info
INFO: Initialising properties : /guestbook.xml
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Database parameters
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: ----------------------------------------------------------
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: dialect : MYSQL
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: schema : guestbook
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: target dir : /Users/jOOQ/Documents/workspace/MySQLTest/src
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: target package : test.generated
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: ----------------------------------------------------------
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Emptying : /Users/jOOQ/workspace/MySQLTest/src/test/generated
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Generating classes in : /Users/jOOQ/workspace/MySQLTest/src/test/generated
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Generating schema : Guestbook.java
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Schema generated : Total: 122.18ms
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Sequences fetched : 0 (0 included, 0 excluded)
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Masterdata tables fetched: 0 (0 included, 0 excluded)
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Tables fetched : 5 (5 included, 0 excluded)
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Generating tables : /Users/jOOQ/workspace/MySQLTest/src/test/generated/tables
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: ARRAYs fetched : 0 (0 included, 0 excluded)
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Enums fetched : 0 (0 included, 0 excluded)
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: UDTs fetched : 0 (0 included, 0 excluded)
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Generating table : Posts.java
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Tables generated : Total: 680.464ms, +558.284ms
Nov 1, 2011 7:25:07 PM org.jooq.impl.JooqLogger info
INFO: Generating Keys : /Users/jOOQ/workspace/MySQLTest/src/test/generated/tables
Nov 1, 2011 7:25:08 PM org.jooq.impl.JooqLogger info
INFO: Keys generated : Total: 718.621ms, +38.157ms
Nov 1, 2011 7:25:08 PM org.jooq.impl.JooqLogger info
INFO: Generating records : /Users/jOOQ/workspace/MySQLTest/src/test/generated/tables/records
Nov 1, 2011 7:25:08 PM org.jooq.impl.JooqLogger info
INFO: Generating record : PostsRecord.java
Nov 1, 2011 7:25:08 PM org.jooq.impl.JooqLogger info
INFO: Table records generated : Total: 782.545ms, +63.924ms
Nov 1, 2011 7:25:08 PM org.jooq.impl.JooqLogger info
INFO: Routines fetched : 0 (0 included, 0 excluded)
Nov 1, 2011 7:25:08 PM org.jooq.impl.JooqLogger info
INFO: Packages fetched : 0 (0 included, 0 excluded)
Nov 1, 2011 7:25:08 PM org.jooq.impl.JooqLogger info
INFO: GENERATION FINISHED! : Total: 791.688ms, +9.143ms
</pre>
<h2 id="step3"><a href="#step3" name="step3">#</a> Step 3: Write a main class and establish a MySQL connection</h2>
<p>
Let's just write a vanilla main class in the project containing the generated classes:
</p>
<pre class="prettyprint lang-java">
// For convenience, always static import your generated tables and
// jOOQ functions to decrease verbosity:
import static test.generated.Tables.*;
import static org.jooq.impl.Factory.*;
public class Main {
public static void main(String[] args) {
Connection conn = null;
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost:3306/guestbook";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
} catch (Exception e) {
// For the sake of this tutorial, let's keep exception handling simple
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ignore) {
}
}
}
}
}
</pre>
<p>
This is pretty standard code for establishing a MySQL connection.
</p>
<h2 id="step4"><a href="#step4" name="step4">#</a> Step 4: Write a query using jOOQ's DSL</h2>
<p>
Let's add a simple query:
</p>
<pre class="prettyprint lang-java">
Executor create = new Executor(conn, SQLDialect.MYSQL);
Result&lt;Record> result = create.select().from(POSTS).fetch();
</pre>
<p>
First get an instance of <code>Factory</code> so we can write a simple
<code>SELECT</code> query. We pass an instance of the MySQL connection to
<code>Factory</code>. Note that the factory doesn't close the connection.
We'll have to do that ourselves.
</p>
<p>
We then use jOOQ's DSL to return an instance of Result. We'll be using this result in
the next step.
</p>
<h2 id="step5"><a href="#step5" name="step5">#</a> Step 5: Iterate over results</h2>
<p>
After the line where we retrieve the results, let's iterate over the results and
print out the data:
</p>
<pre class="prettyprint lang-java">
for (Record r : result) {
Long id = r.getValue(POSTS.ID);
String title = r.getValue(POSTS.TITLE);
String description = r.getValue(POSTS.BODY);
System.out.println("ID: " + id + " title: " + title + " desciption: " + description);
}
</pre>
<p>
The full program should now look like this:
</p>
<pre class="prettyprint lang-java">
package test;
// For convenience, always static import your generated tables and
// jOOQ functions to decrease verbosity:
import static test.generated.Tables.*;
import static org.jooq.impl.Factory.*;
import java.sql.*;
import org.jooq.*;
import org.jooq.impl.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
Connection conn = null;
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost:3306/guestbook";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
Executor create = new Executor(conn, SQLDialect.MYSQL);
Result&lt;Record> result = create.select().from(POSTS).fetch();
for (Record r : result) {
Long id = r.getValue(POSTS.ID);
String title = r.getValue(POSTS.TITLE);
String description = r.getValue(POSTS.BODY);
System.out.println("ID: " + id + " title: " + title + " desciption: " + description);
}
} catch (Exception e) {
// For the sake of this tutorial, let's keep exception handling simple
e.printStackTrace();
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ignore) {
}
}
}
}
}
</pre>
<h2 id="step6"><a href="#step6" name="step6">#</a> Step 6: Explore!</h2>
<p>
jOOQ has grown to be a comprehensive SQL library. For more information, please consider the manual:<br/>
<a href="http://www.jooq.org/doc/<?=$minorVersion?>/manual" title="jOOQ Manual">http://www.jooq.org/doc/<?=$minorVersion?>/manual</a>
</p>
<p>
... explore the Javadoc:<br/>
<a href="http://www.jooq.org/javadoc/latest/" title="jOOQ Javadoc">http://www.jooq.org/javadoc/latest/</a>
</p>
<p>
... or join the news group:<br/>
<a href="https://groups.google.com/forum/#!forum/jooq-user" title="jOOQ news group">https://groups.google.com/forum/#!forum/jooq-user</a>
</p>
<p>
This tutorial is the courtesy of Ikai Lan. See the original source here:<br/>
<a href="http://ikaisays.com/2011/11/01/getting-started-with-jooq-a-tutorial/" target="_blank" title="Ikai Lan's jOOQ tutorial">http://ikaisays.com/2011/11/01/getting-started-with-jooq-a-tutorial/</a>
</p>
<?php
}
require 'conf.php';
header('Location: ' . $root . '/doc/' . $minorVersion . '/manual/getting-started/tutorials/jooq-in-7-steps');
?>