KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > portlets > user > factories > UserCommentsFactory


1 package com.dotmarketing.portlets.user.factories;
2
3
4 import java.util.List JavaDoc;
5
6 import com.dotmarketing.beans.UserProxy;
7 import com.dotmarketing.db.DotConnect;
8 import com.dotmarketing.db.DotHibernate;
9 import com.dotmarketing.factories.InodeFactory;
10 import com.dotmarketing.factories.UserProxyFactory;
11 import com.dotmarketing.portlets.user.model.UserComment;
12
13 /**
14  *
15  * @author maria
16  */

17 public class UserCommentsFactory {
18     
19     private static String JavaDoc COUNT_USER_COMMENTS = "SELECT count(*) as num_rows from user_comments where user_id = ?";
20
21     public static UserComment getComment(long userCommentInode)
22     {
23         UserComment userComment = (UserComment) InodeFactory.getInode(userCommentInode,UserComment.class);
24         return userComment;
25     }
26
27
28     public static List JavaDoc<UserComment> getUserComments(long userProxyInode)
29     {
30         int limit = 0;
31         int offset = 0;
32         List JavaDoc<UserComment> userComments = getUserComments(userProxyInode,limit,offset);
33         return userComments;
34     }
35     
36     public static List JavaDoc<UserComment> getUserComments(long userProxyInode,int offset,int limit)
37     {
38         UserProxy userProxy = (UserProxy) InodeFactory.getInode(userProxyInode,UserProxy.class);
39         List JavaDoc<UserComment> userComments = (List JavaDoc<UserComment>) InodeFactory.getChildrenClass(userProxy,UserComment.class,"cdate desc",limit,offset);
40         return userComments;
41     }
42
43     public static List JavaDoc<UserComment> getLastUserComments(long userProxyInode)
44     {
45         int limit = 5;
46         int offset = 0;
47         List JavaDoc<UserComment> userComments = getUserComments(userProxyInode,offset,limit);
48         return userComments;
49     }
50
51
52     public static void deleteUserComment(long userProxyInode,UserComment userComment)
53     {
54         UserProxy userProxy = UserProxyFactory.getUserProxy(userProxyInode);
55         InodeFactory.deleteInode(userComment);
56         userProxy.deleteChild(userComment);
57     }
58     
59     public static void deleteUserComment(long userProxyInode,long userCommentInode)
60     {
61         UserComment userComment = UserCommentsFactory.getComment(userCommentInode);
62         deleteUserComment(userProxyInode,userComment);
63     }
64
65     public static void saveUserComment(long userProxyInode,UserComment userComment)
66     {
67         UserProxy userProxy = UserProxyFactory.getUserProxy(userProxyInode);
68         InodeFactory.saveInode(userComment);
69         userProxy.addChild(userComment);
70     }
71     
72     public static void saveUserComment(UserComment userComment)
73     {
74         String JavaDoc userId = userComment.getUserId();
75         UserProxy userProxy = UserProxyFactory.getUserProxy(userId);
76         InodeFactory.saveInode(userComment);
77         userProxy.addChild(userComment);
78     }
79
80     public static List JavaDoc<UserComment> getUserCommentsByComm(long userProxyInode, long communicationId)
81     {
82         int limit = 0;
83         int offset = 0;
84         UserProxy userProxy = (UserProxy) InodeFactory.getInode(userProxyInode,UserProxy.class);
85         List JavaDoc<UserComment> userComments = (List JavaDoc<UserComment>) InodeFactory.getChildrenClassByCondition(userProxy,UserComment.class,"communication_id = "+communicationId,limit,offset);
86         return userComments;
87     }
88
89     public static java.util.List JavaDoc getUserComments(String JavaDoc userId, int offset, int limit) {
90         try {
91             DotHibernate dh = new DotHibernate(UserComment.class);
92             dh.setQuery("from user_comments in class com.dotmarketing.portlets.user.model.UserComment where user_id = ? order by cdate desc");
93             dh.setParam(userId);
94             dh.setFirstResult(offset);
95             dh.setMaxResults(limit);
96             return dh.list();
97         } catch (Exception JavaDoc e) {
98             System.out.println("getUserComments failed:" + e);
99             e.printStackTrace(System.out);
100         }
101         return new java.util.ArrayList JavaDoc();
102     }
103
104     public static int countUserComments(String JavaDoc UserId){
105         DotConnect db = new DotConnect();
106         db.setSQL(COUNT_USER_COMMENTS);
107         db.addParam(UserId);
108         return db.getInt("num_rows");
109     
110     }
111 }
112
Popular Tags