use of com.haulmont.cuba.testmodel.primary_keys.IdentityEntity in project cuba by cuba-platform.
the class IdentityTest method testQueryById.
@Test
public void testQueryById() throws Exception {
IdentityEntity foo = metadata.create(IdentityEntity.class);
foo.setName("foo");
foo.setEmail("foo@mail.com");
try (Transaction tx = persistence.createTransaction()) {
persistence.getEntityManager().persist(foo);
tx.commit();
}
IdentityEntity loaded;
try (Transaction tx = persistence.createTransaction()) {
TypedQuery<IdentityEntity> query = persistence.getEntityManager().createQuery("select e from test$IdentityEntity e where e.id = ?1", IdentityEntity.class);
query.setParameter(1, foo.getId());
loaded = query.getSingleResult();
tx.commit();
}
assertEquals(foo, loaded);
try (Transaction tx = persistence.createTransaction()) {
TypedQuery<IdentityEntity> query = persistence.getEntityManager().createQuery("select e from test$IdentityEntity e where e.id = :id", IdentityEntity.class);
query.setParameter("id", foo.getId());
loaded = query.getSingleResult();
tx.commit();
}
assertEquals(foo, loaded);
}
use of com.haulmont.cuba.testmodel.primary_keys.IdentityEntity in project cuba by cuba-platform.
the class IdentityTest method testPersistAndMerge.
@Test
public void testPersistAndMerge() throws Exception {
IdentityEntity foo = metadata.create(IdentityEntity.class);
foo.setName("foo");
foo.setEmail("foo@mail.com");
UUID uuid = foo.getId().getUuid();
try (Transaction tx = persistence.createTransaction()) {
persistence.getEntityManager().persist(foo);
tx.commit();
}
assertNotNull(foo.getId().get());
assertEquals(uuid, foo.getId().getUuid());
foo.setName("bar");
IdentityEntity bar;
try (Transaction tx = persistence.createTransaction()) {
bar = persistence.getEntityManager().merge(foo);
tx.commit();
}
assertEquals(uuid, foo.getId().getUuid());
assertEquals(foo, bar);
bar.setName("baz");
IdentityEntity baz;
try (Transaction tx = persistence.createTransaction()) {
baz = persistence.getEntityManager().merge(foo);
tx.commit();
}
assertEquals(uuid, foo.getId().getUuid());
assertEquals(foo, baz);
}
use of com.haulmont.cuba.testmodel.primary_keys.IdentityEntity in project cuba by cuba-platform.
the class IdentityTest method testIdCopying.
@Test
public void testIdCopying() {
IdentityEntity entity1 = metadata.create(IdentityEntity.class);
assertNull(entity1.getId().get());
IdentityEntity entity2 = metadata.create(IdentityEntity.class);
entity2.setId(entity1.getId());
IdentityEntity entity3 = metadata.create(IdentityEntity.class);
entity3.setId(entity1.getId());
assertTrue(entity2.getId() != entity3.getId());
}
use of com.haulmont.cuba.testmodel.primary_keys.IdentityEntity in project cuba by cuba-platform.
the class IdentityTest method testFindAndDelete.
@Test
public void testFindAndDelete() throws Exception {
IdentityEntity foo = metadata.create(IdentityEntity.class);
foo.setName("foo");
foo.setEmail("foo@mail.com");
try (Transaction tx = persistence.createTransaction()) {
persistence.getEntityManager().persist(foo);
tx.commit();
}
IdentityEntity loaded;
try (Transaction tx = persistence.createTransaction()) {
loaded = persistence.getEntityManager().find(IdentityEntity.class, foo.getId());
tx.commit();
}
assertEquals(foo, loaded);
try (Transaction tx = persistence.createTransaction()) {
loaded = persistence.getEntityManager().find(IdentityEntity.class, loaded.getId());
persistence.getEntityManager().remove(loaded);
tx.commit();
}
assertTrue(BaseEntityInternalAccess.isRemoved(loaded));
try (Transaction tx = persistence.createTransaction()) {
loaded = persistence.getEntityManager().find(IdentityEntity.class, loaded.getId());
assertNull(loaded);
tx.commit();
}
}
use of com.haulmont.cuba.testmodel.primary_keys.IdentityEntity in project cuba by cuba-platform.
the class IdentityTest method testLoadByIdValue.
@Test
public void testLoadByIdValue() throws Exception {
IdentityEntity foo = metadata.create(IdentityEntity.class);
foo.setName("foo");
foo.setEmail("foo@mail.com");
try (Transaction tx = persistence.createTransaction()) {
persistence.getEntityManager().persist(foo);
tx.commit();
}
Long idVal = foo.getId().get();
IdentityEntity loaded;
try (Transaction tx = persistence.createTransaction()) {
loaded = persistence.getEntityManager().find(IdentityEntity.class, IdProxy.of(idVal));
tx.commit();
}
assertEquals(foo, loaded);
try (Transaction tx = persistence.createTransaction()) {
TypedQuery<IdentityEntity> query = persistence.getEntityManager().createQuery("select e from test$IdentityEntity e where e.id = :id", IdentityEntity.class);
query.setParameter("id", idVal);
loaded = query.getSingleResult();
tx.commit();
}
assertEquals(foo, loaded);
try (Transaction tx = persistence.createTransaction()) {
TypedQuery<IdentityEntity> query = persistence.getEntityManager().createQuery("select e from test$IdentityEntity e where e.id = :id", IdentityEntity.class);
query.setParameter("id", IdProxy.of(idVal));
loaded = query.getSingleResult();
tx.commit();
}
assertEquals(foo, loaded);
}
Aggregations