openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r673476 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java
Date Wed, 02 Jul 2008 19:50:37 GMT
Author: ppoddar
Date: Wed Jul  2 12:50:37 2008
New Revision: 673476

URL: http://svn.apache.org/viewvc?rev=673476&view=rev
Log:
OPENJPA-647: ClassMetaData listens to value updates of dynamic property

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=673476&r1=673475&r2=673476&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Wed Jul  2 12:50:37 2008
@@ -41,6 +41,8 @@
 import org.apache.openjpa.enhance.PCRegistry;
 import org.apache.openjpa.enhance.Reflection;
 import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.lib.conf.Value;
+import org.apache.openjpa.lib.conf.ValueListener;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.meta.SourceTracker;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
@@ -79,7 +81,7 @@
 public class ClassMetaData
     extends Extensions
     implements Comparable, SourceTracker, MetaDataContext, MetaDataModes,
-    Commentable {
+    Commentable, ValueListener {
 
     /**
      * Unkonwn identity type.
@@ -196,6 +198,7 @@
         _repos = repos;
         _owner = null;
         setDescribedType(type);
+        registerForValueUpdate("DataCacheTimeout");
     }
 
     /**
@@ -206,6 +209,7 @@
         _repos = owner.getRepository();
         setEnvClassLoader(owner.getFieldMetaData().getDefiningMetaData().
             getEnvClassLoader());
+        registerForValueUpdate("DataCacheTimeout");
     }
 
     /**
@@ -2351,4 +2355,24 @@
 			return f1.getListingIndex () - f2.getListingIndex ();
 		}
 	}
+    
+    public void registerForValueUpdate(String...values) {
+    	if (values == null)
+    		return;
+    	for (String key : values) {
+    		Value value = getRepository().getConfiguration()
+    			.getValue(key);
+    		if (value != null)
+    			value.setListener(this);
+    	}
+    }
+    
+    public void valueChanged(Value val) {
+    	if (val ==  null)
+    		return;
+    	String key = val.getProperty();
+    	if ("DataCacheTimeout".equals(key)) {
+    		_cacheTimeout = Integer.MIN_VALUE;
+    	}
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java?rev=673476&r1=673475&r2=673476&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java
Wed Jul  2 12:50:37 2008
@@ -18,9 +18,13 @@
  */
 package org.apache.openjpa.conf;
 
+import javax.persistence.EntityManager;
+
 import org.apache.openjpa.lib.conf.Value;
+import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.datacache.common.apps.PObject;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
@@ -31,6 +35,10 @@
  */
 public class TestDynamicConfiguration extends SingleEMFTestCase {
 
+	public void setUp() throws Exception {
+		super.setUp(PObject.class);
+	}
+	
     public void testConfigurationIsEqualByValueAndHashCode() {
 		OpenJPAEntityManagerFactorySPI emf1 = createEMF();
 		assertNotNull(emf1);
@@ -102,4 +110,24 @@
 		
 		assertEquals(oldHash, newHash);
 	}
+	
+	public void testClassMetaDataRecognizesDataCacheTimeoutValueChange() {
+		OpenJPAConfiguration conf = emf.getConfiguration();
+		EntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		PObject pc = new PObject();
+		em.persist(pc);
+		
+		int oldValue = conf.getDataCacheTimeout();
+		
+		ClassMetaData meta = conf.getMetaDataRepositoryInstance().getCachedMetaData(PObject.class);
+		assertNotNull(meta);
+		assertEquals(oldValue, meta.getDataCacheTimeout());
+		
+		int newValue = oldValue + 10;
+		conf.setDataCacheTimeout(newValue);
+		assertEquals(newValue, conf.getDataCacheTimeout());
+		assertEquals(newValue, meta.getDataCacheTimeout());
+		
+	}
 }



Mime
View raw message