first cut of merge of STABLE-pre1_0 into HEAD. I won't even guarantee that it
[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         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("mircoders.entity.EntityComment");
41                 }
42                 catch (Exception e) { throw new StorageObjectException(e.toString());   }
43         }
44
45         public SimpleList getPopupData()
46         throws StorageObjectException { return getPopupData("title",true); }
47
48         public boolean deleteByContentId(String id)
49                 throws StorageObjectException {
50                 Statement   stmt=null;
51                 Connection  con=null;
52                 String      sql;
53                 int         res = 0;
54
55                 /** @todo comments and topics should be deleted */
56                 sql = "delete from "+ theTable + " where to_media="+id;
57                 //theLog.printInfo("DELETE "+ sql);
58
59                 try {
60                         con=getPooledCon();
61                         stmt = con.createStatement();
62                         res = stmt.executeUpdate(sql);
63                 }       catch (SQLException sqe) {
64                         new StorageObjectException(sqe.toString());
65                         return false;
66                 } finally {
67                         freeConnection(con,stmt);
68                 }
69                 return true;
70         }
71 }