Skip to content

Commit

Permalink
on 3.8.5 - October 21, 2016
Browse files Browse the repository at this point in the history
================================================================================

This is a patch release with some useful fixes for the 3.8 branch

Features and Improvements
-------------------------

#5454 - Add a big disclaimer to the Mock API not to mock an entire database
#5534 - Mention the possibility of running SELECT * by keeping an empty select() field list
#5565 - Log warnings when users misconfigure forceType / customType elements
#5566 - Improve DSLContext.batchStore() Javadoc
#5606 - Code generator should delete catalog and schema directories when no longer configured

Bug Fixes
---------

#5427 - Don't escape Scala-style setter names produced by naming strategies in ScalaGenerator
#5447 - Unnecessarily costly query to check for Oracle version in code generation
#5458 - "overriding method fields in class AbstractRecord" compilation error when using ScalaGenerator on tables containing columns like "fields", "configuration", etc.
#5465 - Wrong @Support annotations on DSL.sequence() constructors
#5482 - ResultImpl#intoMap produces an incorrect error message on duplicate key
#5496 - NotSerializableException thrown when AbstractXMLasObjectBinding is applied on a column
#5500 - Cannot apply Binding to PostgreSQL UDT arrays
#5523 - Bad SQL generated for PostgreSQL when inlining arrays
#5531 - Don't System.exit(-1) from within GenerationTool. Throw an exception instead
#5548 - Work around an ojdbc7 driver bug producing a NPE for Oracle 12c INSERT .. RETURNING statements
#5560 - Compilation error when generated catalog and one of its contained schemas have the same name
#5572 - DataTypeException: Cannot convert from String to class [B when generated code contains VARBINARY type with default value
#5579 - Incorrect ambiguity warning when column name appears in 3+ joined tables
#5580 - NullPointerException when generating Oracle AQs with payload types outside of the included schemas
#5598 - Code generator IOExceptions are not logged when error appears during closing of file
#5599 - Error on code generation when schema name is a Windows reserved name like CON, AUX
#5610 - JPADatabase includes undesired INFORMATION_SCHEMA by default
#5611 - JPADatabase causes warnings
#5615 - SchemaVersionProvider might cause deletion of schemas that were not updated
  • Loading branch information
lukaseder committed Oct 21, 2016
1 parent b018212 commit fdb2962
Show file tree
Hide file tree
Showing 47 changed files with 645 additions and 267 deletions.
2 changes: 1 addition & 1 deletion jOOQ-codegen-maven/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jooq</groupId>
<artifactId>jooq-parent</artifactId>
<version>3.8.4</version>
<version>3.8.5</version>
</parent>

<groupId>org.jooq</groupId>
Expand Down
2 changes: 1 addition & 1 deletion jOOQ-codegen/pom.xml
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.jooq</groupId>
<artifactId>jooq-parent</artifactId>
<version>3.8.4</version>
<version>3.8.5</version>
</parent>

<groupId>org.jooq</groupId>
Expand Down
40 changes: 30 additions & 10 deletions jOOQ-codegen/src/main/java/org/jooq/util/AbstractGenerator.java
Expand Up @@ -44,6 +44,8 @@
import java.util.Collections;
import java.util.Set;

import org.jooq.tools.JooqLogger;


/**
* A common base implementation for {@link Generator} objects
Expand All @@ -52,6 +54,8 @@
*/
abstract class AbstractGenerator implements Generator {

private static final JooqLogger log = JooqLogger.getLogger(AbstractGenerator.class);

boolean generateDeprecated = true;
boolean generateRelations = true;
boolean generateInstanceFields = true;
Expand Down Expand Up @@ -464,27 +468,43 @@ public void setTargetEncoding(String encoding) {
* If file is a file, delete it.
*/
protected void empty(File file, String suffix) {
empty(file, suffix, Collections.<File>emptySet());
empty(file, suffix, Collections.<File>emptySet(), Collections.<File>emptySet());
}

/**
* If file is a directory, recursively empty its children.
* If file is a file, delete it, except if it is in the list of files to keep.
*/
protected void empty(File file, String suffix, Set<File> keep) {
protected void empty(File file, String suffix, Set<File> keep, Set<File> ignore) {
if (file != null) {

// Just a Murphy's Law safeguard in case a user misconfigures their config...
if (file.getParentFile() == null) {
log.warn("WARNING: Root directory configured for code generation. Not deleting anything from previous generations!");
return;
}

// [#5614] Don't go into these directories
for (File i : ignore)
if (file.getAbsolutePath().startsWith(i.getAbsolutePath()))
return;

if (file.isDirectory()) {
File[] children = file.listFiles();

if (children != null) {
for (File child : children) {
empty(child, suffix, keep);
}
}
} else {
if (file.getName().endsWith(suffix) && !keep.contains(file)) {
if (children != null)
for (File child : children)
empty(child, suffix, keep, ignore);

File[] childrenAfterDeletion = file.listFiles();

// [#5556] Delete directory if empty after content was removed.
// Useful if a catalog / schema was dropped, or removed from code generation, or renamed
if (childrenAfterDeletion != null && childrenAfterDeletion.length == 0)
file.delete();
}
}
else if (file.getName().endsWith(suffix) && !keep.contains(file)) {
file.delete();
}
}
}
Expand Down
Expand Up @@ -67,6 +67,13 @@ public final String getFileName(Definition definition, Mode mode) {
return getJavaClassName(definition, mode) + ".java";
}

@Override
public final File getFileRoot() {
String dir = getTargetDirectory();
String pkg = getTargetPackage().replaceAll("\\.", "/");
return new File(dir + "/" + pkg);
}

@Override
public final File getFile(Definition definition) {
return getFile(definition, Mode.DEFAULT);
Expand Down
78 changes: 29 additions & 49 deletions jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java
Expand Up @@ -135,11 +135,15 @@ public void setDataSource(DataSource dataSource) {
}

public static void main(String[] args) throws Exception {
if (args.length < 1)
error();
if (args.length < 1) {
log.error("Usage : GenerationTool <configuration-file>");
System.exit(-1);
return;
}

argsLoop: for (String arg : args) {
for (String arg : args) {
InputStream in = GenerationTool.class.getResourceAsStream(arg);

try {

// [#2932] Retry loading the file, if it wasn't found. This may be helpful
Expand All @@ -158,23 +162,22 @@ public static void main(String[] args) throws Exception {
log.error(" - on the classpath and qualified as a classpath location.");
log.error(" - in the local directory or at a global path in the file system.");

continue argsLoop;
System.exit(-1);
return;
}

log.info("Initialising properties", arg);

generate(load(in));
}
catch (Exception e) {
log.error("Cannot read " + arg + ". Error : " + e.getMessage());
e.printStackTrace();
log.error("Cannot read " + arg + ". Error : " + e.getMessage(), e);

continue argsLoop;
System.exit(-1);
return;
}
finally {
if (in != null) {
if (in != null)
in.close();
}
}
}
}
Expand Down Expand Up @@ -222,7 +225,8 @@ public void run(Configuration configuration) throws Exception {

Jdbc j = configuration.getJdbc();
org.jooq.util.jaxb.Generator g = configuration.getGenerator();
errorIfNull(g, "The <generator/> tag is mandatory.");
if (g == null)
throw new GeneratorException("The <generator/> tag is mandatory. For details, see " + Constants.NS_CODEGEN);

// Some default values for optional elements to avoid NPE's
if (g.getStrategy() == null)
Expand Down Expand Up @@ -305,12 +309,10 @@ else if (j != null) {
schemata.add(schema);
}
else {
if (!StringUtils.isBlank(d.getInputSchema())) {
if (!StringUtils.isBlank(d.getInputSchema()))
log.warn("WARNING: Cannot combine configuration properties /configuration/generator/database/inputSchema and /configuration/generator/database/schemata");
}
if (!StringUtils.isBlank(d.getOutputSchema())) {
if (!StringUtils.isBlank(d.getOutputSchema()))
log.warn("WARNING: Cannot combine configuration properties /configuration/generator/database/outputSchema and /configuration/generator/database/schemata");
}
}

for (Schema schema : schemata) {
Expand All @@ -325,18 +327,14 @@ else if (j != null) {
// [#3018] Prior to <outputSchemaToDefault/>, empty <outputSchema/> elements meant that
// the outputSchema should be the default schema. This is a bit too clever, and doesn't
// work when Maven parses the XML configurations.
if ("".equals(schema.getOutputSchema())) {
if ("".equals(schema.getOutputSchema()))
log.warn("WARNING: Empty <outputSchema/> should no longer be used to model default outputSchemas. Use <outputSchemaToDefault>true</outputSchemaToDefault>, instead. See also: https://github.com/jOOQ/jOOQ/issues/3018");
}

// [#3018] If users want the output schema to be "" then, ignore the actual <outputSchema/> configuration
if (TRUE.equals(schema.isOutputSchemaToDefault())) {
if (TRUE.equals(schema.isOutputSchemaToDefault()))
schema.setOutputSchema("");
}

else if (schema.getOutputSchema() == null) {
else if (schema.getOutputSchema() == null)
schema.setOutputSchema(trim(schema.getInputSchema()));
}



Expand All @@ -350,11 +348,9 @@ else if (schema.getOutputSchema() == null) {

}

if (schemata.size() == 1) {
if (StringUtils.isBlank(schemata.get(0).getInputSchema())) {
if (schemata.size() == 1)
if (StringUtils.isBlank(schemata.get(0).getInputSchema()))
log.info("No <inputSchema/> was provided. Generating ALL available schemata instead!");
}
}

database.setConnection(connection);
database.setConfiguredSchemata(schemata);
Expand Down Expand Up @@ -531,24 +527,20 @@ else if (schema.getOutputSchema() == null) {


generator.generate(database);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
}
finally {

// Close connection only if it was created by the GenerationTool
if (close && connection != null) {
if (close && connection != null)
connection.close();
}
}
}

private Properties properties(List<Property> properties) {
Properties result = new Properties();

for (Property p : properties) {
for (Property p : properties)
result.put(p.getKey(), p.getValue());
}

return result;
}
Expand All @@ -573,13 +565,13 @@ private Class<? extends Database> databaseClass(Connection c) {
return databaseClass(c.getMetaData().getURL());
}
catch (SQLException e) {
throw new RuntimeException(e);
throw new GeneratorException("Error when reading URL from JDBC connection", e);
}
}

private Class<? extends Database> databaseClass(String url) {
if (isBlank(url))
throw new RuntimeException("No JDBC URL configured.");
throw new GeneratorException("No JDBC URL configured.");

Class<? extends Database> result = Databases.databaseClass(JDBCUtils.dialect(url));
log.info("Database", "Inferring database " + result.getName() + " from URL " + url);
Expand Down Expand Up @@ -623,18 +615,6 @@ private static String trim(String string) {
return (string == null ? null : string.trim());
}

private static void errorIfNull(Object o, String message) {
if (o == null) {
log.error(message + " For details, see " + Constants.NS_CODEGEN);
System.exit(-1);
}
}

private static void error() {
log.error("Usage : GenerationTool <configuration-file>");
System.exit(-1);
}

/**
* Copy bytes from a large (over 2GB) <code>InputStream</code> to an
* <code>OutputStream</code>.
Expand Down Expand Up @@ -697,7 +677,7 @@ public boolean handleEvent(ValidationEvent event) {
return (Configuration) unmarshaller.unmarshal(new StringReader(xml));
}
catch (Exception e) {
throw new RuntimeException(e);
throw new GeneratorException("Error while reading XML configuration", e);
}
}
}

0 comments on commit fdb2962

Please sign in to comment.