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/15 00:08:52 UTC
svn commit: r464044 - in
/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src:
main/java/org/apache/cayenne/enhancer/ test/java/org/apache/cayenne/enhancer/
Author: aadamchik
Date: Sat Oct 14 15:08:49 2006
New Revision: 464044
URL: http://svn.apache.org/viewvc?view=rev&rev=464044
Log:
CAY-682:Generic Cayenne POJO enhancer
(enhancer would add an extra boolean field to store the state of each faulted property)
Added:
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/MockPojo2.java
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2Enhanced.java
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo3.java
Removed:
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockEnhancedPojo.java
Modified:
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/EnhancementHelper.java
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/Enhancer.java
incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/PersistentAccessorVisitor.java
Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/EnhancementHelper.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/EnhancementHelper.java?view=diff&rev=464044&r1=464043&r2=464044
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/EnhancementHelper.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/EnhancementHelper.java Sat Oct 14 15:08:49 2006
@@ -71,12 +71,34 @@
return expandedInterfaces;
}
- public void createProperty(Class type, String name) {
- createProperty(type, name, false);
+ /**
+ * Creates a new protected field in the current class. Field name will be
+ * automatically prefixed by "$cay_".
+ */
+ public void createField(Class fieldType, String name) {
+ createField(fieldType, name, false);
}
- public void createProperty(Class type, String name, boolean isTransient) {
- Type asmType = Type.getType(type);
+ /**
+ * Creates a new protected field in the current class. Field name will be
+ * automatically prefixed by "$cay_".
+ */
+ public void createField(Class fieldType, String name, boolean isTransient) {
+ Type asmType = Type.getType(fieldType);
+ int access = Opcodes.ACC_PROTECTED;
+ if (isTransient) {
+ access += Opcodes.ACC_TRANSIENT;
+ }
+
+ createField(name, asmType, access);
+ }
+
+ public void createProperty(Class propertyType, String name) {
+ createProperty(propertyType, name, false);
+ }
+
+ public void createProperty(Class propertyType, String name, boolean isTransient) {
+ Type asmType = Type.getType(propertyType);
int access = Opcodes.ACC_PROTECTED;
if (isTransient) {
Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/Enhancer.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/Enhancer.java?view=diff&rev=464044&r1=464043&r2=464044
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/Enhancer.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/main/java/org/apache/cayenne/enhancer/Enhancer.java Sat Oct 14 15:08:49 2006
@@ -29,7 +29,8 @@
import org.objectweb.asm.ClassWriter;
/**
- * An abstract ClassFileTransformer for handling class enhancement.
+ * A ClassFileTransformer that delegates class enhancement to a chain of ASM transformers
+ * provided by the {@link EnhancerVisitorFactory}.
*
* @since 3.0
* @author Andrus Adamchik
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=464044&r1=464043&r2=464044
==============================================================================
--- 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 15:08:49 2006
@@ -19,6 +19,7 @@
package org.apache.cayenne.enhancer;
import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.Relationship;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
@@ -60,6 +61,13 @@
Type propertyType) {
if (entity.getAttribute(property) != null) {
+ return new GetterVisitor(mv, helper, property);
+ }
+
+ 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);
}
Added: 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=auto&rev=464044
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1Enhanced.java (added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo1Enhanced.java Sat Oct 14 15:08:49 2006
@@ -0,0 +1,266 @@
+/*****************************************************************
+ * 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.apache.cayenne.ObjectContext;
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.Persistent;
+
+/**
+ * This class in combination with the ASM Eclipse plugin is used as a reference for
+ * building parts of the ASM enhancer. It demonstrates how a pojo should look like after
+ * the enhancement.
+ *
+ * @author Andrus Adamchik
+ */
+public class MockPojo1Enhanced implements Persistent {
+
+ protected ObjectId $cay_objectId;
+ protected int $cay_persistenceState = PersistenceState.TRANSIENT;
+ protected transient ObjectContext $cay_objectContext;
+
+ protected String attribute1;
+ protected int attribute2;
+ protected double attribute3;
+ 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) {
+ $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 getAttribute2() {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.prepareForAccess(this, "attribute2");
+ }
+ return attribute2;
+ }
+
+ public void setAttribute2(int attribute2) {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.propertyChanged(this, "attribute2", Integer
+ .valueOf(this.attribute2), Integer.valueOf(attribute2));
+ }
+
+ this.attribute2 = attribute2;
+ }
+
+ public double getAttribute3() {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.prepareForAccess(this, "attribute3");
+ }
+ return attribute3;
+ }
+
+ public void setAttribute3(double attribute3) {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.propertyChanged(this, "attribute3", Double
+ .valueOf(this.attribute3), Double.valueOf(attribute3));
+ }
+
+ this.attribute3 = attribute3;
+ }
+
+ public byte[] getByteArrayAttribute() {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.prepareForAccess(this, "attribute4");
+ }
+ return byteArrayAttribute;
+ }
+
+ public void setByteArrayAttribute(byte[] attribute4) {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.propertyChanged(
+ 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.attribute7 = attribute7;
+ }
+
+ public boolean isAttribute8() {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.prepareForAccess(this, "attribute8");
+ }
+
+ return attribute8;
+ }
+
+ public void setAttribute8(boolean attribute8) {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.propertyChanged(
+ this,
+ "attribute8",
+ this.attribute8,
+ attribute8);
+ }
+
+ this.attribute8 = attribute8;
+ }
+
+ public long getAttribute9() {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.prepareForAccess(this, "attribute9");
+ }
+
+ return attribute9;
+ }
+
+ public void setAttribute9(long attribute9) {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.propertyChanged(
+ this,
+ "attribute9",
+ this.attribute9,
+ attribute9);
+ }
+
+ this.attribute9 = attribute9;
+ }
+
+
+ public float getAttribute10() {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.prepareForAccess(this, "attribute10");
+ }
+
+ return attribute10;
+ }
+
+
+ public void setAttribute10(float attribute10) {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.propertyChanged(
+ this,
+ "attribute10",
+ this.attribute10,
+ attribute10);
+ }
+
+ this.attribute10 = attribute10;
+ }
+}
Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2.java?view=auto&rev=464044
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2.java (added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2.java Sat Oct 14 15:08:49 2006
@@ -0,0 +1,32 @@
+/*****************************************************************
+ * 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;
+
+public class MockPojo2 {
+
+ protected MockPojo3 toOne;
+
+ public MockPojo3 getToOne() {
+ return toOne;
+ }
+
+ public void setToOne(MockPojo3 toOne) {
+ this.toOne = toOne;
+ }
+}
Added: 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=auto&rev=464044
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2Enhanced.java (added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo2Enhanced.java Sat Oct 14 15:08:49 2006
@@ -0,0 +1,71 @@
+/*****************************************************************
+ * 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.apache.cayenne.ObjectContext;
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.Persistent;
+
+public class MockPojo2Enhanced implements Persistent {
+
+ protected transient boolean $cay_fault_toOne;
+
+ protected MockPojo3 toOne;
+
+ protected ObjectId $cay_objectId;
+ protected int $cay_persistenceState = PersistenceState.TRANSIENT;
+ protected transient ObjectContext $cay_objectContext;
+
+ 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 MockPojo3 getToOne() {
+ if ($cay_objectContext != null) {
+ $cay_objectContext.prepareForAccess(this, "toOne");
+ }
+
+ return toOne;
+ }
+
+ public void setToOne(MockPojo3 toOne) {
+ this.toOne = toOne;
+ }
+}
Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo3.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo3.java?view=auto&rev=464044
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo3.java (added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.5/src/test/java/org/apache/cayenne/enhancer/MockPojo3.java Sat Oct 14 15:08:49 2006
@@ -0,0 +1,34 @@
+/*****************************************************************
+ * 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.List;
+
+public class MockPojo3 {
+
+ protected List<MockPojo2> toMany;
+
+ public List<MockPojo2> getToMany() {
+ return toMany;
+ }
+
+ public void setToMany(List<MockPojo2> toMany) {
+ this.toMany = toMany;
+ }
+}