FileDocCategorySizeDatePackage
SqlMapSequenceDao.javaAPI DocExample1201Sat Dec 27 17:31:26 GMT 2003org.springframework.samples.jpetstore.dao.ibatis

SqlMapSequenceDao

public class SqlMapSequenceDao extends org.springframework.orm.ibatis.support.SqlMapDaoSupport

Fields Summary
Constructors Summary
Methods Summary
public intgetNextId(java.lang.String name)
This is a generic sequence ID generator that is based on a database table called 'SEQUENCE', which contains two columns (NAME, NEXTID). This approach should work with any database.

param
name the name of the sequence
return
the next ID

    Sequence sequence = new Sequence(name, -1);
    sequence = (Sequence) getSqlMapTemplate().executeQueryForObject("getSequence", sequence);
    if (sequence == null) {
      throw new DataRetrievalFailureException("Error: A null sequence was returned from the database (could not get next " +
																							name + " sequence).");
    }
    Object parameterObject = new Sequence(name, sequence.getNextId() + 1);
    getSqlMapTemplate().executeUpdate("updateSequence", parameterObject);
    return sequence.getNextId();