@Service Ŭ·¡½º¿¡¼ ¾Æ·¡¿Í °°ÀÌ ¸Þ¼Òµå¿¡ Æ®·£Àè¼Ç ¾î³ëÅ×À̼ÇÀ» ¼±¾ðÇÏ¿´½À´Ï´Ù.
@Transactional
@Override
public void insertUserStpltAgreeMgt(String userId, String clauseCode, String ipAddr)
throws SbcApiServiceException {
try {
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("userId", userId);
params.put("cretIpadr", ipAddr);
params.put("amdIpadr", ipAddr);
params.put("agreeYn", "Y");
String[] codes = clauseCode.split(",");
for(String s : codes) {
params.put("stpltCd", s);
iUserStpltAgreeMgtDao.insertUserStpltAgreeMgt(params);
throw new SbcApiServiceException("test", null, SbcException.DB_ERROR);
}
} catch (SQLException e) {
throw new SbcApiServiceException(e.getMessage(), e, SbcException.DB_ERROR);
}
}
for ¹®À» 6¹øÁ¤µµ µ¹°Ô µÇ´Âµ¥ ù¹ø° for¹® µ¹°í Exception ¹ß»ý½ÃÄ×À»¶§,
Æ®·£Àè¼ÇÀÌ Á¦´ë·Î °É·ÁÀÖÀ¸¸é ¾Õ¼ insert ¹®¿¡¼ µé¾î°£ µ¥ÀÌÅÍ°¡ roll back µÇ¾î¾ß Çϴµ¥ roll back ÁøÇàÀÌ µÇÁö ¾Ê´õ¶ó°í¿ä;
servlet.xml ÂÊ ¼³Á¤Àº ¾Æ·¡¿Í °°ÀÌ Ãß°¡ÇÏ¿´½À´Ï´Ù.
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
<tx:annotation-driven transaction-manager="transactionManager" />
Æ®·£Àè¼Ç ¾î³ëÅ×À̼ÇÀ» »ç¿ëÇϱâ À§ÇØ Á¦°¡ Ãß°¡·Î È®ÀÎÇغÁ¾ß ÇÏ´Â°Ô ¾î¶²°ÍÀÌ ÀÖ´ÂÁö ¾Ë°í½Í½À´Ï´Ù.
ÀÌ¿Í º°µµ·Î ibatis Æ®·£Àè¼ÇÀ» »ç¿ëÇÏ¿´À»¶§´Â Á¤»óµ¿ÀÛÀ» È®ÀÎÇÏ¿´½À´Ï´Ù.
¾Æ·¡¿Í °°Àº °æ¿ì exception ¹ß»ý ½Ã ¾Õ¼ insert µÈ µ¥ÀÌÅÍ°¡ rollback µÇ´Â°ÍÀ» È®ÀÎ.
SqlMapClient client = gen.session();
try {
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("userId", userId);
params.put("cretIpadr", ipAddr);
params.put("amdIpadr", ipAddr);
params.put("agreeYn", "Y");
String[] codes = clauseCode.split(",");
client.startTransaction();
client.startBatch();
for(String s : codes) {
params.put("stpltCd", s);
iUserStpltAgreeMgtDao.insertUserStpltAgreeMgt(params);
throw new SQLException("");
}
client.executeBatch();
client.commitTransaction();
} catch (SQLException e) {
try {
client.endTransaction();
} catch (SQLException e1) {
e1.printStackTrace();
}
throw new SbcApiServiceException(e.getMessage(), e, SbcException.DB_ERROR);
}
* ¾î³ëÅ×ÀÌ¼Ç ¿É¼ÇÀ¸·Î ¾Æ·¡¿Í°°ÀÌ Çغ¸¾Æµµ ¶È°°ÀÌ ·Ñ¹éÀÌ ¾ÈµË´Ï´Ù..
@Transactional(rollbackFor=SbcApiServiceException.class)
@Transactional(rollbackFor={SbcApiServiceException.class})
Áú¹® | 1765¸íÀÌ Àоú¾î¿ä. 3.145.38.117