Package org.hsqldb_voltpatches.lib

Examples of org.hsqldb_voltpatches.lib.HsqlArrayList


    }

    //
    void startRecording() {

        recordedStatement = new HsqlArrayList();

        recordedStatement.add(token.duplicate());

        isRecording = true;
    }
View Full Code Here


                       || c.getConstraintType() == Constraint.PRIMARY_KEY) {
                resolved.add(c.getName());
            }
        }

        HsqlArrayList list = new HsqlArrayList();

        list.add(getSQL());

        // readonly for TEXT tables only
        if (isText()) {
            if (((TextTable) this).isConnected() && isDataReadOnly()) {
                StringBuffer sb = new StringBuffer(64);

                sb.append(Tokens.T_SET).append(' ').append(
                    Tokens.T_TABLE).append(' ');
                sb.append(getName().getSchemaQualifiedStatementName());
                sb.append(' ').append(Tokens.T_READONLY).append(' ');
                sb.append(Tokens.T_TRUE);
                list.add(sb.toString());
            }

            // data source
            String dataSource = ((TextTable) this).getDataSourceDDL();

            if (dataSource != null) {
                list.add(dataSource);
            }

            // header
            String header = ((TextTable) this).getDataSourceHeader();

            if (header != null) {
                list.add(header);
            }
        }

        if (!isTemp && hasIdentityColumn()) {
            list.add(NumberSequence.getRestartSQL(this));
        }

        for (int i = 0; i < indexList.length; i++) {
            if (!indexList[i].isConstraint()) {
                list.add(indexList[i].getSQL());
            }
        }

        String[] array = new String[list.size()];

        list.toArray(array);

        return array;
    }
View Full Code Here

        if (index != null) {
            tn.addIndex(index);
        }

        HsqlArrayList newList = new HsqlArrayList();

        if (newPK) {
            constraint.core.mainIndex     = tn.indexList[0];
            constraint.core.mainTable     = tn;
            constraint.core.mainTableName = tn.tableName;

            newList.add(constraint);
        }

        for (int i = 0; i < constraintList.length; i++) {
            Constraint c = constraintList[i];

            if (dropConstraints.contains(c.getName())) {
                continue;
            }

            c = c.duplicate();

            c.updateTable(session, this, tn, colIndex, adjust);
            newList.add(c);
        }

        if (!newPK && constraint != null) {
            constraint.updateTable(session, this, tn, -1, 0);
            newList.add(constraint);
        }

        tn.constraintList = new Constraint[newList.size()];

        newList.toArray(tn.constraintList);
        tn.updateConstraintLists();
        tn.setBestRowIdentifiers();

        tn.triggerList  = triggerList;
        tn.triggerLists = triggerLists;
View Full Code Here

        }
    }

    public String[] getSettingsSQL() {

        HsqlArrayList list = new HsqlArrayList();

        if (!getCatalogName().name.equals(
                HsqlNameManager.DEFAULT_CATALOG_NAME)) {
            String name = getCatalogName().statementName;

            list.add("ALTER CATALOG PUBLIC RENAME TO " + name);
        }

        if (collation.name != null) {
            String name = collation.getName().statementName;

            list.add("SET DATABASE COLLATION " + name);
        }

        String[] array = new String[list.size()];

        list.toArray(array);

        return array;
    }
View Full Code Here

        return array;
    }

    public String[] getPropertiesSQL() {

        HsqlArrayList list = new HsqlArrayList();

        if (schemaManager.getDefaultTableType() == TableBase.CACHED_TABLE) {
            list.add("SET DATABASE DEFAULT TABLE TYPE CACHED");
        }

        if (logger.hasLog()) {
            int     delay  = logger.getWriteDelay();
            boolean millis = delay < 1000;

            if (millis) {
                if (delay != 0 && delay < 20) {
                    delay = 20;
                }
            } else {
                delay /= 1000;
            }

            list.add("SET WRITE_DELAY " + delay + (millis ? " MILLIS"
                                                          : ""));
        }

        String[] array = new String[list.size()];

        list.toArray(array);

        return array;
    }
View Full Code Here

        return r;
    }

    Expression XreadInValueList(int degree) {

        HsqlArrayList list = new HsqlArrayList();

        while (true) {
            Expression e = XreadValueExpression();

            if (e.getType() != OpTypes.ROW) {
                e = new Expression(OpTypes.ROW, new Expression[]{ e });
            }

            list.add(e);

            if (token.tokenType == Tokens.COMMA) {
                read();

                continue;
            }

            break;
        }

        Expression[] array = new Expression[list.size()];

        list.toArray(array);

        Expression e = new Expression(OpTypes.TABLE, array);

        for (int i = 0; i < array.length; i++) {
            if (array[i].getType() != OpTypes.ROW) {
View Full Code Here

        throw unexpectedToken();
    }

    HsqlArrayList compileStatements(String sql, int returnType) {

        HsqlArrayList list = new HsqlArrayList();
        Statement     cs   = null;

        reset(sql);

        while (true) {
            if (token.tokenType == Tokens.X_ENDPARSE) {
                break;
            }

            compileContext.reset();

            cs = compilePart();

            if (cs == null) {
                list.add(cs);
            } else {
                list.add(cs);
            }
        }

        if (returnType != StatementTypes.RETURN_ANY) {
            int group = cs.getGroup();
View Full Code Here

    }

    StatementSchema compileCreateTable(int type) {

        HsqlName name = readNewSchemaObjectNameNoCheck(SchemaObject.TABLE);
        HsqlArrayList tempConstraints = new HsqlArrayList();

        name.setSchemaIfNull(session.getCurrentSchemaHsqlName());

        Table table = TableUtil.newTable(database, type, name);

        if (token.tokenType == Tokens.AS) {
            return readTableAsSubqueryDefinition(table);
        }

        int position = getPosition();

        readThis(Tokens.OPENBRACKET);

        {
            Constraint c = new Constraint(null, null, Constraint.TEMP);

            tempConstraints.add(c);
        }

        boolean start     = true;
        boolean startPart = true;
        boolean end       = false;
View Full Code Here

        userTypeModifier.setDefaultClause(defaultClause);

        type.userTypeModifier = userTypeModifier;

        HsqlArrayList tempConstraints = new HsqlArrayList();

        compileContext.currentDomain = type;

        while (true) {
            boolean end = false;

            switch (token.tokenType) {

                case Tokens.CONSTRAINT :
                case Tokens.CHECK :
                    readConstraint(type, tempConstraints);
                    break;

                default :
                    end = true;
                    break;
            }

            if (end) {
                break;
            }
        }

        compileContext.currentDomain = null;

        for (int i = 0; i < tempConstraints.size(); i++) {
            Constraint c = (Constraint) tempConstraints.get(i);

            c.prepareCheckConstraint(session, null, false);
            userTypeModifier.addConstraint(c);
        }
View Full Code Here

        String          newTableName       = null;
        String          oldRowName         = null;
        String          newRowName         = null;
        Table[]         transitions        = new Table[4];
        RangeVariable[] rangeVars          = new RangeVariable[4];
        HsqlArrayList   compiledStatements = new HsqlArrayList();
        String          conditionSQL       = null;
        String          procedureSQL       = null;

        if (token.tokenType == Tokens.REFERENCING) {
            read();

            if (token.tokenType != Tokens.OLD
                    && token.tokenType != Tokens.NEW) {
                throw unexpectedToken();
            }

            while (true) {
                if (token.tokenType == Tokens.OLD) {
                    if (operationType == Tokens.INSERT) {
                        throw unexpectedToken();
                    }

                    read();

                    if (token.tokenType == Tokens.TABLE) {
                        if (oldTableName != null
                                || beforeOrAfterType == Tokens.BEFORE) {
                            throw unexpectedToken();
                        }

                        read();
                        readIfThis(Tokens.AS);
                        checkIsSimpleName();

                        oldTableName = token.tokenString;

                        String n = oldTableName;

                        if (n.equals(newTableName) || n.equals(oldRowName)
                                || n.equals(newRowName)) {
                            throw unexpectedToken();
                        }

                        HsqlName hsqlName = database.nameManager.newHsqlName(
                            table.getSchemaName(), n, isDelimitedIdentifier(),
                            SchemaObject.TRANSITION);
                        Table transition = new Table(table, hsqlName);
                        RangeVariable range = new RangeVariable(transition,
                            null, null, null, compileContext);

                        transitions[TriggerDef.OLD_TABLE] = transition;
                        rangeVars[TriggerDef.OLD_TABLE]   = range;
                    } else if (token.tokenType == Tokens.ROW) {
                        if (oldRowName != null) {
                            throw unexpectedToken();
                        }

                        read();
                        readIfThis(Tokens.AS);
                        checkIsSimpleName();

                        oldRowName = token.tokenString;

                        String n = oldRowName;

                        if (n.equals(newTableName) || n.equals(oldTableName)
                                || n.equals(newRowName)) {
                            throw unexpectedToken();
                        }

                        isForEachRow = true;

                        HsqlName hsqlName = database.nameManager.newHsqlName(
                            table.getSchemaName(), n, isDelimitedIdentifier(),
                            SchemaObject.TRANSITION);
                        Table transition = new Table(table, hsqlName);
                        RangeVariable range = new RangeVariable(transition,
                            null, null, null, compileContext);

                        transitions[TriggerDef.OLD_ROW] = transition;
                        rangeVars[TriggerDef.OLD_ROW]   = range;
                    } else {
                        throw unexpectedToken();
                    }
                } else if (token.tokenType == Tokens.NEW) {
                    if (operationType == Tokens.DELETE) {
                        throw unexpectedToken();
                    }

                    read();

                    if (token.tokenType == Tokens.TABLE) {
                        if (newTableName != null
                                || beforeOrAfterType == Tokens.BEFORE) {
                            throw unexpectedToken();
                        }

                        read();
                        readIfThis(Tokens.AS);
                        checkIsSimpleName();

                        newTableName = token.tokenString;

                        String n = newTableName;

                        if (n.equals(oldTableName) || n.equals(oldRowName)
                                || n.equals(newRowName)) {
                            throw unexpectedToken();
                        }

                        HsqlName hsqlName = database.nameManager.newHsqlName(
                            table.getSchemaName(), n, isDelimitedIdentifier(),
                            SchemaObject.TRANSITION);
                        Table transition = new Table(table, hsqlName);
                        RangeVariable range = new RangeVariable(transition,
                            null, null, null, compileContext);

                        transitions[TriggerDef.NEW_TABLE] = transition;
                        rangeVars[TriggerDef.NEW_TABLE]   = range;
                    } else if (token.tokenType == Tokens.ROW) {
                        if (newRowName != null) {
                            throw unexpectedToken();
                        }

                        read();
                        readIfThis(Tokens.AS);
                        checkIsSimpleName();

                        newRowName   = token.tokenString;
                        isForEachRow = true;

                        String n = newRowName;

                        if (n.equals(oldTableName) || n.equals(newTableName)
                                || n.equals(oldRowName)) {
                            throw unexpectedToken();
                        }

                        HsqlName hsqlName = database.nameManager.newHsqlName(
                            table.getSchemaName(), n, isDelimitedIdentifier(),
                            SchemaObject.TRANSITION);
                        Table transition = new Table(table, hsqlName);
                        RangeVariable range = new RangeVariable(transition,
                            null, null, null, compileContext);

                        transitions[TriggerDef.NEW_ROW] = transition;
                        rangeVars[TriggerDef.NEW_ROW]   = range;
                    } else {
                        throw unexpectedToken();
                    }
                } else {
                    break;
                }

                read();
            }
        }

        if (isForEachRow && token.tokenType != Tokens.FOR) {
            throw unexpectedToken();
        }

        // "FOR EACH ROW" or "CALL"
        if (token.tokenType == Tokens.FOR) {
            read();
            readThis(Tokens.EACH);

            if (token.tokenType == Tokens.ROW) {
                isForEachRow = true;
            } else if (token.tokenType == Tokens.STATEMENT) {
                if (isForEachRow) {
                    throw unexpectedToken();
                }
            } else {
                throw unexpectedToken();
            }

            read();
        }

        //
        if (rangeVars[TriggerDef.OLD_TABLE] != null) {}

        if (rangeVars[TriggerDef.NEW_TABLE] != null) {}

        //
        if (Tokens.T_NOWAIT.equals(token.tokenString)) {
            read();

            isNowait = true;
        } else if (Tokens.T_QUEUE.equals(token.tokenString)) {
            read();

            queueSize    = readInteger();
            hasQueueSize = true;
        }

        if (token.tokenType == Tokens.WHEN
                && beforeOrAfterType != Tokens.INSTEAD) {
            read();
            readThis(Tokens.OPENBRACKET);

            int position = getPosition();

            isCheckOrTriggerCondition = true;
            condition                 = XreadBooleanValueExpression();
            conditionSQL              = getLastPart(position);
            isCheckOrTriggerCondition = false;

            readThis(Tokens.CLOSEBRACKET);

            HsqlList unresolved = condition.resolveColumnReferences(rangeVars,
                null);

            ExpressionColumn.checkColumnsResolved(unresolved);
            condition.resolveTypes(session, null);

            if (condition.getDataType() != Type.SQL_BOOLEAN) {
                throw Error.error(ErrorCode.X_42568);
            }
        }

        if (token.tokenType == Tokens.CALL) {
            read();
            checkIsSimpleName();
            checkIsDelimitedIdentifier();

            className = token.tokenString;

            read();

            td = new TriggerDef(name, beforeOrAfter, operation, isForEachRow,
                                table, transitions, rangeVars, condition,
                                conditionSQL, updateColumnIndexes, className, isNowait,
                                queueSize);

            String   sql  = getLastPart();
            Object[] args = new Object[] {
                td, otherName
            };

            return new StatementSchema(sql, StatementTypes.CREATE_TRIGGER,
                                       args, null, table.getName());
        }

        //
        if (isNowait) {
            throw unexpectedToken(Tokens.T_NOWAIT);
        }

        if (hasQueueSize) {
            throw unexpectedToken(Tokens.T_QUEUE);
        }

        // procedure
        boolean isBlock = false;

        if (readIfThis(Tokens.BEGIN)) {
            readThis(Tokens.ATOMIC);

            isBlock = true;
        }

        int position = getPosition();

        while (true) {
            StatementDMQL cs = null;

            switch (token.tokenType) {

                case Tokens.INSERT :
                    if (beforeOrAfterType == Tokens.BEFORE) {
                        throw unexpectedToken();
                    }

                    cs = compileInsertStatement(rangeVars);

                    compiledStatements.add(cs);

                    if (isBlock) {
                        readThis(Tokens.SEMICOLON);
                    }
                    break;

                case Tokens.UPDATE :
                    if (beforeOrAfterType == Tokens.BEFORE) {
                        throw unexpectedToken();
                    }

                    cs = compileUpdateStatement(rangeVars);

                    compiledStatements.add(cs);

                    if (isBlock) {
                        readThis(Tokens.SEMICOLON);
                    }
                    break;

                case Tokens.DELETE :
                    if (beforeOrAfterType == Tokens.BEFORE) {
                        throw unexpectedToken();
                    }

                    cs = compileDeleteStatement(rangeVars);

                    compiledStatements.add(cs);

                    if (isBlock) {
                        readThis(Tokens.SEMICOLON);
                    }
                    break;

                case Tokens.MERGE :
                    if (beforeOrAfterType == Tokens.BEFORE) {
                        throw unexpectedToken();
                    }

                    cs = compileMergeStatement(rangeVars);

                    compiledStatements.add(cs);

                    if (isBlock) {
                        readThis(Tokens.SEMICOLON);
                    }
                    break;

                case Tokens.SET :
                    if (beforeOrAfterType != Tokens.BEFORE
                            || operationType == Tokens.DELETE) {
                        throw unexpectedToken();
                    }

                    cs = compileTriggerSetStatement(table, rangeVars);

                    compiledStatements.add(cs);

                    if (isBlock) {
                        readThis(Tokens.SEMICOLON);
                    }
                    break;

                case Tokens.END :
                    break;

                default :
                    throw unexpectedToken();
            }

            if (!isBlock || token.tokenType == Tokens.END) {
                break;
            }
        }

        procedureSQL = getLastPart(position);

        if (isBlock) {
            readThis(Tokens.END);
        }

        StatementDMQL[] csArray = new StatementDMQL[compiledStatements.size()];

        compiledStatements.toArray(csArray);

        OrderedHashSet references = compileContext.getSchemaObjectNames();

        for (int i = 0; i < csArray.length; i++) {
            Table     targetTable = csArray[i].targetTable;
View Full Code Here

TOP

Related Classes of org.hsqldb_voltpatches.lib.HsqlArrayList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.