提交 ed7740d3 authored 作者: Thomas Mueller's avatar Thomas Mueller

Triggers: INSTEAD OF triggers are now supported.

上级 4f50daa8
......@@ -3105,6 +3105,10 @@ public class Parser {
if (len == 0) {
throw getSyntaxError();
}
if (!identifiersToUpper) {
// if not yet converted to uppercase, do it now
s = StringUtils.toUpperEnglish(s);
}
return getSaveTokenType(s, database.getMode().supportOffsetFetch);
}
......@@ -3732,11 +3736,17 @@ public class Parser {
boolean ifNotExists = readIfNoExists();
String triggerName = readIdentifierWithSchema(null);
Schema schema = getSchema();
boolean isBefore;
if (readIf("BEFORE")) {
boolean insteadOf, isBefore;
if (readIf("INSTEAD")) {
read("OF");
isBefore = true;
insteadOf = true;
} else if (readIf("BEFORE")) {
insteadOf = false;
isBefore = true;
} else {
read("AFTER");
insteadOf = false;
isBefore = false;
}
int typeMask = 0;
......@@ -3763,6 +3773,7 @@ public class Parser {
command.setForce(force);
command.setTriggerName(triggerName);
command.setIfNotExists(ifNotExists);
command.setInsteadOf(insteadOf);
command.setBefore(isBefore);
command.setOnRollback(onRollback);
command.setTypeMask(typeMask);
......
......@@ -25,6 +25,7 @@ public class CreateTrigger extends SchemaCommand {
private String triggerName;
private boolean ifNotExists;
private boolean insteadOf;
private boolean before;
private int typeMask;
private boolean rowBased;
......@@ -39,6 +40,10 @@ public class CreateTrigger extends SchemaCommand {
super(session, schema);
}
public void setInsteadOf(boolean insteadOf) {
this.insteadOf = insteadOf;
}
public void setBefore(boolean before) {
this.before = before;
}
......@@ -87,6 +92,7 @@ public class CreateTrigger extends SchemaCommand {
int id = getObjectId(false, true);
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);
......
......@@ -56,10 +56,13 @@ public class Delete extends Prepared {
setCurrentRowNumber(rows.size() + 1);
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
Row row = tableFilter.get();
boolean done = false;
if (table.fireRow()) {
table.fireBeforeRow(session, row, null);
done = table.fireBeforeRow(session, row, null);
}
if (!done) {
rows.add(row);
}
rows.add(row);
}
}
int rowScanCount = 0;
......
......@@ -114,11 +114,13 @@ public class Insert extends Prepared {
}
}
table.validateConvertUpdateSequence(session, newRow);
table.fireBeforeRow(session, null, newRow);
table.lock(session, true, false);
table.addRow(session, newRow);
session.log(table, UndoLogRecord.INSERT, newRow);
table.fireAfterRow(session, null, newRow, false);
boolean done = table.fireBeforeRow(session, null, newRow);
if (!done) {
table.lock(session, true, false);
table.addRow(session, newRow);
session.log(table, UndoLogRecord.INSERT, newRow);
table.fireAfterRow(session, null, newRow, false);
}
count++;
}
} else {
......@@ -141,10 +143,12 @@ public class Insert extends Prepared {
}
}
table.validateConvertUpdateSequence(session, newRow);
table.fireBeforeRow(session, null, newRow);
table.addRow(session, newRow);
session.log(table, UndoLogRecord.INSERT, newRow);
table.fireAfterRow(session, null, newRow, false);
boolean done = table.fireBeforeRow(session, null, newRow);
if (!done) {
table.addRow(session, newRow);
session.log(table, UndoLogRecord.INSERT, newRow);
table.fireAfterRow(session, null, newRow, false);
}
}
rows.close();
}
......
......@@ -175,11 +175,13 @@ public class Merge extends Prepared {
if (count == 0) {
try {
table.validateConvertUpdateSequence(session, row);
table.fireBeforeRow(session, null, row);
table.lock(session, true, false);
table.addRow(session, row);
session.log(table, UndoLogRecord.INSERT, row);
table.fireAfterRow(session, null, row, false);
boolean done = table.fireBeforeRow(session, null, row);
if (!done) {
table.lock(session, true, false);
table.addRow(session, row);
session.log(table, UndoLogRecord.INSERT, row);
table.fireAfterRow(session, null, row, false);
}
} catch (SQLException e) {
if (e.getErrorCode() == ErrorCode.DUPLICATE_KEY_1) {
// concurrent merge or insert
......
......@@ -104,11 +104,14 @@ public class Update extends Prepared {
newRow.setValue(i, newValue);
}
table.validateConvertUpdateSequence(session, newRow);
boolean done = false;
if (table.fireRow()) {
table.fireBeforeRow(session, oldRow, newRow);
done = table.fireBeforeRow(session, oldRow, newRow);
}
if (!done) {
rows.add(oldRow);
rows.add(newRow);
}
rows.add(oldRow);
rows.add(newRow);
count++;
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论