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

--no commit message

--no commit message
上级 b9c3b28c
......@@ -912,6 +912,15 @@ public class ErrorCode {
*/
public static final int CONSTRAINT_NOT_FOUND_1 = 90057;
/**
* The error with code <code>90058</code> is thrown when trying to call
* commit or rollback inside a trigger, or when trying to call a method
* inside a trigger that implicitly commits the current transaction, if an
* object is locked. This is not because it would release the lock too
* early.
*/
public static final int COMMIT_ROLLBACK_NOT_ALLOWED = 90058;
/**
* The error with code <code>90059</code> is thrown when
* a query contains a column that could belong to multiple tables.
......@@ -1753,7 +1762,7 @@ public class ErrorCode {
*/
public static final int CAN_ONLY_ASSIGN_TO_VARIABLE_1 = 90137;
// next is 90058, 90108
// next is 90108
/**
* INTERNAL
......
......@@ -11,7 +11,7 @@ package org.h2.engine;
* - Test with Hibernate
* - Run FindBugs
* - ant jarClient, check jar file size
*
* - ant jar, test with IKVM
* - Compile with JDK 1.4, 1.5 and 1.6:
* set path=C:\Programme\Java\jdk1.6.0\bin;%PATH%
* set JAVA_HOME=C:\Programme\Java\jdk1.6.0
......
......@@ -85,10 +85,17 @@ public class Session implements SessionInterface {
private HashSet temporaryResults;
private int queryTimeout = SysProperties.getMaxQueryTimeout();
private int lastUncommittedDelete;
private boolean commitOrRollbackDisabled;
public Session() {
}
public boolean setCommitOrRollbackDisabled(boolean x) {
boolean old = commitOrRollbackDisabled;
commitOrRollbackDisabled = x;
return old;
}
private void initVariables() {
if (variables == null) {
variables = new HashMap();
......@@ -238,6 +245,7 @@ public class Session implements SessionInterface {
}
public void commit(boolean ddl) throws SQLException {
checkCommitRollback();
lastUncommittedDelete = 0;
currentTransactionName = null;
if (containsUncommitted()) {
......@@ -285,7 +293,14 @@ public class Session implements SessionInterface {
unlockAll();
}
private void checkCommitRollback() throws SQLException {
if (commitOrRollbackDisabled && locks.size() > 0) {
throw Message.getSQLException(ErrorCode.COMMIT_ROLLBACK_NOT_ALLOWED);
}
}
public void rollback() throws SQLException {
checkCommitRollback();
currentTransactionName = null;
boolean needCommit = false;
if (undoLog.size() > 0) {
......@@ -491,6 +506,7 @@ public class Session implements SessionInterface {
}
public void rollbackToSavepoint(String name) throws SQLException {
checkCommitRollback();
if (savepoints == null) {
throw Message.getSQLException(ErrorCode.SAVEPOINT_IS_INVALID_1, name);
}
......
......@@ -80,11 +80,14 @@ public class TriggerObject extends SchemaObjectBase {
}
load(session);
Connection c2 = session.createConnection(false);
boolean old = session.setCommitOrRollbackDisabled(true);
try {
triggerCallback.fire(c2, null, null);
} catch (Throwable e) {
throw Message.getSQLException(ErrorCode.ERROR_EXECUTING_TRIGGER_3, new String[] { getName(),
triggerClassName, e.toString() }, e);
} finally {
session.setCommitOrRollbackDisabled(old);
}
}
......@@ -147,6 +150,7 @@ public class TriggerObject extends SchemaObjectBase {
}
Connection c2 = session.createConnection(false);
boolean old = session.getAutoCommit();
boolean oldDisabled = session.setCommitOrRollbackDisabled(true);
try {
session.setAutoCommit(false);
triggerCallback.fire(c2, oldList, newList);
......@@ -160,6 +164,7 @@ public class TriggerObject extends SchemaObjectBase {
}
}
} finally {
session.setCommitOrRollbackDisabled(oldDisabled);
session.setAutoCommit(old);
}
}
......
......@@ -56,6 +56,7 @@ ShutdownHandler {
private Font font;
private Image icon16, icon24;
private Frame frame;
private Button startBrowser;
//#endif
private static final int EXIT_ERROR = 1;
private Server web, tcp, pg;
......@@ -302,7 +303,7 @@ ShutdownHandler {
}
mainPanel.add(text, constraintsTextField);
Button startBrowser = new Button("Start Browser");
startBrowser = new Button("Start Browser");
startBrowser.setFocusable(false);
startBrowser.setActionCommand("console");
startBrowser.addActionListener(this);
......@@ -317,10 +318,9 @@ ShutdownHandler {
try {
frame.setVisible(true);
} catch (Throwable t) {
// ignore
// some systems don't support this method, for example IKVM
// however it still works
// ignore
System.out.println("URL: " + web.getURL());
}
}
......@@ -343,6 +343,9 @@ ShutdownHandler {
startBrowser();
} else if ("status".equals(command)) {
showWindow(false);
} else if (startBrowser == e.getSource()) {
// for some reason, IKVM ignores setActionCommand
startBrowser();
}
}
//#endif
......
......@@ -159,10 +159,10 @@ java org.h2.test.TestAll timer
/*
CREATE TABLE in a before trigger results in an internal error.
add link to new in use, links
merge query and result frames
auto-complete in-place
in-place auto-complete
scheduler: what if invoke takes more than...
scheduler: log at startup next 5
......@@ -176,10 +176,6 @@ read uncommitted and multi-threaded mode at the same time is dangerous
add @author
console autocomplete with pos
remove old in use, links
test multi-threaded kernel fulltext
fix or disable the linear hash index
......@@ -189,6 +185,10 @@ Can sometimes not delete log file? need test case
Add where required // TODO: change in version 1.1
History:
Improved support for IKVM.
A error is now thrown when trying to call a method
inside a trigger that implicitly commits the current transaction,
if an object is locked.
Roadmap:
......
......@@ -131,12 +131,37 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
if (!newRow[1].toString().endsWith("-updated")) {
throw new Error("supposed to be updated");
}
checkCommit(conn);
} else if (triggerName.startsWith("UPD_BEFORE")) {
newRow[1] = newRow[1] + "-updated2";
} else if (triggerName.startsWith("UPD_AFTER")) {
if (!newRow[1].toString().endsWith("-updated2")) {
throw new Error("supposed to be updated2");
}
checkCommit(conn);
}
}
private void checkCommit(Connection conn) {
try {
conn.commit();
throw new Error("Commit must not work here");
} catch (SQLException e) {
try {
checkNotGeneralException(e);
} catch (Exception e2) {
throw new Error("Unexpected: " + e.toString());
}
}
try {
conn.createStatement().execute("CREATE TABLE X(ID INT)");
throw new Error("CREATE TABLE WORKED, but implicitly commits");
} catch (SQLException e) {
try {
checkNotGeneralException(e);
} catch (Exception e2) {
throw new Error("Unexpected: " + e.toString());
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论