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;
}
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);
}
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;
}
Aggregations