|
@@ -185,18 +185,18 @@ public class Config {
|
|
|
/**
|
|
/**
|
|
|
* Support transaction with Transaction interceptor
|
|
* Support transaction with Transaction interceptor
|
|
|
*/
|
|
*/
|
|
|
- public final void setThreadLocalConnection(Connection connection) {
|
|
|
|
|
|
|
+ public void setThreadLocalConnection(Connection connection) {
|
|
|
threadLocal.set(connection);
|
|
threadLocal.set(connection);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public final void removeThreadLocalConnection() {
|
|
|
|
|
|
|
+ public void removeThreadLocalConnection() {
|
|
|
threadLocal.remove();
|
|
threadLocal.remove();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Get Connection. Support transaction if Connection in ThreadLocal
|
|
* Get Connection. Support transaction if Connection in ThreadLocal
|
|
|
*/
|
|
*/
|
|
|
- public final Connection getConnection() throws SQLException {
|
|
|
|
|
|
|
+ public Connection getConnection() throws SQLException {
|
|
|
Connection conn = threadLocal.get();
|
|
Connection conn = threadLocal.get();
|
|
|
if (conn != null)
|
|
if (conn != null)
|
|
|
return conn;
|
|
return conn;
|
|
@@ -207,14 +207,14 @@ public class Config {
|
|
|
* Helps to implement nested transaction.
|
|
* Helps to implement nested transaction.
|
|
|
* Tx.intercept(...) and Db.tx(...) need this method to detected if it in nested transaction.
|
|
* Tx.intercept(...) and Db.tx(...) need this method to detected if it in nested transaction.
|
|
|
*/
|
|
*/
|
|
|
- public final Connection getThreadLocalConnection() {
|
|
|
|
|
|
|
+ public Connection getThreadLocalConnection() {
|
|
|
return threadLocal.get();
|
|
return threadLocal.get();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Return true if current thread in transaction.
|
|
* Return true if current thread in transaction.
|
|
|
*/
|
|
*/
|
|
|
- public final boolean isInTransaction() {
|
|
|
|
|
|
|
+ public boolean isInTransaction() {
|
|
|
return threadLocal.get() != null;
|
|
return threadLocal.get() != null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -222,7 +222,7 @@ public class Config {
|
|
|
* Close ResultSet、Statement、Connection
|
|
* Close ResultSet、Statement、Connection
|
|
|
* ThreadLocal support declare transaction.
|
|
* ThreadLocal support declare transaction.
|
|
|
*/
|
|
*/
|
|
|
- public final void close(ResultSet rs, Statement st, Connection conn) {
|
|
|
|
|
|
|
+ public void close(ResultSet rs, Statement st, Connection conn) {
|
|
|
if (rs != null) {try {rs.close();} catch (SQLException e) {LogKit.error(e.getMessage(), e);}}
|
|
if (rs != null) {try {rs.close();} catch (SQLException e) {LogKit.error(e.getMessage(), e);}}
|
|
|
if (st != null) {try {st.close();} catch (SQLException e) {LogKit.error(e.getMessage(), e);}}
|
|
if (st != null) {try {st.close();} catch (SQLException e) {LogKit.error(e.getMessage(), e);}}
|
|
|
|
|
|
|
@@ -232,7 +232,7 @@ public class Config {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public final void close(Statement st, Connection conn) {
|
|
|
|
|
|
|
+ public void close(Statement st, Connection conn) {
|
|
|
if (st != null) {try {st.close();} catch (SQLException e) {LogKit.error(e.getMessage(), e);}}
|
|
if (st != null) {try {st.close();} catch (SQLException e) {LogKit.error(e.getMessage(), e);}}
|
|
|
|
|
|
|
|
if (threadLocal.get() == null) { // in transaction if conn in threadlocal
|
|
if (threadLocal.get() == null) { // in transaction if conn in threadlocal
|
|
@@ -241,7 +241,7 @@ public class Config {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public final void close(Connection conn) {
|
|
|
|
|
|
|
+ public void close(Connection conn) {
|
|
|
if (threadLocal.get() == null) // in transaction if conn in threadlocal
|
|
if (threadLocal.get() == null) // in transaction if conn in threadlocal
|
|
|
if (conn != null)
|
|
if (conn != null)
|
|
|
try {conn.close();} catch (SQLException e) {throw new ActiveRecordException(e);}
|
|
try {conn.close();} catch (SQLException e) {throw new ActiveRecordException(e);}
|