[#6222] Generate IDENTITY information on data type
This commit is contained in:
parent
74bcc17063
commit
eb33ce9cf7
@ -5223,6 +5223,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
0,
|
||||
0,
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
baseType
|
||||
) + ".getArrayDataType()";
|
||||
@ -5236,6 +5237,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
type.getScale(),
|
||||
type.getLength(),
|
||||
type.isNullable(),
|
||||
type.isIdentity(),
|
||||
type.getDefaultValue(),
|
||||
type.getQualifiedUserType()
|
||||
);
|
||||
@ -5374,15 +5376,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - Use {@link #getTypeReference(Database, SchemaDefinition, String, int, int, int, boolean, String, Name)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
protected String getTypeReference(Database db, SchemaDefinition schema, String t, int p, int s, int l, boolean n, String d, String u) {
|
||||
return getTypeReference(db, schema, t, p, s, l, n, d, name(u));
|
||||
}
|
||||
|
||||
protected String getTypeReference(Database db, SchemaDefinition schema, String t, int p, int s, int l, boolean n, String d, Name u) {
|
||||
protected String getTypeReference(Database db, SchemaDefinition schema, String t, int p, int s, int l, boolean n, boolean i, String d, Name u) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (db.getArray(schema, u) != null) {
|
||||
ArrayDefinition array = database.getArray(schema, u);
|
||||
@ -5417,7 +5411,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
DataType<?> dataType = null;
|
||||
|
||||
try {
|
||||
dataType = mapJavaTimeTypes(DefaultDataType.getDataType(db.getDialect(), t, p, s)).nullable(n);
|
||||
dataType = mapJavaTimeTypes(DefaultDataType.getDataType(db.getDialect(), t, p, s)).nullable(n).identity(i);
|
||||
|
||||
if (d != null)
|
||||
dataType = dataType.defaultValue((Field) DSL.field(d, dataType));
|
||||
@ -5454,6 +5448,9 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
if (!dataType.nullable())
|
||||
sb.append(".nullable(false)");
|
||||
|
||||
if (dataType.identity())
|
||||
sb.append(".identity(true)");
|
||||
|
||||
// [#5291] Some dialects report valid SQL expresions (e.g. PostgreSQL), others
|
||||
// report actual values (e.g. MySQL).
|
||||
if (dataType.defaulted()) {
|
||||
|
||||
@ -95,6 +95,11 @@ public interface DataTypeDefinition {
|
||||
*/
|
||||
boolean isNullable();
|
||||
|
||||
/**
|
||||
* Whether this data type is an identity.
|
||||
*/
|
||||
boolean isIdentity();
|
||||
|
||||
/**
|
||||
* Whether this data type is defaultable.
|
||||
*/
|
||||
|
||||
@ -61,6 +61,10 @@ public class DefaultColumnDefinition
|
||||
|
||||
this.position = position;
|
||||
this.isIdentity = isIdentity || isSyntheticIdentity(this);
|
||||
|
||||
// [#6222] Copy the column's identity flag to the data type definition
|
||||
if (type instanceof DefaultDataTypeDefinition)
|
||||
((DefaultDataTypeDefinition) type).identity(this.isIdentity);
|
||||
}
|
||||
|
||||
private static boolean isSyntheticIdentity(DefaultColumnDefinition column) {
|
||||
|
||||
@ -64,6 +64,7 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
|
||||
private final String converter;
|
||||
private final String binding;
|
||||
private final boolean nullable;
|
||||
private boolean isIdentity;
|
||||
private final String defaultValue;
|
||||
private final int length;
|
||||
private final int precision;
|
||||
@ -224,6 +225,16 @@ public class DefaultDataTypeDefinition implements DataTypeDefinition {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
public final DefaultDataTypeDefinition identity(boolean identity) {
|
||||
this.isIdentity = identity;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isIdentity() {
|
||||
return isIdentity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isDefaulted() {
|
||||
return getDefaultValue() != null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user