From 5d2411baa5ae84890430a2d7e360fc6777054797 Mon Sep 17 00:00:00 2001 From: shicf <shi_chongfu@163.com> Date: 星期一, 08 九月 2025 11:44:48 +0800 Subject: [PATCH] 判断事务是否自动提交,执行提交 ,添加日志输出 --- product-server-datasource/src/main/java/com/product/datasource/dao/impl/OracleDaoImpl.java | 21 +++++++++++++-------- 1 files changed, 13 insertions(+), 8 deletions(-) diff --git a/product-server-datasource/src/main/java/com/product/datasource/dao/impl/OracleDaoImpl.java b/product-server-datasource/src/main/java/com/product/datasource/dao/impl/OracleDaoImpl.java index 56db4d0..3ecf140 100644 --- a/product-server-datasource/src/main/java/com/product/datasource/dao/impl/OracleDaoImpl.java +++ b/product-server-datasource/src/main/java/com/product/datasource/dao/impl/OracleDaoImpl.java @@ -7,7 +7,6 @@ import com.product.core.config.Global; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; -import com.product.core.exception.BaseException; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.datasource.config.DataBaseType; import com.product.datasource.config.ErrorCode; @@ -19,8 +18,6 @@ import com.product.datasource.utils.BatchUtil; import org.apache.commons.lang3.StringUtils; -import java.lang.ref.PhantomReference; -import java.lang.ref.WeakReference; import java.sql.*; import java.util.List; @@ -65,7 +62,7 @@ } private void info(String message) { - if (this.outLog) { + if (this.outLog || "true".equals(Global.getSystemConfig("log.sql.print", "false")) ) { SpringMVCContextHolder.getSystemLogger().info(message); } } @@ -89,7 +86,7 @@ } return this.connection; } catch (Exception e) { - e.printStackTrace(); + SpringMVCContextHolder.getSystemLogger().error(e); throw new BaseException(ErrorCode.GET_CONNECTION_FAIL, e); } } @@ -138,6 +135,7 @@ ResultSet resultSet = pst.executeQuery(); return loaddingDataList(resultSet); } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); SpringMVCContextHolder.getSystemLogger().error("EXECUTE_ERROR_SQL:\n" + sql); throw new BaseException(ErrorCode.GET_LIST_FAIL, e); } @@ -427,6 +425,7 @@ pst.execute(); } catch (Exception e) { e.printStackTrace(); + SpringMVCContextHolder.getSystemLogger().error(e); throw new BaseException(ErrorCode.ADD_RECORD_FAIL, e); } } @@ -486,6 +485,7 @@ info("鎵ц鎵归噺鎻愪氦鏁版嵁瀹屾垚锛屽叡鎻愪氦 " + data.getRows() + " 鏉�,鑰楁椂锛�" + timer.intervalSecond() + " 绉� 锛�"); pst.clearBatch(); } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); throw e; } finally { connection.setAutoCommit(true); @@ -532,11 +532,13 @@ } return pst.executeUpdate(); } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); throw e; } finally { // this.closeConnection(); } } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); throw new BaseException(ErrorCode.UPDATE_BATCH_ERROR, e); } } @@ -597,7 +599,7 @@ int[] ints = pst.executeBatch(); info("鎵ц鎵归噺鎻愪氦鏁版嵁瀹屾垚锛屽叡鎻愪氦 " + data.getRows() + " 鏉�,鑰楁椂锛�" + timer.intervalSecond() + " 绉� 锛�"); pst.clearBatch(); - if (isCommit) { + if (isCommit && !connection.getAutoCommit()) { connection.commit(); } int successCount = 0; @@ -610,14 +612,16 @@ batchResultEntity.setConnection(connection); return batchResultEntity; } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); throw e; } finally { - if (isCommit) { + if (isCommit && !connection.isClosed() && !connection.getAutoCommit()) { connection.setAutoCommit(true); } -// this.closeConnection(); +// this.closeConnection(); } } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); throw new BaseException(ErrorCode.UPDATE_BATCH_ERROR, e); } } @@ -688,6 +692,7 @@ } return pst.executeUpdate(); } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); throw new OracleDaoImpl.BaseException(ErrorCode.EXECUTE_SQL_FAIL, e); } } -- Gitblit v1.9.2