use of org.jooq.util.DataTypeDefinition in project jOOQ by jOOQ.
the class MySQLRoutineDefinition method init55.
private void init55() {
// table is available, which is much more reliable than mysql.proc
for (Record record : create().select(Parameters.ORDINAL_POSITION, Parameters.PARAMETER_NAME, Parameters.PARAMETER_MODE, Parameters.DATA_TYPE, Parameters.DTD_IDENTIFIER, Parameters.CHARACTER_MAXIMUM_LENGTH, Parameters.NUMERIC_PRECISION, Parameters.NUMERIC_SCALE).from(PARAMETERS).where(Parameters.SPECIFIC_SCHEMA.eq(getSchema().getInputName())).and(Parameters.SPECIFIC_NAME.eq(getInputName())).and(Parameters.ROUTINE_TYPE.eq(procType.name())).orderBy(Parameters.ORDINAL_POSITION.asc()).fetch()) {
String inOut = record.get(Parameters.PARAMETER_MODE);
String dataType = record.get(Parameters.DATA_TYPE);
// [#519] Some types have unsigned versions
if (getDatabase().supportsUnsignedTypes()) {
if (asList("tinyint", "smallint", "mediumint", "int", "bigint").contains(dataType.toLowerCase())) {
if (record.get(Parameters.DTD_IDENTIFIER).toLowerCase().contains("unsigned")) {
dataType += "unsigned";
}
}
}
DataTypeDefinition type = new DefaultDataTypeDefinition(getDatabase(), getSchema(), dataType, record.get(Parameters.CHARACTER_MAXIMUM_LENGTH), record.get(Parameters.NUMERIC_PRECISION), record.get(Parameters.NUMERIC_SCALE), null, (String) null);
if (inOut == null) {
addParameter(InOutDefinition.RETURN, new DefaultParameterDefinition(this, "RETURN_VALUE", -1, type));
} else {
ParameterDefinition parameter = new DefaultParameterDefinition(this, record.get(Parameters.PARAMETER_NAME).replaceAll("@", ""), record.get(Parameters.ORDINAL_POSITION, int.class), type);
addParameter(InOutDefinition.getFromString(inOut), parameter);
}
}
}
use of org.jooq.util.DataTypeDefinition in project jOOQ by jOOQ.
the class PostgresDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
for (Record record : create().select(SEQUENCES.SEQUENCE_SCHEMA, SEQUENCES.SEQUENCE_NAME, SEQUENCES.DATA_TYPE, SEQUENCES.NUMERIC_PRECISION, SEQUENCES.NUMERIC_SCALE).from(SEQUENCES).where(SEQUENCES.SEQUENCE_SCHEMA.in(getInputSchemata())).orderBy(SEQUENCES.SEQUENCE_SCHEMA, SEQUENCES.SEQUENCE_NAME).fetch()) {
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));
}
return result;
}
use of org.jooq.util.DataTypeDefinition 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.DataTypeDefinition 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.DataTypeDefinition in project jOOQ by jOOQ.
the class JDBCDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
for (Schema schema : getSchemasFromMeta()) {
for (Sequence<?> sequence : schema.getSequences()) {
SchemaDefinition sd = getSchema(schema.getName());
DataTypeDefinition type = new DefaultDataTypeDefinition(this, sd, sequence.getDataType().getTypeName());
result.add(new DefaultSequenceDefinition(sd, sequence.getName(), type));
}
}
return result;
}
Aggregations