use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class EntityManagerTest method testMerge.
@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);
}
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class SerializationTest method testDetachedSerialization.
@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());
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class SerializationTest method setUp.
@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();
}
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class SerializationTest method testEmptyDetachedSerialization.
@Test
public void testEmptyDetachedSerialization() throws Exception {
User user;
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
user = em.find(User.class, userId);
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());
try {
standardUser.getGroup();
Assert.fail();
} catch (Exception ignored) {
}
try {
kryoUser.getGroup();
Assert.fail();
} catch (Exception ignored) {
}
try {
standardUser.getUserRoles().size();
Assert.fail();
} catch (Exception ignored) {
}
try {
kryoUser.getUserRoles().size();
Assert.fail();
} catch (Exception ignored) {
}
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class QueryCacheTestClass method testNativeQuery.
@Test
public void testNativeQuery() {
appender.clearMessages();
assertEquals(0, queryCache.size());
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.entityManager();
TypedQuery<User> query = em.createNativeQuery("select * from SEC_USER", User.class);
query.setCacheable(true);
query.getResultList();
tx.commit();
}
assertEquals(0, queryCache.size());
}
Aggregations