javax.transaction.Synchronization类的使用及代码示例

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

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

Synchronization介绍

[英]This is the callback interface that has to be implemented by objects interested in receiving notification before and after a transaction commits or rolls back. An interested party can give an instance implementing this interface as an argument to the Transaction#registerSynchronization(Synchronization)method to receive callbacks before and after a transaction commits or rolls back.
[中]这是回调接口,必须由对在事务提交或回滚之前和之后接收通知感兴趣的对象实现。相关方可以将实现此接口的实例作为参数提供给事务#registerSynchronization(同步)方法,以在事务提交或回滚之前和之后接收回调。

代码示例

代码示例来源: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: apache/geode

/**
 * Iterate over the list of Synchronizations to complete all the methods to be performed before
 * completion
 */
boolean notifyBeforeCompletion() {
 Iterator iterator = syncList.iterator();
 boolean result = true;
 while (iterator.hasNext()) {
  sync = ((Synchronization) iterator.next());
  sync.beforeCompletion();
 }
 return result;
}

代码示例来源: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: 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: 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 void notifySynchronizationsBeforeTransactionCompletion() {
  if ( synchronizations != null ) {
    for ( Synchronization synchronization : synchronizations ) {
      try {
        synchronization.beforeCompletion();
      }
      catch ( Throwable t ) {
        LOG.synchronizationFailed( synchronization, t );
      }
    }
  }
}

代码示例来源: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: ehcache/ehcache3

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

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

private void fireBeforeCompletion() {
 for (Synchronization synchronization : synchronizations) {
  synchronization.beforeCompletion();
 }
}

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

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

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

@Override
public void beforeCompletion() {
  try {
    NamespaceContextSelector.pushCurrentSelector(selector);
    synchronization.beforeCompletion();
  } 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: hibernate/hibernate-orm

@Override
public void notifySynchronizationsBeforeTransactionCompletion() {
  log.trace( "SynchronizationRegistryStandardImpl.notifySynchronizationsBeforeTransactionCompletion" );
  if ( synchronizations != null ) {
    for ( Synchronization synchronization : synchronizations ) {
      try {
        synchronization.beforeCompletion();
      }
      catch (Throwable t) {
        log.synchronizationFailed( synchronization, t );
        throw new LocalSynchronizationException(
            "Exception calling user Synchronization (beforeCompletion): " + synchronization.getClass().getName(),
            t
        );
      }
    }
  }
}

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

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

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

+ preJcaSync);
preJcaSync.beforeCompletion();
lastIndexProcessed = lastIndexProcessed + 1;
    + jcaSync);
jcaSync.beforeCompletion();
lastIndexProcessed = lastIndexProcessed + 1;

代码示例来源: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: wildfly/wildfly

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

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

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

代码示例来源:origin: org.apache.openjpa/openjpa-all

/**
   * BeforeCompletion wrapper. Translates WAS proprietary call to a
   * javax.transaction.Synchronization call.
   */
  public void beforeCompletion(int arg0, byte[] arg1) {
    if (_sync != null) {
      _sync.beforeCompletion();
    }
  }
}

代码示例来源:origin: wxbty/meepo

public void afterCompletion(int status) {
  if (this.finishRequired) {
    try {
      this.delegate.afterCompletion(status);
    } catch (RuntimeException rex) {
      // ignore
    } finally {
      this.finishRequired = false;
    }
  }
}

相关文章