Skip to content

Commit

Permalink
Version 3.4.2 - August 08, 2014
Browse files Browse the repository at this point in the history
================================================================================

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

Bug fixes
---------
jOOQ#3392 - Call setAccessible(true) only if really needed
jOOQ#3400 - ALTER TABLE generates invalid syntax on Firebird when data types are
        nullable
jOOQ#3402 - Wrong character length generated by jOOQ for Firebird
jOOQ#3408 - Remove the default log4j.xml configuration file from the maven plugin
        again
jOOQ#3413 - Oracle generated ArrayRecords cannot be constructed through reflection
        if deprecated flag is set to off
jOOQ#3420 - NullPointerException when generating code for Oracle AQ Tables
jOOQ#3430 - JDBC escape syntax is not correctly rendered from plain SQL
jOOQ#3437 - QualifiedField does not respect RenderContext.qualify()
jOOQ#3445 - Cannot run Maven code generator with professional edition
jOOQ#3450 - Backslashes in SQL comments don't get escaped
jOOQ#3455 - UPDATE .. FROM statement renders incorrect SQL for derived tables or
        aliased tables
jOOQ#3456 - Name clash in generated code when Routine argument is called "f"
        (functions) or "p" (procedures)
jOOQ#3462 - Field<Object>.in(Object...) can be called with Select<?> arguments,
        accidentally
jOOQ#3463 - Field.in(...) methods shouldn't return trueCondition() or
        falseCondition()
jOOQ#3473 - java.lang.IllegalArgumentException: Field (null) is not contained in Row
jOOQ#3488 - Compilation error in generated code, when a similar tables T_A and TA
        exist
jOOQ#3489 - DefaultTransactionProvider does not call
        Connection.releaseSavepoint(Savepoint)
  • Loading branch information
lukaseder committed Aug 8, 2014
1 parent c97218e commit 6e29e07
Show file tree
Hide file tree
Showing 55 changed files with 607 additions and 202 deletions.
2 changes: 1 addition & 1 deletion jOOQ-codegen-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jooq</groupId>
<artifactId>jooq-parent</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
</parent>

<groupId>org.jooq</groupId>
Expand Down
15 changes: 0 additions & 15 deletions jOOQ-codegen-maven/src/main/resources/log4j.xml

This file was deleted.

2 changes: 1 addition & 1 deletion jOOQ-codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.jooq</groupId>
<artifactId>jooq-parent</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
</parent>

<groupId>org.jooq</groupId>
Expand Down
74 changes: 58 additions & 16 deletions jOOQ-codegen/src/main/java/org/jooq/util/JavaGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -136,6 +138,7 @@ public class JavaGenerator extends AbstractGenerator {
@Override
public final void generate(Database db) {
this.database = db;
this.database.addFilter(new AvoidAmbiguousClassesFilter());

String url = null;
try {
Expand Down Expand Up @@ -300,6 +303,32 @@ private final void generate(SchemaDefinition schema) {
watch.splitInfo("GENERATION FINISHED!");
}

private class AvoidAmbiguousClassesFilter implements Database.Filter {

private Map<String, String> included = new HashMap<String, String>();

@Override
public boolean exclude(Definition definition) {

// These definitions don't generate types of their own.
if ( definition instanceof ColumnDefinition
|| definition instanceof AttributeDefinition
|| definition instanceof ParameterDefinition)
return false;

// Check if we've previously encountered a Java type of the same case-insensitive, fully-qualified name.
String name = getStrategy().getFullJavaClassName(definition);
String nameLC = name.toLowerCase();
String existing = included.put(nameLC, name);

if (existing == null)
return false;

log.warn("Ambiguous type name", "The object " + definition.getQualifiedOutputName() + " generates a type " + name + " which conflicts with the existing type " + existing + " on some operating systems. Use a custom generator strategy to disambiguate the types.");
return true;
}
}

private boolean hasTableValuedFunctions(SchemaDefinition schema) {
for (TableDefinition table : database.getTables(schema)) {
if (table.isTableValuedFunction()) {
Expand Down Expand Up @@ -1994,7 +2023,12 @@ protected void generateTable(SchemaDefinition schema, TableDefinition table) {
}

private String escapeString(String comment) {
return comment.replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "\\r");

// [#3450] Escape also the escape sequence, among other things that break Java strings.
return comment.replace("\\", "\\\\")
.replace("\"", "\\\"")
.replace("\n", "\\n")
.replace("\r", "\\r");
}

/**
Expand Down Expand Up @@ -2388,6 +2422,7 @@ protected void printConvenienceMethodFunctionAsField(JavaWriter out, RoutineDefi
}

final String className = getStrategy().getFullJavaClassName(function);
final String localVar = disambiguateJavaMemberName(function.getInParameters(), "f");

out.tab(1).javadoc("Get <code>%s</code> as a field", function.getQualifiedOutputName());
out.tab(1).print("public static %s<%s> %s(",
Expand All @@ -2410,17 +2445,17 @@ protected void printConvenienceMethodFunctionAsField(JavaWriter out, RoutineDefi
}

out.println(") {");
out.tab(2).println("%s f = new %s();", className, className);
out.tab(2).println("%s %s = new %s();", className, localVar, className);

for (ParameterDefinition parameter : function.getInParameters()) {
final String paramSetter = getStrategy().getJavaSetterName(parameter, Mode.DEFAULT);
final String paramMember = getStrategy().getJavaMemberName(parameter);

out.tab(2).println("f.%s(%s);", paramSetter, paramMember);
out.tab(2).println("%s.%s(%s);", localVar, paramSetter, paramMember);
}

out.println();
out.tab(2).println("return f.as%s();", function.isAggregate() ? "AggregateFunction" : "Field");
out.tab(2).println("return %s.as%s();", localVar, function.isAggregate() ? "AggregateFunction" : "Field");
out.tab(1).println("}");
}

Expand Down Expand Up @@ -2508,7 +2543,10 @@ protected void printConvenienceMethodFunction(JavaWriter out, RoutineDefinition
final String functionName = function.getQualifiedOutputName();
final String functionType = getJavaType(function.getReturnType());
final String methodName = getStrategy().getJavaMethodName(function, Mode.DEFAULT);

// [#3456] Local variables should not collide with actual function arguments
final String configurationArgument = disambiguateJavaMemberName(function.getInParameters(), "configuration");
final String localVar = disambiguateJavaMemberName(function.getInParameters(), "f");

out.tab(1).javadoc("Call <code>%s</code>", functionName);
out.tab(1).print("public %s%s %s(",
Expand All @@ -2534,23 +2572,23 @@ protected void printConvenienceMethodFunction(JavaWriter out, RoutineDefinition
}

out.println(") {");
out.tab(2).println("%s f = new %s();", className, className);
out.tab(2).println("%s %s = new %s();", className, localVar, className);

for (ParameterDefinition parameter : function.getInParameters()) {
final String paramSetter = getStrategy().getJavaSetterName(parameter, Mode.DEFAULT);
final String paramMember = (instance && parameter.equals(function.getInParameters().get(0)))
? "this"
: getStrategy().getJavaMemberName(parameter);

out.tab(2).println("f.%s(%s);", paramSetter, paramMember);
out.tab(2).println("%s.%s(%s);", localVar, paramSetter, paramMember);
}

out.println();
out.tab(2).println("f.execute(%s);", instance ? "configuration()" : configurationArgument);
out.tab(2).println("%s.execute(%s);", localVar, instance ? "configuration()" : configurationArgument);

// TODO [#956] Find a way to register "SELF" as OUT parameter
// in case this is a UDT instance (member) function
out.tab(2).println("return f.getReturnValue();");
out.tab(2).println("return %s.getReturnValue();", localVar);
out.tab(1).println("}");
}

Expand All @@ -2563,6 +2601,7 @@ protected void printConvenienceMethodProcedure(JavaWriter out, RoutineDefinition

final String className = getStrategy().getFullJavaClassName(procedure);
final String configurationArgument = disambiguateJavaMemberName(procedure.getInParameters(), "configuration");
final String localVar = disambiguateJavaMemberName(procedure.getInParameters(), "p");

out.tab(1).javadoc("Call <code>%s</code>", procedure.getQualifiedOutputName());
out.print("\tpublic ");
Expand Down Expand Up @@ -2608,19 +2647,19 @@ else if (procedure.getOutParameters().size() == 1) {
}

out.println(") {");
out.tab(2).println("%s p = new %s();", className, className);
out.tab(2).println("%s %s = new %s();", className, localVar, className);

for (ParameterDefinition parameter : procedure.getInParameters()) {
final String setter = getStrategy().getJavaSetterName(parameter, Mode.DEFAULT);
final String arg = (instance && parameter.equals(procedure.getInParameters().get(0)))
? "this"
: getStrategy().getJavaMemberName(parameter);

out.tab(2).println("p.%s(%s);", setter, arg);
out.tab(2).println("%s.%s(%s);", localVar, setter, arg);
}

out.println();
out.tab(2).println("p.execute(%s);", instance ? "configuration()" : configurationArgument);
out.tab(2).println("%s.execute(%s);", localVar, instance ? "configuration()" : configurationArgument);

if (procedure.getOutParameters().size() > 0) {
final ParameterDefinition parameter = procedure.getOutParameters().get(0);
Expand All @@ -2633,18 +2672,18 @@ else if (procedure.getOutParameters().size() == 1) {

// [#3117] Avoid funny call-site ambiguity if this is a UDT that is implemented by an interface
if (generateInterfaces() && isUDT) {
out.tab(2).println("from((%s) p.%s());", columnTypeInterface, getter);
out.tab(2).println("from((%s) %s.%s());", columnTypeInterface, localVar, getter);
}
else {
out.tab(2).println("from(p.%s());", getter);
out.tab(2).println("from(%s.%s());", localVar, getter);
}
}

if (procedure.getOutParameters().size() == 1) {
out.tab(2).println("return p.%s();", getter);
out.tab(2).println("return %s.%s();", localVar, getter);
}
else if (procedure.getOutParameters().size() > 1) {
out.tab(2).println("return p;");
out.tab(2).println("return %s;", localVar);
}
}

Expand Down Expand Up @@ -2696,7 +2735,10 @@ protected void printClassJavadoc(JavaWriter out, String comment) {
* This method is used to add line breaks in lengthy javadocs
*/
protected void printJavadocParagraph(JavaWriter out, String comment, String indent) {
printParagraph(out, comment, indent + " * ");

// [#3450] Must not print */ inside Javadoc
String escaped = comment.replace("*/", "* /");
printParagraph(out, escaped, indent + " * ");
}

protected void printParagraph(GeneratorWriter<?> out, String comment, String indent) {
Expand Down
5 changes: 4 additions & 1 deletion jOOQ-codegen/src/main/java/org/jooq/util/JavaWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ public JavaWriter print(Class<?> clazz) {
public JavaWriter javadoc(String string, Object... args) {
final int t = tab();

// [#3450] Must not print */ inside Javadoc
String escaped = string.replace("*/", "* /");

tab(t).println();
tab(t).println("/**");
tab(t).println(" * " + string, args);
tab(t).println(" * " + escaped, args);
tab(t).println(" */");

return this;
Expand Down
4 changes: 2 additions & 2 deletions jOOQ-examples/jOOQ-jax-rs-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.4.1-SNAPSHOT</version>
<version>3.4.2</version>

<executions>
<execution>
Expand Down Expand Up @@ -108,7 +108,7 @@
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.4.1-SNAPSHOT</version>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand Down
2 changes: 1 addition & 1 deletion jOOQ-examples/jOOQ-spring-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.springframework.version>3.2.6.RELEASE</org.springframework.version>
<org.jooq.version>3.4.1</org.jooq.version>
<org.jooq.version>3.4.2</org.jooq.version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion jOOQ-examples/jOOQ-spring-guice-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.springframework.version>3.2.6.RELEASE</org.springframework.version>
<org.jooq.version>3.4.1</org.jooq.version>
<org.jooq.version>3.4.2</org.jooq.version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion jOOQ-meta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jooq</groupId>
<artifactId>jooq-parent</artifactId>
<version>3.4.1</version>
<version>3.4.2</version>
</parent>

<groupId>org.jooq</groupId>
Expand Down
29 changes: 24 additions & 5 deletions jOOQ-meta/src/main/java/org/jooq/util/AbstractDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -89,6 +90,7 @@ public abstract class AbstractDatabase implements Database {
private SQLDialect dialect;
private Connection connection;
private DSLContext create;
private List<Filter> filters;
private String[] excludes;
private String[] includes;
private boolean includeExcludeColumns;
Expand Down Expand Up @@ -140,6 +142,7 @@ public abstract class AbstractDatabase implements Database {

protected AbstractDatabase() {
exists = new HashMap<Table<?>, Boolean>();
filters = new ArrayList<Database.Filter>();
}

@Override
Expand Down Expand Up @@ -283,6 +286,16 @@ public final void setConfiguredSchemata(List<Schema> schemata) {
this.configuredSchemata = schemata;
}

@Override
public final List<Filter> getFilters() {
return Collections.unmodifiableList(filters);
}

@Override
public final void addFilter(Filter filter) {
filters.add(filter);
}

@Override
public final void setExcludes(String[] excludes) {
this.excludes = excludes;
Expand Down Expand Up @@ -821,11 +834,11 @@ private final <T extends Definition> List<T> filterSchema(List<T> definitions, S
}
}

private final <T extends Definition> List<T> filterExcludeInclude(List<T> definitions) {
return filterExcludeInclude(definitions, excludes, includes);
protected final <T extends Definition> List<T> filterExcludeInclude(List<T> definitions) {
return filterExcludeInclude(definitions, excludes, includes, filters);
}

static final <T extends Definition> List<T> filterExcludeInclude(List<T> definitions, String[] excludes, String[] includes) {
protected static final <T extends Definition> List<T> filterExcludeInclude(List<T> definitions, String[] excludes, String[] includes, List<Filter> filters) {
List<T> result = new ArrayList<T>();

definitionsLoop: for (T definition : definitions) {
Expand All @@ -842,6 +855,12 @@ static final <T extends Definition> List<T> filterExcludeInclude(List<T> definit
}
}

for (Filter filter : filters) {
if (filter.exclude(definition)) {
continue definitionsLoop;
}
}

if (includes != null) {
for (String include : includes) {
Pattern p = Pattern.compile(include, Pattern.COMMENTS);
Expand Down Expand Up @@ -933,7 +952,7 @@ private final void syntheticPrimaryKeys(DefaultRelations r) {

for (SchemaDefinition schema : getSchemata()) {
for (TableDefinition table : schema.getTables()) {
List<ColumnDefinition> columns = filterExcludeInclude(table.getColumns(), null, getSyntheticPrimaryKeys());
List<ColumnDefinition> columns = filterExcludeInclude(table.getColumns(), null, getSyntheticPrimaryKeys(), filters);

if (!columns.isEmpty()) {
DefaultUniqueKeyDefinition syntheticKey = new DefaultUniqueKeyDefinition(schema, "SYNTHETIC_PK_" + table.getName(), table, true);
Expand All @@ -952,7 +971,7 @@ private final void syntheticPrimaryKeys(DefaultRelations r) {

private final void overridePrimaryKeys(DefaultRelations r) {
List<UniqueKeyDefinition> allKeys = r.getUniqueKeys();
List<UniqueKeyDefinition> filteredKeys = filterExcludeInclude(allKeys, null, overridePrimaryKeys);
List<UniqueKeyDefinition> filteredKeys = filterExcludeInclude(allKeys, null, overridePrimaryKeys, filters);

log.info("Overriding primary keys", fetchedSize(allKeys, filteredKeys));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected final List<E> getElements() {

// [#2603] Filter exclude / include also for table columns
if (this instanceof TableDefinition && db.getIncludeExcludeColumns()) {
elements = filterExcludeInclude(e, db.getExcludes(), db.getIncludes());
elements = filterExcludeInclude(e, db.getExcludes(), db.getIncludes(), db.getFilters());
log.info("Columns fetched", fetchedSize(e, elements));
}
else {
Expand Down
Loading

0 comments on commit 6e29e07

Please sign in to comment.