private CounterHolder _obtainIncrement(String counterName, long range, long size) throws SystemException { Session session = null; try { session = openSession(); Counter counter = (Counter) session.get(CounterImpl.class, counterName, LockMode.UPGRADE); long newValue = counter.getCurrentId(); if (size > newValue) { newValue = size; } long rangeMax = newValue + range; counter.setCurrentId(rangeMax); CounterHolder counterHolder = new CounterHolder(newValue, rangeMax); session.saveOrUpdate(counter); session.flush(); return counterHolder; } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
protected Counter addCounter() throws Exception { String pk = randomString(); Counter counter = _persistence.create(pk); counter.setCurrentId(nextLong()); _persistence.update(counter, false); return counter; }
public void testUpdateExisting() throws Exception { String pk = randomString(); Counter newCounter = _persistence.create(pk); newCounter.setCurrentId(nextLong()); _persistence.update(newCounter, false); Counter existingCounter = _persistence.findByPrimaryKey(newCounter.getPrimaryKey()); assertEquals(existingCounter.getName(), newCounter.getName()); assertEquals(existingCounter.getCurrentId(), newCounter.getCurrentId()); }