use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class H2Database method getTables0.
@Override
protected List<TableDefinition> getTables0() throws SQLException {
List<TableDefinition> result = new ArrayList<TableDefinition>();
for (Record record : create().select(Tables.TABLE_SCHEMA, Tables.TABLE_NAME, Tables.REMARKS).from(TABLES).where(Tables.TABLE_SCHEMA.in(getInputSchemata())).orderBy(Tables.TABLE_SCHEMA, Tables.TABLE_NAME).fetch()) {
SchemaDefinition schema = getSchema(record.get(Tables.TABLE_SCHEMA));
if (schema != null) {
String name = record.get(Tables.TABLE_NAME);
String comment = record.get(Tables.REMARKS);
H2TableDefinition table = new H2TableDefinition(schema, name, comment);
result.add(table);
}
}
return result;
}
use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method loadPrimaryKeys.
@Override
protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
for (Record record : fetchKeys("PRIMARY KEY")) {
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.addPrimaryKey(key, table.getColumn(columnName));
}
}
}
use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class XMLDatabase method loadPrimaryKeys.
@Override
protected void loadPrimaryKeys(DefaultRelations relations) {
for (KeyColumnUsage usage : keyColumnUsage(PRIMARY_KEY)) {
SchemaDefinition schema = getSchema(usage.getConstraintSchema());
String key = usage.getConstraintName();
String tableName = usage.getTableName();
String columnName = usage.getColumnName();
TableDefinition table = getTable(schema, tableName);
if (table != null) {
relations.addPrimaryKey(key, table.getColumn(columnName));
}
}
}
use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class XMLDatabase method loadForeignKeys.
@Override
protected void loadForeignKeys(DefaultRelations relations) {
for (ReferentialConstraint constraint : info().getReferentialConstraints()) {
if (getInputSchemata().contains(constraint.getConstraintSchema())) {
for (KeyColumnUsage usage : info().getKeyColumnUsages()) {
if (StringUtils.equals(constraint.getConstraintCatalog(), usage.getConstraintCatalog()) && StringUtils.equals(constraint.getConstraintSchema(), usage.getConstraintSchema()) && StringUtils.equals(constraint.getConstraintName(), usage.getConstraintName())) {
SchemaDefinition foreignKeySchema = getSchema(constraint.getConstraintSchema());
SchemaDefinition uniqueKeySchema = getSchema(constraint.getUniqueConstraintSchema());
String foreignKey = usage.getConstraintName();
String foreignKeyTable = usage.getTableName();
String foreignKeyColumn = usage.getColumnName();
String uniqueKey = constraint.getUniqueConstraintName();
TableDefinition referencingTable = getTable(foreignKeySchema, foreignKeyTable);
if (referencingTable != null) {
ColumnDefinition referencingColumn = referencingTable.getColumn(foreignKeyColumn);
relations.addForeignKey(foreignKey, uniqueKey, referencingColumn, uniqueKeySchema);
}
}
}
}
}
}
use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.
the class CUBRIDDatabase method getEnums0.
@Override
protected List<EnumDefinition> getEnums0() throws SQLException {
List<EnumDefinition> result = new ArrayList<EnumDefinition>();
for (TableDefinition tableDefinition : getTables(getSchemata().get(0))) {
for (Record record : create().fetch("SHOW COLUMNS FROM {0} WHERE TYPE LIKE 'ENUM(%)'", field(name(tableDefinition.getInputName())))) {
String table = tableDefinition.getInputName();
String column = record.get("Field", String.class);
String columnType = record.get("Type", String.class);
String name = table + "_" + column;
ColumnDefinition columnDefinition = tableDefinition.getColumn(column);
// are explicitly forced to another type
if (getConfiguredForcedType(columnDefinition) == null) {
DefaultEnumDefinition definition = new DefaultEnumDefinition(getSchemata().get(0), name, "");
for (String string : columnType.replaceAll("ENUM\\(|\\)", "").split(",")) {
definition.addLiteral(string.trim().replaceAll("'", ""));
}
result.add(definition);
}
}
}
return result;
}
Aggregations