cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r464059 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src: main/java/org/apache/cayenne/enhancer/ test/java/org/apache/cayenne/enhancer/
Date Sat, 14 Oct 2006 23:27:37 GMT
Author: aadamchik
Date: Sat Oct 14 16:27:36 2006
New Revision: 464059

URL: http://svn.apache.org/viewvc?view=rev&rev=464059
Log:
CAY-692: Extra argument needed in ObjectContext.prepareForAccess - whether the property is
a fault or not.
(adding lazy faulting support to the enhancer)

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/GetterVisitor.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/PersistentAccessorVisitor.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/CayenneEnhancerVisitorFactoryTest.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockObjectContext.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1Enhanced.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2Enhanced.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/GetterVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/GetterVisitor.java?view=diff&rev=464059&r1=464058&r2=464059
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/GetterVisitor.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/GetterVisitor.java
Sat Oct 14 16:27:36 2006
@@ -33,12 +33,14 @@
 
     private EnhancementHelper helper;
     private String propertyName;
+    private boolean lazyFaulting;
 
-    public GetterVisitor(MethodVisitor mv, EnhancementHelper helper,
-            String propertyName) {
+    public GetterVisitor(MethodVisitor mv, EnhancementHelper helper, String propertyName,
+            boolean lazyFaulting) {
         super(mv);
         this.helper = helper;
         this.propertyName = propertyName;
+        this.lazyFaulting = lazyFaulting;
     }
 
     @Override
@@ -56,9 +58,6 @@
                 objectContextType.getDescriptor());
         Label l1 = new Label();
         mv.visitJumpInsn(Opcodes.IFNULL, l1);
-        Label l2 = new Label();
-        mv.visitLabel(l2);
-        mv.visitLineNumber(42, l2);
         mv.visitVarInsn(Opcodes.ALOAD, 0);
         mv.visitFieldInsn(
                 Opcodes.GETFIELD,
@@ -67,11 +66,12 @@
                 objectContextType.getDescriptor());
         mv.visitVarInsn(Opcodes.ALOAD, 0);
         mv.visitLdcInsn(propertyName);
+        mv.visitInsn(lazyFaulting ? Opcodes.ICONST_1 : Opcodes.ICONST_0);
         mv.visitMethodInsn(
                 Opcodes.INVOKEINTERFACE,
                 objectContextType.getInternalName(),
                 "prepareForAccess",
-                "(Lorg/apache/cayenne/Persistent;Ljava/lang/String;)V");
+                "(Lorg/apache/cayenne/Persistent;Ljava/lang/String;Z)V");
         mv.visitLabel(l1);
     }
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/PersistentAccessorVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/PersistentAccessorVisitor.java?view=diff&rev=464059&r1=464058&r2=464059
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/PersistentAccessorVisitor.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/PersistentAccessorVisitor.java
Sat Oct 14 16:27:36 2006
@@ -61,14 +61,14 @@
             Type propertyType) {
 
         if (entity.getAttribute(property) != null) {
-            return new GetterVisitor(mv, helper, property);
+            return new GetterVisitor(mv, helper, property, false);
         }
 
         Relationship r = entity.getRelationship(property);
         if (r != null && !r.isToMany()) {
             // inject fault flag field
             helper.createField(Boolean.TYPE, "faultResolved_" + property, true);
-            return new GetterVisitor(mv, helper, property);
+            return new GetterVisitor(mv, helper, property, true);
         }
 
         return mv;

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/CayenneEnhancerVisitorFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/CayenneEnhancerVisitorFactoryTest.java?view=diff&rev=464059&r1=464058&r2=464059
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/CayenneEnhancerVisitorFactoryTest.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/CayenneEnhancerVisitorFactoryTest.java
Sat Oct 14 16:27:36 2006
@@ -168,13 +168,14 @@
 
         // now call on attached object
 
-        final Object[] prepared = new Object[2];
+        final Object[] prepared = new Object[3];
         ObjectContext context = new MockObjectContext() {
 
             @Override
-            public void prepareForAccess(Persistent object, String property) {
+            public void prepareForAccess(Persistent object, String property, boolean lazyFaulting)
{
                 prepared[0] = object;
                 prepared[1] = property;
+                prepared[2] = (lazyFaulting) ? Boolean.TRUE : Boolean.FALSE;
             }
         };
 
@@ -191,6 +192,7 @@
         assertEquals(null, getAttribute1.invoke(o, (Object[]) null));
         assertSame(o, prepared[0]);
         assertEquals("attribute1", prepared[1]);
+        assertSame(Boolean.FALSE, prepared[2]);
     }
 
     public void testStringSetterIntercepted() throws Exception {
@@ -261,13 +263,14 @@
 
         // now call on attached object
 
-        final Object[] prepared = new Object[2];
+        final Object[] prepared = new Object[3];
         ObjectContext context = new MockObjectContext() {
 
             @Override
-            public void prepareForAccess(Persistent object, String property) {
+            public void prepareForAccess(Persistent object, String property, boolean lazyFaulting)
{
                 prepared[0] = object;
                 prepared[1] = property;
+                prepared[2] = (lazyFaulting) ? Boolean.TRUE : Boolean.FALSE;
             }
         };
 
@@ -284,6 +287,7 @@
         assertEquals(new Integer(0), getAttribute2.invoke(o, (Object[]) null));
         assertSame(o, prepared[0]);
         assertEquals("attribute2", prepared[1]);
+        assertSame(Boolean.FALSE, prepared[2]);
     }
 
     public void testIntSetterIntercepted() throws Exception {
@@ -352,13 +356,14 @@
 
         // now call on attached object
 
-        final Object[] prepared = new Object[2];
+        final Object[] prepared = new Object[3];
         ObjectContext context = new MockObjectContext() {
 
             @Override
-            public void prepareForAccess(Persistent object, String property) {
+            public void prepareForAccess(Persistent object, String property, boolean lazyFaulting)
{
                 prepared[0] = object;
                 prepared[1] = property;
+                prepared[2] = (lazyFaulting) ? Boolean.TRUE : Boolean.FALSE;
             }
         };
 
@@ -375,6 +380,7 @@
         assertEquals(new Double(0d), getAttribute3.invoke(o, (Object[]) null));
         assertSame(o, prepared[0]);
         assertEquals("attribute3", prepared[1]);
+        assertSame(Boolean.FALSE, prepared[2]);
     }
 
     public void testDoubleSetterIntercepted() throws Exception {

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockObjectContext.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockObjectContext.java?view=diff&rev=464059&r1=464058&r2=464059
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockObjectContext.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockObjectContext.java
Sat Oct 14 16:27:36 2006
@@ -33,6 +33,12 @@
 
 public class MockObjectContext implements ObjectContext {
 
+    public void prepareForAccess(Persistent object, String property, boolean lazyFaulting)
{
+    }
+    
+    /**
+     * @deprecated since 3.0
+     */
     public void prepareForAccess(Persistent object, String property) {
     }
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1Enhanced.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1Enhanced.java?view=diff&rev=464059&r1=464058&r2=464059
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1Enhanced.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1Enhanced.java
Sat Oct 14 16:27:36 2006
@@ -74,7 +74,7 @@
 
     public String getAttribute1() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "attribute1");
+            $cay_objectContext.prepareForAccess(this, "attribute1", false);
         }
         return attribute1;
     }
@@ -93,7 +93,7 @@
 
     public int getAttribute2() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "attribute2");
+            $cay_objectContext.prepareForAccess(this, "attribute2", false);
         }
         return attribute2;
     }
@@ -109,7 +109,7 @@
 
     public double getAttribute3() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "attribute3");
+            $cay_objectContext.prepareForAccess(this, "attribute3", false);
         }
         return attribute3;
     }
@@ -125,7 +125,7 @@
 
     public byte[] getByteArrayAttribute() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "attribute4");
+            $cay_objectContext.prepareForAccess(this, "attribute4", false);
         }
         return byteArrayAttribute;
     }
@@ -144,7 +144,7 @@
 
     public short getAttribute5() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "attribute5");
+            $cay_objectContext.prepareForAccess(this, "attribute5", false);
         }
 
         return attribute5;
@@ -164,7 +164,7 @@
 
     public char getAttribute6() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "attribute6");
+            $cay_objectContext.prepareForAccess(this, "attribute6", false);
         }
 
         return attribute6;
@@ -184,7 +184,7 @@
 
     public byte getAttribute7() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "attribute7");
+            $cay_objectContext.prepareForAccess(this, "attribute7", false);
         }
 
         return attribute7;
@@ -204,7 +204,7 @@
 
     public boolean isAttribute8() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "attribute8");
+            $cay_objectContext.prepareForAccess(this, "attribute8", false);
         }
 
         return attribute8;
@@ -224,7 +224,7 @@
 
     public long getAttribute9() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "attribute9");
+            $cay_objectContext.prepareForAccess(this, "attribute9", false);
         }
 
         return attribute9;
@@ -245,7 +245,7 @@
     
     public float getAttribute10() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "attribute10");
+            $cay_objectContext.prepareForAccess(this, "attribute10", false);
         }
         
         return attribute10;

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2Enhanced.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2Enhanced.java?view=diff&rev=464059&r1=464058&r2=464059
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2Enhanced.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2Enhanced.java
Sat Oct 14 16:27:36 2006
@@ -59,7 +59,7 @@
 
     public MockPojo3 getToOne() {
         if ($cay_objectContext != null) {
-            $cay_objectContext.prepareForAccess(this, "toOne");
+            $cay_objectContext.prepareForAccess(this, "toOne", true);
         }
 
         return toOne;



Mime
View raw message