001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.persistence;
022:
023: import com.liferay.portal.NoSuchUserTrackerPathException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.dao.DynamicQuery;
026: import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
027: import com.liferay.portal.kernel.util.GetterUtil;
028: import com.liferay.portal.kernel.util.OrderByComparator;
029: import com.liferay.portal.kernel.util.StringMaker;
030: import com.liferay.portal.kernel.util.StringPool;
031: import com.liferay.portal.kernel.util.Validator;
032: import com.liferay.portal.model.ModelListener;
033: import com.liferay.portal.model.UserTrackerPath;
034: import com.liferay.portal.model.impl.UserTrackerPathImpl;
035: import com.liferay.portal.model.impl.UserTrackerPathModelImpl;
036: import com.liferay.portal.spring.hibernate.FinderCache;
037: import com.liferay.portal.spring.hibernate.HibernateUtil;
038: import com.liferay.portal.util.PropsUtil;
039:
040: import com.liferay.util.dao.hibernate.QueryUtil;
041:
042: import org.apache.commons.logging.Log;
043: import org.apache.commons.logging.LogFactory;
044:
045: import org.hibernate.Query;
046: import org.hibernate.Session;
047:
048: import java.util.Collections;
049: import java.util.Iterator;
050: import java.util.List;
051:
052: /**
053: * <a href="UserTrackerPathPersistenceImpl.java.html"><b><i>View Source</i></b></a>
054: *
055: * @author Brian Wing Shun Chan
056: *
057: */
058: public class UserTrackerPathPersistenceImpl extends BasePersistence
059: implements UserTrackerPathPersistence {
060: public UserTrackerPath create(long userTrackerPathId) {
061: UserTrackerPath userTrackerPath = new UserTrackerPathImpl();
062:
063: userTrackerPath.setNew(true);
064: userTrackerPath.setPrimaryKey(userTrackerPathId);
065:
066: return userTrackerPath;
067: }
068:
069: public UserTrackerPath remove(long userTrackerPathId)
070: throws NoSuchUserTrackerPathException, SystemException {
071: Session session = null;
072:
073: try {
074: session = openSession();
075:
076: UserTrackerPath userTrackerPath = (UserTrackerPath) session
077: .get(UserTrackerPathImpl.class, new Long(
078: userTrackerPathId));
079:
080: if (userTrackerPath == null) {
081: if (_log.isWarnEnabled()) {
082: _log
083: .warn("No UserTrackerPath exists with the primary key "
084: + userTrackerPathId);
085: }
086:
087: throw new NoSuchUserTrackerPathException(
088: "No UserTrackerPath exists with the primary key "
089: + userTrackerPathId);
090: }
091:
092: return remove(userTrackerPath);
093: } catch (NoSuchUserTrackerPathException nsee) {
094: throw nsee;
095: } catch (Exception e) {
096: throw HibernateUtil.processException(e);
097: } finally {
098: closeSession(session);
099: }
100: }
101:
102: public UserTrackerPath remove(UserTrackerPath userTrackerPath)
103: throws SystemException {
104: ModelListener listener = _getListener();
105:
106: if (listener != null) {
107: listener.onBeforeRemove(userTrackerPath);
108: }
109:
110: userTrackerPath = removeImpl(userTrackerPath);
111:
112: if (listener != null) {
113: listener.onAfterRemove(userTrackerPath);
114: }
115:
116: return userTrackerPath;
117: }
118:
119: protected UserTrackerPath removeImpl(UserTrackerPath userTrackerPath)
120: throws SystemException {
121: Session session = null;
122:
123: try {
124: session = openSession();
125:
126: session.delete(userTrackerPath);
127:
128: session.flush();
129:
130: return userTrackerPath;
131: } catch (Exception e) {
132: throw HibernateUtil.processException(e);
133: } finally {
134: closeSession(session);
135:
136: FinderCache.clearCache(UserTrackerPath.class.getName());
137: }
138: }
139:
140: public UserTrackerPath update(UserTrackerPath userTrackerPath)
141: throws SystemException {
142: return update(userTrackerPath, false);
143: }
144:
145: public UserTrackerPath update(UserTrackerPath userTrackerPath,
146: boolean merge) throws SystemException {
147: ModelListener listener = _getListener();
148:
149: boolean isNew = userTrackerPath.isNew();
150:
151: if (listener != null) {
152: if (isNew) {
153: listener.onBeforeCreate(userTrackerPath);
154: } else {
155: listener.onBeforeUpdate(userTrackerPath);
156: }
157: }
158:
159: userTrackerPath = updateImpl(userTrackerPath, merge);
160:
161: if (listener != null) {
162: if (isNew) {
163: listener.onAfterCreate(userTrackerPath);
164: } else {
165: listener.onAfterUpdate(userTrackerPath);
166: }
167: }
168:
169: return userTrackerPath;
170: }
171:
172: public UserTrackerPath updateImpl(
173: com.liferay.portal.model.UserTrackerPath userTrackerPath,
174: boolean merge) throws SystemException {
175: Session session = null;
176:
177: try {
178: session = openSession();
179:
180: if (merge) {
181: session.merge(userTrackerPath);
182: } else {
183: if (userTrackerPath.isNew()) {
184: session.save(userTrackerPath);
185: }
186: }
187:
188: session.flush();
189:
190: userTrackerPath.setNew(false);
191:
192: return userTrackerPath;
193: } catch (Exception e) {
194: throw HibernateUtil.processException(e);
195: } finally {
196: closeSession(session);
197:
198: FinderCache.clearCache(UserTrackerPath.class.getName());
199: }
200: }
201:
202: public UserTrackerPath findByPrimaryKey(long userTrackerPathId)
203: throws NoSuchUserTrackerPathException, SystemException {
204: UserTrackerPath userTrackerPath = fetchByPrimaryKey(userTrackerPathId);
205:
206: if (userTrackerPath == null) {
207: if (_log.isWarnEnabled()) {
208: _log
209: .warn("No UserTrackerPath exists with the primary key "
210: + userTrackerPathId);
211: }
212:
213: throw new NoSuchUserTrackerPathException(
214: "No UserTrackerPath exists with the primary key "
215: + userTrackerPathId);
216: }
217:
218: return userTrackerPath;
219: }
220:
221: public UserTrackerPath fetchByPrimaryKey(long userTrackerPathId)
222: throws SystemException {
223: Session session = null;
224:
225: try {
226: session = openSession();
227:
228: return (UserTrackerPath) session.get(
229: UserTrackerPathImpl.class, new Long(
230: userTrackerPathId));
231: } catch (Exception e) {
232: throw HibernateUtil.processException(e);
233: } finally {
234: closeSession(session);
235: }
236: }
237:
238: public List findByUserTrackerId(long userTrackerId)
239: throws SystemException {
240: boolean finderClassNameCacheEnabled = UserTrackerPathModelImpl.CACHE_ENABLED;
241: String finderClassName = UserTrackerPath.class.getName();
242: String finderMethodName = "findByUserTrackerId";
243: String[] finderParams = new String[] { Long.class.getName() };
244: Object[] finderArgs = new Object[] { new Long(userTrackerId) };
245:
246: Object result = null;
247:
248: if (finderClassNameCacheEnabled) {
249: result = FinderCache.getResult(finderClassName,
250: finderMethodName, finderParams, finderArgs,
251: getSessionFactory());
252: }
253:
254: if (result == null) {
255: Session session = null;
256:
257: try {
258: session = openSession();
259:
260: StringMaker query = new StringMaker();
261:
262: query
263: .append("FROM com.liferay.portal.model.UserTrackerPath WHERE ");
264:
265: query.append("userTrackerId = ?");
266:
267: query.append(" ");
268:
269: Query q = session.createQuery(query.toString());
270:
271: int queryPos = 0;
272:
273: q.setLong(queryPos++, userTrackerId);
274:
275: List list = q.list();
276:
277: FinderCache.putResult(finderClassNameCacheEnabled,
278: finderClassName, finderMethodName,
279: finderParams, finderArgs, list);
280:
281: return list;
282: } catch (Exception e) {
283: throw HibernateUtil.processException(e);
284: } finally {
285: closeSession(session);
286: }
287: } else {
288: return (List) result;
289: }
290: }
291:
292: public List findByUserTrackerId(long userTrackerId, int begin,
293: int end) throws SystemException {
294: return findByUserTrackerId(userTrackerId, begin, end, null);
295: }
296:
297: public List findByUserTrackerId(long userTrackerId, int begin,
298: int end, OrderByComparator obc) throws SystemException {
299: boolean finderClassNameCacheEnabled = UserTrackerPathModelImpl.CACHE_ENABLED;
300: String finderClassName = UserTrackerPath.class.getName();
301: String finderMethodName = "findByUserTrackerId";
302: String[] finderParams = new String[] { Long.class.getName(),
303:
304: "java.lang.Integer", "java.lang.Integer",
305: "com.liferay.portal.kernel.util.OrderByComparator" };
306: Object[] finderArgs = new Object[] { new Long(userTrackerId),
307:
308: String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
309:
310: Object result = null;
311:
312: if (finderClassNameCacheEnabled) {
313: result = FinderCache.getResult(finderClassName,
314: finderMethodName, finderParams, finderArgs,
315: getSessionFactory());
316: }
317:
318: if (result == null) {
319: Session session = null;
320:
321: try {
322: session = openSession();
323:
324: StringMaker query = new StringMaker();
325:
326: query
327: .append("FROM com.liferay.portal.model.UserTrackerPath WHERE ");
328:
329: query.append("userTrackerId = ?");
330:
331: query.append(" ");
332:
333: if (obc != null) {
334: query.append("ORDER BY ");
335: query.append(obc.getOrderBy());
336: }
337:
338: Query q = session.createQuery(query.toString());
339:
340: int queryPos = 0;
341:
342: q.setLong(queryPos++, userTrackerId);
343:
344: List list = QueryUtil.list(q, getDialect(), begin, end);
345:
346: FinderCache.putResult(finderClassNameCacheEnabled,
347: finderClassName, finderMethodName,
348: finderParams, finderArgs, list);
349:
350: return list;
351: } catch (Exception e) {
352: throw HibernateUtil.processException(e);
353: } finally {
354: closeSession(session);
355: }
356: } else {
357: return (List) result;
358: }
359: }
360:
361: public UserTrackerPath findByUserTrackerId_First(
362: long userTrackerId, OrderByComparator obc)
363: throws NoSuchUserTrackerPathException, SystemException {
364: List list = findByUserTrackerId(userTrackerId, 0, 1, obc);
365:
366: if (list.size() == 0) {
367: StringMaker msg = new StringMaker();
368:
369: msg.append("No UserTrackerPath exists with the key {");
370:
371: msg.append("userTrackerId=" + userTrackerId);
372:
373: msg.append(StringPool.CLOSE_CURLY_BRACE);
374:
375: throw new NoSuchUserTrackerPathException(msg.toString());
376: } else {
377: return (UserTrackerPath) list.get(0);
378: }
379: }
380:
381: public UserTrackerPath findByUserTrackerId_Last(long userTrackerId,
382: OrderByComparator obc)
383: throws NoSuchUserTrackerPathException, SystemException {
384: int count = countByUserTrackerId(userTrackerId);
385:
386: List list = findByUserTrackerId(userTrackerId, count - 1,
387: count, obc);
388:
389: if (list.size() == 0) {
390: StringMaker msg = new StringMaker();
391:
392: msg.append("No UserTrackerPath exists with the key {");
393:
394: msg.append("userTrackerId=" + userTrackerId);
395:
396: msg.append(StringPool.CLOSE_CURLY_BRACE);
397:
398: throw new NoSuchUserTrackerPathException(msg.toString());
399: } else {
400: return (UserTrackerPath) list.get(0);
401: }
402: }
403:
404: public UserTrackerPath[] findByUserTrackerId_PrevAndNext(
405: long userTrackerPathId, long userTrackerId,
406: OrderByComparator obc)
407: throws NoSuchUserTrackerPathException, SystemException {
408: UserTrackerPath userTrackerPath = findByPrimaryKey(userTrackerPathId);
409:
410: int count = countByUserTrackerId(userTrackerId);
411:
412: Session session = null;
413:
414: try {
415: session = openSession();
416:
417: StringMaker query = new StringMaker();
418:
419: query
420: .append("FROM com.liferay.portal.model.UserTrackerPath WHERE ");
421:
422: query.append("userTrackerId = ?");
423:
424: query.append(" ");
425:
426: if (obc != null) {
427: query.append("ORDER BY ");
428: query.append(obc.getOrderBy());
429: }
430:
431: Query q = session.createQuery(query.toString());
432:
433: int queryPos = 0;
434:
435: q.setLong(queryPos++, userTrackerId);
436:
437: Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
438: userTrackerPath);
439:
440: UserTrackerPath[] array = new UserTrackerPathImpl[3];
441:
442: array[0] = (UserTrackerPath) objArray[0];
443: array[1] = (UserTrackerPath) objArray[1];
444: array[2] = (UserTrackerPath) objArray[2];
445:
446: return array;
447: } catch (Exception e) {
448: throw HibernateUtil.processException(e);
449: } finally {
450: closeSession(session);
451: }
452: }
453:
454: public List findWithDynamicQuery(
455: DynamicQueryInitializer queryInitializer)
456: throws SystemException {
457: Session session = null;
458:
459: try {
460: session = openSession();
461:
462: DynamicQuery query = queryInitializer.initialize(session);
463:
464: return query.list();
465: } catch (Exception e) {
466: throw HibernateUtil.processException(e);
467: } finally {
468: closeSession(session);
469: }
470: }
471:
472: public List findWithDynamicQuery(
473: DynamicQueryInitializer queryInitializer, int begin, int end)
474: throws SystemException {
475: Session session = null;
476:
477: try {
478: session = openSession();
479:
480: DynamicQuery query = queryInitializer.initialize(session);
481:
482: query.setLimit(begin, end);
483:
484: return query.list();
485: } catch (Exception e) {
486: throw HibernateUtil.processException(e);
487: } finally {
488: closeSession(session);
489: }
490: }
491:
492: public List findAll() throws SystemException {
493: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
494: }
495:
496: public List findAll(int begin, int end) throws SystemException {
497: return findAll(begin, end, null);
498: }
499:
500: public List findAll(int begin, int end, OrderByComparator obc)
501: throws SystemException {
502: boolean finderClassNameCacheEnabled = UserTrackerPathModelImpl.CACHE_ENABLED;
503: String finderClassName = UserTrackerPath.class.getName();
504: String finderMethodName = "findAll";
505: String[] finderParams = new String[] { "java.lang.Integer",
506: "java.lang.Integer",
507: "com.liferay.portal.kernel.util.OrderByComparator" };
508: Object[] finderArgs = new Object[] { String.valueOf(begin),
509: String.valueOf(end), String.valueOf(obc) };
510:
511: Object result = null;
512:
513: if (finderClassNameCacheEnabled) {
514: result = FinderCache.getResult(finderClassName,
515: finderMethodName, finderParams, finderArgs,
516: getSessionFactory());
517: }
518:
519: if (result == null) {
520: Session session = null;
521:
522: try {
523: session = openSession();
524:
525: StringMaker query = new StringMaker();
526:
527: query
528: .append("FROM com.liferay.portal.model.UserTrackerPath ");
529:
530: if (obc != null) {
531: query.append("ORDER BY ");
532: query.append(obc.getOrderBy());
533: }
534:
535: Query q = session.createQuery(query.toString());
536:
537: List list = QueryUtil.list(q, getDialect(), begin, end);
538:
539: if (obc == null) {
540: Collections.sort(list);
541: }
542:
543: FinderCache.putResult(finderClassNameCacheEnabled,
544: finderClassName, finderMethodName,
545: finderParams, finderArgs, list);
546:
547: return list;
548: } catch (Exception e) {
549: throw HibernateUtil.processException(e);
550: } finally {
551: closeSession(session);
552: }
553: } else {
554: return (List) result;
555: }
556: }
557:
558: public void removeByUserTrackerId(long userTrackerId)
559: throws SystemException {
560: Iterator itr = findByUserTrackerId(userTrackerId).iterator();
561:
562: while (itr.hasNext()) {
563: UserTrackerPath userTrackerPath = (UserTrackerPath) itr
564: .next();
565:
566: remove(userTrackerPath);
567: }
568: }
569:
570: public void removeAll() throws SystemException {
571: Iterator itr = findAll().iterator();
572:
573: while (itr.hasNext()) {
574: remove((UserTrackerPath) itr.next());
575: }
576: }
577:
578: public int countByUserTrackerId(long userTrackerId)
579: throws SystemException {
580: boolean finderClassNameCacheEnabled = UserTrackerPathModelImpl.CACHE_ENABLED;
581: String finderClassName = UserTrackerPath.class.getName();
582: String finderMethodName = "countByUserTrackerId";
583: String[] finderParams = new String[] { Long.class.getName() };
584: Object[] finderArgs = new Object[] { new Long(userTrackerId) };
585:
586: Object result = null;
587:
588: if (finderClassNameCacheEnabled) {
589: result = FinderCache.getResult(finderClassName,
590: finderMethodName, finderParams, finderArgs,
591: getSessionFactory());
592: }
593:
594: if (result == null) {
595: Session session = null;
596:
597: try {
598: session = openSession();
599:
600: StringMaker query = new StringMaker();
601:
602: query.append("SELECT COUNT(*) ");
603: query
604: .append("FROM com.liferay.portal.model.UserTrackerPath WHERE ");
605:
606: query.append("userTrackerId = ?");
607:
608: query.append(" ");
609:
610: Query q = session.createQuery(query.toString());
611:
612: int queryPos = 0;
613:
614: q.setLong(queryPos++, userTrackerId);
615:
616: Long count = null;
617:
618: Iterator itr = q.list().iterator();
619:
620: if (itr.hasNext()) {
621: count = (Long) itr.next();
622: }
623:
624: if (count == null) {
625: count = new Long(0);
626: }
627:
628: FinderCache.putResult(finderClassNameCacheEnabled,
629: finderClassName, finderMethodName,
630: finderParams, finderArgs, count);
631:
632: return count.intValue();
633: } catch (Exception e) {
634: throw HibernateUtil.processException(e);
635: } finally {
636: closeSession(session);
637: }
638: } else {
639: return ((Long) result).intValue();
640: }
641: }
642:
643: public int countAll() throws SystemException {
644: boolean finderClassNameCacheEnabled = UserTrackerPathModelImpl.CACHE_ENABLED;
645: String finderClassName = UserTrackerPath.class.getName();
646: String finderMethodName = "countAll";
647: String[] finderParams = new String[] {};
648: Object[] finderArgs = new Object[] {};
649:
650: Object result = null;
651:
652: if (finderClassNameCacheEnabled) {
653: result = FinderCache.getResult(finderClassName,
654: finderMethodName, finderParams, finderArgs,
655: getSessionFactory());
656: }
657:
658: if (result == null) {
659: Session session = null;
660:
661: try {
662: session = openSession();
663:
664: Query q = session
665: .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.UserTrackerPath");
666:
667: Long count = null;
668:
669: Iterator itr = q.list().iterator();
670:
671: if (itr.hasNext()) {
672: count = (Long) itr.next();
673: }
674:
675: if (count == null) {
676: count = new Long(0);
677: }
678:
679: FinderCache.putResult(finderClassNameCacheEnabled,
680: finderClassName, finderMethodName,
681: finderParams, finderArgs, count);
682:
683: return count.intValue();
684: } catch (Exception e) {
685: throw HibernateUtil.processException(e);
686: } finally {
687: closeSession(session);
688: }
689: } else {
690: return ((Long) result).intValue();
691: }
692: }
693:
694: protected void initDao() {
695: }
696:
697: private static ModelListener _getListener() {
698: if (Validator.isNotNull(_LISTENER)) {
699: try {
700: return (ModelListener) Class.forName(_LISTENER)
701: .newInstance();
702: } catch (Exception e) {
703: _log.error(e);
704: }
705: }
706:
707: return null;
708: }
709:
710: private static final String _LISTENER = GetterUtil
711: .getString(PropsUtil
712: .get("value.object.listener.com.liferay.portal.model.UserTrackerPath"));
713: private static Log _log = LogFactory
714: .getLog(UserTrackerPathPersistenceImpl.class);
715: }
|