Search in sources :

Example 16 with Transaction

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();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) Query(com.haulmont.cuba.core.Query)

Example 17 with Transaction

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();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) Query(com.haulmont.cuba.core.Query) List(java.util.List)

Example 18 with Transaction

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");
    }
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) EntityManager(com.haulmont.cuba.core.EntityManager) MetaClass(com.haulmont.chile.core.model.MetaClass) Transaction(com.haulmont.cuba.core.Transaction) List(java.util.List)

Example 19 with Transaction

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);
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction)

Example 20 with Transaction

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();
    }
}
Also used : EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction)

Aggregations

Transaction (com.haulmont.cuba.core.Transaction)211 EntityManager (com.haulmont.cuba.core.EntityManager)138 Test (org.junit.Test)44 User (com.haulmont.cuba.security.entity.User)30 Query (com.haulmont.cuba.core.Query)26 View (com.haulmont.cuba.core.global.View)21 Before (org.junit.Before)15 Group (com.haulmont.cuba.security.entity.Group)13 TypedQuery (com.haulmont.cuba.core.TypedQuery)11 MetaClass (com.haulmont.chile.core.model.MetaClass)9 SendingMessage (com.haulmont.cuba.core.entity.SendingMessage)8 Entity (com.haulmont.cuba.core.entity.Entity)7 List (java.util.List)6 Role (com.haulmont.cuba.security.entity.Role)5 UserRole (com.haulmont.cuba.security.entity.UserRole)5 SoftDeleteOneToOneA (com.haulmont.cuba.testmodel.softdelete_one_to_one.SoftDeleteOneToOneA)5 UUID (java.util.UUID)5 Nullable (javax.annotation.Nullable)5 AppFolder (com.haulmont.cuba.core.entity.AppFolder)4 IdentityEntity (com.haulmont.cuba.testmodel.primary_keys.IdentityEntity)4