1、如果增删改抛异常,则需要rollback(),在try块中commit();
/**
* description: 刪除數據
*
* @param iBaseVO
* IBaseVO
* @param locale
* String
* @throws BusiException
* 業務異常
* @throws DbAccessException
* 數據庫訪問異常
*/
private void del(IBaseVO iBaseVO, String locale) throws BusiException {
if (LOG.isDebugEnabled()) {
LOG.debug( " [accountYmService] " + " [FUNCTION:delAccountYmTemp] "
+ " [Param iBaseVO: " + iBaseVO + " ][begin] " );
}
AccountYmVO accountYmVO = (AccountYmVO) iBaseVO;
EntityManager mgr = initiate();
AccountYmTempDao ayTempDao = AccountYmTempDao.getInstance(mgr);
ParaMenuDataDao pmdDao = ParaMenuDataDao.getInstance(mgr);
EntityTransaction tx = null ;
tx = mgr.beginTransaction();
try {
// 插入一筆數據到參數設定表
ParaMenuData pmData = new ParaMenuData();
pmData.setOperationCode(Constant.PROCESS_STATUS_DEL);
pmData.setCrtDate(accountYmVO.getCrtDate());
pmData.setCrtId(accountYmVO.getCrtId());
pmData.setCrtPgm(accountYmVO.getCrtPgm());
pmData.setCrtTime(accountYmVO.getCrtTime());
pmData.setHandleStatus(Constant.PROCESS_STATUS_NOPROCESS);
pmData.setMemo( "" );
pmData.setParaCode(Constant.PARACODE_ACCOUNT_YM);
pmData.setSendDate(accountYmVO.getCrtDate());
pmData.setSendId(accountYmVO.getCrtId());
pmdDao.create(pmData);
// 插入一筆數據到臨時表
this .createTemp(ayTempDao, accountYmVO, pmData.getSeqno(),
accountYmVO.getEndDate());
tx.commit();
} catch (DbAccessException e) {
LOG.error( " [FUNCTION:del()] "
+ " [DbAccessException] " , e);
tx.rollback();
throw new BusiException(ExceptionConstant.DATABASE_ADD_EXCEPTION,
"" , locale, ExceptionConstant.INFO_TYPE);
}
}
* description: 刪除數據
*
* @param iBaseVO
* IBaseVO
* @param locale
* String
* @throws BusiException
* 業務異常
* @throws DbAccessException
* 數據庫訪問異常
*/
private void del(IBaseVO iBaseVO, String locale) throws BusiException {
if (LOG.isDebugEnabled()) {
LOG.debug( " [accountYmService] " + " [FUNCTION:delAccountYmTemp] "
+ " [Param iBaseVO: " + iBaseVO + " ][begin] " );
}
AccountYmVO accountYmVO = (AccountYmVO) iBaseVO;
EntityManager mgr = initiate();
AccountYmTempDao ayTempDao = AccountYmTempDao.getInstance(mgr);
ParaMenuDataDao pmdDao = ParaMenuDataDao.getInstance(mgr);
EntityTransaction tx = null ;
tx = mgr.beginTransaction();
try {
// 插入一筆數據到參數設定表
ParaMenuData pmData = new ParaMenuData();
pmData.setOperationCode(Constant.PROCESS_STATUS_DEL);
pmData.setCrtDate(accountYmVO.getCrtDate());
pmData.setCrtId(accountYmVO.getCrtId());
pmData.setCrtPgm(accountYmVO.getCrtPgm());
pmData.setCrtTime(accountYmVO.getCrtTime());
pmData.setHandleStatus(Constant.PROCESS_STATUS_NOPROCESS);
pmData.setMemo( "" );
pmData.setParaCode(Constant.PARACODE_ACCOUNT_YM);
pmData.setSendDate(accountYmVO.getCrtDate());
pmData.setSendId(accountYmVO.getCrtId());
pmdDao.create(pmData);
// 插入一筆數據到臨時表
this .createTemp(ayTempDao, accountYmVO, pmData.getSeqno(),
accountYmVO.getEndDate());
tx.commit();
} catch (DbAccessException e) {
LOG.error( " [FUNCTION:del()] "
+ " [DbAccessException] " , e);
tx.rollback();
throw new BusiException(ExceptionConstant.DATABASE_ADD_EXCEPTION,
"" , locale, ExceptionConstant.INFO_TYPE);
}
}
2、如果是查询,则不需要rollback(),只需要在finally块中commit()。
/**
* 根據seqno查詢臨時表的待審核記錄
*
* @param seqno
* 序號
* @param locale
* String
* @return List
* @throws BusiException
*/
public List qryBySeqno( long seqno, String locale) throws BusiException {
ArrayList al = null ;
if (LOG.isDebugEnabled()) {
LOG.debug( " [AccountYmService] "
+ " [FUNCTION:qryAccountYmData][Param seqno: " + seqno
+ " ][begin] " );
}
EntityManager mgr = initiate();
AccountYmTempDao ayTempDao = AccountYmTempDao.getInstance(mgr);
EntityTransaction tx = null ;
AccountYmVO accountYmVO;
tx = mgr.beginTransaction();
List list;
try {
list = ayTempDao.selectBySeqno(seqno);
tx.commit();
} catch (DbAccessException e) {
LOG.error( " [FUNCTION:qryBySeqno()] " + " [DbAccessException] " , e);
tx.rollback();
throw new BusiException(
ExceptionConstant.DATABASE_ACCESS_EXCEPTION, "" , locale,
ExceptionConstant.INFO_TYPE);
}
if (list != null && list.size() > 0 ) {
if (LOG.isDebugEnabled()) {
LOG.debug( " [FUNCTION:qryBySeqno()] " + " select list success! " );
}
al = new ArrayList();
try {
AccountYmTemp accountYmTemp;
for ( int i = 0 ; i < list.size(); i ++ ) {
accountYmVO = new AccountYmVO();
accountYmTemp = (AccountYmTemp) list.get(i);
BeanUtils.copyProperties(accountYmVO, accountYmTemp);
BeanUtils
.copyProperties(accountYmVO, accountYmTemp.getId());
al.add(accountYmVO);
}
} catch (InvocationTargetException e) {
LOG.error( " [FUNCTION:qryBySeqno()] "
+ " [InvocationTargetException] " , e);
tx.rollback();
throw new BusiException(
ExceptionConstant.INVOCATION_TARGET_EXCEPTION, "" ,
locale, ExceptionConstant.INFO_TYPE);
} catch (IllegalAccessException e) {
LOG.error( " [FUNCTION:qryBySeqno()] "
+ " [IllegalAccessException] " , e);
tx.rollback();
throw new BusiException(
ExceptionConstant.ILLEGAL_ACCESS_EXCEPTION, "" , locale,
ExceptionConstant.INFO_TYPE);
} finally {
tx.commit();
}
} else {
tx.commit();
throw new BusiException(ExceptionConstant.NOT_FOUND_SEQNO_IN_TEMP,
"" , locale, ExceptionConstant.INFO_TYPE);
}
return al;
}
* 根據seqno查詢臨時表的待審核記錄
*
* @param seqno
* 序號
* @param locale
* String
* @return List
* @throws BusiException
*/
public List qryBySeqno( long seqno, String locale) throws BusiException {
ArrayList al = null ;
if (LOG.isDebugEnabled()) {
LOG.debug( " [AccountYmService] "
+ " [FUNCTION:qryAccountYmData][Param seqno: " + seqno
+ " ][begin] " );
}
EntityManager mgr = initiate();
AccountYmTempDao ayTempDao = AccountYmTempDao.getInstance(mgr);
EntityTransaction tx = null ;
AccountYmVO accountYmVO;
tx = mgr.beginTransaction();
List list;
try {
list = ayTempDao.selectBySeqno(seqno);
tx.commit();
} catch (DbAccessException e) {
LOG.error( " [FUNCTION:qryBySeqno()] " + " [DbAccessException] " , e);
tx.rollback();
throw new BusiException(
ExceptionConstant.DATABASE_ACCESS_EXCEPTION, "" , locale,
ExceptionConstant.INFO_TYPE);
}
if (list != null && list.size() > 0 ) {
if (LOG.isDebugEnabled()) {
LOG.debug( " [FUNCTION:qryBySeqno()] " + " select list success! " );
}
al = new ArrayList();
try {
AccountYmTemp accountYmTemp;
for ( int i = 0 ; i < list.size(); i ++ ) {
accountYmVO = new AccountYmVO();
accountYmTemp = (AccountYmTemp) list.get(i);
BeanUtils.copyProperties(accountYmVO, accountYmTemp);
BeanUtils
.copyProperties(accountYmVO, accountYmTemp.getId());
al.add(accountYmVO);
}
} catch (InvocationTargetException e) {
LOG.error( " [FUNCTION:qryBySeqno()] "
+ " [InvocationTargetException] " , e);
tx.rollback();
throw new BusiException(
ExceptionConstant.INVOCATION_TARGET_EXCEPTION, "" ,
locale, ExceptionConstant.INFO_TYPE);
} catch (IllegalAccessException e) {
LOG.error( " [FUNCTION:qryBySeqno()] "
+ " [IllegalAccessException] " , e);
tx.rollback();
throw new BusiException(
ExceptionConstant.ILLEGAL_ACCESS_EXCEPTION, "" , locale,
ExceptionConstant.INFO_TYPE);
} finally {
tx.commit();
}
} else {
tx.commit();
throw new BusiException(ExceptionConstant.NOT_FOUND_SEQNO_IN_TEMP,
"" , locale, ExceptionConstant.INFO_TYPE);
}
return al;
}