001: package org.emforge.wiki.providers.hibernateprovider;
002:
003: import java.io.InputStream;
004: import java.sql.Blob;
005: import java.sql.SQLException;
006: import java.util.Date;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010:
011: import ru.emdev.EmForge.util.BlobImpl;
012:
013: /** Hibernate mapping for wiki_att */
014: public class AttachmentDO {
015: protected final Log logger = LogFactory.getLog(getClass());
016:
017: private Integer id;
018: private String name;
019: private String filename;
020: private Integer version = -1;
021: private String author;
022: private Date lastModified;
023: private String notes;
024: private Blob data;
025: private Integer length = -1;
026:
027: public AttachmentDO() {
028: }
029:
030: public Integer getId() {
031: return this .id;
032: }
033:
034: public void setId(Integer id) {
035: this .id = id;
036: }
037:
038: public void setParentName(String name) {
039: this .name = name;
040: }
041:
042: public String getParentName() {
043: return this .name;
044: }
045:
046: public void setFilename(String filename) {
047: this .filename = filename;
048: }
049:
050: public String getFilename() {
051: return this .filename;
052: }
053:
054: public void setVersion(int version) {
055: this .version = version;
056: }
057:
058: public int getVersion() {
059: return this .version;
060: }
061:
062: public void setAuthor(String author) {
063: this .author = author;
064: }
065:
066: public String getAuthor() {
067: return this .author;
068: }
069:
070: public void setLastModified(Date last) {
071: this .lastModified = last;
072: }
073:
074: public Date getLastModified() {
075: return this .lastModified;
076: }
077:
078: public String getNotes() {
079: return this .notes;
080: }
081:
082: public void setNotes(String notes) {
083: this .notes = notes;
084: }
085:
086: public void setData(Blob data) {
087: this .data = data;
088: }
089:
090: public void setDataAsByteArray(byte[] bytes) {
091: this .data = new BlobImpl(bytes);
092: }
093:
094: public Blob getData() {
095: return this .data;
096: }
097:
098: public InputStream getDataInputStream() {
099: if (data == null) {
100: return null;
101: } else {
102: try {
103: return data.getBinaryStream();
104: } catch (SQLException ex) {
105: logger.error("Cannot get attachment data", ex);
106: return null;
107: }
108: }
109: }
110:
111: public byte[] getDataAsByteArray() {
112: if (data == null) {
113: return null;
114: } else {
115: try {
116: return data.getBytes(1L, Long.valueOf(data.length())
117: .intValue());
118: } catch (SQLException ex) {
119: logger.error("Cannot get attachment data", ex);
120: return null;
121: }
122: }
123: }
124:
125: public void setLength(int length) {
126: this .length = length;
127: }
128:
129: public int getLength() {
130: return this.length;
131: }
132: }
|