Search in sources :

Example 96 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class Table method createPrimaryKey.

/**
     *  Creates a single or multi-column primary key and index. sets the
     *  colTypes array. Finalises the creation of the table. (fredt@users)
     */
public void createPrimaryKey(HsqlName indexName, int[] columns, boolean columnsNotNull) {
    if (primaryKeyCols != null) {
        throw Error.runtimeError(ErrorCode.U_S0500, "Table");
    }
    if (columns == null) {
        columns = ValuePool.emptyIntArray;
    } else {
        for (int i = 0; i < columns.length; i++) {
            getColumn(columns[i]).setPrimaryKey(true);
        }
    }
    primaryKeyCols = columns;
    setColumnStructures();
    primaryKeyTypes = new Type[primaryKeyCols.length];
    ArrayUtil.projectRow(colTypes, primaryKeyCols, primaryKeyTypes);
    primaryKeyColsSequence = new int[primaryKeyCols.length];
    ArrayUtil.fillSequence(primaryKeyColsSequence);
    HsqlName name = indexName;
    if (name == null) {
        name = database.nameManager.newAutoName("IDX", getSchemaName(), getName(), SchemaObject.INDEX);
    }
    createPrimaryIndex(primaryKeyCols, primaryKeyTypes, name);
    setBestRowIdentifiers();
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 97 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class TableWorks method addLimitConstraint.

/* addUniqueExprConstraint */
// A VoltDB extension to support LIMIT PARTITION ROWS
void addLimitConstraint(Constraint c) {
    // Find any pre-existing LIMIT constraint on the table and remove it
    for (Constraint cst : table.constraintList) {
        if (cst.getConstraintType() == Constraint.LIMIT) {
            OrderedHashSet constraintNameSet = new OrderedHashSet();
            HsqlName name = cst.getName();
            constraintNameSet.add(name);
            updateConstraints(table, constraintNameSet);
            database.schemaManager.removeSchemaObject(name);
            // Highlander rules for Constraint.LIMIT
            break;
        }
    }
    table.addConstraint(c);
    database.schemaManager.addSchemaObject(c);
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 98 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ScriptReaderText method readDDL.

protected void readDDL(Session session) throws IOException {
    for (; readLoggedStatement(session); ) {
        Statement cs = null;
        Result result = null;
        if (rowIn.getStatementType() == INSERT_STATEMENT) {
            isInsert = true;
            break;
        }
        try {
            cs = session.compileStatement(statement);
            result = session.executeCompiledStatement(cs, ValuePool.emptyObjectArray);
            if (cs.getType() == StatementTypes.CREATE_SCHEMA) {
                HsqlName name = cs.getSchemaName();
                session.setSchema(name.name);
            }
        } catch (HsqlException e) {
            result = Result.newErrorResult(e);
        }
        if (result.isError()) {
            // handle grants on math and library routines in old versions
            if (cs == null) {
            } else {
                if (cs.getType() == StatementTypes.GRANT) {
                    continue;
                }
            }
        //
        }
        if (result.isError()) {
            db.logger.appLog.logContext(SimpleLog.LOG_ERROR, result.getMainString());
            throw Error.error(ErrorCode.ERROR_IN_SCRIPT_FILE, ErrorCode.M_DatabaseScriptReader_readDDL, new Object[] { new Integer(lineCount), result.getMainString() });
        }
    }
}
Also used : Statement(org.hsqldb_voltpatches.Statement) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) HsqlException(org.hsqldb_voltpatches.HsqlException) Result(org.hsqldb_voltpatches.result.Result)

Example 99 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDQL method readColumnOrFunctionExpression.

/**
     * reads a Column or Function expression
     */
private Expression readColumnOrFunctionExpression() {
    String name = token.tokenString;
    boolean isSimpleQuoted = isDelimitedSimpleName();
    String prefix = token.namePrefix;
    String prePrefix = token.namePrePrefix;
    if (isUndelimitedSimpleName()) {
        // A VoltDB extension to augment the standard sql function set.
        FunctionSQL function;
        function = FunctionForVoltDB.newVoltDBFunction(name);
        if (function == null) {
            // These seem to be JDBC ("Open Group"?) aliases and extensions to the standard sql functions.
            function = FunctionCustom.newCustomFunction(token.tokenString, token.tokenType);
        }
        if (function != null) {
            int pos = getPosition();
            // A VoltDB extension to avoid abusing the exception handling mechanism
            // for normal flow control.
            HsqlException ex = null;
            try {
                ExpressionOrException result = readSQLFunction(function, false);
                ex = result.exception();
                if (ex == null) {
                    return result.knownGood();
                }
            } catch (HsqlException caught) {
                ex = caught;
            }
            if (ex != null) {
                /* disable 3 lines ...
                try {
                    return readSQLFunction(function);
                } catch (HsqlException ex) {
                ... disabled 3 lines */
                // End of VoltDB extension
                ex.setLevel(compileContext.subQueryDepth);
                if (lastError == null || lastError.getLevel() < ex.getLevel()) {
                    lastError = ex;
                }
                rewind(pos);
            }
        } else if (isReservedKey()) {
            function = FunctionSQL.newSQLFunction(name, compileContext);
            if (function != null) {
                // but get post-processed in the similar call above for FunctionForVoltDB and FunctionCustom
                return readSQLFunction(function);
            }
        }
    }
    read();
    if (token.tokenType != Tokens.OPENBRACKET) {
        Expression column = new ExpressionColumn(prePrefix, prefix, name);
        return column;
    }
    checkValidCatalogName(prePrefix);
    prefix = session.getSchemaName(prefix);
    RoutineSchema routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(name, prefix, SchemaObject.FUNCTION);
    if (routineSchema == null && isSimpleQuoted) {
        HsqlName schema = database.schemaManager.getDefaultSchemaHsqlName();
        routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(name, schema.name, SchemaObject.FUNCTION);
        if (routineSchema == null) {
            Method[] methods = Routine.getMethods(name);
            Routine[] routines = Routine.newRoutines(methods);
            HsqlName routineName = database.nameManager.newHsqlName(schema, name, true, SchemaObject.FUNCTION);
            for (int i = 0; i < routines.length; i++) {
                routines[i].setName(routineName);
                session.database.schemaManager.addSchemaObject(routines[i]);
            }
            routineSchema = (RoutineSchema) database.schemaManager.findSchemaObject(name, schema.name, SchemaObject.FUNCTION);
        }
    }
    if (routineSchema == null) {
        throw Error.error(ErrorCode.X_42501, name);
    }
    HsqlArrayList list = new HsqlArrayList();
    readThis(Tokens.OPENBRACKET);
    if (token.tokenType == Tokens.CLOSEBRACKET) {
        read();
    } else {
        while (true) {
            Expression e = XreadValueExpression();
            list.add(e);
            if (token.tokenType == Tokens.COMMA) {
                read();
            } else {
                readThis(Tokens.CLOSEBRACKET);
                break;
            }
        }
    }
    FunctionSQLInvoked function = new FunctionSQLInvoked(routineSchema);
    Expression[] arguments = new Expression[list.size()];
    list.toArray(arguments);
    function.setArguments(arguments);
    compileContext.addRoutine(function);
    return function;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) Method(java.lang.reflect.Method) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 100 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDQL method readNewSchemaObjectName.

HsqlName readNewSchemaObjectName(int type) {
    checkIsSchemaObjectName();
    HsqlName hsqlName = database.nameManager.newHsqlName(token.tokenString, isDelimitedIdentifier(), type);
    if (token.namePrefix != null) {
        if (type == SchemaObject.GRANTEE || type == SchemaObject.VARIABLE || type == SchemaObject.CATALOG) {
            throw unexpectedToken();
        }
        HsqlName schemaName = session.getSchemaHsqlName(token.namePrefix);
        hsqlName.setSchemaIfNull(schemaName);
    }
    read();
    return hsqlName;
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Aggregations

HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)204 Table (org.hsqldb_voltpatches.Table)86 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)73 TextTable (org.hsqldb_voltpatches.TextTable)65 Iterator (org.hsqldb_voltpatches.lib.Iterator)64 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)61 SchemaObject (org.hsqldb_voltpatches.SchemaObject)60 Constraint (org.hsqldb_voltpatches.Constraint)59 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)48 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)22 HsqlException (org.hsqldb_voltpatches.HsqlException)20 Type (org.hsqldb_voltpatches.types.Type)20 Session (org.hsqldb_voltpatches.Session)16 Result (org.hsqldb_voltpatches.result.Result)15 Grantee (org.hsqldb_voltpatches.rights.Grantee)12 NumberType (org.hsqldb_voltpatches.types.NumberType)10 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 Index (org.hsqldb_voltpatches.index.Index)6