5420449ed39476f7676d1bd7cc5c5d0f7aae1ced
[mir.git] / source / mircoders / storage / DatabaseComment.java
1 package mircoders.storage;
2
3 import java.lang.*;
4 import java.sql.*;
5 import java.io.*;
6 import java.util.*;
7
8 import freemarker.template.*;
9
10 import mir.storage.*;
11 import mir.entity.*;
12 import mir.misc.*;
13
14 /**
15  * <b>This class implements the access to the comment-table for the
16  *    media table.
17  *
18  *
19  */
20
21 public class DatabaseComment extends Database implements StorageObject{
22
23         private static DatabaseComment instance;
24
25         // the following *has* to be sychronized cause this static method
26         // could get preemted and we could end up with 2 instances of DatabaseFoo..
27         // see the "Singletons with needles and thread" article at JavaWorld -mh
28         public synchronized static DatabaseComment getInstance() 
29           throws StorageObjectException {
30                 if (instance == null) {
31                         instance = new DatabaseComment();
32                         instance.myselfDatabase = instance;
33                 }
34                 return instance;
35         }
36
37         private DatabaseComment() throws StorageObjectException
38         {
39                 super();
40                 this.hasTimestamp = false;
41                 ////this.cache = new HashMap();
42                 this.theTable="comment";
43                 try {
44                         this.theEntityClass = Class.forName("mircoders.entity.EntityComment");
45                 }
46                 catch (Exception e) { throw new StorageObjectException(e.toString());   }
47         }
48
49         public SimpleList getPopupData()
50         throws StorageObjectException { return getPopupData("title",true); }
51
52         public boolean deleteByContentId(String id)
53                 throws StorageObjectException {
54                 Statement   stmt=null;
55                 Connection  con=null;
56                 String      sql;
57                 int         res = 0;
58
59                 /** @todo comments and topics should be deleted */
60                 sql = "delete from "+ theTable + " where to_media="+id;
61                 //theLog.printInfo("DELETE "+ sql);
62
63                 try {
64                         con=getPooledCon();
65                         stmt = con.createStatement();
66                         res = stmt.executeUpdate(sql);
67                 }       catch (SQLException sqe) {
68                         new StorageObjectException(sqe.toString());
69                         return false;
70                 } finally {
71                         freeConnection(con,stmt);
72                 }
73                 return true;
74         }
75 }