You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by ol...@apache.org on 2011/12/12 15:36:06 UTC
svn commit: r1213257 -
/cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm
Author: oltka
Date: Mon Dec 12 14:36:05 2011
New Revision: 1213257
URL: http://svn.apache.org/viewvc?rev=1213257&view=rev
Log:
CAY-1625 Transient objects do not work in ROP apps patch by John Huss, with some rework by aadamchik
Modified:
cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm
Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm?rev=1213257&r1=1213256&r2=1213257&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm Mon Dec 12 14:36:05 2011
@@ -47,6 +47,10 @@ $importUtils.addType(${rel.CollectionTyp
#end
#if( ${entityUtils.hasToOneDeclaredRelationships()} )
${importUtils.addType('org.apache.cayenne.ValueHolder')}##
+${importUtils.addType('org.apache.cayenne.util.PersistentObjectHolder')}##
+#end
+#if( ${entityUtils.hasToManyDeclaredRelationships()} )
+${importUtils.addType('org.apache.cayenne.util.PersistentObjectList')}##
#end
${importUtils.generate()}
@@ -107,12 +111,12 @@ public abstract class ${superClassName}
}
Object oldValue = this.${stringUtils.formatVariableName($attr.Name)};
- this.${stringUtils.formatVariableName($attr.Name)} = ${stringUtils.formatVariableName($attr.Name)};
-
// notify objectContext about simple property change
if(objectContext != null) {
- objectContext.propertyChanged(this, "${attr.Name}", oldValue, ${stringUtils.formatVariableName($attr.Name)});
+ objectContext.propertyChanged(this, "${attr.Name}", oldValue, $stringUtils.formatVariableName(${attr.Name}));
}
+
+ this.${stringUtils.formatVariableName($attr.Name)} = ${stringUtils.formatVariableName($attr.Name)};
}
#end
@@ -129,7 +133,13 @@ public abstract class ${superClassName}
#end
if(objectContext != null) {
objectContext.prepareForAccess(this, "${rel.Name}", true);
- }
+ } else if (this.$rel.Name == null) {
+#if ( ${rel.CollectionType} == "java.util.Map")
+ throw new RuntimeException("Map relationships cannot be accessed for transient objects");
+#else
+ this.$rel.Name = new PersistentObjectList(this, "${rel.Name}");
+#end
+ }
return ${rel.Name};
}
@@ -138,6 +148,8 @@ public abstract class ${superClassName}
public void addTo${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClientClassName}) object) {
if(objectContext != null) {
objectContext.prepareForAccess(this, "${rel.Name}", true);
+ } else if (this.$rel.Name == null) {
+ throw new RuntimeException("Map relationships cannot be accessed for transient objects");
}
this.${rel.Name}.put(getMapKey("${rel.Name}", object), object);
@@ -145,6 +157,8 @@ public abstract class ${superClassName}
public void removeFrom${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClientClassName}) object) {
if(objectContext != null) {
objectContext.prepareForAccess(this, "${rel.Name}", true);
+ } else if (this.$rel.Name == null) {
+ throw new RuntimeException("Map relationships cannot be accessed for transient objects");
}
this.${rel.Name}.remove(getMapKey("${rel.Name}", object));
@@ -153,14 +167,18 @@ public abstract class ${superClassName}
public void addTo${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClientClassName}) object) {
if(objectContext != null) {
objectContext.prepareForAccess(this, "${rel.Name}", true);
- }
+ } else if (this.$rel.Name == null) {
+ this.$rel.Name = new PersistentObjectList(this, "${rel.Name}");
+ }
this.${rel.Name}.add(object);
}
public void removeFrom${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClientClassName}) object) {
if(objectContext != null) {
objectContext.prepareForAccess(this, "${rel.Name}", true);
- }
+ } else if (this.$rel.Name == null) {
+ this.$rel.Name = new PersistentObjectList(this, "${rel.Name}");
+ }
this.${rel.Name}.remove(object);
}
@@ -170,7 +188,9 @@ public abstract class ${superClassName}
public $importUtils.formatJavaType(${rel.TargetEntity.ClientClassName}) get${stringUtils.capitalized($rel.Name)}() {
if(objectContext != null) {
objectContext.prepareForAccess(this, "${rel.Name}", true);
- }
+ } else if (this.$rel.Name == null) {
+ this.$rel.Name = new PersistentObjectHolder(this, "$rel.Name");
+ }
return ($importUtils.formatJavaType(${rel.TargetEntity.ClientClassName})) ${rel.Name}.getValue();
}
@@ -178,8 +198,17 @@ public abstract class ${superClassName}
public void set${stringUtils.capitalized($rel.Name)}(${importUtils.formatJavaType($rel.TargetEntity.ClientClassName)} $stringUtils.formatVariableName(${rel.Name})) {
if(objectContext != null) {
objectContext.prepareForAccess(this, "${rel.Name}", true);
+ } else if (this.$rel.Name == null) {
+ this.$rel.Name = new PersistentObjectHolder(this, "$rel.Name");
+ }
+
+ // note how we notify ObjectContext of change BEFORE the object is actually
+ // changed... this is needed to take a valid current snapshot
+ Object oldValue = this.${rel.Name}.getValueDirectly();
+ if (objectContext != null) {
+ objectContext.propertyChanged(this, "$rel.Name", oldValue, $stringUtils.formatVariableName(${rel.Name}));
}
-
+
this.${stringUtils.formatVariableName($rel.Name)}.setValue(${stringUtils.formatVariableName($rel.Name)});
}
#end