use of org.jooq.util.ColumnDefinition 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;
}
use of org.jooq.util.ColumnDefinition 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.ColumnDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method loadForeignKeys.
@Override
protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
Rdb$relationConstraints pk = RDB$RELATION_CONSTRAINTS.as("pk");
Rdb$relationConstraints fk = RDB$RELATION_CONSTRAINTS.as("fk");
Rdb$refConstraints rc = RDB$REF_CONSTRAINTS.as("rc");
Rdb$indexSegments isp = RDB$INDEX_SEGMENTS.as("isp");
Rdb$indexSegments isf = RDB$INDEX_SEGMENTS.as("isf");
for (Record record : create().selectDistinct(fk.RDB$CONSTRAINT_NAME.trim().as("fk"), fk.RDB$RELATION_NAME.trim().as("fkTable"), isf.RDB$FIELD_NAME.trim().as("fkField"), pk.RDB$CONSTRAINT_NAME.trim().as("pk"), pk.RDB$RELATION_NAME.trim().as("pkTable")).from(fk).join(rc).on(fk.RDB$CONSTRAINT_NAME.eq(rc.RDB$CONSTRAINT_NAME)).join(pk).on(pk.RDB$CONSTRAINT_NAME.eq(rc.RDB$CONST_NAME_UQ)).join(isp).on(isp.RDB$INDEX_NAME.eq(pk.RDB$INDEX_NAME)).join(isf).on(isf.RDB$INDEX_NAME.eq(fk.RDB$INDEX_NAME)).where(isp.RDB$FIELD_POSITION.eq(isf.RDB$FIELD_POSITION)).orderBy(fk.RDB$CONSTRAINT_NAME.asc(), isf.RDB$FIELD_POSITION.asc()).fetch()) {
String pkName = record.get("pk", String.class);
String pkTable = record.get("pkTable", String.class);
String fkName = record.get("fk", String.class);
String fkTable = record.get("fkTable", String.class);
String fkField = record.get("fkField", String.class);
TableDefinition tdReferencing = getTable(getSchemata().get(0), fkTable, true);
TableDefinition tdReferenced = getTable(getSchemata().get(0), pkTable, true);
if (tdReferenced != null && tdReferencing != null) {
ColumnDefinition referencingColumn = tdReferencing.getColumn(fkField);
relations.addForeignKey(fkName, pkName, referencingColumn, getSchemata().get(0));
}
}
}
use of org.jooq.util.ColumnDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method loadPrimaryKeys.
@Override
protected void loadPrimaryKeys(DefaultRelations r) throws SQLException {
for (Record record : fetchKeys("PRIMARY KEY")) {
String tableName = record.get(RDB$RELATION_CONSTRAINTS.RDB$RELATION_NAME.trim());
String fieldName = record.get(RDB$INDEX_SEGMENTS.RDB$FIELD_NAME.trim());
String key = record.get(RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_NAME.trim());
TableDefinition td = getTable(this.getSchemata().get(0), tableName);
if (td != null) {
ColumnDefinition cd = td.getColumn(fieldName);
r.addPrimaryKey(key, cd);
}
}
}
use of org.jooq.util.ColumnDefinition in project jOOQ by jOOQ.
the class SQLiteDatabase method loadPrimaryKeys.
@Override
protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
for (String tableName : create().select(SQLiteMaster.NAME).from(SQLITE_MASTER).where(SQLiteMaster.TYPE.in("table")).orderBy(SQLiteMaster.NAME).fetch(SQLiteMaster.NAME)) {
for (Record record : create().fetch("pragma table_info('" + tableName + "')")) {
if (record.get("pk", int.class) > 0) {
String columnName = record.get("name", String.class);
// Generate a primary key name
String key = "pk_" + tableName;
TableDefinition table = getTable(getSchemata().get(0), tableName);
if (table != null) {
ColumnDefinition column = table.getColumn(columnName);
relations.addPrimaryKey(key, column);
}
}
}
}
}
Aggregations