cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r454593 - in /incubator/cayenne/sandbox/asm-enhancer/src: main/java/org/apache/cayenne/enhancer/ClassBuilder.java main/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java test/java/org/apache/cayenne/enhancer/CayenneEnhancerTest.java
Date Tue, 10 Oct 2006 03:27:16 GMT
Author: aadamchik
Date: Mon Oct  9 20:27:16 2006
New Revision: 454593

URL: http://svn.apache.org/viewvc?view=rev&rev=454593
Log:
adding interface injection

Modified:
    incubator/cayenne/sandbox/asm-enhancer/src/main/java/org/apache/cayenne/enhancer/ClassBuilder.java
    incubator/cayenne/sandbox/asm-enhancer/src/main/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java
    incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/CayenneEnhancerTest.java

Modified: incubator/cayenne/sandbox/asm-enhancer/src/main/java/org/apache/cayenne/enhancer/ClassBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/src/main/java/org/apache/cayenne/enhancer/ClassBuilder.java?view=diff&rev=454593&r1=454592&r2=454593
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/src/main/java/org/apache/cayenne/enhancer/ClassBuilder.java
(original)
+++ incubator/cayenne/sandbox/asm-enhancer/src/main/java/org/apache/cayenne/enhancer/ClassBuilder.java
Mon Oct  9 20:27:16 2006
@@ -45,6 +45,22 @@
         this.currentClass = Type.getType("L" + className + ";");
     }
 
+    String[] addInterface(String[] interfaces, Class newInterface) {
+
+        String name = Type.getInternalName(newInterface);
+        if (interfaces == null || interfaces.length == 0) {
+            return new String[] {
+                name
+            };
+        }
+
+        String[] expandedInterfaces = new String[interfaces.length + 1];
+        expandedInterfaces[0] = name;
+        System.arraycopy(interfaces, 0, expandedInterfaces, 1, interfaces.length);
+
+        return expandedInterfaces;
+    }
+
     void createProperty(Class type, String name) {
         createProperty(type, name, false);
     }

Modified: incubator/cayenne/sandbox/asm-enhancer/src/main/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/src/main/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java?view=diff&rev=454593&r1=454592&r2=454593
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/src/main/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java
(original)
+++ incubator/cayenne/sandbox/asm-enhancer/src/main/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java
Mon Oct  9 20:27:16 2006
@@ -22,6 +22,7 @@
 
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.Persistent;
 import org.objectweb.asm.ClassAdapter;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.MethodVisitor;
@@ -54,9 +55,11 @@
             String superName,
             String[] interfaces) {
 
+        builder.reset(name);
+        interfaces = builder.addInterface(interfaces, Persistent.class);
+        
         super.visit(version, access, name, signature, superName, interfaces);
 
-        builder.reset(name);
         builder.createProperty(ObjectId.class, "objectId");
         builder.createProperty(ObjectContext.class, "objectContext", true);
         builder.createProperty(Integer.TYPE, "persistenceState");

Modified: incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/CayenneEnhancerTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/CayenneEnhancerTest.java?view=diff&rev=454593&r1=454592&r2=454593
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/CayenneEnhancerTest.java
(original)
+++ incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/CayenneEnhancerTest.java
Mon Oct  9 20:27:16 2006
@@ -13,6 +13,8 @@
 
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.Persistent;
 
 public class CayenneEnhancerTest extends TestCase {
 
@@ -34,11 +36,18 @@
         loader = new EnhancingClassLoader(new CayenneEnhancer(enhancedPropertyMap));
     }
 
-    public void testPersistenceFieldsInjected() throws Exception {
+    public void testPersistentInterfaceInjected() throws Exception {
 
         Class e1Class = Class.forName(C1, true, loader);
         assertNotNull(e1Class);
         assertEquals(C1, e1Class.getName());
+        assertTrue(Persistent.class.isAssignableFrom(e1Class));
+    }
+
+    public void testPersistenceFieldsInjected() throws Exception {
+
+        Class e1Class = Class.forName(C1, true, loader);
+        assertNotNull(e1Class);
 
         Field objectContext = e1Class.getDeclaredField("$cay_objectContext");
         assertTrue(ObjectContext.class.isAssignableFrom(objectContext.getType()));
@@ -62,10 +71,9 @@
         assertTrue(!Modifier.isTransient(objectId.getModifiers()));
     }
 
-    public void testPersistentPropertiesInjected() throws Exception {
+    public void testObjectContentInjectedProperty() throws Exception {
         Class e1Class = Class.forName(C1, true, loader);
         assertNotNull(e1Class);
-        assertEquals(C1, e1Class.getName());
 
         Method getObjectContext = e1Class.getDeclaredMethod(
                 "getObjectContext",
@@ -83,5 +91,30 @@
             oc
         });
         assertSame(oc, getObjectContext.invoke(o, (Object[]) null));
+    }
+
+    public void testPersistenceStateInjectedProperty() throws Exception {
+        Class e1Class = Class.forName(C1, true, loader);
+        assertNotNull(e1Class);
+        assertEquals(C1, e1Class.getName());
+
+        Method getPersistenceState = e1Class.getDeclaredMethod(
+                "getPersistenceState",
+                (Class[]) null);
+        Method setPersistenceState = e1Class.getDeclaredMethod(
+                "setPersistenceState",
+                new Class[] {
+                    Integer.TYPE
+                });
+
+        Object o = e1Class.newInstance();
+        assertEquals(0, getPersistenceState.invoke(o, (Object[]) null));
+
+        setPersistenceState.invoke(o, new Object[] {
+            new Integer(PersistenceState.DELETED)
+        });
+
+        Object state = getPersistenceState.invoke(o, (Object[]) null);
+        assertEquals(PersistenceState.DELETED, state);
     }
 }



Mime
View raw message