Skip to content

Instantly share code, notes, and snippets.

@Zhuoli
Created August 23, 2016 02:11
Show Gist options
  • Save Zhuoli/a34fd2d782f863392186f7711bd89282 to your computer and use it in GitHub Desktop.
Save Zhuoli/a34fd2d782f863392186f7711bd89282 to your computer and use it in GitHub Desktop.
JOOQDemo
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
<profile default="false" name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="true" />
<module name="JOOQDemo" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="JOOQDemo" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>
<component name="libraryTable">
<library name="Maven: mysql:mysql-connector-java:5.1.6">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6-sources.jar!/" />
</SOURCES>
</library>
</component>
<component name="libraryTable">
<library name="Maven: org.jooq:jooq:3.8.4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jooq/jooq/3.8.4/jooq-3.8.4.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/jooq/jooq/3.8.4/jooq-3.8.4-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jooq/jooq/3.8.4/jooq-3.8.4-sources.jar!/" />
</SOURCES>
</library>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/JOOQDemo.iml" filepath="$PROJECT_DIR$/JOOQDemo.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.jooq:jooq:3.8.4" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.6" level="project" />
</component>
</module>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JOOQDemo</groupId>
<artifactId>JOOQDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.jooq/jooq -->
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.8.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
</project>
/**
* This class is generated by jOOQ
*/
package JooqMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Generated;
import org.jooq.Schema;
import org.jooq.impl.CatalogImpl;
/**
* This class is generated by jOOQ.
*/
@Generated(
value = {
"http://www.jooq.org",
"jOOQ version:3.8.4"
},
comments = "This class is generated by jOOQ"
)
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class DefaultCatalog extends CatalogImpl {
private static final long serialVersionUID = 1154484998;
/**
* The reference instance of <code></code>
*/
public static final DefaultCatalog DEFAULT_CATALOG = new DefaultCatalog();
/**
* The schema <code>library</code>.
*/
public final Library LIBRARY = JooqMap.Library.LIBRARY;
/**
* No further instances allowed
*/
private DefaultCatalog() {
super("");
}
@Override
public final List<Schema> getSchemas() {
List result = new ArrayList();
result.addAll(getSchemas0());
return result;
}
private final List<Schema> getSchemas0() {
return Arrays.<Schema>asList(
Library.LIBRARY);
}
}
/**
* This class is generated by jOOQ
*/
package JooqMap;
import JooqMap.tables.Author;
import JooqMap.tables.records.AuthorRecord;
import javax.annotation.Generated;
import org.jooq.UniqueKey;
import org.jooq.impl.AbstractKeys;
/**
* A class modelling foreign key relationships between tables of the <code>library</code>
* schema
*/
@Generated(
value = {
"http://www.jooq.org",
"jOOQ version:3.8.4"
},
comments = "This class is generated by jOOQ"
)
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Keys {
// -------------------------------------------------------------------------
// IDENTITY definitions
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// UNIQUE and PRIMARY KEY definitions
// -------------------------------------------------------------------------
public static final UniqueKey<AuthorRecord> KEY_AUTHOR_PRIMARY = UniqueKeys0.KEY_AUTHOR_PRIMARY;
// -------------------------------------------------------------------------
// FOREIGN KEY definitions
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// [#1459] distribute members to avoid static initialisers > 64kb
// -------------------------------------------------------------------------
private static class UniqueKeys0 extends AbstractKeys {
public static final UniqueKey<AuthorRecord> KEY_AUTHOR_PRIMARY = createUniqueKey(Author.AUTHOR, "KEY_author_PRIMARY", Author.AUTHOR.ID);
}
}
/**
* This class is generated by jOOQ
*/
package JooqMap;
import JooqMap.tables.Author;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Generated;
import org.jooq.Catalog;
import org.jooq.Table;
import org.jooq.impl.SchemaImpl;
/**
* This class is generated by jOOQ.
*/
@Generated(
value = {
"http://www.jooq.org",
"jOOQ version:3.8.4"
},
comments = "This class is generated by jOOQ"
)
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Library extends SchemaImpl {
private static final long serialVersionUID = -1671363872;
/**
* The reference instance of <code>library</code>
*/
public static final Library LIBRARY = new Library();
/**
* The table <code>library.author</code>.
*/
public final Author AUTHOR = JooqMap.tables.Author.AUTHOR;
/**
* No further instances allowed
*/
private Library() {
super("library", null);
}
/**
* {@inheritDoc}
*/
@Override
public Catalog getCatalog() {
return DefaultCatalog.DEFAULT_CATALOG;
}
@Override
public final List<Table<?>> getTables() {
List result = new ArrayList();
result.addAll(getTables0());
return result;
}
private final List<Table<?>> getTables0() {
return Arrays.<Table<?>>asList(
Author.AUTHOR);
}
}
/**
* This class is generated by jOOQ
*/
package JooqMap;
import JooqMap.tables.Author;
import javax.annotation.Generated;
/**
* Convenience access to all tables in library
*/
@Generated(
value = {
"http://www.jooq.org",
"jOOQ version:3.8.4"
},
comments = "This class is generated by jOOQ"
)
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Tables {
/**
* The table <code>library.author</code>.
*/
public static final Author AUTHOR = JooqMap.tables.Author.AUTHOR;
}
/**
* This class is generated by jOOQ
*/
package JooqMap.tables;
import JooqMap.Keys;
import JooqMap.Library;
import JooqMap.tables.records.AuthorRecord;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Generated;
import org.jooq.Field;
import org.jooq.Schema;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.UniqueKey;
import org.jooq.impl.TableImpl;
/**
* This class is generated by jOOQ.
*/
@Generated(
value = {
"http://www.jooq.org",
"jOOQ version:3.8.4"
},
comments = "This class is generated by jOOQ"
)
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Author extends TableImpl<AuthorRecord> {
private static final long serialVersionUID = 1001430949;
/**
* The reference instance of <code>library.author</code>
*/
public static final Author AUTHOR = new Author();
/**
* The class holding records for this type
*/
@Override
public Class<AuthorRecord> getRecordType() {
return AuthorRecord.class;
}
/**
* The column <code>library.author.id</code>.
*/
public final TableField<AuthorRecord, Integer> ID = createField("id", org.jooq.impl.SQLDataType.INTEGER.nullable(false), this, "");
/**
* The column <code>library.author.first_name</code>.
*/
public final TableField<AuthorRecord, String> FIRST_NAME = createField("first_name", org.jooq.impl.SQLDataType.VARCHAR.length(255), this, "");
/**
* The column <code>library.author.last_name</code>.
*/
public final TableField<AuthorRecord, String> LAST_NAME = createField("last_name", org.jooq.impl.SQLDataType.VARCHAR.length(255), this, "");
/**
* Create a <code>library.author</code> table reference
*/
public Author() {
this("author", null);
}
/**
* Create an aliased <code>library.author</code> table reference
*/
public Author(String alias) {
this(alias, AUTHOR);
}
private Author(String alias, Table<AuthorRecord> aliased) {
this(alias, aliased, null);
}
private Author(String alias, Table<AuthorRecord> aliased, Field<?>[] parameters) {
super(alias, null, aliased, parameters, "");
}
/**
* {@inheritDoc}
*/
@Override
public Schema getSchema() {
return Library.LIBRARY;
}
/**
* {@inheritDoc}
*/
@Override
public UniqueKey<AuthorRecord> getPrimaryKey() {
return Keys.KEY_AUTHOR_PRIMARY;
}
/**
* {@inheritDoc}
*/
@Override
public List<UniqueKey<AuthorRecord>> getKeys() {
return Arrays.<UniqueKey<AuthorRecord>>asList(Keys.KEY_AUTHOR_PRIMARY);
}
/**
* {@inheritDoc}
*/
@Override
public Author as(String alias) {
return new Author(alias, this);
}
/**
* Rename this table
*/
public Author rename(String name) {
return new Author(name, null);
}
}
/**
* This class is generated by jOOQ
*/
package JooqMap.tables.records;
import JooqMap.tables.Author;
import javax.annotation.Generated;
import org.jooq.Field;
import org.jooq.Record1;
import org.jooq.Record3;
import org.jooq.Row3;
import org.jooq.impl.UpdatableRecordImpl;
/**
* This class is generated by jOOQ.
*/
@Generated(
value = {
"http://www.jooq.org",
"jOOQ version:3.8.4"
},
comments = "This class is generated by jOOQ"
)
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class AuthorRecord extends UpdatableRecordImpl<AuthorRecord> implements Record3<Integer, String, String> {
private static final long serialVersionUID = 1300972679;
/**
* Setter for <code>library.author.id</code>.
*/
public void setId(Integer value) {
set(0, value);
}
/**
* Getter for <code>library.author.id</code>.
*/
public Integer getId() {
return (Integer) get(0);
}
/**
* Setter for <code>library.author.first_name</code>.
*/
public void setFirstName(String value) {
set(1, value);
}
/**
* Getter for <code>library.author.first_name</code>.
*/
public String getFirstName() {
return (String) get(1);
}
/**
* Setter for <code>library.author.last_name</code>.
*/
public void setLastName(String value) {
set(2, value);
}
/**
* Getter for <code>library.author.last_name</code>.
*/
public String getLastName() {
return (String) get(2);
}
// -------------------------------------------------------------------------
// Primary key information
// -------------------------------------------------------------------------
/**
* {@inheritDoc}
*/
@Override
public Record1<Integer> key() {
return (Record1) super.key();
}
// -------------------------------------------------------------------------
// Record3 type implementation
// -------------------------------------------------------------------------
/**
* {@inheritDoc}
*/
@Override
public Row3<Integer, String, String> fieldsRow() {
return (Row3) super.fieldsRow();
}
/**
* {@inheritDoc}
*/
@Override
public Row3<Integer, String, String> valuesRow() {
return (Row3) super.valuesRow();
}
/**
* {@inheritDoc}
*/
public Field<Integer> field1() {
return Author.AUTHOR.ID;
}
/**
* {@inheritDoc}
*/
public Field<String> field2() {
return Author.AUTHOR.FIRST_NAME;
}
/**
* {@inheritDoc}
*/
public Field<String> field3() {
return Author.AUTHOR.LAST_NAME;
}
/**
* {@inheritDoc}
*/
public Integer value1() {
return getId();
}
/**
* {@inheritDoc}
*/
public String value2() {
return getFirstName();
}
/**
* {@inheritDoc}
*/
public String value3() {
return getLastName();
}
/**
* {@inheritDoc}
*/
public AuthorRecord value1(Integer value) {
setId(value);
return this;
}
/**
* {@inheritDoc}
*/
public AuthorRecord value2(String value) {
setFirstName(value);
return this;
}
/**
* {@inheritDoc}
*/
public AuthorRecord value3(String value) {
setLastName(value);
return this;
}
/**
* {@inheritDoc}
*/
public AuthorRecord values(Integer value1, String value2, String value3) {
value1(value1);
value2(value2);
value3(value3);
return this;
}
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
/**
* Create a detached AuthorRecord
*/
public AuthorRecord() {
super(Author.AUTHOR);
}
/**
* Create a detached, initialised AuthorRecord
*/
public AuthorRecord(Integer id, String firstName, String lastName) {
super(Author.AUTHOR);
set(0, id);
set(1, firstName);
set(2, lastName);
}
}
// For convenience, always static import your generated tables and
// jOOQ functions to decrease verbosity:
import static JooqMap.Tables.AUTHOR;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jooq.*;
import org.jooq.impl.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
String userName = "root";
String password = "cp8482617";
String url = "jdbc:mysql://localhost:3306/library";
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
Logger.getGlobal().log(Level.SEVERE, "", e);
return;
}
// Connection is the only JDBC resource that we need
// PreparedStatement and ResultSet are handled by jOOQ, internally
try (Connection conn = DriverManager.getConnection(url, userName, password)) {
DSLContext create = DSL.using(conn, SQLDialect.MYSQL);
Result<Record> result = create.select().from(AUTHOR).fetch();
for (Record r : result) {
Integer id = r.getValue(AUTHOR.ID);
String firstName = r.getValue(AUTHOR.FIRST_NAME);
String lastName = r.getValue(AUTHOR.LAST_NAME);
System.out.println("ID: " + id + " first name: " + firstName + " last name: " + lastName);
}
}
// For the sake of this tutorial, let's keep exception handling simple
catch (Exception e) {
e.printStackTrace();
}
}
}
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment