001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.migration;
023:
024: /**
025: * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw Dawidowicz</a>
026: * @version $Revision: 8784 $
027: */
028: public class MigrationModule20_22 extends MigrationModule {
029:
030: /*public Set findUsers20(int offset, int limit) throws ModuleException
031: {
032: try
033: {
034: Session session = getCurrentFromSession();
035: Query query = session.createQuery("from User20Impl");
036: query.setFirstResult(offset);
037: query.setMaxResults(limit);
038: Iterator iterator = query.iterate();
039: return Tools.toSet(iterator);
040: }
041: catch(HibernateException e)
042: {
043: String message = "Cannot find user range [" + offset + "," + limit + "]";
044: //log.error(message, e);
045: throw new ModuleException(message, e);
046: }
047: }
048:
049: public User20Impl findUser20ById(String id) throws IllegalArgumentException, ModuleException, NoSuchUserException
050: {
051: if (id == null)
052: {
053: throw new IllegalArgumentException("The id is null");
054: }
055: try
056: {
057: return findUser20ById(new Integer(id));
058: }
059: catch (NumberFormatException e)
060: {
061: throw new IllegalArgumentException("Cannot parse id into an integer " + id);
062: }
063: }
064:
065: public User20Impl findUser20ById(Object id) throws IllegalArgumentException, ModuleException, NoSuchUserException
066: {
067: if(id instanceof Integer)
068: {
069: try
070: {
071: Session session = getCurrentFromSession();
072: User20Impl user = (User20Impl)session.get(User20Impl.class, (Integer)id);
073: if(user == null)
074: {
075: throw new NoSuchUserException("No user found for " + id);
076: }
077: return user;
078: }
079: catch(HibernateException e)
080: {
081: String message = "Cannot find user by id " + id;
082: //log.error(message, e);
083: throw new ModuleException(message, e);
084: }
085: }
086: else
087: {
088: throw new IllegalArgumentException("The id is not an Integer : " + id);
089: }
090: }
091:
092: public Set findUsers20Ids() throws ModuleException
093: {
094: try
095: {
096: Session session = getCurrentFromSession();
097: Query query = session.createQuery("select ID from User20Impl");
098: //query.setFirstResult(offset);
099: //query.setMaxResults(limit);
100: Iterator iterator = query.iterate();
101: return Tools.toSet(iterator);
102: }
103: catch(HibernateException e)
104: {
105: String message = "Cannot find user ids";
106: //log.error(message, e);
107: throw new ModuleException(message, e);
108: }
109: }
110:
111: public Set findUsers22(int offset, int limit) throws ModuleException
112: {
113: try
114: {
115: Session session = getCurrentToSession();
116: Query query = session.createQuery("from User22Impl");
117: query.setFirstResult(offset);
118: query.setMaxResults(limit);
119: Iterator iterator = query.iterate();
120: return Tools.toSet(iterator);
121: }
122: catch(HibernateException e)
123: {
124: String message = "Cannot find user range [" + offset + "," + limit + "]";
125: //log.error(message, e);
126: throw new ModuleException(message, e);
127: }
128: }
129:
130: public User22Impl findUser22ById(String id) throws IllegalArgumentException, ModuleException, NoSuchUserException
131: {
132: if (id == null)
133: {
134: throw new IllegalArgumentException("The id is null");
135: }
136: try
137: {
138: return findUser22ById(new Long(id));
139: }
140: catch (NumberFormatException e)
141: {
142: throw new IllegalArgumentException("Cannot parse id into an integer " + id);
143: }
144: }
145:
146: public User22Impl findUser22ById(Object id) throws IllegalArgumentException, ModuleException, NoSuchUserException
147: {
148: if(id instanceof Long)
149: {
150: try
151: {
152: Session session = getCurrentToSession();
153: User22Impl user = (User22Impl)session.get(User22Impl.class, (Long)id);
154: if(user == null)
155: {
156: throw new NoSuchUserException("No user found for " + id);
157: }
158: return user;
159: }
160: catch(HibernateException e)
161: {
162: String message = "Cannot find user by id " + id;
163: //log.error(message, e);
164: throw new ModuleException(message, e);
165: }
166: }
167: else
168: {
169: throw new IllegalArgumentException("The id is not an Long : " + id);
170: }
171: }
172:
173: public User20Impl findUser20ByUserName(String userName) throws ModuleException
174: {
175: if(userName != null)
176: {
177: try
178: {
179: Session session = getCurrentFromSession();
180: Query query = session.createQuery("from User20Impl where userName=:userName");
181: query.setParameter("userName", userName);
182: //query.setCacheable(true);
183: User20Impl user = (User20Impl)query.uniqueResult();
184: if(user == null)
185: {
186: throw new NoSuchUserException("No such user " + userName);
187: }
188: return user;
189: }
190: catch(HibernateException e)
191: {
192: String message = "Cannot find user by name " + userName;
193: //log.error(message, e);
194: throw new ModuleException(message, e);
195: }
196: }
197: else
198: {
199: throw new IllegalArgumentException("user name cannot be null");
200: }
201: }
202:
203: public User22Impl findUser22ByUserName(String userName) throws ModuleException
204: {
205: if(userName != null)
206: {
207: try
208: {
209: Session session = getCurrentToSession();
210: Query query = session.createQuery("from User22Impl where userName=:userName");
211: query.setParameter("userName", userName);
212: //query.setCacheable(true);
213: User22Impl user = (User22Impl)query.uniqueResult();
214: if(user == null)
215: {
216: throw new NoSuchUserException("No such user " + userName);
217: }
218: return user;
219: }
220: catch(HibernateException e)
221: {
222: String message = "Cannot find user by name " + userName;
223: //log.error(message, e);
224: throw new ModuleException(message, e);
225: }
226: }
227: else
228: {
229: throw new IllegalArgumentException("user name cannot be null");
230: }
231: }
232:
233: public Set findRoles20() throws ModuleException
234: {
235: try
236: {
237: Session session = getCurrentFromSession();
238: Query query = session.createQuery("from Role20Impl");
239: Iterator iterator = query.iterate();
240: return Tools.toSet(iterator);
241: }
242: catch(HibernateException e)
243: {
244: String message = "Cannot find roles";
245: //log.error(message, e);
246: throw new ModuleException(message, e);
247: }
248: }
249:
250: public Role20Impl findRole20ByName(String name) throws ModuleException
251: {
252: if(name != null)
253: {
254: try
255: {
256: Session session = getCurrentFromSession();
257: Criteria criteria = session.createCriteria(Role20Impl.class);
258: criteria.add(Restrictions.naturalId().set("name", name));
259: criteria.setCacheable(true);
260: Role20Impl role = (Role20Impl)criteria.uniqueResult();
261: if(role == null)
262: {
263: throw new ModuleException("No such role " + name);
264: }
265: return role;
266: }
267: catch(HibernateException e)
268: {
269: String message = "Cannot find role by name " + name;
270: //log.error(message, e);
271: throw new ModuleException(message, e);
272: }
273: }
274: else
275: {
276: throw new IllegalArgumentException("name cannot be null");
277: }
278: }
279:
280: public Set findRoles20ByNames(String[] names) throws ModuleException
281: {
282: if(names != null)
283: {
284: try
285: {
286: Session session = getCurrentFromSession();
287: StringBuffer queryString = new StringBuffer("from Role20Impl as g where g.name=?");
288: for(int i = 1; i < names.length; i++)
289: {
290: queryString.append(" or g.name=?");
291: }
292: Query query = session.createQuery(queryString.toString());
293: for(int i = 0; i < names.length; i++)
294: {
295: query.setString(i, names[i]);
296: }
297: Iterator iterator = query.iterate();
298: return Tools.toSet(iterator);
299: }
300: catch(HibernateException e)
301: {
302: String message = "Cannot find roles";
303: //log.error(message, e);
304: throw new ModuleException(message, e);
305: }
306: }
307: else
308: {
309: throw new IllegalArgumentException("name cannot be null");
310: }
311: }
312:
313: public Set findRoles22() throws ModuleException
314: {
315: try
316: {
317: Session session = getCurrentToSession();
318: Query query = session.createQuery("from Role22Impl");
319: Iterator iterator = query.iterate();
320: return Tools.toSet(iterator);
321: }
322: catch(HibernateException e)
323: {
324: String message = "Cannot find roles";
325: //log.error(message, e);
326: throw new ModuleException(message, e);
327: }
328: }
329:
330: public Role22Impl findRole22ByName(String name) throws ModuleException
331: {
332: if(name != null)
333: {
334: try
335: {
336: Session session = getCurrentToSession();
337: Criteria criteria = session.createCriteria(Role22Impl.class);
338: criteria.add(Restrictions.naturalId().set("name", name));
339: criteria.setCacheable(true);
340: Role22Impl role = (Role22Impl)criteria.uniqueResult();
341: if(role == null)
342: {
343: throw new ModuleException("No such role " + name);
344: }
345: return role;
346: }
347: catch(HibernateException e)
348: {
349: String message = "Cannot find role by name " + name;
350: //log.error(message, e);
351: throw new ModuleException(message, e);
352: }
353: }
354: else
355: {
356: throw new IllegalArgumentException("name cannot be null");
357: }
358: }
359:
360: public Set findRoles22ByNames(String[] names) throws ModuleException
361: {
362: if(names != null)
363: {
364: try
365: {
366: Session session = getCurrentFromSession();
367: StringBuffer queryString = new StringBuffer("from Role22Impl as g where g.name=?");
368: for(int i = 1; i < names.length; i++)
369: {
370: queryString.append(" or g.name=?");
371: }
372: Query query = session.createQuery(queryString.toString());
373: for(int i = 0; i < names.length; i++)
374: {
375: query.setString(i, names[i]);
376: }
377: Iterator iterator = query.iterate();
378: return Tools.toSet(iterator);
379: }
380: catch(HibernateException e)
381: {
382: String message = "Cannot find roles";
383: //log.error(message, e);
384: throw new ModuleException(message, e);
385: }
386: }
387: else
388: {
389: throw new IllegalArgumentException("name cannot be null");
390: }
391: }*/
392:
393: }
|