From 7ebeb288385892392cfd46fcf6cf5b88dfc75a9a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andreas=20M=C3=BCller?= Date: Wed, 28 May 2008 23:40:00 +0000 Subject: [PATCH] --- .../cdm/model/name/HomotypicalGroup.java | 6 +- .../cdm/model/name/HybridRelationship.java | 64 +++++++++++------- .../cdm/model/name/NameRelationship.java | 65 ++++++++----------- .../cdm/model/name/TaxonNameBase.java | 39 +++++------ .../etaxonomy/cdm/model/name/ViralName.java | 4 +- .../eu/etaxonomy/cdm/model/taxon/Taxon.java | 4 +- 6 files changed, 94 insertions(+), 88 deletions(-) diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HomotypicalGroup.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HomotypicalGroup.java index f5eb0dd0a2..d76bdacc25 100644 --- a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HomotypicalGroup.java +++ b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HomotypicalGroup.java @@ -62,10 +62,14 @@ public class HomotypicalGroup extends AnnotatableEntity { this.typifiedNames = typifiedNames; } public void addTypifiedName(TaxonNameBase typifiedName) { - typifiedName.setHomotypicalGroup(this); + if (typifiedName != null){ + typifiedName.setHomotypicalGroup(this); + typifiedNames.add(typifiedName); + } } public void removeTypifiedName(TaxonNameBase typifiedName) { typifiedName.setHomotypicalGroup(null); + typifiedNames.remove(typifiedName); } diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HybridRelationship.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HybridRelationship.java index 6764279e02..05c6d1204a 100644 --- a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HybridRelationship.java +++ b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HybridRelationship.java @@ -9,13 +9,9 @@ package eu.etaxonomy.cdm.model.name; - -import eu.etaxonomy.cdm.model.common.ReferencedEntityBase; +import eu.etaxonomy.cdm.model.common.RelationshipBase; +import eu.etaxonomy.cdm.model.reference.ReferenceBase; import org.apache.log4j.Logger; -import org.hibernate.annotations.Cascade; -import org.hibernate.annotations.CascadeType; - -import java.util.*; import javax.persistence.*; /** @@ -25,39 +21,57 @@ import javax.persistence.*; * @created 08-Nov-2007 13:06:26 */ @Entity -public class HybridRelationship extends ReferencedEntityBase { - static Logger logger = Logger.getLogger(HybridRelationship.class); +public class HybridRelationship extends RelationshipBase { + private static final Logger logger = Logger.getLogger(HybridRelationship.class); //The nomenclatural code rule considered. The article/note/recommendation in the code in question that is commented on in //the note property. private String ruleConsidered; - private BotanicalName parentName; - private HybridRelationshipType type; - private BotanicalName hybridName; - @ManyToOne - public HybridRelationshipType getType(){ - return this.type; - } - public void setType(HybridRelationshipType type){ - this.type = type; + //for hibernate, don't use + @Deprecated + private HybridRelationship(){ + super(); } - @ManyToOne - @Cascade({CascadeType.SAVE_UPDATE}) + + /** + * creates a relationship between 2 names and adds this relationship object to the respective name relation sets + * @param toName + * @param fromName + * @param type + * @param ruleConsidered + */ + protected HybridRelationship(BotanicalName hybridName, BotanicalName parentName, HybridRelationshipType type, String ruleConsidered) { + this(parentName, hybridName, type, null, null, ruleConsidered); + } + + /** + * Constructor that adds immediately a relationship instance to both + * Creates a relationship between 2 names and adds this relationship object to the respective name relation sets + * @param toName + * @param fromName + * @param type + * @param citation + * @param citationMicroReference + * @param ruleConsidered + */ + protected HybridRelationship(BotanicalName hybridName, BotanicalName parentName, HybridRelationshipType type, ReferenceBase citation, String citationMicroReference, String ruleConsidered) { + super(parentName, hybridName, type, citation, citationMicroReference); + this.setRuleConsidered(ruleConsidered); + } + public BotanicalName getParentName(){ - return this.parentName; + return super.getRelatedFrom(); } public void setParentName(BotanicalName parentName){ - this.parentName = parentName; + super.setRelatedFrom(parentName); } - @ManyToOne - @Cascade({CascadeType.SAVE_UPDATE}) public BotanicalName getHybridName(){ - return this.hybridName; + return super.getRelatedTo(); } public void setHybridName(BotanicalName hybridName){ - this.hybridName = hybridName; + super.setRelatedTo(hybridName); } public String getRuleConsidered(){ diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NameRelationship.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NameRelationship.java index f05ed75796..24310125be 100644 --- a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NameRelationship.java +++ b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NameRelationship.java @@ -9,17 +9,9 @@ package eu.etaxonomy.cdm.model.name; - -import eu.etaxonomy.cdm.model.common.ReferencedEntityBase; -import eu.etaxonomy.cdm.model.taxon.Synonym; -import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; -import eu.etaxonomy.cdm.model.taxon.Taxon; - +import eu.etaxonomy.cdm.model.common.RelationshipBase; +import eu.etaxonomy.cdm.model.reference.ReferenceBase; import org.apache.log4j.Logger; -import org.hibernate.annotations.Cascade; -import org.hibernate.annotations.CascadeType; - -import java.util.*; import javax.persistence.*; /** @@ -29,19 +21,19 @@ import javax.persistence.*; * @created 08-Nov-2007 13:06:37 */ @Entity -public class NameRelationship extends ReferencedEntityBase { +public class NameRelationship extends RelationshipBase { static Logger logger = Logger.getLogger(NameRelationship.class); //The nomenclatural code rule considered. The article/note/recommendation in the code in question that is commented on in //the note property. private String ruleConsidered; - private TaxonNameBase fromName; private NameRelationshipType type; - private TaxonNameBase toName; + //for hibernate, don't use + @Deprecated private NameRelationship(){ super(); } - + /** * creates a relationship between 2 names and adds this relationship object to the respective name relation sets @@ -51,39 +43,38 @@ public class NameRelationship extends ReferencedEntityBase { * @param ruleConsidered */ protected NameRelationship(TaxonNameBase toName, TaxonNameBase fromName, NameRelationshipType type, String ruleConsidered) { - super(); - setFromName(fromName); - setToName(toName); - setType(type); - setRuleConsidered(ruleConsidered); - fromName.addNameRelationship(this); - toName.addNameRelationship(this); + this(toName, fromName, type, null, null, ruleConsidered); } - @ManyToOne - @Cascade({CascadeType.SAVE_UPDATE}) + /** + * Constructor that adds immediately a relationship instance to both + * Creates a relationship between 2 names and adds this relationship object to the respective name relation sets + * @param toName + * @param fromName + * @param type + * @param citation + * @param citationMicroReference + * @param ruleConsidered + */ + protected NameRelationship(TaxonNameBase toName, TaxonNameBase fromName, NameRelationshipType type, ReferenceBase citation, String citationMicroReference, String ruleConsidered) { + super(fromName, toName, type, citation, citationMicroReference); + this.setRuleConsidered(ruleConsidered); + } + + @Transient public TaxonNameBase getFromName(){ - return this.fromName; + return super.getRelatedFrom(); } private void setFromName(TaxonNameBase fromName){ - this.fromName = fromName; - } - - @ManyToOne - public NameRelationshipType getType(){ - return this.type; - } - private void setType(NameRelationshipType type){ - this.type = type; + super.setRelatedFrom(fromName); } - @ManyToOne - @Cascade({CascadeType.SAVE_UPDATE}) + @Transient public TaxonNameBase getToName(){ - return this.toName; + return super.getRelatedTo(); } private void setToName(TaxonNameBase toName){ - this.toName = toName; + super.setRelatedTo(toName); } public String getRuleConsidered(){ diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TaxonNameBase.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TaxonNameBase.java index 9cfa20a92e..d35f18a0c0 100644 --- a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TaxonNameBase.java +++ b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TaxonNameBase.java @@ -16,9 +16,12 @@ import eu.etaxonomy.cdm.model.reference.StrictReferenceBase; import eu.etaxonomy.cdm.model.taxon.Synonym; import eu.etaxonomy.cdm.model.taxon.Taxon; import eu.etaxonomy.cdm.model.taxon.TaxonBase; +import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; import eu.etaxonomy.cdm.model.common.IParsable; +import eu.etaxonomy.cdm.model.common.IRelated; import eu.etaxonomy.cdm.model.common.IdentifiableEntity; import eu.etaxonomy.cdm.model.common.IReferencedEntity; +import eu.etaxonomy.cdm.model.common.RelationshipBase; import org.apache.log4j.Logger; @@ -50,7 +53,7 @@ import javax.persistence.*; */ @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) -public abstract class TaxonNameBase extends IdentifiableEntity implements IReferencedEntity, IParsable { +public abstract class TaxonNameBase extends IdentifiableEntity implements IReferencedEntity, IParsable, IRelated { static Logger logger = Logger.getLogger(TaxonNameBase.class); //The scientific name without author strings and year private String nameCache; @@ -77,13 +80,6 @@ public abstract class TaxonNameBase extends Identifiabl protected INameCacheStrategy cacheStrategy; static Method methodTaxonBaseSetName; - -// /** -// * Returns a TaxonNameBase instance -// * @param fullName -// */ -// abstract public static TaxonNameBase PARSED_NAME(String fullName); - // ************* CONSTRUCTORS *************/ /** * Class constructor: creates a new empty taxon name instance. @@ -320,6 +316,11 @@ public abstract class TaxonNameBase extends Identifiabl } + public void addRelationship(NameRelationship relation) { + addNameRelationship(relation); + } + + /** * Returns the set of all {@link NameRelationship name relationships} * in which this taxon name is involved as a source. @@ -544,19 +545,8 @@ public abstract class TaxonNameBase extends Identifiabl public HomotypicalGroup getHomotypicalGroup() { return homotypicalGroup; } - public void setHomotypicalGroup(HomotypicalGroup newHomotypicalGroup) { - if(this.homotypicalGroup == newHomotypicalGroup) return; - if (homotypicalGroup != null) { - homotypicalGroup.typifiedNames.remove(this); - } - if (newHomotypicalGroup!= null) { - //hack for avoiding org.hibernate.LazyInitializationException: illegal access to loading collection - if (newHomotypicalGroup.typifiedNames instanceof PersistentSet){ - // - }else{ - newHomotypicalGroup.typifiedNames.add(this); - } - } + @Deprecated //only for bidirectional and persistence use + protected void setHomotypicalGroup(HomotypicalGroup newHomotypicalGroup) { this.homotypicalGroup = newHomotypicalGroup; } @@ -679,8 +669,15 @@ public abstract class TaxonNameBase extends Identifiabl return getRank().isInfraSpecific(); } + @Transient abstract public NomenclaturalCode getNomeclaturalCode(); + + @Override + public String generateTitle() { + // TODO Auto-generated method stub + return null; + } } \ No newline at end of file diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/ViralName.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/ViralName.java index 9a5c285213..a722d6ee2e 100644 --- a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/ViralName.java +++ b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/ViralName.java @@ -12,7 +12,6 @@ package eu.etaxonomy.cdm.model.name; import org.apache.log4j.Logger; -import java.util.*; import javax.persistence.*; /** @@ -23,7 +22,7 @@ import javax.persistence.*; * @created 08-Nov-2007 13:07:02 */ @Entity -public class ViralName extends TaxonNameBase { +public class ViralName extends TaxonNameBase { static Logger logger = Logger.getLogger(ViralName.class); //The accepted acronym for the Virus, e.g. PCV for Peanut Clump Virus @@ -60,4 +59,5 @@ public class ViralName extends TaxonNameBase { public NomenclaturalCode getNomeclaturalCode(){ return NomenclaturalCode.VIRAL(); } + } \ No newline at end of file diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java index 9cb5813b03..5f6983ecde 100644 --- a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java +++ b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java @@ -384,7 +384,7 @@ public class Taxon extends TaxonBase implements Iterable, IRelated, IRelated