Search in sources :

Example 21 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column

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;
    }
}
Also used : OnUpdate$(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKey.OnUpdate$) HashMap(java.util.HashMap) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary) DatabaseMetaData(java.sql.DatabaseMetaData) References$(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKey.References$) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ChangeRule(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ChangeRule) ResultSet(java.sql.ResultSet) OnDelete$(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKey.OnDelete$) Column$(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary.Column$) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 22 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column

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;
}
Also used : HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$CheckReference(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$CheckReference)

Example 23 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column

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;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint) BigDecimal(java.math.BigDecimal) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)

Example 24 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$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;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) ArrayList(java.util.ArrayList) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Example 25 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column

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;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) ArrayList(java.util.ArrayList) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Aggregations

org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)21 ArrayList (java.util.ArrayList)19 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)16 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)16 HashMap (java.util.HashMap)14 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)13 List (java.util.List)11 Column (org.molgenis.emx2.Column)11 Column (com.google.bigtable.v2.Column)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)9 Family (com.google.bigtable.v2.Family)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)8 Test (org.junit.Test)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named)7