My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.apache.ibatis.transaction.jdbc;

import org.apache.ibatis.transaction.Transaction;
import org.apache.ibatis.transaction.TransactionException;

import java.sql.Connection;
import java.sql.SQLException;

public class JdbcTransaction implements Transaction {

protected Connection connection;

public JdbcTransaction(Connection connection, boolean desiredAutoCommit) {
this.connection = connection;
setDesiredAutoCommit(desiredAutoCommit);
}

public Connection getConnection() {
return connection;
}

public void commit() throws SQLException {
if (!connection.getAutoCommit()) {
connection.commit();
}
}

public void rollback() throws SQLException {
if (!connection.getAutoCommit()) {
connection.rollback();
}
}

public void close() throws SQLException {
resetAutoCommit();
connection.close();
}

protected void setDesiredAutoCommit(boolean desiredAutoCommit) {
try {
if (connection.getAutoCommit() != desiredAutoCommit) {
connection.setAutoCommit(desiredAutoCommit);
}
} catch (SQLException e) {
// Only a very poorly implemented driver would fail here,
// and there's not much we can do about that.
throw new TransactionException("Error configuring AutoCommit. " +
"Your driver may not support getAutoCommit() or setAutoCommit(). " +
"Requested setting: " + desiredAutoCommit + ". Cause: " + e, e);
}
}

protected void resetAutoCommit() {
try {
if (!connection.getAutoCommit()) {
// for compatibility we always use true, as some drivers don't like being left in "false" mode.
connection.setAutoCommit(true);
}
} catch (SQLException e) {
// Only a very poorly implemented driver would fail here,
// and there's not much we can do about that.
throw new TransactionException("Error configuring AutoCommit. " +
"Your driver may not support getAutoCommit() or setAutoCommit(). Cause: " + e, e);
}
}

}

Change log

r3491 by simone.tripodi on Dec 31, 2010   Diff
[maven-release-plugin]  copy for tag
mybatis-3.0.4
Go to: 

Older revisions

r1949 by clinton.begin on May 16, 2010   Diff
Moved
mirror/ibatis/java/ibatis-3/trunk to
trunk.
r1898 by cbegin on Mar 28, 2010   Diff
Moved ibatis/java/ibatis-3/temp/ibatis
-3-core to ibatis/java/ibatis-3/trunk.
r1897 by cbegin on Mar 28, 2010   Diff
Renamed trunk
(ibatis/java/ibatis-3/trunk) to temp.
All revisions of this file

File info

Size: 2027 bytes, 67 lines
Powered by Google Project Hosting