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;
}
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;
}
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();
}
Aggregations