Пример #1
0
  public void setRollbackOnly() {
    TransactionID txId = currentTransactionIdThreadLocal.get();
    if (txId == null) {
      throw new TransactionException("no transaction started");
    }

    TransactionContext currentTx = contextMap.get(txId);

    currentTx.setRollbackOnly(true);
  }
Пример #2
0
  public void begin(int transactionTimeout) {
    TransactionID txId = currentTransactionIdThreadLocal.get();
    if (txId != null) {
      throw new TransactionException("transaction already started");
    }

    TransactionContext newTx =
        new TransactionContext(transactionTimeout, transactionIDFactory.createTransactionID());
    contextMap.put(newTx.getTransactionId(), newTx);
    currentTransactionIdThreadLocal.set(newTx.getTransactionId());

    MDC.put(MDC_KEY, newTx.getTransactionId().toString());
    LOG.debug("begun transaction {}", newTx.getTransactionId());
  }
Пример #3
0
  public void rollback() {
    TransactionID txId = currentTransactionIdThreadLocal.get();
    if (txId == null) {
      throw new TransactionException("no transaction started");
    }

    TransactionContext currentTx = contextMap.get(txId);

    try {
      currentTx.rollback();
    } finally {
      contextMap.remove(txId);
      currentTransactionIdThreadLocal.remove();
      MDC.remove(MDC_KEY);
    }
  }
Пример #4
0
  public void commit(boolean ignoreTimeout) {
    TransactionID txId = currentTransactionIdThreadLocal.get();
    if (txId == null) {
      throw new TransactionException("no transaction started");
    }

    TransactionContext currentTx = contextMap.get(txId);

    try {
      currentTx.commit(ignoreTimeout);
    } finally {
      contextMap.remove(txId);
      currentTransactionIdThreadLocal.remove();
      MDC.remove(MDC_KEY);
    }
  }