use of org.jooq.util.DefaultColumnDefinition in project jOOQ by jOOQ.
the class CUBRIDTableDefinition method getElements0.
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
for (Record record : create().select(DB_ATTRIBUTE.ATTR_NAME, DB_ATTRIBUTE.DEF_ORDER, DB_ATTRIBUTE.DATA_TYPE, DB_ATTRIBUTE.PREC, DB_ATTRIBUTE.SCALE, DB_ATTRIBUTE.IS_NULLABLE, DB_ATTRIBUTE.DEFAULT_VALUE, DB_SERIAL.NAME).from(DB_ATTRIBUTE).leftOuterJoin(DB_SERIAL).on(DB_ATTRIBUTE.ATTR_NAME.equal(DB_SERIAL.ATT_NAME).and(DB_ATTRIBUTE.CLASS_NAME.equal(DB_SERIAL.CLASS_NAME))).where(DB_ATTRIBUTE.CLASS_NAME.equal(getName())).orderBy(DB_ATTRIBUTE.DEF_ORDER).fetch()) {
String dataType = record.get(DB_ATTRIBUTE.DATA_TYPE);
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), dataType, record.get(DB_ATTRIBUTE.PREC), record.get(DB_ATTRIBUTE.PREC), record.get(DB_ATTRIBUTE.SCALE), record.get(DB_ATTRIBUTE.IS_NULLABLE, boolean.class), record.get(DB_ATTRIBUTE.DEFAULT_VALUE), getName() + "_" + record.get(DB_ATTRIBUTE.ATTR_NAME));
ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(DB_ATTRIBUTE.ATTR_NAME), record.get(DB_ATTRIBUTE.DEF_ORDER), type, record.get(DB_SERIAL.NAME) != null, null);
result.add(column);
}
return result;
}
use of org.jooq.util.DefaultColumnDefinition in project jOOQ by jOOQ.
the class PostgresTableValuedFunction method getElements0.
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
Routines r = ROUTINES;
Parameters p = PARAMETERS;
PgNamespace pg_n = PG_NAMESPACE;
PgProc pg_p = PG_PROC;
Columns c = COLUMNS;
for (Record record : create().select(p.PARAMETER_NAME, rowNumber().over(partitionBy(p.SPECIFIC_NAME).orderBy(p.ORDINAL_POSITION)).as(p.ORDINAL_POSITION), p.DATA_TYPE, p.CHARACTER_MAXIMUM_LENGTH, p.NUMERIC_PRECISION, p.NUMERIC_SCALE, inline("true").as(c.IS_NULLABLE), (((PostgresDatabase) getDatabase()).is94() ? PARAMETERS.PARAMETER_DEFAULT : inline((String) null)).as(c.COLUMN_DEFAULT), p.UDT_SCHEMA, p.UDT_NAME).from(r).join(p).on(row(r.SPECIFIC_CATALOG, r.SPECIFIC_SCHEMA, r.SPECIFIC_NAME).eq(p.SPECIFIC_CATALOG, p.SPECIFIC_SCHEMA, p.SPECIFIC_NAME)).join(pg_n).on(r.SPECIFIC_SCHEMA.eq(pg_n.NSPNAME)).join(pg_p).on(pg_p.PRONAMESPACE.eq(oid(pg_n))).and(pg_p.PRONAME.eq(r.ROUTINE_NAME)).where(r.SPECIFIC_NAME.eq(specificName)).and(p.PARAMETER_MODE.ne("IN")).and(pg_p.PRORETSET).unionAll(// from INFORMATION_SCHEMA.TABLES
select(nvl(c.COLUMN_NAME, getName()).as(c.COLUMN_NAME), // Type inference doesn't seem to be possible here with Java 8... ?
nvl(c.ORDINAL_POSITION, DSL.<Integer>inline(1)).as(c.ORDINAL_POSITION), nvl(c.DATA_TYPE, r.DATA_TYPE).as(c.DATA_TYPE), nvl(c.CHARACTER_MAXIMUM_LENGTH, r.CHARACTER_MAXIMUM_LENGTH).as(c.CHARACTER_MAXIMUM_LENGTH), nvl(c.NUMERIC_PRECISION, r.NUMERIC_PRECISION).as(c.NUMERIC_PRECISION), 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).leftOuterJoin(c).on(row(r.TYPE_UDT_CATALOG, r.TYPE_UDT_SCHEMA, r.TYPE_UDT_NAME).eq(c.TABLE_CATALOG, c.TABLE_SCHEMA, c.TABLE_NAME)).join(pg_n).on(r.SPECIFIC_SCHEMA.eq(pg_n.NSPNAME)).join(pg_p).on(pg_p.PRONAMESPACE.eq(oid(pg_n))).and(pg_p.PRONAME.concat("_").concat(oid(pg_p)).eq(r.SPECIFIC_NAME)).where(r.SPECIFIC_NAME.eq(specificName)).and(row(r.SPECIFIC_CATALOG, r.SPECIFIC_SCHEMA, r.SPECIFIC_NAME).notIn(select(p.SPECIFIC_CATALOG, p.SPECIFIC_SCHEMA, p.SPECIFIC_NAME).from(p).where(p.PARAMETER_MODE.eq("OUT")))).and(pg_p.PRORETSET)).orderBy(2)) {
SchemaDefinition typeSchema = null;
String schemaName = record.get(p.UDT_SCHEMA);
if (schemaName != null)
typeSchema = getDatabase().getSchema(schemaName);
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), typeSchema, record.get(p.DATA_TYPE), record.get(p.CHARACTER_MAXIMUM_LENGTH), record.get(p.NUMERIC_PRECISION), record.get(p.NUMERIC_SCALE), record.get(c.IS_NULLABLE, boolean.class), record.get(c.COLUMN_DEFAULT), name(record.get(p.UDT_SCHEMA), record.get(p.UDT_NAME)));
ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(p.PARAMETER_NAME), record.get(p.ORDINAL_POSITION, int.class), type, defaultString(record.get(c.COLUMN_DEFAULT)).startsWith("nextval"), null);
result.add(column);
}
return result;
}
use of org.jooq.util.DefaultColumnDefinition in project jOOQ by jOOQ.
the class HSQLDBTableDefinition method getElements0.
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
for (Record record : create().select(COLUMNS.COLUMN_NAME, COLUMNS.ORDINAL_POSITION, nvl(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER, nvl2(COLUMNS.INTERVAL_TYPE, concat(COLUMNS.DATA_TYPE, val(" "), COLUMNS.INTERVAL_TYPE), COLUMNS.DATA_TYPE)).as("datatype"), COLUMNS.IDENTITY_GENERATION, COLUMNS.IS_NULLABLE, COLUMNS.COLUMN_DEFAULT, COLUMNS.CHARACTER_MAXIMUM_LENGTH, COLUMNS.NUMERIC_PRECISION, COLUMNS.NUMERIC_SCALE, COLUMNS.UDT_NAME).from(COLUMNS).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).fetch()) {
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("datatype", String.class), 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), record.get(COLUMNS.UDT_NAME));
ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(COLUMNS.COLUMN_NAME), record.get(COLUMNS.ORDINAL_POSITION, int.class), type, null != record.get(COLUMNS.IDENTITY_GENERATION), null);
result.add(column);
}
return result;
}
use of org.jooq.util.DefaultColumnDefinition in project jOOQ by jOOQ.
the class H2TableDefinition method getElements0.
@Override
public List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
for (Record record : create().select(Columns.COLUMN_NAME, Columns.ORDINAL_POSITION, Columns.TYPE_NAME, Columns.CHARACTER_MAXIMUM_LENGTH, Columns.NUMERIC_PRECISION, Columns.NUMERIC_SCALE, Columns.IS_NULLABLE, Columns.COLUMN_DEFAULT, Columns.REMARKS, Columns.SEQUENCE_NAME).from(COLUMNS).where(Columns.TABLE_SCHEMA.equal(getSchema().getName())).and(Columns.TABLE_NAME.equal(getName())).orderBy(Columns.ORDINAL_POSITION).fetch()) {
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get(Columns.TYPE_NAME), 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));
ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(Columns.COLUMN_NAME), record.get(Columns.ORDINAL_POSITION), type, // [#5331] AUTO_INCREMENT (MySQL style)
null != record.get(Columns.SEQUENCE_NAME) || // [#5331] DEFAULT nextval('sequence') (PostgreSQL style)
defaultString(record.get(Columns.COLUMN_DEFAULT)).trim().toLowerCase().startsWith("nextval"), record.get(Columns.REMARKS));
result.add(column);
}
return result;
}
use of org.jooq.util.DefaultColumnDefinition in project jOOQ by jOOQ.
the class FirebirdTableDefinition method getElements0.
@Override
protected List<ColumnDefinition> getElements0() throws SQLException {
List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
Rdb$relationFields r = RDB$RELATION_FIELDS.as("r");
Rdb$fields f = RDB$FIELDS.as("f");
// DatabaseMetaData implementation
for (Record record : create().select(r.RDB$FIELD_NAME.trim(), r.RDB$DESCRIPTION, r.RDB$DEFAULT_VALUE, DSL.bitOr(r.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(r.RDB$NULL_FLAG), r.RDB$DEFAULT_SOURCE, r.RDB$FIELD_POSITION, // [#3342] FIELD_LENGTH should be ignored for LOBs
CHARACTER_LENGTH(f).as("CHARACTER_LENGTH"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), FIELD_TYPE(f).as("FIELD_TYPE"), f.RDB$FIELD_SUB_TYPE).from(r).leftOuterJoin(f).on(r.RDB$FIELD_SOURCE.eq(f.RDB$FIELD_NAME)).where(r.RDB$RELATION_NAME.eq(getName())).orderBy(r.RDB$FIELD_POSITION).fetch()) {
DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), record.get("FIELD_TYPE", String.class), record.get("CHARACTER_LENGTH", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(r.RDB$NULL_FLAG) == 0, record.get(r.RDB$DEFAULT_SOURCE));
ColumnDefinition column = new DefaultColumnDefinition(getDatabase().getTable(getSchema(), getName()), record.get(r.RDB$FIELD_NAME.trim()), record.get(r.RDB$FIELD_POSITION), type, false, null);
result.add(column);
}
return result;
}
Aggregations