openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r819800 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/apache...
Date Tue, 29 Sep 2009 02:43:34 GMT
Author: ppoddar
Date: Tue Sep 29 02:43:32 2009
New Revision: 819800

URL: http://svn.apache.org/viewvc?rev=819800&view=rev
Log:
OPENJPA-1050: Use generics for BrokerFactory

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ClassRedefiner.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ClassResolver.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/AbstractBrokerSerializationTest.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
Tue Sep 29 02:43:32 2009
@@ -20,8 +20,6 @@
 
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
 import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
@@ -44,6 +42,7 @@
  * @author Abe White
  * @author Marc Prud'hommeaux
  */
+@SuppressWarnings("serial")
 public class JDBCBrokerFactory
     extends AbstractBrokerFactory {
 
@@ -67,7 +66,7 @@
      * Invoked from {@link Bootstrap#getBrokerFactory}.
      */
     public static JDBCBrokerFactory getInstance(ConfigurationProvider cp) {
-        Map props = cp.getProperties();
+        Map<String,Object> props = cp.getProperties();
         Object key = toPoolKey(props);
         JDBCBrokerFactory factory = (JDBCBrokerFactory)
             getPooledFactoryForKey(key);
@@ -134,7 +133,7 @@
             return;
 
         MappingRepository repo = conf.getMappingRepositoryInstance();
-        Collection classes = repo.loadPersistentTypes(false, loader);
+        Collection<Class<?>> classes = repo.loadPersistentTypes(false, loader);
         if (classes.isEmpty())
             return;
 
@@ -145,9 +144,7 @@
             "SynchronizeMappings");
 
         // initialize the schema
-        Class cls;
-        for (Iterator itr = classes.iterator(); itr.hasNext();) {
-            cls = (Class) itr.next();
+        for (Class<?> cls : classes) {
             try {
                 tool.run(cls);
             } catch (IllegalArgumentException iae) {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ClassRedefiner.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ClassRedefiner.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ClassRedefiner.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ClassRedefiner.java
Tue Sep 29 02:43:32 2009
@@ -18,37 +18,29 @@
  */
 package org.apache.openjpa.enhance;
 
-import java.lang.instrument.Instrumentation;
-import java.lang.instrument.ClassFileTransformer;
 import java.lang.instrument.ClassDefinition;
-import java.lang.instrument.UnmodifiableClassException;
-import java.lang.reflect.InvocationTargetException;
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.Instrumentation;
 import java.lang.reflect.Method;
 import java.security.ProtectionDomain;
 import java.util.Map;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.ArrayList;
-import java.io.IOException;
 
 import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.JavaVersions;
 import org.apache.openjpa.lib.util.Localizer;
-import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.util.InternalException;
-import org.apache.openjpa.util.UserException;
 
 /**
  * Redefines the method bodies of existing classes. Supports Java 5 VMs that
- * have a javaagent installed on the command line as well as newer VMs without
- * any javaagent flag.
+ * have a java agent installed on the command line as well as newer VMs without
+ * any <code>-javaagent</code> flag.
  *
  * @since 1.0.0
  */
 public class ClassRedefiner {
 
-    private static final Localizer _loc = 
-        Localizer.forPackage(ClassRedefiner.class);
+    private static final Localizer _loc = Localizer.forPackage(ClassRedefiner.class);
 
     private static Boolean _canRedefine = null;
 
@@ -59,7 +51,7 @@
      * this method is a no-op.
      */
     public static void redefineClasses(OpenJPAConfiguration conf,
-        final Map<Class,byte[]> classes) {
+        final Map<Class<?>,byte[]> classes) {
         Log log = conf.getLog(OpenJPAConfiguration.LOG_ENHANCE);
         if (classes == null || classes.size() == 0 || !canRedefineClasses(log))
             return;
@@ -67,10 +59,9 @@
         Instrumentation inst = null;
         ClassFileTransformer t = null;
         try {
-            inst =
-                InstrumentationFactory.getInstrumentation(log);
+            inst = InstrumentationFactory.getInstrumentation(log);
 
-            Class[] array = classes.keySet().toArray(new Class[classes.size()]);
+            Class<?>[] array = classes.keySet().toArray(new Class[classes.size()]);
             if (JavaVersions.VERSION >= 6) {
                 log.trace(_loc.get("retransform-types", classes.keySet()));
 
@@ -120,15 +111,13 @@
     public static boolean canRedefineClasses(Log log) {
         if (_canRedefine == null) {
             try {
-                Instrumentation inst = InstrumentationFactory
-                    .getInstrumentation(log);
+                Instrumentation inst = InstrumentationFactory.getInstrumentation(log);
                 if (inst == null) {
                     _canRedefine = Boolean.FALSE;
                 } else if (JavaVersions.VERSION == 5) {
-                    // if inst is non-null and we're using Java 5,
+                    // if instrumentation is non-null and we're using Java 5,
                     // isRetransformClassesSupported isn't available,
-                    // so we use the more basic class redefinition
-                    // instead.
+                    // so we use the more basic class redefinition instead.
                     _canRedefine = Boolean.TRUE;
                 } else {
                     _canRedefine = (Boolean) Instrumentation.class.getMethod(

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
Tue Sep 29 02:43:32 2009
@@ -25,7 +25,6 @@
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -78,20 +77,19 @@
      *
      * @since 1.0.0
      */
-    public static List<Class> prepareUnenhancedClasses(
+    public static List<Class<?>> prepareUnenhancedClasses(
         final OpenJPAConfiguration conf,
-        final Collection<? extends Class> classes,
+        final Collection<? extends Class<?>> classes,
         final ClassLoader envLoader) {
         if (classes == null)
             return null;
         if (classes.size() == 0)
-            return Collections.EMPTY_LIST;
+            return Collections.emptyList();
 
         Log log = conf.getLog(OpenJPAConfiguration.LOG_ENHANCE);
-        if (conf.getRuntimeUnenhancedClassesConstant()
-            != RuntimeUnenhancedClassesModes.SUPPORTED) {
-            Collection unenhanced = new ArrayList();
-            for (Class cls : classes)
+        if (conf.getRuntimeUnenhancedClassesConstant() != RuntimeUnenhancedClassesModes.SUPPORTED)
{
+            Collection<Class<?>> unenhanced = new ArrayList<Class<?>>();
+            for (Class<?> cls : classes)
                 if (!PersistenceCapable.class.isAssignableFrom(cls))
                     unenhanced.add(cls);
             if (unenhanced.size() > 0) {
@@ -123,28 +121,26 @@
 
         boolean redefine = ClassRedefiner.canRedefineClasses(log);
         if (redefine)
-            log.info(_loc.get("enhance-and-subclass-and-redef-start",
-                classes));
+            log.info(_loc.get("enhance-and-subclass-and-redef-start", classes));
         else
-            log.info(_loc.get("enhance-and-subclass-no-redef-start",
-                classes));
+            log.info(_loc.get("enhance-and-subclass-no-redef-start",  classes));
 
-        final Map<Class, byte[]> map = new HashMap<Class, byte[]>();
-        final List subs = new ArrayList(classes.size());
-        final List ints = new ArrayList(classes.size());
-        Set<Class> unspecified = null;
-        for (Iterator iter = classes.iterator(); iter.hasNext(); ) {
-            final Class cls = (Class) iter.next();
+        final Map<Class<?>, byte[]> map = new HashMap<Class<?>, byte[]>();
+        final List<Class<?>> subs = new ArrayList<Class<?>>(classes.size());
+        final List<Class<?>> ints = new ArrayList<Class<?>>(classes.size());
+        Set<Class<?>> unspecified = null;
+        for (Class<?> cls : classes) {
+            final Class<?> c = cls;
             final PCEnhancer enhancer = new PCEnhancer(conf, cls); 
 
             enhancer.setBytecodeWriter(new BytecodeWriter() {
                 public void write(BCClass bc) throws IOException {
-                    ManagedClassSubclasser.write(bc, enhancer, map,
-                        cls, subs, ints);
+                    ManagedClassSubclasser.write(bc, enhancer, map, c, subs, ints);
                 }
             });
-            if (redefine)
+            if (redefine) {
                 enhancer.setRedefine(true);
+            }
             enhancer.setCreateSubclass(true);
             enhancer.setAddDefaultConstructor(true);
 
@@ -157,13 +153,11 @@
             // reconfiguration at the end of this method.
             ClassMetaData meta = enhancer.getMetaData();
             if (meta == null) {
-                throw new MetaDataException(_loc.get("no-meta", cls)).
-                        setFatal(true);
+                throw new MetaDataException(_loc.get("no-meta", cls)).setFatal(true);
             }
             configureMetaData(meta, conf, redefine, false);
 
-            unspecified = collectRelatedUnspecifiedTypes(enhancer.getMetaData(),
-                classes, unspecified);
+            unspecified = collectRelatedUnspecifiedTypes(enhancer.getMetaData(), classes,
unspecified);
 
             int runResult = enhancer.run();
             if (runResult == PCEnhancer.ENHANCE_PC) {
@@ -177,24 +171,23 @@
         }
 
         if (unspecified != null && !unspecified.isEmpty())
-            throw new UserException(_loc.get("unspecified-unenhanced-types",
-                classes, unspecified));
+            throw new UserException(_loc.get("unspecified-unenhanced-types", classes, unspecified));
 
         ClassRedefiner.redefineClasses(conf, map);
-        for (Class cls : map.keySet()) {
+        for (Class<?> cls : map.keySet()) {
             setIntercepting(conf, envLoader, cls);
             configureMetaData(conf, envLoader, cls, redefine);
         }
-        for (Class cls : (Collection<Class>) subs)
+        for (Class<?> cls : subs)
             configureMetaData(conf, envLoader, cls, redefine);
-        for (Class cls : (Collection<Class>) ints)
+        for (Class<?> cls : ints)
             setIntercepting(conf, envLoader, cls);
 
         return subs;
     }
 
-    private static Set<Class> collectRelatedUnspecifiedTypes(ClassMetaData meta,
-        Collection<? extends Class> classes, Set<Class> unspecified) {
+    private static Set<Class<?>> collectRelatedUnspecifiedTypes(ClassMetaData
meta,
+        Collection<? extends Class<?>> classes, Set<Class<?>> unspecified)
{
         unspecified = collectUnspecifiedType(meta.getPCSuperclass(), classes,
             unspecified);
 
@@ -217,20 +210,20 @@
         return unspecified;
     }
 
-    private static Set<Class> collectUnspecifiedType(Class cls,
-        Collection<? extends Class> classes, Set<Class> unspecified) {
+    private static Set<Class<?>> collectUnspecifiedType(Class<?> cls,
+        Collection<? extends Class<?>> classes, Set<Class<?>> unspecified)
{
         if (cls != null && !classes.contains(cls)
             && !ImplHelper.isManagedType(null, cls)
             && !cls.isInterface()) {
             if (unspecified == null)
-                unspecified = new HashSet<Class>();
+                unspecified = new HashSet<Class<?>>();
             unspecified.add(cls);
         }
         return unspecified;
     }
 
     private static void configureMetaData(OpenJPAConfiguration conf,
-        ClassLoader envLoader, Class cls, boolean redefineAvailable) {
+        ClassLoader envLoader, Class<?> cls, boolean redefineAvailable) {
         ClassMetaData meta = conf.getMetaDataRepositoryInstance()
             .getMetaData(cls, envLoader, true);
         configureMetaData(meta, conf, redefineAvailable, true);
@@ -272,7 +265,7 @@
     }
 
     private static void write(BCClass bc, PCEnhancer enhancer,
-        Map<Class, byte[]> map, Class cls, List subs, List ints)
+        Map<Class<?>, byte[]> map, Class<?> cls, List<Class<?>>
subs, List<Class<?>> ints)
         throws IOException {
 
         if (bc == enhancer.getManagedTypeBytecode()) {
@@ -313,7 +306,7 @@
     }
 
     private static void setIntercepting(OpenJPAConfiguration conf,
-        ClassLoader envLoader, Class cls) {
+        ClassLoader envLoader, Class<?> cls) {
         ClassMetaData meta = conf.getMetaDataRepositoryInstance()
             .getMetaData(cls, envLoader, true);
         meta.setIntercepting(true);

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
Tue Sep 29 02:43:32 2009
@@ -28,7 +28,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -57,6 +56,7 @@
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet;
+import org.apache.openjpa.meta.MetaDataModes;
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.util.GeneralException;
 import org.apache.openjpa.util.InvalidStateException;
@@ -77,8 +77,7 @@
 public abstract class AbstractBrokerFactory
     implements BrokerFactory {
 
-    private static final Localizer _loc = Localizer.forPackage
-        (AbstractBrokerFactory.class);
+    private static final Localizer _loc = Localizer.forPackage(AbstractBrokerFactory.class);
 
     // static mapping of configurations to pooled broker factories
     private static final Map<Object,AbstractBrokerFactory> _pool = 
@@ -111,7 +110,7 @@
     private transient Map<Object, Class<?>[]> _lifecycleListeners = null;
 
     // transaction listeners to pass to each broker
-    private transient List _transactionListeners = null;
+    private transient List<Object> _transactionListeners = null;
 
     // key under which this instance can be stored in the broker pool
     // and later identified
@@ -124,7 +123,7 @@
      *
      * @since 1.1.0
      */
-    protected static Object toPoolKey(Map map) {
+    protected static Object toPoolKey(Map<String,Object> map) {
         Object key = Configurations.getProperty("Id", map);
         return ( key != null) ? key : map;
     }
@@ -209,7 +208,7 @@
             assertOpen();
             makeReadOnly();
 
-            BrokerImpl broker = null;
+            Broker broker = null;
             if (findExisting)
                 broker = findBroker(user, pass, managed);
             if (broker == null) {
@@ -224,22 +223,19 @@
         }
     }
 
-    void initializeBroker(boolean managed, int connRetainMode,
-        BrokerImpl broker, boolean fromDeserialization) {
+    void initializeBroker(boolean managed, int connRetainMode, Broker broker, boolean fromDeserialization)
{
         assertOpen();
         makeReadOnly();
         
         DelegatingStoreManager dsm = createDelegatingStoreManager();
 
-        broker.initialize(this, dsm, managed, connRetainMode,
-            fromDeserialization);
+        ((BrokerImpl) broker).initialize(this, dsm, managed, connRetainMode, fromDeserialization);
         if (!fromDeserialization)
             addListeners(broker);
 
         // if we're using remote events, register the event manager so
         // that it can broadcast commit notifications from the broker
-        RemoteCommitEventManager remote = _conf.
-            getRemoteCommitEventManager();
+        RemoteCommitEventManager remote = _conf.getRemoteCommitEventManager();
         if (remote.areRemoteEventsEnabled())
             broker.addTransactionListener(remote);
 
@@ -251,19 +247,15 @@
     /**
      * Add factory-registered lifecycle listeners to the broker.
      */
-    protected void addListeners(BrokerImpl broker) {
+    protected void addListeners(Broker broker) {
         if (_lifecycleListeners != null && !_lifecycleListeners.isEmpty()) {
-            Map.Entry entry;
-            for (Iterator itr = _lifecycleListeners.entrySet().iterator();
-                itr.hasNext();) {
-                entry = (Map.Entry) itr.next();
-                broker.addLifecycleListener(entry.getKey(), (Class[])
-                    entry.getValue());
+            for (Map.Entry<Object,Class<?>[]> entry : _lifecycleListeners.entrySet())
{
+                broker.addLifecycleListener(entry.getKey(), entry.getValue());
             }
         }
 
         if (_transactionListeners != null && !_transactionListeners.isEmpty()) {
-            for (Iterator itr = _transactionListeners.iterator();
+            for (Iterator<Object> itr = _transactionListeners.iterator();
                 itr.hasNext(); ) {
                 broker.addTransactionListener(itr.next());
             }
@@ -294,7 +286,7 @@
             Collection<Class<?>> clss = _conf.getMetaDataRepositoryInstance().
                 loadPersistentTypes(false, loader, _conf.isInitializeEagerly());
             if (clss.isEmpty())
-                _pcClassNames = Collections.EMPTY_SET;
+                _pcClassNames = Collections.emptyList();
             else {
                 Collection<String> c = new ArrayList<String>(clss.size());
                 for (Iterator<Class<?>> itr = clss.iterator(); itr.hasNext();)
{
@@ -310,31 +302,28 @@
         } else {
             // reload with this loader
             if (getPcClassLoaders().add(loader)) {
-                for (Iterator itr = _pcClassNames.iterator(); itr.hasNext();) {
+                for (String clsName : _pcClassNames) {
                     try {
-                        Class cls =
-                            Class.forName((String) itr.next(), true, loader);
+                        Class<?> cls = Class.forName(clsName, true, loader);
                         if (needsSub(cls))
                             toRedefine.add(cls);
                     } catch (Throwable t) {
-                        _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME)
-                            .warn(null, t);
+                        _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME).warn(null, t);
                     }
                 }
             }
         }
 
         // get the ManagedClassSubclasser into the loop
-        ManagedClassSubclasser.prepareUnenhancedClasses(
-            _conf, toRedefine, envLoader);
+        ManagedClassSubclasser.prepareUnenhancedClasses(_conf, toRedefine, envLoader);
     }
 
-    private boolean needsSub(Class cls) {
+    private boolean needsSub(Class<?> cls) {
         return !cls.isInterface()
             && !PersistenceCapable.class.isAssignableFrom(cls);
     }
 
-    public void addLifecycleListener(Object listener, Class[] classes) {
+    public void addLifecycleListener(Object listener, Class<?>[] classes) {
         lock();
         try {
             assertOpen();
@@ -362,7 +351,7 @@
         try {
             assertOpen();
             if (_transactionListeners == null)
-                _transactionListeners = new LinkedList();
+                _transactionListeners = new LinkedList<Object>();
             _transactionListeners.add(listener);
         } finally {
             unlock();
@@ -405,9 +394,7 @@
             }
 
             // close all brokers
-            Broker broker;
-            for (Iterator itr = _brokers.iterator(); itr.hasNext();) {
-                broker = (Broker) itr.next();
+            for (Broker broker : _brokers) {
                 // Check for null because _brokers may contain weak references
                 if ((broker != null) && (!broker.isClosed()))
                     broker.close();
@@ -491,14 +478,14 @@
             return factory;
 
         // reset these transient fields to empty values
-        _transactional = new ConcurrentHashMap();
+        _transactional = new ConcurrentHashMap<Object,Collection<Broker>>();
         _brokers = newBrokerSet();
 
         makeReadOnly();
         return this;
     }
 
-    private Set newBrokerSet() {
+    private Set<Broker> newBrokerSet() {
         BrokerValue bv;
         if (_conf instanceof OpenJPAConfigurationImpl)
             bv = ((OpenJPAConfigurationImpl) _conf).brokerPlugin;
@@ -507,11 +494,9 @@
 
         if (FinalizingBrokerImpl.class.isAssignableFrom(
             bv.getTemplateBrokerType(_conf))) {
-            return MapBackedSet.decorate(new ConcurrentHashMap(),
-                new Object() { });
+            return MapBackedSet.decorate(new ConcurrentHashMap(), new Object() { });
         } else {
-            return new ConcurrentReferenceHashSet(
-                ConcurrentReferenceHashSet.WEAK);
+            return new ConcurrentReferenceHashSet<Broker>(ConcurrentReferenceHashSet.WEAK);
         }
     }
 
@@ -534,7 +519,7 @@
      * pooling can return a matching manager before a new {@link StoreManager}
      * is created.
      */
-    protected BrokerImpl findBroker(String user, String pass, boolean managed) {
+    protected Broker findBroker(String user, String pass, boolean managed) {
         if (managed)
             return findTransactionalBroker(user, pass);
         return null;
@@ -572,7 +557,7 @@
      * Find a managed runtime broker associated with the
      * current transaction, or returns null if none.
      */
-    protected BrokerImpl findTransactionalBroker(String user, String pass) {
+    protected Broker findTransactionalBroker(String user, String pass) {
         Transaction trans;
         ManagedRuntime mr = _conf.getManagedRuntimeInstance();
         Object txKey;
@@ -591,16 +576,13 @@
             throw new GeneralException(e);
         }
 
-        Collection brokers = (Collection) _transactional.get(txKey);
+        Collection<Broker> brokers = _transactional.get(txKey);
         if (brokers != null) {
             // we don't need to synchronize on brokers since one JTA transaction
             // can never be active on multiple concurrent threads.
-            BrokerImpl broker;
-            for (Iterator itr = brokers.iterator(); itr.hasNext();) {
-                broker = (BrokerImpl) itr.next();
-                if (StringUtils.equals(broker.getConnectionUserName(),
-                    user) && StringUtils.equals
-                    (broker.getConnectionPassword(), pass))
+            for (Broker broker : brokers) {
+                if (StringUtils.equals(broker.getConnectionUserName(), user) 
+                 && StringUtils.equals(broker.getConnectionPassword(), pass))
                     return broker;
             }
         }
@@ -641,15 +623,13 @@
             if (log.isInfoEnabled())
                 log.info(getFactoryInitializationBanner());
             if (log.isTraceEnabled()) {
-                Map props = _conf.toProperties(true);
+                Map<String,Object> props = _conf.toProperties(true);
                 String lineSep = J2DoPrivHelper.getLineSeparator();
                 StringBuffer buf = new StringBuffer();
-                Map.Entry entry;
-                for (Iterator itr = props.entrySet().iterator();
-                    itr.hasNext();) {
-                    entry = (Map.Entry) itr.next();
-                    buf.append(entry.getKey()).append(": ").
-                        append(entry.getValue());
+                Map.Entry<?,?> entry;
+                for (Iterator<Map.Entry<String,Object>> itr = props.entrySet().iterator();
itr.hasNext();) {
+                    entry = itr.next();
+                    buf.append(entry.getKey()).append(": ").append(entry.getValue());
                     if (itr.hasNext())
                         buf.append(lineSep);
                 }
@@ -662,8 +642,8 @@
             // register the metdata repository to auto-load persistent types
             // and make sure types are enhanced
             MetaDataRepository repos = _conf.getMetaDataRepositoryInstance();
-            repos.setValidate(repos.VALIDATE_RUNTIME, true);
-            repos.setResolve(repos.MODE_MAPPING_INIT, true);
+            repos.setValidate(MetaDataRepository.VALIDATE_RUNTIME, true);
+            repos.setResolve(MetaDataModes.MODE_MAPPING_INIT, true);
             PCRegistry.addRegisterClassListener(repos);
 
             // freeze underlying configuration and eagerly initialize to
@@ -715,24 +695,20 @@
      * failed objects in the nested exceptions.
      */
     private void assertNoActiveTransaction() {
-        Collection excs;
+        Collection<Throwable> excs;
         if (_transactional.isEmpty())
             return;
 
-        excs = new ArrayList(_transactional.size());
-        for (Iterator trans = _transactional.values().iterator();
-            trans.hasNext();) {
-            Collection brokers = (Collection) trans.next();
-            for (Iterator itr = brokers.iterator(); itr.hasNext();) {
-                excs.add(new InvalidStateException(_loc.get("active")).
-                    setFailedObject(itr.next()));
+        excs = new ArrayList<Throwable>(_transactional.size());
+        for (Collection<Broker> brokers : _transactional.values()) {
+            for (Broker broker : brokers) {
+                excs.add(new InvalidStateException(_loc.get("active")).setFailedObject(broker));
             }
         }
 
         if (!excs.isEmpty())
             throw new InvalidStateException(_loc.get("nested-exceps")).
-                setNestedThrowables((Throwable[]) excs.toArray
-                    (new Throwable[excs.size()]));
+                setNestedThrowables((Throwable[]) excs.toArray(new Throwable[excs.size()]));
     }
 
     /**
@@ -765,10 +741,10 @@
             // threads using the same trans since one JTA transaction can never
             // be active on multiple concurrent threads.
             Object txKey = mr.getTransactionKey();
-            Collection brokers = (Collection) _transactional.get(txKey);
+            Collection<Broker> brokers = _transactional.get(txKey);
             
             if (brokers == null) {
-                brokers = new ArrayList(2);
+                brokers = new ArrayList<Broker>(2);
                 _transactional.put(txKey, brokers);
                 trans.registerSynchronization(new RemoveTransactionSync(txKey));
             }
@@ -844,10 +820,9 @@
     /**
      * Method insures that deserialized EMF has this reference re-instantiated
      */
-    private Collection getPcClassLoaders() {
+    private Collection<ClassLoader> getPcClassLoaders() {
        if (_pcClassLoaders == null)
-         _pcClassLoaders = new ConcurrentReferenceHashSet(
-             ConcurrentReferenceHashSet.WEAK);
+         _pcClassLoaders = new ConcurrentReferenceHashSet<ClassLoader>(ConcurrentReferenceHashSet.WEAK);
           
        return _pcClassLoaders;
     }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
Tue Sep 29 02:43:32 2009
@@ -20,7 +20,6 @@
 
 import java.io.Serializable;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Set;
 
 import org.apache.openjpa.conf.OpenJPAConfiguration;
@@ -83,7 +82,7 @@
      *
      * @since 0.3.3
      */
-    public void addLifecycleListener(Object listener, Class[] classes);
+    public void addLifecycleListener(Object listener, Class<?>[] classes);
 
     /**
      * Remove a listener for lifecycle-related events.

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ClassResolver.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ClassResolver.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ClassResolver.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ClassResolver.java
Tue Sep 29 02:43:32 2009
@@ -40,6 +40,5 @@
      * was obtained; may be null if operating outside
      * the context of persistence environment
      */
-    public ClassLoader getClassLoader(Class contextClass,
-        ClassLoader envLoader);
+    public ClassLoader getClassLoader(Class<?> contextClass, ClassLoader envLoader);
 }

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configuration.java
Tue Sep 29 02:43:32 2009
@@ -173,7 +173,7 @@
      * @param storeDefaults if true, then properties will be written
      * out even if they match the default value for a property
      */
-    public Map toProperties(boolean storeDefaults);
+    public Map<String,Object> toProperties(boolean storeDefaults);
     
     /**
      * Get the set of all known property keys, including any equivalent keys,

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationProvider.java
Tue Sep 29 02:43:32 2009
@@ -34,13 +34,13 @@
     /**
      * Return properties loaded thus far, or empty map if none.
      */
-    public Map getProperties();
+    public Map<String,Object> getProperties();
 
     /**
      * Add the given properties to those in this provider, overwriting
-     * any exisitng properties under the same keys.
+     * any existing properties under the same keys.
      */
-    public void addProperties(Map props);
+    public void addProperties(Map<?,?> props);
 
     /**
      * Add a single property, overwriting any existing property under the

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/enhance/AbstractUnenhancedClassTest.java
Tue Sep 29 02:43:32 2009
@@ -263,9 +263,8 @@
     }
 
     public void testEnhancer() throws IOException {
-        List<Class> subs =  ManagedClassSubclasser.prepareUnenhancedClasses(
-            emf.getConfiguration(),
-            Collections.singleton(getUnenhancedClass()), null);
+        List<Class<?>> subs =  ManagedClassSubclasser.prepareUnenhancedClasses(
+            emf.getConfiguration(), Collections.singleton(getUnenhancedClass()), null);
         Class sub = subs.get(0);
         assertNotNull(sub);
         assertEquals("org.apache.openjpa.enhance."
@@ -588,9 +587,9 @@
     public void testGetMetaDataOfSubtype() {
         ClassMetaData meta = JPAFacadeHelper.getMetaData(emf,
             getUnenhancedClass());
-        List<Class> subs =  ManagedClassSubclasser.prepareUnenhancedClasses(
-            emf.getConfiguration(),
-            Collections.singleton(getUnenhancedClass()), null);
+        List<Class<?>> subs =  ManagedClassSubclasser.prepareUnenhancedClasses(
+            emf.getConfiguration(), Collections.singleton(getUnenhancedClass()),
+            null);
         assertSame(meta, JPAFacadeHelper.getMetaData(emf, subs.get(0)));
 
         meta = JPAFacadeHelper.getMetaData(emf, getUnenhancedSubclass());

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/AbstractBrokerSerializationTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/AbstractBrokerSerializationTest.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/AbstractBrokerSerializationTest.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/AbstractBrokerSerializationTest.java
Tue Sep 29 02:43:32 2009
@@ -398,7 +398,7 @@
     /**
      * An additional type that must be available in this PC. May be null.
      */
-    protected Class getSecondaryType() {
+    protected Class<?> getSecondaryType() {
         return null;
     }
 

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java?rev=819800&r1=819799&r2=819800&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
Tue Sep 29 02:43:32 2009
@@ -21,8 +21,8 @@
 import java.lang.instrument.ClassFileTransformer;
 import java.lang.instrument.IllegalClassFormatException;
 import java.security.ProtectionDomain;
-import java.util.BitSet;
 import java.util.Map;
+
 import javax.persistence.EntityManager;
 import javax.persistence.spi.ClassTransformer;
 import javax.persistence.spi.LoadState;
@@ -35,18 +35,13 @@
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
 import org.apache.openjpa.enhance.PCClassFileTransformer;
 import org.apache.openjpa.enhance.PCEnhancerAgent;
-import org.apache.openjpa.enhance.PersistenceCapable;
-import org.apache.openjpa.enhance.StateManager;
 import org.apache.openjpa.kernel.Bootstrap;
 import org.apache.openjpa.kernel.BrokerFactory;
-import org.apache.openjpa.kernel.OpenJPAStateManager;
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
 import org.apache.openjpa.lib.conf.Configurations;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
-import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet;
-import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.meta.MetaDataModes;
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.persistence.validation.ValidationUtils;
@@ -66,10 +61,8 @@
     static final String CLASS_TRANSFORMER_OPTIONS = "ClassTransformerOptions";
     private static final String EMF_POOL = "EntityManagerFactoryPool";
 
-    private static final Localizer _loc = Localizer.forPackage(
-        PersistenceProviderImpl.class);
+    private static final Localizer _loc = Localizer.forPackage(PersistenceProviderImpl.class);
 
-    private static final String _name = PersistenceProviderImpl.class.getName();
     private Log _log;
     /**
      * Loads the entity manager specified by <code>name</code>, applying
@@ -82,8 +75,7 @@
      * This does no pooling of EntityManagersFactories.
      * @return EntityManagerFactory or null
      */
-    public OpenJPAEntityManagerFactory createEntityManagerFactory(String name,
-        String resource, Map m) {
+    public OpenJPAEntityManagerFactory createEntityManagerFactory(String name, String resource,
Map m) {
         PersistenceProductDerivation pd = new PersistenceProductDerivation();
         try {
             Object poolValue = Configurations.removeProperty(EMF_POOL, m);
@@ -108,9 +100,18 @@
             if (_log != null) {
                 _log.error(_loc.get("create-emf-error", name), e);
             }
+            
             /*
+             * 
              * Maintain 1.x behavior of throwing exceptions, even though
-             * JPA2 9.2 - createEMF "must" return null for PU it can't handle
+             * JPA2 9.2 - createEMF "must" return null for PU it can't handle.
+             * 
+             * JPA 2.0 Specification Section 9.2 states:
+             * "If a provider does not qualify as the provider for the named persistence
unit, 
+             * it must return null when createEntityManagerFactory is invoked on it."
+             * That specification compliance behavior has happened few lines above on null
return. 
+             * Throwing runtime exception in the following code is valid (and useful) behavior
+             * because the qualified provider has encountered an unexpected situation.
              */
             throw PersistenceExceptions.toPersistenceException(e);                
         }
@@ -135,13 +136,11 @@
             return Bootstrap.getBrokerFactory(cp, loader);
     }
 
-    public OpenJPAEntityManagerFactory createEntityManagerFactory(String name,
-        Map m) {
+    public OpenJPAEntityManagerFactory createEntityManagerFactory(String name, Map m) {
         return createEntityManagerFactory(name, null, m);
     }
 
-    public OpenJPAEntityManagerFactory createContainerEntityManagerFactory(
-        PersistenceUnitInfo pui, Map m) {
+    public OpenJPAEntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo
pui, Map m) {
         PersistenceProductDerivation pd = new PersistenceProductDerivation();
         try {
             Object poolValue = Configurations.removeProperty(EMF_POOL, m);
@@ -151,8 +150,7 @@
 
             // add enhancer
             Exception transformerException = null;
-            String ctOpts = (String) Configurations.getProperty
-                (CLASS_TRANSFORMER_OPTIONS, pui.getProperties());
+            String ctOpts = (String) Configurations.getProperty(CLASS_TRANSFORMER_OPTIONS,
pui.getProperties());
             try {
                 pui.addTransformer(new ClassTransformerImpl(cp, ctOpts,
                     pui.getNewTempClassLoader(), newConfigurationImpl()));
@@ -164,24 +162,17 @@
             // if the BrokerImpl hasn't been specified, switch to the
             // non-finalizing one, since anything claiming to be a container
             // should be doing proper resource management.
-            if (!Configurations.containsProperty(BrokerValue.KEY,
-                cp.getProperties())) {
-                cp.addProperty("openjpa." + BrokerValue.KEY, 
-                    getDefaultBrokerAlias());
+            if (!Configurations.containsProperty(BrokerValue.KEY, cp.getProperties())) {
+                cp.addProperty("openjpa." + BrokerValue.KEY, getDefaultBrokerAlias());
             }
 
-            BrokerFactory factory = getBrokerFactory(cp, poolValue,
-                pui.getClassLoader());
+            BrokerFactory factory = getBrokerFactory(cp, poolValue, pui.getClassLoader());
             if (transformerException != null) {
-                Log log = factory.getConfiguration().getLog(
-                    OpenJPAConfiguration.LOG_RUNTIME);
+                Log log = factory.getConfiguration().getLog(OpenJPAConfiguration.LOG_RUNTIME);
                 if (log.isTraceEnabled()) {
-                    log.warn(
-                        _loc.get("transformer-registration-error-ex", pui),
-                        transformerException);
+                    log.warn(_loc.get("transformer-registration-error-ex", pui), transformerException);
                 } else {
-                    log.warn(
-                        _loc.get("transformer-registration-error", pui));
+                    log.warn(_loc.get("transformer-registration-error", pui));
                 }
             }
             
@@ -234,10 +225,9 @@
         private ClassTransformerImpl(ConfigurationProvider cp, String props, 
             final ClassLoader tmpLoader, OpenJPAConfiguration conf) {
             cp.setInto(conf);
-            // use the tmp loader for everything
+            // use the temporary loader for everything
             conf.setClassResolver(new ClassResolver() {
-                public ClassLoader getClassLoader(Class context, 
-                    ClassLoader env) {
+                public ClassLoader getClassLoader(Class<?> context, ClassLoader env)
{
                     return tmpLoader;
                 }
             });



Mime
View raw message