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:
Patrick Linskey 2007-02-23 18:25:55 +00:00
parent 65bd1f02e3
commit e20afb3134
1 changed files with 36 additions and 42 deletions

View File

@ -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,9 +452,10 @@ 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
// can never be active on multiple concurrent threads.
BrokerImpl broker; BrokerImpl broker;
for (Iterator itr = brokers.iterator(); itr.hasNext();) { for (Iterator itr = brokers.iterator(); itr.hasNext();) {
broker = (BrokerImpl) itr.next(); broker = (BrokerImpl) itr.next();
@ -464,7 +467,6 @@ public abstract class AbstractBrokerFactory
} }
return null; return null;
} }
}
/** /**
* Configures the given broker with the current factory option settings. * Configures the given broker with the current factory option settings.
@ -579,7 +581,6 @@ 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;
@ -592,7 +593,6 @@ public abstract class AbstractBrokerFactory
setFailedObject(itr.next())); setFailedObject(itr.next()));
} }
} }
}
if (!excs.isEmpty()) if (!excs.isEmpty())
throw new InvalidStateException(_loc.get("nested-exceps")). throw new InvalidStateException(_loc.get("nested-exceps")).
@ -626,19 +626,16 @@ 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
// threads using the same trans since one JTA transaction can never
// be active on multiple concurrent threads.
Collection brokers = (Collection) _transactional.get(trans); Collection brokers = (Collection) _transactional.get(trans);
if (brokers == null) { if (brokers == null) {
brokers = new ArrayList(2); brokers = new ArrayList(2);
_transactional.put(trans, brokers); _transactional.put(trans, brokers);
trans.registerSynchronization(new RemoveTransactionSync(trans));
// register a callback to remove the trans from the
// cache when it ends
trans.registerSynchronization
(new RemoveTransactionSync(trans));
} }
brokers.add(broker); brokers.add(broker);
}
return true; return true;
} catch (OpenJPAException ke) { } catch (OpenJPAException 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);
} }
} }
}
} }