diff options
author | Chris Stodden | 2013-01-04 22:18:42 +0000 |
---|---|---|
committer | Neil Hauge | 2013-01-04 22:18:42 +0000 |
commit | d5e101b2f6ccf6a020a5e674a24cb35df13dd78b (patch) | |
tree | 2b5df4745a383d90a3acbb27402623f2cc51d28b /jpa | |
parent | c1abd865df7280bd740775aa5d6bf882eb7fbce6 (diff) | |
download | webtools.dali-d5e101b2f6ccf6a020a5e674a24cb35df13dd78b.tar.gz webtools.dali-d5e101b2f6ccf6a020a5e674a24cb35df13dd78b.tar.xz webtools.dali-d5e101b2f6ccf6a020a5e674a24cb35df13dd78b.zip |
388568 - add/remove methods for one to many bidi relationships.
Diffstat (limited to 'jpa')
3 files changed, 38 insertions, 1 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 cb76bdd3a8..85cdb36c22 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 @@ -26,7 +26,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.jpa.core.prefs.JpaEntityGenPreferencesManager; import org.eclipse.jpt.jpa.db.Column; import org.eclipse.jpt.jpa.db.Schema; import org.eclipse.jpt.jpa.db.Table; @@ -552,6 +551,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, '"'); } @@ -567,6 +580,9 @@ public abstract class ORMGenCustomizer implements java.io.Serializable public String convertToXmlStringLiteral(String s) { return StringTools.convertToXmlStringLiteral(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 |