[#4388] Compilation errors when applying <customType/> for PostgreSQL array types

This commit is contained in:
lukaseder 2016-02-24 18:42:06 +01:00
parent 2e91fda461
commit 9dc8e8e637
4 changed files with 54 additions and 29 deletions

View File

@ -4894,27 +4894,33 @@ public class JavaGenerator extends AbstractGenerator {
type.getPrecision(),
type.getScale(),
type.getUserType(),
type.getJavaType(),
Object.class.getName(),
udtMode);
}
protected String getType(Database db, SchemaDefinition schema, String t, int p, int s, String u, String defaultType) {
return getType(db, schema, t, p, s, u, defaultType, Mode.RECORD);
protected String getType(Database db, SchemaDefinition schema, String t, int p, int s, String u, String javaType, String defaultType) {
return getType(db, schema, t, p, s, u, javaType, defaultType, Mode.RECORD);
}
protected String getType(Database db, SchemaDefinition schema, String t, int p, int s, String u, String defaultType, Mode udtMode) {
protected String getType(Database db, SchemaDefinition schema, String t, int p, int s, String u, String javaType, String defaultType, Mode udtMode) {
String type = defaultType;
// Custom types
if (javaType != null) {
type = javaType;
}
// Array types
if (db.isArrayType(t)) {
else if (db.isArrayType(t)) {
// [#4388] TODO: Improve array handling
String baseType = GenerationUtil.getArrayBaseType(db.getDialect(), t, u);
if (scala)
type = "scala.Array[" + getType(db, schema, baseType, p, s, baseType, defaultType, udtMode) + "]";
type = "scala.Array[" + getType(db, schema, baseType, p, s, baseType, javaType, defaultType, udtMode) + "]";
else
type = getType(db, schema, baseType, p, s, baseType, defaultType, udtMode) + "[]";
type = getType(db, schema, baseType, p, s, baseType, javaType, defaultType, udtMode) + "[]";
}
// Check for Oracle-style VARRAY types
@ -5080,8 +5086,8 @@ public class JavaGenerator extends AbstractGenerator {
sb.append(typeClass);
sb.append(".");
String type1 = getType(db, schema, t, p, s, u, null);
String type2 = getType(db, schema, t, 0, 0, u, null);
String type1 = getType(db, schema, t, p, s, u, null, null);
String type2 = getType(db, schema, t, 0, 0, u, null, null);
String typeName = DefaultDataType.normalise(t);
// [#1298] Prevent compilation errors for missing types

View File

@ -197,7 +197,8 @@ abstract class AbstractTypedElementDefinition<T extends Definition>
p = result.getPrecision();
s = result.getScale();
String t = result.getType();
result = new DefaultDataTypeDefinition(db, child.getSchema(), t, l, p, s, n, d, type, converter, binding);
String u = result.getUserType();
result = new DefaultDataTypeDefinition(db, child.getSchema(), t, l, p, s, n, d, u, converter, binding, type);
}
// [#4597] If we don't have a type-rewrite (forcedDataType) or a

View File

@ -85,6 +85,11 @@ public interface DataTypeDefinition {
*/
String getUserType();
/**
* The custom Java type to represent this data type, if applicable.
*/
String getJavaType();
/**
* Whether this data type is nullable.
*/

View File

@ -54,8 +54,9 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
private final Database database;
private final SchemaDefinition schema;
private final String typeName;
private final String udtName;
private final String type;
private final String userType;
private final String javaType;
private final String converter;
private final String binding;
private final boolean nullable;
@ -72,21 +73,26 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
this(database, schema, typeName, length, precision, scale, nullable, defaultable, typeName, null);
}
public DefaultDataTypeDefinition(Database database, SchemaDefinition schema, String typeName, Number length, Number precision, Number scale, Boolean nullable, Boolean defaultable, String udtName) {
this(database, schema, typeName, length, precision, scale, nullable, defaultable, udtName, null);
public DefaultDataTypeDefinition(Database database, SchemaDefinition schema, String typeName, Number length, Number precision, Number scale, Boolean nullable, Boolean defaultable, String userType) {
this(database, schema, typeName, length, precision, scale, nullable, defaultable, userType, null);
}
public DefaultDataTypeDefinition(Database database, SchemaDefinition schema, String typeName, Number length, Number precision, Number scale, Boolean nullable, Boolean defaultable, String udtName, String converter) {
this(database, schema, typeName, length, precision, scale, nullable, defaultable, udtName, converter, null);
public DefaultDataTypeDefinition(Database database, SchemaDefinition schema, String typeName, Number length, Number precision, Number scale, Boolean nullable, Boolean defaultable, String userType, String converter) {
this(database, schema, typeName, length, precision, scale, nullable, defaultable, userType, converter, null);
}
public DefaultDataTypeDefinition(Database database, SchemaDefinition schema, String typeName, Number length, Number precision, Number scale, Boolean nullable, Boolean defaultable, String udtName, String converter, String binding) {
public DefaultDataTypeDefinition(Database database, SchemaDefinition schema, String typeName, Number length, Number precision, Number scale, Boolean nullable, Boolean defaultable, String userType, String converter, String binding) {
this(database, schema, typeName, length, precision, scale, nullable, defaultable, userType, converter, binding, null);
}
public DefaultDataTypeDefinition(Database database, SchemaDefinition schema, String typeName, Number length, Number precision, Number scale, Boolean nullable, Boolean defaultable, String userType, String converter, String binding, String javaType) {
this.database = database;
this.schema = schema;
// [#3420] Some databases report NULL as a data type, e.g. Oracle for (some) AQ tables
this.typeName = typeName == null ? "OTHER" : typeName;
this.udtName = udtName;
this.type = typeName == null ? "OTHER" : typeName;
this.userType = userType;
this.javaType = javaType;
this.converter = converter;
this.binding = binding;
@ -95,7 +101,7 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
// [#650] TODO Use the central type registry to find the right
// data type instead of pattern matching
if (this.typeName.toLowerCase().matches(".*?(char|text|lob|xml|graphic|string).*?")) {
if (this.type.toLowerCase().matches(".*?(char|text|lob|xml|graphic|string).*?")) {
precision = null;
scale = null;
}
@ -137,17 +143,17 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
@Override
public final boolean isUDT() {
return getDatabase().getUDT(schema, udtName) != null;
return getDatabase().getUDT(schema, userType) != null;
}
@Override
public final boolean isArray() {
return getDatabase().getArray(schema, udtName) != null;
return getDatabase().getArray(schema, userType) != null;
}
@Override
public final String getType() {
return typeName;
return type;
}
@Override
@ -177,7 +183,12 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
@Override
public final String getUserType() {
return udtName;
return userType;
}
@Override
public final String getJavaType() {
return javaType;
}
@Override
@ -199,8 +210,8 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((typeName == null) ? 0 : typeName.hashCode());
result = prime * result + ((udtName == null) ? 0 : udtName.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((userType == null) ? 0 : userType.hashCode());
return result;
}
@ -212,8 +223,8 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
if (obj instanceof DefaultDataTypeDefinition) {
DefaultDataTypeDefinition other = (DefaultDataTypeDefinition) obj;
if (normalise(typeName).equals(normalise(other.typeName)) &&
normalise(udtName).equals(normalise(other.udtName))) {
if (normalise(type).equals(normalise(other.type)) &&
normalise(userType).equals(normalise(other.userType))) {
return true;
}
}
@ -226,13 +237,15 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
StringBuilder sb = new StringBuilder();
sb.append("DataType [ t=");
sb.append(typeName);
sb.append(type);
sb.append("; p=");
sb.append(precision);
sb.append("; s=");
sb.append(scale);
sb.append("; u=");
sb.append(udtName);
sb.append(userType);
sb.append("; j=");
sb.append(javaType);
sb.append(" ]");
return sb.toString();