mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
commit
648bac61fc
@ -224,15 +224,12 @@ public class FlexDataSource extends AbstractDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class ConnectionHandler implements InvocationHandler {
|
private static class ConnectionHandler implements InvocationHandler {
|
||||||
|
|
||||||
private static final String[] proxyMethods = new String[]{"commit", "rollback", "close", "setAutoCommit"};
|
private static final String[] proxyMethods = new String[]{"commit", "rollback", "close", "setAutoCommit"};
|
||||||
private final Connection original;
|
private final Connection original;
|
||||||
private final String xid;
|
private final String xid;
|
||||||
|
|
||||||
public ConnectionHandler(Connection original, String xid) {
|
public ConnectionHandler(Connection original, String xid) {
|
||||||
|
|
||||||
closeAutoCommit(original);
|
closeAutoCommit(original);
|
||||||
|
|
||||||
this.original = original;
|
this.original = original;
|
||||||
this.xid = xid;
|
this.xid = xid;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
package com.mybatisflex.spring;
|
package com.mybatisflex.spring;
|
||||||
|
|
||||||
import com.mybatisflex.core.datasource.FlexDataSource;
|
import com.mybatisflex.core.datasource.FlexDataSource;
|
||||||
|
import com.mybatisflex.core.transaction.TransactionContext;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@ -30,7 +31,7 @@ public class FlexSpringTransaction implements Transaction {
|
|||||||
|
|
||||||
DataSource dataSource;
|
DataSource dataSource;
|
||||||
|
|
||||||
boolean isTransaction;
|
boolean isTransaction =false;
|
||||||
|
|
||||||
TransactionIsolationLevel level;
|
TransactionIsolationLevel level;
|
||||||
boolean autoCommit;
|
boolean autoCommit;
|
||||||
@ -46,6 +47,10 @@ public class FlexSpringTransaction implements Transaction {
|
|||||||
@Override
|
@Override
|
||||||
public Connection getConnection() throws SQLException {
|
public Connection getConnection() throws SQLException {
|
||||||
if (dataSource instanceof FlexDataSource) {
|
if (dataSource instanceof FlexDataSource) {
|
||||||
|
this.autoCommit = this.dataSource.getConnection().getAutoCommit();
|
||||||
|
if ( TransactionContext.getXID() != null){
|
||||||
|
isTransaction = true;
|
||||||
|
}
|
||||||
return dataSource.getConnection();
|
return dataSource.getConnection();
|
||||||
}else{
|
}else{
|
||||||
throw new SQLException("The datasource must be FlextDataSource");
|
throw new SQLException("The datasource must be FlextDataSource");
|
||||||
@ -56,13 +61,18 @@ public class FlexSpringTransaction implements Transaction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void commit() throws SQLException {
|
public void commit() throws SQLException {
|
||||||
|
if (!isTransaction && !autoCommit){
|
||||||
getConnection().commit();
|
getConnection().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rollback() throws SQLException {
|
public void rollback() throws SQLException {
|
||||||
|
if (!isTransaction && !autoCommit){
|
||||||
getConnection().rollback();
|
getConnection().rollback();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws SQLException {
|
public void close() throws SQLException {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user