本文整理汇总了Java中javax.transaction.Status.STATUS_NO_TRANSACTION属性的典型用法代码示例。如果您正苦于以下问题:Java Status.STATUS_NO_TRANSACTION属性的具体用法?Java Status.STATUS_NO_TRANSACTION怎么用?Java Status.STATUS_NO_TRANSACTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.transaction.Status
的用法示例。
在下文中一共展示了Status.STATUS_NO_TRANSACTION属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doBegin
@Override
protected void doBegin() {
LOG.debug( "begin" );
userTransaction = locateUserTransaction();
try {
if ( userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION ) {
userTransaction.begin();
isInitiator = true;
LOG.debug( "Began a new JTA transaction" );
}
}
catch ( Exception e ) {
throw new TransactionException( "JTA transaction begin failed", e );
}
}
示例2: setTransactionTimeout
/**
* Implementation required for {@link UserTransaction}.
*/
public void setTransactionTimeout(int timeout) throws SystemException
{
if (internalStatus != Status.STATUS_NO_TRANSACTION)
{
throw new RuntimeException("Can only set the timeout before begin");
}
this.timeout = timeout;
}
示例3: setRollbackOnly
public synchronized void setRollbackOnly() throws IllegalStateException, SystemException
{
// just a check
TransactionInfo txnInfo = getTransactionInfo();
int status = getStatus();
// check the status
if (status == Status.STATUS_MARKED_ROLLBACK)
{
// this is acceptable
}
else if (status == Status.STATUS_NO_TRANSACTION)
{
throw new IllegalStateException("The transaction has not been started yet");
}
else if (status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK)
{
throw new IllegalStateException("The transaction has already been rolled back");
}
else if (status == Status.STATUS_COMMITTING || status == Status.STATUS_COMMITTED)
{
throw new IllegalStateException("The transaction has already been committed");
}
else if (status != Status.STATUS_ACTIVE)
{
throw new IllegalStateException("The transaction is not active: " + status);
}
// mark for rollback
txnInfo.getTransactionStatus().setRollbackOnly();
// make sure that we record the fact that we have been marked for rollback
internalStatus = Status.STATUS_MARKED_ROLLBACK;
// done
if (logger.isDebugEnabled())
{
logger.debug("Set transaction status to rollback only: " + this);
}
}
示例4: commit
public void commit() {
status = Status.STATUS_NO_TRANSACTION;
stubCalls.add("commit()");
if (failCommit) {
throw new RollbackException();
}
}
示例5: commit
@Override
public void commit() {
status = Status.STATUS_NO_TRANSACTION;
stubCalls.add("commit()");
if (failCommit) {
throw new RollbackException();
}
}
示例6: isExistingTransaction
@Override
protected boolean isExistingTransaction(Object transaction) {
JtaTransactionObject txObject = (JtaTransactionObject) transaction;
try {
return (txObject.getUserTransaction().getStatus() != Status.STATUS_NO_TRANSACTION);
}
catch (SystemException ex) {
throw new TransactionSystemException("JTA failure on getStatus", ex);
}
}
示例7: doRegisterAfterCompletionWithJtaTransaction
/**
* Register a JTA synchronization on the JTA TransactionManager, for calling
* {@code afterCompletion} on the given Spring TransactionSynchronizations.
* <p>The default implementation registers the synchronizations on the
* JTA 1.1 TransactionSynchronizationRegistry, if available, or on the
* JTA TransactionManager's current Transaction - again, if available.
* If none of the two is available, a warning will be logged.
* <p>Can be overridden in subclasses, for specific JTA implementations.
* @param txObject the current transaction object
* @param synchronizations List of TransactionSynchronization objects
* @throws RollbackException if thrown by JTA methods
* @throws SystemException if thrown by JTA methods
* @see #getTransactionManager()
* @see javax.transaction.Transaction#registerSynchronization
* @see javax.transaction.TransactionSynchronizationRegistry#registerInterposedSynchronization
*/
protected void doRegisterAfterCompletionWithJtaTransaction(
JtaTransactionObject txObject, List<TransactionSynchronization> synchronizations)
throws RollbackException, SystemException {
int jtaStatus = txObject.getUserTransaction().getStatus();
if (jtaStatus == Status.STATUS_NO_TRANSACTION) {
throw new RollbackException("JTA transaction already completed - probably rolled back");
}
if (jtaStatus == Status.STATUS_ROLLEDBACK) {
throw new RollbackException("JTA transaction already rolled back (probably due to a timeout)");
}
if (this.transactionSynchronizationRegistry != null) {
// JTA 1.1 TransactionSynchronizationRegistry available - use it.
this.transactionSynchronizationRegistry.registerInterposedSynchronization(
new JtaAfterCompletionSynchronization(synchronizations));
}
else if (getTransactionManager() != null) {
// At least the JTA TransactionManager available - use that one.
Transaction transaction = getTransactionManager().getTransaction();
if (transaction == null) {
throw new IllegalStateException("No JTA Transaction available");
}
transaction.registerSynchronization(new JtaAfterCompletionSynchronization(synchronizations));
}
else {
// No JTA TransactionManager available - log a warning.
logger.warn("Participating in existing JTA transaction, but no JTA TransactionManager available: " +
"cannot register Spring after-completion callbacks with outer JTA transaction - " +
"processing Spring after-completion callbacks with outcome status 'unknown'");
invokeAfterCompletion(synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
}
}
示例8: getStatus
/**
* Get the status of the global transaction associated with this thread
*
* @see javax.transaction.TransactionManager#getStatus()
*/
public int getStatus() throws SystemException {
if (!isActive) {
throw new SystemException(
LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGER_INVALID.toLocalizedString());
}
GlobalTransaction gtx = getGlobalTransaction();
if (gtx == null) {
return Status.STATUS_NO_TRANSACTION;
}
return gtx.getStatus();
}
示例9: transactionManager
private TransactionManager transactionManager() {
return new TransactionManager() {
private int status = Status.STATUS_NO_TRANSACTION;
@Override
public void begin() throws NotSupportedException, SystemException {
status = Status.STATUS_ACTIVE;
}
@Override
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
status = Status.STATUS_NO_TRANSACTION;
}
@Override
public void rollback() throws IllegalStateException, SecurityException, SystemException {
status = Status.STATUS_NO_TRANSACTION;
}
@Override
public void setRollbackOnly() throws IllegalStateException, SystemException {
// Nothing to do
}
@Override
public int getStatus() throws SystemException {
return status;
}
@Override
public Transaction getTransaction() throws SystemException {
return transaction();
}
@Override
public void setTransactionTimeout(int seconds) throws SystemException {
throw new AssertionError("setTransactionTimeout");
}
@Override
public Transaction suspend() throws SystemException {
return transaction();
}
@Override
public void resume(Transaction tobj) throws InvalidTransactionException, IllegalStateException, SystemException {
// nothing to do
}
};
}
示例10: getTransactionInfo
/**
* Gets the current transaction info, or null if none exists.
* <p>
* A check is done to ensure that the transaction info on the stack is exactly
* the same instance used when this transaction was started.
* The internal status is also checked against the transaction info.
* These checks ensure that the transaction demarcation is done correctly and that
* thread safety is adhered to.
*
* @return Returns the current transaction
*/
private TransactionInfo getTransactionInfo()
{
// a few quick self-checks
if (threadId < 0 && internalStatus != Status.STATUS_NO_TRANSACTION)
{
throw new RuntimeException("Transaction has been started but there is no thread ID");
}
else if (threadId >= 0 && internalStatus == Status.STATUS_NO_TRANSACTION)
{
throw new RuntimeException("Transaction has not been started but a thread ID has been recorded");
}
TransactionInfo txnInfo = null;
try
{
txnInfo = TransactionAspectSupport.currentTransactionInfo();
// we are in a transaction
}
catch (NoTransactionException e)
{
// No transaction. It is possible that the transaction threw an exception during commit.
}
// perform checks for active transactions
if (internalStatus == Status.STATUS_ACTIVE)
{
if (Thread.currentThread().getId() != threadId)
{
// the internally stored transaction info (retrieved in begin()) should match the info
// on the thread
throw new RuntimeException("UserTransaction may not be accessed by multiple threads");
}
else if (txnInfo == null)
{
// internally we recorded a transaction starting, but there is nothing on the thread
throw new RuntimeException("Transaction boundaries have been made to overlap in the stack");
}
else if (txnInfo != internalTxnInfo)
{
// the transaction info on the stack isn't the one we started with
throw new RuntimeException("UserTransaction begin/commit mismatch");
}
}
return txnInfo;
}
示例11: commit
/**
* @throws IllegalStateException if a transaction was not started
*/
public synchronized void commit()
throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
SecurityException, IllegalStateException, SystemException
{
// perform checks
TransactionInfo txnInfo = getTransactionInfo();
int status = getStatus();
// check the status
if (status == Status.STATUS_NO_TRANSACTION)
{
throw new IllegalStateException("The transaction has not yet begun");
}
else if (status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK)
{
throw new RollbackException("The transaction has already been rolled back");
}
else if (status == Status.STATUS_MARKED_ROLLBACK)
{
throw new RollbackException("The transaction has already been marked for rollback");
}
else if (status == Status.STATUS_COMMITTING || status == Status.STATUS_COMMITTED)
{
throw new IllegalStateException("The transaction has already been committed");
}
else if (status != Status.STATUS_ACTIVE || txnInfo == null)
{
throw new IllegalStateException("No user transaction is active");
}
if (!finalized)
{
try
{
// the status seems correct - we can try a commit
commitTransactionAfterReturning(txnInfo);
}
catch (Throwable e)
{
if (logger.isDebugEnabled())
{
logger.debug("Transaction didn't commit", e);
}
// commit failed
internalStatus = Status.STATUS_ROLLEDBACK;
RollbackException re = new RollbackException("Transaction didn't commit: " + e.getMessage());
// Stick the originating reason for failure into the exception.
re.initCause(e);
throw re;
}
finally
{
// make sure that we clean up the stack
cleanupTransactionInfo(txnInfo);
finalized = true;
// clean up leaked transaction logging
isBeginMatched = true;
beginCallStack = null;
}
}
// regardless of whether the transaction was finally committed or not, the status
// as far as UserTransaction is concerned should be 'committed'
// keep track that this UserTransaction was explicitly committed
internalStatus = Status.STATUS_COMMITTED;
// done
if (logger.isDebugEnabled())
{
logger.debug("Committed user transaction: " + this);
}
}
示例12: rollback
public void rollback() throws RollbackException {
status = Status.STATUS_NO_TRANSACTION;
stubCalls.add("rollback()");
}
示例13: getStatus
public int getStatus() {
return Status.STATUS_NO_TRANSACTION;
}
示例14: rollback
@Override
public void rollback() throws RollbackException {
status = Status.STATUS_NO_TRANSACTION;
stubCalls.add("rollback()");
}
示例15: getStatus
@Override
public int getStatus() throws SystemException {
return getTransaction() == null ? Status.STATUS_NO_TRANSACTION : getTransaction().getStatus();
}