Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

NUCCORE-1214 Cache populated ClassMetadata #6

Closed
wants to merge 1 commit into from

2 participants

@kaarelk

NUCCORE-1214 Cache populated ClassMetadata

@andyjefferson

I applied an adaption of this patch to GitHub master, just by removing the synchronized keyword on the method and putting it in a block lower down those 2 methods so we restrict the scope of where syncing is used. Also renamed the map field. Suggest you try it and if you have any updates to that, patch against that baseline. Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 23, 2014
  1. NUCCORE-1214 Cache populated ClassMetadata

    kaarelk authored
This page is out of date. Refresh to see the latest.
Showing with 54 additions and 4 deletions.
  1. +54 −4 src/main/java/org/datanucleus/metadata/MetaDataManagerImpl.java
View
58 src/main/java/org/datanucleus/metadata/MetaDataManagerImpl.java
@@ -187,6 +187,9 @@
protected Map<String, DiscriminatorLookup> discriminatorLookupByRootClassName = new ConcurrentHashMap<String, MetaDataManagerImpl.DiscriminatorLookup>();
+ /** Map of populated/initialized ClassMetaData, keyed by the class name. */
+ protected Map<String, AbstractClassMetaData> populatedClassMetaDataByClass = new ConcurrentHashMap<String, AbstractClassMetaData>();
+
private class DiscriminatorLookup
{
Map<String, String> discrimValueByClass = new HashMap<String, String>();
@@ -255,7 +258,10 @@ public void close()
{
classMetaDataByClass.clear();
classMetaDataByClass = null;
-
+
+ populatedClassMetaDataByClass.clear();
+ populatedClassMetaDataByClass = null;
+
fileMetaDataByURLString.clear();
fileMetaDataByURLString = null;
@@ -1199,6 +1205,8 @@ public void unloadMetaDataForClass(String className)
{
updateLock.lock();
+ populatedClassMetaDataByClass.remove(className);
+
// Remove any reference to the AbstractClassMetaData
AbstractClassMetaData cmd = classMetaDataByClass.remove(className);
Iterator<Map.Entry<String, AbstractClassMetaData>> iter = classMetaDataByDiscriminatorName.entrySet().iterator();
@@ -1501,14 +1509,35 @@ protected boolean isClassWithoutPersistenceInfo(String className)
/* (non-Javadoc)
* @see org.datanucleus.metadata.MetaDataManager#getMetaDataForClass(java.lang.String, org.datanucleus.ClassLoaderResolver)
*/
- @Override
- public synchronized AbstractClassMetaData getMetaDataForClass(String className, ClassLoaderResolver clr)
+ public AbstractClassMetaData getMetaDataForClass(String className, ClassLoaderResolver clr)
{
if (className == null)
{
return null;
}
+ AbstractClassMetaData d = populatedClassMetaDataByClass.get(className);
+ if (d != null)
+ {
+ return d;
+ }
+
+ d = getMetaDataForClassImpl(className, clr);
+ if (d != null)
+ {
+ populatedClassMetaDataByClass.put(className, d);
+ }
+ return d;
+ }
+
+ private synchronized AbstractClassMetaData getMetaDataForClassImpl(String className, ClassLoaderResolver clr)
+ {
+
+ if (className == null)
+ {
+ return null;
+ }
+
// Check if this class has no MetaData/annotations before instantiating its class
if (isClassWithoutPersistenceInfo(className))
{
@@ -1563,7 +1592,28 @@ public synchronized AbstractClassMetaData getMetaDataForClass(String className,
* @see org.datanucleus.metadata.MetaDataManager#getMetaDataForClass(java.lang.Class, org.datanucleus.ClassLoaderResolver)
*/
@Override
- public synchronized AbstractClassMetaData getMetaDataForClass(Class c, ClassLoaderResolver clr)
+ public AbstractClassMetaData getMetaDataForClass(Class c, ClassLoaderResolver clr)
+ {
+ if (c == null)
+ {
+ return null;
+ }
+
+ AbstractClassMetaData d = populatedClassMetaDataByClass.get(c.getName());
+ if (d != null)
+ {
+ return d;
+ }
+
+ d = getMetaDataForClassImpl(c, clr);
+ if (d != null)
+ {
+ populatedClassMetaDataByClass.put(c.getName(), d);
+ }
+ return d;
+ }
+
+ public synchronized AbstractClassMetaData getMetaDataForClassImpl(Class c, ClassLoaderResolver clr)
{
if (c == null)
{
Something went wrong with that request. Please try again.