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

Triggers: INSTEAD OF triggers are now supported.

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