use of org.jooq.meta.DefaultDataTypeDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<>();
for (Record record : sequences(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(SEQUENCES.SEQUENCE_SCHEMA));
DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, record.get(SEQUENCES.DATA_TYPE));
result.add(new DefaultSequenceDefinition(schema, record.get(SEQUENCES.SEQUENCE_NAME), type));
}
return result;
}
use of org.jooq.meta.DefaultDataTypeDefinition 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.DefaultDataTypeDefinition in project jOOQ by jOOQ.
the class PostgresDatabase method getDomains0.
@Override
protected List<DomainDefinition> getDomains0() throws SQLException {
List<DomainDefinition> result = new ArrayList<>();
if (existAll(PG_CONSTRAINT, PG_TYPE)) {
PgNamespace n = PG_NAMESPACE.as("n");
PgConstraint c = PG_CONSTRAINT.as("c");
PgType d = PG_TYPE.as("d");
PgType b = PG_TYPE.as("b");
Field<String[]> src = field(name("domains", "src"), String[].class);
Field<String> constraintDef = field("pg_get_constraintdef({0})", VARCHAR, c.OID);
for (Record record : create().withRecursive("domains", "domain_id", "base_id", "typbasetype", "src").as(select(d.OID, d.OID, d.TYPBASETYPE, when(c.OID.isNotNull(), array(constraintDef))).from(d).join(n).on(n.OID.eq(d.TYPNAMESPACE)).leftJoin(c).on(d.OID.eq(c.CONTYPID)).where(d.TYPTYPE.eq("d")).and(n.NSPNAME.in(getInputSchemata())).unionAll(select(field(name("domains", "domain_id"), Long.class), d.OID, d.TYPBASETYPE, decode().when(c.CONBIN.isNull(), src).otherwise(arrayAppend(src, constraintDef))).from(name("domains")).join(d).on(field(name("domains", d.TYPBASETYPE.getName())).eq(d.OID)).leftJoin(c).on(d.OID.eq(c.CONTYPID)))).select(n.NSPNAME, d.TYPNAME, d.TYPNOTNULL, d.TYPDEFAULT, b.TYPNAME, // See https://github.com/postgres/postgres/blob/master/src/backend/catalog/information_schema.sql
field("information_schema._pg_char_max_length({0}, {1})", INTEGER, d.TYPBASETYPE, d.TYPTYPMOD).as(DOMAINS.CHARACTER_MAXIMUM_LENGTH), field("information_schema._pg_numeric_precision({0}, {1})", INTEGER, d.TYPBASETYPE, d.TYPTYPMOD).as(DOMAINS.NUMERIC_PRECISION), field("information_schema._pg_numeric_scale({0}, {1})", INTEGER, d.TYPBASETYPE, d.TYPTYPMOD).as(DOMAINS.NUMERIC_SCALE), src).from(d).join(name("domains")).on(field(name("domains", "typbasetype")).eq(0)).and(field(name("domains", "domain_id")).eq(d.OID)).join(b).on(field(name("domains", "base_id")).eq(b.OID)).join(n).on(n.OID.eq(d.TYPNAMESPACE)).where(d.TYPTYPE.eq("d")).and(n.NSPNAME.in(getInputSchemata())).orderBy(n.NSPNAME, d.TYPNAME)) {
SchemaDefinition schema = getSchema(record.get(n.NSPNAME));
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(b.TYPNAME), record.get(DOMAINS.CHARACTER_MAXIMUM_LENGTH), record.get(DOMAINS.NUMERIC_PRECISION), record.get(DOMAINS.NUMERIC_SCALE), !record.get(d.TYPNOTNULL, boolean.class), record.get(d.TYPDEFAULT), name(record.get(n.NSPNAME), record.get(b.TYPNAME)));
DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(d.TYPNAME), baseType);
domain.addCheckClause(record.get(src));
result.add(domain);
}
}
return result;
}
use of org.jooq.meta.DefaultDataTypeDefinition in project jOOQ by jOOQ.
the class PostgresDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<>();
for (Record record : sequences(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(SEQUENCES.SEQUENCE_SCHEMA));
DataTypeDefinition type = new DefaultDataTypeDefinition(this, schema, record.get(SEQUENCES.DATA_TYPE), 0, record.get(SEQUENCES.NUMERIC_PRECISION), record.get(SEQUENCES.NUMERIC_SCALE), false, (String) null);
result.add(new DefaultSequenceDefinition(schema, record.get(SEQUENCES.SEQUENCE_NAME), type, null, record.get(SEQUENCES.START_VALUE, BigInteger.class), record.get(SEQUENCES.INCREMENT, BigInteger.class), record.get(SEQUENCES.MINIMUM_VALUE, BigInteger.class), record.get(SEQUENCES.MAXIMUM_VALUE, BigInteger.class), record.get(SEQUENCES.CYCLE_OPTION, Boolean.class), // [#9442] The CACHE flag is not available from SEQUENCES
null));
}
return result;
}
use of org.jooq.meta.DefaultDataTypeDefinition 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;
}
Aggregations