mkalen 2005/03/11 10:07:21
Modified: src/java/org/apache/ojb/broker/core/proxy
AbstractCollectionProxy.java
src/java/org/apache/ojb/broker/metadata MetadataManager.java
Log:
Merge with OJB_1_0_RELEASE branch: Optimize fix for collection-proxy
instantiation in per-thread metadata changes environment: make
currentProfileKey thread local in MetadataManager to allow loading of profile
only if not set in CollectionProxy.
Revision Changes Path
1.4 +10 -7
db-ojb/src/java/org/apache/ojb/broker/core/proxy/AbstractCollectionProxy.java
Index: AbstractCollectionProxy.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/AbstractCollectionProxy.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractCollectionProxy.java 11 Mar 2005 18:01:05 -0000 1.3
+++ AbstractCollectionProxy.java 11 Mar 2005 18:07:21 -0000 1.4
@@ -116,13 +116,16 @@
setQuery(query);
}
- protected void loadProfile()
+ protected void loadProfileIfNeeded()
{
final Object key = getProfileKey();
if (key != null)
{
final MetadataManager mm =
persistenceConf.getOjb().getMetadataManager();
- mm.loadProfile(key);
+ if (!key.equals(mm.getCurrentProfileKey()))
+ {
+ mm.loadProfile(key);
+ }
}
}
@@ -165,7 +168,7 @@
{
if (_perThreadDescriptorsEnabled)
{
- loadProfile();
+ loadProfileIfNeeded();
}
return broker.getCount(getQuery());
}
@@ -210,7 +213,7 @@
{
if (_perThreadDescriptorsEnabled)
{
- loadProfile();
+ loadProfileIfNeeded();
}
result = (Collection)
broker.getCollectionByQuery(getCollectionClass(), getQuery());
}
@@ -241,7 +244,7 @@
if (_perThreadDescriptorsEnabled)
{
- loadProfile();
+ loadProfileIfNeeded();
}
for (int idx = listeners.size() - 1; idx >= 0; idx--)
{
@@ -262,7 +265,7 @@
if (_perThreadDescriptorsEnabled)
{
- loadProfile();
+ loadProfileIfNeeded();
}
for (int idx = listeners.size() - 1; idx >= 0; idx--)
{
1.26 +7 -7
db-ojb/src/java/org/apache/ojb/broker/metadata/MetadataManager.java
Index: MetadataManager.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/MetadataManager.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- MetadataManager.java 11 Mar 2005 18:01:05 -0000 1.25
+++ MetadataManager.java 11 Mar 2005 18:07:21 -0000 1.26
@@ -139,6 +139,7 @@
private Logger log = LoggerFactory.getLogger(MetadataManager.class);
private static ThreadLocal threadedRepository = new ThreadLocal();
+ private static ThreadLocal currentProfileKey = new ThreadLocal();
/** The path to the repository file */
private String repositoryPath = DEFAULT_REPOSITORY_PATH;
@@ -149,7 +150,6 @@
private boolean enablePerThreadChanges;
private PBKey defaultPBKey;
private Map persistenceConfigurationDescriptorMap;
- private Object currentProfileKey;
public MetadataManager(PersistentFieldFactory fieldFactory)
{
@@ -277,7 +277,7 @@
{
throw new MetadataException("Call to this method is undefined,
since per-thread mode is disabled.");
}
- return currentProfileKey;
+ return currentProfileKey.get();
}
/**
@@ -286,7 +286,7 @@
public void initialize()
{
metadataProfiles = new Hashtable();
- currentProfileKey = null;
+ currentProfileKey.set(null);
try
{
globalRepository =
persistor.readDescriptorRepository(repositoryPath);
@@ -646,7 +646,7 @@
throw new MetadataException("Can not find profile for key '" +
key + "'");
}
setDescriptor(rep);
- currentProfileKey = key;
+ currentProfileKey.set(key);
}
/**
@@ -663,7 +663,7 @@
public void clearProfiles()
{
metadataProfiles.clear();
- currentProfileKey = null;
+ currentProfileKey.set(null);
}
/**
@@ -675,7 +675,7 @@
public void removeAllProfiles()
{
metadataProfiles.clear();
- currentProfileKey = null;
+ currentProfileKey.set(null);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]