/* *

ClassName: OLDCodeBLS

*

Description: LDCodeBLS类文件

*

Copyright: Copyright (c) 2002

*

Company: sinosoft

* @Database: LIS * @CreateDate:2003-06-21 */ package com.sinosoft.lis.sys; import com.sinosoft.lis.i18n.I18nMessage; import com.sinosoft.lis.db.LDCodeDB; import com.sinosoft.lis.schema.LDCodeSchema; import com.sinosoft.utility.CError; import com.sinosoft.utility.CErrors; import com.sinosoft.utility.DBConnPool; import com.sinosoft.utility.VData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.Connection; import java.sql.SQLException; public class ALDCodeBLS { private static final Logger logger = LoggerFactory.getLogger(ALDCodeBLS.class); /** 错误处理类,每个需要错误处理的类中都放置该类 */ public CErrors mErrors = new CErrors(); /** 数据操作字符串 */ private String mOperate; public ALDCodeBLS() { } /** * 传输数据的公共方法 */ public boolean submitData(VData cInputData, String cOperate) { boolean tReturn = false; // 将操作数据拷贝到本类中 this.mOperate = cOperate; logger.debug("Start LDCodeBLS Submit..."); if (this.mOperate.equals("INSERT||MAIN")) { tReturn = saveLDCode(cInputData); } if (this.mOperate.equals("DELETE||MAIN")) { tReturn = deleteLDCode(cInputData); } if (this.mOperate.equals("UPDATE||MAIN")) { tReturn = updateLDCode(cInputData); } if (tReturn) { logger.debug(" sucessful"); } else { logger.debug("Save failed"); } logger.debug("End LDCodeBLS Submit..."); return tReturn; } /** * 保存函数 */ private boolean saveLDCode(VData mInputData) { boolean tReturn = true; logger.debug("Start Save..."); Connection conn; conn = null; conn = DBConnPool.getConnection(); if (conn == null) { // @@错误处理 CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "saveData"; tError.errorMessage(new I18nMessage("数据库连接失败!", "LIS-06519")); this.mErrors.addOneError(tError); return false; } try { conn.setAutoCommit(false); logger.debug("Start 保存..."); LDCodeDB tLDCodeDB = new LDCodeDB(conn); tLDCodeDB.setSchema(mInputData.get(LDCodeSchema.class, 0)); if (!tLDCodeDB.insert()) { // @@错误处理 this.mErrors.copyAllErrors(tLDCodeDB.mErrors); CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "saveData"; tError.errorMessage(new I18nMessage("数据保存失败!", "LIS-06914")); this.mErrors.addOneError(tError); conn.rollback(); // 移除此处conn.close(),移至finally统一处理 return false; } conn.commit(); // 移除此处conn.close(),移至finally统一处理 } catch (Exception ex) { // @@错误处理 CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "submitData"; tError.errorMessage(new I18nMessage( ex.toString(), null)); this.mErrors.addOneError(tError); tReturn = false; try { conn.rollback(); // 异常时回滚 } catch (Exception e) { } } finally { // 集中处理所有连接关闭操作 try { // 仅关闭未关闭的连接 conn.close(); } catch (SQLException e) { logger.error("关闭数据库连接失败",e); // 补充错误日志记录,保持原有错误处理风格 CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "saveLDCode"; tError.errorMessage(new I18nMessage("关闭数据库连接失败", null)); this.mErrors.addOneError(tError); logger.error("saveLDCode: 关闭连接失败", e); } } return tReturn; } /** * 保存函数 */ private boolean deleteLDCode(VData mInputData) { boolean tReturn = true; logger.debug("Start Save..."); Connection conn; conn = null; conn = DBConnPool.getConnection(); if (conn == null) { // @@错误处理 CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "saveData"; tError.errorMessage(new I18nMessage("数据库连接失败!", "LIS-06519")); this.mErrors.addOneError(tError); return false; } try { conn.setAutoCommit(false); logger.debug("Start 保存..."); LDCodeDB tLDCodeDB = new LDCodeDB(conn); tLDCodeDB.setSchema(mInputData.get(LDCodeSchema.class, 0)); if (!tLDCodeDB.delete()) { // @@错误处理 this.mErrors.copyAllErrors(tLDCodeDB.mErrors); CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "saveData"; tError.errorMessage(new I18nMessage("数据删除失败!", "LIS-07063")); this.mErrors.addOneError(tError); conn.rollback(); // 移除此处conn.close(),移至finally统一处理 return false; } conn.commit(); // 移除此处conn.close(),移至finally统一处理 } catch (Exception ex) { // @@错误处理 CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "submitData"; tError.errorMessage(new I18nMessage( ex.toString(), null)); this.mErrors.addOneError(tError); tReturn = false; try { conn.rollback(); // 移除此处conn.close(),移至finally统一处理 } catch (Exception e) { } } finally { // 集中处理所有连接关闭操作 try { conn.close(); } catch (SQLException e) { logger.error("关闭数据库连接失败",e); // 处理连接关闭异常,保持原有错误处理风格 CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "deleteLDCode"; tError.errorMessage(new I18nMessage("关闭数据库连接失败", null)); this.mErrors.addOneError(tError); logger.error("deleteLDCode: 关闭连接失败", e); } } return tReturn; } /** * 保存函数 */ private boolean updateLDCode(VData mInputData) { boolean tReturn = true; logger.debug("Start Save..."); Connection conn; conn = null; conn = DBConnPool.getConnection(); if (conn == null) { CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "updateData"; tError.errorMessage(new I18nMessage("数据库连接失败!", "LIS-06519")); this.mErrors.addOneError(tError); return false; } try { conn.setAutoCommit(false); logger.debug("Start 保存..."); LDCodeDB tLDCodeDB = new LDCodeDB(conn); tLDCodeDB.setSchema(mInputData.get(LDCodeSchema.class, 0)); if (!tLDCodeDB.update()) { // @@错误处理 this.mErrors.copyAllErrors(tLDCodeDB.mErrors); CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "saveData"; tError.errorMessage(new I18nMessage("数据保存失败!", "LIS-06914")); this.mErrors.addOneError(tError); conn.rollback(); // 移除此处conn.close(),移至finally统一处理 return false; } conn.commit(); // 移除此处conn.close(),移至finally统一处理 } catch (Exception ex) { // @@错误处理 CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "submitData"; tError.errorMessage(new I18nMessage( ex.toString(), null)); this.mErrors.addOneError(tError); tReturn = false; try { conn.rollback(); // 移除此处conn.close(),移至finally统一处理 } catch (Exception e) { } } finally { // 集中处理所有连接关闭操作 if (conn != null) { try { conn.close(); } catch (SQLException e) { logger.error("关闭数据库连接失败",e); // 处理连接关闭异常,保持原有错误处理风格 CError tError = new CError(); tError.moduleName = "LDCodeBLS"; tError.functionName = "updateLDCode"; tError.errorMessage(new I18nMessage("关闭数据库连接失败", null)); this.mErrors.addOneError(tError); logger.error("updateLDCode: 关闭连接失败", e); } } } return tReturn; } }