Package org.springframework.transaction.support

Examples of org.springframework.transaction.support.TransactionTemplate


    sessionControl.setReturnValue(null, 1);
    sfControl.replay();
    sessionControl.replay();

    JtaTransactionManager tm = new JtaTransactionManager(ut);
    TransactionTemplate tt = new TransactionTemplate(tm);
    tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));

    tt.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
        assertTrue("Is not new transaction", !status.isNewTransaction());
        assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
        assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
View Full Code Here


    sessionControl.setReturnValue(null, 1);
    sfControl.replay();
    sessionControl.replay();

    JtaTransactionManager tm = new JtaTransactionManager(ut);
    TransactionTemplate tt = new TransactionTemplate(tm);
    tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
    final TransactionTemplate tt2 = new TransactionTemplate(tm);
    tt2.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
    tt.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
        assertTrue("Is not new transaction", !status.isNewTransaction());
        assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
        assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
        HibernateTemplate ht = new HibernateTemplate(sf);
        ht.setFlushMode(HibernateTemplate.FLUSH_EAGER);
        ht.execute(new HibernateCallback() {
          public Object doInHibernate(org.hibernate.Session session) {
            return null;
          }
        });
        assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
        tt2.execute(new TransactionCallback() {
          public Object doInTransaction(TransactionStatus status) {
            HibernateTemplate ht = new HibernateTemplate(sf);
            ht.setFlushMode(HibernateTemplate.FLUSH_EAGER);
            return ht.executeFind(new HibernateCallback() {
              public Object doInHibernate(org.hibernate.Session session) {
View Full Code Here

    thread.join();

    assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
    assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

    TransactionTemplate tt = new TransactionTemplate(new JtaTransactionManager(tm));
    tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
    tt.setReadOnly(true);
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
        for (int i = 0; i < 5; i++) {
          ht.executeFind(new HibernateCallback() {
            public Object doInHibernate(org.hibernate.Session sess) {
View Full Code Here

          return null;
        }
      });
    }

    TransactionTemplate tt = new TransactionTemplate(new JtaTransactionManager(ut));
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        for (int i = 2; i < 5; i++) {
          ht.executeFind(new HibernateCallback() {
            public Object doInHibernate(org.hibernate.Session sess) {
              assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
View Full Code Here

        entityManagerFactory, null, OpenJPAEntityManager.class);
    assertNotNull(openJPAEntityManager.getDelegate());
  }

  public void testSavepoint() {
    TransactionTemplate tt = new TransactionTemplate(transactionManager);
    tt.setPropagationBehavior(TransactionTemplate.PROPAGATION_NESTED);
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        Person tony = new Person();
        tony.setFirstName("Tony");
        sharedEntityManager.merge(tony);
        Query q = sharedEntityManager.createQuery("select p from Person as p");
View Full Code Here

    tx = (EntityTransaction) txControl.getMock();

    transactionManager = new JpaTransactionManager(factory);
    template = new JpaTemplate(factory);
    template.afterPropertiesSet();
    tt = new TransactionTemplate(transactionManager);

    factoryControl.expectAndReturn(factory.createEntityManager(), manager);
    managerControl.expectAndReturn(manager.getTransaction(), tx);
    tx.begin();
    manager.close();
View Full Code Here

    assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());

    Object result = tt.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        assertFalse(TransactionSynchronizationManager.hasResource(factory));
        TransactionTemplate tt2 = new TransactionTemplate(transactionManager);
        tt2.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        return tt2.execute(new TransactionCallback() {
          public Object doInTransaction(TransactionStatus status) {
            return template.execute(new JpaCallback() {
              public Object doInJpa(EntityManager em2) {
                em2.flush();
                return l;
View Full Code Here

            return null;
          }
        });

        assertTrue(TransactionSynchronizationManager.hasResource(factory));
        TransactionTemplate tt2 = new TransactionTemplate(transactionManager);
        tt2.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        return tt2.execute(new TransactionCallback() {
          public Object doInTransaction(TransactionStatus status) {
            return template.execute(new JpaCallback() {
              public Object doInJpa(EntityManager em2) {
                em2.flush();
                return l;
View Full Code Here

  }
 
  @Test (groups="reads", dependsOnGroups="createsObjectInDB")
  public void testReadExclusive() {
   
    TransactionTemplate transactionTemplate =
      new TransactionTemplate(transactionManager);
   
    transactionTemplate.execute(
        new TransactionCallback() {
          public Object doInTransaction(TransactionStatus ts) {
            Employee employee =  employeeDao.readExclusive(testEmployees.get(0).getId());
            AssertJUnit.assertNotNull("Employee for id=1 not read.", employee);
            return null;
View Full Code Here

    }
   
  @Test (groups="createsObjectInDB")
    public void testStoreMultiple() {
        employeeDao.flushAndClear();
      TransactionTemplate xTemplate = new TransactionTemplate(transactionManager);
      xTemplate.execute(new TransactionCallback() {
   
      public Object doInTransaction(TransactionStatus arg0) {
            List<Employee> employees =Arrays.asList(
                new Employee[] {
                    new Employee("StoreMultipleOne", "Hightower"),
View Full Code Here

TOP

Related Classes of org.springframework.transaction.support.TransactionTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.