Revision 228c04ef
Added by Katja Luther over 12 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/SpecimenTypeDesignation.java | ||
---|---|---|
12 | 12 |
|
13 | 13 |
import javax.persistence.Entity; |
14 | 14 |
import javax.persistence.FetchType; |
15 |
import javax.persistence.JoinColumn; |
|
15 | 16 |
import javax.persistence.ManyToOne; |
16 | 17 |
import javax.persistence.Transient; |
17 | 18 |
import javax.xml.bind.annotation.XmlAccessType; |
... | ... | |
65 | 66 |
@XmlIDREF |
66 | 67 |
@XmlSchemaType(name = "IDREF") |
67 | 68 |
@ManyToOne(fetch = FetchType.LAZY) |
69 |
@JoinColumn(name="typeSpecimen_id") |
|
68 | 70 |
@Cascade(CascadeType.SAVE_UPDATE) |
69 | 71 |
private DerivedUnitBase typeSpecimen; |
70 | 72 |
|
... | ... | |
131 | 133 |
String originalNameString, boolean isNotDesignated) { |
132 | 134 |
super(citation, citationMicroReference, originalNameString, isNotDesignated); |
133 | 135 |
this.setTypeSpecimen(specimen); |
136 |
|
|
134 | 137 |
this.setTypeStatus(status); |
135 | 138 |
} |
136 | 139 |
|
... | ... | |
150 | 153 |
*/ |
151 | 154 |
public void setTypeSpecimen(DerivedUnitBase typeSpecimen){ |
152 | 155 |
this.typeSpecimen = typeSpecimen; |
156 |
typeSpecimen.addSpecimenTypeDesignation(this); |
|
153 | 157 |
} |
154 | 158 |
|
155 | 159 |
/* (non-Javadoc) |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/occurrence/DerivedUnitBase.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.cdm.model.occurrence; |
11 | 11 |
|
12 |
import java.util.HashSet; |
|
12 | 13 |
import java.util.Set; |
13 | 14 |
|
14 | 15 |
import javax.persistence.Entity; |
15 | 16 |
import javax.persistence.FetchType; |
16 | 17 |
import javax.persistence.ManyToOne; |
18 |
import javax.persistence.OneToMany; |
|
17 | 19 |
import javax.persistence.Transient; |
18 | 20 |
import javax.xml.bind.annotation.XmlAccessType; |
19 | 21 |
import javax.xml.bind.annotation.XmlAccessorType; |
20 | 22 |
import javax.xml.bind.annotation.XmlElement; |
23 |
import javax.xml.bind.annotation.XmlElementWrapper; |
|
21 | 24 |
import javax.xml.bind.annotation.XmlIDREF; |
22 | 25 |
import javax.xml.bind.annotation.XmlRootElement; |
23 | 26 |
import javax.xml.bind.annotation.XmlSchemaType; |
... | ... | |
32 | 35 |
import org.hibernate.search.annotations.IndexedEmbedded; |
33 | 36 |
import org.hibernate.validator.constraints.Length; |
34 | 37 |
|
38 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
35 | 39 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
36 | 40 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
37 | 41 |
import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty; |
... | ... | |
108 | 112 |
@Cascade(CascadeType.SAVE_UPDATE) |
109 | 113 |
@IndexedEmbedded(depth = 4) |
110 | 114 |
private DerivationEvent derivedFrom; |
115 |
|
|
116 |
@XmlElementWrapper(name = "SpecimenTypeDesignations") |
|
117 |
@XmlElement(name = "SpecimenTypeDesignation") |
|
118 |
@OneToMany(fetch = FetchType.LAZY, mappedBy = "typeSpecimen") |
|
119 |
@Cascade({ CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE }) |
|
120 |
private Set<SpecimenTypeDesignation> specimenTypeDesignations = new HashSet<SpecimenTypeDesignation>(); |
|
111 | 121 |
|
112 | 122 |
/** |
113 | 123 |
* Constructor |
... | ... | |
225 | 235 |
return storedUnder; |
226 | 236 |
} |
227 | 237 |
|
238 |
public void addSpecimenTypeDesignation(SpecimenTypeDesignation specimenTypeDesignation){ |
|
239 |
specimenTypeDesignations.add(specimenTypeDesignation); |
|
240 |
} |
|
241 |
|
|
242 |
public Set<SpecimenTypeDesignation> getSpecimenTypeDesignations(){ |
|
243 |
return specimenTypeDesignations; |
|
244 |
} |
|
245 |
|
|
228 | 246 |
//*********** CLONE **********************************/ |
229 | 247 |
|
230 | 248 |
/** |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/name/SpecimenTypeDesignationTest.java | ||
---|---|---|
15 | 15 |
import static org.junit.Assert.assertNotNull; |
16 | 16 |
import static org.junit.Assert.assertTrue; |
17 | 17 |
|
18 |
import java.util.Set; |
|
19 |
|
|
18 | 20 |
import org.apache.log4j.Logger; |
19 | 21 |
import org.junit.Before; |
20 | 22 |
import org.junit.BeforeClass; |
... | ... | |
64 | 66 |
assertEquals(term1.getTypeStatus(), SpecimenTypeDesignationStatus.EPITYPE()); |
65 | 67 |
assertTrue(term1.getTypeStatus().isInstanceOf(SpecimenTypeDesignationStatus.class)); |
66 | 68 |
} |
69 |
@Test |
|
70 |
public void testBidirectionalRelationship(){ |
|
71 |
term2 = new SpecimenTypeDesignation(Specimen.NewInstance(), SpecimenTypeDesignationStatus.ISOTYPE(), |
|
72 |
null, null, null, false);; |
|
73 |
Specimen specimen = (Specimen) term2.getTypeSpecimen(); |
|
74 |
Set<SpecimenTypeDesignation> set = specimen.getSpecimenTypeDesignations(); |
|
75 |
boolean contains = false; |
|
76 |
for (SpecimenTypeDesignation spec: set){ |
|
77 |
if (spec.equals(term2)){ |
|
78 |
contains = true; |
|
79 |
break; |
|
80 |
} |
|
81 |
} |
|
82 |
assertTrue(contains); |
|
83 |
} |
|
67 | 84 |
|
68 | 85 |
} |
Also available in: Unified diff
bidirectional relation between SpecimenTypeDesignation and DerivedUnitBase