KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > om > dbpsml > JetspeedUserProfilePeer


1 package org.apache.jetspeed.om.dbpsml;
2
3 // JDK classes
4
import java.util.List JavaDoc;
5 import java.sql.Connection JavaDoc;
6
7
8 // Jetspeed classes for Database PsmlManager implementation
9
import org.apache.jetspeed.services.psmlmanager.db.DBUtils;
10
11 // Turbine classes
12
import org.apache.jetspeed.om.security.JetspeedUser;
13 import org.apache.turbine.util.RunData;
14
15 //Torque classes
16
import org.apache.torque.util.Criteria;
17 import org.apache.torque.util.BasePeer;
18
19
20 // Local classes
21
import org.apache.jetspeed.om.dbpsml.map.*;
22
23 // Jetspeed classes (Profiler)
24
import org.apache.jetspeed.services.Profiler;
25
26 import org.apache.jetspeed.om.profile.Profile;
27 import org.apache.jetspeed.om.profile.ProfileLocator;
28 import org.apache.jetspeed.services.psmlmanager.db.DBOperations;
29 import org.apache.jetspeed.services.psmlmanager.db.DBUtils;
30 import org.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManager;
31 import org.apache.jetspeed.services.PsmlManager;
32
33 /**
34   * The skeleton for this class was autogenerated by Torque on:
35   *
36   * [Mon Sep 10 13:30:53 PDT 2001]
37   *
38   * You should add additional methods to this class to meet the
39   * application requirements. This class will only be generated as
40   * long as it does not already exist in the output directory.
41   *
42   * @author <a HREF="mailto:adambalk@cisco.com">Atul Dambalkar</a>
43   * @version $Id: JetspeedUserProfilePeer.java,v 1.14 2003/07/23 19:50:14 morciuch Exp $
44   */

45 public class JetspeedUserProfilePeer
46     extends org.apache.jetspeed.om.dbpsml.BaseJetspeedUserProfilePeer
47     implements DBOperations
48 {
49
50     /**
51      * Default constructor.
52      */

53     public JetspeedUserProfilePeer() {}
54
55
56     /**
57      * Insert a user profile record in the database table.
58      *
59      * @param profile Profile object that will be inserted in the database
60      * @param connection A database connection to use
61      */

62     public void insert(Profile profile, Connection JavaDoc connection) throws Exception JavaDoc
63     {
64         doInsertOrUpdate(profile, INSERT, connection);
65     }
66
67     /**
68      * Insert a user profile record in the database table.
69      *
70      * @param profile Profile object that will be inserted in the database
71      * @param connection A database connection to use
72      */

73     public void update(Profile profile, Connection JavaDoc connection) throws Exception JavaDoc
74     {
75         doInsertOrUpdate(profile, UPDATE, connection);
76     }
77
78     private void doInsertOrUpdate(Profile profile, int operation, Connection JavaDoc connection)
79                          throws Exception JavaDoc
80     {
81         JetspeedUserProfile userProfile = new JetspeedUserProfile();
82         DatabasePsmlManager service = (DatabasePsmlManager)PsmlManager.getService();
83
84         userProfile.setUserName(profile.getUser().getUserName());
85         userProfile.setMediaType(profile.getMediaType());
86         
87         String JavaDoc language = profile.getLanguage();
88         if(language != null && (!language.equals("-1")))
89         {
90             userProfile.setLanguage(language);
91         }
92         else
93         {
94             userProfile.setLanguage(null);
95         }
96         
97         String JavaDoc country = profile.getCountry();
98         if(country != null && (!country.equals("-1")))
99         {
100             userProfile.setCountry(country);
101         }
102         else
103         {
104             userProfile.setCountry(null);
105         }
106
107         
108         String JavaDoc name = profile.getName();
109         if (name == null || name.equals(""))
110         {
111             profile.setName(Profiler.FULL_DEFAULT_PROFILE);
112         }
113         else if (!name.endsWith(Profiler.DEFAULT_EXTENSION))
114         {
115             profile.setName(name + Profiler.DEFAULT_EXTENSION);
116         }
117         userProfile.setPage(profile.getName());
118         userProfile.setProfile(DBUtils.portletsToBytes(
119                                         profile.getDocument().getPortlets(), service.getMapping()));
120
121         if (operation == INSERT)
122         {
123             super.doInsert(userProfile, connection);
124         }
125         else if (operation == UPDATE)
126         {
127             Criteria values = buildCriteria(userProfile);
128             Criteria select = buildCriteria(userProfile);
129             select.remove(PROFILE);
130             BasePeer.doUpdate( select, values, connection );
131         }
132     }
133
134
135     /**
136      * Delete user profile record from the database table.
137      *
138      * @param profile Profile object that will be deleted from the database
139      * @param connection A database connection to use
140      */

141     public void delete(ProfileLocator locator, Connection JavaDoc connection) throws Exception JavaDoc
142     {
143         super.doDelete(buildCriteria(locator), connection);
144     }
145
146     /**
147      * Select user profile record from the database table for the given
148      * locator object.
149      *
150      * @param locator ProfileLocator object that will be used to select required
151      * profile from the database
152      * @param connection A database connection to use
153      * @return List of records that statisfy the given locator criteria.
154      */

155     public List JavaDoc select(ProfileLocator locator, Connection JavaDoc connection) throws Exception JavaDoc
156     {
157         Criteria criteria = buildCriteria(locator);
158         return super.doSelect(criteria, connection); // buildCriteria(locator));
159
}
160
161     /**
162      * Select user profile record from the database table for the given
163      * locator object and return list ordered by primary key.
164      *
165      * @param locator ProfileLocator object that will be used to select required
166      * profile from the database
167      * @param connection A database connection to use
168      * @return List of records that statisfy the given locator criteria.
169      */

170     public List JavaDoc selectOrdered(ProfileLocator locator, Connection JavaDoc connection) throws Exception JavaDoc
171     {
172         Criteria criteria = buildCriteria(locator);
173
174         criteria.addAscendingOrderByColumn(USER_NAME);
175         criteria.addAscendingOrderByColumn(MEDIA_TYPE);
176         criteria.addAscendingOrderByColumn(LANGUAGE);
177         criteria.addAscendingOrderByColumn(COUNTRY);
178         criteria.addAscendingOrderByColumn(PAGE);
179
180         return super.doSelect(criteria, connection);
181     }
182
183
184     /**
185      * Delete all records from the database table for a user.
186      *
187      * @param user User object for which all the records will be deleted from the database
188      * @param connection A database connection to use
189      */

190     public void delete(JetspeedUser user, Connection JavaDoc connection) throws Exception JavaDoc
191     {
192         Criteria criteria = new Criteria();
193
194         criteria.add(USER_NAME, user.getUserName());
195
196         super.doDelete(criteria, connection);
197     }
198
199     /*
200      * Build criteria for selecting, deleting groups
201      *
202      */

203     protected Criteria buildCriteria(ProfileLocator locator)
204     {
205         Criteria criteria = new Criteria();
206
207         String JavaDoc mediaType = locator.getMediaType();
208         String JavaDoc language = locator.getLanguage();
209         String JavaDoc country = locator.getCountry();
210         String JavaDoc pageName = locator.getName();
211         String JavaDoc userName = null;
212         JetspeedUser user= locator.getUser();
213
214         if (user != null) {
215             userName = user.getUserName();
216         }
217
218         if (userName != null && userName.length() > 0)
219         {
220             criteria.add(USER_NAME, userName) ;
221         }
222
223         if (pageName != null && pageName.length() > 0)
224         {
225             criteria.add(PAGE, pageName);
226         }
227
228         if (mediaType != null && mediaType.length() > 0)
229         {
230             criteria.add(MEDIA_TYPE, mediaType);
231         }
232
233         if (language != null && language.length() > 0 && (!language.equals("-1")))
234         {
235             criteria.add(LANGUAGE, language);
236         }
237         else if(language != null && language.equals("-1"))
238         {
239             criteria.add(LANGUAGE, null);
240         }
241
242         if (country != null && country.length() > 0 && (!country.equals("-1")))
243         {
244             criteria.add(COUNTRY, country);
245         }
246         else if(country != null && country.equals("-1"))
247         {
248             criteria.add(COUNTRY, null);
249         }
250         return criteria;
251     }
252 }
253
254
Popular Tags