Search in sources :

Example 11 with Column$

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

the class OracleCompiler method triggers.

@Override
List<CreateStatement> triggers(final $Table table) {
    final List<CreateStatement> statements = new ArrayList<>();
    if (table.getColumn() != null) {
        for (final $Column column : table.getColumn()) {
            if (column instanceof $Integer) {
                final $Integer type = ($Integer) column;
                if (Generator.isAuto(type)) {
                    final String sequenceName = getSequenceName(table, type);
                    final String columnName = q(column.getName$().text());
                    statements.add(0, new CreateStatement("CREATE TRIGGER " + q(getTriggerName(table, type)) + " BEFORE INSERT ON " + q(table.getName$().text()) + " FOR EACH ROW WHEN (new." + columnName + " IS NULL) BEGIN SELECT " + q(sequenceName) + ".NEXTVAL INTO " + ":new." + columnName + " FROM dual; END;"));
                }
            }
        }
    }
    statements.addAll(super.triggers(table));
    return statements;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) ArrayList(java.util.ArrayList) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Example 12 with Column$

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

the class OracleCompiler method types.

@Override
List<CreateStatement> types(final $Table table, final Map<String, Map<String, String>> tableNameToEnumToOwner) {
    final List<CreateStatement> statements = new ArrayList<>();
    if (table.getColumn() != null) {
        for (final $Column column : table.getColumn()) {
            if (column instanceof $Integer) {
                final $Integer integer = ($Integer) column;
                if (Generator.isAuto(integer)) {
                    final StringBuilder builder = new StringBuilder();
                    builder.append("CREATE SEQUENCE ").append(q(getSequenceName(table, integer)));
                    builder.append(" INCREMENT BY 1");
                    final String startWith = getAttr("default", integer);
                    if (startWith != null)
                        builder.append(" START WITH ").append(startWith);
                    final String max = getAttr("max", integer);
                    final Byte precision;
                    builder.append(" MAXVALUE ");
                    builder.append(max != null ? max : (precision = getPrecision(integer)) != null ? FastMath.longE10[precision] : Long.MAX_VALUE);
                    String min = getAttr("min", integer);
                    if (min == null)
                        min = startWith;
                    if (min != null)
                        builder.append(" MINVALUE ").append(min);
                    else
                        builder.append(" NOMINVALUE ");
                    builder.append(" CYCLE NOCACHE");
                    statements.add(0, new CreateStatement(builder.toString()));
                }
            }
        }
    }
    statements.addAll(super.types(table, tableNameToEnumToOwner));
    return statements;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) ArrayList(java.util.ArrayList) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Example 13 with Column$

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

the class PostgreSQLCompiler method types.

@Override
List<CreateStatement> types(final $Table table, final Map<String, Map<String, String>> tableNameToEnumToOwner) {
    final List<CreateStatement> statements = new ArrayList<>();
    if (table.getColumn() != null) {
        StringBuilder sql = null;
        for (final $Column column : table.getColumn()) {
            if (column instanceof $Enum) {
                final $Enum type = ($Enum) column;
                if (sql == null)
                    sql = new StringBuilder();
                else
                    sql.setLength(0);
                sql.append("CREATE TYPE ").append(q(Dialect.getTypeName(type, tableNameToEnumToOwner))).append(" AS ENUM (");
                if (type.getValues$() != null) {
                    final List<String> enums = Dialect.parseEnum(type.getValues$().text());
                    final Iterator<String> iterator = enums.iterator();
                    for (int i = 0; iterator.hasNext(); ++i) {
                        if (i > 0)
                            sql.append(", ");
                        sql.append('\'').append(iterator.next()).append('\'');
                    }
                }
                statements.add(0, new CreateStatement(sql.append(')').toString()));
            } else if (column instanceof $Integer) {
                final $Integer integer = ($Integer) column;
                if (Generator.isAuto(integer)) {
                    final StringBuilder builder = new StringBuilder("CREATE SEQUENCE " + q(getSequenceName(table, integer)));
                    final String min = getAttr("min", integer);
                    if (min != null)
                        builder.append(" MINVALUE ").append(min);
                    final String max = getAttr("max", integer);
                    if (max != null)
                        builder.append(" MAXVALUE ").append(max);
                    final String _default = getAttr("default", integer);
                    if (_default != null)
                        builder.append(" START ").append(_default);
                    builder.append(" CYCLE");
                    statements.add(0, new CreateStatement(builder.toString()));
                }
            }
        }
    }
    statements.addAll(super.types(table, tableNameToEnumToOwner));
    return statements;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) ArrayList(java.util.ArrayList) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)

Example 14 with Column$

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$ForeignKeyUnary.Column$ 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 15 with Column$

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

the class DerbyDecompiler method makeCheck.

// TODO: This only supports single-column constraints
private static $CheckReference makeCheck(final String checkDefinition) {
    final String[] terms = checkDefinition.substring(1, checkDefinition.length() - 1).split(" ");
    $CheckReference check = null;
    $CheckReference previousCheck = null;
    for (int i = 0; i < terms.length; i += 3) {
        final $CheckReference nextCheck = makeCheck(i == 0 ? null : terms[i++], Strings.trim(terms[i], '"'), terms[i + 1], terms[i + 2]);
        if (previousCheck == null)
            check = previousCheck = nextCheck;
        else {
            if (nextCheck instanceof $Table.Constraints.Check.And)
                previousCheck.setAnd(nextCheck);
            else if (nextCheck instanceof $Table.Constraints.Check.Or)
                previousCheck.setOr(nextCheck);
            else
                throw new UnsupportedOperationException("Unsupported check type: " + nextCheck.getClass().getName());
            previousCheck = nextCheck;
        }
    }
    return check;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Check(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Check) 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.$CheckReference(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$CheckReference)

Aggregations

org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)21 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)16 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)16 ArrayList (java.util.ArrayList)13 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)13 HashMap (java.util.HashMap)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named)7 ResultSet (java.sql.ResultSet)6 List (java.util.List)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob)6