1 6 package com.ibatis.jpetstore.persistence.sqlmapdao; 7 8 import com.ibatis.dao.client.DaoException; 9 import com.ibatis.dao.client.DaoManager; 10 import com.ibatis.jpetstore.domain.Sequence; 11 import com.ibatis.jpetstore.persistence.iface.SequenceDao; 12 13 public class SequenceSqlMapDao extends BaseSqlMapDao implements SequenceDao { 14 15 public SequenceSqlMapDao(DaoManager daoManager) { 16 super(daoManager); 17 } 18 19 29 public synchronized int getNextId(String name) { 30 Sequence sequence = new Sequence(name, -1); 31 32 sequence = (Sequence) queryForObject("getSequence", sequence); 33 if (sequence == null) { 34 throw new DaoException("Error: A null sequence was returned from the database (could not get next " + name + " sequence)."); 35 } 36 Object parameterObject = new Sequence(name, sequence.getNextId() + 1); 37 update("updateSequence", parameterObject); 38 39 return sequence.getNextId(); 40 } 41 42 } 43 | Popular Tags |