Examples of TransactionTemplate


Examples of org.springframework.transaction.support.TransactionTemplate

   
    public void testTransactionCommitWithPrebound() throws Exception
    {
    mockReplay();
   
    TransactionTemplate tt = new TransactionTemplate(jiniTM);
    assertSynchronizationManager();
   

    Created crtd = new Created(tx, lease);
    // bind tx object
    JiniHolder holder = new JiniHolder(crtd);
   
      TransactionSynchronizationManager.bindResource(space, holder);
     
      assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(space));
       
        tt.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(space));
                spaceTemplate.execute(new JavaSpaceCallback() {
                  public Object doInSpace(JavaSpace js, Transaction transaction) throws RemoteException, TransactionException, UnusableEntryException, InterruptedException {
                  return null;
View Full Code Here

Examples of org.springframework.transaction.support.TransactionTemplate

   
    public void testTransactionRollbackOnlyWithPrebound() throws Exception
    {
    mockReplay();
   
    TransactionTemplate tt = new TransactionTemplate(jiniTM);
    assertSynchronizationManager();
   
    Created crtd = new Created(tx, lease);
    // bind tx object
    JiniHolder holder = new JiniHolder(crtd);
   
      TransactionSynchronizationManager.bindResource(space, holder);
     
      assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(space));
       
        tt.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(space));
                spaceTemplate.execute(new JavaSpaceCallback() {
                  public Object doInSpace(JavaSpace js, Transaction transaction) throws RemoteException, TransactionException, UnusableEntryException, InterruptedException {
                  return null;
View Full Code Here

Examples of org.springframework.transaction.support.TransactionTemplate

    final SomeBean anotherTemplate = new SomeBean();
    anotherTemplate.name = "another bean";

    final long timeout = 1000 * 2;

    final TransactionTemplate notSupportedTransaction = new TransactionTemplate(
        txTemplate.getTransactionManager());
    notSupportedTransaction.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
    notSupportedTransaction.afterPropertiesSet();

    final TransactionTemplate mandatoryTransaction = new TransactionTemplate(txTemplate.getTransactionManager());
    mandatoryTransaction.setPropagationBehavior(TransactionDefinition.PROPAGATION_MANDATORY);
    mandatoryTransaction.afterPropertiesSet();

    final RuntimeException EXCEPTION = new RuntimeException("intentional exception");

    try {
      // start tx (REQUIRED)
      txTemplate.execute(new TransactionCallbackWithoutResult() {

        protected void doInTransactionWithoutResult(final TransactionStatus status) {
          spaceTemplate.execute(new JavaSpaceCallback() {
            public Object doInSpace(JavaSpace js, final Transaction transaction)
                throws RemoteException, TransactionException, UnusableEntryException,
                InterruptedException {
              // check that we have a tx
              assertNotNull("no tx started", transaction);
              Object result = js.read(template, transaction, timeout);
              assertNull(result);
              // write
              js.write(template, transaction, Lease.ANY);

              notSupportedTransaction.execute(new TransactionCallbackWithoutResult() {
                protected void doInTransactionWithoutResult(final TransactionStatus status2) {
                  spaceTemplate.execute(new JavaSpaceCallback() {
                    public Object doInSpace(JavaSpace js2, Transaction transaction2)
                        throws RemoteException, TransactionException,
                        UnusableEntryException, InterruptedException {
                      // NOT_SUPPORTED means tx was suspended
                      assertNull(transaction2);
                     
                      assertSame(transaction2, JiniUtils.getTransaction(space));
                     
                      js2.write(anotherTemplate, transaction2, Lease.ANY);
                      // check object from
                      // find the object in the parent transaction
                      Object rez = js2.read(template, transaction, timeout);
                      assertNotNull(rez);
                      // but not in child transaction (NOT_SUPPORTED)
                      rez = js2.read(template, transaction2, timeout);
                      assertNull(rez);
                      rez = js2.read(anotherTemplate, transaction2, timeout);
                      assertNotNull(rez);
                      return null;
                    }
                  });

                }
              });
              // find the template
              result = js.read(template, transaction, timeout);
              assertNotNull(result);
              result = js.read(anotherTemplate, transaction, timeout);
              assertNotNull(result);

              return mandatoryTransaction.execute(new TransactionCallbackWithoutResult() {
                protected void doInTransactionWithoutResult(TransactionStatus status) {
                  Transaction tx = JiniUtils.getTransaction(space);
                  assertSame(transaction ,tx);
                  assertNotNull(spaceTemplate.readIfExists(template,timeout));
                  throw EXCEPTION;
View Full Code Here

Examples of org.springframework.transaction.support.TransactionTemplate

      protected PersistenceBroker getPersistenceBroker() {
        return pb;
      }
    };

    TransactionTemplate tt = new TransactionTemplate(tm);
    assertTrue("Hasn't thread broker", !TransactionSynchronizationManager.hasResource(tm.getPbKey()));
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
        PersistenceBrokerTemplate pbt = new PersistenceBrokerTemplate();
        pbt.delete(entity);
      }
View Full Code Here

Examples of org.springframework.transaction.support.TransactionTemplate

      protected PersistenceBroker getPersistenceBroker() {
        return pb;
      }
    };

    TransactionTemplate tt = new TransactionTemplate(tm);
    tt.setReadOnly(true);
    tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
    assertTrue("Hasn't thread broker", !TransactionSynchronizationManager.hasResource(tm.getPbKey()));
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
        PersistenceBrokerTemplate pbt = new PersistenceBrokerTemplate();
        pbt.delete(entity);
        status.setRollbackOnly();
View Full Code Here

Examples of org.springframework.transaction.support.TransactionTemplate

        return pb;
      }
    };

    assertTrue("Hasn't thread broker", !TransactionSynchronizationManager.hasResource(tm.getPbKey()));
    final TransactionTemplate tt = new TransactionTemplate(tm);
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
        tt.execute(new TransactionCallbackWithoutResult() {
          protected void doInTransactionWithoutResult(TransactionStatus status) {
            assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
            PersistenceBrokerTemplate pbt = new PersistenceBrokerTemplate();
            pbt.delete(entity);
          }
View Full Code Here

Examples of org.springframework.transaction.support.TransactionTemplate

        return pb;
      }
    };

    assertTrue("Hasn't thread broker", !TransactionSynchronizationManager.hasResource(tm.getPbKey()));
    final TransactionTemplate tt = new TransactionTemplate(tm);
    try {
      tt.execute(new TransactionCallbackWithoutResult() {
        protected void doInTransactionWithoutResult(TransactionStatus status) {
          assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
          tt.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
              assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
              PersistenceBrokerTemplate pbt = new PersistenceBrokerTemplate();
              pbt.delete(entity);
              status.setRollbackOnly();
View Full Code Here

Examples of org.springframework.transaction.support.TransactionTemplate

        return (counter > 1 ? pb2 : pb1);
      }
    };

    assertTrue("Hasn't thread broker", !TransactionSynchronizationManager.hasResource(tm.getPbKey()));
    final TransactionTemplate tt = new TransactionTemplate(tm);
    tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
        assertEquals(pb1, OjbFactoryUtils.getPersistenceBroker(tm.getPbKey(), false));
        tt.execute(new TransactionCallbackWithoutResult() {
          protected void doInTransactionWithoutResult(TransactionStatus status) {
            assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
            assertEquals(pb2, OjbFactoryUtils.getPersistenceBroker(tm.getPbKey(), false));
          }
        });
View Full Code Here

Examples of org.springframework.transaction.support.TransactionTemplate

        return pb;
      }
    };
    tm.setDataSource(ds);

    TransactionTemplate tt = new TransactionTemplate(tm);
    assertTrue("Hasn't thread broker", !TransactionSynchronizationManager.hasResource(tm.getPbKey()));
    assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        assertTrue("Has thread broker", TransactionSynchronizationManager.hasResource(tm.getPbKey()));
        assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(ds));
        PersistenceBrokerTemplate pbt = new PersistenceBrokerTemplate();
        pbt.delete(entity);
View Full Code Here

Examples of org.springframework.transaction.support.TransactionTemplate

  public void testGetSessionInsideTransaction() {
    log.info("getSessionInsideTransaction");
    final Map sessionMap = new HashMap();

    TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
    transactionTemplate.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        JbpmSession firstSession = JbpmSessionFactoryUtils.getSession(jbpmSessionFactory);
        JbpmSession secondSession = JbpmSessionFactoryUtils.getSession(jbpmSessionFactory);
        sessionMap.put("first", firstSession);
        sessionMap.put("second", secondSession);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.