use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project jaxdb by jaxdb.
the class Decompiler method getForeignKeys.
@SuppressWarnings("null")
// FIXME: This does not support composite foreign keys
Map<String, Map<String, $ForeignKeyUnary>> getForeignKeys(final Connection connection) throws SQLException {
final DatabaseMetaData metaData = connection.getMetaData();
try (final ResultSet foreignKeyRows = metaData.getImportedKeys(null, null, null)) {
final Map<String, Map<String, $ForeignKeyUnary>> tableNameToForeignKeys = new HashMap<>();
String lastTable = null;
Map<String, $ForeignKeyUnary> columnNameToForeignKey = null;
while (foreignKeyRows.next()) {
final String tableName = foreignKeyRows.getString("FKTABLE_NAME").toLowerCase();
if (!tableName.equals(lastTable)) {
lastTable = tableName;
tableNameToForeignKeys.put(tableName, columnNameToForeignKey = new HashMap<>());
}
final String primaryTable = foreignKeyRows.getString("PKTABLE_NAME").toLowerCase();
final String primaryColumn = foreignKeyRows.getString("PKCOLUMN_NAME").toLowerCase();
final String columnName = foreignKeyRows.getString("FKCOLUMN_NAME").toLowerCase();
final short updateRule = foreignKeyRows.getShort("UPDATE_RULE");
final short deleteRule = foreignKeyRows.getShort("DELETE_RULE");
final $ForeignKeyUnary foreignKey = new $Column.ForeignKey();
foreignKey.setReferences$(new References$(primaryTable));
foreignKey.setColumn$(new Column$(primaryColumn));
final $ChangeRule.Enum onUpdate = toBinding(updateRule);
if (onUpdate != null)
foreignKey.setOnUpdate$(new OnUpdate$(onUpdate));
final $ChangeRule.Enum onDelete = toBinding(deleteRule);
if (onDelete != null)
foreignKey.setOnDelete$(new OnDelete$(onDelete));
columnNameToForeignKey.put(columnName, foreignKey);
}
return tableNameToForeignKeys;
}
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project jaxdb by jaxdb.
the class DerbyDecompiler method getCheckConstraints.
@Override
@SuppressWarnings("null")
Map<String, List<$CheckReference>> getCheckConstraints(final Connection connection) throws SQLException {
final PreparedStatement statement = connection.prepareStatement(checkSql);
final ResultSet rows = statement.executeQuery();
final Map<String, List<$CheckReference>> tableNameToChecks = new HashMap<>();
String lastTable = null;
List<$CheckReference> checks = null;
while (rows.next()) {
final String tableName = rows.getString(2);
if (!tableName.equals(lastTable)) {
lastTable = tableName;
tableNameToChecks.put(tableName, checks = new ArrayList<>());
}
final String checkDefinition = rows.getString(3);
final String referencedColumns = rows.getString(4);
if (referencedColumns.contains(","))
throw new UnsupportedOperationException("Only support single-column check constraints");
checks.add(makeCheck(checkDefinition));
}
return tableNameToChecks;
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project jaxdb by jaxdb.
the class DerbyDecompiler method makeColumn.
@Override
$Column makeColumn(final String columnName, final String typeName, final long size, final int decimalDigits, final String _default, final Boolean nullable, final Boolean autoIncrement) {
final $Column column;
if ("BIGINT".equals(typeName)) {
final $Bigint type = newColumn($Bigint.class);
// type.setPrecision$(new $Bigint.Precision$((byte)size));
if (_default != null && !"GENERATED_BY_DEFAULT".equals(_default))
type.setDefault$(new $Bigint.Default$(Long.valueOf(getDefault(_default))));
if (autoIncrement != null && autoIncrement)
type.setGenerateOnInsert$(new $Bigint.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
column = type;
} else if ("CHAR () FOR BIT DATA".equals(typeName) || "VARCHAR () FOR BIT DATA".equals(typeName)) {
final $Binary type = newColumn($Binary.class);
if (typeName.startsWith("VARCHAR"))
type.setVarying$(new $Binary.Varying$(true));
type.setLength$(new $Binary.Length$(size));
column = type;
} else if ("BLOB".equals(typeName)) {
final $Blob type = newColumn($Blob.class);
type.setLength$(new $Blob.Length$(size));
column = type;
} else if ("BOOLEAN".equals(typeName)) {
final $Boolean type = newColumn($Boolean.class);
if (_default != null)
type.setDefault$(new $Boolean.Default$(Boolean.valueOf(_default)));
column = type;
} else if ("VARCHAR".equals(typeName) || "CHAR".equals(typeName)) {
final $Char type = newColumn($Char.class);
if ("VARCHAR".equals(typeName))
type.setVarying$(new $Char.Varying$(true));
type.setLength$(new $Char.Length$(size));
if (_default != null)
type.setDefault$(new $Char.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else if ("CLOB".equals(typeName)) {
final $Clob type = newColumn($Clob.class);
type.setLength$(new $Clob.Length$(size));
column = type;
} else if ("DATE".equals(typeName)) {
final $Date type = newColumn($Date.class);
if (_default != null)
type.setDefault$(new $Date.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else if ("TIMESTAMP".equals(typeName)) {
final $Datetime type = newColumn($Datetime.class);
// type.setPrecision$(new $Datetime.Precision$((byte)size));
if (_default != null)
type.setDefault$(new $Datetime.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else if ("DECIMAL".equals(typeName)) {
final int precision = (int) size;
final $Decimal type = newColumn($Decimal.class);
type.setPrecision$(new $Decimal.Precision$(precision));
type.setScale$(new $Decimal.Scale$(decimalDigits));
if (_default != null)
type.setDefault$(new $Decimal.Default$(new BigDecimal(_default)));
column = type;
} else if ("DOUBLE".equals(typeName)) {
final $Double type = newColumn($Double.class);
if (_default != null)
type.setDefault$(new $Double.Default$(Double.valueOf(_default)));
column = type;
} else // }
if ("FLOAT".equals(typeName)) {
final $Float type = newColumn($Float.class);
if (_default != null)
type.setDefault$(new $Float.Default$(Float.valueOf(_default)));
column = type;
} else if ("INTEGER".equals(typeName)) {
final $Int type = newColumn($Int.class);
type.setPrecision$(new $Int.Precision$((byte) size));
if (_default != null && !"GENERATED_BY_DEFAULT".equals(_default))
type.setDefault$(new $Int.Default$(Integer.valueOf(getDefault(_default))));
if (autoIncrement != null && autoIncrement)
type.setGenerateOnInsert$(new $Int.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
column = type;
} else if ("SMALLINT".equals(typeName)) {
final $Smallint type = newColumn($Smallint.class);
type.setPrecision$(new $Smallint.Precision$((byte) size));
if (_default != null && !"GENERATED_BY_DEFAULT".equals(_default))
type.setDefault$(new $Smallint.Default$(Short.valueOf(getDefault(_default))));
if (autoIncrement != null && autoIncrement)
type.setGenerateOnInsert$(new $Smallint.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
column = type;
} else if ("TIME".equals(typeName)) {
final $Time type = newColumn($Time.class);
type.setPrecision$(new $Time.Precision$((byte) size));
if (_default != null)
type.setDefault$(new $Time.Default$(_default.substring(1, _default.length() - 1)));
column = type;
} else // else if ("TINYINT".equals(typeName)) {
// final $Tinyint type = newColumn($Tinyint.class);
// type.setPrecision$(new $Tinyint.Precision$((byte)size));
// if (_default != null && !"GENERATED_BY_DEFAULT".equals(_default))
// type.setDefault$(new $Tinyint.setDefault$(new BigInteger(getDefault(_default))));
//
// if (autoIncrement != null && autoIncrement)
// type.GenerateOnInsert$(new $Integer.GenerateOnInsert$($Integer.GenerateOnInsert$.AUTO_5FINCREMENT));
//
// column = type;
// }
{
throw new UnsupportedOperationException("Unsupported column type: " + typeName);
}
column.setName$(new $Column.Name$(columnName));
if (nullable != null && !nullable)
column.setNull$(new $Column.Null$(false));
return column;
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project jaxdb by jaxdb.
the class OracleCompiler method triggers.
@Override
List<CreateStatement> triggers(final $Table table) {
final List<CreateStatement> statements = new ArrayList<>();
if (table.getColumn() != null) {
for (final $Column column : table.getColumn()) {
if (column instanceof $Integer) {
final $Integer type = ($Integer) column;
if (Generator.isAuto(type)) {
final String sequenceName = getSequenceName(table, type);
final String columnName = q(column.getName$().text());
statements.add(0, new CreateStatement("CREATE TRIGGER " + q(getTriggerName(table, type)) + " BEFORE INSERT ON " + q(table.getName$().text()) + " FOR EACH ROW WHEN (new." + columnName + " IS NULL) BEGIN SELECT " + q(sequenceName) + ".NEXTVAL INTO " + ":new." + columnName + " FROM dual; END;"));
}
}
}
}
statements.addAll(super.triggers(table));
return statements;
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column in project jaxdb by jaxdb.
the class OracleCompiler method types.
@Override
List<CreateStatement> types(final $Table table, final Map<String, Map<String, String>> tableNameToEnumToOwner) {
final List<CreateStatement> statements = new ArrayList<>();
if (table.getColumn() != null) {
for (final $Column column : table.getColumn()) {
if (column instanceof $Integer) {
final $Integer integer = ($Integer) column;
if (Generator.isAuto(integer)) {
final StringBuilder builder = new StringBuilder();
builder.append("CREATE SEQUENCE ").append(q(getSequenceName(table, integer)));
builder.append(" INCREMENT BY 1");
final String startWith = getAttr("default", integer);
if (startWith != null)
builder.append(" START WITH ").append(startWith);
final String max = getAttr("max", integer);
final Byte precision;
builder.append(" MAXVALUE ");
builder.append(max != null ? max : (precision = getPrecision(integer)) != null ? FastMath.longE10[precision] : Long.MAX_VALUE);
String min = getAttr("min", integer);
if (min == null)
min = startWith;
if (min != null)
builder.append(" MINVALUE ").append(min);
else
builder.append(" NOMINVALUE ");
builder.append(" CYCLE NOCACHE");
statements.add(0, new CreateStatement(builder.toString()));
}
}
}
}
statements.addAll(super.types(table, tableNameToEnumToOwner));
return statements;
}
Aggregations