Created
August 23, 2016 02:11
-
-
Save Zhuoli/a34fd2d782f863392186f7711bd89282 to your computer and use it in GitHub Desktop.
JOOQDemo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="CopyrightManager"> | |
<settings default="" /> | |
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} | |
} | |
} |
This file has been truncated, but you can view the full file.
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