use of com.haulmont.cuba.core.model.common.Server in project jmix by jmix-framework.
the class TransactionTest method testRunInTransaction.
@Test
public void testRunInTransaction() throws Exception {
UUID id = persistence.callInTransaction(em -> {
assertNotNull(em);
Server server = new Server();
server.setName("localhost");
server.setRunning(true);
em.persist(server);
return server.getId();
});
persistence.runInTransaction(em -> {
Server server = em.find(Server.class, id);
assertNotNull(server);
assertEquals(id, server.getId());
server.setRunning(false);
});
}
use of com.haulmont.cuba.core.model.common.Server in project jmix by jmix-framework.
the class NonDetachedTest method testCreateNew_DM.
@Test
public void testCreateNew_DM() throws Exception {
// check versioned entity
Group companyGroupCopy = metadata.getTools().copy(companyGroup);
assertTrue(entityStates.isNew(companyGroupCopy));
entityStates.makeDetached(companyGroupCopy);
User user = persistence.callInTransaction((em) -> em.find(User.class, this.user.getId()));
User userCopy = metadata.getTools().copy(user);
assertNull(userCopy.getGroup());
assertTrue(entityStates.isNew(userCopy));
entityStates.makeDetached(userCopy);
userCopy.setId(UuidProvider.createUuid());
userCopy.setVersion(null);
userCopy.setGroup(companyGroupCopy);
userCopy.setName("new name");
try {
AppBeans.get(DataManager.class).commit(userCopy);
user = persistence.callInTransaction((em) -> em.find(User.class, userCopy.getId()));
assertEquals("new name", user.getName());
} finally {
testSupport.deleteRecord(userCopy);
}
// check non-versioned entity
Server server = metadata.create(Server.class);
server.setName("server-" + server.getId());
assertTrue(entityStates.isNew(server));
entityStates.makeDetached(server);
try {
AppBeans.get(DataManager.class).commit(server);
Server loaded = persistence.callInTransaction(em -> em.find(Server.class, server.getId()));
assertNotNull(loaded);
} finally {
testSupport.deleteRecord(server);
}
}
Aggregations