本文整理汇总了Java中com.haulmont.cuba.core.EntityManager.find方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.find方法的具体用法?Java EntityManager.find怎么用?Java EntityManager.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.haulmont.cuba.core.EntityManager
的用法示例。
在下文中一共展示了EntityManager.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCleanupMode
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testCleanupMode() {
System.out.println("===================== BEGIN testCleanupMode =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
em.setSoftDeletion(false);
Role role = em.find(Role.class, role2Id);
assertNotNull(role);
assertTrue(role.isDeleted());
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testCleanupMode =====================");
}
示例2: testOneToOneMappedByLazy
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testOneToOneMappedByLazy() {
System.out.println("===================== BEGIN testOneToOneMappedByLazy =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id);
assertNotNull(oneToOneB);
assertNull(oneToOneB.getA());
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToOneMappedByLazy =====================");
}
示例3: testOneToManyLazy
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的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 =====================");
}
示例4: testNew
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testNew() {
createGroups();
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group group2 = em.find(Group.class, group2Id);
for (GroupHierarchy hierarchy : group2.getHierarchyList()) {
assertEquals(group2, hierarchy.getGroup());
if (hierarchy.getLevel() == 0)
assertEquals(rootId, hierarchy.getParent().getId());
else if (hierarchy.getLevel() == 1)
assertEquals(group1Id, hierarchy.getParent().getId());
}
tx.commit();
} finally {
tx.end();
}
}
示例5: testFind
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的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());
}
示例6: createRole
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
public UUID createRole() {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
User user = em.find(User.class, UUID.fromString("60885987-1b61-4247-94c7-dff348347f93"));
Role role = new Role();
role.setName("RelationTest");
em.persist(role);
UserRole userRole = new UserRole();
userRole.setUser(user);
userRole.setRole(role);
em.persist(userRole);
tx.commit();
return role.getId();
} finally {
tx.end();
}
}
示例7: testNormalMode
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的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 =====================");
}
示例8: 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);
}
}
示例9: testFindCombinedView
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testFindCombinedView() throws Exception {
View view1 = new View(User.class, false)
.addProperty("name")
.addProperty("login");
View view2 = new View(User.class, false)
.addProperty("name")
.addProperty("login")
.addProperty("group", new View(Group.class)
.addProperty("name"));
User user1;
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.persistence().getEntityManager();
user1 = em.find(User.class, userId, view1, view2);
tx.commit();
}
user1 = reserialize(user1);
assertNotNull(user1);
assertNotNull(user1.getCreatedBy());
assertNotNull(user1.getGroup());
}
示例10: substituteUser
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Nonnull
@Override
public UserSession substituteUser(User substitutedUser) {
UserSession currentSession = userSessionSource.getUserSession();
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
User user;
if (currentSession.getUser().equals(substitutedUser)) {
user = em.find(User.class, substitutedUser.getId());
if (user == null) {
throw new NoResultException("User not found");
}
} else {
user = loadSubstitutedUser(substitutedUser, currentSession, em);
}
UserSession session = userSessionManager.createSession(currentSession, user);
withSecurityContext(new SecurityContext(serverSession), () ->
publishUserSubstitutedEvent(currentSession, session)
);
tx.commit();
userSessions.remove(currentSession);
userSessionManager.clearPermissionsOnUser(session);
userSessions.add(session);
return session;
}
}
示例11: setActive
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Override
public void setActive(ScheduledTask task, boolean active) {
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
ScheduledTask t = em.find(ScheduledTask.class, task.getId());
t.setActive(active);
tx.commit();
} finally {
tx.end();
}
}
示例12: 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);
}
}
示例13: testDetachedSerialization
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void testDetachedSerialization() throws Exception {
View view = getView();
User user;
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
user = em.find(User.class, userId, view);
assertNotNull(user);
tx.commit();
} finally {
tx.end();
}
KryoSerialization kryoSerialization = new KryoSerialization();
User kryoUser = (User) kryoSerialization.deserialize(kryoSerialization.serialize(user));
StandardSerialization standardSerialization = new StandardSerialization();
User standardUser = (User) standardSerialization.deserialize(standardSerialization.serialize(user));
assertEquals(standardUser, kryoUser);
assertEquals(standardUser.getLogin(), kryoUser.getLogin());
assertEquals(standardUser.getName(), kryoUser.getName());
assertEquals(standardUser.getPosition(), kryoUser.getPosition());
assertEquals(standardUser.getGroup(), kryoUser.getGroup());
assertEquals(standardUser.getGroup().getName(), kryoUser.getGroup().getName());
assertEquals(standardUser.getUserRoles().get(0), kryoUser.getUserRoles().get(0));
assertEquals(standardUser.getUserRoles().get(0).getRole(), kryoUser.getUserRoles().get(0).getRole());
assertEquals(standardUser.getUserRoles().get(0).getRole().getName(), kryoUser.getUserRoles().get(0).getRole().getName());
}
示例14: build
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Override
public Object build(String string) {
if (StringUtils.isBlank(string)) {
return null;
}
EntityLoadInfo info = EntityLoadInfo.parse(string);
if (info == null) {
throw new IllegalArgumentException("Invalid entity info: " + string);
}
Entity entity;
String property = AppContext.getProperty("cuba.useCurrentTxForConfigEntityLoad");
Transaction tx = Boolean.valueOf(property) ? persistence.getTransaction() : persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
View view = null;
if (info.getViewName() != null) {
view = metadata.getViewRepository().getView(info.getMetaClass(), info.getViewName());
}
Class javaClass = info.getMetaClass().getJavaClass();
if (view != null) {
entity = em.find(javaClass, info.getId(), view);
} else {
entity = em.find(javaClass, info.getId());
}
tx.commit();
} finally {
tx.end();
}
return entity;
}
示例15: test
import com.haulmont.cuba.core.EntityManager; //导入方法依赖的package包/类
@Test
public void test() {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Role role = new Role();
role.setName("testRole1");
em.persist(role);
Group group = new Group();
group.setName("testGroup1");
em.persist(group);
User user = new User();
UUID userId = user.getId();
user.setLogin("testUser1");
user.setName("Test User 1");
user.setGroup(group);
em.persist(user);
UserRole userRole = new UserRole();
userRole.setUser(user);
userRole.setRole(role);
em.persist(userRole);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
user = em.find(User.class, userId);
List<UserRole> userRoles = user.getUserRoles();
assertEquals(1, userRoles.size());
for (UserRole ur : userRoles) {
Role r = ur.getRole();
assertEquals(role.getName(), r.getName());
}
} finally {
tx.end();
}
}