Search in sources :

Example 11 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Columns

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Columns in project jaxdb by jaxdb.

the class DerbyDecompiler method getUniqueConstraints.

@Override
@SuppressWarnings("null")
Map<String, List<$Table.Constraints.Unique>> getUniqueConstraints(final Connection connection) throws SQLException {
    final Map<String, List<String>> tableNameToColumns = getTables(connection);
    final PreparedStatement statement = connection.prepareStatement(constraintsSql);
    final ResultSet rows = statement.executeQuery();
    final Map<String, List<$Table.Constraints.Unique>> tableNameToUniques = new HashMap<>();
    String lastTable = null;
    List<$Table.Constraints.Unique> uniques = null;
    while (rows.next()) {
        final String tableName = rows.getString(2);
        if (!tableName.equals(lastTable)) {
            lastTable = tableName;
            tableNameToUniques.put(tableName, uniques = new ArrayList<>());
        }
        final List<String> columns = tableNameToColumns.get(tableName);
        final String descriptor = rows.getString(3);
        final int close = descriptor.lastIndexOf(')');
        final int open = descriptor.lastIndexOf('(', close - 1);
        final String[] colRefs = descriptor.substring(open + 1, close).split(",");
        final $Table.Constraints.Unique unique = new $Table.Constraints.Unique();
        uniques.add(unique);
        for (int i = 0; i < colRefs.length; ++i) {
            colRefs[i] = columns.get(Integer.valueOf(colRefs[i].trim()) - 1);
            final $Table.Constraints.Unique.Column column = new $Table.Constraints.Unique.Column();
            column.setName$(new $Table.Constraints.Unique.Column.Name$(colRefs[i].toLowerCase()));
            unique.addColumn(column);
        }
    }
    return tableNameToUniques;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) 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) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Columns

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Columns in project jaxdb by jaxdb.

the class Generator method registerColumns.

private static void registerColumns(final $Table table, final Set<? super String> tableNames, final Map<? super String, ColumnRef> columnNameToColumn) throws GeneratorExecutionException {
    final String tableName = table.getName$().text();
    final List<String> violations = new ArrayList<>();
    String nameViolation = checkNameViolation(tableName);
    if (nameViolation != null)
        violations.add(nameViolation);
    if (tableNames.contains(tableName))
        throw new GeneratorExecutionException("Circular table dependency detected: " + tableName);
    tableNames.add(tableName);
    final List<$Column> columns = table.getColumn();
    if (columns != null) {
        for (int c = 0, len = columns.size(); c < len; ++c) {
            final $Column column = columns.get(c);
            final String columnName = column.getName$().text();
            nameViolation = checkNameViolation(columnName);
            if (nameViolation != null)
                violations.add(nameViolation);
            final ColumnRef existing = columnNameToColumn.get(columnName);
            if (existing != null)
                throw new GeneratorExecutionException("Duplicate column definition: " + tableName + "." + columnName);
            columnNameToColumn.put(columnName, new ColumnRef(column, c));
        }
    }
    if (violations.size() > 0)
        violations.forEach(logger::warn);
}
Also used : ArrayList(java.util.ArrayList) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Example 13 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Columns

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Columns in project jaxdb by jaxdb.

the class Generator method getTypes.

private Type[] getTypes(final Table table, final Map<String, Table> tableNameToTable, final int depth, final Info info) throws GeneratorExecutionException {
    final List<$Column> columns = table.getColumn();
    final int size = columns == null ? 0 : columns.size();
    final Type[] types;
    if (table.getExtends$() == null) {
        types = new Type[depth + size];
        info.rootClassName = schemaClassName + "." + Identifiers.toClassCase(table.getName$().text());
    } else {
        types = getTypes(tableNameToTable.get(table.getExtends$().text()), tableNameToTable, depth + size, info);
    }
    if (columns != null) {
        final boolean isSuperTable = depth != 0;
        info.totalPrimaryCount.inc(getPrimaryColumnCount(table), isSuperTable);
        for (int c = 1; c <= size; ++c) {
            final $Column column = columns.get(size - c);
            final Type type = getType(table, column);
            if (org.jaxdb.ddlx.Generator.isAuto(column))
                info.totalAutoCount.inc(1, isSuperTable);
            if (type.keyForUpdate)
                info.totalKeyForUpdateCount.inc(1, isSuperTable);
            types[types.length - depth - c] = type;
        }
    }
    return types;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)

Aggregations

org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named)6 ArrayList (java.util.ArrayList)5 org.jaxdb.jsql.data (org.jaxdb.jsql.data)4 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char)3 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal)3 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double)3 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float)3 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int)3 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 GeneratorExecutionException (org.jaxdb.ddlx.GeneratorExecutionException)2 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)2 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob)2 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean)2