}
static public Long getNextSequenceNum(Site site, String sequenceId) throws Exception {
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
Object object = new Object();
Sequence sequence = null;
synchronized(object) {
sequence = (Sequence) em.find(Sequence.class, sequenceId);
if (sequence == null) {
sequence = new Sequence();
sequence.setSequenceId(sequenceId);
sequence.setNextSequenceNum(Long.valueOf(0));
sequence.setRecCreateBy(Constants.USERNAME_SYSTEM);
sequence.setRecCreateDatetime(new Date());
sequence.setRecUpdateBy(Constants.USERNAME_SYSTEM);
sequence.setRecUpdateDatetime(new Date());
sequence.setSite(site);
em.persist(sequence);
}
else {
em.lock(sequence, LockModeType.WRITE);
}
}
Long sequenceNum = sequence.getNextSequenceNum();
sequenceNum = Long.valueOf(sequenceNum.longValue() + 1);
sequence.setNextSequenceNum(sequenceNum);
return sequenceNum;
}