Return-Path: X-Original-To: apmail-openjpa-commits-archive@www.apache.org Delivered-To: apmail-openjpa-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CA8AEDF42 for ; Mon, 23 Jul 2012 15:35:29 +0000 (UTC) Received: (qmail 49913 invoked by uid 500); 23 Jul 2012 15:35:29 -0000 Delivered-To: apmail-openjpa-commits-archive@openjpa.apache.org Received: (qmail 49773 invoked by uid 500); 23 Jul 2012 15:35:25 -0000 Mailing-List: contact commits-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list commits@openjpa.apache.org Received: (qmail 49740 invoked by uid 99); 23 Jul 2012 15:35:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jul 2012 15:35:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 Jul 2012 15:35:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A637623889BB for ; Mon, 23 Jul 2012 15:35:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1364683 - in /openjpa/trunk/openjpa-kernel/src: main/java/org/apache/openjpa/util/ test/java/org/apache/openjpa/util/ test/java/org/apache/openjpa/util/custom/ Date: Mon, 23 Jul 2012 15:35:02 -0000 To: commits@openjpa.apache.org From: curtisr7@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120723153502.A637623889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: curtisr7 Date: Mon Jul 23 15:35:01 2012 New Revision: 1364683 URL: http://svn.apache.org/viewvc?rev=1364683&view=rev Log: OPENJPA-2238: Don't create custom proxies for default scoped classes. Added: openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/ openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeList.java (with props) openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeType.java (with props) Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/TestProxyManager.java Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java?rev=1364683&r1=1364682&r2=1364683&view=diff ============================================================================== --- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java (original) +++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyManagerImpl.java Mon Jul 23 15:35:01 2012 @@ -291,6 +291,9 @@ public class ProxyManagerImpl return (Proxy) orig; if (ImplHelper.isManageable(orig)) return null; + if (!isProxyable(orig.getClass())) + return null; + if (orig instanceof Collection) { Comparator comp = (orig instanceof SortedSet) ? ((SortedSet) orig).comparator() : null; @@ -598,6 +601,21 @@ public class ProxyManagerImpl if (Modifier.isFinal(type.getModifiers())) throw new UnsupportedException(_loc.get("no-proxy-final", type)); } + + private static boolean isProxyable(Class cls){ + int mod = cls.getModifiers(); + if(Modifier.isFinal(mod)) + return false; + if(Modifier.isProtected(mod) || Modifier.isPublic(mod)) + return true; + // Default scoped class, we can only extend if it is in the same package as the generated proxy. Ideally + // we'd fix the code gen portion and place proxies in the same pacakge as the types being proxied. + if(cls.getPackage().getName().equals("org.apache.openjpa.util")) + return true; + + return false; + + } /** * Generate the bytecode for a map proxy for the given type. Modified: openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/TestProxyManager.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/TestProxyManager.java?rev=1364683&r1=1364682&r2=1364683&view=diff ============================================================================== --- openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/TestProxyManager.java (original) +++ openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/TestProxyManager.java Mon Jul 23 15:35:01 2012 @@ -19,6 +19,7 @@ package org.apache.openjpa.util; import java.io.InputStream; +import java.lang.reflect.Method; import java.sql.Time; import java.sql.Timestamp; import java.util.AbstractMap; @@ -27,6 +28,7 @@ import java.util.AbstractSet; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.GregorianCalendar; @@ -52,11 +54,10 @@ import junit.textui.TestRunner; /** * Test proxies generated by the proxy manager. - * + * * @author Abe White */ -public class TestProxyManager - extends TestCase { +public class TestProxyManager extends TestCase { private ProxyManagerImpl _mgr; @@ -97,13 +98,13 @@ public class TestProxyManager assertEquals(l1.size(), l2.size()); for (int i = 0; i < l1.size(); i++) assertTrue(l1.get(i) + " != " + l2.get(i), l1.get(i) == l2.get(i)); - } + } public void testCopySets() { Set orig = new HashSet(); populate(orig); assertSetsEqual(orig, (Set) _mgr.copyCollection(orig)); - + orig = new CustomSet(); populate(orig); assertSetsEqual(orig, (Set) _mgr.copyCollection(orig)); @@ -116,7 +117,7 @@ public class TestProxyManager assertTrue(s1.getClass() == s2.getClass()); assertEquals(s1.size(), s2.size()); assertEquals(s1, s2); - } + } public void testCopySortedSets() { SortedSet orig = new TreeSet(); @@ -126,7 +127,7 @@ public class TestProxyManager orig = new TreeSet(new CustomComparator()); populate(orig); assertSortedSetsEqual(orig, (SortedSet) _mgr.copyCollection(orig)); - + orig = new CustomSortedSet(); populate(orig); assertSortedSetsEqual(orig, (SortedSet) _mgr.copyCollection(orig)); @@ -153,7 +154,7 @@ public class TestProxyManager private static void assertSortedSetsEqual(SortedSet s1, SortedSet s2) { assertTrue(s1.getClass() == s2.getClass()); assertSortedSetsEquals(s1, s2); - } + } /** * Assert that the given sets are exactly the same (minus the class). @@ -166,68 +167,56 @@ public class TestProxyManager while (itr1.hasNext()) assertTrue(itr1.next() == itr2.next()); assertTrue(s1.equals(s2)); - } + } public void testCopyNullCollection() { assertNull(_mgr.copyCollection(null)); } public void testCopyProxyCollection() { - List orig = (List) _mgr.newCollectionProxy(ArrayList.class, null, null,true); + List orig = (List) _mgr.newCollectionProxy(ArrayList.class, null, null, true); populate(orig); assertListsEqual(new ArrayList(orig), (List) _mgr.copyCollection(orig)); - TreeSet torig = (TreeSet) _mgr.newCollectionProxy(TreeSet.class, null, - new CustomComparator(),true); + TreeSet torig = (TreeSet) _mgr.newCollectionProxy(TreeSet.class, null, new CustomComparator(), true); assertTrue(torig.comparator() instanceof CustomComparator); populate(torig); - assertSortedSetsEqual(new TreeSet(torig), (SortedSet) - _mgr.copyCollection(torig)); + assertSortedSetsEqual(new TreeSet(torig), (SortedSet) _mgr.copyCollection(torig)); } public void testCloneProxyCollection() { // List doesn't support clone() - - TreeSet torig = (TreeSet) _mgr.newCollectionProxy(TreeSet.class, null, - new CustomComparator(),true); + + TreeSet torig = (TreeSet) _mgr.newCollectionProxy(TreeSet.class, null, new CustomComparator(), true); assertTrue(torig.comparator() instanceof CustomComparator); populate(torig); assertSortedSetsEquals(new TreeSet(torig), (SortedSet) torig.clone()); } - public void testListMethodsProxied() - throws Exception { - Class proxy = _mgr.newCollectionProxy(ArrayList.class, null, null,true). - getClass(); + public void testListMethodsProxied() throws Exception { + Class proxy = _mgr.newCollectionProxy(ArrayList.class, null, null, true).getClass(); assertListMethodsProxied(proxy); - proxy = _mgr.newCollectionProxy(CustomList.class, null, null,true). - getClass(); + proxy = _mgr.newCollectionProxy(CustomList.class, null, null, true).getClass(); assertListMethodsProxied(proxy); } /** - * Assert that the methods we need to override to dirty the collection are - * proxied appropriately. + * Assert that the methods we need to override to dirty the collection are proxied appropriately. */ - private void assertCollectionMethodsProxied(Class cls) - throws Exception { - assertNotNull(cls.getDeclaredMethod("add", new Class[] {Object.class})); - assertNotNull(cls.getDeclaredMethod("addAll", - new Class[] {Collection.class})); + private void assertCollectionMethodsProxied(Class cls) throws Exception { + assertNotNull(cls.getDeclaredMethod("add", new Class[] { Object.class })); + assertNotNull(cls.getDeclaredMethod("addAll", new Class[] { Collection.class })); assertNotNull(cls.getDeclaredMethod("clear", (Class[]) null)); assertNotNull(cls.getDeclaredMethod("iterator", (Class[]) null)); - assertNotNull(cls.getDeclaredMethod("remove", - new Class[] {Object.class})); - assertNotNull(cls.getDeclaredMethod("removeAll", - new Class[] {Collection.class})); - assertNotNull(cls.getDeclaredMethod("retainAll", - new Class[] {Collection.class})); + assertNotNull(cls.getDeclaredMethod("remove", new Class[] { Object.class })); + assertNotNull(cls.getDeclaredMethod("removeAll", new Class[] { Collection.class })); + assertNotNull(cls.getDeclaredMethod("retainAll", new Class[] { Collection.class })); // check a non-mutating method to make sure we're not just proxying - // everything + // everything try { - cls.getDeclaredMethod("contains", new Class[] {Object.class}); + cls.getDeclaredMethod("contains", new Class[] { Object.class }); fail("Proxied non-mutating method."); } catch (NoSuchMethodException nsme) { // expected @@ -235,56 +224,43 @@ public class TestProxyManager } /** - * Assert that the methods we need to override to dirty the list are - * proxied appropriately. + * Assert that the methods we need to override to dirty the list are proxied appropriately. */ - private void assertListMethodsProxied(Class cls) - throws Exception { + private void assertListMethodsProxied(Class cls) throws Exception { assertCollectionMethodsProxied(cls); - assertNotNull(cls.getDeclaredMethod("add", - new Class[] {int.class, Object.class})); - assertNotNull(cls.getDeclaredMethod("addAll", - new Class[] {int.class, Collection.class})); - assertNotNull(cls.getDeclaredMethod("listIterator", (Class[]) null)); - assertNotNull(cls.getDeclaredMethod("listIterator", - new Class[] {int.class})); - assertNotNull(cls.getDeclaredMethod("remove", new Class[] {int.class})); - assertNotNull(cls.getDeclaredMethod("set", - new Class[] {int.class, Object.class})); - } - - public void testSetMethodsProxied() - throws Exception { - Class proxy = _mgr.newCollectionProxy(HashSet.class, null, null,true). - getClass(); + assertNotNull(cls.getDeclaredMethod("add", new Class[] { int.class, Object.class })); + assertNotNull(cls.getDeclaredMethod("addAll", new Class[] { int.class, Collection.class })); + assertNotNull(cls.getDeclaredMethod("listIterator", (Class[]) null)); + assertNotNull(cls.getDeclaredMethod("listIterator", new Class[] { int.class })); + assertNotNull(cls.getDeclaredMethod("remove", new Class[] { int.class })); + assertNotNull(cls.getDeclaredMethod("set", new Class[] { int.class, Object.class })); + } + + public void testSetMethodsProxied() throws Exception { + Class proxy = _mgr.newCollectionProxy(HashSet.class, null, null, true).getClass(); assertCollectionMethodsProxied(proxy); - proxy = _mgr.newCollectionProxy(CustomSet.class, null, null,true).getClass(); + proxy = _mgr.newCollectionProxy(CustomSet.class, null, null, true).getClass(); assertCollectionMethodsProxied(proxy); - proxy = _mgr.newCollectionProxy(CustomSortedSet.class, null, null,true). - getClass(); + proxy = _mgr.newCollectionProxy(CustomSortedSet.class, null, null, true).getClass(); assertCollectionMethodsProxied(proxy); - proxy = _mgr.newCollectionProxy(CustomComparatorSortedSet.class, null, - new CustomComparator(),true).getClass(); + proxy = _mgr.newCollectionProxy(CustomComparatorSortedSet.class, null, new CustomComparator(), true).getClass(); assertCollectionMethodsProxied(proxy); } - public void testQueueMethodsProxied() - throws Exception { + public void testQueueMethodsProxied() throws Exception { Class queue = getQueueClass(); if (queue == null) return; - Class proxy = _mgr.newCollectionProxy(LinkedList.class, null, null,true). - getClass(); - assertTrue(queue.isAssignableFrom(proxy)); + Class proxy = _mgr.newCollectionProxy(LinkedList.class, null, null, true).getClass(); + assertTrue(queue.isAssignableFrom(proxy)); assertCollectionMethodsProxied(proxy); - assertNotNull(proxy.getDeclaredMethod("offer", - new Class[] {Object.class})); - assertNotNull(proxy.getDeclaredMethod("poll", (Class[]) null)); - assertNotNull(proxy.getDeclaredMethod("remove", (Class[]) null)); + assertNotNull(proxy.getDeclaredMethod("offer", new Class[] { Object.class })); + assertNotNull(proxy.getDeclaredMethod("poll", (Class[]) null)); + assertNotNull(proxy.getDeclaredMethod("remove", (Class[]) null)); try { proxy.getDeclaredMethod("peek", (Class[]) null); fail("Proxied non-mutating method."); @@ -293,82 +269,66 @@ public class TestProxyManager } } - public void testLinkedListMethodsProxied() - throws Exception { - Class proxy = _mgr.newCollectionProxy(LinkedList.class, null, null,true). - getClass(); + public void testLinkedListMethodsProxied() throws Exception { + Class proxy = _mgr.newCollectionProxy(LinkedList.class, null, null, true).getClass(); assertListMethodsProxied(proxy); - assertNotNull(proxy.getDeclaredMethod("addFirst", - new Class[] {Object.class})); - assertNotNull(proxy.getDeclaredMethod("addLast", - new Class[] {Object.class})); - assertNotNull(proxy.getDeclaredMethod("removeFirst", (Class[]) null)); - assertNotNull(proxy.getDeclaredMethod("removeLast", (Class[]) null)); + assertNotNull(proxy.getDeclaredMethod("addFirst", new Class[] { Object.class })); + assertNotNull(proxy.getDeclaredMethod("addLast", new Class[] { Object.class })); + assertNotNull(proxy.getDeclaredMethod("removeFirst", (Class[]) null)); + assertNotNull(proxy.getDeclaredMethod("removeLast", (Class[]) null)); } - public void testVectorMethodsProxied() - throws Exception { - Class proxy = _mgr.newCollectionProxy(Vector.class, null, null,true). - getClass(); + public void testVectorMethodsProxied() throws Exception { + Class proxy = _mgr.newCollectionProxy(Vector.class, null, null, true).getClass(); assertListMethodsProxied(proxy); - assertNotNull(proxy.getDeclaredMethod("addElement", - new Class[] {Object.class})); - assertNotNull(proxy.getDeclaredMethod("insertElementAt", - new Class[] {Object.class, int.class})); - assertNotNull(proxy.getDeclaredMethod("removeAllElements", - (Class[]) null)); - assertNotNull(proxy.getDeclaredMethod("removeElement", - new Class[] {Object.class})); - assertNotNull(proxy.getDeclaredMethod("removeElementAt", - new Class[] {int.class})); - assertNotNull(proxy.getDeclaredMethod("setElementAt", - new Class[] {Object.class, int.class})); + assertNotNull(proxy.getDeclaredMethod("addElement", new Class[] { Object.class })); + assertNotNull(proxy.getDeclaredMethod("insertElementAt", new Class[] { Object.class, int.class })); + assertNotNull(proxy.getDeclaredMethod("removeAllElements", (Class[]) null)); + assertNotNull(proxy.getDeclaredMethod("removeElement", new Class[] { Object.class })); + assertNotNull(proxy.getDeclaredMethod("removeElementAt", new Class[] { int.class })); + assertNotNull(proxy.getDeclaredMethod("setElementAt", new Class[] { Object.class, int.class })); } public void testListChangeTracker() { - Proxy coll = _mgr.newCollectionProxy(ArrayList.class, null, null,true); + Proxy coll = _mgr.newCollectionProxy(ArrayList.class, null, null, true); assertNotNull(coll); assertNotNull(coll.getChangeTracker()); - assertTrue(coll.getChangeTracker() - instanceof CollectionChangeTrackerImpl); - CollectionChangeTrackerImpl ct = (CollectionChangeTrackerImpl) - coll.getChangeTracker(); + assertTrue(coll.getChangeTracker() instanceof CollectionChangeTrackerImpl); + CollectionChangeTrackerImpl ct = (CollectionChangeTrackerImpl) coll.getChangeTracker(); assertTrue(ct.allowsDuplicates()); assertTrue(ct.isOrdered()); } - + public void testSetChangeTracker() { - Proxy coll = _mgr.newCollectionProxy(HashSet.class, null, null,true); + Proxy coll = _mgr.newCollectionProxy(HashSet.class, null, null, true); assertNotNull(coll); assertNotNull(coll.getChangeTracker()); - assertTrue(coll.getChangeTracker() - instanceof CollectionChangeTrackerImpl); - CollectionChangeTrackerImpl ct = (CollectionChangeTrackerImpl) - coll.getChangeTracker(); + assertTrue(coll.getChangeTracker() instanceof CollectionChangeTrackerImpl); + CollectionChangeTrackerImpl ct = (CollectionChangeTrackerImpl) coll.getChangeTracker(); assertFalse(ct.allowsDuplicates()); assertFalse(ct.isOrdered()); } - + public void testCollectionInterfaceProxy() { - Proxy coll = _mgr.newCollectionProxy(Collection.class, null, null,true); + Proxy coll = _mgr.newCollectionProxy(Collection.class, null, null, true); assertNotNull(coll); } public void testListInterfaceProxy() { - Proxy coll = _mgr.newCollectionProxy(List.class, null, null,true); + Proxy coll = _mgr.newCollectionProxy(List.class, null, null, true); assertNotNull(coll); assertTrue(coll instanceof List); } public void testSetInterfaceProxy() { - Proxy coll = _mgr.newCollectionProxy(Set.class, null, null,true); + Proxy coll = _mgr.newCollectionProxy(Set.class, null, null, true); assertNotNull(coll); assertTrue(coll instanceof Set); assertFalse(coll instanceof SortedSet); } public void testSortedSetInterfaceProxy() { - Proxy coll = _mgr.newCollectionProxy(SortedSet.class, null, null,true); + Proxy coll = _mgr.newCollectionProxy(SortedSet.class, null, null, true); assertNotNull(coll); assertTrue(coll instanceof SortedSet); } @@ -378,11 +338,37 @@ public class TestProxyManager if (queue == null) return; - Proxy coll = _mgr.newCollectionProxy(queue, null, null,true); + Proxy coll = _mgr.newCollectionProxy(queue, null, null, true); assertNotNull(coll); assertTrue(queue.isInstance(coll)); } + public void testProxyCustomDefaultScopedType() throws Exception { + // Use reflection to instantiate a type that isn't in the current package. + Class cls = Class.forName("org.apache.openjpa.util.custom.CustomProxyDefaultScopeType"); + assertNotNull(cls); + Method meth = cls.getMethod("instance", new Class[0]); + assertNotNull(meth); + + meth.setAccessible(true); + Object obj = meth.invoke(cls, new Object[0]); + assertNotNull(obj); + assertNull(_mgr.newCustomProxy(obj, true)); + } + + public void testProxyCustomDefaultScopedList() throws Exception { + // Use reflection to instantiate a type that isn't in the current package. + Class cls = Class.forName("org.apache.openjpa.util.custom.CustomProxyDefaultScopeList"); + assertNotNull(cls); + Method meth = cls.getMethod("instance", new Class[0]); + assertNotNull(meth); + + meth.setAccessible(true); + Object obj = meth.invoke(cls, new Object[0]); + assertNotNull(obj); + assertNull(_mgr.newCustomProxy(obj, true)); + } + /** * Return the {@link java.util.Queue} class if avaialble. */ @@ -427,7 +413,7 @@ public class TestProxyManager assertTrue(m1.getClass() == m2.getClass()); assertEquals(m1.size(), m2.size()); assertEquals(m1, m2); - } + } public void testCopySortedMaps() { SortedMap orig = new TreeMap(); @@ -453,7 +439,7 @@ public class TestProxyManager private static void assertSortedMapsEqual(SortedMap m1, SortedMap m2) { assertTrue(m1.getClass() == m2.getClass()); assertSortedMapsEquals(m1, m2); - } + } /** * Assert that the given maps are exactly the same (minus the class). @@ -472,98 +458,81 @@ public class TestProxyManager assertTrue(entry1.getValue() == entry2.getValue()); } assertTrue(m1.equals(m2)); - } + } public void testCopyNullMap() { assertNull(_mgr.copyMap(null)); } public void testCopyProxyMap() { - Map orig = (Map) _mgr.newMapProxy(HashMap.class, null, null, null,true); + Map orig = (Map) _mgr.newMapProxy(HashMap.class, null, null, null, true); populate(orig); assertMapsEqual(new HashMap(orig), (Map) _mgr.copyMap(orig)); - TreeMap torig = (TreeMap) _mgr.newMapProxy(TreeMap.class, null, null, - new CustomComparator(),true); + TreeMap torig = (TreeMap) _mgr.newMapProxy(TreeMap.class, null, null, new CustomComparator(), true); assertTrue(torig.comparator() instanceof CustomComparator); populate(torig); - assertSortedMapsEqual(new TreeMap(torig), (SortedMap) - _mgr.copyMap(torig)); + assertSortedMapsEqual(new TreeMap(torig), (SortedMap) _mgr.copyMap(torig)); } public void testCloneProxyMap() { // Map does not support clone() - - TreeMap torig = (TreeMap) _mgr.newMapProxy(TreeMap.class, null, null, - new CustomComparator(),true); + + TreeMap torig = (TreeMap) _mgr.newMapProxy(TreeMap.class, null, null, new CustomComparator(), true); assertTrue(torig.comparator() instanceof CustomComparator); populate(torig); assertSortedMapsEquals(new TreeMap(torig), (SortedMap) torig.clone()); } - public void testMapMethodsProxied() - throws Exception { - Class proxy = _mgr.newMapProxy(HashMap.class, null, null, null,true). - getClass(); + public void testMapMethodsProxied() throws Exception { + Class proxy = _mgr.newMapProxy(HashMap.class, null, null, null, true).getClass(); assertMapMethodsProxied(proxy); - proxy = _mgr.newMapProxy(TreeMap.class, null, null, null,true).getClass(); + proxy = _mgr.newMapProxy(TreeMap.class, null, null, null, true).getClass(); assertMapMethodsProxied(proxy); - proxy = _mgr.newMapProxy(TreeMap.class, null, null, - new CustomComparator(),true).getClass(); + proxy = _mgr.newMapProxy(TreeMap.class, null, null, new CustomComparator(), true).getClass(); assertMapMethodsProxied(proxy); - proxy = _mgr.newMapProxy(CustomMap.class, null, null, null,true).getClass(); + proxy = _mgr.newMapProxy(CustomMap.class, null, null, null, true).getClass(); assertMapMethodsProxied(proxy); - proxy = _mgr.newMapProxy(CustomSortedMap.class, null, null, null,true). - getClass(); + proxy = _mgr.newMapProxy(CustomSortedMap.class, null, null, null, true).getClass(); assertMapMethodsProxied(proxy); - proxy = _mgr.newMapProxy(CustomComparatorSortedMap.class, null, null, - new CustomComparator(),true).getClass(); + proxy = _mgr.newMapProxy(CustomComparatorSortedMap.class, null, null, new CustomComparator(), true).getClass(); assertMapMethodsProxied(proxy); } /** - * Assert that the methods we need to override to dirty the collection are - * proxied appropriately. + * Assert that the methods we need to override to dirty the collection are proxied appropriately. */ - private void assertMapMethodsProxied(Class cls) - throws Exception { - assertNotNull(cls.getDeclaredMethod("put", - new Class[] {Object.class, Object.class})); - assertNotNull(cls.getDeclaredMethod("putAll", new Class[] {Map.class})); + private void assertMapMethodsProxied(Class cls) throws Exception { + assertNotNull(cls.getDeclaredMethod("put", new Class[] { Object.class, Object.class })); + assertNotNull(cls.getDeclaredMethod("putAll", new Class[] { Map.class })); assertNotNull(cls.getDeclaredMethod("clear", (Class[]) null)); - assertNotNull(cls.getDeclaredMethod("remove", - new Class[] {Object.class})); + assertNotNull(cls.getDeclaredMethod("remove", new Class[] { Object.class })); assertNotNull(cls.getDeclaredMethod("keySet", (Class[]) null)); assertNotNull(cls.getDeclaredMethod("values", (Class[]) null)); assertNotNull(cls.getDeclaredMethod("entrySet", (Class[]) null)); // check a non-mutating method to make sure we're not just proxying - // everything + // everything try { - cls.getDeclaredMethod("containsKey", new Class[] {Object.class}); + cls.getDeclaredMethod("containsKey", new Class[] { Object.class }); fail("Proxied non-mutating method."); } catch (NoSuchMethodException nsme) { // expected } } - public void testPropertiesMethodsProxied() - throws Exception { - Class proxy = _mgr.newMapProxy(Properties.class, null, null, null,true). - getClass(); + public void testPropertiesMethodsProxied() throws Exception { + Class proxy = _mgr.newMapProxy(Properties.class, null, null, null, true).getClass(); assertMapMethodsProxied(proxy); - assertNotNull(proxy.getDeclaredMethod("setProperty", - new Class[] {String.class, String.class})); - assertNotNull(proxy.getDeclaredMethod("load", - new Class[] {InputStream.class})); - assertNotNull(proxy.getDeclaredMethod("loadFromXML", - new Class[] {InputStream.class})); - } + assertNotNull(proxy.getDeclaredMethod("setProperty", new Class[] { String.class, String.class })); + assertNotNull(proxy.getDeclaredMethod("load", new Class[] { InputStream.class })); + assertNotNull(proxy.getDeclaredMethod("loadFromXML", new Class[] { InputStream.class })); + } public void testCopyDates() { Date orig = new Date(1999); @@ -590,14 +559,14 @@ public class TestProxyManager private static void assertDatesEqual(Date d1, Date d2) { assertTrue(d1.getClass() == d2.getClass()); assertDatesEquals(d1, d2); - } + } /** * Assert that the given dates are exactly the same (minus the class). */ private static void assertDatesEquals(Date d1, Date d2) { assertTrue(d1.equals(d2)); - } + } public void testCopyNullDate() { assertNull(_mgr.copyDate(null)); @@ -615,8 +584,7 @@ public class TestProxyManager assertDatesEquals(new Time(orig.getTime()), (Date) orig.clone()); } - public void testDateMethodsProxied() - throws Exception { + public void testDateMethodsProxied() throws Exception { Class proxy = _mgr.newDateProxy(Date.class).getClass(); assertDateMethodsProxied(proxy); @@ -634,28 +602,19 @@ public class TestProxyManager } /** - * Assert that the methods we need to override to dirty the date are - * proxied appropriately. + * Assert that the methods we need to override to dirty the date are proxied appropriately. */ - private void assertDateMethodsProxied(Class cls) - throws Exception { - assertNotNull(cls.getDeclaredMethod("setDate", - new Class[] {int.class})); - assertNotNull(cls.getDeclaredMethod("setHours", - new Class[] {int.class})); - assertNotNull(cls.getDeclaredMethod("setMinutes", - new Class[] {int.class})); - assertNotNull(cls.getDeclaredMethod("setMonth", - new Class[] {int.class})); - assertNotNull(cls.getDeclaredMethod("setSeconds", - new Class[] {int.class})); - assertNotNull(cls.getDeclaredMethod("setTime", - new Class[] {long.class})); - assertNotNull(cls.getDeclaredMethod("setYear", - new Class[] {int.class})); + private void assertDateMethodsProxied(Class cls) throws Exception { + assertNotNull(cls.getDeclaredMethod("setDate", new Class[] { int.class })); + assertNotNull(cls.getDeclaredMethod("setHours", new Class[] { int.class })); + assertNotNull(cls.getDeclaredMethod("setMinutes", new Class[] { int.class })); + assertNotNull(cls.getDeclaredMethod("setMonth", new Class[] { int.class })); + assertNotNull(cls.getDeclaredMethod("setSeconds", new Class[] { int.class })); + assertNotNull(cls.getDeclaredMethod("setTime", new Class[] { long.class })); + assertNotNull(cls.getDeclaredMethod("setYear", new Class[] { int.class })); // check a non-mutating method to make sure we're not just proxying - // everything + // everything try { cls.getDeclaredMethod("getTime", (Class[]) null); fail("Proxied non-mutating method."); @@ -665,14 +624,11 @@ public class TestProxyManager } /** - * Assert that the methods we need to override to dirty the timestamp are - * proxied appropriately. + * Assert that the methods we need to override to dirty the timestamp are proxied appropriately. */ - private void assertTimestampMethodsProxied(Class cls) - throws Exception { + private void assertTimestampMethodsProxied(Class cls) throws Exception { assertDateMethodsProxied(cls); - assertNotNull(cls.getDeclaredMethod("setNanos", - new Class[] {int.class})); + assertNotNull(cls.getDeclaredMethod("setNanos", new Class[] { int.class })); } public void testCopyCalendars() { @@ -699,22 +655,21 @@ public class TestProxyManager private static void assertCalendarsEqual(Calendar c1, Calendar c2) { assertTrue(c1.getClass() == c2.getClass()); assertCalendarsEquals(c1, c2); - } + } /** * Assert that the given dates are exactly the same (minus the class). */ private static void assertCalendarsEquals(Calendar c1, Calendar c2) { assertTrue(c1.equals(c2)); - } + } public void testCopyNullCalendar() { assertNull(_mgr.copyCalendar(null)); } public void testCopyProxyCalendar() { - Calendar orig = (Calendar) _mgr.newCalendarProxy - (GregorianCalendar.class, TimeZone.getTimeZone("CST")); + Calendar orig = (Calendar) _mgr.newCalendarProxy(GregorianCalendar.class, TimeZone.getTimeZone("CST")); populate(orig); Calendar cal = new GregorianCalendar(); populate(cal); @@ -722,12 +677,11 @@ public class TestProxyManager } public void testCloneProxyCalendar() { - Calendar orig = (Calendar) _mgr.newCalendarProxy - (GregorianCalendar.class, TimeZone.getTimeZone("CST")); + Calendar orig = (Calendar) _mgr.newCalendarProxy(GregorianCalendar.class, TimeZone.getTimeZone("CST")); populate(orig); Calendar cal = new GregorianCalendar(); populate(cal); - assertCalendarsEquals(cal, (Calendar)orig.clone()); + assertCalendarsEquals(cal, (Calendar) orig.clone()); } public void testCalendarAbstractClassProxy() { @@ -735,39 +689,29 @@ public class TestProxyManager assertNotNull(cal); } - public void testCalendarMethodsProxied() - throws Exception { - Class proxy = _mgr.newCalendarProxy(GregorianCalendar.class, - TimeZone.getDefault()).getClass(); + public void testCalendarMethodsProxied() throws Exception { + Class proxy = _mgr.newCalendarProxy(GregorianCalendar.class, TimeZone.getDefault()).getClass(); assertCalendarMethodsProxied(proxy); - proxy = _mgr.newCalendarProxy(CustomCalendar.class, - TimeZone.getDefault()).getClass(); + proxy = _mgr.newCalendarProxy(CustomCalendar.class, TimeZone.getDefault()).getClass(); assertCalendarMethodsProxied(proxy); - proxy = _mgr.newCalendarProxy(Calendar.class, - TimeZone.getDefault()).getClass(); + proxy = _mgr.newCalendarProxy(Calendar.class, TimeZone.getDefault()).getClass(); assertCalendarMethodsProxied(proxy); } /** - * Assert that the methods we need to override to dirty the calendar are - * proxied appropriately. + * Assert that the methods we need to override to dirty the calendar are proxied appropriately. */ - private void assertCalendarMethodsProxied(Class cls) - throws Exception { - assertNotNull(cls.getDeclaredMethod("set", - new Class[] {int.class, int.class})); - assertNotNull(cls.getDeclaredMethod("roll", - new Class[] {int.class, int.class})); - assertNotNull(cls.getDeclaredMethod("setTimeInMillis", - new Class[] {long.class})); - assertNotNull(cls.getDeclaredMethod("setTimeZone", - new Class[] {TimeZone.class})); + private void assertCalendarMethodsProxied(Class cls) throws Exception { + assertNotNull(cls.getDeclaredMethod("set", new Class[] { int.class, int.class })); + assertNotNull(cls.getDeclaredMethod("roll", new Class[] { int.class, int.class })); + assertNotNull(cls.getDeclaredMethod("setTimeInMillis", new Class[] { long.class })); + assertNotNull(cls.getDeclaredMethod("setTimeZone", new Class[] { TimeZone.class })); assertNotNull(cls.getDeclaredMethod("computeFields", (Class[]) null)); // check a non-mutating method to make sure we're not just proxying - // everything + // everything try { cls.getDeclaredMethod("getTimeInMillis", (Class[]) null); fail("Proxied non-mutating method."); @@ -797,10 +741,9 @@ public class TestProxyManager NonproxyableBean orig = new NonproxyableBean(1); populate(orig); assertNull(_mgr.copyCustom(orig)); - assertNull(_mgr.newCustomProxy(orig,true)); + assertNull(_mgr.newCustomProxy(orig, true)); } - /** * Assert that the given beans are exactly the same. */ @@ -808,43 +751,37 @@ public class TestProxyManager assertTrue(b1.getClass() == b2.getClass()); assertTrue(b1.getString() == b2.getString()); assertTrue(b1.getNumber() == b2.getNumber()); - } + } public void testCopyNullBean() { assertNull(_mgr.copyCustom(null)); } public void testCopyProxyBean() { - CustomBean orig = (CustomBean) _mgr.newCustomProxy(new CustomBean(),true); + CustomBean orig = (CustomBean) _mgr.newCustomProxy(new CustomBean(), true); populate(orig); CustomBean comp = new CustomBean(); populate(comp); assertBeansEqual(comp, (CustomBean) _mgr.copyCustom(orig)); } - public void testBeanMethodsProxied() - throws Exception { - Class proxy = _mgr.newCustomProxy(new CustomBean(),true).getClass(); + public void testBeanMethodsProxied() throws Exception { + Class proxy = _mgr.newCustomProxy(new CustomBean(), true).getClass(); assertBeanMethodsProxied(proxy); - proxy = _mgr.newCustomProxy(new CustomCopyConstructorBean - (new CustomBean()),true).getClass(); + proxy = _mgr.newCustomProxy(new CustomCopyConstructorBean(new CustomBean()), true).getClass(); assertBeanMethodsProxied(proxy); } /** - * Assert that the methods we need to override to dirty the bean are - * proxied appropriately. + * Assert that the methods we need to override to dirty the bean are proxied appropriately. */ - private void assertBeanMethodsProxied(Class cls) - throws Exception { - assertNotNull(cls.getDeclaredMethod("setString", - new Class[] {String.class})); - assertNotNull(cls.getDeclaredMethod("setNumber", - new Class[] {int.class})); + private void assertBeanMethodsProxied(Class cls) throws Exception { + assertNotNull(cls.getDeclaredMethod("setString", new Class[] { String.class })); + assertNotNull(cls.getDeclaredMethod("setNumber", new Class[] { int.class })); // check a non-mutating method to make sure we're not just proxying - // everything + // everything try { cls.getDeclaredMethod("getString", (Class[]) null); fail("Proxied non-mutating method."); @@ -858,14 +795,12 @@ public class TestProxyManager } /** - * Used to test custom list handling. Copy constructor intentionally - * ommitted. + * Used to test custom list handling. Copy constructor intentionally ommitted. */ - public static class CustomList - extends AbstractSequentialList { + public static class CustomList extends AbstractSequentialList { private final List _delegate = new ArrayList(); - + public int size() { return _delegate.size(); } @@ -876,14 +811,12 @@ public class TestProxyManager } /** - * Used to test custom set handling. Copy constructor intentionally - * ommitted. + * Used to test custom set handling. Copy constructor intentionally ommitted. */ - public static class CustomSet - extends AbstractSet { + public static class CustomSet extends AbstractSet { private final Set _delegate = new HashSet(); - + public int size() { return _delegate.size(); } @@ -898,19 +831,15 @@ public class TestProxyManager } /** - * Used to test custom set handling. Copy constructor intentionally - * ommitted. + * Used to test custom set handling. Copy constructor intentionally ommitted. */ - public static class CustomSortedSet - extends TreeSet { + public static class CustomSortedSet extends TreeSet { } /** - * Used to test custom set handling. Copy constructor intentionally - * ommitted. + * Used to test custom set handling. Copy constructor intentionally ommitted. */ - public static class CustomComparatorSortedSet - extends TreeSet { + public static class CustomComparatorSortedSet extends TreeSet { public CustomComparatorSortedSet() { } @@ -921,37 +850,31 @@ public class TestProxyManager } /** - * Used to test custom map handling. Copy constructor intentionally - * ommitted. + * Used to test custom map handling. Copy constructor intentionally ommitted. */ - public static class CustomMap - extends AbstractMap { + public static class CustomMap extends AbstractMap { private final Map _delegate = new HashMap(); public Object put(Object key, Object value) { return _delegate.put(key, value); } - + public Set entrySet() { return _delegate.entrySet(); } } /** - * Used to test custom map handling. Copy constructor intentionally - * ommitted. + * Used to test custom map handling. Copy constructor intentionally ommitted. */ - public static class CustomSortedMap - extends TreeMap { + public static class CustomSortedMap extends TreeMap { } /** - * Used to test custom map handling. Copy constructor intentionally - * ommitted. + * Used to test custom map handling. Copy constructor intentionally ommitted. */ - public static class CustomComparatorSortedMap - extends TreeMap { + public static class CustomComparatorSortedMap extends TreeMap { public CustomComparatorSortedMap() { } @@ -964,8 +887,7 @@ public class TestProxyManager /** * Used to test transfer of comparators to proxies. */ - private static class CustomComparator - implements Comparator { + private static class CustomComparator implements Comparator { public int compare(Object o1, Object o2) { return ((Comparable) o1).compareTo(o2); @@ -975,8 +897,7 @@ public class TestProxyManager /** * Used to test custom date handling. */ - public static class CustomDate - extends Timestamp { + public static class CustomDate extends Timestamp { public CustomDate(long time) { super(time); @@ -998,7 +919,7 @@ public class TestProxyManager _string = str; } - public int getNumber() { + public int getNumber() { return _number; } @@ -1010,8 +931,7 @@ public class TestProxyManager /** * Used to test custom bean handling. */ - public static class CustomCopyConstructorBean - extends CustomBean { + public static class CustomCopyConstructorBean extends CustomBean { public CustomCopyConstructorBean(CustomBean bean) { setString(bean.getString()); @@ -1022,8 +942,7 @@ public class TestProxyManager /** * Used to non-proxyable custom bean handling. */ - public static class NonproxyableBean - extends CustomBean { + public static class NonproxyableBean extends CustomBean { public NonproxyableBean(long x) { // single non-default, non-copy constructor @@ -1033,7 +952,6 @@ public class TestProxyManager /** * Used to test custom calendar handling. */ - public static class CustomCalendar - extends GregorianCalendar { + public static class CustomCalendar extends GregorianCalendar { } } Added: openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeList.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeList.java?rev=1364683&view=auto ============================================================================== --- openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeList.java (added) +++ openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeList.java Mon Jul 23 15:35:01 2012 @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openjpa.util.custom; + +import java.util.AbstractSequentialList; +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; + +class CustomProxyDefaultScopeList extends AbstractSequentialList { + + private final List _delegate = new ArrayList(); + + public int size() { + return _delegate.size(); + } + + public ListIterator listIterator(int idx) { + return _delegate.listIterator(idx); + } + + public static Object instance() { + return new CustomProxyDefaultScopeList(); + }; +} Propchange: openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeList.java ------------------------------------------------------------------------------ svn:eol-style = native Added: openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeType.java URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeType.java?rev=1364683&view=auto ============================================================================== --- openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeType.java (added) +++ openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeType.java Mon Jul 23 15:35:01 2012 @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openjpa.util.custom; + +class CustomProxyDefaultScopeType { + + int data; + + public CustomProxyDefaultScopeType() { + + } + + public CustomProxyDefaultScopeType(CustomProxyDefaultScopeType c) { + data = c.data; + } + + public int getData() { + return data; + } + + public void setData(int data) { + this.data = data; + } + + public static Object instance() { + return new CustomProxyDefaultScopeType(); + }; +} Propchange: openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/util/custom/CustomProxyDefaultScopeType.java ------------------------------------------------------------------------------ svn:eol-style = native