当前位置: 首页>>代码示例>>Java>>正文


Java UnitOfWork类代码示例

本文整理汇总了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]*/
}
 
开发者ID:mangrish,项目名称:guice-persist-neo4j,代码行数:18,代码来源:Neo4jPersistModule.java

示例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);
}
 
开发者ID:mangrish,项目名称:guice-persist-neo4j,代码行数:18,代码来源:Neo4jPersistModule.java

示例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());
}
 
开发者ID:MoodCat,项目名称:MoodCat.me-Core,代码行数:19,代码来源:CallableInUnitOfWorkTest.java

示例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);
  }
}
 
开发者ID:google,项目名称:guice,代码行数:21,代码来源:JpaPersistModule.java

示例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());
}
 
开发者ID:google,项目名称:guice,代码行数:23,代码来源:JoiningLocalTransactionsTest.java

示例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) {
  }
}
 
开发者ID:google,项目名称:guice,代码行数:26,代码来源:JoiningLocalTransactionsTest.java

示例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());
}
 
开发者ID:google,项目名称:guice,代码行数:21,代码来源:ManagedLocalTransactionsTest.java

示例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());
}
 
开发者ID:google,项目名称:guice,代码行数:24,代码来源:ManagedLocalTransactionsTest.java

示例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) {
  }
}
 
开发者ID:google,项目名称:guice,代码行数:24,代码来源:ManagedLocalTransactionsTest.java

示例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();
}
 
开发者ID:google,项目名称:guice,代码行数:22,代码来源:ManagedLocalTransactionsAcrossRequestTest.java

示例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();
}
 
开发者ID:google,项目名称:guice,代码行数:26,代码来源:ManagedLocalTransactionsAcrossRequestTest.java

示例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();
}
 
开发者ID:google,项目名称:guice,代码行数:26,代码来源:ManagedLocalTransactionsAcrossRequestTest.java

示例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);
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:27,代码来源:JpaPersistModule.java

示例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();
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:27,代码来源:ManualLocalTransactionsWithCustomMatcherTest.java

示例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());
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:19,代码来源:JoiningLocalTransactionsTest.java


注:本文中的com.google.inject.persist.UnitOfWork类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。