Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 b053bf5087..dbd7358c96 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 31306f4969..dc59acbe90 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 0000000000..c0ba0396ec
--- /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

Back to the top