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

--no commit message

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