Package javax.transaction

Examples of javax.transaction.Synchronization


      cache.put("/one/two/three", "key1", "val1");
      numLocks = cache.getNumberOfLocksHeld();
      assertEquals(4, numLocks);

      // we register *second*
      tx.registerSynchronization(new Synchronization()
      {

         public void beforeCompletion()
         {
            try
View Full Code Here


      cache.put("/one/two/three", "key1", "val1");
      numLocks = cache.getNumberOfLocksHeld();
      assertEquals(4, numLocks);

      // we register *second*
      tx.registerSynchronization(new Synchronization()
      {

         public void beforeCompletion()
         {
         }
View Full Code Here

    if ( !open ) {
      throw new IllegalStateException( "EntityManager is closed" );
    }
    if ( !discardOnClose && isTransactionInProgress() ) {
      //delay the closing till the end of the enlisted transaction
            getSession().getTransaction().registerSynchronization(new Synchronization() {
                public void beforeCompletion() {
                    // nothing to do
                }

        public void afterCompletion( int i ) {
View Full Code Here

         OrderedSynchronizationHandler osh = transactionContext.getOrderedSynchronizationHandler();

         final Transaction finalTx = tx;
         System.out.println("Notify called.");
         // add an aborting sync handler.
         Synchronization abort = new Synchronization()
         {

            public void beforeCompletion()
            {
               if (abortBeforeCompletion)
View Full Code Here

        when(transactionSynchronizationRegistry.getTransactionKey()).thenReturn("TX1");
        final List<Synchronization> synchronizations = new LinkedList<Synchronization>();
        doAnswer(new Answer<Void>() {
            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                Synchronization synchronization = (Synchronization) invocation.getArguments()[0];
                synchronizations.add(synchronization);
                return null;
            }
        }).when(transactionSynchronizationRegistry).registerInterposedSynchronization((Synchronization) any());
        final StatefulSessionComponentInstance instance = mock(StatefulSessionComponentInstance.class);
        when(instance.getComponent()).thenReturn(component);
        context.putPrivateData(ComponentInstance.class, instance);

        interceptor.processInvocation(context);

        // commit
        for (Synchronization synchronization : synchronizations) {
            synchronization.beforeCompletion();
        }
        for (Synchronization synchronization : synchronizations) {
            synchronization.afterCompletion(Status.STATUS_COMMITTED);
        }
        synchronizations.clear();

        when(transactionSynchronizationRegistry.getTransactionKey()).thenReturn("TX2");
View Full Code Here

        map = Collections.synchronizedMap(new HashMap<Object, CacheEntry>());
        final Map<Object, CacheEntry> existing = cache.putIfAbsent(key, map);
        if (existing != null) {
            map = existing;
        }
        transactionSynchronizationRegistry.registerInterposedSynchronization(new Synchronization() {
            @Override
            public void beforeCompletion() {

            }
View Full Code Here

                    //and if the transaction is rolled back we release the instance back into the pool

                    final TransactionSynchronizationRegistry transactionSynchronizationRegistry = entityBeanComponent.getTransactionSynchronizationRegistry();
                    if (transactionSynchronizationRegistry.getTransactionKey() != null) {
                        if(!instanceCachedBefore) {
                            transactionSynchronizationRegistry.registerInterposedSynchronization(new Synchronization() {
                                @Override
                                public void beforeCompletion() {

                                }
View Full Code Here

        //and if the transaction is rolled back we release the instance back into the pool

        final TransactionSynchronizationRegistry transactionSynchronizationRegistry = entityBeanComponent.getTransactionSynchronizationRegistry();

        if (transactionSynchronizationRegistry.getTransactionKey() != null) {
            transactionSynchronizationRegistry.registerInterposedSynchronization(new Synchronization() {
                @Override
                public void beforeCompletion() {

                }
View Full Code Here

                        // if this entity instance is already associated with a different transaction, then it's an error

                        // if the thread is currently associated with a tx, then register a tx synchronization
                        if (currentTransactionKey != null) {
                            // register a tx synchronization for this entity instance
                            final Synchronization entitySynchronization = new EntityBeanSynchronization(instance, lockOwner);
                            transactionSynchronizationRegistry.registerInterposedSynchronization(entitySynchronization);
                            syncRegistered = true;
                            if (ROOT_LOGGER.isTraceEnabled()) {
                                ROOT_LOGGER.trace("Registered tx synchronization: " + entitySynchronization + " for tx: " + currentTransactionKey +
                                        " associated with stateful component instance: " + instance);
View Full Code Here

   * avoiding object loading during a flush. Not needed during transactions.
   */
  public void onFlush(FlushEvent event) {
    if ( used ) {
      Session session = event.getSession();
      Synchronization synchronization = flushSynch.get( session );
      if ( synchronization != null ) {
        //first cleanup
        flushSynch.remove( session );
        log.debug( "flush event causing index update out of transaction" );
        synchronization.beforeCompletion();
        synchronization.afterCompletion( Status.STATUS_COMMITTED );
      }
    }
  }
View Full Code Here

TOP

Related Classes of javax.transaction.Synchronization

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.