本文整理汇总了Java中com.google.inject.persist.UnitOfWork类的典型用法代码示例。如果您正苦于以下问题:Java UnitOfWork类的具体用法?Java UnitOfWork怎么用?Java UnitOfWork使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnitOfWork类属于com.google.inject.persist包,在下文中一共展示了UnitOfWork类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
@Override
protected final void configure() {
configurePersistence();
requireBinding(PersistService.class);
requireBinding(UnitOfWork.class);
/*if[AOP]*/
// wrapping in an if[AOP] just to allow this to compile in NO_AOP -- it won't be used
// class-level @Transacational
bindInterceptor(annotatedWith(Transactional.class),
new TransactionalClassMethodMatcher(),
getTransactionInterceptor());
// method-level @Transacational
bindInterceptor(any(), new TransactionalMethodMatcher(), getTransactionInterceptor());
/*end[AOP]*/
}
示例2: configurePersistence
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
protected void configurePersistence() {
bind(String[].class).annotatedWith(Neo4j.class).toInstance(packages);
if (null != properties) {
bind(Properties.class).annotatedWith(Neo4j.class).toInstance(properties);
} else {
bind(Properties.class).annotatedWith(Neo4j.class).toProvider(Providers.of(null));
}
bind(Neo4jPersistService.class).in(Singleton.class);
bind(PersistService.class).to(Neo4jPersistService.class);
bind(UnitOfWork.class).to(Neo4jPersistService.class);
bind(Session.class).toProvider(Neo4jPersistService.class);
transactionInterceptor = new Neo4jLocalTxnInterceptor();
requestInjection(transactionInterceptor);
}
示例3: testCall
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void testCall() throws Exception {
final String message = "TestMessage";
final CallableInUnitOfWork<String> unitOfWork = new CallableInUnitOfWork<>(
() -> new UnitOfWork() {
@Override
public void begin() {
}
@Override
public void end() {
}
}, () -> message);
assertEquals(message, unitOfWork.call());
}
示例4: configurePersistence
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
@Override
protected void configurePersistence() {
bindConstant().annotatedWith(Jpa.class).to(jpaUnit);
bind(JpaPersistService.class).in(Singleton.class);
bind(PersistService.class).to(JpaPersistService.class);
bind(UnitOfWork.class).to(JpaPersistService.class);
bind(EntityManager.class).toProvider(JpaPersistService.class);
bind(EntityManagerFactory.class)
.toProvider(JpaPersistService.EntityManagerFactoryProvider.class);
transactionInterceptor = new JpaLocalTxnInterceptor();
requestInjection(transactionInterceptor);
// Bind dynamic finders.
for (Class<?> finder : dynamicFinders) {
bindFinder(finder);
}
}
示例5: testSimpleTransaction
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void testSimpleTransaction() {
injector
.getInstance(JoiningLocalTransactionsTest.TransactionalObject.class)
.runOperationInTxn();
EntityManager em = injector.getInstance(EntityManager.class);
assertFalse("txn was not closed by transactional service", em.getTransaction().isActive());
//test that the data has been stored
Object result =
em.createQuery("from JpaTestEntity where text = :text")
.setParameter("text", UNIQUE_TEXT)
.getSingleResult();
injector.getInstance(UnitOfWork.class).end();
assertTrue("odd result returned fatal", result instanceof JpaTestEntity);
assertEquals(
"queried entity did not match--did automatic txn fail?",
UNIQUE_TEXT,
((JpaTestEntity) result).getText());
}
示例6: testSimpleTransactionRollbackOnUnchecked
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void testSimpleTransactionRollbackOnUnchecked() {
try {
injector
.getInstance(JoiningLocalTransactionsTest.TransactionalObject.class)
.runOperationInTxnThrowingUnchecked();
} catch (RuntimeException re) {
//ignore
injector.getInstance(UnitOfWork.class).end();
}
EntityManager em = injector.getInstance(EntityManager.class);
assertFalse(
"Session was not closed by transactional service (rollback didnt happen?)",
em.getTransaction().isActive());
try {
Object result =
em.createQuery("from JpaTestEntity where text = :text")
.setParameter("text", TRANSIENT_UNIQUE_TEXT)
.getSingleResult();
injector.getInstance(UnitOfWork.class).end();
fail("a result was returned! rollback sure didnt happen!!!");
} catch (NoResultException e) {
}
}
示例7: testSimpleTransaction
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void testSimpleTransaction() {
injector.getInstance(TransactionalObject.class).runOperationInTxn();
EntityManager em = injector.getInstance(EntityManager.class);
assertFalse("txn was not closed by transactional service", em.getTransaction().isActive());
//test that the data has been stored
Object result =
em.createQuery("from JpaTestEntity where text = :text")
.setParameter("text", UNIQUE_TEXT)
.getSingleResult();
injector.getInstance(UnitOfWork.class).end();
assertTrue("odd result returned fatal", result instanceof JpaTestEntity);
assertEquals(
"queried entity did not match--did automatic txn fail?",
UNIQUE_TEXT,
((JpaTestEntity) result).getText());
}
示例8: testSimpleTransactionWithMerge
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void testSimpleTransactionWithMerge() {
JpaTestEntity entity =
injector.getInstance(TransactionalObject.class).runOperationInTxnWithMerge();
EntityManager em = injector.getInstance(EntityManager.class);
assertFalse("txn was not closed by transactional service", em.getTransaction().isActive());
//test that the data has been stored
assertTrue("Em was closed after txn!", em.isOpen());
Object result =
em.createQuery("from JpaTestEntity where text = :text")
.setParameter("text", UNIQUE_TEXT_MERGE)
.getSingleResult();
injector.getInstance(UnitOfWork.class).end();
assertTrue(result instanceof JpaTestEntity);
assertEquals(
"queried entity did not match--did automatic txn fail?",
UNIQUE_TEXT_MERGE,
((JpaTestEntity) result).getText());
}
示例9: testSimpleTransactionRollbackOnUnchecked
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void testSimpleTransactionRollbackOnUnchecked() {
try {
injector.getInstance(TransactionalObject.class).runOperationInTxnThrowingUnchecked();
} catch (RuntimeException re) {
//ignore
injector.getInstance(UnitOfWork.class).end();
}
EntityManager em = injector.getInstance(EntityManager.class);
assertFalse(
"Session was not closed by transactional service (rollback didnt happen?)",
em.getTransaction().isActive());
try {
Object result =
em.createQuery("from JpaTestEntity where text = :text")
.setParameter("text", TRANSIENT_UNIQUE_TEXT)
.getSingleResult();
injector.getInstance(UnitOfWork.class).end();
fail("a result was returned! rollback sure didnt happen!!!");
} catch (NoResultException e) {
}
}
示例10: testSimpleTransaction
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void testSimpleTransaction() {
injector.getInstance(TransactionalObject.class).runOperationInTxn();
EntityManager em = injector.getInstance(EntityManager.class);
assertFalse(em.getTransaction().isActive());
//test that the data has been stored
Object result =
em.createQuery("from JpaTestEntity where text = :text")
.setParameter("text", UNIQUE_TEXT)
.getSingleResult();
injector.getInstance(UnitOfWork.class).end();
assertTrue("odd result returned fatal", result instanceof JpaTestEntity);
assertEquals(
"queried entity did not match--did automatic txn fail?",
UNIQUE_TEXT,
((JpaTestEntity) result).getText());
injector.getInstance(UnitOfWork.class).end();
}
示例11: disabled_testSimpleTransactionWithMergeAndDF
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void disabled_testSimpleTransactionWithMergeAndDF() {
EntityManager emOrig = injector.getInstance(EntityManager.class);
JpaTestEntity entity =
injector.getInstance(TransactionalObject.class).runOperationInTxnWithMergeForDf();
EntityManager em = injector.getInstance(EntityManager.class);
assertFalse("txn was not closed by transactional service", em.getTransaction().isActive());
//test that the data has been stored
assertTrue("Em was closed after txn!", em.isOpen());
assertEquals("Em was not kept open across txns", emOrig, em);
assertTrue("Merge did not store state or did not return persistent copy", em.contains(entity));
Object result = injector.getInstance(TransactionalObject.class).find(UNIQUE_TEXT_MERGE_FORDF);
injector.getInstance(UnitOfWork.class).end();
assertNotNull(result);
assertTrue(result instanceof JpaTestEntity);
assertEquals(
"queried entity did not match--did automatic txn fail?",
UNIQUE_TEXT_MERGE_FORDF,
((JpaTestEntity) result).getText());
injector.getInstance(UnitOfWork.class).end();
}
示例12: testSimpleTransactionRollbackOnUnchecked
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void testSimpleTransactionRollbackOnUnchecked() {
try {
injector.getInstance(TransactionalObject.class).runOperationInTxnThrowingUnchecked();
} catch (RuntimeException re) {
//ignore
injector.getInstance(UnitOfWork.class).end();
}
EntityManager em = injector.getInstance(EntityManager.class);
assertFalse(
"Session was not closed by transactional service (rollback didnt happen?)",
em.getTransaction().isActive());
try {
Object result =
em.createQuery("from JpaTestEntity where text = :text")
.setParameter("text", TRANSIENT_UNIQUE_TEXT)
.getSingleResult();
injector.getInstance(UnitOfWork.class).end();
fail();
} catch (NoResultException e) {
}
injector.getInstance(UnitOfWork.class).end();
}
示例13: configurePersistence
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
@Override protected void configurePersistence() {
bindConstant().annotatedWith(Jpa.class).to(jpaUnit);
if (null != properties) {
bind(Properties.class).annotatedWith(Jpa.class).toInstance(properties);
} else {
bind(Properties.class).annotatedWith(Jpa.class)
.toProvider(Providers.<Properties>of(null));
}
bind(JpaPersistService.class).in(Singleton.class);
bind(PersistService.class).to(JpaPersistService.class);
bind(UnitOfWork.class).to(JpaPersistService.class);
bind(EntityManager.class).toProvider(JpaPersistService.class);
bind(EntityManagerFactory.class)
.toProvider(JpaPersistService.EntityManagerFactoryProvider.class);
transactionInterceptor = new JpaLocalTxnInterceptor();
requestInjection(transactionInterceptor);
// Bind dynamic finders.
for (Class<?> finder : dynamicFinders) {
bindFinder(finder);
}
}
示例14: testSimpleCrossTxnWork
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void testSimpleCrossTxnWork() {
//pretend that the request was started here
EntityManager em = injector.getInstance(EntityManager.class);
JpaTestEntity entity = injector
.getInstance(ManualLocalTransactionsWithCustomMatcherTest.TransactionalObject.class)
.runOperationInTxn();
injector.getInstance(ManualLocalTransactionsWithCustomMatcherTest.TransactionalObject.class)
.runOperationInTxn2();
//persisted entity should remain in the same em (which should still be open)
assertTrue("EntityManager appears to have been closed across txns!",
injector.getInstance(EntityManager.class).contains(entity));
assertTrue("EntityManager appears to have been closed across txns!", em.contains(entity));
assertTrue("EntityManager appears to have been closed across txns!", em.isOpen());
injector.getInstance(UnitOfWork.class).end();
//try to query them back out
em = injector.getInstance(EntityManager.class);
assertNotNull(em.createQuery("from JpaTestEntity where text = :text")
.setParameter("text", UNIQUE_TEXT).getSingleResult());
assertNotNull(em.createQuery("from JpaTestEntity where text = :text")
.setParameter("text", UNIQUE_TEXT_2).getSingleResult());
em.close();
}
示例15: testSimpleTransaction
import com.google.inject.persist.UnitOfWork; //导入依赖的package包/类
public void testSimpleTransaction() {
injector.getInstance(JoiningLocalTransactionsTest.TransactionalObject.class)
.runOperationInTxn();
EntityManager em = injector.getInstance(EntityManager.class);
assertFalse("txn was not closed by transactional service",
em.getTransaction().isActive());
//test that the data has been stored
Object result = em.createQuery("from JpaTestEntity where text = :text")
.setParameter("text", UNIQUE_TEXT).getSingleResult();
injector.getInstance(UnitOfWork.class).end();
assertTrue("odd result returned fatal", result instanceof JpaTestEntity);
assertEquals("queried entity did not match--did automatic txn fail?", UNIQUE_TEXT,
((JpaTestEntity) result).getText());
}