1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.notes;
18
19 import java.io.InputStream;
20
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.FetchType;
25 import javax.persistence.Id;
26 import javax.persistence.JoinColumn;
27 import javax.persistence.ManyToOne;
28 import javax.persistence.NamedQueries;
29 import javax.persistence.NamedQuery;
30 import javax.persistence.PrePersist;
31 import javax.persistence.Table;
32 import javax.persistence.Transient;
33 import javax.persistence.Version;
34
35 import org.kuali.rice.core.jpa.annotations.Sequence;
36 import org.kuali.rice.core.util.OrmUtils;
37 import org.kuali.rice.kns.service.KNSServiceLocator;
38
39
40
41
42
43
44
45
46 @Entity
47 @Table(name="KREW_ATT_T")
48 @Sequence(name="KREW_DOC_NTE_S",property="attachmentId")
49 @NamedQueries({
50 @NamedQuery(name="Attachment.FindAttachmentById",query="select a from Attachment as a where a.attachmentId = :attachmentId")
51 })
52 public class Attachment {
53
54 @Id
55 @Column(name="ATTACHMENT_ID")
56 private Long attachmentId;
57 @Transient
58 private Long noteId;
59 @Column(name="FILE_NM")
60 private String fileName;
61 @Column(name="FILE_LOC")
62 private String fileLoc;
63 @Column(name="MIME_TYP")
64 private String mimeType;
65 @Version
66 @Column(name="VER_NBR")
67 private Integer lockVerNbr;
68 @Transient
69 private InputStream attachedObject;
70 @ManyToOne(fetch=FetchType.EAGER)
71 @JoinColumn(name="NTE_ID")
72 private Note note;
73
74 public Long getAttachmentId() {
75 return attachmentId;
76 }
77 public void setAttachmentId(Long attachmentId) {
78 this.attachmentId = attachmentId;
79 }
80 public String getFileLoc() {
81 return fileLoc;
82 }
83 public void setFileLoc(String fileLoc) {
84 this.fileLoc = fileLoc;
85 }
86 public String getFileName() {
87 return fileName;
88 }
89 public void setFileName(String fileName) {
90 this.fileName = fileName;
91 }
92 public Integer getLockVerNbr() {
93 return lockVerNbr;
94 }
95 public void setLockVerNbr(Integer lockVerNbr) {
96 this.lockVerNbr = lockVerNbr;
97 }
98 public String getMimeType() {
99 return mimeType;
100 }
101 public void setMimeType(String mimeType) {
102 this.mimeType = mimeType;
103 }
104 public Long getNoteId() {
105
106 if (noteId == null && note != null){
107 return note.getNoteId();
108 }
109 return noteId;
110 }
111 public void setNoteId(Long noteId) {
112 this.noteId = noteId;
113 }
114 public Note getNote() {
115 return note;
116 }
117 public void setNote(Note note) {
118 this.note = note;
119 }
120 public InputStream getAttachedObject() {
121 return attachedObject;
122 }
123 public void setAttachedObject(InputStream attachedObject) {
124 this.attachedObject = attachedObject;
125 }
126
127 @PrePersist
128 public void beforeInsert(){
129 OrmUtils.populateAutoIncValue(this, KNSServiceLocator.getEntityManagerFactory().createEntityManager());
130 }
131
132 }
133