当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.commit方法代码示例

本文整理汇总了Java中com.haulmont.cuba.core.Transaction.commit方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.commit方法的具体用法?Java Transaction.commit怎么用?Java Transaction.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.haulmont.cuba.core.Transaction的用法示例。


在下文中一共展示了Transaction.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPermissionValue

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
public Integer getPermissionValue(User user, PermissionType permissionType, String target) {
    Integer result;
    List<Role> roles = new ArrayList<>();

    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        user = em.find(User.class, user.getId());
        for (UserRole userRole : user.getUserRoles()) {
            if (userRole.getRole() != null) {
                roles.add(userRole.getRole());
            }
        }
        UserSession session = new UserSession(uuidSource.createUuid(), user, roles, userSessionSource.getLocale(), false);
        compilePermissions(session, roles);
        result = session.getPermissionValue(permissionType, target);
        tx.commit();
    } finally {
        tx.end();
    }
    return result; 
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:UserSessionManager.java

示例2: testMerge

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testMerge() throws Exception {
    UUID newUserId = UUID.randomUUID();
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        User user = new User();
        user.setId(newUserId);
        user.setName("testMerge");
        user.setLogin("testMerge");
        user.setPassword("testMerge");
        user.setGroup(em.getReference(Group.class, groupId));
        user = em.merge(user);
        User userFromPersistentContext = em.find(User.class, newUserId);
        assertEquals(user, userFromPersistentContext);
        tx.commit();
    } finally {
        tx.end();
        cont.deleteRecord("SEC_USER", newUserId);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:22,代码来源:EntityManagerTest.java

示例3: testQueryWithoutConditions

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testQueryWithoutConditions() {
    System.out.println("===================== BEGIN testQueryWithoutConditions =====================");

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        Query query = em.createQuery("select r from sec$Role r");

        List<Role> list = query.getResultList();
        for (Role role : list) {
            if (role.getId().equals(role2Id)) {
                fail();
            }
        }

        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testQueryWithoutConditions =====================");
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:SoftDeleteTest.java

示例4: testRole

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testRole() {
    UUID roleId = createRole();

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        Role role = em.find(Role.class, roleId);
        em.remove(role);

        tx.commit();
    } finally {
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:17,代码来源:RelationsTest.java

示例5: testOneToMany_Query

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testOneToMany_Query() {
    System.out.println("===================== BEGIN testOneToMany_Query =====================");

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        Query q = em.createQuery("select u from sec$User u where u.id = ?1");
        q.setParameter(1, userId);
        User user = (User) q.getSingleResult();

        List<UserRole> userRoles = user.getUserRoles();
        assertEquals(1, userRoles.size());
        for (UserRole ur : userRoles) {
            assertNotNull(ur.getRole());
        }

        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToMany_Query =====================");
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:SoftDeleteTest.java

示例6: registerExecutionFinish

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
protected void registerExecutionFinish(ScheduledTask task, ScheduledExecution execution, Object result) {
    if ((!BooleanUtils.isTrue(task.getLogFinish()) && !BooleanUtils.isTrue(task.getSingleton()) && task.getSchedulingType() != SchedulingType.FIXED_DELAY)
            || execution == null)
        return;

    log.trace("{}: registering execution finish", task);
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        execution = em.merge(execution);
        execution.setFinishTime(timeSource.currentTimestamp());
        if (result != null)
            execution.setResult(result.toString());

        tx.commit();
    } finally {
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:RunnerBean.java

示例7: deleteSequence

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Override
public void deleteSequence(String domain) {
    String seqName = getSequenceName(domain);

    if (!containsSequence(seqName)) {
        throw new IllegalStateException("Attempt to delete nonexistent sequence " + domain);
    }
    
    String sqlScript = getSequenceSupport(domain).deleteSequenceSql(seqName);

    Transaction tx = persistence.getTransaction(getDataStore(domain));
    try {
        lock.writeLock().lock();
        if (!containsSequence(seqName)) {
            tx.commit();
            return;
        }

        executeScript(domain, sqlScript);
        tx.commit();
        existingSequences.remove(seqName);
    } finally {
        lock.writeLock().unlock();
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:27,代码来源:UniqueNumbers.java

示例8: testReloadSameTx

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testReloadSameTx() throws Exception {
    User originalUser, reloadedUser;

    View view = new View(User.class, false)
            .addProperty("name");

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        originalUser = em.find(User.class, userId, view);
        assertNotNull(originalUser);
        reloadedUser = em.reload(originalUser, "user.edit");

        tx.commit();
    } finally {
        tx.end();
    }
    assertTrue(originalUser == reloadedUser);
    reloadedUser = reserialize(reloadedUser);
    assertNotNull(reloadedUser);
    assertNotNull(reloadedUser.getLogin());
    assertTrue(PersistenceHelper.isLoaded(reloadedUser, "userRoles"));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:26,代码来源:EntityManagerTest.java

示例9: getResult

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
protected long getResult(String entityName, String sqlScript, long startValue, long increment) {
    Transaction tx = persistence.getTransaction(getDataStore(entityName));
    try {
        checkSequenceExists(entityName, startValue, increment);

        Object value = executeScript(entityName, sqlScript);
        tx.commit();
        if (value instanceof Long)
            return (Long) value;
        else if (value instanceof BigDecimal)
            return ((BigDecimal) value).longValue();
        else if (value instanceof String)
            return Long.parseLong((String) value);
        else if (value == null)
            throw new IllegalStateException("No value returned");
        else
            throw new IllegalStateException("Unsupported value type: " + value.getClass());
    } finally {
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:22,代码来源:NumberIdWorker.java

示例10: checkSequenceExists

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:NumberIdWorker.java

示例11: build

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Override
public Object build(String string) {
    if (StringUtils.isBlank(string)) {
        return null;
    }

    EntityLoadInfo info = EntityLoadInfo.parse(string);
    if (info == null) {
        throw new IllegalArgumentException("Invalid entity info: " + string);
    }

    Entity entity;
    String property = AppContext.getProperty("cuba.useCurrentTxForConfigEntityLoad");
    Transaction tx = Boolean.valueOf(property) ? persistence.getTransaction() : persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        View view = null;
        if (info.getViewName() != null) {
            view = metadata.getViewRepository().getView(info.getMetaClass(), info.getViewName());
        }

        Class javaClass = info.getMetaClass().getJavaClass();
        if (view != null) {
            entity = em.find(javaClass, info.getId(), view);
        } else {
            entity = em.find(javaClass, info.getId());
        }

        tx.commit();
    } finally {
        tx.end();
    }
    return entity;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:35,代码来源:EntityFactory.java

示例12: reloadAppFolders

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Override
public List<AppFolder> reloadAppFolders(List<AppFolder> folders) {
    log.debug("Reloading AppFolders {}", folders);

    StopWatch stopWatch = new Slf4JStopWatch("AppFolders");
    stopWatch.start();

    try {
        if (!folders.isEmpty()) {
            Binding binding = new Binding();
            binding.setVariable("persistence", persistence);
            binding.setVariable("metadata", metadata);
            binding.setProperty("userSession", userSessionSource.getUserSession());

            for (AppFolder folder : folders) {
                Transaction tx = persistence.createTransaction();
                try {
                    if (loadFolderQuantity(binding, folder)) {
                        tx.commit();
                    }
                } finally {
                    tx.end();
                }
            }
        }

        return folders;
    } finally {
        stopWatch.stop();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:32,代码来源:FoldersServiceBean.java

示例13: updateData

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Override
public void updateData(CacheSet cacheSet, Map<String, Object> params) throws CacheException {
    if (configuration.getConfig(GlobalConfig.class).getTestMode())
        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");
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:38,代码来源:StandardCacheLoader.java

示例14: tearDown

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@After
public void tearDown() throws Exception {
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        Query q;

        q = em.createNativeQuery("delete from SEC_USER_ROLE where ID = ? or ID = ?");
        q.setParameter(1, userRole1Id.toString());
        q.setParameter(2, userRole2Id.toString());
        q.executeUpdate();

        q = em.createNativeQuery("delete from SEC_USER where ID = ?");
        q.setParameter(1, userId.toString());
        q.executeUpdate();

        q = em.createNativeQuery("delete from SEC_GROUP where ID = ?");
        q.setParameter(1, groupId.toString());
        q.executeUpdate();

        q = em.createNativeQuery("delete from SEC_PERMISSION where ID = ? or ID = ?");
        q.setParameter(1, permission1Id.toString());
        q.setParameter(2, permission2Id.toString());
        q.executeUpdate();

        q = em.createNativeQuery("delete from SEC_ROLE where ID = ? or ID = ?");
        q.setParameter(1, role1Id.toString());
        q.setParameter(2, role2Id.toString());
        q.executeUpdate();

        tx.commit();
    } finally {
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:37,代码来源:PermissionTest.java

示例15: setCurrentNumber

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Override
public void setCurrentNumber(String domain, long value) {
    String sqlScript = getSequenceSupport(domain).modifySequenceSql(getSequenceName(domain), value);

    Transaction tx = persistence.getTransaction(getDataStore(domain));
    try {
        lock.readLock().lock();
        checkSequenceExists(domain);
        executeScript(domain, sqlScript);
        tx.commit();
    } finally {
        lock.readLock().unlock();
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:16,代码来源:UniqueNumbers.java


注:本文中的com.haulmont.cuba.core.Transaction.commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。