use of org.jaxdb.ddlx.Generator.ColumnRef in project jaxdb by jaxdb.
the class Compiler method blockPrimaryKey.
String blockPrimaryKey(final $Table table, final $Constraints constraints, final Map<String, ColumnRef> columnNameToColumn) throws GeneratorExecutionException {
if (constraints.getPrimaryKey() == null)
return "";
final StringBuilder builder = new StringBuilder();
final List<$Named> columns = constraints.getPrimaryKey().getColumn();
final PrimaryKey.Using$ using = constraints.getPrimaryKey().getUsing$();
final int[] columnIndexes = new int[columns.size()];
final Iterator<$Named> iterator = columns.iterator();
for (int i = 0; iterator.hasNext(); ++i) {
final $Named primaryColumn = iterator.next();
final String primaryKeyColumn = primaryColumn.getName$().text();
final ColumnRef ref = columnNameToColumn.get(primaryKeyColumn);
if (ref == null)
throw new GeneratorExecutionException("PRIMARY KEY column " + table.getName$().text() + "." + primaryKeyColumn + " is not defined");
if (ref.column.getNull$() == null || ref.column.getNull$().text())
throw new GeneratorExecutionException("Column " + ref.column.getName$() + " must be NOT NULL to be a PRIMARY KEY");
if (i > 0)
builder.append(", ");
builder.append(q(primaryKeyColumn));
columnIndexes[i] = ref.index;
}
return ",\n " + primaryKey(table, columnIndexes, using) + " (" + builder + ")";
}
Aggregations