KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > factories > UserProxyFactory


1 package com.dotmarketing.factories;
2
3 import com.dotmarketing.beans.UserProxy;
4 import com.dotmarketing.db.DotHibernate;
5 import com.dotmarketing.util.Logger;
6 import com.liferay.portal.model.User;
7
8 /**
9  *
10  * @author David Torres
11  */

12 public class UserProxyFactory {
13
14     public static UserProxy getUserProxy(String JavaDoc userId) {
15         if(userId == null){
16             return null;
17         }
18         UserProxy up = null;
19         try {
20             DotHibernate dh = new DotHibernate(UserProxy.class);
21             dh.setQuery("from user_proxy in class com.dotmarketing.beans.UserProxy where user_id = ?");
22             dh.setParam(userId);
23
24             up = (UserProxy) dh.load();
25         } catch (Exception JavaDoc e) {
26             Logger.warn(UserProxyFactory.class, "getUserProxy failed:" + e, e);
27         }
28
29         if (up.getInode() == 0) {
30             // if we don't have a user proxy, create one
31
up.setUserId(userId);
32             InodeFactory.saveInode(up);
33         }
34         return up;
35         
36     }
37
38     public static UserProxy getUserProxy(User user) {
39         
40         return getUserProxy(user.getUserId());
41
42     }
43     
44     public static UserProxy getUserProxy(long userProxyInode)
45     {
46         return (UserProxy) InodeFactory.getInode(userProxyInode,UserProxy.class);
47     }
48     
49     public static void saveUserProxy(UserProxy userProxy)
50     {
51         InodeFactory.saveInode(userProxy);
52     }
53 }
Popular Tags