javax.transaction.Synchronization.afterCompletion()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(81)

本文整理了Java中javax.transaction.Synchronization.afterCompletion()方法的一些代码示例,展示了Synchronization.afterCompletion()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Synchronization.afterCompletion()方法的具体详情如下:
包路径:javax.transaction.Synchronization
类名称:Synchronization
方法名:afterCompletion

Synchronization.afterCompletion介绍

[英]This method is invoked after the transaction has committed or rolled back.
[中]此方法在事务提交或回滚后调用。

代码示例

代码示例来源:origin: apache/geode

/**
 * Iterate over the list of Synchronizations to complete all the methods to be performed after
 * completion
 *
 * @param status int The status of the Global transaction associated with the transaction
 */
void notifyAfterCompletion(int status) throws SystemException {
 Iterator iterator = syncList.iterator();
 while (iterator.hasNext()) {
  sync = ((Synchronization) iterator.next());
  sync.afterCompletion(status);
 }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public void notifySynchronizationsAfterTransactionCompletion(int status) {
  if ( synchronizations != null ) {
    for ( Synchronization synchronization : synchronizations ) {
      try {
        synchronization.afterCompletion( status );
      }
      catch ( Throwable t ) {
        LOG.synchronizationFailed( synchronization, t );
      }
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
  if ( "afterCompletion".equals( method.getName() ) ) {
    int status = args[2].equals(Boolean.TRUE) ?
        Status.STATUS_COMMITTED :
        Status.STATUS_UNKNOWN;
    synchronization.afterCompletion(status);
  }
  else if ( "beforeCompletion".equals( method.getName() ) ) {
    synchronization.beforeCompletion();
  }
  else if ( "toString".equals( method.getName() ) ) {
    return synchronization.toString();
  }
  return null;
}

代码示例来源:origin: ehcache/ehcache3

private void fireAfterCompletion(int status) {
 for (Synchronization synchronization : synchronizations) {
  synchronization.afterCompletion(status);
 }
}

代码示例来源:origin: wildfly/wildfly

@Override
public void afterCompletion(final int status) {
  try {
    NamespaceContextSelector.pushCurrentSelector(selector);
    synchronization.afterCompletion(status);
  } finally {
    NamespaceContextSelector.popCurrentSelector();
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public void notifySynchronizationsAfterTransactionCompletion(int status) {
  log.tracef(
      "SynchronizationRegistryStandardImpl.notifySynchronizationsAfterTransactionCompletion(%s)",
      status
  );
  if ( synchronizations != null ) {
    try {
      for ( Synchronization synchronization : synchronizations ) {
        try {
          synchronization.afterCompletion( status );
        }
        catch (Throwable t) {
          log.synchronizationFailed( synchronization, t );
          throw new LocalSynchronizationException(
              "Exception calling user Synchronization (afterCompletion): " + synchronization.getClass().getName(),
              t
          );
        }
      }
    }
    finally {
      clearSynchronizations();
    }
  }
}

代码示例来源:origin: wildfly/wildfly

preJcaSync.afterCompletion(status);
} catch (Exception e) {
  jcaSync.afterCompletion(status);
} catch (Exception e) {

代码示例来源:origin: wildfly/wildfly

public void afterCompletion(final int status) {
    try {
      if (importBacking()) try {
        sync.afterCompletion(status);
      } finally {
        unimportBacking();
      } else {
        performConsumer(Synchronization::afterCompletion, sync, status);
      }
    } catch (SystemException e) {
      throw new SynchronizationException(e);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void jtaTransactionManagerWithExistingTransactionAndJtaSynchronization() throws Exception {
  UserTransaction ut = mock(UserTransaction.class);
  TransactionManager tm = mock(TransactionManager.class);
  MockJtaTransaction tx = new MockJtaTransaction();
  given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
  given(tm.getTransaction()).willReturn(tx);
  final TransactionSynchronization synch = mock(TransactionSynchronization.class);
  JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
  TransactionTemplate tt = new TransactionTemplate(ptm);
  assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  tt.execute(new TransactionCallbackWithoutResult() {
    @Override
    protected void doInTransactionWithoutResult(TransactionStatus status) {
      assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
      TransactionSynchronizationManager.registerSynchronization(synch);
      status.setRollbackOnly();
    }
  });
  assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  assertNotNull(tx.getSynchronization());
  tx.getSynchronization().beforeCompletion();
  tx.getSynchronization().afterCompletion(Status.STATUS_ROLLEDBACK);
  verify(ut).setRollbackOnly();
  verify(synch).beforeCompletion();
  verify(synch).afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
}

代码示例来源:origin: org.jboss.jbossas/jboss-as-server

public void afterCompletion(int status)
 {
   for(Synchronization sync : otherSync)
   {
    sync.afterCompletion(status);
   }
 }
}

代码示例来源:origin: org.ow2.bonita/bonita-pvm

public void afterCompletion(StandardTransaction.State transactionState) {
 if (transactionState == StandardTransaction.State.COMMITTED) {
  synchronization.afterCompletion(Status.STATUS_COMMITTED);
 } else if (transactionState == StandardTransaction.State.ROLLEDBACK) {
  synchronization.afterCompletion(Status.STATUS_ROLLEDBACK);
 } else {
  throw new TransactionException("invalid transaction state: "
    + transactionState);
 }
}

代码示例来源:origin: org.bytesoft/bytejta-core

public void afterCompletion(int status) {
  int length = this.synchronizations.size();
  for (int i = 0; i < length; i++) {
    Synchronization synchronization = this.synchronizations.get(i);
    synchronization.afterCompletion(status);
  } // end-for
}

代码示例来源:origin: net.oneandone/ejb-cdi-unit

public void synchAfterCompletion(int res) {
  if (synchronizations.get() != null) {
    for (Synchronization s : synchronizations.get()) {
      s.afterCompletion(res);
    }
  }
}

代码示例来源:origin: hibernate/hibernate-search

private void doAfterCompletion(int status) {
    if ( afterExecuted ) {
      log.tracef(
          "Transaction's afterCompletion() phase already been processed, ignoring: %s", delegate
      );
    }
    else {
      delegate.afterCompletion( status );
      afterExecuted = true;
    }
  }
}

代码示例来源:origin: org.apache.openejb/openejb-core

private void doAfterCompletion(final int status) {
  for (final Synchronization sync : new ArrayList<Synchronization>(registeredSynchronizations)) {
    try {
      sync.afterCompletion(status);
    } catch (final RuntimeException e) {
      logger.warning("Synchronization afterCompletion threw a RuntimeException", e);
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-core-tests

@Override
public void rollback() throws IllegalStateException, SystemException {
  if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK)
    throw new SystemException("Unable to rollback: invalid tx status: " + status);
  status = Status.STATUS_ROLLEDBACK;
  for (Synchronization sync : syncs) {
    sync.afterCompletion(Status.STATUS_ROLLEDBACK);
  }
}

代码示例来源:origin: hibernate/hibernate-search

@Override
  public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor sessionImplementor) {
    try {
      synchronization.afterCompletion( success ? Status.STATUS_COMMITTED : Status.STATUS_ROLLEDBACK );
    }
    catch (Exception e) {
      throw new HibernateException( "Error while indexing in Hibernate Search (after transaction completion)", e );
    }
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-weld-transactions

@Override
public void afterCompletion(final int status) {
  try {
    NamespaceContextSelector.pushCurrentSelector(selector);
    synchronization.afterCompletion(status);
  } finally {
    NamespaceContextSelector.popCurrentSelector();
  }
}

代码示例来源:origin: hibernate/hibernate-search

public void end() {
    this.progress = false;
    for ( Synchronization sync : syncs ) {
      sync.beforeCompletion();
    }

    for ( Synchronization sync : syncs ) {
      sync.afterCompletion( Status.STATUS_COMMITTED );
    }
  }
}

代码示例来源:origin: org.apache.aries.tx-control/tx-control-provider-jpa-xa-plugin-openjpa

@Override
public void registerSynchronization(Synchronization synch)
    throws IllegalStateException, RollbackException, SystemException {
  LOGGER.debug("Registering a synchronization with the current transaction");
  TransactionContext currentContext = getTxControl().getCurrentContext();
  currentContext.preCompletion(synch::beforeCompletion);
  currentContext.postCompletion(status -> synch.afterCompletion(toIntStatus(status)));
}

相关文章