Ejemplo n.º 1
0
 private boolean isTxRunning() {
   ThreadContext.Context ctx = ThreadContext.getContext(this.metaData.getName());
   if (ctx == null) {
     return false;
   }
   return ctx.getTransactionStatus() != null;
 }
Ejemplo n.º 2
0
  @Override
  public void begin() {
    if (txLogger.isInfoEnabled()) {
      txLogger.info("begin");
    }

    ThreadContext.Context ctx = ThreadContext.getContext(this.metaData.getName());
    if (ctx == null) {
      ctx = new ThreadContext.Context(this.txMgr, this.metaData, this.cfg, this.sessionFactory);
    }

    TransactionStatus txStatus = ctx.getTransactionStatus();

    if (txStatus == null) {
      txStatus = this.txMgr.getTransaction(null);
      ctx.setTransactionStatus(txStatus);
    } else {
      if (txLogger.isWarnEnabled()) {
        txLogger.warn("ignoring begin - tx already in progress");
        if (txLogger.isDebugEnabled()) {
          logStackTrace();
        }
      }
    }
  }
Ejemplo n.º 3
0
  @Override
  public void commit() {

    if (txLogger.isInfoEnabled()) {
      txLogger.info("commit");
    }

    ThreadContext.Context ctx = ThreadContext.getContext(this.metaData.getName());

    if (ctx == null) {
      if (txLogger.isWarnEnabled()) {
        txLogger.warn("ignoring commit - no tx in progress");
        if (txLogger.isDebugEnabled()) {
          logStackTrace();
        }
      }
      return;
    }

    TransactionStatus txStatus = ctx.getTransactionStatus();

    try {
      if (txStatus == null) {
        if (txLogger.isWarnEnabled()) {
          txLogger.warn("ignoring commit - no tx status");
          if (txLogger.isDebugEnabled()) {
            logStackTrace();
          }
        }
      } else {
        this.txMgr.commit(txStatus);
      }
    } finally {
      ctx.setTransactionStatus(null);
      ThreadContext.unsetContext(this.metaData.getName());
      HashMap<String, ThreadContext.Context> contextHash = ThreadContext.getThreadLocalHash();

      if (contextHash != null && contextHash.size() > 0) {
        if (!TransactionSynchronizationManager.isSynchronizationActive()) {
          TransactionSynchronizationManager.initSynchronization();
        }
      } else {
        if (TransactionSynchronizationManager.isSynchronizationActive()) {
          TransactionSynchronizationManager.clear();
          Map map = TransactionSynchronizationManager.getResourceMap();
          for (Object entry : map.keySet()) {
            TransactionSynchronizationManager.unbindResource(entry);
          }
        }
      }
    }
  }
Ejemplo n.º 4
0
  @Override
  public void rollback() {

    if (txLogger.isInfoEnabled()) {
      txLogger.info("rollback");
    }

    ThreadContext.Context ctx = ThreadContext.getContext(this.metaData.getName());

    if (ctx == null) {
      if (txLogger.isWarnEnabled()) {
        txLogger.warn("ignoring rollback - no tx in progress");
        if (txLogger.isDebugEnabled()) {
          logStackTrace();
        }
      }
      return;
    }

    TransactionStatus txStatus = ctx.getTransactionStatus();

    try {

      if (txStatus == null) {
        if (txLogger.isWarnEnabled()) {
          txLogger.warn("ignoring rollback - no tx status");
          if (txLogger.isDebugEnabled()) {
            logStackTrace();
          }
        }
      } else {
        this.txMgr.rollback(txStatus);
      }
    } finally {
      ctx.setTransactionStatus(null);
      ThreadContext.unsetContext(this.metaData.getName());
    }
  }