mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-06 14:15:50 +08:00
优化jdbc executor,增加日志打印
This commit is contained in:
@@ -16,14 +16,23 @@ import java.util.Objects;
|
||||
*/
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
public class DefaultJdbcExecutor extends AbstractJdbcSqlExecutor {
|
||||
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return DataSourceUtils.getConnection(DataSourceHolder.currentDataSource().getNative());
|
||||
DataSource dataSource = DataSourceHolder.currentDataSource().getNative();
|
||||
Connection connection = DataSourceUtils.getConnection(dataSource);
|
||||
boolean isConnectionTransactional = DataSourceUtils.isConnectionTransactional(connection, dataSource);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("DataSource ({}) JDBC Connection [{}] will {}be managed by Spring", DataSourceHolder.switcher().currentDataSourceId(), connection, (isConnectionTransactional ? "" : "not "));
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseConnection(Connection connection) throws SQLException {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Releasing DataSource ({}) JDBC Connection [{}]", DataSourceHolder.switcher().currentDataSourceId(), connection);
|
||||
}
|
||||
DataSourceUtils.releaseConnection(connection, DataSourceHolder.currentDataSource().getNative());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,12 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.jtds</groupId>
|
||||
<artifactId>jtds</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -20,11 +21,20 @@ import java.sql.SQLException;
|
||||
public class JtaJdbcSqlExecutor extends AbstractJdbcSqlExecutor {
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return DataSourceUtils.getConnection(DataSourceHolder.currentDataSource().getNative());
|
||||
DataSource dataSource = DataSourceHolder.currentDataSource().getNative();
|
||||
Connection connection = DataSourceUtils.getConnection(dataSource);
|
||||
boolean isConnectionTransactional = DataSourceUtils.isConnectionTransactional(connection, dataSource);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("DataSource ({}) JDBC Connection [{}] will {}be managed by Spring", DataSourceHolder.switcher().currentDataSourceId(), connection, (isConnectionTransactional ? "" : "not "));
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseConnection(Connection connection) throws SQLException {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Releasing DataSource ({}) JDBC Connection [{}]", DataSourceHolder.switcher().currentDataSourceId(), connection);
|
||||
}
|
||||
DataSourceUtils.releaseConnection(connection, DataSourceHolder.currentDataSource().getNative());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user