KickJava   Java API By Example, From Geeks To Geeks.

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


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 //Torque classes
9
import org.apache.torque.util.Criteria;
10 import org.apache.torque.util.BasePeer;
11
12 import org.apache.jetspeed.om.security.Group;
13 import org.apache.jetspeed.om.profile.Profile;
14 import org.apache.jetspeed.om.profile.ProfileLocator;
15 import org.apache.jetspeed.services.psmlmanager.db.DBOperations;
16 import org.apache.jetspeed.services.psmlmanager.db.DBUtils;
17 import org.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManager;
18 import org.apache.jetspeed.services.PsmlManager;
19 import org.apache.jetspeed.services.Profiler;
20
21 /**
22   * The skeleton for this class was autogenerated by Torque on:
23   *
24   * [Mon Sep 10 13:30:53 PDT 2001]
25   *
26   * You should add additional methods to this class to meet the
27   * application requirements. This class will only be generated as
28   * long as it does not already exist in the output directory.
29   *
30   * @author <a HREF="mailto:adambalk@cisco.com">Atul Dambalkar</a>
31   * @version $Id: JetspeedGroupProfilePeer.java,v 1.13 2003/08/13 04:18:17 taylor Exp $
32   */

33 public class JetspeedGroupProfilePeer
34     extends org.apache.jetspeed.om.dbpsml.BaseJetspeedGroupProfilePeer
35     implements DBOperations
36 {
37
38     /**
39      * Default constructor.
40      */

41     public JetspeedGroupProfilePeer() {}
42
43
44     /**
45      * Insert a group profile record in the database table.
46      *
47      * @param profile Profile object that will be inserted in the database
48      * @param connection A database connection to use
49      */

50     public void insert(Profile profile, Connection JavaDoc connection) throws Exception JavaDoc
51     {
52         doInsertOrUpdate(profile, INSERT, connection);
53     }
54
55     /**
56      * Update group profile record from the database table.
57      *
58      * @param profile Profile object that will be deleted from the database
59      * @param connection A database connection to use
60      */

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

128     public void delete(ProfileLocator locator, Connection JavaDoc connection) throws Exception JavaDoc
129     {
130         super.doDelete(buildCriteria(locator), connection);
131     }
132
133     /**
134      * Select group profile record from the database table for the given
135      * locator object.
136      *
137      * @param locator ProfileLocator object that will be used to select required
138      * profile from the database
139      * @param connection A database connection to use
140      * @return List of records that statisfy the given locator criteria.
141      */

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

156     public List JavaDoc selectOrdered(ProfileLocator locator, Connection JavaDoc connection) throws Exception JavaDoc
157     {
158         Criteria criteria = buildCriteria(locator);
159
160         criteria.addAscendingOrderByColumn(GROUP_NAME);
161         criteria.addAscendingOrderByColumn(MEDIA_TYPE);
162         criteria.addAscendingOrderByColumn(LANGUAGE);
163         criteria.addAscendingOrderByColumn(COUNTRY);
164         criteria.addAscendingOrderByColumn(PAGE);
165
166         return super.doSelect(criteria, connection);
167     }
168
169     /**
170      * Delete all records from the database table for a group.
171      *
172      * @param group Group object for which all the records will be deleted from the database
173      * @param connection A database connection to use
174      */

175     public void delete(Group group, Connection JavaDoc connection) throws Exception JavaDoc
176     {
177         Criteria criteria = new Criteria();
178
179         criteria.add(GROUP_NAME, group.getName());
180
181         super.doDelete(criteria, connection);
182     }
183
184
185     /*
186      * Build criteria for selecting, deleting groups
187      *
188      */

189     protected Criteria buildCriteria(ProfileLocator locator)
190     {
191         Criteria criteria = new Criteria();
192
193         String JavaDoc mediaType = locator.getMediaType();
194         String JavaDoc language = locator.getLanguage();
195         String JavaDoc country = locator.getCountry();
196         String JavaDoc pageName = locator.getName();
197         String JavaDoc groupName = null;
198
199         Group group = locator.getGroup();
200         if (group != null) {
201             groupName = group.getName();
202         }
203
204         if (groupName != null && groupName.length() > 0)
205         {
206             criteria.add(GROUP_NAME, groupName);
207         }
208
209         if (pageName != null && pageName.length() > 0)
210         {
211             criteria.add(PAGE, pageName);
212         }
213
214         if (mediaType != null && mediaType.length() > 0)
215         {
216             criteria.add(MEDIA_TYPE, locator.getMediaType());
217         }
218
219         if (language != null && language.length() > 0 && (!language.equals("-1")))
220         {
221             criteria.add(LANGUAGE, language);
222         }
223         else if(language != null && language.equals("-1"))
224         {
225             criteria.add(LANGUAGE, null);
226         }
227
228         if (country != null && country.length() > 0 && (!country.equals("-1")))
229         {
230             criteria.add(COUNTRY, country);
231         }
232         else if(country != null && country.equals("-1"))
233         {
234             criteria.add(COUNTRY, null);
235         }
236         
237         return criteria;
238     }
239
240 }
241
242
Popular Tags