summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Stodden2013-01-04 17:18:42 (EST)
committer Neil Hauge2013-01-04 18:13:01 (EST)
commit8c4d9c7cfac93981df5c901d5bf41aed7c2682ae (patch)
tree5074980d35e41dca0a6ed730ba00564bc4130908
parent02e14a522b0ae719369e438f745d477a75306935 (diff)
downloadwebtools.dali-8c4d9c7cfac93981df5c901d5bf41aed7c2682ae.zip
webtools.dali-8c4d9c7cfac93981df5c901d5bf41aed7c2682ae.tar.gz
webtools.dali-8c4d9c7cfac93981df5c901d5bf41aed7c2682ae.tar.bz2
388568 - add/remove methods for one to many bidi relationships.v201301082227
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java17
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.gen/templates/entities/main.java.vm5
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.gen/templates/entities/oneToManyMethods.vm16
3 files changed, 38 insertions, 0 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java
index b053bf5..dbd7358 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/src/org/eclipse/jpt/jpa/gen/internal/ORMGenCustomizer.java
@@ -546,6 +546,20 @@ public abstract class ORMGenCustomizer implements java.io.Serializable
public String propertySetter(String propertyName) {
return "set"+StringUtil.initUpper(propertyName);
}
+ /**
+ * Returns a add method name given a property name.
+ */
+ public String propertyAdd(String propertyName) {
+ String name = StringUtil.singularise(propertyName);
+ return "add"+StringUtil.initUpper(name);
+ }
+ /**
+ * Returns a remove method name given a property name.
+ */
+ public String propertyRemove(String propertyName) {
+ String name = StringUtil.singularise(propertyName);
+ return "remove"+StringUtil.initUpper(name);
+ }
public String quote(String s) {
return StringUtil.quote(s, '"');
}
@@ -561,6 +575,9 @@ public abstract class ORMGenCustomizer implements java.io.Serializable
public String convertToXmlStringLiteral(String s) {
return StringTools.convertToXmlAttributeValue(s);
}
+ public String convertToSingularisedString(String s) {
+ return StringUtil.singularise(s);
+ }
/**
* Appends an annotation member name and value to an existing annotation.
*
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/entities/main.java.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/entities/main.java.vm
index 31306f4..dc59acb 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/entities/main.java.vm
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/entities/main.java.vm
@@ -128,6 +128,11 @@ public class ${table.className} ${table.generateExtendsImplements()} {
this.${role.propertyName} = $role.propertyName;
}
+#if ($role.cardinality == "one-to-many" && $role.association.bidirectional)
+#parse("oneToManyMethods.vm")
+
+
+#end
##
#end
##
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/entities/oneToManyMethods.vm b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/entities/oneToManyMethods.vm
new file mode 100644
index 0000000..c0ba039
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.gen/templates/entities/oneToManyMethods.vm
@@ -0,0 +1,16 @@
+##included template. Generates the @OneToMany methods.
+##Assumes that the context has a "role" object representing the generated AssociationRole
+##
+ public $role.referencedTable.className $customizer.propertyAdd($role.propertyName)($role.referencedTable.className $customizer.convertToSingularisedString($role.propertyName)) {
+ $customizer.propertyGetter($role.propertyName)().add($customizer.convertToSingularisedString($role.propertyName));
+ $customizer.convertToSingularisedString($role.propertyName).$customizer.propertySetter($role.oppositeRole.propertyName)(this);
+
+ return $customizer.convertToSingularisedString($role.propertyName);
+ }
+
+ public $role.referencedTable.className $customizer.propertyRemove($role.propertyName)($role.referencedTable.className $customizer.convertToSingularisedString($role.propertyName)) {
+ $customizer.propertyGetter($role.propertyName)().remove($customizer.convertToSingularisedString($role.propertyName));
+ $customizer.convertToSingularisedString($role.propertyName).$customizer.propertySetter($role.oppositeRole.propertyName)(null);
+
+ return $customizer.convertToSingularisedString($role.propertyName);
+ } \ No newline at end of file