mirror of https://github.com/apache/openjpa.git
OPENJPA-295
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@562530 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
60d4f7cd70
commit
4150e7f566
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.openjpa.ee;
|
||||
|
||||
import javax.transaction.SystemException;
|
||||
|
||||
/*
|
||||
* AbstractManagedRuntime.java
|
||||
*
|
||||
* Created on August 2, 2007, 2:38 PM
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractManagedRuntime implements ManagedRuntime {
|
||||
|
||||
/**
|
||||
* Returns a transaction key that can be used to associate transactions
|
||||
* and Brokers.
|
||||
* The default implementation returns the Transaction associated
|
||||
* with the current thread's transaction.
|
||||
* @return the transaction key
|
||||
*/
|
||||
public Object getTransactionKey() throws Exception, SystemException {
|
||||
return getTransactionManager().getTransaction();
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,8 @@ package org.apache.openjpa.ee;
|
|||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
import org.apache.openjpa.lib.conf.Configurable;
|
||||
|
@ -47,7 +49,7 @@ import org.apache.openjpa.util.InvalidStateException;
|
|||
*
|
||||
* @author Marc Prud'hommeaux
|
||||
*/
|
||||
public class AutomaticManagedRuntime
|
||||
public class AutomaticManagedRuntime extends AbstractManagedRuntime
|
||||
implements ManagedRuntime, Configurable {
|
||||
|
||||
private static final String [] JNDI_LOCS = new String []{
|
||||
|
@ -244,4 +246,14 @@ public class AutomaticManagedRuntime
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getTransactionKey() throws Exception, SystemException {
|
||||
if(_runtime == null)
|
||||
getTransactionManager();
|
||||
|
||||
if(_runtime != null )
|
||||
return _runtime.getTransactionKey();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.apache.openjpa.lib.conf.Configuration;
|
|||
*
|
||||
* @author Marc Prud'hommeaux
|
||||
*/
|
||||
public class InvocationManagedRuntime
|
||||
public class InvocationManagedRuntime extends AbstractManagedRuntime
|
||||
implements ManagedRuntime, Configurable {
|
||||
|
||||
private String _methodName = null;
|
||||
|
|
|
@ -28,7 +28,7 @@ import javax.transaction.TransactionManager;
|
|||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class JNDIManagedRuntime
|
||||
public class JNDIManagedRuntime extends AbstractManagedRuntime
|
||||
implements ManagedRuntime {
|
||||
|
||||
private String _tmLoc = "java:/TransactionManager";
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.apache.openjpa.ee;
|
||||
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
/**
|
||||
|
@ -56,4 +57,13 @@ public interface ManagedRuntime {
|
|||
*/
|
||||
public Throwable getRollbackCause()
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Returns a transaction key that can be used to associate transactions
|
||||
* and Brokers.
|
||||
* @return the transaction key
|
||||
*/
|
||||
public Object getTransactionKey()
|
||||
throws Exception, SystemException;
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public class RegistryManagedRuntime
|
|||
|
||||
private String _registryName =
|
||||
"java:comp/TransactionSynchronizationRegistry";
|
||||
private TransactionManager _tm = null;
|
||||
private TransactionManagerRegistryFacade _tm = null;
|
||||
|
||||
/**
|
||||
* Return the cached TransactionManager instance.
|
||||
|
@ -84,6 +84,10 @@ public class RegistryManagedRuntime
|
|||
return _registryName;
|
||||
}
|
||||
|
||||
public Object getTransactionKey() throws Exception, SystemException {
|
||||
return _tm.getTransactionKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link TransactionManager} and {@link Transaction} facade
|
||||
* that delegates the appropriate methods to the internally-held
|
||||
|
@ -126,6 +130,10 @@ public class RegistryManagedRuntime
|
|||
return _registry.getTransactionStatus();
|
||||
}
|
||||
|
||||
public Object getTransactionKey() {
|
||||
return _registry.getTransactionKey();
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Unsupported methods follow
|
||||
//////////////////////////////
|
||||
|
|
|
@ -26,7 +26,7 @@ import javax.transaction.TransactionManager;
|
|||
*
|
||||
* @author Marc Prud'hommeaux
|
||||
*/
|
||||
public class SunOneManagedRuntime
|
||||
public class SunOneManagedRuntime extends AbstractManagedRuntime
|
||||
implements ManagedRuntime {
|
||||
|
||||
private Method _switchMeth;
|
||||
|
|
|
@ -59,9 +59,10 @@ import serp.bytecode.Project;
|
|||
* WASManagedRuntime provides the wrapper classes needed to interact with the
|
||||
* WAS proprietary interface and the OpenJPA kernel.
|
||||
*
|
||||
* @author Michael Dick, Kevin Sutter
|
||||
* @author Kevin Sutter
|
||||
*/
|
||||
public class WASManagedRuntime implements ManagedRuntime, Configurable {
|
||||
public class WASManagedRuntime extends AbstractManagedRuntime
|
||||
implements ManagedRuntime, Configurable {
|
||||
|
||||
private static final Localizer _loc =
|
||||
Localizer.forPackage(WASManagedRuntime.class);
|
||||
|
|
|
@ -28,7 +28,7 @@ import javax.transaction.TransactionManager;
|
|||
*
|
||||
* @author Arunabh Hazarika, Patrick Linskey
|
||||
*/
|
||||
public class WLSManagedRuntime
|
||||
public class WLSManagedRuntime extends AbstractManagedRuntime
|
||||
implements ManagedRuntime {
|
||||
|
||||
private final Method _txHelperMeth;
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.apache.commons.lang.StringUtils;
|
|||
import org.apache.openjpa.conf.OpenJPAConfiguration;
|
||||
import org.apache.openjpa.conf.OpenJPAVersion;
|
||||
import org.apache.openjpa.datacache.DataCacheStoreManager;
|
||||
import org.apache.openjpa.ee.ManagedRuntime;
|
||||
import org.apache.openjpa.enhance.PCRegistry;
|
||||
import org.apache.openjpa.enhance.PersistenceCapable;
|
||||
import org.apache.openjpa.event.RemoteCommitEventManager;
|
||||
|
@ -526,9 +527,12 @@ public abstract class AbstractBrokerFactory
|
|||
*/
|
||||
protected BrokerImpl findTransactionalBroker(String user, String pass) {
|
||||
Transaction trans;
|
||||
ManagedRuntime mr = _conf.getManagedRuntimeInstance();
|
||||
Object txKey;
|
||||
try {
|
||||
trans = _conf.getManagedRuntimeInstance().getTransactionManager().
|
||||
trans = mr.getTransactionManager().
|
||||
getTransaction();
|
||||
txKey = mr.getTransactionKey();
|
||||
|
||||
if (trans == null
|
||||
|| trans.getStatus() == Status.STATUS_NO_TRANSACTION
|
||||
|
@ -540,7 +544,7 @@ public abstract class AbstractBrokerFactory
|
|||
throw new GeneralException(e);
|
||||
}
|
||||
|
||||
Collection brokers = (Collection) _transactional.get(trans);
|
||||
Collection brokers = (Collection) _transactional.get(txKey);
|
||||
if (brokers != null) {
|
||||
// we don't need to synchronize on brokers since one JTA transaction
|
||||
// can never be active on multiple concurrent threads.
|
||||
|
@ -703,8 +707,8 @@ public abstract class AbstractBrokerFactory
|
|||
boolean syncWithManagedTransaction(BrokerImpl broker, boolean begin) {
|
||||
Transaction trans;
|
||||
try {
|
||||
TransactionManager tm = broker.getManagedRuntime().
|
||||
getTransactionManager();
|
||||
ManagedRuntime mr = broker.getManagedRuntime();
|
||||
TransactionManager tm = mr.getTransactionManager();
|
||||
trans = tm.getTransaction();
|
||||
if (trans != null
|
||||
&& (trans.getStatus() == Status.STATUS_NO_TRANSACTION
|
||||
|
@ -723,11 +727,13 @@ public abstract class AbstractBrokerFactory
|
|||
// we don't need to synchronize on brokers or guard against multiple
|
||||
// threads using the same trans since one JTA transaction can never
|
||||
// be active on multiple concurrent threads.
|
||||
Collection brokers = (Collection) _transactional.get(trans);
|
||||
Object txKey = mr.getTransactionKey();
|
||||
Collection brokers = (Collection) _transactional.get(txKey);
|
||||
|
||||
if (brokers == null) {
|
||||
brokers = new ArrayList(2);
|
||||
_transactional.put(trans, brokers);
|
||||
trans.registerSynchronization(new RemoveTransactionSync(trans));
|
||||
_transactional.put(txKey, brokers);
|
||||
trans.registerSynchronization(new RemoveTransactionSync(txKey));
|
||||
}
|
||||
brokers.add(broker);
|
||||
|
||||
|
@ -754,9 +760,9 @@ public abstract class AbstractBrokerFactory
|
|||
private class RemoveTransactionSync
|
||||
implements Synchronization {
|
||||
|
||||
private final Transaction _trans;
|
||||
private final Object _trans;
|
||||
|
||||
public RemoveTransactionSync(Transaction trans) {
|
||||
public RemoveTransactionSync(Object trans) {
|
||||
_trans = trans;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import javax.transaction.Transaction;
|
|||
import javax.transaction.TransactionManager;
|
||||
import javax.transaction.xa.XAResource;
|
||||
|
||||
import org.apache.openjpa.ee.AbstractManagedRuntime;
|
||||
import org.apache.openjpa.ee.ManagedRuntime;
|
||||
import org.apache.openjpa.lib.util.Localizer;
|
||||
import org.apache.openjpa.util.InternalException;
|
||||
|
@ -40,7 +41,7 @@ import org.apache.openjpa.util.UserException;
|
|||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
class LocalManagedRuntime
|
||||
class LocalManagedRuntime extends AbstractManagedRuntime
|
||||
implements ManagedRuntime, TransactionManager, Transaction {
|
||||
|
||||
private static final Localizer _loc = Localizer.forPackage
|
||||
|
|
Loading…
Reference in New Issue