openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpala...@apache.org
Subject svn commit: r939817 - in /openjpa/branches/1.1.x: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/ openjpa-persistence-jdbc/src/...
Date Fri, 30 Apr 2010 21:07:23 GMT
Author: rpalache
Date: Fri Apr 30 21:07:22 2010
New Revision: 939817

URL: http://svn.apache.org/viewvc?rev=939817&view=rev
Log:
OpenJPA-647 Applying Pinaki Poddar's trunk patch to 1.1.x branch. PObject.java is added as
part of 1.1.x branch as it is used by TestDynamicConfiguration and is new to 1.1.x branch

Added:
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/PObject.java
Modified:
    openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    openjpa/branches/1.1.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
    openjpa/branches/1.1.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java

Modified: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java?rev=939817&r1=939816&r2=939817&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
(original)
+++ openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
Fri Apr 30 21:07:22 2010
@@ -41,6 +41,8 @@ import org.apache.openjpa.datacache.Data
 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 @@ import serp.util.Strings;
 public class ClassMetaData
     extends Extensions
     implements Comparable, SourceTracker, MetaDataContext, MetaDataModes,
-    Commentable {
+    Commentable, ValueListener {
 
     /**
      * Unkonwn identity type.
@@ -198,6 +200,7 @@ public class ClassMetaData
         _repos = repos;
         _owner = null;
         setDescribedType(type);
+        registerForValueUpdate("DataCacheTimeout");
     }
 
     /**
@@ -208,6 +211,7 @@ public class ClassMetaData
         _repos = owner.getRepository();
         setEnvClassLoader(owner.getFieldMetaData().getDefiningMetaData().
             getEnvClassLoader());
+        registerForValueUpdate("DataCacheTimeout");
     }
 
     /**
@@ -2357,6 +2361,26 @@ public class ClassMetaData
 		}
 	}
     
+    public void registerForValueUpdate(String...values) {
+        if (values == null)
+            return;
+        for (String key : values) {
+            Value value = getRepository().getConfiguration()
+                    .getValue(key);
+            if (value != null)
+                value.addListener(this);
+        }
+    }
+        
+    public void valueChanged(Value val) {
+        if (val ==  null)
+            return;
+        String key = val.getProperty();
+        if ("DataCacheTimeout".equals(key)) {
+            _cacheTimeout = Integer.MIN_VALUE;
+        }
+    }
+    
     /**
      * Returns true if the pcType modeled by this ClassMetaData
      * object is abstract (ie, a MappedSuperclass in JPA terms.)

Modified: openjpa/branches/1.1.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java?rev=939817&r1=939816&r2=939817&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
(original)
+++ openjpa/branches/1.1.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java
Fri Apr 30 21:07:22 2010
@@ -912,13 +912,13 @@ public class ConfigurationImpl
     public boolean removeValue(Value val) {
         if (!_vals.remove(val))
             return false;
-        val.setListener(null);
+        val.removeListener(this);
         return true;
     }
 
     public Value addValue(Value val) {
         _vals.add(val);
-        val.setListener(this);
+        val.addListener(this);
         return val;
     }
 

Modified: openjpa/branches/1.1.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java?rev=939817&r1=939816&r2=939817&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java
(original)
+++ openjpa/branches/1.1.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java
Fri Apr 30 21:07:22 2010
@@ -18,7 +18,10 @@
  */
 package org.apache.openjpa.lib.conf;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
@@ -41,7 +44,7 @@ public abstract class Value implements C
     private String def = null;
     private String[] aliases = null;
     private String getter = null;
-    private ValueListener listen = null;
+    private List<ValueListener> listeners = null;
     private boolean aliasListComprehensive = false;
     private Class scope = null;
     private boolean isDynamic = false;
@@ -368,25 +371,37 @@ public abstract class Value implements C
     protected abstract void setInternalObject(Object obj);
 
     /**
-     * Listener for value changes.
+     * Gets unmodifable list of listeners for value changes.
      */
-    public ValueListener getListener() {
-        return this.listen;
+    public List<ValueListener> getListeners() {
+    	return Collections.unmodifiableList(this.listeners);
     }
 
     /**
      * Listener for value changes.
      */
-    public void setListener(ValueListener listen) {
-        this.listen = listen;
+    public void addListener(ValueListener listener) {
+        if (listener == null)
+            return;
+        if (listeners == null)
+            listeners = new ArrayList<ValueListener>();
+        listeners.add(listener);
+    }
+    
+    public void removeListener(ValueListener listener) {
+        if (listener == null)
+            return;
+        listeners.remove(listener);
     }
 
     /**
      * Subclasses should call this method when their internal value changes.
      */
     public void valueChanged() {
-        if (listen != null) {
-        	listen.valueChanged(this);
+        if (listeners == null) 
+            return;
+        for (ValueListener listener : listeners) {
+            listener.valueChanged(this);
         }
     }
     
@@ -401,13 +416,23 @@ public abstract class Value implements C
      * <LI>Configuration is read-only
      */
     protected void assertChangeable() {
-    	if (!isDynamic() && listen instanceof Configuration && 
-        	((Configuration)listen).isReadOnly()) {
+        if (!isDynamic() && containsReadOnlyConfigurationAsListener()) {
         	throw new RuntimeException(s_loc.get("veto-change",
         		this.getProperty()).toString());
        	}
     }
-    
+
+    boolean containsReadOnlyConfigurationAsListener() {
+        if (listeners == null)
+            return false;
+        for (ValueListener listener : listeners) {
+        if (listener instanceof Configuration
+        && ((Configuration)listener).isReadOnly())
+            return true;
+        }
+        return false;
+    }
+        
     /**
      * Sets if this receiver can be mutated even when the configuration it 
      * belongs to has been {@link Configuration#isReadOnly() frozen}.

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java?rev=939817&r1=939816&r2=939817&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestDynamicConfiguration.java
Fri Apr 30 21:07:22 2010
@@ -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 @@ import org.apache.openjpa.persistence.te
  */
 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,26 @@ public class TestDynamicConfiguration ex
 		
 		assertEquals(oldHash, newHash);
 	}
+
+    public void testClassMetaDataRecognizesDataCacheTimeoutValueChange() {
+        OpenJPAConfiguration conf = emf.getConfiguration();
+        
+        // ensure that PObject is in metadata repository
+        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());	
+    }
 }

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/PObject.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/PObject.java?rev=939817&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/PObject.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/PObject.java
Fri Apr 30 21:07:22 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.datacache.common.apps;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+/**
+ * A Simple entity for testing. Has a version field for testing optimistic
+ * concurrent usage.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+@Entity
+public class PObject {
+	@Id
+	@GeneratedValue
+	private long id;
+	private String name;
+	@Version
+	private int version;
+	
+	public String getName() {
+		return name;
+	}
+	
+	public void setName(String name) {
+		this.name = name;
+	}
+	
+	public long getId() {
+		return id;
+	}
+	
+	public int getVersion() {
+		return version;
+	}
+}



Mime
View raw message