(no commit message)
authorAndreas Müller <a.mueller@bgbm.org>
Wed, 28 May 2008 23:40:00 +0000 (23:40 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Wed, 28 May 2008 23:40:00 +0000 (23:40 +0000)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HomotypicalGroup.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/HybridRelationship.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NameRelationship.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TaxonNameBase.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/ViralName.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java

index f5eb0dd0a20d08cd66b536ac91d92064a413a84f..d76bdacc25db73108125091466c653b33dd097dd 100644 (file)
@@ -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);     
        }
 
        
index 6764279e02ef7cd8e4e3dec03132013036ba9029..05c6d1204a0eb90be775504d1e4e4d32a4ead9ba 100644 (file)
@@ -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<BotanicalName, BotanicalName, HybridRelationshipType> {
+       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(){
index f05ed757962b288a46cb874b574c911c4d127dc7..24310125beaaf027d4d3176974e29a361011b2c2 100644 (file)
@@ -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<TaxonNameBase, TaxonNameBase, NameRelationshipType> {
        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(){
index 9cfa20a92e36fd6441b60b56563af3326523e32d..d35f18a0c0738fb61020c98f546ade23a73e955a 100644 (file)
@@ -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<T extends TaxonNameBase> extends IdentifiableEntity<TaxonNameBase> implements IReferencedEntity, IParsable {
+public abstract class TaxonNameBase<T extends TaxonNameBase> extends IdentifiableEntity<TaxonNameBase> implements IReferencedEntity, IParsable, IRelated<NameRelationship> {
        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<T extends TaxonNameBase> extends Identifiabl
        protected INameCacheStrategy<T> 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<T extends 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<T extends 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<T extends 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
index 9a5c28521378ffd1fafada0d43aa2968001e1caf..a722d6ee2ea235496650a5b833a938216b200be5 100644 (file)
@@ -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<ViralName>  {
        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
index 9cb5813b03797464c278ce335d35fbd02ca27003..5f6983ecde6516f69e24fe5a2e6e8d228e113298 100644 (file)
@@ -384,7 +384,7 @@ public class Taxon extends TaxonBase implements Iterable<Taxon>, IRelated<Relati
        public SynonymRelationship addHeterotypicSynonymName(TaxonNameBase synonymName, HomotypicalGroup homotypicalGroup){
                Synonym synonym = Synonym.NewInstance(synonymName, this.getSec());
                if (homotypicalGroup != null){
-                       synonymName.setHomotypicalGroup(homotypicalGroup);
+                       homotypicalGroup.addTypifiedName(synonymName);
                }
                return addSynonym(synonym, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
        }
@@ -399,7 +399,7 @@ public class Taxon extends TaxonBase implements Iterable<Taxon>, IRelated<Relati
        public SynonymRelationship addHomotypicSynonymName(TaxonNameBase synonymName){
                Synonym synonym = Synonym.NewInstance(synonymName, this.getSec());
                if (this.getName() != null){
-                       synonymName.setHomotypicalGroup(this.getName().getHomotypicalGroup());
+                       this.getName().getHomotypicalGroup().addTypifiedName(synonymName);
                }
                SynonymRelationship synRel = addSynonym(synonym, SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF());
                return synRel;