Project

General

Profile

« Previous | Next » 

Revision c6a0721d

Added by Andreas Müller almost 8 years ago

  • ID c6a0721db1da86894a25afad447639cf60cb78a0
  • Parent ed77d49a

Preliminary changes for FK problem on sourcedObj_id using common base
class #5534, later reverted due to #5743

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IdentifiableEntity.java
90 90
})
91 91
@Audited
92 92
@MappedSuperclass
93
public abstract class IdentifiableEntity<S extends IIdentifiableEntityCacheStrategy> extends AnnotatableEntity
93
public abstract class IdentifiableEntity<S extends IIdentifiableEntityCacheStrategy> extends SourceableEntity<IdentifiableSource>
94 94
        implements IIdentifiableEntity /*, ISourceable<IdentifiableSource> */ {
95 95
    private static final long serialVersionUID = -5610995424730659058L;
96 96
    private static final Logger logger = Logger.getLogger(IdentifiableEntity.class);
......
160 160
    @NotNull
161 161
    private List<Identifier> identifiers = new ArrayList<Identifier>();
162 162

  
163
    @XmlElementWrapper(name = "Sources", nillable = true)
164
    @XmlElement(name = "IdentifiableSource")
165
    @OneToMany(fetch = FetchType.LAZY, orphanRemoval=true)
166
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
167
    @Merge(MergeMode.ADD_CLONE)
168
    @NotNull
169
    private Set<IdentifiableSource> sources = new HashSet<IdentifiableSource>();
163
//    @XmlElementWrapper(name = "Sources", nillable = true)
164
//    @XmlElement(name = "IdentifiableSource")
165
//    @OneToMany(fetch = FetchType.LAZY, orphanRemoval=true)
166
//    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
167
//    @Merge(MergeMode.ADD_CLONE)
168
//    @NotNull
169
//    private Set<IdentifiableSource> sources = new HashSet<IdentifiableSource>();
170 170

  
171 171
    @XmlTransient
172 172
    @Transient
......
445 445
        this.protectedTitleCache = protectedTitleCache;
446 446
    }
447 447

  
448
    @Override
449
    public Set<IdentifiableSource> getSources() {
450
        if(sources == null) {
451
            this.sources = new HashSet<IdentifiableSource>();
452
        }
453
        return this.sources;
454
    }
455

  
456
    @Override
457
    public void addSource(IdentifiableSource source) {
458
        if (source != null){
459
            IdentifiableEntity<?> oldSourcedObj = source.getSourcedObj();
460
            if (oldSourcedObj != null && oldSourcedObj != this){
461
                oldSourcedObj.getSources().remove(source);
462
            }
463
            getSources().add(source);
464
            source.setSourcedObj(this);
465
        }
466
    }
467

  
468
    @Override
469
    public void addSources(Set<IdentifiableSource> sources) {
470
        if (sources != null){
471
        	for (IdentifiableSource source: sources){
472
	            IdentifiableEntity<?> oldSourcedObj = source.getSourcedObj();
473
	            if (oldSourcedObj != null && oldSourcedObj != this){
474
	                oldSourcedObj.getSources().remove(source);
475
	            }
476
	            getSources().add(source);
477
	            source.setSourcedObj(this);
478
        	}
479
        }
480
    }
481

  
448
//    @Override
449
//    public Set<IdentifiableSource> getSources() {
450
//        if(sources == null) {
451
//            this.sources = new HashSet<IdentifiableSource>();
452
//        }
453
//        return this.sources;
454
//    }
455
//
456
//    @Override
457
//    public void addSource(IdentifiableSource source) {
458
//        if (source != null){
459
//            IdentifiableEntity<?> oldSourcedObj = source.getSourcedObj();
460
//            if (oldSourcedObj != null && oldSourcedObj != this){
461
//                oldSourcedObj.getSources().remove(source);
462
//            }
463
//            getSources().add(source);
464
//            source.setSourcedObj(this);
465
//        }
466
//    }
467
//
468
//    @Override
469
//    public void addSources(Set<IdentifiableSource> sources) {
470
//        if (sources != null){
471
//        	for (IdentifiableSource source: sources){
472
//	            IdentifiableEntity<?> oldSourcedObj = source.getSourcedObj();
473
//	            if (oldSourcedObj != null && oldSourcedObj != this){
474
//	                oldSourcedObj.getSources().remove(source);
475
//	            }
476
//	            getSources().add(source);
477
//	            source.setSourcedObj(this);
478
//        	}
479
//        }
480
//    }
481
//
482
//    @Override
483
//    public IdentifiableSource addSource(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation) {
484
//        if (id == null && idNamespace == null && citation == null && microCitation == null){
485
//            return null;
486
//        }
487
//        IdentifiableSource source = IdentifiableSource.NewInstance(type, id, idNamespace, citation, microCitation);
488
//        addSource(source);
489
//        return source;
490
//    }
491
//
492
//
493
//    @Override
494
//    public IdentifiableSource addImportSource(String id, String idNamespace, Reference<?> citation, String microCitation) {
495
//        if (id == null && idNamespace == null && citation == null && microCitation == null){
496
//            return null;
497
//        }
498
//        IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, id, idNamespace, citation, microCitation);
499
//        addSource(source);
500
//        return source;
501
//    }
502
//
503
//
504
//    @Override
505
//    public void removeSource(IdentifiableSource source) {
506
//        getSources().remove(source);
507
//    }
508

  
509
    //
482 510
    @Override
483 511
    public void removeSources() {
484 512
       this.sources.clear();
485 513
    }
486 514

  
487 515
    @Override
488
    public IdentifiableSource addSource(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation) {
489
        if (id == null && idNamespace == null && citation == null && microCitation == null){
490
            return null;
491
        }
492
        IdentifiableSource source = IdentifiableSource.NewInstance(type, id, idNamespace, citation, microCitation);
493
        addSource(source);
494
        return source;
495
    }
496

  
497

  
498
    @Override
499
    public IdentifiableSource addImportSource(String id, String idNamespace, Reference<?> citation, String microCitation) {
500
        if (id == null && idNamespace == null && citation == null && microCitation == null){
501
            return null;
502
        }
503
        IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, id, idNamespace, citation, microCitation);
504
        addSource(source);
505
        return source;
516
    protected IdentifiableSource sourceInstance(OriginalSourceType type, String id, String idNamespace,
517
            Reference<?> citation, String microCitation) {
518
        return IdentifiableSource.NewInstance(type, id, idNamespace, citation, microCitation);
506 519
    }
507 520

  
508 521

  
509
    @Override
510
    public void removeSource(IdentifiableSource source) {
511
        getSources().remove(source);
512
    }
513

  
514 522
//******************************** TO STRING *****************************************************/
515 523

  
516
    /* (non-Javadoc)
517
     * @see eu.etaxonomy.cdm.model.common.IIdentifiableEntity#toString()
518
     */
519 524
     @Override
520 525
    public String toString() {
521 526
        String result;
......
527 532
        return result;
528 533
    }
529 534

  
530

  
531 535
    public int compareTo(IdentifiableEntity identifiableEntity) {
532 536

  
533 537
         int result = 0;
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IdentifiableSource.java
10 10

  
11 11
package eu.etaxonomy.cdm.model.common;
12 12

  
13
import javax.persistence.Column;
14 13
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
16
import javax.persistence.JoinColumn;
17
import javax.xml.bind.annotation.XmlElement;
18
import javax.xml.bind.annotation.XmlIDREF;
19
import javax.xml.bind.annotation.XmlSchemaType;
20 14
import javax.xml.bind.annotation.XmlType;
21 15

  
22 16
import org.apache.log4j.Logger;
23
import org.hibernate.annotations.Any;
24 17
import org.hibernate.envers.Audited;
25
import org.hibernate.envers.NotAudited;
26 18

  
27 19
import eu.etaxonomy.cdm.model.reference.Reference;
28 20

  
......
88 80

  
89 81
// ******************************** FIELDS ************************************/
90 82

  
91
	@XmlElement(name = "SourcedObject")
92
    @XmlIDREF
93
    @XmlSchemaType(name = "IDREF")
94
	@Any(metaDef = "CdmBase",
95
	    	 metaColumn=@Column(name = "sourcedObj_type"),
96
	    	 fetch = FetchType.LAZY,
97
	    	 optional = false)
98
	@JoinColumn(name = "sourcedObj_id")
99
	@NotAudited
100

  
101
//	@org.hibernate.annotations.AnyMetaDef(name = "OriginalSource" ,
102
//        metaType="string",
103
//        idType="integer",
104
//        metaValues={
105
//        @MetaValue(value = "eu.etaxonomy.cdm.model.common.IdentifiableEntity", targetEntity = IdentifiableEntity.class),
106
//        @MetaValue(value = "eu.etaxonomy.cdm.model.description.DescriptionElementBase", targetEntity = DescriptionElementBase.class),
107
//    })
108
	private IdentifiableEntity<?> sourcedObj;
83
//	@XmlElement(name = "SourcedObject")
84
//    @XmlIDREF
85
//    @XmlSchemaType(name = "IDREF")
86
//	@Any(metaDef = "CdmBase",
87
//	    	 metaColumn=@Column(name = "sourcedObj_type"),
88
//	    	 fetch = FetchType.LAZY,
89
//	    	 optional = true)
90
//	@JoinColumn(name = "sourcedObj_id")
91
//	@NotAudited
92
//	private IdentifiableEntity<?> sourcedObj;
109 93

  
110 94
// ****************** CONSTRUCTOR ********************************/
111 95

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/OriginalSourceBase.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
12 12

  
13 13
import javax.persistence.Column;
14 14
import javax.persistence.Entity;
15
import javax.persistence.FetchType;
15 16
import javax.persistence.Inheritance;
16 17
import javax.persistence.InheritanceType;
18
import javax.persistence.JoinColumn;
17 19
import javax.validation.constraints.NotNull;
18 20
import javax.xml.bind.annotation.XmlAccessType;
19 21
import javax.xml.bind.annotation.XmlAccessorType;
20 22
import javax.xml.bind.annotation.XmlAttribute;
21 23
import javax.xml.bind.annotation.XmlElement;
24
import javax.xml.bind.annotation.XmlIDREF;
22 25
import javax.xml.bind.annotation.XmlRootElement;
26
import javax.xml.bind.annotation.XmlSchemaType;
23 27
import javax.xml.bind.annotation.XmlType;
24 28

  
25 29
import org.apache.commons.lang.StringUtils;
26 30
import org.apache.log4j.Logger;
27

  
31
import org.hibernate.annotations.Any;
32
import org.hibernate.annotations.Cascade;
33
import org.hibernate.annotations.CascadeType;
28 34
import org.hibernate.annotations.Table;
29 35
import org.hibernate.annotations.Type;
30 36
import org.hibernate.envers.Audited;
37
import org.hibernate.envers.NotAudited;
31 38
import org.springframework.util.Assert;
32 39

  
33 40
import eu.etaxonomy.cdm.common.CdmUtils;
......
35 42
/**
36 43
 * Abstract base class for classes implementing {@link eu.etaxonomy.cdm.model.common.IOriginalSource IOriginalSource}.
37 44
 * @see eu.etaxonomy.cdm.model.common.IOriginalSource
38
 * 
45
 *
39 46
 * @author m.doering
40 47
 * @version 1.0
41 48
 * @created 08-Nov-2007 13:06:22
......
56 63
	private static final long serialVersionUID = -1972959999261181462L;
57 64
	@SuppressWarnings("unused")
58 65
	private static final Logger logger = Logger.getLogger(OriginalSourceBase.class);
59
	
66

  
60 67
	/**
61
	 * The {@link OriginalSourceType type} of this source. According to PROV the type has to be thought as 
68
	 * The {@link OriginalSourceType type} of this source. According to PROV the type has to be thought as
62 69
	 * an activity that leads from the source entity to the current entity. It is not a property of the
63 70
	 * source itself.
64 71
	 */
......
70 77
    )
71 78
	@Audited
72 79
	private OriginalSourceType type;
73
	
80

  
74 81
	//The object's ID in the source, where the alternative string comes from
75 82
	@XmlElement(name = "IdInSource")
76 83
	private String idInSource;
77
	
84

  
78 85
	@XmlElement(name = "IdNamespace")
79 86
	private String idNamespace;
80 87

  
81
//***************** CONSTRUCTOR ***********************/	
88
	@XmlElement(name = "SourcedObject")
89
    @XmlIDREF
90
    @XmlSchemaType(name = "IDREF")
91
    @Any(metaDef = "CdmBase",
92
             metaColumn=@Column(name = "sourcedObj_type"),
93
             fetch = FetchType.LAZY,
94
             optional = false)
95
    @JoinColumn(name = "sourcedObj_id")
96
	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
97
    @NotAudited
98
    protected T sourcedObj;
99

  
100
//***************** CONSTRUCTOR ***********************/
82 101

  
83 102
	//for hibernate use only
84 103
	protected OriginalSourceBase() {
85
		
104

  
86 105
	}
87
	
106

  
88 107
	/**
89 108
	 * Constructor
90
	 * @param type2 
109
	 * @param type2
91 110
	 */
92 111
	protected OriginalSourceBase(OriginalSourceType type){
93 112
		if (type == null){
......
117 136
	public void setIdNamespace(String idNamespace) {
118 137
		this.idNamespace = idNamespace;
119 138
	}
120
	
139

  
121 140

  
122 141
	@Override
123 142
	public OriginalSourceType getType() {
......
129 148
		this.type = type;
130 149
	}
131 150

  
132
	
151

  
133 152
//********************** CLONE ************************************************/
134
	 
153

  
135 154
	@Override
136 155
	public Object clone() throws CloneNotSupportedException{
137 156
		OriginalSourceBase<?> result = (OriginalSourceBase<?>)super.clone();
138
		
157

  
139 158
		//no changes to: idInSource, sourcedObj
140 159
		return result;
141 160
	}
142 161

  
143
	
162

  
144 163
//************************ toString ***************************************/
145 164
	@Override
146 165
	public String toString(){
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionElementBase.java
46 46
import org.hibernate.search.annotations.IndexedEmbedded;
47 47

  
48 48
import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
49
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
50 49
import eu.etaxonomy.cdm.model.common.DefinedTerm;
51 50
import eu.etaxonomy.cdm.model.common.IMultiLanguageTextHolder;
52 51
import eu.etaxonomy.cdm.model.common.IOriginalSource;
......
55 54
import eu.etaxonomy.cdm.model.common.LanguageString;
56 55
import eu.etaxonomy.cdm.model.common.MultilanguageText;
57 56
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
57
import eu.etaxonomy.cdm.model.common.SourceableEntity;
58 58
import eu.etaxonomy.cdm.model.common.TermVocabulary;
59 59
import eu.etaxonomy.cdm.model.common.TimePeriod;
60 60
import eu.etaxonomy.cdm.model.media.Media;
......
62 62
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
63 63
import eu.etaxonomy.cdm.model.reference.Reference;
64 64
import eu.etaxonomy.cdm.model.taxon.Taxon;
65
import eu.etaxonomy.cdm.strategy.merge.Merge;
66
import eu.etaxonomy.cdm.strategy.merge.MergeMode;
67 65

  
68 66
/**
69 67
 * The upmost (abstract) class for a piece of information) about
......
95 93
@Entity
96 94
@Audited
97 95
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
98
public abstract class DescriptionElementBase extends AnnotatableEntity implements ISourceable<DescriptionElementSource>, IModifiable, IMultiLanguageTextHolder{
96
public abstract class DescriptionElementBase
97
        extends SourceableEntity<DescriptionElementSource>
98
        implements ISourceable<DescriptionElementSource>, IModifiable, IMultiLanguageTextHolder{
99

  
99 100
    private static final long serialVersionUID = 5000910777835755905L;
100 101
    @SuppressWarnings("unused")
101 102
    private static final Logger logger = Logger.getLogger(DescriptionElementBase.class);
......
149 150
	@XmlElement(name = "TimePeriod")
150 151
    private TimePeriod timeperiod = TimePeriod.NewInstance();
151 152

  
152
    @XmlElementWrapper(name = "Sources")
153
    @XmlElement(name = "DescriptionElementSource")
154
    @OneToMany(fetch = FetchType.LAZY, orphanRemoval=true)
155
    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
156
    @Merge(MergeMode.ADD_CLONE)
157
    private Set<DescriptionElementSource> sources = new HashSet<DescriptionElementSource>();
153
//    @XmlElementWrapper(name = "Sources")
154
//    @XmlElement(name = "DescriptionElementSource")
155
//    @OneToMany(fetch = FetchType.LAZY, orphanRemoval=true)
156
//    @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
157
//    @Merge(MergeMode.ADD_CLONE)
158
//    private Set<DescriptionElementSource> sources = new HashSet<DescriptionElementSource>();
158 159

  
159 160

  
160 161

  
......
387 388
        return this.modifyingText.remove(language);
388 389
    }
389 390

  
390
    /* (non-Javadoc)
391
     * @see eu.etaxonomy.cdm.model.common.ISourceable#getSources()
392
     */
393
    @Override
394
    public Set<DescriptionElementSource> getSources() {
395
        return this.sources;
396
    }
397

  
398
    /* (non-Javadoc)
399
     * @see eu.etaxonomy.cdm.model.common.ISourceable#addSource(eu.etaxonomy.cdm.model.common.IOriginalSource)
400
     */
401
    @Override
402
    public void addSource(DescriptionElementSource source) {
403
        if (source != null){
404
            DescriptionElementBase oldSourcedObj = source.getSourcedObj();
405
            if (oldSourcedObj != null && oldSourcedObj != this){
406
                oldSourcedObj.getSources().remove(source);
407
            }
408
            this.sources.add(source);
409
            source.setSourcedObj(this);
410
        }
411
    }
412

  
413
    /* (non-Javadoc)
414
     * @see eu.etaxonomy.cdm.model.common.ISourceable#addSource(eu.etaxonomy.cdm.model.common.OriginalSourceType, java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)
415
     */
416
    @Override
417
    public DescriptionElementSource addSource(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation) {
418
        if (id == null && idNamespace == null && citation == null && microCitation == null){
419
            return null;
420
        }
421
        DescriptionElementSource source = DescriptionElementSource.NewInstance(type, id, idNamespace, citation, microCitation);
422
        addSource(source);
423
        return source;
424
    }
425
    @Override
426
    public void addSources(Set<DescriptionElementSource> sources){
427
    	for (DescriptionElementSource source:sources){
428
    		addSource(source);
429
    	}
430
    }
431

  
432

  
433
    /* (non-Javadoc)
434
     * @see eu.etaxonomy.cdm.model.common.ISourceable#addImportSource(java.lang.String, java.lang.String, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)
435
     */
436
    @Override
437
    public DescriptionElementSource addImportSource(String id, String idNamespace, Reference<?> citation, String microCitation) {
438
        if (id == null && idNamespace == null && citation == null && microCitation == null){
439
            return null;
440
        }
441
        DescriptionElementSource source = DescriptionElementSource.NewInstance(OriginalSourceType.Import, id, idNamespace, citation, microCitation);
442
        addSource(source);
443
        return source;
444
    }
445

  
391
//    @Override
392
//    public Set<DescriptionElementSource> getSources() {
393
//        return this.sources;
394
//    }
395
//
396
//    @Override
397
//    public void addSource(DescriptionElementSource source) {
398
//        if (source != null){
399
//            DescriptionElementBase oldSourcedObj = source.getSourcedObj();
400
//            if (oldSourcedObj != null && oldSourcedObj != this){
401
//                oldSourcedObj.getSources().remove(source);
402
//            }
403
//            this.sources.add(source);
404
//            source.setSourcedObj(this);
405
//        }
406
//    }
407
//
408
//    @Override
409
//    public DescriptionElementSource addSource(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation) {
410
//        if (id == null && idNamespace == null && citation == null && microCitation == null){
411
//            return null;
412
//        }
413
//        DescriptionElementSource source = DescriptionElementSource.NewInstance(type, id, idNamespace, citation, microCitation);
414
//        addSource(source);
415
//        return source;
416
//    }
417
//    @Override
418
//    public void addSources(Set<DescriptionElementSource> sources){
419
//    	for (DescriptionElementSource source:sources){
420
//    		addSource(source);
421
//    	}
422
//    }
423
//
424
//
425
//    @Override
426
//    public DescriptionElementSource addImportSource(String id, String idNamespace, Reference<?> citation, String microCitation) {
427
//        if (id == null && idNamespace == null && citation == null && microCitation == null){
428
//            return null;
429
//        }
430
//        DescriptionElementSource source = DescriptionElementSource.NewInstance(OriginalSourceType.Import, id, idNamespace, citation, microCitation);
431
//        addSource(source);
432
//        return source;
433
//    }
434
//
446 435
    /**
447 436
     * Adds a {@link IOriginalSource source} to this description element.
448 437
     * @param type the type of the source
......
453 442
     * @param nameUsedInSource the taxon name used in the source
454 443
     * @param originalNameString the name as text used in the source
455 444
     */
445
//    @Override
456 446
    public void addSource(OriginalSourceType type, String idInSource, String idNamespace, Reference citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){
457 447
        DescriptionElementSource newSource = DescriptionElementSource.NewInstance(type, idInSource, idNamespace, citation, microReference, nameUsedInSource, originalNameString);
458 448
        addSource(newSource);
459 449
    }
450
//
451
//    @Override
452
//    public void removeSource(DescriptionElementSource source) {
453
//        this.sources.remove(source);
454
//    }
455

  
456

  
460 457

  
461
    /* (non-Javadoc)
462
     * @see eu.etaxonomy.cdm.model.common.ISourceable#removeSource(eu.etaxonomy.cdm.model.common.IOriginalSource)
463
     */
464 458
    @Override
465
    public void removeSource(DescriptionElementSource source) {
466
        this.sources.remove(source);
459
    protected DescriptionElementSource sourceInstance(OriginalSourceType type, String idInSource, String idNamespace,
460
            Reference<?> citation, String microCitation) {
461
        return DescriptionElementSource.NewInstance(type, idInSource, idNamespace, citation, microCitation);
467 462
    }
468 463

  
469 464
// ******************* METHODS *************************************************************/
......
480 475
        return result;
481 476
    }
482 477

  
478

  
483 479
    public List<DefinedTerm> getModifiers(TermVocabulary voc){
484 480
        List<DefinedTerm> result = makeModifierMap().get(voc);
485 481
        if (result == null){
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionElementSource.java
10 10

  
11 11
package eu.etaxonomy.cdm.model.description;
12 12

  
13
import javax.persistence.Column;
14 13
import javax.persistence.Entity;
15 14
import javax.persistence.FetchType;
16
import javax.persistence.JoinColumn;
17 15
import javax.persistence.ManyToOne;
18 16
import javax.xml.bind.annotation.XmlElement;
19 17
import javax.xml.bind.annotation.XmlIDREF;
......
21 19
import javax.xml.bind.annotation.XmlType;
22 20

  
23 21
import org.apache.log4j.Logger;
24
import org.hibernate.annotations.Any;
25 22
import org.hibernate.annotations.Cascade;
26 23
import org.hibernate.annotations.CascadeType;
27 24
import org.hibernate.envers.Audited;
28
import org.hibernate.envers.NotAudited;
29 25

  
30 26
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
31 27
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
......
123 119

  
124 120
//TODO evtl. JoinTable http://www.programcreek.com/java-api-examples/index.php?api=org.hibernate.annotations.AnyMetaDef
125 121

  
126
	@XmlElement(name = "SourcedObject")
127
    @XmlIDREF
128
    @XmlSchemaType(name = "IDREF")
129
	@Any(metaDef = "CdmBase",
130
	    	 metaColumn=@Column(name = "sourcedObj_type"),
131
	    	 fetch = FetchType.LAZY,
132
	    	 optional = false)
133
	@JoinColumn(name = "sourcedObj_id")
134
	@ManyToOne(fetch = FetchType.LAZY)
135
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
136
	@NotAudited
137
	private DescriptionElementBase sourcedObj;
122
//	@XmlElement(name = "SourcedObject")
123
//    @XmlIDREF
124
//    @XmlSchemaType(name = "IDREF")
125
//	@Any(metaDef = "CdmBase",
126
//	    	 metaColumn=@Column(name = "sourcedObj_type"),
127
//	    	 fetch = FetchType.LAZY,
128
//	    	 optional = false)
129
//	@JoinTable(
130
//	        name = "DescriptionElementBase_OriginalSourceBase",
131
//	        joinColumns = @JoinColumn( name = "DescriptionElementBase_id" ),
132
//	        inverseJoinColumns = @JoinColumn( name = "sources_id" ) )
133
////	@JoinColumn(name = "sourcedObj_id")
134
//	@ManyToOne(fetch = FetchType.LAZY)
135
//	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
136
//	@NotAudited
137
//	private DescriptionElementBase sourcedObj;
138 138

  
139 139
	@XmlElement(name = "nameUsedInSource")
140 140
	@XmlIDREF
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/merge/DefaultMergeStrategy.java
12 12

  
13 13
import java.lang.annotation.Annotation;
14 14
import java.lang.reflect.Field;
15
import java.lang.reflect.GenericDeclaration;
16 15
import java.lang.reflect.Method;
17 16
import java.lang.reflect.ParameterizedType;
18 17
import java.lang.reflect.Type;
......
523 522
			Type[] arguments = paraType.getActualTypeArguments();
524 523

  
525 524
			if (arguments.length == 1){
526
				Class collectionClass;
525
				Class<?> collectionClass;
527 526
				if (arguments[0] instanceof Class){
528
					collectionClass = (Class)arguments[0];
527
					collectionClass = (Class<?>)arguments[0];
529 528
				}else if(arguments[0] instanceof TypeVariable/*Impl*/){
530
					TypeVariable typeVariable = (TypeVariable)arguments[0];
531
					GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
532
					collectionClass = (Class)genericDeclaration;
529
					TypeVariable<Class<?>> typeVariable = (TypeVariable<Class<?>>)arguments[0];
530

  
531
					//NEW:
532
					//TODO is index = 0 always correct or only for SourceableEntity
533
					collectionClass = (Class<?>)typeVariable.getBounds()[0];
534

  
535
//					OLD:
536
//					GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
537
//					collectionClass = (Class)genericDeclaration;
533 538
				}else{
534 539
					throw new MergeException("Collection with other types than TypeVariableImpl are not yet supported");
535 540
				}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmGenericDaoImpl.java
294 294
			makePropertyType(result, referencedClass, sessionFactory, cdmClass, elType, propertyName, true);
295 295
		}else if (propertyType.isAnyType()){
296 296
//			AnyType anyType = (AnyType)propertyType;
297
			Field field = cdmClass.getDeclaredField(propertyName);
297
			Field field = getDeclaredFieldRecursive(cdmClass, propertyName);
298 298
			Class<?> returnType = field.getType();
299 299
			if (returnType.isInterface()){
300 300
				logger.debug("There is an interface");
......
334 334

  
335 335
	}
336 336

  
337
	private boolean makeSingleProperty(Class<?> itemClass, Class<?> type, String propertyName, Class cdmClass, Set<ReferenceHolder> result,/*CdmBase item,*/ boolean isCollection){
337
	/**
338
     * @param cdmClass
339
     * @param propertyName
340
     * @return
341
     */
342
    private Field getDeclaredFieldRecursive(Class<? extends CdmBase> cdmClass, String propertyName) {
343
        for (Field field : cdmClass.getDeclaredFields()){
344
            if (field.getName().equals(propertyName)){
345
                return field;
346
            }
347
        }
348
        Class<?> superClass = cdmClass.getSuperclass();
349
        if (superClass == Object.class){
350
            throw new IllegalStateException("Field not found in class hierarchy: " + propertyName);
351
        }else{
352
            return getDeclaredFieldRecursive((Class<? extends CdmBase>)superClass, propertyName);
353
        }
354
    }
355

  
356
    private boolean makeSingleProperty(Class<?> itemClass, Class<?> type, String propertyName, Class cdmClass, Set<ReferenceHolder> result,/*CdmBase item,*/ boolean isCollection){
338 357
//			String fieldName = StringUtils.rightPad(propertyName, 30);
339 358
//			String className = StringUtils.rightPad(cdmClass.getSimpleName(), 30);
340 359
//			String returnTypeName = StringUtils.rightPad(type.getSimpleName(), 30);
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/HandlingCdmEntitiesTest.java
27 27
import eu.etaxonomy.cdm.model.agent.Team;
28 28
import eu.etaxonomy.cdm.model.common.Annotation;
29 29
import eu.etaxonomy.cdm.model.common.CdmBase;
30
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
31
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
32 30
import eu.etaxonomy.cdm.model.description.Feature;
33 31
import eu.etaxonomy.cdm.model.description.TaxonDescription;
34 32
import eu.etaxonomy.cdm.model.description.TextData;
......
377 375
        textData.setFeature(Feature.ECOLOGY());
378 376
        description.addElement(textData);
379 377

  
380
        DescriptionElementSource descriptionElementSource = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
378
//        DescriptionElementSource descriptionElementSource = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
379
//
380
//        textData.addSource(descriptionElementSource);
381 381

  
382
        textData.addSource(descriptionElementSource);
382
        textData.addAnnotation(Annotation.NewDefaultLanguageInstance("abc"));
383 383

  
384 384
        taxonService.merge(taxon);
385 385
    }
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestModelUpdate.java
34 34

  
35 35

  
36 36
	private void testSelectedDb(){
37
		DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
37
		DbSchemaValidation schema = DbSchemaValidation.CREATE;
38 38

  
39
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
39
		DatabaseTypeEnum dbType = DatabaseTypeEnum.H2;
40 40

  
41 41

  
42 42
		String database = (schema == DbSchemaValidation.VALIDATE  ? "cdm36" : "cdm40");
......
53 53
			e.printStackTrace();
54 54
		}
55 55

  
56
		CdmApplicationController appCtr = CdmApplicationController.NewInstance(dataSource,schema);
56
		try {
57
            CdmApplicationController appCtr = CdmApplicationController.NewInstance(dataSource,schema);
57 58

  
58 59
//		Classification classification = Classification.NewInstance("Me");
59 60
//		Taxon taxon = Taxon.NewInstance(null, null);
......
63 64
//		TaxonNodeAgentRelation rel = node.addAgentRelation(lastScrutiny, person);
64 65
//      appCtr.getClassificationService().save(classification);
65 66

  
66
//		appCtr.getCommonService().createFullSampleData();
67
//            BotanicalName botName = BotanicalName.NewInstance(Rank.SPECIES());
68
//            Reference ref = ReferenceFactory.newBook();
69
//            botName.addImportSource("1", "ns", ref, "detail");
70
//            appCtr.getNameService().save(botName);
67 71

  
72
            appCtr.getCommonService().createFullSampleData();
68 73

  
69 74

  
70
		appCtr.close();
71
		System.exit(0);
75

  
76
            appCtr.close();
77
        } catch (Exception e) {
78
            e.printStackTrace();
79
        }finally {
80
            System.exit(0);
81
        }
72 82
	}
73 83

  
74 84

  

Also available in: Unified diff