mirror of https://github.com/apache/openjpa.git
OPENJPA-161
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@511043 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
65bd1f02e3
commit
e20afb3134
|
@ -37,6 +37,7 @@ import org.apache.openjpa.event.RemoteCommitEventManager;
|
||||||
import org.apache.openjpa.lib.log.Log;
|
import org.apache.openjpa.lib.log.Log;
|
||||||
import org.apache.openjpa.lib.util.Localizer;
|
import org.apache.openjpa.lib.util.Localizer;
|
||||||
import org.apache.openjpa.lib.util.ReferenceHashSet;
|
import org.apache.openjpa.lib.util.ReferenceHashSet;
|
||||||
|
import org.apache.openjpa.lib.util.concurrent.ConcurrentHashMap;
|
||||||
import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet;
|
import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet;
|
||||||
import org.apache.openjpa.lib.util.concurrent.ReentrantLock;
|
import org.apache.openjpa.lib.util.concurrent.ReentrantLock;
|
||||||
import org.apache.openjpa.meta.MetaDataRepository;
|
import org.apache.openjpa.meta.MetaDataRepository;
|
||||||
|
@ -71,7 +72,8 @@ public abstract class AbstractBrokerFactory
|
||||||
private final ReentrantLock _lock = new ReentrantLock();
|
private final ReentrantLock _lock = new ReentrantLock();
|
||||||
|
|
||||||
// maps global transactions to associated brokers
|
// maps global transactions to associated brokers
|
||||||
private transient Map _transactional = new HashMap();
|
private transient ConcurrentHashMap _transactional
|
||||||
|
= new ConcurrentHashMap();
|
||||||
|
|
||||||
// weak-ref tracking of open brokers
|
// weak-ref tracking of open brokers
|
||||||
private transient Collection _brokers = new ConcurrentReferenceHashSet
|
private transient Collection _brokers = new ConcurrentReferenceHashSet
|
||||||
|
@ -369,7 +371,7 @@ public abstract class AbstractBrokerFactory
|
||||||
return factory;
|
return factory;
|
||||||
|
|
||||||
// reset these transient fields to empty values
|
// reset these transient fields to empty values
|
||||||
_transactional = new HashMap();
|
_transactional = new ConcurrentHashMap();
|
||||||
_brokers = new ConcurrentReferenceHashSet(
|
_brokers = new ConcurrentReferenceHashSet(
|
||||||
ConcurrentReferenceHashSet.WEAK);
|
ConcurrentReferenceHashSet.WEAK);
|
||||||
|
|
||||||
|
@ -450,20 +452,20 @@ public abstract class AbstractBrokerFactory
|
||||||
throw new GeneralException(e);
|
throw new GeneralException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (_transactional) {
|
Collection brokers = (Collection) _transactional.get(trans);
|
||||||
Collection brokers = (Collection) _transactional.get(trans);
|
if (brokers != null) {
|
||||||
if (brokers != null) {
|
// we don't need to synchronize on brokers since one JTA transaction
|
||||||
BrokerImpl broker;
|
// can never be active on multiple concurrent threads.
|
||||||
for (Iterator itr = brokers.iterator(); itr.hasNext();) {
|
BrokerImpl broker;
|
||||||
broker = (BrokerImpl) itr.next();
|
for (Iterator itr = brokers.iterator(); itr.hasNext();) {
|
||||||
if (StringUtils.equals(broker.getConnectionUserName(),
|
broker = (BrokerImpl) itr.next();
|
||||||
user) && StringUtils.equals
|
if (StringUtils.equals(broker.getConnectionUserName(),
|
||||||
(broker.getConnectionPassword(), pass))
|
user) && StringUtils.equals
|
||||||
return broker;
|
(broker.getConnectionPassword(), pass))
|
||||||
}
|
return broker;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -579,18 +581,16 @@ public abstract class AbstractBrokerFactory
|
||||||
*/
|
*/
|
||||||
private void assertNoActiveTransaction() {
|
private void assertNoActiveTransaction() {
|
||||||
Collection excs = null;
|
Collection excs = null;
|
||||||
synchronized (_transactional) {
|
if (_transactional.isEmpty())
|
||||||
if (_transactional.isEmpty())
|
return;
|
||||||
return;
|
|
||||||
|
|
||||||
excs = new ArrayList(_transactional.size());
|
excs = new ArrayList(_transactional.size());
|
||||||
for (Iterator trans = _transactional.values().iterator();
|
for (Iterator trans = _transactional.values().iterator();
|
||||||
trans.hasNext();) {
|
trans.hasNext();) {
|
||||||
Collection brokers = (Collection) trans.next();
|
Collection brokers = (Collection) trans.next();
|
||||||
for (Iterator itr = brokers.iterator(); itr.hasNext();) {
|
for (Iterator itr = brokers.iterator(); itr.hasNext();) {
|
||||||
excs.add(new InvalidStateException(_loc.get("active")).
|
excs.add(new InvalidStateException(_loc.get("active")).
|
||||||
setFailedObject(itr.next()));
|
setFailedObject(itr.next()));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,20 +626,17 @@ public abstract class AbstractBrokerFactory
|
||||||
// synch broker and trans
|
// synch broker and trans
|
||||||
trans.registerSynchronization(broker);
|
trans.registerSynchronization(broker);
|
||||||
|
|
||||||
synchronized (_transactional) {
|
// we don't need to synchronize on brokers or guard against multiple
|
||||||
Collection brokers = (Collection) _transactional.get(trans);
|
// threads using the same trans since one JTA transaction can never
|
||||||
if (brokers == null) {
|
// be active on multiple concurrent threads.
|
||||||
brokers = new ArrayList(2);
|
Collection brokers = (Collection) _transactional.get(trans);
|
||||||
_transactional.put(trans, brokers);
|
if (brokers == null) {
|
||||||
|
brokers = new ArrayList(2);
|
||||||
// register a callback to remove the trans from the
|
_transactional.put(trans, brokers);
|
||||||
// cache when it ends
|
trans.registerSynchronization(new RemoveTransactionSync(trans));
|
||||||
trans.registerSynchronization
|
|
||||||
(new RemoveTransactionSync(trans));
|
|
||||||
}
|
|
||||||
brokers.add(broker);
|
|
||||||
}
|
}
|
||||||
|
brokers.add(broker);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (OpenJPAException ke) {
|
} catch (OpenJPAException ke) {
|
||||||
throw ke;
|
throw ke;
|
||||||
|
@ -665,10 +662,7 @@ public abstract class AbstractBrokerFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterCompletion(int status) {
|
public void afterCompletion(int status) {
|
||||||
synchronized (_transactional)
|
_transactional.remove (_trans);
|
||||||
{
|
|
||||||
_transactional.remove (_trans);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue