1 package org.apache.jetspeed.om.dbpsml; 2 3 import java.util.List ; 5 import java.sql.Connection ; 6 7 8 import org.apache.jetspeed.services.psmlmanager.db.DBUtils; 10 11 import org.apache.jetspeed.om.security.JetspeedUser; 13 import org.apache.turbine.util.RunData; 14 15 import org.apache.torque.util.Criteria; 17 import org.apache.torque.util.BasePeer; 18 19 20 import org.apache.jetspeed.om.dbpsml.map.*; 22 23 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 45 public class JetspeedUserProfilePeer 46 extends org.apache.jetspeed.om.dbpsml.BaseJetspeedUserProfilePeer 47 implements DBOperations 48 { 49 50 53 public JetspeedUserProfilePeer() {} 54 55 56 62 public void insert(Profile profile, Connection connection) throws Exception 63 { 64 doInsertOrUpdate(profile, INSERT, connection); 65 } 66 67 73 public void update(Profile profile, Connection connection) throws Exception 74 { 75 doInsertOrUpdate(profile, UPDATE, connection); 76 } 77 78 private void doInsertOrUpdate(Profile profile, int operation, Connection connection) 79 throws Exception 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 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 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 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 141 public void delete(ProfileLocator locator, Connection connection) throws Exception 142 { 143 super.doDelete(buildCriteria(locator), connection); 144 } 145 146 155 public List select(ProfileLocator locator, Connection connection) throws Exception 156 { 157 Criteria criteria = buildCriteria(locator); 158 return super.doSelect(criteria, connection); } 160 161 170 public List selectOrdered(ProfileLocator locator, Connection connection) throws Exception 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 190 public void delete(JetspeedUser user, Connection connection) throws Exception 191 { 192 Criteria criteria = new Criteria(); 193 194 criteria.add(USER_NAME, user.getUserName()); 195 196 super.doDelete(criteria, connection); 197 } 198 199 203 protected Criteria buildCriteria(ProfileLocator locator) 204 { 205 Criteria criteria = new Criteria(); 206 207 String mediaType = locator.getMediaType(); 208 String language = locator.getLanguage(); 209 String country = locator.getCountry(); 210 String pageName = locator.getName(); 211 String 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 |