openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r943294 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ openjpa-project/src/doc/manual/ openjpa-slice/src/main/java/org/apache/openjpa/slice/ openj...
Date Tue, 11 May 2010 21:09:18 GMT
Author: ppoddar
Date: Tue May 11 21:09:17 2010
New Revision: 943294

URL: http://svn.apache.org/viewvc?rev=943294&view=rev
Log:
OPENJPA-1662: Remove usage of @Replicated annotation. Replace with openjpa.slice.ReplicatedTypes
plug-in.

Removed:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Replicated.java
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ClassMetaData.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
    openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_slice.xml
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/DistributedConfiguration.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/DistributedQueryImpl.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/ReentrantSliceLock.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/ReplicationPolicy.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/SliceImplHelper.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/SliceInfo.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfiguration.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCStoreManager.java
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
    openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/Country.java
    openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/ReplicatedChild.java
    openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/ReplicatedParent.java
    openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestReplication.java
    openjpa/trunk/openjpa-slice/src/test/resources/META-INF/persistence.xml

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=943294&r1=943293&r2=943294&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
Tue May 11 21:09:17 2010
@@ -23,14 +23,11 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.security.AccessController;
-import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -41,6 +38,7 @@ import java.util.TreeMap;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.datacache.CacheDistributionPolicy;
 import org.apache.openjpa.datacache.DataCache;
 import org.apache.openjpa.enhance.PCRegistry;
 import org.apache.openjpa.enhance.PersistenceCapable;
@@ -67,7 +65,6 @@ import org.apache.openjpa.util.LongId;
 import org.apache.openjpa.util.MetaDataException;
 import org.apache.openjpa.util.ObjectId;
 import org.apache.openjpa.util.OpenJPAId;
-import org.apache.openjpa.util.Proxy;
 import org.apache.openjpa.util.ShortId;
 import org.apache.openjpa.util.StringId;
 import org.apache.openjpa.util.UnsupportedException;
@@ -182,7 +179,6 @@ public class ClassMetaData
     private int _identity = ID_UNKNOWN;
     private int _idStrategy = ValueStrategies.NONE;
     private int _accessType = AccessCode.UNKNOWN;
-    private boolean _replicated = false;
     
     private String _seqName = DEFAULT_STRING;
     private SequenceMetaData _seqMeta = null;
@@ -2646,21 +2642,6 @@ public class ClassMetaData
     	return result.toArray(new String[result.size()]);
     }
     
-    /**
-     * Affirms the persistence instances of this receiver is replicated across
-     * multiple databases.
-     */
-    public boolean isReplicated() {
-    	return _replicated;
-    }
-    
-    /**
-     * Sets the persistence instances of this receiver to be replicated across
-     * multiple databases.
-     */
-    public void setReplicated(boolean flag) {
-    	_replicated = flag;
-    }
 
     public boolean isAbstract() {
         return _abstract;

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Tue May 11 21:09:17 2010
@@ -235,7 +235,6 @@ public class AnnotationPersistenceMetaDa
         _tags.put(ManagedInterface.class, MANAGED_INTERFACE);
         _tags.put(ReadOnly.class, READ_ONLY);
         _tags.put(Type.class, TYPE);
-        _tags.put(Replicated.class, REPLICATED);
     }
 
     private final OpenJPAConfiguration _conf;
@@ -647,9 +646,6 @@ public class AnnotationPersistenceMetaDa
                     if (isMetaDataMode())
                         parseManagedInterface(meta, (ManagedInterface) anno);
                     break;
-                case REPLICATED:
-                	meta.setReplicated(true);
-                	break;
                 case ACCESS:
                     if (isMetaDataMode())
                         parseAccess(meta, (Access)anno);

Modified: openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_slice.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_slice.xml?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_slice.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_slice.xml Tue May 11 21:09:17 2010
@@ -217,9 +217,9 @@
 			same slice, there can be data elements that are commonly referred by
 			many instances such as Country or Currency code. Such quasi-static 
 			master data can be stored as identical copies in multiple slices. 
-			The user application needs to annotate such entity with
-			<classname>@Replicated</classname> annotation and implement 
-			a <classname>org.apache.openjpa.slice.ReplicationPolicy</classname> 
+			The user application must enumerate the replicated entity type names in
+			<classname>openjpa.slice.ReplicatedTypes</classname> as a comma-separated
list
+			and implement a <classname>org.apache.openjpa.slice.ReplicationPolicy</classname>

 			interface. The <classname>ReplicationPolicy</classname> interface 
 			is quite similar to <classname>DistributionPolicy</classname> 
 			interface except it returns an array of target slice names instead

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/DistributedConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/DistributedConfiguration.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/DistributedConfiguration.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/DistributedConfiguration.java
Tue May 11 21:09:17 2010
@@ -117,4 +117,6 @@ public interface DistributedConfiguratio
      * replicated instances will be replicated across the available slices.
      */
     void setReplicationPolicy(String policy);
+    
+    boolean isReplicated(Class<?> type);
 }

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/DistributedQueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/DistributedQueryImpl.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/DistributedQueryImpl.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/DistributedQueryImpl.java
Tue May 11 21:09:17 2010
@@ -28,10 +28,10 @@ import org.apache.openjpa.kernel.StoreQu
  * @author Pinaki Poddar
  *
  */
+@SuppressWarnings("serial")
 public class DistributedQueryImpl extends QueryImpl {
     private final ReentrantSliceLock _lock;
-    public DistributedQueryImpl(Broker broker, String language,
-            StoreQuery storeQuery) {
+    public DistributedQueryImpl(Broker broker, String language, StoreQuery storeQuery) {
         super(broker, language, storeQuery);
         _lock = new ReentrantSliceLock();
     }

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/ReentrantSliceLock.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/ReentrantSliceLock.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/ReentrantSliceLock.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/ReentrantSliceLock.java
Tue May 11 21:09:17 2010
@@ -26,6 +26,7 @@ import java.util.concurrent.locks.Reentr
  * @author Pinaki Poddar
  *
  */
+@SuppressWarnings("serial")
 public class ReentrantSliceLock extends ReentrantLock {
 
     public ReentrantSliceLock() {

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/ReplicationPolicy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/ReplicationPolicy.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/ReplicationPolicy.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/ReplicationPolicy.java
Tue May 11 21:09:17 2010
@@ -24,12 +24,11 @@ import java.util.List;
  * Policy to select one or more of the physical databases referred as 
  * <em>slice</em> in which a given persistent instance will be persisted.
  * 
- * This interface is invoked for entity types annotated as @Replicated
+ * This interface is invoked for entity types that are specified as ReplicatedTypes in the
configuration.
  *  
  * @author Pinaki Poddar 
  * 
  * @see DistributionPolicy
- * @see Replicated
  *
  */
 public interface ReplicationPolicy {

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/SliceImplHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/SliceImplHelper.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/SliceImplHelper.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/SliceImplHelper.java
Tue May 11 21:09:17 2010
@@ -40,7 +40,7 @@ public class SliceImplHelper {
 	/**
 	 * Gets the target slices by calling user-specified 
 	 * {@link DistributionPolicy} or {@link ReplicationPolicy} 
-     * depending on whether the given instance is {@link Replicated replicated}.
+     * depending on whether the given instance is {@link DistributedConfiguration#isReplicated(Class)
replicated}.
 	 */
 	public static SliceInfo getSlicesByPolicy(Object pc, 
 			DistributedConfiguration conf, Object ctx) {
@@ -84,22 +84,19 @@ public class SliceImplHelper {
 	/**
 	 * Affirms if the given instance be replicated to multiple slices.
 	 */
-    public static boolean isReplicated(Object pc, OpenJPAConfiguration conf) {
-		if (pc == null)
-			return false;
-		ClassMetaData meta = conf.getMetaDataRepositoryInstance()
-			.getMetaData(pc.getClass(), null, false);
-		return (meta == null) ? false : meta.isReplicated();
+    public static boolean isReplicated(Object pc, DistributedConfiguration conf) {
+        return pc == null ? false : conf.isReplicated(pc.getClass());
 	}
 
 	/**
 	 * Affirms if the given instance be replicated to multiple slices.
 	 */
-	public static boolean isReplicated(OpenJPAStateManager sm) {
-		if (sm == null)
-			return false;
-		return sm.getMetaData().isReplicated();
-	}
+//	public static boolean isReplicated(OpenJPAStateManager sm) {
+//	    return sm == null ? false : 
+//		if (sm == null)
+//			return false;
+//		return sm.getMetaData().isReplicated();
+//	}
 	
 	/**
 	 * Affirms if the given StateManager has an assigned slice.

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/SliceInfo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/SliceInfo.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/SliceInfo.java (original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/SliceInfo.java Tue
May 11 21:09:17 2010
@@ -37,8 +37,7 @@ public class SliceInfo implements Serial
 	private final boolean  _isReplicated;
 	private String[] _slices;
 	
-	private static transient Localizer _loc = 
-		Localizer.forPackage(SliceInfo.class);
+	private static transient Localizer _loc = Localizer.forPackage(SliceInfo.class);
 	
     /**
      * Generic constructor given one or more slice names. 
@@ -105,8 +104,6 @@ public class SliceInfo implements Serial
 	public SliceInfo setInto(OpenJPAStateManager sm) {
 		if (sm == null)
 			throw new NullPointerException();
-		if (SliceImplHelper.isReplicated(sm) != isReplicated())
-		    throw new InternalException();
 		Object previous = sm.setImplData(this, true);
 		if (previous == null || previous instanceof SliceInfo)
 			return (SliceInfo)previous;

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfiguration.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfiguration.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfiguration.java
Tue May 11 21:09:17 2010
@@ -35,5 +35,5 @@ public interface DistributedJDBCConfigur
      * Gets the master slice.
      */
     Slice getMasterSlice();
-
+    
 }

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCConfigurationImpl.java
Tue May 11 21:09:17 2010
@@ -21,10 +21,13 @@ package org.apache.openjpa.slice.jdbc;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 
 import javax.sql.DataSource;
 import javax.sql.XADataSource;
@@ -44,6 +47,8 @@ import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.log.LogFactory;
 import org.apache.openjpa.lib.log.LogFactoryImpl;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.slice.DistributedBrokerImpl;
 import org.apache.openjpa.slice.DistributionPolicy;
 import org.apache.openjpa.slice.ProductDerivation;
@@ -72,13 +77,16 @@ public class DistributedJDBCConfiguratio
     protected StringListValue namesPlugin;
     public PluginValue distributionPolicyPlugin;
     public PluginValue replicationPolicyPlugin;
+    public StringListValue replicatedTypesPlugin;
+    
+    private ReplicatedTypeRepository _replicationRepos;
     
     public static final String DOT = ".";
     public static final String REGEX_DOT = "\\.";
     public static final String PREFIX_SLICE = ProductDerivation.PREFIX_SLICE + DOT;
     public static final String PREFIX_OPENJPA = "openjpa.";
     private static Localizer _loc = Localizer.forPackage(DistributedJDBCConfigurationImpl.class);
-
+    
     /**
      * Create a configuration and declare the plug-ins.
      */
@@ -99,6 +107,9 @@ public class DistributedJDBCConfiguratio
         replicationPolicyPlugin.setString("all");
         replicationPolicyPlugin.setDynamic(true);
         
+        replicatedTypesPlugin = new StringListValue(PREFIX_SLICE + "ReplicatedTypes");
+        addValue(replicatedTypesPlugin);
+        
         lenientPlugin = addBoolean(PREFIX_SLICE + "Lenient");
         lenientPlugin.setDefault("true");
         
@@ -552,4 +563,51 @@ public class DistributedJDBCConfiguratio
         }
         return virtualDataSource;
     }
+    
+    public boolean isReplicated(Class<?> cls) {
+        if (_replicationRepos == null) {
+            _replicationRepos = new ReplicatedTypeRepository(getMetaDataRepositoryInstance(),
+                    Arrays.asList(replicatedTypesPlugin.get()));
+        }
+        return _replicationRepos.contains(cls);
+    }
+    
+    /**
+     * A private repository of replicated types.
+     * 
+     * @author Pinaki Poddar
+     *
+     */
+    private static class ReplicatedTypeRepository {
+        private Set<Class<?>> _replicatedTypes = new HashSet<Class<?>>();
+        private Set<Class<?>> _nonreplicatedTypes = new HashSet<Class<?>>();
+
+
+        List<String> names;
+        MetaDataRepository repos;
+        
+        ReplicatedTypeRepository(MetaDataRepository repos, List<String> given) {
+            names = given;
+            this.repos = repos;
+        }
+        
+        boolean contains(Class<?> cls) {
+            if (_replicatedTypes.contains(cls))
+                return true;
+            if (_nonreplicatedTypes.contains(cls)) 
+                return false;
+            ClassMetaData meta = repos.getMetaData(cls, null, false);
+            if (meta == null) {
+                _nonreplicatedTypes.add(cls);
+                return false;
+            }
+            boolean replicated = names.contains(meta.getDescribedType().getName());
+            if (replicated) {
+                _replicatedTypes.add(cls);
+            } else {
+                _nonreplicatedTypes.add(cls);
+            }
+            return replicated;
+        }
+    }
 }

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCStoreManager.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCStoreManager.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedJDBCStoreManager.java
Tue May 11 21:09:17 2010
@@ -56,6 +56,7 @@ import org.apache.openjpa.lib.util.Concr
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
+import org.apache.openjpa.slice.DistributedConfiguration;
 import org.apache.openjpa.slice.DistributedStoreManager;
 import org.apache.openjpa.slice.ProductDerivation;
 import org.apache.openjpa.slice.Slice;
@@ -145,7 +146,7 @@ class DistributedJDBCStoreManager extend
         SliceInfo result = null;
         PersistenceCapable pc = sm.getPersistenceCapable();
         Object ctx = getContext();
-        if (SliceImplHelper.isReplicated(sm)) {
+        if (_conf.isReplicated(sm.getMetaData().getDescribedType())) {
             result = SliceImplHelper.getSlicesByPolicy(pc, _conf, ctx);
         } else {
             String origin = estimateSlice(sm, edata);
@@ -159,7 +160,7 @@ class DistributedJDBCStoreManager extend
     }
     
     private void assignSlice(OpenJPAStateManager sm, String hint) {
-        if (SliceImplHelper.isReplicated(sm)) {
+        if (_conf.isReplicated(sm.getMetaData().getDescribedType())) {
             SliceImplHelper.getSlicesByPolicy(sm, _conf, getContext())
                 .setInto(sm);
             return;
@@ -349,10 +350,10 @@ class DistributedJDBCStoreManager extend
      * by the associated slice identifier of each StateManager.
      */
     private Map<String, StateManagerSet> bin(Collection sms, Object edata) {
-        Map<String, StateManagerSet> subsets =  
-            new HashMap<String, StateManagerSet>();
-        for (SliceStoreManager slice : _slices)
-            subsets.put(slice.getName(), new StateManagerSet());
+        Map<String, StateManagerSet> subsets =  new HashMap<String, StateManagerSet>();
+        for (SliceStoreManager slice : _slices) {
+            subsets.put(slice.getName(), new StateManagerSet(_conf));
+        }
         for (Object x : sms) {
             OpenJPAStateManager sm = (OpenJPAStateManager) x;
             String[] targets = findSliceNames(sm, edata).getSlices();
@@ -498,7 +499,7 @@ class DistributedJDBCStoreManager extend
            if (targetNames.contains(slice.getName()))
               targets.add(slice);
            }
-          if (targets.isEmpty())
+        if (targets.isEmpty())
             return _slices;
         return targets;
     }
@@ -523,11 +524,15 @@ class DistributedJDBCStoreManager extend
      *  
      */
     private static class StateManagerSet extends HashSet<OpenJPAStateManager> {
+        private final DistributedConfiguration conf;
         List<OpenJPAStateManager> replicated;
         
+        StateManagerSet(DistributedConfiguration conf) {
+            this.conf = conf;
+        }
         @Override
         public boolean add(OpenJPAStateManager sm) {
-            boolean isReplicated = sm.getMetaData().isReplicated();
+            boolean isReplicated =  conf.isReplicated(sm.getMetaData().getDescribedType());
             if (isReplicated) {
                 if (replicated == null)
                     replicated = new ArrayList<OpenJPAStateManager>();

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
Tue May 11 21:09:17 2010
@@ -45,6 +45,7 @@ import org.apache.openjpa.lib.rop.Merged
 import org.apache.openjpa.lib.rop.RangeResultObjectProvider;
 import org.apache.openjpa.lib.rop.ResultObjectProvider;
 import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.slice.DistributedConfiguration;
 import org.apache.openjpa.slice.SliceThread;
 import org.apache.openjpa.util.StoreException;
 
@@ -184,19 +185,17 @@ class DistributedStoreQuery extends JDBC
          * Scans metadata to find out if a replicated class is the candidate.
 		 */
 		boolean containsReplicated(QueryContext query) {
-			Class candidate = query.getCandidateType();
+			Class<?> candidate = query.getCandidateType();
+			DistributedConfiguration conf = (DistributedConfiguration)query.getStoreContext()
+			    .getConfiguration();
 			if (candidate != null) {
-                ClassMetaData meta = query.getStoreContext().getConfiguration()
-                        .getMetaDataRepositoryInstance().getMetaData(candidate,
-								null, true);
-				if (meta != null && meta.isReplicated())
-					return true;
+			    return conf.isReplicated(candidate);
 			}
 			ClassMetaData[] metas = query.getAccessPathMetaDatas();
 			if (metas == null || metas.length < 1)
 				return false;
-			for (ClassMetaData type : metas)
-				if (type.isReplicated())
+			for (ClassMetaData meta : metas)
+				if (conf.isReplicated(meta.getDescribedType()))
 					return true;
 			return false;
 		}

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/Country.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/Country.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/Country.java (original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/Country.java Tue May
11 21:09:17 2010
@@ -22,8 +22,6 @@ import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Version;
 
-import org.apache.openjpa.persistence.Replicated;
-
 /**
  * A persistence entity to be replicated across multiple databases. A
  * non-replicated entity can refer to a replicated entity.
@@ -32,7 +30,6 @@ import org.apache.openjpa.persistence.Re
  * 
  */
 @Entity
-@Replicated
 public class Country {
     @Id
     private String name;

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/ReplicatedChild.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/ReplicatedChild.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/ReplicatedChild.java
(original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/ReplicatedChild.java
Tue May 11 21:09:17 2010
@@ -22,10 +22,7 @@ import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.ManyToOne;
 
-import org.apache.openjpa.persistence.Replicated;
-
 @Entity
-@Replicated
 public class ReplicatedChild {
     @Id 
     private String name;

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/ReplicatedParent.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/ReplicatedParent.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/ReplicatedParent.java
(original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/ReplicatedParent.java
Tue May 11 21:09:17 2010
@@ -23,10 +23,7 @@ import java.util.Set;
 
 import javax.persistence.*;
 
-import org.apache.openjpa.persistence.Replicated;
-
 @Entity
-@Replicated
 public class ReplicatedParent {
     @Id 
     private String name;

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestReplication.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestReplication.java?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestReplication.java
(original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestReplication.java
Tue May 11 21:09:17 2010
@@ -23,7 +23,7 @@ import java.util.Set;
 import javax.persistence.EntityManager;
 
 /**
- * Tests that parent-child relation both @Repliated are stored in all replicated
+ * Tests that parent-child relation both replicated are stored in all replicated
  * slices.
  * 
  * <A HREF="https://issues.apache.org/jira/browse/OPENJPA-981">OPENJPA-981</A>

Modified: openjpa/trunk/openjpa-slice/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/resources/META-INF/persistence.xml?rev=943294&r1=943293&r2=943294&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-slice/src/test/resources/META-INF/persistence.xml Tue May 11 21:09:17
2010
@@ -101,6 +101,8 @@
             <property name="openjpa.QueryCompilationCache" value="false"/>
             <property name="openjpa.jdbc.MappingDefaults" value="DefaultMissingInfo=true"/>
             
+            <property name="openjpa.slice.ReplicatedTypes" value="org.apache.openjpa.slice.Country"/>
+            
             <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
             <property name="openjpa.DynamicEnhancementAgent"   value="false"/>
       	</properties>
@@ -171,12 +173,13 @@
          <property name="openjpa.slice.One.ConnectionURL" value="jdbc:derby:target/database/openjpa-slice1;create=true"/>
          <property name="openjpa.slice.Two.ConnectionURL" value="jdbc:derby:target/database/openjpa-slice2;create=true"/>
          
+         <property name="openjpa.slice.ReplicatedTypes" value="org.apache.openjpa.slice.ReplicatedParent,org.apache.openjpa.slice.ReplicatedChild"/>
          <property name="openjpa.Multithreaded" value="false"/>
          <property name="openjpa.Log" value="DefaultLevel=INFO, Enhance=TRACE, SQL=TRACE"/>
          <property name="openjpa.jdbc.SynchronizeMappings" value="refresh"/>
          <property name="openjpa.jdbc.MappingDefaults" value="DefaultMissingInfo=true"/>
-            <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
-            <property name="openjpa.DynamicEnhancementAgent"   value="false"/>
+         <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
+         <property name="openjpa.DynamicEnhancementAgent"   value="false"/>
       </properties>
    </persistence-unit>
    
@@ -228,5 +231,50 @@
       </properties>
    </persistence-unit>
    
-   
+   <persistence-unit name="perf.mysql.slice">
+   		<class>org.apache.openjpa.slice.Person</class>
+   		<class>org.apache.openjpa.slice.Address</class>
+   		<class>org.apache.openjpa.slice.Country</class>
+   		
+      <properties>
+         <property name="openjpa.BrokerFactory" value="slice"/>
+         <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
+
+         <property name="openjpa.slice.Names" value="S1,S2,S3,S4"/>
+         
+         <property name="openjpa.ConnectionUserName"        value="root"/>
+         <property name="openjpa.ConnectionPassword"        value=""/>
+         <property name="openjpa.slice.S1.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S1,MaxActive=4"/>
+         <property name="openjpa.slice.S2.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S2,MaxActive=4"/>
+         <property name="openjpa.slice.S3.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S3,MaxActive=4"/>
+         <property name="openjpa.slice.S4.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S4,MaxActive=4"/>
+         
+         <property name="openjpa.jdbc.DBDictionary"        value="mysql"/>
+         <property name="openjpa.Multithreaded" value="false"/>
+         <property name="openjpa.jdbc.SynchronizeMappings" value="refresh"/>
+         <property name="openjpa.jdbc.MappingDefaults" value="DefaultMissingInfo=true"/>
+         <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
+         <property name="openjpa.DynamicEnhancementAgent"   value="false"/>
+      </properties>
+   </persistence-unit>
+   <persistence-unit name="perf.mysql.mono">
+   		<class>org.apache.openjpa.slice.Person</class>
+   		<class>org.apache.openjpa.slice.Address</class>
+   		<class>org.apache.openjpa.slice.Country</class>
+   		
+      <properties>
+         <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
+         
+         <property name="openjpa.ConnectionUserName"        value="root"/>
+         <property name="openjpa.ConnectionPassword"        value=""/>
+         <property name="openjpa.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/S,MaxActive=4"/>
+         
+         <property name="openjpa.jdbc.DBDictionary"        value="mysql"/>
+         <property name="openjpa.Multithreaded" value="false"/>
+         <property name="openjpa.jdbc.SynchronizeMappings" value="refresh"/>
+         <property name="openjpa.jdbc.MappingDefaults" value="DefaultMissingInfo=true"/>
+         <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
+         <property name="openjpa.DynamicEnhancementAgent"   value="false"/>
+      </properties>
+   </persistence-unit>
 </persistence>



Mime
View raw message