org.hibernate.Transaction.registerSynchronization()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(124)

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

Transaction.registerSynchronization介绍

[英]Register a user synchronization callback for this transaction.
[中]为此事务注册用户同步回调。

代码示例

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

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    // on the inverse, it makes sense that if a ThreadLocalSessionContext-
    // bound session then gets deserialized to go ahead and re-bind it to
    // the ThreadLocalSessionContext session map.
    ois.defaultReadObject();
    realSession.getTransaction().registerSynchronization( buildCleanupSynch() );
    doBind( wrappedSession, factory() );
  }
}

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

@Override
public final Session currentSession() throws HibernateException {
  Session current = existingSession( factory() );
  if ( current == null ) {
    current = buildOrObtainSession();
    // register a cleanup sync
    current.getTransaction().registerSynchronization( buildCleanupSynch() );
    // wrap the session in the transaction-protection proxy
    if ( needsWrapping( current ) ) {
      current = wrap( current );
    }
    // then bind it
    doBind( current, factory() );
  }
  else {
    validateExistingSession( current );
  }
  return current;
}

代码示例来源:origin: org.aperteworkflow/activiti-context

@Override
public void addTransactionCallback(HibernateTransactionCallback callback) {
  transaction.registerSynchronization(callback);
}

代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter

@Override
public void registerSynchronization(final Synchronization synchronization) throws HibernateException {
  transaction.registerSynchronization(synchronization);
}

代码示例来源:origin: jboss.jboss-embeddable-ejb3/hibernate-all

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    // on the inverse, it makes sense that if a ThreadLocalSessionContext-
    // bound session then gets deserialized to go ahead and re-bind it to
    // the ThreadLocalSessionContext session map.
    ois.defaultReadObject();
    realSession.getTransaction().registerSynchronization( buildCleanupSynch() );
    doBind( wrappedSession, factory );
  }
}

代码示例来源:origin: org.compass-project/compass

public static void registerRemovalHook(EventSource eventSource, Map<Object, Collection> pendingMap, Object entity) {
  eventSource.getTransaction().registerSynchronization(new RemoveFromPending(pendingMap, entity));
}

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

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    // on the inverse, it makes sense that if a ThreadLocalSessionContext-
    // bound session then gets deserialized to go ahead and re-bind it to
    // the ThreadLocalSessionContext session map.
    ois.defaultReadObject();
    realSession.getTransaction().registerSynchronization( buildCleanupSynch() );
    doBind( wrappedSession, factory() );
  }
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    // on the inverse, it makes sense that if a ThreadLocalSessionContext-
    // bound session then gets deserialized to go ahead and re-bind it to
    // the ThreadLocalSessionContext session map.
    ois.defaultReadObject();
    realSession.getTransaction().registerSynchronization( buildCleanupSynch() );
    doBind( wrappedSession, factory() );
  }
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.core

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    // on the inverse, it makes sense that if a ThreadLocalSessionContext-
    // bound session then gets deserialized to go ahead and re-bind it to
    // the ThreadLocalSessionContext session map.
    ois.defaultReadObject();
    realSession.getTransaction().registerSynchronization( buildCleanupSynch() );
    doBind( wrappedSession, factory() );
  }
}

代码示例来源:origin: org.jboss.seam.transaction/seam-transaction

@Override
public void registerSynchronization(Synchronization sync) {
  if (log.isDebugEnabled()) {
    log.debug("registering synchronization: " + sync);
  }
  getDelegate().registerSynchronization(sync);
}

代码示例来源:origin: org.jboss.seam/jboss-seam

@Override
public boolean registerSynchronization(Synchronization sync, EntityManager entityManager)
{
 try
 {
   //TODO: just make sure that a Hibernate JPA EntityTransaction
   //      delegates to the Hibernate Session transaction
   getSession(entityManager).getTransaction().registerSynchronization(sync);
   return true;
 }
 catch (NotHibernateException nhe)
 {
   return super.registerSynchronization(sync, entityManager);
 }
}

代码示例来源:origin: org.jbpm.jbpm3/jbpm-jpdl

private static void registerNotification(final String event) {
 Synchronization notification = new Synchronization() {
  public void beforeCompletion() {
  }
  public void afterCompletion(int status) {
   if (status == Status.STATUS_COMMITTED) {
    if (log.isDebugEnabled()) log.debug("sending '" + event + "' notification");
    Semaphore eventSemaphore = getEventSemaphore(event);
    eventSemaphore.release();
   }
  }
 };
 JbpmContext.getCurrentJbpmContext()
  .getSession()
  .getTransaction()
  .registerSynchronization(notification);
}

代码示例来源:origin: com.github.albfernandez/jbpm-jpdl

private static void registerNotification(final String event) {
 Synchronization notification = new Synchronization() {
  public void beforeCompletion() {
  }
  public void afterCompletion(int status) {
   if (status == Status.STATUS_COMMITTED) {
    if (log.isDebugEnabled()) log.debug("sending '" + event + "' notification");
    Semaphore eventSemaphore = getEventSemaphore(event);
    eventSemaphore.release();
   }
  }
 };
 JbpmContext.getCurrentJbpmContext()
  .getSession()
  .getTransaction()
  .registerSynchronization(notification);
}

代码示例来源:origin: org.jboss.seam/jboss-seam

@Override
public void registerSynchronization(Synchronization sync)
{
 if ( log.isDebugEnabled() )
 {
   log.debug("registering synchronization: " + sync);
 }
 assertActive();
 getDelegate().registerSynchronization(sync);
}

代码示例来源:origin: theonedev/onedev

@Override
public void doAfterCommit(Runnable runnable) {
  if (getSession().getTransaction().isActive()) {
    getSession().getTransaction().registerSynchronization(new Synchronization() {
      
      @Override
      public void beforeCompletion() {
      }
      
      @Override
      public void afterCompletion(int status) {
        if (status == Status.STATUS_COMMITTED)
          runnable.run();
      }
      
    });
  } else {
    runnable.run();
  }
}

代码示例来源:origin: org.jboss.seam/jboss-seam

private void joinTransaction() throws SystemException
{
 UserTransaction transaction = Transaction.instance();
 if ( transaction.isActive() )
 {
   session.isOpen();
   try
   {
    transaction.registerSynchronization(this);
   }
   catch (Exception e)
   {
    session.getTransaction().registerSynchronization(this);
   }
   synchronizationRegistered = true;
 }
}

代码示例来源:origin: org.jboss.seam.transaction/seam-transaction

public void begin() throws NotSupportedException, SystemException {
  log.debug("beginning JPA resource-local transaction");
  // TODO: translate exceptions that occur into the correct JTA exception
  try {
    getDelegate().begin();
    getSynchronizations().afterTransactionBegin();
    // use hibernate to manage the synchronizations
    // that way even if the user commits the transaction
    // themselves they will still be handled
    getDelegate().registerSynchronization(this);
    synchronizationRegistered = true;
  } catch (RuntimeException re) {
    throw re;
  }
}

代码示例来源:origin: jboss.jboss-embeddable-ejb3/hibernate-all

public final Session currentSession() throws HibernateException {
  Session current = existingSession( factory );
  if (current == null) {
    current = buildOrObtainSession();
    // register a cleanup synch
    current.getTransaction().registerSynchronization( buildCleanupSynch() );
    // wrap the session in the transaction-protection proxy
    if ( needsWrapping( current ) ) {
      current = wrap( current );
    }
    // then bind it
    doBind( current, factory );
  }
  return current;
}

代码示例来源:origin: org.jboss.seam/jboss-seam

private void joinTransaction() throws SystemException
{
 UserTransaction transaction = Transaction.instance();
 
 if ( !transaction.isActiveOrMarkedRollback() )
 {
   throw new IllegalStateException("JbpmContext may only be used inside a transaction");
 }
 
 if ( !synchronizationRegistered && !Lifecycle.isDestroying() && transaction.isActive() )
 {
   jbpmContext.getSession().isOpen();
   try //TODO: what we really want here is if (!cmt)
   {
    transaction.registerSynchronization(this);
   }
   catch (UnsupportedOperationException uoe)
   {
    jbpmContext.getSession().getTransaction().registerSynchronization(this);
   }
   synchronizationRegistered = true;
 }
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate

@Override
public final Session currentSession() throws HibernateException {
  Session current = existingSession( factory() );
  if ( current == null ) {
    current = buildOrObtainSession();
    // register a cleanup sync
    current.getTransaction().registerSynchronization( buildCleanupSynch() );
    // wrap the session in the transaction-protection proxy
    if ( needsWrapping( current ) ) {
      current = wrap( current );
    }
    // then bind it
    doBind( current, factory() );
  }
  else {
    validateExistingSession( current );
  }
  return current;
}

相关文章