Line | |
---|
1 |
/** |
---|
2 |
* |
---|
3 |
*/ |
---|
4 |
package org.springframework.samples.kyuriboard.dao.ibatis; |
---|
5 |
|
---|
6 |
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; |
---|
7 |
import org.springframework.dao.DataAccessException; |
---|
8 |
import org.springframework.dao.DataRetrievalFailureException; |
---|
9 |
|
---|
10 |
/** |
---|
11 |
* @author DAMI(archy712@naver.com) |
---|
12 |
* |
---|
13 |
*/ |
---|
14 |
public class SqlMapSequenceDao extends SqlMapClientDaoSupport { |
---|
15 |
|
---|
16 |
/** |
---|
17 |
* 씨퀀스의 다음 ID를 얻어오고, 해당 시퀀스의 번호를 1 증가 시킨다. |
---|
18 |
* @param name 해당 시퀀스 명 |
---|
19 |
* @return 시퀀스의 증가된 값 |
---|
20 |
* @throws DataAccessException 해당 시퀀스 Row를 찾을 수 없슴. |
---|
21 |
*/ |
---|
22 |
public int getNextId(String name) throws DataAccessException { |
---|
23 |
Sequence sequence = new Sequence(name, -1); |
---|
24 |
sequence = (Sequence) getSqlMapClientTemplate().queryForObject("getSequence", sequence); |
---|
25 |
if (sequence == null) { |
---|
26 |
throw new DataRetrievalFailureException("Could not get next value of sequence [" + name + "] : sequence does not exist"); |
---|
27 |
} |
---|
28 |
Object parameterObject = new Sequence(name, sequence.getNextId() + 1); |
---|
29 |
getSqlMapClientTemplate().update("updateSequence", parameterObject, 1); |
---|
30 |
return sequence.getNextId(); |
---|
31 |
} |
---|
32 |
|
---|
33 |
} |
---|