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


Java EntityManager.merge方法代码示例

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


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

示例1: assignLibraryDepartment

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的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: registerExecutionFinish

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的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

示例3: computeSecurityState

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的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

示例4: testMerge

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的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

示例5: returnToQueue

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void returnToQueue(SendingMessage sendingMessage) {
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        SendingMessage msg = em.merge(sendingMessage);

        msg.setAttemptsMade(msg.getAttemptsMade() + 1);
        msg.setStatus(SendingStatus.QUEUE);

        tx.commit();
    } catch (Exception e) {
        log.error("Error returning message to '{}' to the queue", sendingMessage.getAddress(), e);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:14,代码来源:Emailer.java

示例6: markAsSent

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void markAsSent(SendingMessage sendingMessage) {
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        SendingMessage msg = em.merge(sendingMessage);

        msg.setStatus(SendingStatus.SENT);
        msg.setAttemptsMade(msg.getAttemptsMade() + 1);
        msg.setDateSent(timeSource.currentTimestamp());

        tx.commit();
    } catch (Exception e) {
        log.error("Error marking message to '{}' as sent", sendingMessage.getAddress(), e);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:15,代码来源:Emailer.java

示例7: markAsNonSent

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void markAsNonSent(SendingMessage sendingMessage) {
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        SendingMessage msg = em.merge(sendingMessage);

        msg.setStatus(SendingStatus.NOTSENT);
        msg.setAttemptsMade(msg.getAttemptsMade() + 1);

        tx.commit();
    } catch (Exception e) {
        log.error("Error marking message to '{}' as not sent", sendingMessage.getAddress(), e);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:14,代码来源:Emailer.java

示例8: migrateMessage

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void migrateMessage(EntityManager em, SendingMessage msg) {
    msg = em.merge(msg);
    byte[] bodyBytes = bodyTextToBytes(msg);
    FileDescriptor bodyFile = createBodyFileDescriptor(msg, bodyBytes);

    try {
        fileStorage.saveFile(bodyFile, bodyBytes);
    } catch (FileStorageException e) {
        throw new RuntimeException(e);
    }
    em.persist(bodyFile);
    msg.setContentTextFile(bodyFile);
    msg.setContentText(null);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:15,代码来源:Emailer.java

示例9: migrateAttachment

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void migrateAttachment(EntityManager em, SendingAttachment attachment) {
    attachment = em.merge(attachment);
    FileDescriptor contentFile = createAttachmentFileDescriptor(attachment);

    try {
        fileStorage.saveFile(contentFile, attachment.getContent());
    } catch (FileStorageException e) {
        throw new RuntimeException(e);
    }
    em.persist(contentFile);
    attachment.setContentFile(contentFile);
    attachment.setContent(null);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:14,代码来源:Emailer.java

示例10: restoreEntity

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
protected void restoreEntity(Entity entity, String storeName) {
    EntityManager em = persistence.getEntityManager(storeName);
    Entity reloadedEntity = em.find(entity.getClass(), entity.getId());
    if (reloadedEntity != null && ((SoftDelete) reloadedEntity).isDeleted()) {
        log.info("Restoring deleted entity " + entity);
        Date deleteTs = ((SoftDelete) reloadedEntity).getDeleteTs();
        ((SoftDelete) reloadedEntity).setDeleteTs(null);
        em.merge(reloadedEntity);
        restoreDetails(reloadedEntity, deleteTs, storeName);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:12,代码来源:EntityRestoreServiceBean.java

示例11: testMergeEmbedded

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testMergeEmbedded() throws Exception {
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.persistence().getEntityManager();
        EntitySnapshot entitySnapshot = cont.metadata().create(EntitySnapshot.class);
        entitySnapshot.setObjectEntityId(1);
        EntitySnapshot mergedEntitySnapshot = em.merge(entitySnapshot);

        assertNotNull(mergedEntitySnapshot.getEntity());
        assertEquals(1, mergedEntitySnapshot.getEntity().getObjectEntityId());
    } finally {
        tx.end();
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:16,代码来源:EntityManagerTest.java

示例12: doStoreDynamicAttributes

import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected void doStoreDynamicAttributes(BaseGenericIdEntity entity) {
    final EntityManager em = persistence.getEntityManager();
    Map<String, CategoryAttributeValue> dynamicAttributes = entity.getDynamicAttributes();
    if (dynamicAttributes != null) {
        Map<String, CategoryAttributeValue> mergedDynamicAttributes = new HashMap<>();
        for (Map.Entry<String, CategoryAttributeValue> entry : dynamicAttributes.entrySet()) {
            CategoryAttributeValue categoryAttributeValue = entry.getValue();
            if (categoryAttributeValue.getCategoryAttribute() == null
                    && categoryAttributeValue.getCode() != null) {
                CategoryAttribute attribute =
                        getAttributeForMetaClass(entity.getMetaClass(), categoryAttributeValue.getCode());
                categoryAttributeValue.setCategoryAttribute(attribute);
            }

            //remove deleted and empty attributes
            if (categoryAttributeValue.getDeleteTs() == null && categoryAttributeValue.getValue() != null) {
                if (entity instanceof BaseDbGeneratedIdEntity && categoryAttributeValue.getObjectEntityId() == null) {
                    categoryAttributeValue.setObjectEntityId(referenceToEntitySupport.getReferenceId(entity));
                }
                CategoryAttributeValue mergedCategoryAttributeValue = em.merge(categoryAttributeValue);
                mergedCategoryAttributeValue.setCategoryAttribute(categoryAttributeValue.getCategoryAttribute());

                //copy transient fields (for nested CAVs as well)
                mergedCategoryAttributeValue.setTransientEntityValue(categoryAttributeValue.getTransientEntityValue());
                mergedCategoryAttributeValue.setTransientCollectionValue(categoryAttributeValue.getTransientCollectionValue());
                if (BooleanUtils.isTrue(categoryAttributeValue.getCategoryAttribute().getIsCollection()) && categoryAttributeValue.getChildValues() != null) {
                    for (CategoryAttributeValue childCAV : categoryAttributeValue.getChildValues()) {
                        for (CategoryAttributeValue mergedChildCAV : mergedCategoryAttributeValue.getChildValues()) {
                            if (mergedChildCAV.getId().equals(childCAV.getId())) {
                                mergedChildCAV.setTransientEntityValue(childCAV.getTransientEntityValue());
                                break;
                            }
                        }

                    }
                }

                if (BooleanUtils.isTrue(mergedCategoryAttributeValue.getCategoryAttribute().getIsCollection())) {
                    storeCategoryAttributeValueWithCollectionType(mergedCategoryAttributeValue);
                }

                mergedDynamicAttributes.put(entry.getKey(), mergedCategoryAttributeValue);
            } else {
                em.remove(categoryAttributeValue);
            }
        }

        entity.setDynamicAttributes(mergedDynamicAttributes);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:52,代码来源:DynamicAttributesManager.java


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