use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class TestingServiceBean method clearScheduledTasks.
@Override
public void clearScheduledTasks() {
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
Query query = em.createNativeQuery("delete from SYS_SCHEDULED_EXECUTION");
query.executeUpdate();
query = em.createNativeQuery("delete from SYS_SCHEDULED_TASK");
query.executeUpdate();
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class UniqueNumbers method checkSequenceExists.
protected void checkSequenceExists(String domain) {
String seqName = getSequenceName(domain);
if (containsSequence(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(domain));
try {
lock.readLock().unlock();
lock.writeLock().lock();
EntityManager em = persistence.getEntityManager(getDataStore(domain));
Query query = em.createNativeQuery(getSequenceSupport(domain).sequenceExistsSql(seqName));
List list = query.getResultList();
if (list.isEmpty()) {
query = em.createNativeQuery(getSequenceSupport(domain).createSequenceSql(seqName, 1, 1));
query.executeUpdate();
}
tx.commit();
existingSequences.add(seqName);
} finally {
lock.readLock().lock();
lock.writeLock().unlock();
tx.end();
}
}
use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class StandardCacheLoader method updateData.
@Override
public void updateData(CacheSet cacheSet, Map<String, Object> params) throws CacheException {
if (configuration.getConfig(GlobalConfig.class).getPerformanceTestMode())
return;
Collection<Object> items = cacheSet.getItems();
List updateItems = (List) params.get("items");
if ((updateItems != null) && (updateItems.size() > 0)) {
MetaClass metaClass = metadata.getSession().getClass(metaClassName);
View view = metadata.getViewRepository().getView(metaClass, viewName);
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
for (Object item : updateItems) {
Entity entity = (Entity) item;
entity = em.find(entity.getClass(), entity.getId(), view);
items.remove(item);
if (entity != null)
items.add(entity);
}
tx.commit();
} catch (Exception e) {
throw new CacheException(e);
} finally {
tx.end();
}
} else {
log.debug("Nothing to update");
}
}
use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class ServerTokenStoreImpl method getRefreshTokenValuesByUserLoginFromDatabase.
protected Set<String> getRefreshTokenValuesByUserLoginFromDatabase(String userLogin) {
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
List<String> result = em.createQuery("select e.tokenValue from sys$RefreshToken e where e.userLogin = :userLogin", String.class).setParameter("userLogin", userLogin).getResultList();
tx.commit();
return new HashSet<>(result);
}
}
use of com.haulmont.cuba.core.Transaction in project cuba by cuba-platform.
the class ServerTokenStoreImpl method deleteExpiredAccessTokensInDatabase.
protected void deleteExpiredAccessTokensInDatabase() {
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
em.createQuery("delete from sys$AccessToken t where t.expiry < CURRENT_TIMESTAMP").executeUpdate();
tx.commit();
}
}
Aggregations