[#4708] Wrong enum type referenced from UDT, when the same enum type exists in different schemas in PostgreSQL
This commit is contained in:
parent
e89a2a8c9e
commit
b2fc85457f
@ -146,7 +146,6 @@ public abstract class AbstractDatabase implements Database {
|
||||
private transient Map<SchemaDefinition, List<ForeignKeyDefinition>> foreignKeysBySchema;
|
||||
private transient Map<SchemaDefinition, List<CheckConstraintDefinition>> checkConstraintsBySchema;
|
||||
private transient Map<SchemaDefinition, List<TableDefinition>> tablesBySchema;
|
||||
@SuppressWarnings("unused")
|
||||
private transient Map<SchemaDefinition, List<EnumDefinition>> enumsBySchema;
|
||||
private transient Map<SchemaDefinition, List<UDTDefinition>> udtsBySchema;
|
||||
private transient Map<SchemaDefinition, List<ArrayDefinition>> arraysBySchema;
|
||||
@ -781,7 +780,11 @@ public abstract class AbstractDatabase implements Database {
|
||||
}
|
||||
}
|
||||
|
||||
return enums;
|
||||
if (enumsBySchema == null) {
|
||||
enumsBySchema = new LinkedHashMap<SchemaDefinition, List<EnumDefinition>>();
|
||||
}
|
||||
|
||||
return filterSchema(enums, schema, enumsBySchema);
|
||||
}
|
||||
|
||||
private final List<EnumDefinition> getConfiguredEnums() {
|
||||
|
||||
@ -610,6 +610,7 @@ public class PostgresDatabase extends AbstractDatabase {
|
||||
r1.CHARACTER_MAXIMUM_LENGTH,
|
||||
r1.NUMERIC_PRECISION,
|
||||
r1.NUMERIC_SCALE,
|
||||
r1.TYPE_UDT_SCHEMA,
|
||||
r1.TYPE_UDT_NAME,
|
||||
|
||||
// Calculate overload index if applicable
|
||||
|
||||
@ -59,6 +59,7 @@ import org.jooq.util.DefaultDataTypeDefinition;
|
||||
import org.jooq.util.DefaultParameterDefinition;
|
||||
import org.jooq.util.InOutDefinition;
|
||||
import org.jooq.util.ParameterDefinition;
|
||||
import org.jooq.util.SchemaDefinition;
|
||||
|
||||
/**
|
||||
* Postgres implementation of {@link AbstractRoutineDefinition}
|
||||
@ -79,9 +80,17 @@ public class PostgresRoutineDefinition extends AbstractRoutineDefinition {
|
||||
record.getValue(PG_PROC.PROISAGG, boolean.class));
|
||||
|
||||
if (!Arrays.asList("void", "record").contains(record.getValue("data_type"))) {
|
||||
SchemaDefinition typeSchema = null;
|
||||
|
||||
String schemaName = record.getValue(ROUTINES.TYPE_UDT_SCHEMA);
|
||||
if (schemaName != null)
|
||||
typeSchema = getDatabase().getSchema(schemaName);
|
||||
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(
|
||||
getDatabase(),
|
||||
database.getSchema(record.getValue(ROUTINES.ROUTINE_SCHEMA)),
|
||||
typeSchema == null
|
||||
? database.getSchema(record.getValue(ROUTINES.ROUTINE_SCHEMA))
|
||||
: typeSchema,
|
||||
record.getValue("data_type", String.class),
|
||||
record.getValue(ROUTINES.CHARACTER_MAXIMUM_LENGTH),
|
||||
record.getValue(ROUTINES.NUMERIC_PRECISION),
|
||||
|
||||
@ -82,6 +82,7 @@ public class PostgresTableDefinition extends AbstractTableDefinition {
|
||||
COLUMNS.NUMERIC_SCALE,
|
||||
COLUMNS.IS_NULLABLE,
|
||||
COLUMNS.COLUMN_DEFAULT,
|
||||
COLUMNS.UDT_SCHEMA,
|
||||
COLUMNS.UDT_NAME,
|
||||
PG_DESCRIPTION.DESCRIPTION)
|
||||
.from(COLUMNS)
|
||||
@ -98,9 +99,15 @@ public class PostgresTableDefinition extends AbstractTableDefinition {
|
||||
.orderBy(COLUMNS.ORDINAL_POSITION)
|
||||
.fetch()) {
|
||||
|
||||
SchemaDefinition typeSchema = null;
|
||||
|
||||
String schemaName = record.getValue(COLUMNS.UDT_SCHEMA);
|
||||
if (schemaName != null)
|
||||
typeSchema = getDatabase().getSchema(schemaName);
|
||||
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(
|
||||
getDatabase(),
|
||||
getSchema(),
|
||||
typeSchema,
|
||||
record.getValue(COLUMNS.DATA_TYPE),
|
||||
record.getValue(COLUMNS.CHARACTER_MAXIMUM_LENGTH),
|
||||
record.getValue(COLUMNS.NUMERIC_PRECISION),
|
||||
|
||||
@ -113,6 +113,7 @@ public class PostgresTableValuedFunction extends AbstractTableDefinition {
|
||||
p.NUMERIC_SCALE,
|
||||
inline("true").as(c.IS_NULLABLE),
|
||||
inline(null, String.class).as(c.COLUMN_DEFAULT),
|
||||
p.UDT_SCHEMA,
|
||||
p.UDT_NAME
|
||||
)
|
||||
.from(r)
|
||||
@ -142,6 +143,7 @@ public class PostgresTableValuedFunction extends AbstractTableDefinition {
|
||||
nvl(c.NUMERIC_SCALE , r.NUMERIC_SCALE ).as(c.NUMERIC_SCALE),
|
||||
nvl(c.IS_NULLABLE , "true" ).as(c.IS_NULLABLE),
|
||||
nvl(c.COLUMN_DEFAULT , inline((String) null) ).as(c.COLUMN_DEFAULT),
|
||||
nvl(c.UDT_SCHEMA , inline((String) null) ).as(c.UDT_SCHEMA),
|
||||
nvl(c.UDT_NAME , r.UDT_NAME ).as(c.UDT_NAME)
|
||||
)
|
||||
.from(r)
|
||||
@ -167,9 +169,15 @@ public class PostgresTableValuedFunction extends AbstractTableDefinition {
|
||||
.orderBy(2)
|
||||
) {
|
||||
|
||||
SchemaDefinition typeSchema = null;
|
||||
|
||||
String schemaName = record.getValue(p.UDT_SCHEMA);
|
||||
if (schemaName != null)
|
||||
typeSchema = getDatabase().getSchema(schemaName);
|
||||
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(
|
||||
getDatabase(),
|
||||
getSchema(),
|
||||
typeSchema,
|
||||
record.getValue(p.DATA_TYPE),
|
||||
record.getValue(p.CHARACTER_MAXIMUM_LENGTH),
|
||||
record.getValue(p.NUMERIC_PRECISION),
|
||||
|
||||
@ -75,6 +75,7 @@ public class PostgresUDTDefinition extends AbstractUDTDefinition {
|
||||
ATTRIBUTES.NUMERIC_SCALE,
|
||||
ATTRIBUTES.IS_NULLABLE,
|
||||
ATTRIBUTES.ATTRIBUTE_DEFAULT,
|
||||
ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA,
|
||||
ATTRIBUTES.ATTRIBUTE_UDT_NAME)
|
||||
.from(ATTRIBUTES)
|
||||
.where(ATTRIBUTES.UDT_SCHEMA.equal(getSchema().getName()))
|
||||
@ -82,9 +83,15 @@ public class PostgresUDTDefinition extends AbstractUDTDefinition {
|
||||
.orderBy(ATTRIBUTES.ORDINAL_POSITION)
|
||||
.fetch()) {
|
||||
|
||||
SchemaDefinition typeSchema = null;
|
||||
|
||||
String schemaName = record.getValue(ATTRIBUTES.ATTRIBUTE_UDT_SCHEMA);
|
||||
if (schemaName != null)
|
||||
typeSchema = getDatabase().getSchema(schemaName);
|
||||
|
||||
DataTypeDefinition type = new DefaultDataTypeDefinition(
|
||||
getDatabase(),
|
||||
getSchema(),
|
||||
typeSchema == null ? getSchema() : typeSchema,
|
||||
record.getValue(ATTRIBUTES.DATA_TYPE),
|
||||
record.getValue(ATTRIBUTES.CHARACTER_MAXIMUM_LENGTH),
|
||||
record.getValue(ATTRIBUTES.NUMERIC_PRECISION),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user