* @param initialValue the initial value of the given generator
* @return the next value in a sequence
*/
public int nextValue(IdSourceKey idSourceKey, int increment, int initialValue) {
Transaction tx = neo4jDb.beginTx();
Lock lock = null;
try {
Node sequence = getSequence( idSourceKey );
if ( sequence == null ) {
// sequence nodes are expected to have been created up-front
if ( idSourceKey.getMetadata().getType() == IdSourceType.SEQUENCE ) {
throw new HibernateException( "Sequence missing: " + idSourceKey.getMetadata().getName() );
}
// table sequence nodes (think of them as rows in a generator table) are created upon first usage
else {
addTableSequence( idSourceKey.getMetadata(), (String) idSourceKey.getColumnValues()[0], initialValue );
sequence = getSequence( idSourceKey );
}
}
lock = tx.acquireWriteLock( sequence );
int nextValue = updateSequenceValue( idSourceKey, sequence, increment );
tx.success();
lock.release();
return nextValue;
}
finally {
tx.close();
}