1 package org.springframework.samples.jpetstore.dao.ibatis; 2 3 import org.springframework.dao.DataAccessException; 4 import org.springframework.dao.DataRetrievalFailureException; 5 import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 6 7 public class SqlMapSequenceDao extends SqlMapClientDaoSupport { 8 9 16 public int getNextId(String name) throws DataAccessException { 17 Sequence sequence = new Sequence(name, -1); 18 sequence = (Sequence) getSqlMapClientTemplate().queryForObject("getSequence", sequence); 19 if (sequence == null) { 20 throw new DataRetrievalFailureException("Error: A null sequence was returned from the database (could not get next " + 21 name + " sequence)."); 22 } 23 Object parameterObject = new Sequence(name, sequence.getNextId() + 1); 24 getSqlMapClientTemplate().update("updateSequence", parameterObject, 1); 25 return sequence.getNextId(); 26 } 27 } 28 | Popular Tags |