use of org.apache.aries.tx.control.itests.entity.Message in project aries by apache.
the class AbstractSimpleTransactionTest method testRequiredInheritsTx.
@Test
public void testRequiredInheritsTx() {
Message message = new Message();
message.message = "Hello World!";
Message message2 = new Message();
message2.message = "Hello Nested World!";
txControl.required(() -> {
em.persist(message);
txControl.required(() -> {
em.persist(message2);
return null;
});
return null;
});
List<Message> results = txControl.notSupported(() -> {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Message> query = cb.createQuery(Message.class);
query.orderBy(cb.asc(query.from(Message.class).get("message")));
return em.createQuery(query).getResultList();
});
System.out.println(results);
assertEquals(2, results.size());
assertEquals("Hello Nested World!", results.get(0).message);
assertEquals("Hello World!", results.get(1).message);
}
use of org.apache.aries.tx.control.itests.entity.Message in project aries by apache.
the class AbstractSimpleTransactionTest method testNestedTxInnerRollback.
@Test
public void testNestedTxInnerRollback() {
Message message = new Message();
message.message = "Hello World!";
Message message2 = new Message();
message2.message = "Hello Nested World!";
txControl.required(() -> {
// This will end up in the database
em.persist(message);
// This nested transaction will not commit
txControl.requiresNew(() -> {
em.persist(message2);
txControl.setRollbackOnly();
return null;
});
return null;
});
List<Message> results = txControl.notSupported(() -> {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Message> query = cb.createQuery(Message.class);
query.orderBy(cb.asc(query.from(Message.class).get("message")));
return em.createQuery(query).getResultList();
});
System.out.println(results);
assertEquals(1, results.size());
assertEquals("Hello World!", results.get(0).message);
}
use of org.apache.aries.tx.control.itests.entity.Message in project aries by apache.
the class AbstractSimpleTransactionTest method testTx.
@Test
public void testTx() {
Message message = new Message();
message.message = "Hello World!";
txControl.required(() -> {
em.persist(message);
return null;
});
assertEquals("Hello World!", txControl.notSupported(() -> {
return em.find(Message.class, message.id).message;
}));
}
use of org.apache.aries.tx.control.itests.entity.Message in project aries by apache.
the class AbstractSimpleTransactionTest method testSuspendedTx.
@Test
public void testSuspendedTx() {
Message message = new Message();
message.message = "Hello World!";
txControl.required(() -> {
em.persist(message);
assertEquals(Long.valueOf(0), txControl.notSupported(() -> {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
countQuery.select(cb.count(countQuery.from(Message.class)));
return em.createQuery(countQuery).getSingleResult();
}));
return null;
});
}
use of org.apache.aries.tx.control.itests.entity.Message in project aries by apache.
the class AbstractSimpleTransactionTest method testRollback.
@Test
public void testRollback() {
Message message = new Message();
message.message = "Hello World!";
txControl.required(() -> {
em.persist(message);
txControl.setRollbackOnly();
return null;
});
assertEquals(Long.valueOf(0), txControl.notSupported(() -> {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
countQuery.select(cb.count(countQuery.from(Message.class)));
return em.createQuery(countQuery).getSingleResult();
}));
}
Aggregations