001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * Created on Jan 17, 2005 4:36:30 PM
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.dao.generic;
044:
045: import java.sql.PreparedStatement;
046: import java.sql.ResultSet;
047: import java.sql.SQLException;
048: import java.sql.Timestamp;
049: import java.util.ArrayList;
050: import java.util.Date;
051: import java.util.HashMap;
052: import java.util.List;
053: import java.util.Map;
054:
055: import net.jforum.JForumExecutionContext;
056: import net.jforum.entities.Attachment;
057: import net.jforum.entities.AttachmentExtension;
058: import net.jforum.entities.AttachmentExtensionGroup;
059: import net.jforum.entities.AttachmentInfo;
060: import net.jforum.entities.QuotaLimit;
061: import net.jforum.exceptions.DatabaseException;
062: import net.jforum.util.DbUtils;
063: import net.jforum.util.preferences.ConfigKeys;
064: import net.jforum.util.preferences.SystemGlobals;
065:
066: /**
067: * @author Rafael Steil
068: * @version $Id: GenericAttachmentDAO.java,v 1.11 2006/08/23 02:13:41 rafaelsteil Exp $
069: */
070: public class GenericAttachmentDAO extends AutoKeys implements
071: net.jforum.dao.AttachmentDAO {
072: /**
073: * @see net.jforum.dao.AttachmentDAO#addQuotaLimit(net.jforum.entities.QuotaLimit)
074: */
075: public void addQuotaLimit(QuotaLimit limit) {
076: PreparedStatement p = null;
077: try {
078: p = JForumExecutionContext
079: .getConnection()
080: .prepareStatement(
081: SystemGlobals
082: .getSql("AttachmentModel.addQuotaLimit"));
083: p.setString(1, limit.getDescription());
084: p.setInt(2, limit.getSize());
085: p.setInt(3, limit.getType());
086: p.executeUpdate();
087: } catch (SQLException e) {
088: throw new DatabaseException(e);
089: } finally {
090: DbUtils.close(p);
091: }
092: }
093:
094: /**
095: * @see net.jforum.dao.AttachmentDAO#updateQuotaLimit(net.jforum.entities.QuotaLimit)
096: */
097: public void updateQuotaLimit(QuotaLimit limit) {
098: PreparedStatement p = null;
099: try {
100: p = JForumExecutionContext
101: .getConnection()
102: .prepareStatement(
103: SystemGlobals
104: .getSql("AttachmentModel.updateQuotaLimit"));
105: p.setString(1, limit.getDescription());
106: p.setInt(2, limit.getSize());
107: p.setInt(3, limit.getType());
108: p.setInt(4, limit.getId());
109: p.executeUpdate();
110: } catch (SQLException e) {
111: throw new DatabaseException(e);
112: } finally {
113: DbUtils.close(p);
114: }
115: }
116:
117: /**
118: * @see net.jforum.dao.AttachmentDAO#cleanGroupQuota()
119: */
120: public void cleanGroupQuota() {
121: PreparedStatement p = null;
122: try {
123: p = JForumExecutionContext
124: .getConnection()
125: .prepareStatement(
126: SystemGlobals
127: .getSql("AttachmentModel.deleteGroupQuota"));
128: p.executeUpdate();
129: } catch (SQLException e) {
130: throw new DatabaseException(e);
131: } finally {
132: DbUtils.close(p);
133: }
134: }
135:
136: /**
137: * @see net.jforum.dao.AttachmentDAO#setGroupQuota(int, int)
138: */
139: public void setGroupQuota(int groupId, int quotaId) {
140: PreparedStatement p = null;
141: try {
142: p = JForumExecutionContext
143: .getConnection()
144: .prepareStatement(
145: SystemGlobals
146: .getSql("AttachmentModel.setGroupQuota"));
147: p.setInt(1, groupId);
148: p.setInt(2, quotaId);
149: p.executeUpdate();
150: } catch (SQLException e) {
151: throw new DatabaseException(e);
152: } finally {
153: DbUtils.close(p);
154: }
155: }
156:
157: /**
158: * @see net.jforum.dao.AttachmentDAO#removeQuotaLimit(int)
159: */
160: public void removeQuotaLimit(int id) {
161: this .removeQuotaLimit(new String[] { Integer.toString(id) });
162: }
163:
164: /**
165: * @see net.jforum.dao.AttachmentDAO#removeQuotaLimit(java.lang.String[])
166: */
167: public void removeQuotaLimit(String[] ids) {
168: PreparedStatement p = null;
169: try {
170: p = JForumExecutionContext
171: .getConnection()
172: .prepareStatement(
173: SystemGlobals
174: .getSql("AttachmentModel.removeQuotaLimit"));
175:
176: for (int i = 0; i < ids.length; i++) {
177: p.setInt(1, Integer.parseInt(ids[i]));
178: p.executeUpdate();
179: }
180: } catch (SQLException e) {
181: throw new DatabaseException(e);
182: } finally {
183: DbUtils.close(p);
184: }
185: }
186:
187: /**
188: * @see net.jforum.dao.AttachmentDAO#selectQuotaLimit()
189: */
190: public List selectQuotaLimit() {
191: List l = new ArrayList();
192: PreparedStatement p = null;
193: ResultSet rs = null;
194: try {
195: p = JForumExecutionContext
196: .getConnection()
197: .prepareStatement(
198: SystemGlobals
199: .getSql("AttachmentModel.selectQuotaLimit"));
200:
201: rs = p.executeQuery();
202: while (rs.next()) {
203: l.add(this .getQuotaLimit(rs));
204: }
205:
206: return l;
207: } catch (SQLException e) {
208: throw new DatabaseException(e);
209: } finally {
210: DbUtils.close(rs, p);
211: }
212: }
213:
214: /**
215: * @see net.jforum.dao.AttachmentDAO#selectQuotaLimit()
216: */
217: public QuotaLimit selectQuotaLimitByGroup(int groupId) {
218: QuotaLimit ql = null;
219:
220: PreparedStatement p = null;
221: ResultSet rs = null;
222: try {
223: p = JForumExecutionContext
224: .getConnection()
225: .prepareStatement(
226: SystemGlobals
227: .getSql("AttachmentModel.selectQuotaLimitByGroup"));
228: p.setInt(1, groupId);
229:
230: rs = p.executeQuery();
231: if (rs.next()) {
232: ql = this .getQuotaLimit(rs);
233: }
234: return ql;
235: } catch (SQLException e) {
236: throw new DatabaseException(e);
237: } finally {
238: DbUtils.close(rs, p);
239: }
240: }
241:
242: /**
243: * @see net.jforum.dao.AttachmentDAO#selectGroupsQuotaLimits()
244: */
245: public Map selectGroupsQuotaLimits() {
246: Map m = new HashMap();
247: PreparedStatement p = null;
248: ResultSet rs = null;
249: try {
250: p = JForumExecutionContext
251: .getConnection()
252: .prepareStatement(
253: SystemGlobals
254: .getSql("AttachmentModel.selectGroupsQuotaLimits"));
255:
256: rs = p.executeQuery();
257: while (rs.next()) {
258: m.put(new Integer(rs.getInt("group_id")), new Integer(
259: rs.getInt("quota_limit_id")));
260: }
261:
262: return m;
263: } catch (SQLException e) {
264: throw new DatabaseException(e);
265: } finally {
266: DbUtils.close(rs, p);
267: }
268: }
269:
270: protected QuotaLimit getQuotaLimit(ResultSet rs)
271: throws SQLException {
272: QuotaLimit ql = new QuotaLimit();
273: ql.setDescription(rs.getString("quota_desc"));
274: ql.setId(rs.getInt("quota_limit_id"));
275: ql.setSize(rs.getInt("quota_limit"));
276: ql.setType(rs.getInt("quota_type"));
277:
278: return ql;
279: }
280:
281: /**
282: * @see net.jforum.dao.AttachmentDAO#addExtensionGroup(net.jforum.entities.AttachmentExtensionGroup)
283: */
284: public void addExtensionGroup(AttachmentExtensionGroup g) {
285: PreparedStatement p = null;
286: try {
287: p = JForumExecutionContext
288: .getConnection()
289: .prepareStatement(
290: SystemGlobals
291: .getSql("AttachmentModel.addExtensionGroup"));
292: p.setString(1, g.getName());
293: p.setInt(2, g.isAllow() ? 1 : 0);
294: p.setString(3, g.getUploadIcon());
295: p.setInt(4, g.getDownloadMode());
296: p.executeUpdate();
297: } catch (SQLException e) {
298: throw new DatabaseException(e);
299: } finally {
300: DbUtils.close(p);
301: }
302: }
303:
304: /**
305: * @see net.jforum.dao.AttachmentDAO#removeExtensionGroups(java.lang.String[])
306: */
307: public void removeExtensionGroups(String[] ids) {
308: PreparedStatement p = null;
309: try {
310: p = JForumExecutionContext
311: .getConnection()
312: .prepareStatement(
313: SystemGlobals
314: .getSql("AttachmentModel.removeExtensionGroups"));
315:
316: for (int i = 0; i < ids.length; i++) {
317: p.setInt(1, Integer.parseInt(ids[i]));
318: p.executeUpdate();
319: }
320: } catch (SQLException e) {
321: throw new DatabaseException(e);
322: } finally {
323: DbUtils.close(p);
324: }
325: }
326:
327: /**
328: * @see net.jforum.dao.AttachmentDAO#selectExtensionGroups()
329: */
330: public List selectExtensionGroups() {
331: List l = new ArrayList();
332:
333: PreparedStatement p = null;
334: ResultSet rs = null;
335: try {
336: p = JForumExecutionContext
337: .getConnection()
338: .prepareStatement(
339: SystemGlobals
340: .getSql("AttachmentModel.selectExtensionGroups"));
341:
342: rs = p.executeQuery();
343: while (rs.next()) {
344: l.add(this .getExtensionGroup(rs));
345: }
346:
347: return l;
348: } catch (SQLException e) {
349: throw new DatabaseException(e);
350: } finally {
351: DbUtils.close(rs, p);
352: }
353: }
354:
355: /**
356: * @see net.jforum.dao.AttachmentDAO#extensionsForSecurity()
357: */
358: public Map extensionsForSecurity() {
359: Map m = new HashMap();
360:
361: PreparedStatement p = null;
362: ResultSet rs = null;
363: try {
364: p = JForumExecutionContext
365: .getConnection()
366: .prepareStatement(
367: SystemGlobals
368: .getSql("AttachmentModel.extensionsForSecurity"));
369:
370: rs = p.executeQuery();
371: while (rs.next()) {
372: int allow = rs.getInt("group_allow");
373: if (allow == 1) {
374: allow = rs.getInt("allow");
375: }
376:
377: m.put(rs.getString("extension"), Boolean
378: .valueOf(allow == 1));
379: }
380:
381: return m;
382: } catch (SQLException e) {
383: throw new DatabaseException(e);
384: } finally {
385: DbUtils.close(rs, p);
386: }
387: }
388:
389: /**
390: * @see net.jforum.dao.AttachmentDAO#updateExtensionGroup(net.jforum.entities.AttachmentExtensionGroup)
391: */
392: public void updateExtensionGroup(AttachmentExtensionGroup g) {
393: PreparedStatement p = null;
394: try {
395: p = JForumExecutionContext
396: .getConnection()
397: .prepareStatement(
398: SystemGlobals
399: .getSql("AttachmentModel.updateExtensionGroups"));
400: p.setString(1, g.getName());
401: p.setInt(2, g.isAllow() ? 1 : 0);
402: p.setString(3, g.getUploadIcon());
403: p.setInt(4, g.getDownloadMode());
404: p.setInt(5, g.getId());
405: p.executeUpdate();
406: } catch (SQLException e) {
407: throw new DatabaseException(e);
408: } finally {
409: DbUtils.close(p);
410: }
411: }
412:
413: protected AttachmentExtensionGroup getExtensionGroup(ResultSet rs)
414: throws SQLException {
415: AttachmentExtensionGroup g = new AttachmentExtensionGroup();
416: g.setId(rs.getInt("extension_group_id"));
417: g.setName(rs.getString("name"));
418: g.setUploadIcon(rs.getString("upload_icon"));
419: g.setAllow(rs.getInt("allow") == 1);
420: g.setDownloadMode(rs.getInt("download_mode"));
421:
422: return g;
423: }
424:
425: /**
426: * @see net.jforum.dao.AttachmentDAO#addExtension(net.jforum.entities.AttachmentExtension)
427: */
428: public void addExtension(AttachmentExtension extension) {
429: PreparedStatement p = null;
430: try {
431: p = JForumExecutionContext
432: .getConnection()
433: .prepareStatement(
434: SystemGlobals
435: .getSql("AttachmentModel.addExtension"));
436: p.setInt(1, extension.getExtensionGroupId());
437: p.setString(2, extension.getComment());
438: p.setString(3, extension.getUploadIcon());
439: p.setString(4, extension.getExtension().toLowerCase());
440: p.setInt(5, extension.isAllow() ? 1 : 0);
441: p.executeUpdate();
442: } catch (SQLException ex) {
443: throw new DatabaseException(ex);
444: } finally {
445: DbUtils.close(p);
446: }
447: }
448:
449: /**
450: * @see net.jforum.dao.AttachmentDAO#removeExtensions(java.lang.String[])
451: */
452: public void removeExtensions(String[] ids) {
453: PreparedStatement p = null;
454: try {
455: p = JForumExecutionContext
456: .getConnection()
457: .prepareStatement(
458: SystemGlobals
459: .getSql("AttachmentModel.removeExtension"));
460: for (int i = 0; i < ids.length; i++) {
461: p.setInt(1, Integer.parseInt(ids[i]));
462: p.executeUpdate();
463: }
464: } catch (SQLException e) {
465: throw new DatabaseException(e);
466: } finally {
467: DbUtils.close(p);
468: }
469: }
470:
471: /**
472: * @see net.jforum.dao.AttachmentDAO#selectExtensions()
473: */
474: public List selectExtensions() {
475: List l = new ArrayList();
476:
477: PreparedStatement p = null;
478: ResultSet rs = null;
479: try {
480: p = JForumExecutionContext
481: .getConnection()
482: .prepareStatement(
483: SystemGlobals
484: .getSql("AttachmentModel.selectExtensions"));
485:
486: rs = p.executeQuery();
487: while (rs.next()) {
488: l.add(this .getExtension(rs));
489: }
490:
491: return l;
492: } catch (SQLException e) {
493: throw new DatabaseException(e);
494: } finally {
495: DbUtils.close(rs, p);
496: }
497: }
498:
499: /**
500: * @see net.jforum.dao.AttachmentDAO#updateExtension(net.jforum.entities.AttachmentExtension)
501: */
502: public void updateExtension(AttachmentExtension extension) {
503: PreparedStatement p = null;
504: try {
505: p = JForumExecutionContext
506: .getConnection()
507: .prepareStatement(
508: SystemGlobals
509: .getSql("AttachmentModel.updateExtension"));
510: p.setInt(1, extension.getExtensionGroupId());
511: p.setString(2, extension.getComment());
512: p.setString(3, extension.getUploadIcon());
513: p.setString(4, extension.getExtension().toLowerCase());
514: p.setInt(5, extension.isAllow() ? 1 : 0);
515: p.setInt(6, extension.getId());
516: p.executeUpdate();
517: } catch (SQLException e) {
518: throw new DatabaseException(e);
519: } finally {
520: DbUtils.close(p);
521: }
522: }
523:
524: /**
525: * @see net.jforum.dao.AttachmentDAO#selectExtension(java.lang.String)
526: */
527: public AttachmentExtension selectExtension(String extension) {
528: return this .searchExtension(SystemGlobals
529: .getValue(ConfigKeys.EXTENSION_FIELD), extension);
530: }
531:
532: private AttachmentExtension selectExtension(int extensionId) {
533: return this .searchExtension("extension_id", new Integer(
534: extensionId));
535: }
536:
537: private AttachmentExtension searchExtension(String paramName,
538: Object paramValue) {
539: PreparedStatement p = null;
540: ResultSet rs = null;
541: try {
542: String sql = SystemGlobals
543: .getSql("AttachmentModel.selectExtension");
544: sql = sql.replaceAll("\\$field", paramName);
545:
546: p = JForumExecutionContext.getConnection()
547: .prepareStatement(sql);
548: p.setObject(1, paramValue);
549:
550: AttachmentExtension e = new AttachmentExtension();
551:
552: rs = p.executeQuery();
553: if (rs.next()) {
554: e = this .getExtension(rs);
555: } else {
556: e.setUnknown(true);
557: }
558:
559: return e;
560: } catch (SQLException e) {
561: throw new DatabaseException(e);
562: } finally {
563: DbUtils.close(rs, p);
564: }
565: }
566:
567: protected AttachmentExtension getExtension(ResultSet rs)
568: throws SQLException {
569: AttachmentExtension e = new AttachmentExtension();
570: e.setAllow(rs.getInt("allow") == 1);
571: e.setComment(rs.getString("description"));
572: e.setExtension(rs.getString("extension"));
573: e.setExtensionGroupId(rs.getInt("extension_group_id"));
574: e.setId(rs.getInt("extension_id"));
575:
576: String icon = rs.getString("upload_icon");
577: if (icon == null || icon.equals("")) {
578: icon = rs.getString("group_icon");
579: }
580:
581: e.setUploadIcon(icon);
582:
583: return e;
584: }
585:
586: /**
587: * @see net.jforum.dao.AttachmentDAO#addAttachment(net.jforum.entities.Attachment)
588: */
589: public void addAttachment(Attachment a) {
590: PreparedStatement p = null;
591: try {
592: p = this
593: .getStatementForAutoKeys("AttachmentModel.addAttachment");
594: p.setInt(1, a.getPostId());
595: p.setInt(2, a.getPrivmsgsId());
596: p.setInt(3, a.getUserId());
597:
598: this
599: .setAutoGeneratedKeysQuery(SystemGlobals
600: .getSql("AttachmentModel.lastGeneratedAttachmentId"));
601: int id = this .executeAutoKeysQuery(p);
602: p.close();
603: p = null;
604:
605: p = JForumExecutionContext
606: .getConnection()
607: .prepareStatement(
608: SystemGlobals
609: .getSql("AttachmentModel.addAttachmentInfo"));
610: p.setInt(1, id);
611: p.setString(2, a.getInfo().getPhysicalFilename());
612: p.setString(3, a.getInfo().getRealFilename());
613: p.setString(4, a.getInfo().getComment());
614: p.setString(5, a.getInfo().getMimetype());
615: p.setLong(6, a.getInfo().getFilesize());
616: p.setTimestamp(7, new Timestamp(a.getInfo()
617: .getUploadTimeInMillis()));
618: p.setInt(8, 0);
619: p.setInt(9, a.getInfo().getExtension().getId());
620: p.executeUpdate();
621:
622: this .updatePost(a.getPostId(), 1);
623: } catch (SQLException e) {
624: throw new DatabaseException(e);
625: } finally {
626: DbUtils.close(p);
627: }
628: }
629:
630: protected void updatePost(int postId, int count) {
631: PreparedStatement p = null;
632: try {
633: p = JForumExecutionContext
634: .getConnection()
635: .prepareStatement(
636: SystemGlobals
637: .getSql("AttachmentModel.updatePost"));
638: p.setInt(1, count);
639: p.setInt(2, postId);
640: p.executeUpdate();
641: } catch (SQLException e) {
642: throw new DatabaseException(e);
643: } finally {
644: DbUtils.close(p);
645: }
646: }
647:
648: /**
649: * @see net.jforum.dao.AttachmentDAO#removeAttachment(int, int)
650: */
651: public void removeAttachment(int id, int postId) {
652: PreparedStatement p = null;
653: ResultSet rs = null;
654: try {
655: p = JForumExecutionContext
656: .getConnection()
657: .prepareStatement(
658: SystemGlobals
659: .getSql("AttachmentModel.removeAttachmentInfo"));
660: p.setInt(1, id);
661: p.executeUpdate();
662: p.close();
663: p = null;
664:
665: p = JForumExecutionContext
666: .getConnection()
667: .prepareStatement(
668: SystemGlobals
669: .getSql("AttachmentModel.removeAttachment"));
670: p.setInt(1, id);
671: p.executeUpdate();
672: p.close();
673: p = null;
674:
675: p = JForumExecutionContext
676: .getConnection()
677: .prepareStatement(
678: SystemGlobals
679: .getSql("AttachmentModel.countPostAttachments"));
680: p.setInt(1, postId);
681:
682: rs = p.executeQuery();
683: if (rs.next()) {
684: this .updatePost(postId, rs.getInt(1));
685: }
686: } catch (SQLException e) {
687: throw new DatabaseException(e);
688: } finally {
689: DbUtils.close(rs, p);
690: }
691: }
692:
693: /**
694: * @see net.jforum.dao.AttachmentDAO#updateAttachment(net.jforum.entities.Attachment)
695: */
696: public void updateAttachment(Attachment a) {
697: PreparedStatement p = null;
698: try {
699: p = JForumExecutionContext
700: .getConnection()
701: .prepareStatement(
702: SystemGlobals
703: .getSql("AttachmentModel.updateAttachment"));
704: p.setString(1, a.getInfo().getComment());
705: p.setInt(2, a.getInfo().getDownloadCount());
706: p.setInt(3, a.getId());
707: p.executeUpdate();
708: } catch (SQLException e) {
709: throw new DatabaseException(e);
710: } finally {
711: DbUtils.close(p);
712: }
713: }
714:
715: /**
716: * @see net.jforum.dao.AttachmentDAO#selectAttachments(int)
717: */
718: public List selectAttachments(int postId) {
719: List l = new ArrayList();
720:
721: PreparedStatement p = null;
722: ResultSet rs = null;
723: try {
724: p = JForumExecutionContext
725: .getConnection()
726: .prepareStatement(
727: SystemGlobals
728: .getSql("AttachmentModel.selectAttachments"));
729: p.setInt(1, postId);
730:
731: rs = p.executeQuery();
732: while (rs.next()) {
733: l.add(this .getAttachment(rs));
734: }
735:
736: return l;
737: } catch (SQLException e) {
738: throw new DatabaseException(e);
739: } finally {
740: DbUtils.close(rs, p);
741: }
742: }
743:
744: protected Attachment getAttachment(ResultSet rs)
745: throws SQLException {
746: Attachment a = new Attachment();
747: a.setId(rs.getInt("attach_id"));
748: a.setPostId(rs.getInt("post_id"));
749: a.setPrivmsgsId(rs.getInt("privmsgs_id"));
750:
751: AttachmentInfo ai = new AttachmentInfo();
752: ai.setComment(rs.getString("description"));
753: ai.setDownloadCount(rs.getInt("download_count"));
754: ai.setFilesize(rs.getLong("filesize"));
755: ai.setMimetype(rs.getString("mimetype"));
756: ai.setPhysicalFilename(rs.getString("physical_filename"));
757: ai.setRealFilename(rs.getString("real_filename"));
758: ai.setUploadTime(new Date(rs.getTimestamp("upload_time")
759: .getTime()));
760: ai
761: .setExtension(this .selectExtension(rs
762: .getInt("extension_id")));
763:
764: a.setInfo(ai);
765:
766: return a;
767: }
768:
769: /**
770: * @see net.jforum.dao.AttachmentDAO#selectAttachmentById(int)
771: */
772: public Attachment selectAttachmentById(int attachId) {
773: ResultSet rs = null;
774: PreparedStatement p = null;
775: try {
776: Attachment e = null;
777:
778: p = JForumExecutionContext
779: .getConnection()
780: .prepareStatement(
781: SystemGlobals
782: .getSql("AttachmentModel.selectAttachmentById"));
783: p.setInt(1, attachId);
784:
785: rs = p.executeQuery();
786: if (rs.next()) {
787: e = this .getAttachment(rs);
788: }
789:
790: return e;
791: } catch (SQLException e) {
792: throw new DatabaseException(e);
793: } finally {
794: DbUtils.close(rs, p);
795: }
796: }
797:
798: public boolean isPhysicalDownloadMode(int extensionGroupId) {
799: boolean result = true;
800:
801: PreparedStatement p = null;
802: ResultSet rs = null;
803: try {
804: p = JForumExecutionContext
805: .getConnection()
806: .prepareStatement(
807: SystemGlobals
808: .getSql("AttachmentModel.isPhysicalDownloadMode"));
809:
810: p.setInt(1, extensionGroupId);
811:
812: rs = p.executeQuery();
813: if (rs.next()) {
814: result = (rs.getInt("download_mode") == 2);
815: }
816:
817: return result;
818: } catch (SQLException e) {
819: throw new DatabaseException(e);
820: } finally {
821: DbUtils.close(rs, p);
822: }
823: }
824: }
|