Search in sources :

Example 1 with PrimaryKey

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

the class SQLiteCompiler method $autoIncrement.

@Override
String $autoIncrement(final LinkedHashSet<CreateStatement> alterStatements, final $Table table, final $Integer column) {
    if (!Generator.isAuto(column))
        return null;
    final $Columns primaryKey;
    if (table.getConstraints() == null || (primaryKey = table.getConstraints().getPrimaryKey()) == null) {
        if (logger.isWarnEnabled())
            logger.warn("AUTO_INCREMENT is only allowed on an INT PRIMARY KEY -- Ignoring AUTO_INCREMENT spec.");
        return null;
    }
    if (primaryKey.getColumn().size() > 1) {
        if (logger.isWarnEnabled())
            logger.warn("AUTO_INCREMENT is not allowed for tables with composite primary keys -- Ignoring AUTO_INCREMENT spec.");
        return null;
    }
    for (final $Named primaryColumn : primaryKey.getColumn()) {
        if (primaryColumn.getName$().text().equals(column.getName$().text())) {
            final String min = getAttr("min", column);
            if (min != null && logger.isWarnEnabled())
                logger.warn("AUTO_INCREMENT does not consider min=\"" + min + "\" -- Ignoring min spec.");
            final String max = getAttr("max", column);
            if (max != null && logger.isWarnEnabled())
                logger.warn("AUTO_INCREMENT does not consider max=\"" + max + "\" -- Ignoring max spec.");
            final String _default = getAttr("default", column);
            if (_default != null && logger.isWarnEnabled())
                logger.warn("AUTO_INCREMENT does not consider default=\"" + _default + "\" -- Ignoring default spec.");
            return "PRIMARY KEY";
        }
    }
    if (logger.isWarnEnabled())
        logger.warn("AUTO_INCREMENT is only allowed on an INT PRIMARY KEY -- Ignoring AUTO_INCREMENT spec.");
    return null;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Columns(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Columns)

Example 2 with PrimaryKey

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Constraints.PrimaryKey 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

org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named)2 ColumnRef (org.jaxdb.ddlx.Generator.ColumnRef)1 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)1 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Columns (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Columns)1 PrimaryKey (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Constraints.PrimaryKey)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