openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r954678 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-lib/src/main/java/org/apache/openjp...
Date Tue, 15 Jun 2010 00:09:18 GMT
Author: ppoddar
Date: Tue Jun 15 00:09:17 2010
New Revision: 954678

URL: http://svn.apache.org/viewvc?rev=954678&view=rev
Log:
OPENJPA-1686: Upgrade to Java runtime version 5. Remove reflection. 

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ManagedClassSubclasser.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/JavaVersions.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java?rev=954678&r1=954677&r2=954678&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
Tue Jun 15 00:09:17 2010
@@ -1463,9 +1463,7 @@ public class MappingRepository extends M
         switch (vfield.getTypeCode()) {
             case JavaTypes.DATE:
             case JavaTypes.CALENDAR:
-                return (JavaVersions.VERSION >= 5) 
-                    ? new NanoPrecisionTimestampVersionStrategy()
-                    : new TimestampVersionStrategy();
+                return new NanoPrecisionTimestampVersionStrategy();
             case JavaTypes.BYTE:
             case JavaTypes.INT:
             case JavaTypes.LONG:
@@ -1478,7 +1476,6 @@ public class MappingRepository extends M
                 return new NumberVersionStrategy();
             default:
                 throw new UserException(_loc.get("version-type-unsupported", vfield, vfield.getDeclaredType()));
-//                return NoneVersionStrategy.getInstance();
         }
     }
     

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java?rev=954678&r1=954677&r2=954678&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ApplicationIdTool.java
Tue Jun 15 00:09:17 2010
@@ -380,15 +380,12 @@ public class ApplicationIdTool {
         // static block to register class
         code.tab().append("static").openBrace(2).endl();
         code.tab(2).append("// register persistent class in JVM").endl();
-        if (JavaVersions.VERSION >= 5) {
-            code.tab(2).append("try { Class.forName").openParen(true).
+        code.tab(2).append("try { Class.forName").openParen(true).
                 append("\"").append(_type.getName()).append("\"").
                 closeParen().append(";").append(" }").endl();
-            code.tab(2).append("catch").openParen(true).
+        code.tab(2).append("catch").openParen(true).
                 append("Exception e").closeParen().append(" {}").endl();
-        } else
-            code.tab(2).append("Class c = ").append(_type.getName()).
-                append(".class;").endl();
+        
         code.closeBrace(2);
 
         // field declarations

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=954678&r1=954677&r2=954678&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 Jun 15 00:09:17 2010
@@ -274,7 +274,7 @@ public class ManagedClassSubclasser {
             // but do set the metadata accordingly.
             if (enhancer.isAlreadyRedefined())
                 ints.add(bc.getType());
-            else if (JavaVersions.VERSION >= 5) {
+            else {
                 map.put(bc.getType(), bc.toByteArray());
                 debugBytecodes(bc);
             }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java?rev=954678&r1=954677&r2=954678&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
Tue Jun 15 00:09:17 2010
@@ -648,7 +648,7 @@ public class FieldMetaData
     private boolean isEnum() {
         if (_enumField == null) {
             Class<?> decl = getDeclaredType();
-            _enumField = JavaVersions.isEnumeration(decl)
+            _enumField =  Enum.class.isAssignableFrom(decl) 
                 ? Boolean.TRUE : Boolean.FALSE;
         }
         return _enumField.booleanValue();

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java?rev=954678&r1=954677&r2=954678&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
Tue Jun 15 00:09:17 2010
@@ -282,9 +282,10 @@ public class ProductDerivations {
         }
         reportErrors(errs, resource, err);
         String rsrc = resource + "#" + anchor;
-        throw (MissingResourceException) JavaVersions.initCause
-            (new MissingResourceException(rsrc,
-                ProductDerivations.class.getName(), rsrc), err);
+        MissingResourceException ex = new MissingResourceException(rsrc,
+                ProductDerivations.class.getName(), rsrc);
+        ex.initCause(err);
+        throw ex;
     }
 
     /**
@@ -319,9 +320,10 @@ public class ProductDerivations {
             J2DoPrivHelper.getAbsolutePathAction(file));
         reportErrors(errs, aPath, err);
         String rsrc = aPath + "#" + anchor;
-        throw (MissingResourceException) JavaVersions.initCause
-            (new MissingResourceException(rsrc,
-                ProductDerivations.class.getName(), rsrc), err);
+        MissingResourceException ex = new MissingResourceException(rsrc,
+                ProductDerivations.class.getName(), rsrc);
+        ex.initCause(err);
+        throw ex;
     }
    
     /**
@@ -375,9 +377,10 @@ public class ProductDerivations {
         Throwable nested) {
         if (errs == null)
             return;
-        throw (MissingResourceException) JavaVersions.initCause
-            (new MissingResourceException(errs.toString(),
-                ProductDerivations.class.getName(), resource), nested);
+        MissingResourceException ex = new MissingResourceException(errs.toString(),
+                ProductDerivations.class.getName(), resource);
+        ex.initCause(nested);
+        throw ex;
     }
 
     /**

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java?rev=954678&r1=954677&r2=954678&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java
Tue Jun 15 00:09:17 2010
@@ -394,7 +394,7 @@ public abstract class XMLMetaDataParser 
             finish();
         } catch (SAXException se) {
             IOException ioe = new IOException(se.toString());
-            JavaVersions.initCause(ioe, se);
+            ioe.initCause(se);
             throw ioe;
         } finally {
             reset();

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/JavaVersions.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/JavaVersions.java?rev=954678&r1=954677&r2=954678&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/JavaVersions.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/JavaVersions.java
Tue Jun 15 00:09:17 2010
@@ -20,6 +20,8 @@ package org.apache.openjpa.lib.util;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.security.AccessController;
 
 /**
@@ -39,16 +41,6 @@ public class JavaVersions {
 
     private static final Class<?>[] EMPTY_CLASSES = new Class[0];
 
-    private static Class<?> PARAM_TYPE = null;
-    private static Class<?> ENUM_TYPE  = null;
-    private static Class<?> ANNO_TYPE  = null;
-    private static Method GET_STACK = null;
-    private static Method SET_STACK = null;
-    private static Method GET_CAUSE = null;
-    private static Method INIT_CAUSE = null;
-    private static Object[] NO_ARGS  = null;
-    private static Class<?>[] NO_CLASS_ARGS = null;
-
     static {
         String specVersion = AccessController.doPrivileged(
             J2DoPrivHelper.getPropertyAction("java.specification.version")); 
@@ -64,104 +56,14 @@ public class JavaVersions {
             VERSION = 6;
         else
             VERSION = 7; // maybe someday...
-
-        if (VERSION >= 5) {
-            try {
-                PARAM_TYPE = Class.forName("java.lang.reflect.ParameterizedType");
-                ENUM_TYPE = Class.forName("java.lang.Enum");
-                ANNO_TYPE = Class.forName("java.lang.annotation.Annotation");
-            } catch (Throwable t) {
-            }
-        }
-
-        if (VERSION >= 4) {
-            try {
-                Class<?> stack = Class.forName("[Ljava.lang.StackTraceElement;");
-                GET_STACK = Throwable.class.getMethod("getStackTrace", NO_CLASS_ARGS);
-                SET_STACK = Throwable.class.getMethod("setStackTrace", new Class[]{ stack
});
-                GET_CAUSE = Throwable.class.getMethod("getCause", NO_CLASS_ARGS);
-                INIT_CAUSE = Throwable.class.getMethod("initCause", new Class[]{ Throwable.class
});
-            } catch (Throwable t) {
-            }
-        }
-    }
-
-    /**
-     * Returns a version-specific instance of the specified class
-     *
-     * @param base the base class to check
-     * @return the JDK-version-specific version of the class
-     * @see #getVersionSpecificClass(String)
-     */
-    public static Class<?> getVersionSpecificClass(Class<?> base) {
-        try {
-            return getVersionSpecificClass(base.getName());
-        } catch (ClassNotFoundException e) {
-            return base;
-        }
-    }
-
-    /**
-     * Obtains a subclass of the specific base class that is
-     * specific to the current version of Java in use. The
-     * heuristic for the class name to load will be that OpenJPA
-     * first checks for the name of the class with the current
-     * setting of the {@link #VERSION} field, then each number in
-     * decreasing order, until ending in the unqualified name.
-     * For example, if we are using JDK 1.5.1, and we want to load
-     * "org.apache.openjpa.lib.SomeClass", we will try to load the following
-     * classes in order and return the first one that is successfully
-     * found and loaded:
-     * <ol>
-     * <li>org.apache.openjpa.lib.SomeClass5</li>
-     * <li>org.apache.openjpa.lib.SomeClass4</li>
-     * <li>org.apache.openjpa.lib.SomeClass3</li>
-     * <li>org.apache.openjpa.lib.SomeClass2</li>
-     * <li>org.apache.openjpa.lib.SomeClass1</li>
-     * <li>org.apache.openjpa.lib.SomeClass</li>
-     * </ol>
-     *
-     * @param base the base name of the class to load
-     * @return the subclass appropriate for the current Java version
-     */
-    public static Class<?> getVersionSpecificClass(String base)
-        throws ClassNotFoundException {
-        for (int i = VERSION; i >= 1; i--) {
-            try {
-                return Class.forName(base + i);
-            } catch (Throwable e) {
-                // throwables might occur with bytecode that we cannot understand
-            }
-        }
-        return Class.forName(base);
-    }
-
-    /**
-     * Return true if the given type is an annotation.
-     */
-    public static boolean isAnnotation(Class<?> cls) {
-        return ANNO_TYPE != null && ANNO_TYPE.isAssignableFrom(cls);
-    }
-
-    /**
-     * Return true if the given type is an enumeration.
-     */
-    public static boolean isEnumeration(Class<?> cls) {
-        return ENUM_TYPE != null && ENUM_TYPE.isAssignableFrom(cls);
     }
 
     /**
      * Collects the parameterized type declarations for a given field.
      */
     public static Class<?>[] getParameterizedTypes(Field f) {
-        if (f == null)
-            return null;
-        if (VERSION < 5)
-            return EMPTY_CLASSES;
-
         try {
-            Object type = invokeGetter(f, "getGenericType");
-            return collectParameterizedTypes(type, f.getType());
+            return collectParameterizedTypes(f.getGenericType(), f.getType());
         } catch (Exception e) {
             return EMPTY_CLASSES;
         }
@@ -171,14 +73,8 @@ public class JavaVersions {
      * Collects the parameterized return type declarations for a given method.
      */
     public static Class<?>[] getParameterizedTypes(Method meth) {
-        if (meth == null)
-            return null;
-        if (VERSION < 5)
-            return EMPTY_CLASSES;
-
         try {
-            Object type = invokeGetter(meth, "getGenericReturnType");
-            return collectParameterizedTypes(type, meth.getReturnType());
+            return collectParameterizedTypes(meth.getGenericReturnType(), meth.getReturnType());
         } catch (Exception e) {
             return EMPTY_CLASSES;
         }
@@ -187,9 +83,9 @@ public class JavaVersions {
     /**
      * Return all parameterized classes for the given type.
      */
-    private static Class<?>[] collectParameterizedTypes(Object type, Class<?>
cls) throws Exception {
-        if (isParameterizedType(type)) {
-            Object[] args = (Object[]) invokeGetter(type, "getActualTypeArguments");
+    private static Class<?>[] collectParameterizedTypes(Type type, Class<?> cls)
throws Exception {
+        if (type instanceof ParameterizedType) {
+            Type[] args = ((ParameterizedType)type).getActualTypeArguments();
             Class<?>[] clss = new Class[args.length];
             for (int i = 0; i < args.length; i++) {
                 Class<?> c = extractClass(args[i]);
@@ -209,74 +105,12 @@ public class JavaVersions {
     /**
      * Extracts the class from the given argument, if possible. Null otherwise.
      */
-    static Class<?> extractClass(Object o) throws Exception {
-        if (o == null)
-            return null;
-        if (o instanceof Class)
-            return (Class<?>)o;
-        
-        if (isParameterizedType(o)) {
-            return extractClass(invokeGetter(o, "getRawType"));
+    static Class<?> extractClass(Type type) throws Exception {
+        if (type instanceof Class) {
+            return (Class<?>)type;
+        } else if (type instanceof ParameterizedType) {
+            return extractClass(((ParameterizedType)type).getRawType());
         }
         return null;
     }
-    
-    static Object invokeGetter(Object target, String method) throws Exception {
-        return AccessController.doPrivileged(
-                J2DoPrivHelper.getDeclaredMethodAction(target.getClass(), method, NO_CLASS_ARGS))
-                     .invoke(target, NO_ARGS);
-    }
-    
-    static boolean isParameterizedType(Object cls) {
-        return PARAM_TYPE != null && PARAM_TYPE.isInstance(cls);
-    }
-
-    /**
-     * Transfer the stack from one throwable to another, or return
-     * false if it cannot be done, possibly due to an unsupported Java version.
-     */
-    public static boolean transferStackTrace(Throwable from, Throwable to) {
-        if (GET_STACK == null || SET_STACK == null || from == null || to == null)
-            return false;
-
-        try {
-            Object stack = GET_STACK.invoke(from, NO_ARGS);
-            SET_STACK.invoke(to, new Object[]{ stack });
-            return true;
-        } catch (Throwable t) {
-            return false;
-        }
-    }
-
-    /**
-     * Return the cause of the given throwable.
-     */
-    public static Throwable getCause(Throwable ex) {
-        if (GET_CAUSE == null || ex == null)
-            return null;
-
-        try {
-            return (Throwable) GET_CAUSE.invoke(ex, NO_ARGS);
-        } catch (Throwable t) {
-            return null;
-        }
-    }
-
-    /**
-     * Set the cause of the given throwable.
-     */
-    public static Throwable initCause(Throwable ex, Throwable cause) {
-        if (INIT_CAUSE == null || ex == null || cause == null)
-            return ex;
-
-        try {
-            return (Throwable) INIT_CAUSE.invoke(ex, new Object[]{ cause });
-        } catch (Throwable t) {
-            return ex;
-        }
-    }
-
-    public static void main(String[] args) {
-        System.out.println("Java version is: " + VERSION);
-    }
 }

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=954678&r1=954677&r2=954678&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 Jun 15 00:09:17 2010
@@ -62,7 +62,6 @@ import static org.apache.openjpa.persist
 import static org.apache.openjpa.persistence.MetaDataTag.QUERIES;
 import static org.apache.openjpa.persistence.MetaDataTag.QUERY;
 import static org.apache.openjpa.persistence.MetaDataTag.READ_ONLY;
-import static org.apache.openjpa.persistence.MetaDataTag.REPLICATED;
 import static org.apache.openjpa.persistence.MetaDataTag.SEQ_GENERATOR;
 import static org.apache.openjpa.persistence.MetaDataTag.TYPE;
 import static org.apache.openjpa.persistence.MetaDataTag.VERSION;



Mime
View raw message