package eu.etaxonomy.cdm.model.common;
-import eu.etaxonomy.cdm.model.agent.Person;
-import org.apache.log4j.Logger;
-import org.hibernate.annotations.Cascade;
-import org.hibernate.annotations.CascadeType;
-
import java.net.MalformedURLException;
import java.net.URL;
-import javax.persistence.*;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
+import org.apache.log4j.Logger;
+import org.hibernate.annotations.Any;
+import org.hibernate.annotations.Cascade;
+import org.hibernate.annotations.CascadeType;
+import org.hibernate.envers.Audited;
+import org.hibernate.envers.NotAudited;
+
+import eu.etaxonomy.cdm.model.agent.Person;
+
/**
* @author m.doering
* @version 1.0
"linkbackUrl"
})
@Entity
+@Audited
public class Annotation extends LanguageStringBase implements Cloneable {
private static final long serialVersionUID = -4484677078599520233L;
private static final Logger logger = Logger.getLogger(Annotation.class);
return new Annotation(text, lang);
}
+ public static Annotation NewInstance(String text, AnnotationType annotationType, Language lang){
+ Annotation annotation = new Annotation(text, lang);
+ annotation.setAnnotationType(annotationType);
+ return annotation;
+ }
+
/**
* Factory method. Using default language.
* @param text
return new Annotation(text, Language.DEFAULT());
}
- private Annotation(){
+ protected Annotation(){
super();
}
@XmlElement(name = "Commentator")
@XmlIDREF
@XmlSchemaType(name = "IDREF")
+ @ManyToOne(fetch = FetchType.LAZY)
+ @Cascade(CascadeType.SAVE_UPDATE)
private Person commentator;
@XmlElement(name = "AnnotatedObject")
@XmlIDREF
@XmlSchemaType(name = "IDREF")
+ @Any(metaDef = "CdmBase",
+ metaColumn=@Column(name = "annotatedObj_type"),
+ fetch = FetchType.EAGER,
+ optional = false)
+ @JoinColumn(name = "annotatedObj_id")
+ @NotAudited
private AnnotatableEntity annotatedObj;
@XmlElement(name = "AnnotationType")
@XmlIDREF
@XmlSchemaType(name = "IDREF")
- private MarkerType annotationType;
+ @ManyToOne(fetch = FetchType.LAZY)
+ private AnnotationType annotationType;
// for external annotations/comments the URL of these can be set.
// should be useful to implement trackback, pingback or linkback:
@XmlElement(name = "LinkbackURL")
private URL linkbackUrl;
- @Transient
+ /**
+ * Currently envers does not support @Any
+ * @return
+ */
public AnnotatableEntity getAnnotatedObj() {
return annotatedObj;
}
- protected void setAnnotatedObj(AnnotatableEntity newAnnotatedObj) {
- this.annotatedObj = newAnnotatedObj;
+ //TODO make not public, but TaxonTaoHibernateImpl.delete has to be changed then
+ public void setAnnotatedObj(AnnotatableEntity newAnnotatedObj) {
+ this.annotatedObj = newAnnotatedObj;
+ }
+
+ public AnnotationType getAnnotationType() {
+ return annotationType;
+ }
+
+ public void setAnnotationType(AnnotationType annotationType) {
+ this.annotationType = annotationType;
}
- @ManyToOne
- @Cascade({CascadeType.SAVE_UPDATE})
public Person getCommentator(){
return this.commentator;
}
this.commentator = commentator;
}
- @Transient
+
public URL getLinkbackUrl() {
return linkbackUrl;
}