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

When enabling autocommit, the transaction is now committed (as required by the JDBC API).

上级 c8631bc5
...@@ -349,11 +349,8 @@ public class Session extends SessionWithState { ...@@ -349,11 +349,8 @@ public class Session extends SessionWithState {
} }
public void setAutoCommit(boolean b) { public void setAutoCommit(boolean b) {
if (autoCommit != b) {
commit(false);
autoCommit = b; autoCommit = b;
} }
}
public int getLockTimeout() { public int getLockTimeout() {
return lockTimeout; return lockTimeout;
......
...@@ -109,7 +109,8 @@ public interface SessionInterface extends Closeable { ...@@ -109,7 +109,8 @@ public interface SessionInterface extends Closeable {
boolean getAutoCommit(); boolean getAutoCommit();
/** /**
* Set the auto-commit mode. * Set the auto-commit mode. This call doesn't commit the current
* transaction.
* *
* @param autoCommit the new value * @param autoCommit the new value
*/ */
......
...@@ -253,8 +253,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -253,8 +253,7 @@ public class JdbcConnection extends TraceObject implements Connection {
* *
* @param sql the SQL statement * @param sql the SQL statement
* @return the prepared statement * @return the prepared statement
* @throws SQLException * @throws SQLException if the connection is closed
* if the connection is closed
*/ */
public PreparedStatement prepareStatement(String sql) throws SQLException { public PreparedStatement prepareStatement(String sql) throws SQLException {
try { try {
...@@ -297,8 +296,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -297,8 +296,7 @@ public class JdbcConnection extends TraceObject implements Connection {
* Gets the database meta data for this database. * Gets the database meta data for this database.
* *
* @return the database meta data * @return the database meta data
* @throws SQLException * @throws SQLException if the connection is closed
* if the connection is closed
*/ */
public DatabaseMetaData getMetaData() throws SQLException { public DatabaseMetaData getMetaData() throws SQLException {
try { try {
...@@ -393,13 +391,11 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -393,13 +391,11 @@ public class JdbcConnection extends TraceObject implements Connection {
} }
/** /**
* Switches auto commit on or off. Calling this function does not commit the * Switches auto commit on or off. Enabling it commits an uncommitted
* current transaction. * transaction, if there is one.
* *
* @param autoCommit * @param autoCommit true for auto commit on, false for off
* true for auto commit on, false for off * @throws SQLException if the connection is closed
* @throws SQLException
* if the connection is closed
*/ */
public synchronized void setAutoCommit(boolean autoCommit) throws SQLException { public synchronized void setAutoCommit(boolean autoCommit) throws SQLException {
try { try {
...@@ -407,6 +403,9 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -407,6 +403,9 @@ public class JdbcConnection extends TraceObject implements Connection {
debugCode("setAutoCommit(" + autoCommit + ");"); debugCode("setAutoCommit(" + autoCommit + ");");
} }
checkClosed(); checkClosed();
if (autoCommit && !session.getAutoCommit()) {
commit();
}
session.setAutoCommit(autoCommit); session.setAutoCommit(autoCommit);
} catch (Exception e) { } catch (Exception e) {
throw logAndConvert(e); throw logAndConvert(e);
...@@ -417,8 +416,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -417,8 +416,7 @@ public class JdbcConnection extends TraceObject implements Connection {
* Gets the current setting for auto commit. * Gets the current setting for auto commit.
* *
* @return true for on, false for off * @return true for on, false for off
* @throws SQLException * @throws SQLException if the connection is closed
* if the connection is closed
*/ */
public synchronized boolean getAutoCommit() throws SQLException { public synchronized boolean getAutoCommit() throws SQLException {
try { try {
...@@ -431,11 +429,10 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -431,11 +429,10 @@ public class JdbcConnection extends TraceObject implements Connection {
} }
/** /**
* Commits the current transaction. This call has only an effect if * Commits the current transaction. This call has only an effect if auto
* auto commit is switched off. * commit is switched off.
* *
* @throws SQLException * @throws SQLException if the connection is closed
* if the connection is closed
*/ */
public synchronized void commit() throws SQLException { public synchronized void commit() throws SQLException {
try { try {
...@@ -453,11 +450,10 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -453,11 +450,10 @@ public class JdbcConnection extends TraceObject implements Connection {
} }
/** /**
* Rolls back the current transaction. This call has only an effect if * Rolls back the current transaction. This call has only an effect if auto
* auto commit is switched off. * commit is switched off.
* *
* @throws SQLException * @throws SQLException if the connection is closed
* if the connection is closed
*/ */
public synchronized void rollback() throws SQLException { public synchronized void rollback() throws SQLException {
try { try {
...@@ -492,8 +488,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -492,8 +488,7 @@ public class JdbcConnection extends TraceObject implements Connection {
* *
* @param sql the SQL statement with or without JDBC escape sequences * @param sql the SQL statement with or without JDBC escape sequences
* @return the translated statement * @return the translated statement
* @throws SQLException * @throws SQLException if the connection is closed
* if the connection is closed
*/ */
public String nativeSQL(String sql) throws SQLException { public String nativeSQL(String sql) throws SQLException {
try { try {
...@@ -506,13 +501,11 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -506,13 +501,11 @@ public class JdbcConnection extends TraceObject implements Connection {
} }
/** /**
* According to the JDBC specs, this * According to the JDBC specs, this setting is only a hint to the database
* setting is only a hint to the database to enable optimizations - it does * to enable optimizations - it does not cause writes to be prohibited.
* not cause writes to be prohibited.
* *
* @param readOnly ignored * @param readOnly ignored
* @throws SQLException * @throws SQLException if the connection is closed
* if the connection is closed
*/ */
public void setReadOnly(boolean readOnly) throws SQLException { public void setReadOnly(boolean readOnly) throws SQLException {
try { try {
...@@ -529,8 +522,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -529,8 +522,7 @@ public class JdbcConnection extends TraceObject implements Connection {
* Returns true if the database is read-only. * Returns true if the database is read-only.
* *
* @return if the database is read-only * @return if the database is read-only
* @throws SQLException * @throws SQLException if the connection is closed
* if the connection is closed
*/ */
public boolean isReadOnly() throws SQLException { public boolean isReadOnly() throws SQLException {
try { try {
...@@ -547,8 +539,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -547,8 +539,7 @@ public class JdbcConnection extends TraceObject implements Connection {
} }
/** /**
* Set the default catalog name. * Set the default catalog name. This call is ignored.
* This call is ignored.
* *
* @param catalog ignored * @param catalog ignored
* @throws SQLException if the connection is closed * @throws SQLException if the connection is closed
...@@ -807,8 +798,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -807,8 +798,7 @@ public class JdbcConnection extends TraceObject implements Connection {
* Gets the type map. * Gets the type map.
* *
* @return null * @return null
* @throws SQLException * @throws SQLException if the connection is closed
* if the connection is closed
*/ */
public Map<String, Class<?>> getTypeMap() throws SQLException { public Map<String, Class<?>> getTypeMap() throws SQLException {
try { try {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论