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


Java Transaction.end方法代码示例

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


在下文中一共展示了Transaction.end方法的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: testOneToMany_JoinFetchQuery

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

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

        Query q = em.createQuery("select u from sec$User u join fetch u.userRoles 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_JoinFetchQuery =====================");
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:SoftDeleteTest.java

示例3: migrateAttachmentsBatch

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
protected int migrateAttachmentsBatch() {
    List<SendingAttachment> resultList;
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        String qstr = "select a from sys$SendingAttachment a where a.content is not null";
        TypedQuery<SendingAttachment> query = em.createQuery(qstr, SendingAttachment.class);
        query.setMaxResults(50);
        query.setViewName(View.MINIMAL);

        resultList = query.getResultList();

        tx.commit();
    } finally {
        tx.end();
    }

    if (!resultList.isEmpty()) {
        emailer.migrateAttachmentsToFileStorage(resultList);
    }

    return resultList.size();
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:24,代码来源:Emailer.java

示例4: getAvailableUsers

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Override
public List<String> getAvailableUsers() {
    List<String> result = new ArrayList<>();

    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        Query query = em.createQuery("select u from sec$User u");
        List<User> userList = query.getResultList();
        for (User user : userList) {
            result.add(user.getLogin());
        }
        tx.commit();
    } finally {
        tx.end();
    }

    return result;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:SchedulingServiceBean.java

示例5: testQuery

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

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        Query query = em.createQuery("select r from sec$Role r where r.name = ?1");
        query.setParameter(1, "roleToBeDeleted");

        List<Role> list = query.getResultList();
        assertTrue(list.isEmpty());

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

示例6: testRemoveNotManaged

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

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        UserRole userRole = em.find(UserRole.class, userRole1Id);

        tx.commitRetaining();

        em = cont.persistence().getEntityManager();
        em.remove(userRole);

        tx.commitRetaining();

        em = cont.persistence().getEntityManager();
        UserRole deletedUserRole = em.find(UserRole.class, userRole1Id);
        assertNull(deletedUserRole);

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

示例7: 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

示例8: 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

示例9: 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

示例10: testUpdateQuery_CleanupMode

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

    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        em.setSoftDeletion(false);
        Query query = em.createQuery("update sec$Role r set r.description = ?1 where r.name = ?2");
        query.setParameter(1, "Updated");
        query.setParameter(2, "roleToBeDeleted");
        int updated = query.executeUpdate();

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

示例11: 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

示例12: createGroups

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
private void createGroups() {
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        Group root = new Group();
        rootId = root.getId();
        root.setName("root");
        em.persist(root);
        tx.commitRetaining();

        em = cont.persistence().getEntityManager();
        root = em.find(Group.class, rootId);
        Group group1 = new Group();
        group1Id = group1.getId();
        group1.setName("group1");
        group1.setParent(root);
        em.persist(group1);
        tx.commitRetaining();

        em = cont.persistence().getEntityManager();
        group1 = em.find(Group.class, group1Id);
        Group group2 = new Group();
        group2Id = group2.getId();
        group2.setName("group2");
        group2.setParent(group1);
        em.persist(group2);
        tx.commitRetaining();

        em = cont.persistence().getEntityManager();
        root = em.find(Group.class, rootId);
        Group group3 = new Group();
        group3Id = group3.getId();
        group3.setName("group3");
        group3.setParent(root);
        em.persist(group3);
        tx.commit();
    } finally {
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:41,代码来源:GroupTest.java

示例13: 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

示例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 = em.createNativeQuery("delete from SEC_USER_SETTING where USER_ID = ?");
        q.setParameter(1, TestUserSessionSource.USER_ID);
        q.executeUpdate();
        tx.commit();
    } finally {
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:14,代码来源:UserSettingServiceTest.java

示例15: begin

import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Override
public Context begin() {
    Transaction tx = persistence.createTransaction();
    try {
        List<ScheduledTask> tasks = getTasks();
        return new ContextImpl(tasks, tx);
    } catch (Exception e) {
        tx.end();
        throw new RuntimeException(e);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:12,代码来源:DbBasedCoordinator.java


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