本文整理汇总了Java中com.haulmont.cuba.core.EntityManager.remove方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.remove方法的具体用法?Java EntityManager.remove怎么用?Java EntityManager.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.haulmont.cuba.core.EntityManager
的用法示例。
在下文中一共展示了EntityManager.remove方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBeforeUpdate
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Override
public void onBeforeUpdate(Group entity, EntityManager entityManager) {
if (!persistence.getTools().getDirtyFields(entity).contains("parent"))
return;
EntityManager em = persistence.getEntityManager();
for (GroupHierarchy oldHierarchy : entity.getHierarchyList()) {
em.remove(oldHierarchy);
}
createNewHierarchy(entity, entity.getParent());
TypedQuery<GroupHierarchy> q = em.createQuery(
"select h from sec$GroupHierarchy h join fetch h.group " +
"where h.parent.id = ?1", GroupHierarchy.class);
q.setParameter(1, entity);
List<GroupHierarchy> list = q.getResultList();
for (GroupHierarchy hierarchy : list) {
Group dependentGroup = hierarchy.getGroup();
for (GroupHierarchy depHierarchy : dependentGroup.getHierarchyList()) {
em.remove(depHierarchy);
}
em.remove(hierarchy);
createNewHierarchy(dependentGroup, dependentGroup.getParent());
}
}
示例2: testRole
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的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();
}
}
示例3: testEntityListenerOnCascadeDelete
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testEntityListenerOnCascadeDelete() throws Exception {
EntityListenerManager entityListenerManager = AppBeans.get(EntityListenerManager.class);
entityListenerManager.addListener(CascadeEntity.class, DeleteCascadeEntityListener.class);
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.persistence().getEntityManager();
CascadeEntity loadedSecond = em.find(CascadeEntity.class, second.getId());
em.find(CascadeEntity.class, third.getId());
em.remove(loadedSecond);
tx.commit();
}
entityListenerManager.removeListener(CascadeEntity.class, DeleteCascadeEntityListener.class);
assertEquals(2, DeleteCascadeEntityListener.deletedEvents.size());
assertTrue(DeleteCascadeEntityListener.deletedEvents.contains(second.getId().toString()));
assertTrue(DeleteCascadeEntityListener.deletedEvents.contains(third.getId().toString()));
}
示例4: testRemoveNotManaged
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的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 =====================");
}
示例5: storeCategoryAttributeValueWithCollectionType
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
/**
* Removes nested {@code CategoryAttributeValue} entities for items that were removed from the collection value
* and creates new child {@code CategoryAttributeValue} instances for just added collection value items.
*
* @param categoryAttributeValue
*/
protected void storeCategoryAttributeValueWithCollectionType(CategoryAttributeValue categoryAttributeValue) {
EntityManager em = persistence.getEntityManager();
List<Object> collectionValue = categoryAttributeValue.getTransientCollectionValue();
List<Object> newCollectionValue = new ArrayList<>(collectionValue);
//remove existing child CategoryAttributeValues that are not in the CategoryAttributeValue.collectionValue property
if (categoryAttributeValue.getChildValues() != null) {
for (CategoryAttributeValue existingChildCategoryAttributeValue : categoryAttributeValue.getChildValues()) {
Object value = existingChildCategoryAttributeValue.getValue();
if (!collectionValue.contains(value)) {
em.remove(existingChildCategoryAttributeValue);
}
newCollectionValue.remove(value);
}
}
//newCollectionValue now contains only the values that were added but not persisted yet
newCollectionValue.forEach(value -> {
CategoryAttributeValue childCAV = metadata.create(CategoryAttributeValue.class);
childCAV.setParent(categoryAttributeValue);
childCAV.setValue(value);
if (categoryAttributeValue.getObjectEntityId() != null) {
childCAV.setObjectEntityId(categoryAttributeValue.getObjectEntityId());
}
childCAV.setCode(categoryAttributeValue.getCode());
childCAV.setCategoryAttribute(categoryAttributeValue.getCategoryAttribute());
em.persist(childCAV);
});
}
示例6: test_PL_3452
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
/**
* @see <a href="https://youtrack.haulmont.com/issue/PL-3452">PL-3452</a>
*/
@Test
public void test_PL_3452() throws Exception {
Many2ManyA a1;
Many2ManyA a2;
Many2ManyB b1;
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
a1 = em.find(Many2ManyA.class, this.a1.getId());
assertNotNull(a1);
assertEquals(2, a1.getCollectionOfB().size());
a2 = em.find(Many2ManyA.class, this.a2.getId());
assertNotNull(a2);
assertEquals(1, a2.getCollectionOfB().size());
tx.commitRetaining();
em = cont.entityManager();
b1 = em.find(Many2ManyB.class, this.b1.getId());
em.remove(b1);
tx.commitRetaining();
em = cont.entityManager();
a1 = em.find(Many2ManyA.class, this.a1.getId());
assertNotNull(a1);
assertEquals(1, a1.getCollectionOfB().size());
tx.commit();
}
}
示例7: onBeforeDelete
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Override
public void onBeforeDelete(Server entity, EntityManager entityManager) {
EntityManager em = persistence.getEntityManager();
UUID relatedId = UUID.fromString(entity.getData());
FileDescriptor related = em.find(FileDescriptor.class, relatedId);
if (related != null) {
System.out.println(">>>>> remove related: " + relatedId);
em.remove(related);
} else
throw new RuntimeException("Related entity not found" + relatedId);
}
示例8: 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);
}
}
示例9: setUp
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
dataManager = AppBeans.get(DataManager.class);
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
SoftDelete_Service service = new SoftDelete_Service();
serviceId = service.getId();
service.setName("service");
service.setCode("serviceCode");
em.persist(service);
SoftDelete_Task task = new SoftDelete_Task();
taskId = task.getId();
task.setMessage("message");
task.setService(service);
em.persist(task);
SoftDelete_TaskValue taskValue = new SoftDelete_TaskValue();
taskValueId = taskValue.getId();
taskValue.setTask(task);
em.persist(taskValue);
SoftDelete_Project project = new SoftDelete_Project();
projectId = project.getId();
project.setName("project");
project.setAValue(taskValue);
project.setTask(task);
em.persist(project);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
task = em.find(SoftDelete_Task.class, taskId);
em.remove(task);
tx.commit();
} finally {
tx.end();
}
}