Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* ====================================================================
* Project: openMDX, http://www.openmdx.org/
* Description: Lightweight Transaction
* Owner: OMEX AG, Switzerland, http://www.omex.ch
* ====================================================================
*
* This software is published under the BSD license as listed below.
*
* Copyright (c) 2005-2011, OMEX AG, Switzerland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the openMDX team nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* ------------------
*
* This product includes software developed by other organizations as
* listed in the NOTICE file.
*/
package org.openmdx.kernel.lightweight.transaction;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import java.util.logging.Level;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import org.openmdx.kernel.exception.BasicException;
import org.openmdx.kernel.exception.Throwables;
import org.openmdx.kernel.log.SysLog;
/**
* JTA Transaction implementation.
*/
final class LightweightTransaction implements Transaction {
// -------------------------------------------------------------- Constants
/**
* The string representation of the status values
*/
private static final String[] STATI = {
//
// A transaction is associated with the target object and it is in the
// active state. An implementation returns this status after a
// transaction has been started and prior to a Coordinator issuing
// any prepares, unless the transaction has been marked for rollback.
//
"STATUS_ACTIVE",
//
// A transaction is associated with the target object and it has been
// marked for rollback, perhaps as a result of a setRollbackOnly operation.
//
"STATUS_MARKED_ROLLBACK",
//
// A transaction is associated with the target object and it has been
// prepared. That is, all subordinates have agreed to commit. The
// target object may be waiting for instructions from a superior as to how
// to proceed.
//
"STATUS_PREPARED",
//
// A transaction is associated with the target object and it has been
// committed. It is likely that heuristics exist; otherwise, the
// transaction would have been destroyed and NoTransaction returned.
//
"STATUS_COMMITTED",
//
// A transaction is associated with the target object and the outcome
// has been determined to be rollback. It is likely that heuristics exist;
// otherwise, the transaction would have been destroyed and NoTransaction
// returned.
//
"STATUS_ROLLEDBACK",
//
// A transaction is associated with the target object but its
// current status cannot be determined. This is a transient condition
// and a subsequent invocation will ultimately return a different status.
//
"STATUS_UNKNOWN",
//
// No transaction is currently associated with the target object. This
// will occur after a transaction has completed.
//
"STATUS_NO_TRANSACTION",
//
// A transaction is associated with the target object and it is in the
// process of preparing. An implementation returns this status if it
// has started preparing, but has not yet completed the process. The
// likely reason for this is that the implementation is probably
// waiting for responses to prepare from one or more
// Resources.
//
"STATUS_PREPARING",
//
// A transaction is associated with the target object and it is in the
// process of committing. An implementation returns this status if it
// has decided to commit but has not yet completed the committing process.
// This occurs because the implementation is probably waiting for
// responses from one or more Resources.
//
"STATUS_COMMITTING",
//
// A transaction is associated with the target object and it is in the
// process of rolling back. An implementation returns this status if
// it has decided to rollback but has not yet completed the process.
// The implementation is probably waiting for responses from one or more
// Resources.
//
"STATUS_ROLLING_BACK"
};
/**
* The default transaction timeout in seconds
*/
public static final int DEFAULT_TRANSACTION_TIMEOUT = 60;
// ------------------------------------------------------------ Constructor
/**
* Constructor.
*/
LightweightTransaction(TransactionIdFactory xidFactory) {
this.xidFactory = xidFactory;
this.xid = xidFactory.createTransactionId();
}
// ----------------------------------------------------- Instance Variables
/**
* Transaction Id factory
*/
private final TransactionIdFactory xidFactory;
/**
* Global transaction id.
*/
final Xid xid;
/**
* Branches.
* Keyed : branch xid -> resource manager.
*/
private final Map branches = new HashMap();
/**
* Active branches.
* Keyed : resource manager -> branches xid.
*/
private final Map activeBranches = new HashMap();
/**
* Enlisted resources.
*/
private final List enlistedResources = new ArrayList();
/**
* Suspended resources.
* Keyed : resource manager -> branches xid.
*/
private Map suspendedResources = new HashMap();
/**
* Transaction status.
*/
int status = Status.STATUS_ACTIVE;
/**
* Synchronization objects.
*/
private final List synchronizationObjects = new ArrayList();
/**
* Branch counter.
*/
private int branchCounter = 1;
/**
* Map of resources being managed for the transaction
*/
final Map