use of com.haulmont.cuba.core.sys.persistence.SequenceSupport in project cuba by cuba-platform.
the class NumberIdWorker method checkSequenceExists.
protected void checkSequenceExists(String entityName, long startValue, long increment) {
String seqName = getSequenceName(entityName);
if (existingSequences.contains(seqName))
return;
// Create sequence in separate transaction because it's name is cached and we want to be sure it is created
// regardless of possible errors in the invoking code
Transaction tx = persistence.createTransaction(getDataStore(entityName));
try {
EntityManager em = persistence.getEntityManager(getDataStore(entityName));
SequenceSupport sequenceSupport = getSequenceSupport(entityName);
Query query = em.createNativeQuery(sequenceSupport.sequenceExistsSql(seqName));
List list = query.getResultList();
if (list.isEmpty()) {
query = em.createNativeQuery(sequenceSupport.createSequenceSql(seqName, startValue, increment));
query.executeUpdate();
}
existingSequences.add(seqName);
tx.commit();
} finally {
tx.end();
}
}
Aggregations