Initial revision
[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 webdb.storage.*;
11 import webdb.entity.*;
12 import webdb.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         public static DatabaseComment getInstance() throws StorageObjectException {
26                 if (instance == null) {
27                         instance = new DatabaseComment();
28                         instance.myselfDatabase = instance;
29                 }
30                 return instance;
31         }
32
33         private DatabaseComment() throws StorageObjectException
34         {
35                 super();
36                 this.hasTimestamp = false;
37                 this.cache = new HashMap();
38                 this.theTable="comment";
39                 try {
40                         this.theEntityClass = Class.forName("mir.entity.EntityComment");
41                 }
42                 catch (Exception e) { throw new StorageObjectException(e.toString());   }
43         }
44
45         public SimpleList getPopupData() { return getPopupData("title",true); }
46
47         public boolean deleteByContentId(String id)
48                 throws StorageObjectException {
49                 Statement   stmt=null;
50                 Connection  con=null;
51                 String      sql;
52                 int         res = 0;
53
54                 /** @todo comments and topics should be deleted */
55                 sql = "delete from "+ theTable + " where to_media="+id;
56                 //theLog.printInfo("DELETE "+ sql);
57
58                 try {
59                         con=getPooledCon();
60                         stmt = con.createStatement();
61                         res = stmt.executeUpdate(sql);
62                 }       catch (SQLException sqe) {
63                         new StorageObjectException(sqe.toString());
64                         return false;
65                 } finally {
66                         freeConnection(con,stmt);
67                 }
68                 return true;
69         }
70 }