Package org.hsqldb_voltpatches.HsqlNameManager

Examples of org.hsqldb_voltpatches.HsqlNameManager.HsqlName


        }
    }

    void add(SchemaObject object) {

        HsqlName name = object.getName();

        if (map.containsKey(name.name)) {
            int code = getAddErrorCode(name.type);

            throw Error.error(code, name.name);
View Full Code Here


                if (trigger.getName().parent == parent) {
                    it.remove();
                }
            } else {
                HsqlName name = (HsqlName) it.next();

                if (name.parent == parent) {
                    it.remove();
                }
            }
View Full Code Here

            if (references != null) {
                boolean isResolved = true;

                for (int j = 0; j < references.size(); j++) {
                    HsqlName name = (HsqlName) references.get(j);

                    if (SqlInvariants.isSchemaNameSystem(name)) {
                        continue;
                    }
View Full Code Here

        session.database.setMetaDirty(true);

        switch (type) {

            case StatementTypes.RENAME_OBJECT : {
                HsqlName     name    = (HsqlName) arguments[0];
                HsqlName     newName = (HsqlName) arguments[1];
                SchemaObject object;

                if (name.type == SchemaObject.CATALOG) {
                    try {
                        session.checkAdmin();
                        session.checkDDLWrite();
                        name.rename(newName);

                        break;
                    } catch (HsqlException e) {
                        return Result.newErrorResult(e, sql);
                    }
                }

                try {
                    name.setSchemaIfNull(session.getCurrentSchemaHsqlName());

                    object =
                        session.database.schemaManager.getSchemaObject(name);

                    if (object == null) {
                        throw Error.error(ErrorCode.X_42501, name.name);
                    }

                    name = object.getName();

                    checkSchemaUpdateAuthorisation(session, name.schema);
                    newName.setSchemaIfNull(name.schema);

                    if (name.schema != newName.schema) {
                        HsqlException e = Error.error(ErrorCode.X_42505);

                        return Result.newErrorResult(e, sql);
                    }

                    newName.parent = name.parent;

                    switch (object.getType()) {

                        case SchemaObject.COLUMN :
                            HsqlName parent = object.getName().parent;

                            session.database.schemaManager
                                .checkColumnIsReferenced(parent,
                                                         object.getName());

                            Table table =
                                session.database.schemaManager.getUserTable(
                                    session, parent);

                            table.renameColumn((ColumnSchema) object, newName);
                            break;

                        case SchemaObject.SCHEMA :

                            /**
                             * @todo 1.9.0 - review for schemas referenced in
                             *  external view or trigger definitions
                             */
                            session.database.schemaManager.renameSchema(name,
                                    newName);
                            break;

                        default :
                            session.database.schemaManager.renameSchemaObject(
                                name, newName);
                    }

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.ALTER_SEQUENCE : {
                try {
                    NumberSequence sequence = (NumberSequence) arguments[0];
                    NumberSequence settings = (NumberSequence) arguments[1];

                    checkSchemaUpdateAuthorisation(session,
                                                   sequence.getSchemaName());
                    sequence.reset(settings);

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.ALTER_DOMAIN :
            case StatementTypes.ALTER_ROUTINE :
            case StatementTypes.ALTER_TYPE :
            case StatementTypes.ALTER_TABLE :
            case StatementTypes.ALTER_TRANSFORM : {
                try {
                    session.parser.reset(sql);
                    session.parser.read();
                    session.parser.processAlter();

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.DROP_COLUMN : {
                try {
                    HsqlName name       = (HsqlName) arguments[0];
                    int      objectType = ((Integer) arguments[1]).intValue();
                    boolean  cascade = ((Boolean) arguments[2]).booleanValue();
                    boolean ifExists = ((Boolean) arguments[3]).booleanValue();
                    Table table =
                        session.database.schemaManager.getUserTable(session,
                            name.parent);
                    int colindex = table.getColumnIndex(name.name);

                    if (table.getColumnCount() == 1) {
                        throw Error.error(ErrorCode.X_42591);
                    }

                    checkSchemaUpdateAuthorisation(session,
                                                   table.getSchemaName());
                    session.commit(false);

                    TableWorks tableWorks = new TableWorks(session, table);

                    tableWorks.dropColumn(colindex, cascade);

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.DROP_ASSERTION :
            case StatementTypes.DROP_CHARACTER_SET :
            case StatementTypes.DROP_COLLATION :
            case StatementTypes.DROP_TYPE :
            case StatementTypes.DROP_DOMAIN :
            case StatementTypes.DROP_ROLE :
            case StatementTypes.DROP_USER :
            case StatementTypes.DROP_ROUTINE :
            case StatementTypes.DROP_SCHEMA :
            case StatementTypes.DROP_SEQUENCE :
            case StatementTypes.DROP_TABLE :
            case StatementTypes.DROP_TRANSFORM :
            case StatementTypes.DROP_TRANSLATION :
            case StatementTypes.DROP_TRIGGER :
            case StatementTypes.DROP_CAST :
            case StatementTypes.DROP_ORDERING :
            case StatementTypes.DROP_VIEW :
            case StatementTypes.DROP_INDEX :
            case StatementTypes.DROP_CONSTRAINT : {
                try {
                    HsqlName name       = (HsqlName) arguments[0];
                    int      objectType = ((Integer) arguments[1]).intValue();
                    boolean  cascade = ((Boolean) arguments[2]).booleanValue();
                    boolean ifExists = ((Boolean) arguments[3]).booleanValue();

                    switch (type) {

                        case StatementTypes.DROP_ROLE :
                        case StatementTypes.DROP_USER :
                            session.checkAdmin();
                            session.checkDDLWrite();
                            break;

                        case StatementTypes.DROP_SCHEMA :
                            checkSchemaUpdateAuthorisation(session, name);

                            if (!session.database.schemaManager.schemaExists(
                                    name.name)) {
                                if (ifExists) {
                                    return Result.updateZeroResult;
                                }
                            }
                            break;

                        default :
                            if (name.schema == null) {
                                name.schema =
                                    session.getCurrentSchemaHsqlName();
                            } else {
                                if (!session.database.schemaManager
                                        .schemaExists(name.schema.name)) {
                                    if (ifExists) {
                                        return Result.updateZeroResult;
                                    }
                                }
                            }

                            name.schema =
                                session.database.schemaManager
                                    .getUserSchemaHsqlName(name.schema.name);

                            checkSchemaUpdateAuthorisation(session,
                                                           name.schema);

                            name = session.database.schemaManager
                                .getSchemaObjectName(name.schema, name.name,
                                                     objectType, !ifExists);

                            if (name == null) {
                                return Result.updateZeroResult;
                            }
                    }

                    if (!cascade) {
                        session.database.schemaManager.checkObjectIsReferenced(
                            name);
                    }

                    switch (type) {

                        case StatementTypes.DROP_ROLE :
                            dropRole(session, name, cascade);
                            break;

                        case StatementTypes.DROP_USER :
                            dropUser(session, name, cascade);
                            break;

                        case StatementTypes.DROP_SCHEMA :
                            dropSchema(session, name, cascade);
                            break;

                        case StatementTypes.DROP_ASSERTION :
                            break;

                        case StatementTypes.DROP_CHARACTER_SET :
                        case StatementTypes.DROP_COLLATION :
                        case StatementTypes.DROP_SEQUENCE :
                        case StatementTypes.DROP_TRIGGER :
                            dropObject(session, name, cascade);
                            break;

                        case StatementTypes.DROP_TYPE :
                            dropType(session, name, cascade);
                            break;

                        case StatementTypes.DROP_DOMAIN :
                            dropDomain(session, name, cascade);
                            break;

                        case StatementTypes.DROP_ROUTINE :
                            dropRoutine(session, name, cascade);
                            break;

                        case StatementTypes.DROP_TABLE :
                        case StatementTypes.DROP_VIEW :
                            dropTable(session, name, cascade);
                            break;

                        case StatementTypes.DROP_TRANSFORM :
                        case StatementTypes.DROP_TRANSLATION :
                        case StatementTypes.DROP_CAST :
                        case StatementTypes.DROP_ORDERING :
                            break;

                        case StatementTypes.DROP_INDEX :
                            checkSchemaUpdateAuthorisation(session,
                                                           name.schema);
                            session.database.schemaManager.dropIndex(session,
                                    name);
                            break;

                        case StatementTypes.DROP_CONSTRAINT :
                            checkSchemaUpdateAuthorisation(session,
                                                           name.schema);
                            session.database.schemaManager.dropConstraint(
                                session, name, cascade);
                            break;
                    }

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.GRANT :
            case StatementTypes.REVOKE : {
                try {
                    boolean        grant       = type == StatementTypes.GRANT;
                    OrderedHashSet granteeList = (OrderedHashSet) arguments[0];
                    HsqlName       name        = (HsqlName) arguments[1];

                    this.setSchemaName(session, null, name);

                    name = session.database.schemaManager.getSchemaObjectName(
                        name.schema, name.name, name.type, true);

                    SchemaObject schemaObject =
                        session.database.schemaManager.getSchemaObject(name);
                    Right   right   = (Right) arguments[2];
                    Grantee grantor = (Grantee) arguments[3];
                    boolean cascade = ((Boolean) arguments[4]).booleanValue();
                    boolean isGrantOption =
                        ((Boolean) arguments[5]).booleanValue();

                    if (grantor == null) {
                        grantor = isSchemaDefinition ? schemaName.owner
                                                     : session.getGrantee();
                    }

                    GranteeManager gm = session.database.granteeManager;

                    switch (schemaObject.getType()) {

                        case SchemaObject.CHARSET :
                            System.out.println("grant charset!");
                            break;

                        case SchemaObject.VIEW :
                        case SchemaObject.TABLE : {
                            Table t = (Table) schemaObject;

                            right.setColumns(t);

                            if (t.getTableType() == TableBase.TEMP_TABLE
                                    && !right.isFull()) {
                                return Result.newErrorResult(
                                    Error.error(ErrorCode.X_42595), sql);
                            }
                        }
                    }

                    if (grant) {
                        gm.grant(granteeList, schemaObject, right, grantor,
                                 isGrantOption);
                    } else {
                        gm.revoke(granteeList, schemaObject, right, grantor,
                                  isGrantOption, cascade);
                    }

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.GRANT_ROLE :
            case StatementTypes.REVOKE_ROLE : {
                try {
                    boolean        grant = type == StatementTypes.GRANT_ROLE;
                    OrderedHashSet granteeList = (OrderedHashSet) arguments[0];
                    OrderedHashSet roleList    = (OrderedHashSet) arguments[1];
                    Grantee        grantor     = (Grantee) arguments[2];
                    boolean        cascade     = (Boolean) arguments[3];
                    GranteeManager gm = session.database.granteeManager;

                    gm.checkGranteeList(granteeList);

                    for (int i = 0; i < granteeList.size(); i++) {
                        String grantee = (String) granteeList.get(i);

                        gm.checkRoleList(grantee, roleList, grantor, grant);
                    }

                    if (grant) {
                        for (int i = 0; i < granteeList.size(); i++) {
                            String grantee = (String) granteeList.get(i);

                            for (int j = 0; j < roleList.size(); j++) {
                                String roleName = (String) roleList.get(j);

                                gm.grant(grantee, roleName, grantor);
                            }
                        }
                    } else {
                        for (int i = 0; i < granteeList.size(); i++) {
                            String grantee = (String) granteeList.get(i);

                            for (int j = 0; j < roleList.size(); j++) {
                                gm.revoke(grantee, (String) roleList.get(j),
                                          grantor);
                            }
                        }
                    }

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_ASSERTION : {
                return Result.updateZeroResult;
            }
            case StatementTypes.CREATE_CHARACTER_SET : {
                Charset charset = (Charset) arguments[0];

                try {
                    setOrCheckObjectName(session, null, charset.getName(),
                                         true);
                    session.database.schemaManager.addSchemaObject(charset);

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_COLLATION : {
                return Result.updateZeroResult;
            }
            case StatementTypes.CREATE_ROLE : {
                try {
                    session.checkAdmin();
                    session.checkDDLWrite();

                    HsqlName name = (HsqlName) arguments[0];

                    session.database.getGranteeManager().addRole(name);

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_USER : {
                HsqlName name     = (HsqlName) arguments[0];
                String   password = (String) arguments[1];
                Grantee  grantor  = (Grantee) arguments[2];
                boolean  admin    = ((Boolean) arguments[3]).booleanValue();

                try {
                    session.checkAdmin();
                    session.checkDDLWrite();
                    session.database.getUserManager().createUser(name,
                            password);

                    if (admin) {
                        session.database.getGranteeManager().grant(name.name,
                                SqlInvariants.DBA_ADMIN_ROLE_NAME, grantor);
                    }

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_SCHEMA : {
                HsqlName name  = (HsqlName) arguments[0];
                Grantee  owner = (Grantee) arguments[1];

                try {
                    session.checkDDLWrite();

                    if (session.database.schemaManager.schemaExists(
                            name.name)) {
                        if (session.isProcessingScript
                                && SqlInvariants.PUBLIC_SCHEMA.equals(
                                    name.name)) {}
                        else {
                            throw Error.error(ErrorCode.X_42504, name.name);
                        }
                    } else {
                        session.database.schemaManager.createSchema(name,
                                owner);
                    }

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_ROUTINE : {
                Routine routine = (Routine) arguments[0];

                try {
                    routine.resolve();
                    setOrCheckObjectName(session, null, routine.getName(),
                                         false);
                    session.database.schemaManager.addSchemaObject(routine);

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_ALIAS : {
                HsqlName  name     = (HsqlName) arguments[0];
                Routine[] routines = (Routine[]) arguments[1];

                try {
                    session.checkAdmin();
                    session.checkDDLWrite();

                    if (name != null) {
                        for (int i = 0; i < routines.length; i++) {
                            routines[i].setName(name);
                            session.database.schemaManager.addSchemaObject(
                                routines[i]);
                        }
                    }

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_SEQUENCE : {
                NumberSequence sequence = (NumberSequence) arguments[0];

                try {
                    setOrCheckObjectName(session, null, sequence.getName(),
                                         true);
                    session.database.schemaManager.addSchemaObject(sequence);

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_DOMAIN : {
                Type type = (Type) arguments[0];
                Constraint[] constraints =
                    type.userTypeModifier.getConstraints();

                try {
                    setOrCheckObjectName(session, null, type.getName(), true);

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

                        setOrCheckObjectName(session, type.getName(),
                                             c.getName(), true);
                        session.database.schemaManager.addSchemaObject(c);
                    }

                    session.database.schemaManager.addSchemaObject(type);

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_TABLE : {
                Table         table              = (Table) arguments[0];
                HsqlArrayList tempConstraints = (HsqlArrayList) arguments[1];
                StatementDMQL statement = (StatementDMQL) arguments[2];
                HsqlArrayList foreignConstraints = null;

                try {
                    setOrCheckObjectName(session, null, table.getName(), true);
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }

                try {
                    if (isSchemaDefinition) {
                        foreignConstraints = new HsqlArrayList();
                    }

                    if (tempConstraints != null) {
                        table =
                            ParserDDL.addTableConstraintDefinitions(session,
                                table, tempConstraints, foreignConstraints);
                        arguments[1] = foreignConstraints;
                    }

                    session.database.schemaManager.addSchemaObject(table);

                    if (statement != null) {
                        Result result = statement.execute(session);

                        table.insertIntoTable(session, result);
                    }

                    return Result.updateZeroResult;
                } catch (HsqlException e) {
                    session.database.schemaManager.removeExportedKeys(table);
                    session.database.schemaManager.removeDependentObjects(
                        table.getName());

                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_TRANSFORM :
                return Result.updateZeroResult;

            case StatementTypes.CREATE_TRANSLATION :
                return Result.updateZeroResult;

            case StatementTypes.CREATE_TRIGGER : {
                TriggerDef trigger   = (TriggerDef) arguments[0];
                HsqlName   otherName = (HsqlName) arguments[1];

                try {
                    checkSchemaUpdateAuthorisation(session,
                                                   trigger.getSchemaName());
                    session.database.schemaManager.checkSchemaObjectNotExists(
                        trigger.getName());

                    if (otherName != null) {
                        if (session.database.schemaManager.getSchemaObject(
                                otherName) == null) {
                            throw Error.error(ErrorCode.X_42501,
                                              otherName.name);
                        }
                    }

                    trigger.table.addTrigger(trigger, otherName);
                    session.database.schemaManager.addSchemaObject(trigger);

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_CAST :
                return Result.updateZeroResult;

            case StatementTypes.CREATE_TYPE : {
                Type type = (Type) arguments[0];

                try {
                    setOrCheckObjectName(session, null, type.getName(), true);
                    session.database.schemaManager.addSchemaObject(type);

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
            }
            case StatementTypes.CREATE_ORDERING :
                return Result.updateZeroResult;

            case StatementTypes.CREATE_VIEW : {
                try {
                    session.parser.reset(sql);
                    session.parser.read();
                    session.parser.read();
                    session.parser.processCreateView();

                    break;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
/*
                View view = (View) arguments[0];

                try {
                    checkSchemaUpdateAuthorisation(session,
                                                   view.getSchemaName());
                    session.database.schemaManager.checkSchemaObjectNotExists(
                        view.getName());
                    session.database.schemaManager.addSchemaObject(view);
                    session.database.logger.writeToLog(session, sql);

                    return Result.updateZeroResult;
                } catch (HsqlException e) {
                    return Result.newErrorResult(e, sql);
                }
*/
            }
            case StatementTypes.CREATE_INDEX : {
                Table    table;
                HsqlName name;
                int[]    indexColumns;
                boolean  unique;

                table        = (Table) arguments[0];
                indexColumns = (int[]) arguments[1];
View Full Code Here

        OrderedHashSet set =
            session.database.schemaManager.getReferencingObjects(
                domain.getName());

        if (!cascade && set.size() > 0) {
            HsqlName objectName = (HsqlName) set.get(0);

            throw Error.error(ErrorCode.X_42502,
                              objectName.getSchemaQualifiedStatementName());
        }

        Constraint[] constraints = domain.userTypeModifier.getConstraints();

        set.clear();
View Full Code Here

        session.database.getUserManager().dropUser(name.name);
    }

    private void dropSchema(Session session, HsqlName name, boolean cascade) {

        HsqlName schema =
            session.database.schemaManager.getUserSchemaHsqlName(name.name);

        checkSchemaUpdateAuthorisation(session, schema);
        session.database.schemaManager.dropSchema(name.name, cascade);
    }
View Full Code Here

        session.database.schemaManager.dropSchema(name.name, cascade);
    }

    private void dropRoutine(Session session, HsqlName name, boolean cascade) {

        HsqlName routineName =
            session.database.schemaManager.getSchemaObjectName(name.schema,
                name.name, name.type, true);

        checkSchemaUpdateAuthorisation(session, name.schema);
        session.database.schemaManager.removeSchemaObject(routineName,
View Full Code Here

                set.add(sequence.getName());
            }

            for (int i = 0; i < rangeVariables.size(); i++) {
                RangeVariable range = (RangeVariable) rangeVariables.get(i);
                HsqlName      name  = range.rangeTable.getName();

                if (name.schema != SqlInvariants.SYSTEM_SCHEMA_HSQLNAME) {
                    set.add(range.rangeTable.getName());
                    set.addAll(range.getColumnNames());
                } else if (name.type == SchemaObject.TRANSITION) {
View Full Code Here

    }

    static TableDerived newSubqueryTable(Database database,
                                         QueryExpression queryExpression) {

        HsqlName name = database.nameManager.getSubqueryTableName();

        try {
            return new TableDerived(database, name, TableBase.SYSTEM_SUBQUERY,
                                    queryExpression);
        } catch (Exception e) {
View Full Code Here

    public static void setColumnsInSchemaTable(Table table,
            HsqlName[] columnNames, Type[] columnTypes) {

        for (int i = 0; i < columnNames.length; i++) {
            HsqlName columnName = columnNames[i];

            columnName = table.database.nameManager.newColumnSchemaHsqlName(
                table.getName(), columnName);

            ColumnSchema column = new ColumnSchema(columnName, columnTypes[i],
View Full Code Here

TOP

Related Classes of org.hsqldb_voltpatches.HsqlNameManager.HsqlName

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.