You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/10/13 03:21:22 UTC

svn commit: r463544 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src: main/java/org/apache/cayenne/enhancer/SetterVisitor.java test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java test/java/org/apache/cayenne/enhancer/MockPojo1.java

Author: aadamchik
Date: Thu Oct 12 18:21:21 2006
New Revision: 463544

URL: http://svn.apache.org/viewvc?view=rev&rev=463544
Log:
CAY-682: Generic Cayenne POJO enhancer
Support for all primitive setters

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/SetterVisitor.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/SetterVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/SetterVisitor.java?view=diff&rev=463544&r1=463543&r2=463544
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/SetterVisitor.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/SetterVisitor.java Thu Oct 12 18:21:21 2006
@@ -75,33 +75,7 @@
                 propertyName,
                 propertyDescriptor);
 
-        if ("I".equals(propertyDescriptor)) {
-            mv.visitMethodInsn(
-                    Opcodes.INVOKESTATIC,
-                    "java/lang/Integer",
-                    "valueOf",
-                    "(I)Ljava/lang/Integer;");
-            mv.visitVarInsn(Opcodes.ILOAD, 1);
-            mv.visitMethodInsn(
-                    Opcodes.INVOKESTATIC,
-                    "java/lang/Integer",
-                    "valueOf",
-                    "(I)Ljava/lang/Integer;");
-        }
-        else if ("D".equals(propertyDescriptor)) {
-            mv.visitMethodInsn(
-                    Opcodes.INVOKESTATIC,
-                    "java/lang/Double",
-                    "valueOf",
-                    "(D)Ljava/lang/Double;");
-            mv.visitVarInsn(Opcodes.DLOAD, 1);
-            mv.visitMethodInsn(
-                    Opcodes.INVOKESTATIC,
-                    "java/lang/Double",
-                    "valueOf",
-                    "(D)Ljava/lang/Double;");
-        }
-        else {
+        if (!visitPrimitiveConversion(propertyDescriptor)) {
             mv.visitVarInsn(Opcodes.ALOAD, 1);
         }
 
@@ -112,5 +86,120 @@
                         "propertyChanged",
                         "(Lorg/apache/cayenne/Persistent;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V");
         mv.visitLabel(l1);
+    }
+
+    protected boolean visitPrimitiveConversion(String propertyDescriptor) {
+        if (propertyDescriptor.length() != 1) {
+            return false;
+        }
+
+        switch (propertyDescriptor.charAt(0)) {
+            case 'I':
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Integer",
+                        "valueOf",
+                        "(I)Ljava/lang/Integer;");
+                mv.visitVarInsn(Opcodes.ILOAD, 1);
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Integer",
+                        "valueOf",
+                        "(I)Ljava/lang/Integer;");
+                return true;
+            case 'D':
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Double",
+                        "valueOf",
+                        "(D)Ljava/lang/Double;");
+                mv.visitVarInsn(Opcodes.DLOAD, 1);
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Double",
+                        "valueOf",
+                        "(D)Ljava/lang/Double;");
+                return true;
+            case 'F':
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Float",
+                        "valueOf",
+                        "(F)Ljava/lang/Float;");
+                mv.visitVarInsn(Opcodes.FLOAD, 1);
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Float",
+                        "valueOf",
+                        "(F)Ljava/lang/Float;");
+                return true;
+            case 'Z':
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Boolean",
+                        "valueOf",
+                        "(Z)Ljava/lang/Boolean;");
+                mv.visitVarInsn(Opcodes.ILOAD, 1);
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Boolean",
+                        "valueOf",
+                        "(Z)Ljava/lang/Boolean;");
+                return true;
+            case 'J':
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Long",
+                        "valueOf",
+                        "(J)Ljava/lang/Long;");
+                mv.visitVarInsn(Opcodes.LLOAD, 1);
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Long",
+                        "valueOf",
+                        "(J)Ljava/lang/Long;");
+                return true;
+            case 'B':
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Byte",
+                        "valueOf",
+                        "(B)Ljava/lang/Byte;");
+                mv.visitVarInsn(Opcodes.ILOAD, 1);
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Byte",
+                        "valueOf",
+                        "(B)Ljava/lang/Byte;");
+                return true;
+            case 'C':
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Character",
+                        "valueOf",
+                        "(C)Ljava/lang/Character;");
+                mv.visitVarInsn(Opcodes.ILOAD, 1);
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Character",
+                        "valueOf",
+                        "(C)Ljava/lang/Character;");
+                return true;
+            case 'S':
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Short",
+                        "valueOf",
+                        "(S)Ljava/lang/Short;");
+                mv.visitVarInsn(Opcodes.ILOAD, 1);
+                mv.visitMethodInsn(
+                        Opcodes.INVOKESTATIC,
+                        "java/lang/Short",
+                        "valueOf",
+                        "(S)Ljava/lang/Short;");
+                return true;
+            default:
+                return false;
+        }
     }
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java?view=diff&rev=463544&r1=463543&r2=463544
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java Thu Oct 12 18:21:21 2006
@@ -39,7 +39,38 @@
     protected String attribute1;
     protected int attribute2;
     protected double attribute3;
-    protected byte[] attribute4;
+    protected short attribute5;
+    protected char attribute6;
+    protected byte attribute7;
+    protected boolean attribute8;
+    protected long attribute9;
+    protected float attribute10;
+
+    protected byte[] byteArrayAttribute;
+
+    public int getPersistenceState() {
+        return $cay_persistenceState;
+    }
+
+    public void setPersistenceState(int persistenceState) {
+        this.$cay_persistenceState = persistenceState;
+    }
+
+    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;
+    }
 
     public String getAttribute1() {
         if ($cay_objectContext != null) {
@@ -69,13 +100,10 @@
 
     public void setAttribute2(int attribute2) {
         if ($cay_objectContext != null) {
-            $cay_objectContext.propertyChanged(
-                    this,
-                    "attribute2",
-                    Integer.valueOf(this.attribute2),
-                    Integer.valueOf(attribute2));
+            $cay_objectContext.propertyChanged(this, "attribute2", Integer
+                    .valueOf(this.attribute2), Integer.valueOf(attribute2));
         }
-        
+
         this.attribute2 = attribute2;
     }
 
@@ -88,56 +116,151 @@
 
     public void setAttribute3(double attribute3) {
         if ($cay_objectContext != null) {
-            $cay_objectContext.propertyChanged(
-                    this,
-                    "attribute3",
-                    Double.valueOf(this.attribute3),
-                    Double.valueOf(attribute3));
+            $cay_objectContext.propertyChanged(this, "attribute3", Double
+                    .valueOf(this.attribute3), Double.valueOf(attribute3));
         }
-        
+
         this.attribute3 = attribute3;
     }
 
-    public byte[] getAttribute4() {
+    public byte[] getByteArrayAttribute() {
         if ($cay_objectContext != null) {
             $cay_objectContext.prepareForAccess(this, "attribute4");
         }
-        return attribute4;
+        return byteArrayAttribute;
     }
 
-    public void setAttribute4(byte[] attribute4) {
+    public void setByteArrayAttribute(byte[] attribute4) {
         if ($cay_objectContext != null) {
             $cay_objectContext.propertyChanged(
                     this,
                     "attribute4",
-                    this.attribute4,
+                    this.byteArrayAttribute,
                     attribute4);
         }
+
+        this.byteArrayAttribute = attribute4;
+    }
+
+    public short getAttribute5() {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.prepareForAccess(this, "attribute5");
+        }
+
+        return attribute5;
+    }
+
+    public void setAttribute5(short attribute5) {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.propertyChanged(
+                    this,
+                    "attribute5",
+                    this.attribute5,
+                    attribute5);
+        }
+
+        this.attribute5 = attribute5;
+    }
+
+    public char getAttribute6() {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.prepareForAccess(this, "attribute6");
+        }
+
+        return attribute6;
+    }
+
+    public void setAttribute6(char attribute6) {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.propertyChanged(
+                    this,
+                    "attribute6",
+                    this.attribute6,
+                    attribute6);
+        }
+
+        this.attribute6 = attribute6;
+    }
+
+    public byte getAttribute7() {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.prepareForAccess(this, "attribute7");
+        }
+
+        return attribute7;
+    }
+
+    public void setAttribute7(byte attribute7) {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.propertyChanged(
+                    this,
+                    "attribute7",
+                    this.attribute7,
+                    attribute7);
+        }
         
-        this.attribute4 = attribute4;
+        this.attribute7 = attribute7;
     }
 
-    public int getPersistenceState() {
-        return $cay_persistenceState;
+    public boolean isAttribute8() {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.prepareForAccess(this, "attribute8");
+        }
+
+        return attribute8;
     }
 
-    public void setPersistenceState(int persistenceState) {
-        this.$cay_persistenceState = persistenceState;
+    public void setAttribute8(boolean attribute8) {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.propertyChanged(
+                    this,
+                    "attribute8",
+                    this.attribute8,
+                    attribute8);
+        }
+        
+        this.attribute8 = attribute8;
     }
 
-    public ObjectContext getObjectContext() {
-        return $cay_objectContext;
+    public long getAttribute9() {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.prepareForAccess(this, "attribute9");
+        }
+
+        return attribute9;
     }
 
-    public void setObjectContext(ObjectContext objectContext) {
-        this.$cay_objectContext = objectContext;
+    public void setAttribute9(long attribute9) {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.propertyChanged(
+                    this,
+                    "attribute9",
+                    this.attribute9,
+                    attribute9);
+        }
+        
+        this.attribute9 = attribute9;
     }
 
-    public ObjectId getObjectId() {
-        return $cay_objectId;
+    
+    public float getAttribute10() {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.prepareForAccess(this, "attribute10");
+        }
+        
+        return attribute10;
     }
 
-    public void setObjectId(ObjectId objectId) {
-        this.$cay_objectId = objectId;
+    
+    public void setAttribute10(float attribute10) {
+        if ($cay_objectContext != null) {
+            $cay_objectContext.propertyChanged(
+                    this,
+                    "attribute10",
+                    this.attribute10,
+                    attribute10);
+        }
+        
+        this.attribute10 = attribute10;
     }
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1.java?view=diff&rev=463544&r1=463543&r2=463544
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1.java Thu Oct 12 18:21:21 2006
@@ -23,7 +23,14 @@
     protected String attribute1;
     protected int attribute2;
     protected double attribute3;
-    protected byte[] attribute4;
+    protected short attribute5;
+    protected char attribute6;
+    protected byte attribute7;
+    protected boolean attribute8;
+    protected long attribute9;
+    protected float attribute10;
+
+    protected byte[] byteArrayAttribute;
 
     public String getAttribute1() {
         return attribute1;
@@ -49,11 +56,61 @@
         this.attribute3 = attribute3;
     }
 
-    public byte[] getAttribute4() {
-        return attribute4;
+    public byte[] getByteArrayAttribute() {
+        return byteArrayAttribute;
+    }
+
+    public void setByteArrayAttribute(byte[] attribute4) {
+        this.byteArrayAttribute = attribute4;
+    }
+
+    public short getAttribute5() {
+        return attribute5;
+    }
+
+    public void setAttribute5(short attribute5) {
+        this.attribute5 = attribute5;
+    }
+
+    public char getAttribute6() {
+        return attribute6;
+    }
+
+    public void setAttribute6(char attribute6) {
+        this.attribute6 = attribute6;
+    }
+
+    public byte getAttribute7() {
+        return attribute7;
+    }
+
+    public void setAttribute7(byte attribute7) {
+        this.attribute7 = attribute7;
+    }
+
+    public boolean isAttribute8() {
+        return attribute8;
+    }
+
+    public void setAttribute8(boolean attribute8) {
+        this.attribute8 = attribute8;
+    }
+
+    public long getAttribute9() {
+        return attribute9;
+    }
+
+    public void setAttribute9(long attribute9) {
+        this.attribute9 = attribute9;
+    }
+
+    
+    public float getAttribute10() {
+        return attribute10;
     }
 
-    public void setAttribute4(byte[] attribute4) {
-        this.attribute4 = attribute4;
+    
+    public void setAttribute10(float attribute10) {
+        this.attribute10 = attribute10;
     }
 }