use of org.jooq.meta.ColumnDefinition in project jOOQ by jOOQ.
the class FirebirdTableValuedFunction method getElements0.
@Override
protected List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<>();
Rdb$procedureParameters p = RDB$PROCEDURE_PARAMETERS.as("p");
Rdb$fields f = RDB$FIELDS.as("f");
// DatabaseMetaData implementation
for (Record record : create().select(p.RDB$PARAMETER_NUMBER, p.RDB$PARAMETER_NAME.trim(), p.RDB$DESCRIPTION, p.RDB$DEFAULT_VALUE, DSL.bitOr(p.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(p.RDB$NULL_FLAG), p.RDB$DEFAULT_SOURCE, // [#3342] FIELD_LENGTH should be ignored for LOBs
CHARACTER_LENGTH(f).as("CHAR_LEN"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), FIELD_TYPE(f).as("FIELD_TYPE"), f.RDB$FIELD_SUB_TYPE).from(p).leftOuterJoin(f).on(p.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(p.RDB$PROCEDURE_NAME.eq(getName())).and(p.RDB$PARAMETER_TYPE.eq((short) 1)).orderBy(p.RDB$PARAMETER_NUMBER)) {
DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("FIELD_TYPE", String.class), record.get("CHAR_LEN", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(p.RDB$NULL_FLAG) == 0, record.get(p.RDB$DEFAULT_SOURCE));
result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(p.RDB$PARAMETER_NAME.trim()), result.size() + 1, type, false, null));
}
return result;
}
use of org.jooq.meta.ColumnDefinition in project jOOQ by jOOQ.
the class H2TableDefinition method getElements1_4.
public List<ColumnDefinition> getElements1_4() {
List<ColumnDefinition> result = new ArrayList<>();
// [#7206] H2 defaults to these precision/scale values when a DECIMAL/NUMERIC type
// does not have any precision/scale. What works in H2 works in almost no
// other database, which is relevant when using the DDLDatabase for instance,
// which is based on the H2Database
Param<Long> maxP = inline(65535L);
Param<Long> maxS = inline(32767L);
H2Database db = (H2Database) getDatabase();
for (Record record : create().select(COLUMNS.COLUMN_NAME, COLUMNS.ORDINAL_POSITION, // [#2230] [#11733] Translate INTERVAL_TYPE to supported types
(db.is1_4_198() ? (when(COLUMNS.INTERVAL_TYPE.like(any(inline("%YEAR%"), inline("%MONTH%"))), inline("INTERVAL YEAR TO MONTH")).when(COLUMNS.INTERVAL_TYPE.like(any(inline("%DAY%"), inline("%HOUR%"), inline("%MINUTE%"), inline("%SECOND%"))), inline("INTERVAL DAY TO SECOND")).else_(COLUMNS.TYPE_NAME)) : COLUMNS.TYPE_NAME).as(COLUMNS.TYPE_NAME), choose().when(COLUMNS.NUMERIC_PRECISION.eq(maxP).and(COLUMNS.NUMERIC_SCALE.eq(maxS)), inline(0L)).otherwise(COLUMNS.CHARACTER_MAXIMUM_LENGTH).as(COLUMNS.CHARACTER_MAXIMUM_LENGTH), COLUMNS.NUMERIC_PRECISION.decode(maxP, inline(0L), COLUMNS.NUMERIC_PRECISION).as(COLUMNS.NUMERIC_PRECISION), COLUMNS.NUMERIC_SCALE.decode(maxS, inline(0L), COLUMNS.NUMERIC_SCALE).as(COLUMNS.NUMERIC_SCALE), COLUMNS.IS_NULLABLE, COLUMNS.IS_COMPUTED.as(COLUMNS.IS_COMPUTED), COLUMNS.COLUMN_DEFAULT.as("GENERATION_EXPRESSION"), COLUMNS.COLUMN_DEFAULT, COLUMNS.REMARKS, field(COLUMNS.SEQUENCE_NAME.isNotNull()).as("IS_IDENTITY"), db.is1_4_198() ? COLUMNS.DOMAIN_SCHEMA : inline("").as(COLUMNS.DOMAIN_SCHEMA), db.is1_4_198() ? COLUMNS.DOMAIN_NAME : inline("").as(COLUMNS.DOMAIN_NAME)).from(COLUMNS).where(COLUMNS.TABLE_SCHEMA.equal(getSchema().getName())).and(COLUMNS.TABLE_NAME.equal(getName())).and(!getDatabase().getIncludeInvisibleColumns() ? db.is1_4_198() ? COLUMNS.IS_VISIBLE.eq(inline("TRUE")) : COLUMNS.COLUMN_TYPE.notLike(inline("%INVISIBLE%")) : noCondition()).orderBy(COLUMNS.ORDINAL_POSITION)) {
// [#5331] AUTO_INCREMENT (MySQL style)
// [#5331] DEFAULT nextval('sequence') (PostgreSQL style)
// [#6332] [#6339] system-generated defaults shouldn't produce a default clause
boolean isIdentity = record.get("IS_IDENTITY", boolean.class) || defaultString(record.get(COLUMNS.COLUMN_DEFAULT)).trim().toLowerCase().startsWith("nextval");
boolean isComputed = record.get(COLUMNS.IS_COMPUTED, boolean.class);
// [#7644] H2 1.4.200 puts DATETIME_PRECISION in NUMERIC_SCALE column
boolean isTimestamp = record.get(COLUMNS.TYPE_NAME).trim().toLowerCase().startsWith("timestamp");
// [#681] Domain name if available
Name userType = record.get(COLUMNS.DOMAIN_NAME) != null ? name(record.get(COLUMNS.DOMAIN_SCHEMA), record.get(COLUMNS.DOMAIN_NAME)) : name(getSchema().getName(), getName() + "_" + record.get(COLUMNS.COLUMN_NAME));
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get(COLUMNS.TYPE_NAME), record.get(COLUMNS.CHARACTER_MAXIMUM_LENGTH), isTimestamp ? record.get(COLUMNS.NUMERIC_SCALE) : record.get(COLUMNS.NUMERIC_PRECISION), isTimestamp ? 0 : record.get(COLUMNS.NUMERIC_SCALE), record.get(COLUMNS.IS_NULLABLE, boolean.class), isIdentity || isComputed ? null : record.get(COLUMNS.COLUMN_DEFAULT), userType).generatedAlwaysAs(isComputed ? record.get("GENERATION_EXPRESSION", String.class) : null);
result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), result.size() + 1, type, isIdentity, record.get(COLUMNS.REMARKS)));
}
return result;
}
use of org.jooq.meta.ColumnDefinition in project jOOQ by jOOQ.
the class HSQLDBTableDefinition method getElements0.
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<>();
for (Record record : create().select(COLUMNS.COLUMN_NAME, COLUMNS.ORDINAL_POSITION, nvl(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER, // [#2230] Translate INTERVAL_TYPE to supported types
when(COLUMNS.INTERVAL_TYPE.like(any(inline("%YEAR%"), inline("%MONTH%"))), inline("INTERVAL YEAR TO MONTH")).when(COLUMNS.INTERVAL_TYPE.like(any(inline("%DAY%"), inline("%HOUR%"), inline("%MINUTE%"), inline("%SECOND%"))), inline("INTERVAL DAY TO SECOND")).else_(COLUMNS.DATA_TYPE)).as(COLUMNS.DATA_TYPE), COLUMNS.IDENTITY_GENERATION, COLUMNS.IS_NULLABLE, COLUMNS.COLUMN_DEFAULT, COLUMNS.GENERATION_EXPRESSION, nvl(ELEMENT_TYPES.CHARACTER_MAXIMUM_LENGTH, COLUMNS.CHARACTER_MAXIMUM_LENGTH).as(COLUMNS.CHARACTER_MAXIMUM_LENGTH), coalesce(ELEMENT_TYPES.DATETIME_PRECISION, ELEMENT_TYPES.NUMERIC_PRECISION, COLUMNS.DATETIME_PRECISION, COLUMNS.NUMERIC_PRECISION).as(COLUMNS.NUMERIC_PRECISION), nvl(ELEMENT_TYPES.NUMERIC_SCALE, COLUMNS.NUMERIC_SCALE).as(COLUMNS.NUMERIC_SCALE), coalesce(COLUMNS.DOMAIN_SCHEMA, COLUMNS.UDT_SCHEMA).as(COLUMNS.UDT_SCHEMA), coalesce(COLUMNS.DOMAIN_NAME, COLUMNS.UDT_NAME).as(COLUMNS.UDT_NAME), SYSTEM_COLUMNS.REMARKS).from(COLUMNS).leftOuterJoin(SYSTEM_COLUMNS).on(COLUMNS.TABLE_CATALOG.eq(SYSTEM_COLUMNS.TABLE_CAT)).and(COLUMNS.TABLE_SCHEMA.eq(SYSTEM_COLUMNS.TABLE_SCHEM)).and(COLUMNS.TABLE_NAME.eq(SYSTEM_COLUMNS.TABLE_NAME)).and(COLUMNS.COLUMN_NAME.eq(SYSTEM_COLUMNS.COLUMN_NAME)).leftOuterJoin(ELEMENT_TYPES).on(COLUMNS.TABLE_SCHEMA.equal(ELEMENT_TYPES.OBJECT_SCHEMA)).and(COLUMNS.TABLE_NAME.equal(ELEMENT_TYPES.OBJECT_NAME)).and(COLUMNS.DTD_IDENTIFIER.equal(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER)).where(COLUMNS.TABLE_SCHEMA.equal(getSchema().getName())).and(COLUMNS.TABLE_NAME.equal(getName())).orderBy(COLUMNS.ORDINAL_POSITION)) {
String generated = record.get(COLUMNS.GENERATION_EXPRESSION);
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get(COLUMNS.DATA_TYPE), record.get(COLUMNS.CHARACTER_MAXIMUM_LENGTH), record.get(COLUMNS.NUMERIC_PRECISION), record.get(COLUMNS.NUMERIC_SCALE), record.get(COLUMNS.IS_NULLABLE, boolean.class), generated != null ? null : record.get(COLUMNS.COLUMN_DEFAULT), DSL.name(record.get(COLUMNS.UDT_SCHEMA), record.get(COLUMNS.UDT_NAME))).generatedAlwaysAs(generated);
result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), result.size() + 1, type, null != record.get(COLUMNS.IDENTITY_GENERATION), record.get(SYSTEM_COLUMNS.REMARKS)));
}
return result;
}
use of org.jooq.meta.ColumnDefinition in project jOOQ by jOOQ.
the class HSQLDBTableValuedFunction method getElements0.
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<>();
Field<?>[] fields = create().meta(source.replaceAll(".*? RETURNS TABLE(.*)SPECIFIC .*", "CREATE TABLE X $1")).getTables("X").get(0).fields();
for (int i = 0; i < fields.length; i++) {
Field<?> field = fields[i];
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), field.getDataType().getTypeName(create().configuration()), field.getDataType().length(), field.getDataType().precision(), field.getDataType().scale(), field.getDataType().nullable(), (String) null);
result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), field.getName(), result.size() + 1, type, false, null));
}
return result;
}
use of org.jooq.meta.ColumnDefinition in project jOOQ by jOOQ.
the class PostgresMaterializedViewDefinition method getElements0.
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<>();
Columns col = COLUMNS;
PgAttribute a = PG_ATTRIBUTE.as("a");
PgAttrdef ad = PG_ATTRDEF.as("ad");
PgType t = PG_TYPE.as("t");
PgType bt = PG_TYPE.as("bt");
PgClass c = PG_CLASS.as("c");
PgCollation co = PG_COLLATION.as("co");
PgNamespace nt = PG_NAMESPACE.as("nt");
PgNamespace nc = PG_NAMESPACE.as("nc");
PgNamespace nbt = PG_NAMESPACE.as("nbt");
PgNamespace nco = PG_NAMESPACE.as("nco");
for (Record record : create().select(field("({0})::information_schema.sql_identifier", col.COLUMN_NAME.getDataType(), a.ATTNAME).as(col.COLUMN_NAME), field("({0})::information_schema.cardinal_number", col.ORDINAL_POSITION.getDataType(), a.ATTNUM).as(col.ORDINAL_POSITION), field("({0})::information_schema.character_data", col.DATA_TYPE.getDataType(), when(t.TYPTYPE.eq(inline("d")), when(bt.TYPELEM.ne(inline(0L)).and(bt.TYPLEN.eq(inline((short) -1))), inline("ARRAY")).when(nbt.NSPNAME.eq(inline("pg_catalog")), field("format_type({0}, NULL::integer)", String.class, t.TYPBASETYPE)).otherwise(inline("USER-DEFINED"))).otherwise(when(t.TYPELEM.ne(inline(0L)).and(t.TYPLEN.eq(inline((short) -1))), inline("ARRAY")).when(nt.NSPNAME.eq(inline("pg_catalog")), field("format_type({0}, NULL::integer)", String.class, a.ATTTYPID)).otherwise(inline("USER-DEFINED")))).as(col.DATA_TYPE), field("(information_schema._pg_char_max_length(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number", col.CHARACTER_MAXIMUM_LENGTH.getDataType()).as(col.CHARACTER_MAXIMUM_LENGTH), field("(information_schema._pg_numeric_precision(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number", col.NUMERIC_PRECISION.getDataType()).as(col.NUMERIC_PRECISION), field("(information_schema._pg_numeric_scale(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number", col.NUMERIC_SCALE.getDataType()).as(col.NUMERIC_SCALE), field("({0})::information_schema.yes_or_no", col.IS_NULLABLE.getDataType(), when(condition(a.ATTNOTNULL).or(t.TYPTYPE.eq(inline("d")).and(t.TYPNOTNULL)), inline("NO")).otherwise(inline("YES"))).as(col.IS_NULLABLE), field("(pg_get_expr({0}, {1}))::information_schema.character_data", col.COLUMN_DEFAULT.getDataType(), ad.ADBIN, ad.ADRELID).as(col.COLUMN_DEFAULT), field("({0})::information_schema.sql_identifier", col.UDT_SCHEMA.getDataType(), nvl(nbt.NSPNAME, nt.NSPNAME)).as(col.UDT_SCHEMA), field("({0})::information_schema.sql_identifier", col.UDT_NAME.getDataType(), nvl(bt.TYPNAME, t.TYPNAME)).as(col.UDT_NAME), PG_DESCRIPTION.DESCRIPTION).from(a.leftJoin(ad).on(a.ATTRELID.eq(ad.ADRELID)).and(a.ATTNUM.eq(ad.ADNUM)).join(c.join(nc).on(c.RELNAMESPACE.eq(nc.OID))).on(a.ATTRELID.eq(c.OID)).join(t.join(nt).on(t.TYPNAMESPACE.eq(nt.OID))).on(a.ATTTYPID.eq(t.OID))).leftJoin(bt.join(nbt).on(bt.TYPNAMESPACE.eq(nbt.OID))).on(t.TYPTYPE.eq(inline("d")).and(t.TYPBASETYPE.eq(bt.OID))).leftJoin(co.join(nco).on(co.COLLNAMESPACE.eq(nco.OID))).on(a.ATTCOLLATION.eq(co.OID).and(nco.NSPNAME.ne(inline("pg_catalog")).or(co.COLLNAME.ne(inline("default"))))).leftJoin(PG_DESCRIPTION).on(PG_DESCRIPTION.OBJOID.eq(c.OID)).and(PG_DESCRIPTION.OBJSUBID.eq(a.ATTNUM.coerce(PG_DESCRIPTION.OBJSUBID))).where(not(condition("pg_is_other_temp_schema({0})", nc.OID)).and(a.ATTNUM.gt(inline((short) 0))).and(not(a.ATTISDROPPED)).and(c.RELKIND.eq(inline("m"))).and(nc.NSPNAME.in(getSchema().getName())).and(c.RELNAME.eq(getName()))).orderBy(a.ATTNUM)) {
SchemaDefinition typeSchema = null;
String schemaName = record.get(COLUMNS.UDT_SCHEMA);
if (schemaName != null)
typeSchema = getDatabase().getSchema(schemaName);
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema, record.get(COLUMNS.DATA_TYPE), record.get(COLUMNS.CHARACTER_MAXIMUM_LENGTH), record.get(COLUMNS.NUMERIC_PRECISION), record.get(COLUMNS.NUMERIC_SCALE), record.get(COLUMNS.IS_NULLABLE, boolean.class), record.get(COLUMNS.COLUMN_DEFAULT), name(record.get(COLUMNS.UDT_SCHEMA), record.get(COLUMNS.UDT_NAME)));
result.add(new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), result.size() + 1, type, defaultString(record.get(COLUMNS.COLUMN_DEFAULT)).startsWith("nextval"), record.get(PG_DESCRIPTION.DESCRIPTION)));
}
return result;
}
Aggregations