• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Transaction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: assignLibraryDepartment

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Override
public Collection<BookInstance> assignLibraryDepartment(Collection<BookInstance> bookInstances,
                                                        LibraryDepartment libraryDepartment, View bookInstanceView) {
    checkPermission(EntityOp.UPDATE);
    Collection<BookInstance> mergedInstances = new ArrayList<>();
    // Explicit transaction control
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        for (BookInstance booksInstance : bookInstances) {
            BookInstance instance = em.merge(booksInstance, bookInstanceView);
            instance.setLibraryDepartment(libraryDepartment);
            // Return the updated instance
            mergedInstances.add(instance);
        }
        tx.commit();
    }
    return mergedInstances;
}
 
开发者ID:cuba-platform,项目名称:old-library,代码行数:19,代码来源:BookInstanceServiceBean.java


示例2: testOneToOneLazy

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Test
public void testOneToOneLazy() {
    System.out.println("===================== BEGIN testOneToOneLazy =====================");
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        SoftDeleteOneToOneA oneToOneA = em.find(SoftDeleteOneToOneA.class, oneToOneA2Id);
        assertNotNull(oneToOneA);
        assertNotNull(oneToOneA.getB());
        assertEquals(oneToOneA.getB().getId(), oneToOneB2Id);
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToOneLazy =====================");
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:17,代码来源:SoftDeleteTest.java


示例3: authenticate

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Override
@Nonnull
public AuthenticationDetails authenticate(Credentials credentials) throws LoginException {
    checkNotNullArgument(credentials, "credentials should not be null");

    SecurityContext previousSecurityContext = AppContext.getSecurityContext();
    AppContext.setSecurityContext(new SecurityContext(serverSession));

    try (Transaction tx = persistence.getTransaction()) {
        AuthenticationDetails authenticationDetails = authenticateInternal(credentials);

        tx.commit();

        userSessionManager.clearPermissionsOnUser(authenticationDetails.getSession());

        return authenticationDetails;
    } finally {
        AppContext.setSecurityContext(previousSecurityContext);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:AuthenticationManagerBean.java


示例4: testOneToManyLazy

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Test
public void testOneToManyLazy() {
    System.out.println("===================== BEGIN testOneToManyLazy =====================");
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();

        User user = em.find(User.class, userId);

        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 testOneToManyLazy =====================");
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:22,代码来源:SoftDeleteTest.java


示例5: setUp

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

        User user = new User();
        userId = user.getId();
        user.setName("testUser");
        user.setLogin("testLogin");
        user.setPosition("manager");
        user.setGroup(em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93")));
        em.persist(user);

        UserRole userRole = new UserRole();
        userRoleId = userRole.getId();
        userRole.setUser(user);
        userRole.setRole(em.find(Role.class, UUID.fromString("0c018061-b26f-4de2-a5be-dff348347f93")));
        em.persist(userRole);

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


示例6: storeAccessToken

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Override
public void storeAccessToken(String tokenValue,
                             byte[] accessTokenBytes,
                             String authenticationKey,
                             byte[] authenticationBytes,
                             Date tokenExpiry,
                             String userLogin,
                             Locale locale,
                             String refreshTokenValue) {
    storeAccessTokenToMemory(tokenValue, accessTokenBytes, authenticationKey, authenticationBytes, tokenExpiry,
            userLogin, refreshTokenValue);
    if (serverConfig.getRestStoreTokensInDb()) {
        try (Transaction tx = persistence.getTransaction()) {
            removeAccessTokenFromDatabase(tokenValue);
            storeAccessTokenToDatabase(tokenValue, accessTokenBytes, authenticationKey, authenticationBytes,
                    tokenExpiry, userLogin, locale, refreshTokenValue);
            tx.commit();
        }
    }
    clusterManagerAPI.send(new TokenStoreAddAccessTokenMsg(tokenValue, accessTokenBytes, authenticationKey,
            authenticationBytes, tokenExpiry, userLogin, refreshTokenValue));
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:ServerTokenStoreImpl.java


示例7: storeAccessTokenToDatabase

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
protected void storeAccessTokenToDatabase(String tokenValue,
                                          byte[] accessTokenBytes,
                                          String authenticationKey,
                                          byte[] authenticationBytes,
                                          Date tokenExpiry,
                                          String userLogin,
                                          @Nullable Locale locale,
                                          @Nullable String refreshTokenValue) {
    try (Transaction tx = persistence.getTransaction()) {
        EntityManager em = persistence.getEntityManager();
        AccessToken accessToken = metadata.create(AccessToken.class);
        accessToken.setCreateTs(timeSource.currentTimestamp());
        accessToken.setTokenValue(tokenValue);
        accessToken.setTokenBytes(accessTokenBytes);
        accessToken.setAuthenticationKey(authenticationKey);
        accessToken.setAuthenticationBytes(authenticationBytes);
        accessToken.setExpiry(tokenExpiry);
        accessToken.setUserLogin(userLogin);
        accessToken.setLocale(locale != null ? locale.toString() : null);
        accessToken.setRefreshTokenValue(refreshTokenValue);
        em.persist(accessToken);
        tx.commit();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:25,代码来源:ServerTokenStoreImpl.java


示例8: testCreateEntity

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Test
public void testCreateEntity() throws Exception {
    User u = metadata.create(User.class);
    u.setLogin("u-" + u.getId());
    u.setGroup(companyGroup);

    TestBeforeCommitTxListener.test = "testCreateEntity";
    try (Transaction tx = persistence.createTransaction()) {
        persistence.getEntityManager().persist(u);
        tx.commit();
    } finally {
        TestBeforeCommitTxListener.test = null;
    }

    try (Transaction tx = persistence.createTransaction()) {
        User user = persistence.getEntityManager().find(User.class, TestBeforeCommitTxListener.createdEntityId);
        assertNotNull(user);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:BeforeCommitTransactionListenerTest.java


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


示例10: testCommit

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Test
public void testCommit() throws Exception {
    User u = metadata.create(User.class);
    u.setLogin("TxLstnrTst-1-" + u.getId());
    u.setGroup(companyGroup);
    TestAfterCompleteTxListener.test = "testCommit";
    try {
        try (Transaction tx = persistence.createTransaction()) {
            persistence.getEntityManager().persist(u);
            tx.commit();
        }
    } finally {
        TestAfterCompleteTxListener.test = null;
    }

    try (Transaction tx = persistence.createTransaction()) {
        User user = persistence.getEntityManager().find(User.class, u.getId());
        assertEquals("updated by TestAfterCompleteTxListener", user.getName());
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:AfterCompleteTransactionListenerTest.java


示例11: testOpenTransaction

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Test
public void testOpenTransaction() throws Exception {
    TestingService service = AppBeans.get(TestingService.class);
    appender.getMessages().clear();

    // programmatic tx without proper completion
    Object tx = service.leaveOpenTransaction();
    ((Transaction) tx).commit();
    assertEquals(1, appender.getMessages().stream().filter(s -> s.contains("Open transaction")).count());

    appender.getMessages().clear();

    // declarative tx
    service.declarativeTransaction();
    assertEquals(0, appender.getMessages().stream().filter(s -> s.contains("Open transaction")).count());
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:17,代码来源:ServiceInterceptorTest.java


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


示例13: loadContentText

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Override
public String loadContentText(SendingMessage sendingMessage) {
    SendingMessage msg;
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        msg = em.reload(sendingMessage, "sendingMessage.loadContentText");
        tx.commit();
    }
    Objects.requireNonNull(msg, "Sending message not found: " + sendingMessage.getId());
    if (msg.getContentTextFile() != null) {
        byte[] bodyContent;
        try {
            bodyContent = fileStorage.loadFile(msg.getContentTextFile());
        } catch (FileStorageException e) {
            throw new RuntimeException(e);
        }
        //noinspection UnnecessaryLocalVariable
        String res = bodyTextFromByteArray(bodyContent);
        return res;
    } else {
        return msg.getContentText();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:24,代码来源:Emailer.java


示例14: persistMessages

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
protected void persistMessages(List<SendingMessage> sendingMessageList, SendingStatus status) {
    MessagePersistingContext context = new MessagePersistingContext();

    try {
        try (Transaction tx = persistence.createTransaction()) {
            EntityManager em = persistence.getEntityManager();
            for (SendingMessage message : sendingMessageList) {
                message.setStatus(status);

                try {
                    persistSendingMessage(em, message, context);
                } catch (FileStorageException e) {
                    throw new RuntimeException("Failed to store message " + message.getCaption(), e);
                }
            }
            tx.commit();
        }
        context.finished();
    } finally {
        removeOrphanFiles(context);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:Emailer.java


示例15: computeSecurityState

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Override
public SecurityState computeSecurityState(Entity entity) {
    Preconditions.checkNotNullArgument(entity, "entity is null");

    SecurityState state;
    String storeName = metadataTools.getStoreName(metadata.getClassNN(entity.getClass()));
    Transaction tx = persistence.createTransaction(storeName);
    try {
        EntityManager em = persistence.getEntityManager(storeName);
        Entity managedEntity = em.merge(entity);
        support.setupAttributeAccess(managedEntity);
        state = BaseEntityInternalAccess.getSecurityState(managedEntity);
        // do not commit the transaction
    } finally {
        tx.end();
    }
    return state;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:19,代码来源:AttributeAccessServiceBean.java


示例16: testFind

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Test
public void testFind() throws Exception {

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

    User user;

    try (Transaction tx = cont.persistence().createTransaction()) {
        EntityManager em = cont.persistence().getEntityManager();
        user = em.find(User.class, userId, view);

        tx.commit();
    }
    user = reserialize(user);

    assertNotNull(user.getCreatedBy());
    assertNotNull(user.getGroup());
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:23,代码来源:EntityManagerTest.java


示例17: testNormalMode

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

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

        Role role = em.find(Role.class, role2Id);
        assertNull(role);

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


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


示例19: testQueryWithFlush

import com.haulmont.cuba.core.Transaction; //导入依赖的package包/类
@Test
public void testQueryWithFlush() throws Exception {
    User u1 = metadata.create(User.class);
    u1.setLogin("TxLstnrTst-2-" + u1.getId());
    u1.setGroup(companyGroup);

    TestBeforeCommitTxListener.test = "testQueryWithFlush";
    try (Transaction tx = persistence.createTransaction()) {
        persistence.getEntityManager().persist(u1);
        tx.commit();
    } finally {
        TestBeforeCommitTxListener.test = null;
    }

    try (Transaction tx = persistence.createTransaction()) {
        User user = persistence.getEntityManager().find(User.class, u1.getId());
        assertEquals(u1, user);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:BeforeCommitTransactionListenerTest.java


示例20: clearScheduledTasks

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FlowQueryList类代码示例发布时间:2022-05-23
下一篇:
Java MessagePayload类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap