Search in sources :

Example 1 with ColumnRef

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 + ")";
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named) PrimaryKey(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Constraints.PrimaryKey) ColumnRef(org.jaxdb.ddlx.Generator.ColumnRef) 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

ColumnRef (org.jaxdb.ddlx.Generator.ColumnRef)1 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)1 PrimaryKey (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Constraints.PrimaryKey)1 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named)1 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)1 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)1