use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class XMLDatabase method getRoutines0.
@Override
protected List<RoutineDefinition> getRoutines0() {
List<RoutineDefinition> result = new ArrayList<>();
for (Routine routine : info().getRoutines()) {
if (isBlank(routine.getSpecificPackage()) && isBlank(routine.getRoutinePackage())) {
String schemaName = defaultIfBlank(routine.getSpecificSchema(), routine.getRoutineSchema());
if (getInputSchemata().contains(schemaName)) {
SchemaDefinition schema = getSchema(schemaName);
result.add(new XMLRoutineDefinition(schema, null, info(), routine, routine.getComment()));
}
}
}
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class XMLDatabase method loadForeignKeys.
@Override
protected void loadForeignKeys(DefaultRelations relations) {
for (ReferentialConstraint fk : info().getReferentialConstraints()) {
if (getInputSchemata().contains(fk.getConstraintSchema())) {
for (KeyColumnUsage usage : info().getKeyColumnUsages()) {
if (StringUtils.equals(defaultIfNull(fk.getConstraintCatalog(), ""), defaultIfNull(usage.getConstraintCatalog(), "")) && StringUtils.equals(defaultIfNull(fk.getConstraintSchema(), ""), defaultIfNull(usage.getConstraintSchema(), "")) && StringUtils.equals(defaultIfNull(fk.getConstraintName(), ""), defaultIfNull(usage.getConstraintName(), ""))) {
SchemaDefinition foreignKeySchema = getSchema(fk.getConstraintSchema());
SchemaDefinition uniqueKeySchema = getSchema(fk.getUniqueConstraintSchema());
String foreignKey = usage.getConstraintName();
String foreignKeyTableName = usage.getTableName();
String foreignKeyColumn = usage.getColumnName();
String uniqueKey = fk.getUniqueConstraintName();
TableConstraint fktc = tableConstraint(fk.getConstraintCatalog(), fk.getConstraintSchema(), fk.getConstraintName());
TableConstraint uktc = tableConstraint(fk.getUniqueConstraintCatalog(), fk.getUniqueConstraintSchema(), fk.getUniqueConstraintName());
if (fktc != null && uktc != null) {
TableDefinition foreignKeyTable = getTable(foreignKeySchema, foreignKeyTableName);
TableDefinition uniqueKeyTable = getTable(uniqueKeySchema, uktc.getTableName());
if (foreignKeyTable != null && uniqueKeyTable != null)
relations.addForeignKey(foreignKey, foreignKeyTable, foreignKeyTable.getColumn(foreignKeyColumn), uniqueKey, uniqueKeyTable, !FALSE.equals(fktc.isEnforced()));
}
}
}
}
}
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class MySQLDatabase method getRoutines0.
@Override
protected List<RoutineDefinition> getRoutines0() throws SQLException {
List<RoutineDefinition> result = new ArrayList<>();
Result<Record6<String, String, String, byte[], byte[], ProcType>> records = is8() ? create().select(ROUTINES.ROUTINE_SCHEMA, ROUTINES.ROUTINE_NAME, ROUTINES.ROUTINE_COMMENT, inline(new byte[0]).as(PROC.PARAM_LIST), inline(new byte[0]).as(PROC.RETURNS), ROUTINES.ROUTINE_TYPE.coerce(PROC.TYPE).as(ROUTINES.ROUTINE_TYPE)).from(ROUTINES).where(ROUTINES.ROUTINE_SCHEMA.in(getInputSchemata())).orderBy(1, 2, 6).fetch() : create().select(PROC.DB.as(ROUTINES.ROUTINE_SCHEMA), PROC.NAME.as(ROUTINES.ROUTINE_NAME), PROC.COMMENT.as(ROUTINES.ROUTINE_COMMENT), PROC.PARAM_LIST, PROC.RETURNS, PROC.TYPE.as(ROUTINES.ROUTINE_TYPE)).from(PROC).where(PROC.DB.in(getInputSchemata())).orderBy(1, 2, 6).fetch();
Map<Record, Result<Record6<String, String, String, byte[], byte[], ProcType>>> groups = records.intoGroups(new Field[] { ROUTINES.ROUTINE_SCHEMA, ROUTINES.ROUTINE_NAME });
// [#1908] This indirection is necessary as MySQL allows for overloading
// procedures and functions with the same signature.
groups.forEach((k, overloads) -> {
overloads.forEach(record -> {
SchemaDefinition schema = getSchema(record.get(ROUTINES.ROUTINE_SCHEMA));
String name = record.get(ROUTINES.ROUTINE_NAME);
String comment = record.get(ROUTINES.ROUTINE_COMMENT);
String params = is8() ? "" : new String(record.get(PROC.PARAM_LIST));
String returns = is8() ? "" : new String(record.get(PROC.RETURNS));
ProcType type = record.get(ROUTINES.ROUTINE_TYPE.coerce(PROC.TYPE).as(ROUTINES.ROUTINE_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;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class MySQLDatabase method getTables0.
@Override
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<>();
for (Record record : create().select(TABLES.TABLE_SCHEMA, TABLES.TABLE_NAME, TABLES.TABLE_COMMENT, when(TABLES.TABLE_TYPE.eq(inline("VIEW")), inline(TableType.VIEW.name())).else_(inline(TableType.TABLE.name())).as("table_type"), when(VIEWS.VIEW_DEFINITION.lower().like(inline("create%")), VIEWS.VIEW_DEFINITION).else_(inline("create view `").concat(TABLES.TABLE_NAME).concat("` as ").concat(VIEWS.VIEW_DEFINITION)).as(VIEWS.VIEW_DEFINITION)).from(TABLES).leftJoin(VIEWS).on(TABLES.TABLE_SCHEMA.eq(VIEWS.TABLE_SCHEMA)).and(TABLES.TABLE_NAME.eq(VIEWS.TABLE_NAME)).where(TABLES.TABLE_SCHEMA.in(workaroundFor5213(getInputSchemata()))).and(TABLES.TABLE_TYPE.ne(inline("SEQUENCE"))).orderBy(TABLES.TABLE_SCHEMA, TABLES.TABLE_NAME)) {
SchemaDefinition schema = getSchema(record.get(TABLES.TABLE_SCHEMA));
String name = record.get(TABLES.TABLE_NAME);
String comment = record.get(TABLES.TABLE_COMMENT);
TableType tableType = record.get("table_type", TableType.class);
String source = record.get(VIEWS.VIEW_DEFINITION);
MySQLTableDefinition table = new MySQLTableDefinition(schema, name, comment, tableType, source);
result.add(table);
}
return result;
}
use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.
the class MySQLDatabase method loadUniqueKeys.
@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
for (Record record : uniqueKeys(getInputSchemata())) {
SchemaDefinition schema = getSchema(record.get(STATISTICS.TABLE_SCHEMA));
String constraintName = record.get(STATISTICS.INDEX_NAME);
String tableName = record.get(STATISTICS.TABLE_NAME);
String columnName = record.get(STATISTICS.COLUMN_NAME);
String key = getKeyName(tableName, constraintName);
TableDefinition table = getTable(schema, tableName);
if (table != null)
relations.addUniqueKey(key, table, table.getColumn(columnName));
}
}
Aggregations