- Log all column and parameter types in DEBUG level in JavaGenerator
- Add DataTypeDefinition.getMatchNames()
This commit is contained in:
Lukas Eder 2020-09-15 16:19:24 +02:00
parent a127ec65ef
commit df5f0cdd14
6 changed files with 65 additions and 21 deletions

View File

@ -915,6 +915,7 @@ public class GenerationTool {
+ "- regular expressions depending on whitespace (Pattern.COMMENTS is turned on!)\n"
+ "- missing or inadequate object qualification\n"
+ "- the " + objectType + " are obsolete\n"
+ "Try turning on DEBUG logging (-X in Maven, and <logging/> in jOOQ) to get additional info about the schema"
);
for (Object o : list)

View File

@ -2632,6 +2632,11 @@ public class JavaGenerator extends AbstractGenerator {
protected void generateUDT(SchemaDefinition schema, UDTDefinition udt) {
JavaWriter out = newJavaWriter(getFile(udt));
log.info("Generating UDT ", out.file().getName());
if (log.isDebugEnabled())
for (AttributeDefinition attribute : udt.getAttributes())
log.debug("With attribute", "name=" + attribute.getOutputName() + ", matching type names=" + attribute.getDefinedType().getMatchNames());
generateUDT(udt, out);
closeJavaWriter(out);
}
@ -4813,6 +4818,17 @@ public class JavaGenerator extends AbstractGenerator {
JavaWriter out = newJavaWriter(getFile(table));
out.refConflicts(getStrategy().getJavaIdentifiers(table.getColumns()));
out.refConflicts(getStrategy().getJavaIdentifiers(table.getReferencedEmbeddables()));
log.info("Generating table", out.file().getName() +
" [input=" + table.getInputName() +
", output=" + table.getOutputName() +
", pk=" + (table.getPrimaryKey() != null ? table.getPrimaryKey().getName() : "N/A") +
"]");
if (log.isDebugEnabled())
for (ColumnDefinition column : table.getColumns())
log.debug("With column", "name=" + column.getOutputName() + ", matching type names=" + column.getDefinedType().getMatchNames());
generateTable(table, out);
closeJavaWriter(out);
}
@ -4839,12 +4855,6 @@ public class JavaGenerator extends AbstractGenerator {
: "table";
final List<ParameterDefinition> parameters = table.getParameters();
log.info("Generating table", out.file().getName() +
" [input=" + table.getInputName() +
", output=" + table.getOutputName() +
", pk=" + (primaryKey != null ? primaryKey.getName() : "N/A") +
"]");
printPackage(out, table);
if (scala) {
@ -5758,6 +5768,7 @@ public class JavaGenerator extends AbstractGenerator {
@SuppressWarnings("unused")
protected void generateEmbeddable(SchemaDefinition schema, EmbeddableDefinition embeddable) {
JavaWriter out = newJavaWriter(getFile(embeddable, Mode.RECORD));
log.info("Generating embeddable", out.file().getName());
generateRecord0(embeddable, out);
closeJavaWriter(out);
}
@ -6733,6 +6744,11 @@ public class JavaGenerator extends AbstractGenerator {
protected void generateRoutine(SchemaDefinition schema, RoutineDefinition routine) {
JavaWriter out = newJavaWriter(getFile(routine));
log.info("Generating routine", out.file().getName());
if (log.isDebugEnabled())
for (ParameterDefinition parameter : routine.getAllParameters())
log.debug("With parameter", "name=" + parameter.getOutputName() + ", matching type names=" + parameter.getDefinedType().getMatchNames());
generateRoutine(routine, out);
closeJavaWriter(out);
}

View File

@ -1816,20 +1816,11 @@ public abstract class AbstractDatabase implements Database {
}
private boolean matches(DataTypeDefinition type, Pattern pattern) {
return ( pattern.matcher(type.getType()).matches() )
|| ( type.getLength() != 0
&& pattern.matcher(type.getType() + "(" + type.getLength() + ")").matches() )
|| ( type.getScale() == 0
&& pattern.matcher(type.getType() + "(" + type.getPrecision() + ")").matches() )
|| ( pattern.matcher(type.getType() + "(" + type.getPrecision() + "," + type.getScale() + ")").matches() )
|| ( pattern.matcher(type.getType() + "(" + type.getPrecision() + ", " + type.getScale() + ")").matches() )
for (String matchName : type.getMatchNames())
if (pattern.matcher(matchName).matches())
return true;
// [#5872] We should match user-defined types as well, in case of which the type might be reported
// as USER-DEFINED (in PostgreSQL)
|| ( !StringUtils.isBlank(type.getUserType())
&& ( pattern.matcher(type.getUserType()).matches()
|| pattern.matcher(type.getQualifiedUserType().unquotedName().toString()).matches() )
);
return false;
}
@Override

View File

@ -37,7 +37,10 @@
*/
package org.jooq.meta;
import java.util.List;
import org.jooq.Name;
import org.jooq.meta.jaxb.ForcedType;
/**
* A definition for a data type object.
@ -146,4 +149,9 @@ public interface DataTypeDefinition {
*/
SchemaDefinition getSchema();
/**
* The various type names by which this type can be matched by a
* {@link ForcedType}.
*/
List<String> getMatchNames();
}

View File

@ -44,9 +44,14 @@ import static org.jooq.impl.DefaultDataType.normalise;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.jooq.Name;
import org.jooq.SQLDialect;
import org.jooq.tools.StringUtils;
import org.jooq.types.UByte;
import org.jooq.types.UInteger;
import org.jooq.types.ULong;
@ -347,6 +352,29 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
return false;
}
@Override
public List<String> getMatchNames() {
Set<String> result = new LinkedHashSet<>();
result.add(getType());
if (getLength() != 0)
result.add(getType() + "(" + getLength() + ")");
if (getScale() == 0)
result.add(getType() + "(" + getPrecision() + ")");
result.add(getType() + "(" + getPrecision() + "," + getScale() + ")");
result.add(getType() + "(" + getPrecision() + ", " + getScale() + ")");
// [#5872] We should match user-defined types as well, in case of which the type might be reported
// as USER-DEFINED (in PostgreSQL)
if (!StringUtils.isBlank(getUserType())) {
result.add(getUserType());
result.add(getQualifiedUserType().unquotedName().toString());
}
return new ArrayList<>(result);
}
@Override
public int hashCode() {
final int prime = 31;

View File

@ -28,7 +28,7 @@ import org.jooq.meta.derby.sys.Sys;
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class Syschecks extends TableImpl<Record> {
private static final long serialVersionUID = -1008578696;
private static final long serialVersionUID = -1825970802;
/**
* The reference instance of <code>SYS.SYSCHECKS</code>
@ -57,7 +57,7 @@ public class Syschecks extends TableImpl<Record> {
* @deprecated Unknown data type. Please define an explicit {@link org.jooq.Binding} to specify how this type should be handled. Deprecation can be turned off using {@literal <deprecationOnUnknownTypes/>} in your code generator configuration.
*/
@java.lang.Deprecated
public final TableField<Record, Object> REFERENCEDCOLUMNS = createField(DSL.name("REFERENCEDCOLUMNS"), org.jooq.impl.DefaultDataType.getDefaultDataType("\"org.apache.derby.catalog.ReferencedColumns\"").nullable(false), this, "");
public final TableField<Record, Object> REFERENCEDCOLUMNS = createField(DSL.name("REFERENCEDCOLUMNS"), org.jooq.impl.SQLDataType.OTHER.nullable(false), this, "");
private Syschecks(Name alias, Table<Record> aliased) {
this(alias, aliased, null);