Search in sources :

Example 6 with TriggerObject

use of org.h2.schema.TriggerObject in project h2database by h2database.

the class CreateTrigger method update.

@Override
public int update() {
    session.commit(true);
    Database db = session.getDatabase();
    if (getSchema().findTrigger(triggerName) != null) {
        if (ifNotExists) {
            return 0;
        }
        throw DbException.get(ErrorCode.TRIGGER_ALREADY_EXISTS_1, triggerName);
    }
    if ((typeMask & Trigger.SELECT) == Trigger.SELECT && rowBased) {
        throw DbException.get(ErrorCode.TRIGGER_SELECT_AND_ROW_BASED_NOT_SUPPORTED, triggerName);
    }
    int id = getObjectId();
    Table table = getSchema().getTableOrView(session, tableName);
    TriggerObject trigger = new TriggerObject(getSchema(), id, triggerName, table);
    trigger.setInsteadOf(insteadOf);
    trigger.setBefore(before);
    trigger.setNoWait(noWait);
    trigger.setQueueSize(queueSize);
    trigger.setRowBased(rowBased);
    trigger.setTypeMask(typeMask);
    trigger.setOnRollback(onRollback);
    if (this.triggerClassName != null) {
        trigger.setTriggerClassName(triggerClassName, force);
    } else {
        trigger.setTriggerSource(triggerSource, force);
    }
    db.addSchemaObject(session, trigger);
    table.addTrigger(trigger);
    return 0;
}
Also used : Table(org.h2.table.Table) Database(org.h2.engine.Database) TriggerObject(org.h2.schema.TriggerObject)

Example 7 with TriggerObject

use of org.h2.schema.TriggerObject in project h2database by h2database.

the class DropTrigger method update.

@Override
public int update() {
    session.commit(true);
    Database db = session.getDatabase();
    TriggerObject trigger = getSchema().findTrigger(triggerName);
    if (trigger == null) {
        if (!ifExists) {
            throw DbException.get(ErrorCode.TRIGGER_NOT_FOUND_1, triggerName);
        }
    } else {
        Table table = trigger.getTable();
        session.getUser().checkRight(table, Right.ALL);
        db.removeSchemaObject(session, trigger);
    }
    return 0;
}
Also used : Table(org.h2.table.Table) Database(org.h2.engine.Database) TriggerObject(org.h2.schema.TriggerObject)

Example 8 with TriggerObject

use of org.h2.schema.TriggerObject in project h2database by h2database.

the class Schema method removeChildrenAndResources.

@Override
public void removeChildrenAndResources(Session session) {
    while (triggers != null && triggers.size() > 0) {
        TriggerObject obj = (TriggerObject) triggers.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (constraints != null && constraints.size() > 0) {
        Constraint obj = (Constraint) constraints.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    // There can be dependencies between tables e.g. using computed columns,
    // so we might need to loop over them multiple times.
    boolean runLoopAgain = false;
    do {
        runLoopAgain = false;
        if (tablesAndViews != null) {
            // Loop over a copy because the map is modified underneath us.
            for (Table obj : new ArrayList<>(tablesAndViews.values())) {
                // in one go underneath us.
                if (obj.getName() != null) {
                    if (database.getDependentTable(obj, obj) == null) {
                        database.removeSchemaObject(session, obj);
                    } else {
                        runLoopAgain = true;
                    }
                }
            }
        }
    } while (runLoopAgain);
    while (indexes != null && indexes.size() > 0) {
        Index obj = (Index) indexes.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (sequences != null && sequences.size() > 0) {
        Sequence obj = (Sequence) sequences.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (constants != null && constants.size() > 0) {
        Constant obj = (Constant) constants.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (functions != null && functions.size() > 0) {
        FunctionAlias obj = (FunctionAlias) functions.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    for (Right right : database.getAllRights()) {
        if (right.getGrantedObject() == this) {
            database.removeDatabaseObject(session, right);
        }
    }
    database.removeMeta(session, getId());
    owner = null;
    invalidate();
}
Also used : RegularTable(org.h2.table.RegularTable) Table(org.h2.table.Table) Constraint(org.h2.constraint.Constraint) FunctionAlias(org.h2.engine.FunctionAlias) ArrayList(java.util.ArrayList) Right(org.h2.engine.Right) Index(org.h2.index.Index)

Aggregations

TriggerObject (org.h2.schema.TriggerObject)7 Table (org.h2.table.Table)6 Constraint (org.h2.constraint.Constraint)5 Sequence (org.h2.schema.Sequence)5 Right (org.h2.engine.Right)4 Index (org.h2.index.Index)4 IOException (java.io.IOException)3 Database (org.h2.engine.Database)3 DbObject (org.h2.engine.DbObject)3 Schema (org.h2.schema.Schema)3 SchemaObject (org.h2.schema.SchemaObject)3 ArrayList (java.util.ArrayList)2 ConstraintReferential (org.h2.constraint.ConstraintReferential)2 FunctionAlias (org.h2.engine.FunctionAlias)2 Role (org.h2.engine.Role)2 Setting (org.h2.engine.Setting)2 User (org.h2.engine.User)2 UserAggregate (org.h2.engine.UserAggregate)2 UserDataType (org.h2.engine.UserDataType)2 Constant (org.h2.schema.Constant)2