use of org.jooq.util.SchemaDefinition in project jOOQ by jOOQ.
the class PostgresDatabase method getUDTs0.
@Override
protected List<UDTDefinition> getUDTs0() throws SQLException {
List<UDTDefinition> result = new ArrayList<UDTDefinition>();
// [#2736] This table is unavailable in Amazon Redshift
if (exists(ATTRIBUTES)) {
for (Record record : create().selectDistinct(ATTRIBUTES.UDT_SCHEMA, ATTRIBUTES.UDT_NAME).from(ATTRIBUTES).where(ATTRIBUTES.UDT_SCHEMA.in(getInputSchemata())).orderBy(ATTRIBUTES.UDT_SCHEMA, ATTRIBUTES.UDT_NAME).fetch()) {
SchemaDefinition schema = getSchema(record.get(ATTRIBUTES.UDT_SCHEMA));
String name = record.get(ATTRIBUTES.UDT_NAME);
result.add(new PostgresUDTDefinition(schema, name, null));
}
}
return result;
}
use of org.jooq.util.SchemaDefinition 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.SchemaDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
for (Record record : fetchKeys("UNIQUE")) {
SchemaDefinition schema = getSchema(record.get(KEY_COLUMN_USAGE.TABLE_SCHEMA));
String key = record.get(KEY_COLUMN_USAGE.CONSTRAINT_NAME);
String tableName = record.get(KEY_COLUMN_USAGE.TABLE_NAME);
String columnName = record.get(KEY_COLUMN_USAGE.COLUMN_NAME);
TableDefinition table = getTable(schema, tableName);
if (table != null) {
relations.addUniqueKey(key, table.getColumn(columnName));
}
}
}
use of org.jooq.util.SchemaDefinition 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;
}
use of org.jooq.util.SchemaDefinition in project jOOQ by jOOQ.
the class MySQLDatabase method getRoutines0.
@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
List<RoutineDefinition> result = new ArrayList<RoutineDefinition>();
try {
create(true).fetchCount(PROC);
} catch (DataAccessException e) {
log.warn("Table unavailable", "The `mysql`.`proc` table is unavailable. Stored procedures cannot be loaded. Check if you have sufficient grants");
return result;
}
Result<Record6<String, String, String, byte[], byte[], ProcType>> records = create().select(Proc.DB, Proc.NAME, Proc.COMMENT, Proc.PARAM_LIST, Proc.RETURNS, Proc.TYPE).from(PROC).where(DB.in(getInputSchemata())).orderBy(DB, Proc.NAME).fetch();
Map<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> groups = records.intoGroups(new Field[] { Proc.DB, Proc.NAME });
// procedures and functions with the same signature.
for (Entry<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> entry : groups.entrySet()) {
Result<?> overloads = entry.getValue();
for (int i = 0; i < overloads.size(); i++) {
Record record = overloads.get(i);
SchemaDefinition schema = getSchema(record.get(DB));
String name = record.get(Proc.NAME);
String comment = record.get(Proc.COMMENT);
String params = new String(record.get(Proc.PARAM_LIST));
String returns = new String(record.get(Proc.RETURNS));
ProcType type = record.get(Proc.TYPE);
if (overloads.size() > 1) {
result.add(new MySQLRoutineDefinition(schema, name, comment, params, returns, type, "_" + type.name()));
} else {
result.add(new MySQLRoutineDefinition(schema, name, comment, params, returns, type, null));
}
}
}
return result;
}
Aggregations