diff --git a/jOOQ-release/release/template/RELEASENOTES.txt b/jOOQ-release/release/template/RELEASENOTES.txt index d57ff34cfc..c8d594b63a 100644 --- a/jOOQ-release/release/template/RELEASENOTES.txt +++ b/jOOQ-release/release/template/RELEASENOTES.txt @@ -26,6 +26,9 @@ generation. These improvements include: and to annotate both POJOs and Records with JPA annotations such as @Entity, @Table, @Id, @Column, @UniqueConstraint, etc. +You can migrate your existing .properties configuration by running +> org.jooq.util.GenerationTool /your.properties migrate + Besides that, there is a lot of ongoing work to improve the integration of Oracle's TABLE and VARRAY types. diff --git a/jOOQ-website/inc/RELEASENOTES.txt b/jOOQ-website/inc/RELEASENOTES.txt index d57ff34cfc..c8d594b63a 100644 --- a/jOOQ-website/inc/RELEASENOTES.txt +++ b/jOOQ-website/inc/RELEASENOTES.txt @@ -26,6 +26,9 @@ generation. These improvements include: and to annotate both POJOs and Records with JPA annotations such as @Entity, @Table, @Id, @Column, @UniqueConstraint, etc. +You can migrate your existing .properties configuration by running +> org.jooq.util.GenerationTool /your.properties migrate + Besides that, there is a lot of ongoing work to improve the integration of Oracle's TABLE and VARRAY types. diff --git a/jOOQ-website/manual-pdf/jOOQ-manual.fo.xml b/jOOQ-website/manual-pdf/jOOQ-manual.fo.xml index 5c30c59812..7aa43b4d10 100644 --- a/jOOQ-website/manual-pdf/jOOQ-manual.fo.xml +++ b/jOOQ-website/manual-pdf/jOOQ-manual.fo.xml @@ -1859,7 +1859,7 @@ i.execute(); In some occasions, you may prefer the INSERT SELECT syntax, for instance, when you copy records from one table to another: Insert i = create.insertInto(T_AUTHOR_ARCHIVE) - .select(create.selectFrom(T_AUTHOR).where(T_AUTHOR.DECEASED.equal(1))); + .select(create.selectFrom(T_AUTHOR).where(T_AUTHOR.DECEASED.isTrue())); i.execute(); @@ -2078,6 +2078,8 @@ Object[] fetchArray(String fieldName); true and true +// configurations to generate such POJOs with jOOQ List fetchInto(Class type); // Fetch the resulting records into a custom @@ -2558,86 +2560,183 @@ public void bind(BindContext context) throws DataAccessException; - Configure jOOQ + Configure jOOQ's code generator You need to tell jOOQ some things about your database connection. - Here's an example of how to do it for a MySQL database -#Configure the database connection here -jdbc.Driver=com.mysql.jdbc.Driver -jdbc.URL=jdbc:mysql://[your jdbc URL] -jdbc.User=[your database user] -jdbc.Password=[your database password] + Here's an example of how to do it for an Oracle database + + + + + oracle.jdbc.OracleDriver + jdbc:oracle:thin:@[your jdbc connection parameters] + [your database user] + [your database password] + -#The default code generator. You can override this one, to generate your own code style -#Defaults to org.jooq.util.DefaultGenerator -generator=org.jooq.util.DefaultGenerator + + + org.jooq.util.DefaultGenerator -#The database type. The format here is: -#generator.database=org.util.[database].[database]Database -generator.database=org.jooq.util.mysql.MySQLDatabase + + + org.jooq.util.DefaultGeneratorStrategy + -#The schema that is used locally as a source for meta information. This could be your -#development schema or the production schema, etc: -generator.database.input-schema=[your database schema / owner / name] + + + org.jooq.util.oracle.OracleDatabase -#Primary key / foreign key relations should be generated and used. -#This will be a prerequisite for various advanced features -#Defaults to false -generator.generate.relations=true + + .* -#Generate deprecated code for backwards compatibility -#Defaults to true -generator.generate.deprecated=false + + -#The destination package of your generated classes (within the destination directory) -generator.target.package=[org.jooq.your.package] + + [your database schema / owner / name] + -#The destination directory of your generated classes -generator.target.directory=[/path/to/your/dir] + + + - And you can add some optional advanced configuration parameters: -#The schema that is used in generated source code. This will be the production schema -#Use this to override your local development schema name for source code generation -#If not specified, this will be the same as the input-schema. -generator.database.output-schema=[your database schema / owner / name] + + + [org.jooq.your.packagename] -#Generate java.sql.Timestamp fields for DATE columns. This is particularly useful for Oracle databases -#Defaults to false -generator.database.date-as-timestamp=true + + [/path/to/your/dir] + + +]]> -#Generate instance fields in your tables, as opposed to static fields. This simplifies aliasing -#Defaults to true -generator.generate.instance-fields=true + And you can add some optional advanced configuration parameters for the database: -#Generate the javax.annotation.Generated annotation to indicate jOOQ version used for source code -#generation. Defaults to true -generator.generate.generated-annotation=true + + + + false -#Generate jOOU data types for your unsigned data types, which are not natively supported in Java -#Defaults to true -generator.generate.unsigned-types=true + + true -#Generate a master data table enum classes (several Java regular expressions, separated by comma) -generator.generate.master-data-tables=[a list of tables] + + [your database schema / owner / name] + + + + + ... + ... + + [ ... ... ] + + + + ... + + + ... + + + ... +]]> + + Also, you can add some optional advanced configuration parameters for the generator: + + + + + false + + + true + + + true + + + true + + + true + + + false + + + false +]]> -#For every master data table, specify two special columns -generator.generate.master-data-table-literal.[master data table]=[column used for enum literals] -generator.generate.master-data-table-description.[master data table]=[column used for documentation] Check out the manual's section about master data to find out more about those advanced configuration parameters. + Also, check out the official XSD file at + http://www.jooq.org/xsd/jooq-codegen-2.0.4.xsd + for a formal specification + Run jOOQ code generation Code generation works by calling this class with the above property file as argument. - org.jooq.util.GenerationTool /jooq-config.properties + org.jooq.util.GenerationTool /jooq-config.xml Be sure that these elements are located on the classpath: @@ -2830,13 +2929,6 @@ generator.generate.master-data-table-description.[master data table]=[column use org.jooq.util.maven.example target/generated-sources/jooq - - - t_language - cd - description - - @@ -2845,6 +2937,19 @@ generator.generate.master-data-table-description.[master data table]=[column use https://github.com/lukaseder/jOOQ/blob/master/jOOQ-codegen-maven-example/pom.xml + Migrate properties files from jOOQ 1.7, early versions of jOOQ 2.0.x: + + Before jOOQ 2.0.4, the code generator was configured using properties files + These files are still supported for source code generation, but their syntax + won't be maintained any longer. If you wish to migrate to XML, you can + migrate the file using this command on the command line + + org.jooq.util.GenerationTool /jooq-config.properties migrate + + Using the migrate flag, jOOQ will read the properties file and output + a corresponding XML file on system out + + Use jOOQ generated classes in your application Be sure, both jOOQ.jar and your generated package (see configuration) are located on your classpath. Once this is done, you @@ -5325,12 +5430,23 @@ create.select(LAST_NAME, COUNT1, COUNT2) As previously discussed in the configuration and setup section, you can configure master data tables as follows: -#Generate a master data table enum classes (several Java regular expressions, separated by comma) -generator.generate.master-data-tables=[a list of tables] + + + + + + [a table name] -#For every master data table, specify two special columns -generator.generate.master-data-table-literal.[master data table]=[column used for enum literals] -generator.generate.master-data-table-description.[master data table]=[column used for documentation] + + [a column name] + + + [a column name] + + + [ ... ... ] + + ]]> The results of this will be a Java enum that looks similar to this: { diff --git a/jOOQ-website/manual-pdf/jOOQ-manual.pdf b/jOOQ-website/manual-pdf/jOOQ-manual.pdf index 1d07852485..976fec868a 100644 Binary files a/jOOQ-website/manual-pdf/jOOQ-manual.pdf and b/jOOQ-website/manual-pdf/jOOQ-manual.pdf differ diff --git a/jOOQ-website/manual-single-page/index.php b/jOOQ-website/manual-single-page/index.php index 01dd8760dd..aa7cd235db 100644 --- a/jOOQ-website/manual-single-page/index.php +++ b/jOOQ-website/manual-single-page/index.php @@ -1030,7 +1030,7 @@ i.execute();

In some occasions, you may prefer the INSERT SELECT syntax, for instance, when you copy records from one table to another:

Insert i = create.insertInto(T_AUTHOR_ARCHIVE)
-                 .select(create.selectFrom(T_AUTHOR).where(T_AUTHOR.DECEASED.equal(1)));
+                 .select(create.selectFrom(T_AUTHOR).where(T_AUTHOR.DECEASED.isTrue()));
 i.execute();
@@ -1210,6 +1210,8 @@ Object[] fetchArray(String fieldName);
// Fetch the resulting records into a custom POJO
 // type, which may or may not be JPA-annotated
+// Use the generator's <pojos>true</pojos> and <jpaAnnotation>true</jpaAnnotation>
+// configurations to generate such POJOs with jOOQ
 <E> List<E> fetchInto(Class<? extends E> type);
 
 // Fetch the resulting records into a custom
@@ -1605,86 +1607,183 @@ public void bind(BindContext context) throws DataAccessException;

-

Configure jOOQ

+

Configure jOOQ's code generator

You need to tell jOOQ some things about your database connection. - Here's an example of how to do it for a MySQL database

-
#Configure the database connection here
-jdbc.Driver=com.mysql.jdbc.Driver
-jdbc.URL=jdbc:mysql://[your jdbc URL]
-jdbc.User=[your database user]
-jdbc.Password=[your database password]
+								Here's an example of how to do it for an Oracle database 

+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<configuration>
+  <!-- Configure the database connection here -->
+  <jdbc>
+    <driver>oracle.jdbc.OracleDriver</driver>
+    <url>jdbc:oracle:thin:@[your jdbc connection parameters]</url>
+    <user>[your database user]</user>
+    <password>[your database password]</password>
+  </jdbc>
 
-#The default code generator. You can override this one, to generate your own code style
-#Defaults to org.jooq.util.DefaultGenerator
-generator=org.jooq.util.DefaultGenerator
+  <generator>
+    <!-- The default code generator. You can override this one, to generate your own code style
+         Defaults to org.jooq.util.DefaultGenerator -->
+    <name>org.jooq.util.DefaultGenerator</name>
 
-#The database type. The format here is:
-#generator.database=org.util.[database].[database]Database
-generator.database=org.jooq.util.mysql.MySQLDatabase
+    <!-- The naming strategy used for class and field names.
+         You may override this with your custom naming strategy.
+         Defaults to org.jooq.util.DefaultGeneratorStrategy -->
+    <strategy>
+      <name>org.jooq.util.DefaultGeneratorStrategy</name>
+    </strategy>
 
-#The schema that is used locally as a source for meta information. This could be your
-#development schema or the production schema, etc:
-generator.database.input-schema=[your database schema / owner / name]
+    <database>
+      <!-- The database dialect from jooq-meta. Available dialects are
+           named org.util.[database].[database]Database. Known values are:
 
-#All elements that are generated from your schema (several Java regular expressions, separated by comma)
-#Watch out for case-sensitivity. Depending on your database, this might be important!
-#You can create case-insensitive regular expressions using this syntax: (?i:expr)
-generator.database.includes=.*
+           org.jooq.util.ase.ASEDatabase
+           org.jooq.util.db2.DB2Database
+           org.jooq.util.derby.DerbyDatabase
+           org.jooq.util.h2.H2Database
+           org.jooq.util.hsqldb.HSQLDBDatabase
+           org.jooq.util.ingres.IngresDatabase
+           org.jooq.util.mysql.MySQLDatabase
+           org.jooq.util.oracle.OracleDatabase
+           org.jooq.util.postgres.PostgresDatabase
+           org.jooq.util.sqlite.SQLiteDatabaes
+           org.jooq.util.sqlserver.SQLServerDatabase
+           org.jooq.util.sybase.SybaseDatabase
 
-#All elements that are excluded from your schema (several Java regular expressions, separated by comma). Excludes match before includes
-generator.database.excludes=
+           You can also provide your own org.jooq.util.Database implementation
+           here, if your database is currently not supported -->
+      <name>org.jooq.util.oracle.OracleDatabase</name>
 
-#Primary key / foreign key relations should be generated and used.
-#This will be a prerequisite for various advanced features
-#Defaults to false
-generator.generate.relations=true
+      <!-- All elements that are generated from your schema (several Java
+           regular expressions, separated by comma) Watch out for
+           case-sensitivity. Depending on your database, this might be
+           important! You can create case-insensitive regular expressions
+           using this syntax: (?i:expr)A comma-separated list of regular
+           expressions -->
+      <includes>.*</includes>
 
-#Generate deprecated code for backwards compatibility
-#Defaults to true
-generator.generate.deprecated=false
+      <!-- All elements that are excluded from your schema (several Java
+           regular expressions, separated by comma). Excludes match before
+           includes -->
+      <excludes></excludes>
 
-#The destination package of your generated classes (within the destination directory)
-generator.target.package=[org.jooq.your.package]
+      <!-- The schema that is used locally as a source for meta information.
+           This could be your development schema or the production schema, etc
+           This cannot be combined with the schemata element. -->
+      <inputSchema>[your database schema / owner / name]</inputSchema>
+    </database>
 
-#The destination directory of your generated classes
-generator.target.directory=[/path/to/your/dir]
+ <generate> + <!-- See advanced configuration properties --> + </generate> -

And you can add some optional advanced configuration parameters:

-
#The schema that is used in generated source code. This will be the production schema
-#Use this to override your local development schema name for source code generation
-#If not specified, this will be the same as the input-schema.
-generator.database.output-schema=[your database schema / owner / name]
+    <target>
+      <!-- The destination package of your generated classes (within the
+           destination directory) -->
+      <packageName>[org.jooq.your.packagename]</packageName>
 
-#Generate java.sql.Timestamp fields for DATE columns. This is particularly useful for Oracle databases
-#Defaults to false
-generator.database.date-as-timestamp=true
+      <!-- The destination directory of your generated classes -->
+      <directory>[/path/to/your/dir]</directory>
+    </target>
+  </generator>
+</configuration>
-#Generate instance fields in your tables, as opposed to static fields. This simplifies aliasing -#Defaults to true -generator.generate.instance-fields=true +

And you can add some optional advanced configuration parameters for the database:

-#Generate the javax.annotation.Generated annotation to indicate jOOQ version used for source code -#generation. Defaults to true -generator.generate.generated-annotation=true +
<!-- These properties can be added to the database element: -->
+<database>
+  <!-- Generate java.sql.Timestamp fields for DATE columns. This is
+       particularly useful for Oracle databases.
+       Defaults to false -->
+  <dateAsTimestamp>false</dateAsTimestamp>
 
-#Generate jOOU data types for your unsigned data types, which are not natively supported in Java
-#Defaults to true
-generator.generate.unsigned-types=true
+  <!-- Generate jOOU data types for your unsigned data types, which are
+       not natively supported in Java.
+       Defaults to true -->
+  <unsignedTypes>true</unsignedTypes>
 
-#Generate a master data table enum classes (several Java regular expressions, separated by comma)
-generator.generate.master-data-tables=[a list of tables]
+  <!-- The schema that is used in generated source code. This will be the
+       production schema. Use this to override your local development
+       schema name for source code generation. If not specified, this
+       will be the same as the input-schema. -->
+  <outputSchema>[your database schema / owner / name]</outputSchema>
+
+  <!-- A configuration element to configure several input and/or output
+       schemata for jooq-meta, in case you're using jooq-meta in a multi-
+       schema environment.
+       This cannot be combined with the above inputSchema / outputSchema -->
+  <schemata>
+    <schema>
+      <inputSchema>...</inputSchema>
+      <outputSchema>...</outputSchema>
+    </schema>
+    [ <schema>...</schema> ... ]
+  </schemata>
+
+  <!-- A configuration element to configure master data table enum classes -->
+  <masterDataTables>...</masterDataTables>
+
+  <!-- A configuration element to configure synthetic enum types
+       This is EXPERIMENTAL functionality. Use at your own risk -->
+  <enumTypes>...</enumTypes>
+
+  <!-- A configuration element to configure type overrides for generated
+       artefacts (e.g. in combination with enumTypes)
+       This is EXPERIMENTAL functionality. Use at your own risk -->
+  <forcedTypes>...</forcedTypes>
+</database>
+ +

Also, you can add some optional advanced configuration parameters for the generator:

+ +
<!-- These properties can be added to the generate element: -->
+<generate>
+  <!-- Primary key / foreign key relations should be generated and used.
+       This is a prerequisite for various advanced features.
+       Defaults to false -->
+  <relations>false</relations>
+
+  <!-- Generate navigation methods to navigate foreign key relationships
+       directly from Record classes. This is only relevant if relations
+       is set to true, too.
+       Defaults to true -->
+  <navigationMethods>true</navigationMethods>
+
+  <!-- Generate deprecated code for backwards compatibility
+       Defaults to true -->
+  <deprecated>true</deprecated>
+
+  <!-- Generate instance fields in your tables, as opposed to static
+       fields. This simplifies aliasing.
+       Defaults to true -->
+  <instanceFields>true</instanceFields>
+
+  <!-- Generate the javax.annotation.Generated annotation to indicate
+       jOOQ version used for source code.
+       Defaults to true -->
+  <generatedAnnotation>true</generatedAnnotation>
+
+  <!-- Generate POJOs in addition to Record classes for usage of the
+       ResultQuery.fetchInto(Class) API
+       Defaults to false -->
+  <pojos>false</pojos>
+
+  <!-- Annotate POJOs and Records with JPA annotations for increased
+       compatibility and better integration with JPA/Hibernate, etc
+       Defaults to false -->
+  <jpaAnnotations>false</jpaAnnotations>
+</generate>
-#For every master data table, specify two special columns -generator.generate.master-data-table-literal.[master data table]=[column used for enum literals] -generator.generate.master-data-table-description.[master data table]=[column used for documentation]

Check out the manual's section about master data to find out more about those advanced configuration parameters.

+

Also, check out the official XSD file at + http://www.jooq.org/xsd/jooq-codegen-2.0.4.xsd + for a formal specification

+

Run jOOQ code generation

Code generation works by calling this class with the above property file as argument.

-
org.jooq.util.GenerationTool /jooq-config.properties
+
org.jooq.util.GenerationTool /jooq-config.xml

Be sure that these elements are located on the classpath: