cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r454581 - in /incubator/cayenne/sandbox/asm-enhancer: .settings/ main/ src/ src/src/java/org/apache/cayenne/enhancer/ src/test/java/org/apache/cayenne/enhancer/
Date Tue, 10 Oct 2006 01:34:22 GMT
Author: aadamchik
Date: Mon Oct  9 18:34:21 2006
New Revision: 454581

URL: http://svn.apache.org/viewvc?view=rev&rev=454581
Log:
moving stuff around to fix the maven structure

Added:
    incubator/cayenne/sandbox/asm-enhancer/src/
      - copied from r454578, incubator/cayenne/sandbox/asm-enhancer/main/
    incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/EnhancedPojoDescriptor.java
    incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockObjectContext.java
Removed:
    incubator/cayenne/sandbox/asm-enhancer/.settings/org.eclipse.ltk.core.refactoring.prefs
    incubator/cayenne/sandbox/asm-enhancer/main/
    incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistenceDelegate.java
    incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PojoAdapter.java
    incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PojoAdapterFactory.java
    incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockPersistenceDelegate.java
    incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/PojoAdapterFactoryTest.java
Modified:
    incubator/cayenne/sandbox/asm-enhancer/.settings/org.eclipse.jdt.core.prefs
    incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java
    incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentGetterVisitor.java
    incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentSetterVisitor.java
    incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/AsmEnhancerTest.java
    incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java

Modified: incubator/cayenne/sandbox/asm-enhancer/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/.settings/org.eclipse.jdt.core.prefs?view=diff&rev=454581&r1=454580&r2=454581
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/.settings/org.eclipse.jdt.core.prefs (original)
+++ incubator/cayenne/sandbox/asm-enhancer/.settings/org.eclipse.jdt.core.prefs Mon Oct  9
18:34:21 2006
@@ -1,4 +1,4 @@
-#Sun Jul 23 18:13:04 EDT 2006
+#Thu Aug 24 07:23:42 MDT 2006
 eclipse.preferences.version=1
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5

Added: incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/EnhancedPojoDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/EnhancedPojoDescriptor.java?view=auto&rev=454581
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/EnhancedPojoDescriptor.java
(added)
+++ incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/EnhancedPojoDescriptor.java
Mon Oct  9 18:34:21 2006
@@ -0,0 +1,26 @@
+/*****************************************************************
+ *   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.cayenne.enhancer;
+
+class EnhancedPojoDescriptor {
+
+    static final String OBJECT_ID_FIELD = "$cay_objectId";
+    static final String PERSISTENCE_STATE_FIELD = "$cay_persistenceState";
+    static final String OBJECT_CONTEXT_FIELD = "$cay_objectContext";
+}

Modified: incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java?view=diff&rev=454581&r1=454578&r2=454581
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java
(original)
+++ incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentClassVisitor.java
Mon Oct  9 18:34:21 2006
@@ -1,3 +1,21 @@
+/*****************************************************************
+ *   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.cayenne.enhancer;
 
 import java.util.Collection;
@@ -5,65 +23,122 @@
 import org.objectweb.asm.ClassAdapter;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 
+/**
+ * ASM-based visitor that turns a pojo class into enahnced persistent object.
+ * 
+ * @author Andrus Adamchik
+ */
 class PersistentClassVisitor extends ClassAdapter {
 
-	private String className;
+    private String className;
+    private Collection<String> enhancedProperties;
 
-	private Collection<String> enhancedProperties;
-
-	PersistentClassVisitor(ClassVisitor visitor,
-			Collection<String> enhancedProperties) {
-		super(visitor);
-		this.enhancedProperties = enhancedProperties;
-	}
-
-	/**
-	 * Handles injection of additional fields and Persistent interface
-	 * properties.
-	 */
-	@Override
-	public void visit(int version, int access, String name, String signature,
-			String superName, String[] interfaces) {
-
-		this.className = name;
-
-		super.visit(version, access, name, signature, superName, interfaces);
-
-		// inject persistence delegate field.
-		FieldVisitor fv = visitField(
-				Opcodes.ACC_PUBLIC + Opcodes.ACC_TRANSIENT,
-				PojoAdapterFactory.PERSISTENCE_DELEGATE_FIELD,
-				"Lorg/apache/cayenne/jpa/enhancer/PersistenceDelegate;", null,
-				null);
-		fv.visitEnd();
-	}
-
-	/**
-	 * Handles getter and setter enhancements.
-	 */
-	@Override
-	public MethodVisitor visitMethod(int access, String name, String desc,
-			String signature, String[] exceptions) {
-
-		MethodVisitor mv = super.visitMethod(access, name, desc, signature,
-				exceptions);
-
-		// TODO: andrus, 10/8/2006 - check method sig for real... just checking
-		// the name is not enough
-
-		String getProperty = EnhancerUtil.propertyNameForGetter(name);
-		if (getProperty != null && enhancedProperties.contains(getProperty)) {
-			return new PersistentGetterVisitor(mv, className, getProperty);
-		}
-
-		String setProperty = EnhancerUtil.propertyNameForSetter(name);
-		if (setProperty != null && enhancedProperties.contains(setProperty)) {
-			return new PersistentSetterVisitor(mv, className, setProperty);
-		}
-
-		return mv;
-	}
+    PersistentClassVisitor(ClassVisitor visitor, Collection<String> enhancedProperties)
{
+        super(visitor);
+        this.enhancedProperties = enhancedProperties;
+    }
+
+    /**
+     * Handles injection of additional fields and Persistent interface properties.
+     */
+    @Override
+    public void visit(
+            int version,
+            int access,
+            String name,
+            String signature,
+            String superName,
+            String[] interfaces) {
+
+        this.className = name;
+
+        super.visit(version, access, name, signature, superName, interfaces);
+
+        injectPersistenceFields();
+        injectPersistenceMethods();
+    }
+
+    /**
+     * Handles getter and setter enhancements.
+     */
+    @Override
+    public MethodVisitor visitMethod(
+            int access,
+            String name,
+            String desc,
+            String signature,
+            String[] exceptions) {
+
+        MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
+
+        // TODO: andrus, 10/8/2006 - check method sig for real... just checking
+        // the name is not enough
+
+        String getProperty = EnhancerUtil.propertyNameForGetter(name);
+        if (getProperty != null && enhancedProperties.contains(getProperty)) {
+            return new PersistentGetterVisitor(mv, className, getProperty);
+        }
+
+        String setProperty = EnhancerUtil.propertyNameForSetter(name);
+        if (setProperty != null && enhancedProperties.contains(setProperty)) {
+            return new PersistentSetterVisitor(mv, className, setProperty);
+        }
+
+        return mv;
+    }
+
+    private void injectPersistenceFields() {
+        FieldVisitor fv = visitField(
+                Opcodes.ACC_PROTECTED,
+                EnhancedPojoDescriptor.OBJECT_ID_FIELD,
+                "Lorg/apache/cayenne/ObjectId;",
+                null,
+                null);
+        fv.visitEnd();
+
+        fv = visitField(
+                Opcodes.ACC_PROTECTED,
+                EnhancedPojoDescriptor.PERSISTENCE_STATE_FIELD,
+                "I",
+                null,
+                null);
+        fv.visitEnd();
+
+        fv = visitField(
+                Opcodes.ACC_PROTECTED + Opcodes.ACC_TRANSIENT,
+                EnhancedPojoDescriptor.OBJECT_CONTEXT_FIELD,
+                "Lorg/apache/cayenne/ObjectContext;",
+                null,
+                null);
+        fv.visitEnd();
+    }
+
+    private void injectPersistenceMethods() {
+
+        MethodVisitor mv = visitMethod(
+                Opcodes.ACC_PUBLIC,
+                "getObjectContext",
+                "()Lorg/apache/cayenne/ObjectContext;",
+                null,
+                null);
+        mv.visitCode();
+        Label l0 = new Label();
+        mv.visitLabel(l0);
+        mv.visitVarInsn(Opcodes.ALOAD, 0);
+        mv.visitFieldInsn(
+                Opcodes.GETFIELD,
+                className,
+                EnhancedPojoDescriptor.OBJECT_CONTEXT_FIELD,
+                "Lorg/apache/cayenne/ObjectContext;");
+        mv.visitInsn(Opcodes.ARETURN);
+        Label l1 = new Label();
+        mv.visitLabel(l1);
+        mv.visitLocalVariable("this", className, null, l0, l1, 0);
+        mv.visitMaxs(1, 1);
+        mv.visitEnd();
+    }
 }

Modified: incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentGetterVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentGetterVisitor.java?view=diff&rev=454581&r1=454578&r2=454581
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentGetterVisitor.java
(original)
+++ incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentGetterVisitor.java
Mon Oct  9 18:34:21 2006
@@ -1,40 +1,55 @@
+/*****************************************************************
+ *   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.cayenne.enhancer;
 
-import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodAdapter;
 import org.objectweb.asm.MethodVisitor;
-import org.objectweb.asm.Opcodes;
 
 class PersistentGetterVisitor extends MethodAdapter {
 
-	private String className;
-	private String propertyName;
+    private String className;
+    private String propertyName;
 
-	PersistentGetterVisitor(MethodVisitor mv, String className,
-			String propertyName) {
-		super(mv);
-		this.className = className;
-		this.propertyName = propertyName;
-	}
-
-	@Override
-	public void visitCode() {
-		super.visitCode();
-
-		mv.visitVarInsn(Opcodes.ALOAD, 0);
-		mv.visitFieldInsn(Opcodes.GETFIELD, className,
-				"$cayenne_persistenceDelegate",
-				"Lorg/apache/cayenne/jpa/enhancer/PersistenceDelegate;");
-		Label l1 = new Label();
-		mv.visitJumpInsn(Opcodes.IFNULL, l1);
-		mv.visitVarInsn(Opcodes.ALOAD, 0);
-		mv.visitFieldInsn(Opcodes.GETFIELD, className,
-				PojoAdapterFactory.PERSISTENCE_DELEGATE_FIELD,
-				"Lorg/apache/cayenne/jpa/enhancer/PersistenceDelegate;");
-		mv.visitLdcInsn(propertyName);
-		mv.visitMethodInsn(Opcodes.INVOKEINTERFACE,
-				"org/apache/cayenne/jpa/enhancer/PersistenceDelegate",
-				"prepareForAccess", "(Ljava/lang/String;)V");
-		mv.visitLabel(l1);
-	}
+    PersistentGetterVisitor(MethodVisitor mv, String className, String propertyName) {
+        super(mv);
+        this.className = className;
+        this.propertyName = propertyName;
+    }
+
+    @Override
+    public void visitCode() {
+        super.visitCode();
+
+        // mv.visitVarInsn(Opcodes.ALOAD, 0);
+        // mv.visitFieldInsn(Opcodes.GETFIELD, className,
+        // "$cayenne_persistenceDelegate",
+        // "Lorg/apache/cayenne/jpa/enhancer/PersistenceDelegate;");
+        // Label l1 = new Label();
+        // mv.visitJumpInsn(Opcodes.IFNULL, l1);
+        // mv.visitVarInsn(Opcodes.ALOAD, 0);
+        // mv.visitFieldInsn(Opcodes.GETFIELD, className,
+        // PojoAdapterFactory.PERSISTENCE_DELEGATE_FIELD,
+        // "Lorg/apache/cayenne/jpa/enhancer/PersistenceDelegate;");
+        // mv.visitLdcInsn(propertyName);
+        // mv.visitMethodInsn(Opcodes.INVOKEINTERFACE,
+        // "org/apache/cayenne/jpa/enhancer/PersistenceDelegate",
+        // "prepareForAccess", "(Ljava/lang/String;)V");
+        // mv.visitLabel(l1);
+    }
 }

Modified: incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentSetterVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentSetterVisitor.java?view=diff&rev=454581&r1=454578&r2=454581
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentSetterVisitor.java
(original)
+++ incubator/cayenne/sandbox/asm-enhancer/src/src/java/org/apache/cayenne/enhancer/PersistentSetterVisitor.java
Mon Oct  9 18:34:21 2006
@@ -1,41 +1,55 @@
+/*****************************************************************
+ *   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.cayenne.enhancer;
 
-import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodAdapter;
 import org.objectweb.asm.MethodVisitor;
-import org.objectweb.asm.Opcodes;
 
 class PersistentSetterVisitor extends MethodAdapter {
 
-	private String className;
+    private String className;
+    private String propertyName;
 
-	private String propertyName;
-
-	PersistentSetterVisitor(MethodVisitor mv, String className,
-			String propertyName) {
-		super(mv);
-		this.className = className;
-		this.propertyName = propertyName;
-	}
-
-	@Override
-	public void visitCode() {
-		super.visitCode();
-
-		mv.visitVarInsn(Opcodes.ALOAD, 0);
-		mv.visitFieldInsn(Opcodes.GETFIELD, className,
-				PojoAdapterFactory.PERSISTENCE_DELEGATE_FIELD,
-				"Lorg/apache/cayenne/jpa/enhancer/PersistenceDelegate;");
-		Label l1 = new Label();
-		mv.visitJumpInsn(Opcodes.IFNULL, l1);
-		mv.visitVarInsn(Opcodes.ALOAD, 0);
-		mv.visitFieldInsn(Opcodes.GETFIELD, className,
-				PojoAdapterFactory.PERSISTENCE_DELEGATE_FIELD,
-				"Lorg/apache/cayenne/jpa/enhancer/PersistenceDelegate;");
-		mv.visitLdcInsn(propertyName);
-		mv.visitMethodInsn(Opcodes.INVOKEINTERFACE,
-				"org/apache/cayenne/jpa/enhancer/PersistenceDelegate",
-				"prepareForUpdate", "(Ljava/lang/String;)V");
-		mv.visitLabel(l1);
-	}
+    PersistentSetterVisitor(MethodVisitor mv, String className, String propertyName) {
+        super(mv);
+        this.className = className;
+        this.propertyName = propertyName;
+    }
+
+    @Override
+    public void visitCode() {
+        super.visitCode();
+
+        // mv.visitVarInsn(Opcodes.ALOAD, 0);
+        // mv.visitFieldInsn(Opcodes.GETFIELD, className,
+        // PojoAdapterFactory.PERSISTENCE_DELEGATE_FIELD,
+        // "Lorg/apache/cayenne/jpa/enhancer/PersistenceDelegate;");
+        // Label l1 = new Label();
+        // mv.visitJumpInsn(Opcodes.IFNULL, l1);
+        // mv.visitVarInsn(Opcodes.ALOAD, 0);
+        // mv.visitFieldInsn(Opcodes.GETFIELD, className,
+        // PojoAdapterFactory.PERSISTENCE_DELEGATE_FIELD,
+        // "Lorg/apache/cayenne/jpa/enhancer/PersistenceDelegate;");
+        // mv.visitLdcInsn(propertyName);
+        // mv.visitMethodInsn(Opcodes.INVOKEINTERFACE,
+        // "org/apache/cayenne/jpa/enhancer/PersistenceDelegate",
+        // "prepareForUpdate", "(Ljava/lang/String;)V");
+        // mv.visitLabel(l1);
+    }
 }

Modified: incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/AsmEnhancerTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/AsmEnhancerTest.java?view=diff&rev=454581&r1=454578&r2=454581
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/AsmEnhancerTest.java
(original)
+++ incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/AsmEnhancerTest.java
Mon Oct  9 18:34:21 2006
@@ -10,76 +10,56 @@
 
 import junit.framework.TestCase;
 
-import org.apache.cayenne.enhancer.AsmEnhancer;
-import org.apache.cayenne.enhancer.PersistenceDelegate;
-import org.apache.cayenne.enhancer.PojoAdapterFactory;
-import org.apache.cayenne.property.PropertyUtils;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.ObjectId;
 
 public class AsmEnhancerTest extends TestCase {
 
-	public static final String C1 = "org.apache.cayenne.jpa.enhancer.MockPojo1";
+    public static final String C1 = "org.apache.cayenne.jpa.enhancer.MockPojo1";
 
-	protected ClassLoader loader;
+    protected ClassLoader loader;
 
-	@Override
-	protected void setUp() throws Exception {
-		Collection<String> managedClasses = new ArrayList<String>();
-		managedClasses.add(C1);
-
-		Map<String, Collection<String>> enhancedPropertyMap = new HashMap<String,
Collection<String>>();
-
-		Collection<String> c1 = new HashSet<String>();
-		c1.add("attribute1");
-		enhancedPropertyMap.put(C1, c1);
-
-		loader = new EnhancingClassLoader(new AsmEnhancer(enhancedPropertyMap));
-	}
-
-	public void testPersistenceDelegatePropertyInjected() throws Exception {
-
-		Class e1Class = Class.forName(C1, true, loader);
-		assertNotNull(e1Class);
-		assertEquals(C1, e1Class.getName());
-
-		Field f = e1Class
-				.getDeclaredField(PojoAdapterFactory.PERSISTENCE_DELEGATE_FIELD);
-		assertTrue(PersistenceDelegate.class.isAssignableFrom(f.getType()));
-		assertTrue(!Modifier.isStatic(f.getModifiers()));
-		assertTrue(Modifier.isPublic(f.getModifiers()));
-		assertTrue(!Modifier.isFinal(f.getModifiers()));
-		assertTrue(Modifier.isTransient(f.getModifiers()));
-	}
-
-	public void testGetterCallbackInjected() throws Exception {
-
-		Class e1Class = Class.forName(C1, true, loader);
-		assertNotNull(e1Class);
-		assertEquals(C1, e1Class.getName());
-
-		Object o = e1Class.newInstance();
-
-		// assert with no delegate (make sure no NPE is thrown)
-		assertNull(PropertyUtils.getProperty(o, "attribute1"));
-		PropertyUtils.setProperty(o, "attribute1", "x");
-		assertEquals("x", PropertyUtils.getProperty(o, "attribute1"));
-
-		// now test if callbacks are executed
-
-		Field f = e1Class
-				.getDeclaredField(PojoAdapterFactory.PERSISTENCE_DELEGATE_FIELD);
-
-		MockPersistenceDelegate delegate = new MockPersistenceDelegate();
-		f.set(o, delegate);
-
-		assertEquals("x", PropertyUtils.getProperty(o, "attribute1"));
-		assertEquals("attribute1", delegate.getPreparedForAccess());
-		assertNull(delegate.getPreparedForUpdate());
-
-		delegate = new MockPersistenceDelegate();
-		f.set(o, delegate);
-		PropertyUtils.setProperty(o, "attribute1", "y");
-		assertNull(delegate.getPreparedForAccess());
-		assertEquals("attribute1", delegate.getPreparedForUpdate());
-		assertEquals("y", PropertyUtils.getProperty(o, "attribute1"));
-	}
+    @Override
+    protected void setUp() throws Exception {
+        Collection<String> managedClasses = new ArrayList<String>();
+        managedClasses.add(C1);
+
+        Map<String, Collection<String>> enhancedPropertyMap = new HashMap<String,
Collection<String>>();
+
+        Collection<String> c1 = new HashSet<String>();
+        c1.add("attribute1");
+        enhancedPropertyMap.put(C1, c1);
+
+        loader = new EnhancingClassLoader(new AsmEnhancer(enhancedPropertyMap));
+    }
+
+    public void testPersistenceFieldsInjected() throws Exception {
+
+        Class e1Class = Class.forName(C1, true, loader);
+        assertNotNull(e1Class);
+        assertEquals(C1, e1Class.getName());
+
+        Field objectContext = e1Class
+                .getDeclaredField(EnhancedPojoDescriptor.OBJECT_CONTEXT_FIELD);
+        assertTrue(ObjectContext.class.isAssignableFrom(objectContext.getType()));
+        assertTrue(!Modifier.isStatic(objectContext.getModifiers()));
+        assertTrue(Modifier.isProtected(objectContext.getModifiers()));
+        assertTrue(!Modifier.isFinal(objectContext.getModifiers()));
+        assertTrue(Modifier.isTransient(objectContext.getModifiers()));
+
+        Field persistenceState = e1Class
+                .getDeclaredField(EnhancedPojoDescriptor.PERSISTENCE_STATE_FIELD);
+        assertTrue(Integer.TYPE.isAssignableFrom(persistenceState.getType()));
+        assertTrue(!Modifier.isStatic(persistenceState.getModifiers()));
+        assertTrue(Modifier.isProtected(persistenceState.getModifiers()));
+        assertTrue(!Modifier.isFinal(persistenceState.getModifiers()));
+        assertTrue(!Modifier.isTransient(persistenceState.getModifiers()));
+
+        Field objectId = e1Class.getDeclaredField(EnhancedPojoDescriptor.OBJECT_ID_FIELD);
+        assertTrue(ObjectId.class.isAssignableFrom(objectId.getType()));
+        assertTrue(!Modifier.isStatic(objectId.getModifiers()));
+        assertTrue(Modifier.isProtected(objectId.getModifiers()));
+        assertTrue(!Modifier.isFinal(objectId.getModifiers()));
+        assertTrue(!Modifier.isTransient(objectId.getModifiers()));
+    }
 }

Modified: incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java?view=diff&rev=454581&r1=454578&r2=454581
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java
(original)
+++ incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java
Mon Oct  9 18:34:21 2006
@@ -18,25 +18,63 @@
  ****************************************************************/
 package org.apache.cayenne.enhancer;
 
-import org.apache.cayenne.enhancer.PersistenceDelegate;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.Persistent;
 
-public class MockEnhancedPojo {
+public class MockEnhancedPojo implements Persistent {
 
-	public transient PersistenceDelegate $cayenne_persistenceDelegate;
+    protected ObjectId $cay_objectId;
+    protected int $cay_persistenceState = PersistenceState.TRANSIENT;
+    protected transient ObjectContext $cay_objectContext;
 
-	protected String attribute1;
+    protected String attribute1;
 
-	public String getAttribute1() {
-		if ($cayenne_persistenceDelegate != null) {
-			$cayenne_persistenceDelegate.prepareForAccess("attribute1");
-		}
-		return attribute1;
-	}
-
-	public void setAttribute1(String attribute1) {
-		if ($cayenne_persistenceDelegate != null) {
-			$cayenne_persistenceDelegate.prepareForUpdate("attribute1");
-		}
-		this.attribute1 = attribute1;
-	}
+    public String getAttribute1() {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.prepareForAccess(this, "attribute1");
+        }
+        return attribute1;
+    }
+
+    public void setAttribute1(String attribute1) {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.propertyChanged(
+                    this,
+                    "attribute1",
+                    this.attribute1,
+                    attribute1);
+        }
+
+        this.attribute1 = attribute1;
+    }
+
+    public int getPersistenceState() {
+        return $cay_persistenceState;
+    }
+
+    public void setPersistenceState(int persistenceState) {
+        this.$cay_persistenceState = persistenceState;
+
+        if (persistenceState == PersistenceState.TRANSIENT) {
+            this.$cay_objectContext = null;
+        }
+    }
+
+    public ObjectContext getObjectContext() {
+        return $cay_objectContext;
+    }
+
+    public void setObjectContext(ObjectContext objectContext) {
+        this.$cay_objectContext = objectContext;
+    }
+
+    public ObjectId getObjectId() {
+        return $cay_objectId;
+    }
+
+    public void setObjectId(ObjectId objectId) {
+        this.$cay_objectId = objectId;
+    }
 }

Added: incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockObjectContext.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockObjectContext.java?view=auto&rev=454581
==============================================================================
--- incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockObjectContext.java
(added)
+++ incubator/cayenne/sandbox/asm-enhancer/src/test/java/org/apache/cayenne/enhancer/MockObjectContext.java
Mon Oct  9 18:34:21 2006
@@ -0,0 +1,109 @@
+/*****************************************************************
+ *   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.cayenne.enhancer;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.DeleteDenyException;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.QueryResponse;
+import org.apache.cayenne.graph.GraphManager;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.Query;
+
+public class MockObjectContext implements ObjectContext {
+    
+    protected boolean preparedForAccess;
+
+    public void prepareForAccess(Persistent object, String property) {
+    }
+
+    public void propertyChanged(
+            Persistent object,
+            String property,
+            Object oldValue,
+            Object newValue) {
+    }
+
+    public void commitChanges() {
+    }
+
+    public void commitChangesToParent() {
+    }
+
+    public void deleteObject(Persistent object) throws DeleteDenyException {
+    }
+
+    public Collection deletedObjects() {
+        return null;
+    }
+
+    public DataChannel getChannel() {
+        return null;
+    }
+
+    public EntityResolver getEntityResolver() {
+        return null;
+    }
+
+    public GraphManager getGraphManager() {
+        return null;
+    }
+
+    public Persistent localObject(ObjectId id, Persistent prototype) {
+        return null;
+    }
+
+    public Collection modifiedObjects() {
+        return null;
+    }
+
+    public Persistent newObject(Class persistentClass) {
+        return null;
+    }
+
+    public Collection newObjects() {
+        return null;
+    }
+
+    public QueryResponse performGenericQuery(Query query) {
+        return null;
+    }
+
+    public List performQuery(Query query) {
+        return null;
+    }
+
+    public void registerNewObject(Persistent object) {
+    }
+
+    public void rollbackChanges() {
+    }
+
+    public void rollbackChangesLocally() {
+    }
+
+    public Collection uncommittedObjects() {
+        return null;
+    }
+}



Mime
View raw message