本文整理汇总了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;
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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();
}
}
示例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);
}
}