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.NoSuchPasswordPolicyRelException;
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.PasswordPolicyRel;
034: import com.liferay.portal.model.impl.PasswordPolicyRelImpl;
035: import com.liferay.portal.model.impl.PasswordPolicyRelModelImpl;
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="PasswordPolicyRelPersistenceImpl.java.html"><b><i>View Source</i></b></a>
054: *
055: * @author Brian Wing Shun Chan
056: *
057: */
058: public class PasswordPolicyRelPersistenceImpl extends BasePersistence
059: implements PasswordPolicyRelPersistence {
060: public PasswordPolicyRel create(long passwordPolicyRelId) {
061: PasswordPolicyRel passwordPolicyRel = new PasswordPolicyRelImpl();
062:
063: passwordPolicyRel.setNew(true);
064: passwordPolicyRel.setPrimaryKey(passwordPolicyRelId);
065:
066: return passwordPolicyRel;
067: }
068:
069: public PasswordPolicyRel remove(long passwordPolicyRelId)
070: throws NoSuchPasswordPolicyRelException, SystemException {
071: Session session = null;
072:
073: try {
074: session = openSession();
075:
076: PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel) session
077: .get(PasswordPolicyRelImpl.class, new Long(
078: passwordPolicyRelId));
079:
080: if (passwordPolicyRel == null) {
081: if (_log.isWarnEnabled()) {
082: _log
083: .warn("No PasswordPolicyRel exists with the primary key "
084: + passwordPolicyRelId);
085: }
086:
087: throw new NoSuchPasswordPolicyRelException(
088: "No PasswordPolicyRel exists with the primary key "
089: + passwordPolicyRelId);
090: }
091:
092: return remove(passwordPolicyRel);
093: } catch (NoSuchPasswordPolicyRelException nsee) {
094: throw nsee;
095: } catch (Exception e) {
096: throw HibernateUtil.processException(e);
097: } finally {
098: closeSession(session);
099: }
100: }
101:
102: public PasswordPolicyRel remove(PasswordPolicyRel passwordPolicyRel)
103: throws SystemException {
104: ModelListener listener = _getListener();
105:
106: if (listener != null) {
107: listener.onBeforeRemove(passwordPolicyRel);
108: }
109:
110: passwordPolicyRel = removeImpl(passwordPolicyRel);
111:
112: if (listener != null) {
113: listener.onAfterRemove(passwordPolicyRel);
114: }
115:
116: return passwordPolicyRel;
117: }
118:
119: protected PasswordPolicyRel removeImpl(
120: PasswordPolicyRel passwordPolicyRel) throws SystemException {
121: Session session = null;
122:
123: try {
124: session = openSession();
125:
126: session.delete(passwordPolicyRel);
127:
128: session.flush();
129:
130: return passwordPolicyRel;
131: } catch (Exception e) {
132: throw HibernateUtil.processException(e);
133: } finally {
134: closeSession(session);
135:
136: FinderCache.clearCache(PasswordPolicyRel.class.getName());
137: }
138: }
139:
140: public PasswordPolicyRel update(PasswordPolicyRel passwordPolicyRel)
141: throws SystemException {
142: return update(passwordPolicyRel, false);
143: }
144:
145: public PasswordPolicyRel update(
146: PasswordPolicyRel passwordPolicyRel, boolean merge)
147: throws SystemException {
148: ModelListener listener = _getListener();
149:
150: boolean isNew = passwordPolicyRel.isNew();
151:
152: if (listener != null) {
153: if (isNew) {
154: listener.onBeforeCreate(passwordPolicyRel);
155: } else {
156: listener.onBeforeUpdate(passwordPolicyRel);
157: }
158: }
159:
160: passwordPolicyRel = updateImpl(passwordPolicyRel, merge);
161:
162: if (listener != null) {
163: if (isNew) {
164: listener.onAfterCreate(passwordPolicyRel);
165: } else {
166: listener.onAfterUpdate(passwordPolicyRel);
167: }
168: }
169:
170: return passwordPolicyRel;
171: }
172:
173: public PasswordPolicyRel updateImpl(
174: com.liferay.portal.model.PasswordPolicyRel passwordPolicyRel,
175: boolean merge) throws SystemException {
176: Session session = null;
177:
178: try {
179: session = openSession();
180:
181: if (merge) {
182: session.merge(passwordPolicyRel);
183: } else {
184: if (passwordPolicyRel.isNew()) {
185: session.save(passwordPolicyRel);
186: }
187: }
188:
189: session.flush();
190:
191: passwordPolicyRel.setNew(false);
192:
193: return passwordPolicyRel;
194: } catch (Exception e) {
195: throw HibernateUtil.processException(e);
196: } finally {
197: closeSession(session);
198:
199: FinderCache.clearCache(PasswordPolicyRel.class.getName());
200: }
201: }
202:
203: public PasswordPolicyRel findByPrimaryKey(long passwordPolicyRelId)
204: throws NoSuchPasswordPolicyRelException, SystemException {
205: PasswordPolicyRel passwordPolicyRel = fetchByPrimaryKey(passwordPolicyRelId);
206:
207: if (passwordPolicyRel == null) {
208: if (_log.isWarnEnabled()) {
209: _log
210: .warn("No PasswordPolicyRel exists with the primary key "
211: + passwordPolicyRelId);
212: }
213:
214: throw new NoSuchPasswordPolicyRelException(
215: "No PasswordPolicyRel exists with the primary key "
216: + passwordPolicyRelId);
217: }
218:
219: return passwordPolicyRel;
220: }
221:
222: public PasswordPolicyRel fetchByPrimaryKey(long passwordPolicyRelId)
223: throws SystemException {
224: Session session = null;
225:
226: try {
227: session = openSession();
228:
229: return (PasswordPolicyRel) session.get(
230: PasswordPolicyRelImpl.class, new Long(
231: passwordPolicyRelId));
232: } catch (Exception e) {
233: throw HibernateUtil.processException(e);
234: } finally {
235: closeSession(session);
236: }
237: }
238:
239: public PasswordPolicyRel findByC_C(long classNameId, long classPK)
240: throws NoSuchPasswordPolicyRelException, SystemException {
241: PasswordPolicyRel passwordPolicyRel = fetchByC_C(classNameId,
242: classPK);
243:
244: if (passwordPolicyRel == null) {
245: StringMaker msg = new StringMaker();
246:
247: msg.append("No PasswordPolicyRel exists with the key {");
248:
249: msg.append("classNameId=" + classNameId);
250:
251: msg.append(", ");
252: msg.append("classPK=" + classPK);
253:
254: msg.append(StringPool.CLOSE_CURLY_BRACE);
255:
256: if (_log.isWarnEnabled()) {
257: _log.warn(msg.toString());
258: }
259:
260: throw new NoSuchPasswordPolicyRelException(msg.toString());
261: }
262:
263: return passwordPolicyRel;
264: }
265:
266: public PasswordPolicyRel fetchByC_C(long classNameId, long classPK)
267: throws SystemException {
268: boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
269: String finderClassName = PasswordPolicyRel.class.getName();
270: String finderMethodName = "fetchByC_C";
271: String[] finderParams = new String[] { Long.class.getName(),
272: Long.class.getName() };
273: Object[] finderArgs = new Object[] { new Long(classNameId),
274: new Long(classPK) };
275:
276: Object result = null;
277:
278: if (finderClassNameCacheEnabled) {
279: result = FinderCache.getResult(finderClassName,
280: finderMethodName, finderParams, finderArgs,
281: getSessionFactory());
282: }
283:
284: if (result == null) {
285: Session session = null;
286:
287: try {
288: session = openSession();
289:
290: StringMaker query = new StringMaker();
291:
292: query
293: .append("FROM com.liferay.portal.model.PasswordPolicyRel WHERE ");
294:
295: query.append("classNameId = ?");
296:
297: query.append(" AND ");
298:
299: query.append("classPK = ?");
300:
301: query.append(" ");
302:
303: Query q = session.createQuery(query.toString());
304:
305: int queryPos = 0;
306:
307: q.setLong(queryPos++, classNameId);
308:
309: q.setLong(queryPos++, classPK);
310:
311: List list = q.list();
312:
313: FinderCache.putResult(finderClassNameCacheEnabled,
314: finderClassName, finderMethodName,
315: finderParams, finderArgs, list);
316:
317: if (list.size() == 0) {
318: return null;
319: } else {
320: return (PasswordPolicyRel) list.get(0);
321: }
322: } catch (Exception e) {
323: throw HibernateUtil.processException(e);
324: } finally {
325: closeSession(session);
326: }
327: } else {
328: List list = (List) result;
329:
330: if (list.size() == 0) {
331: return null;
332: } else {
333: return (PasswordPolicyRel) list.get(0);
334: }
335: }
336: }
337:
338: public PasswordPolicyRel findByP_C_C(long passwordPolicyId,
339: long classNameId, long classPK)
340: throws NoSuchPasswordPolicyRelException, SystemException {
341: PasswordPolicyRel passwordPolicyRel = fetchByP_C_C(
342: passwordPolicyId, classNameId, classPK);
343:
344: if (passwordPolicyRel == null) {
345: StringMaker msg = new StringMaker();
346:
347: msg.append("No PasswordPolicyRel exists with the key {");
348:
349: msg.append("passwordPolicyId=" + passwordPolicyId);
350:
351: msg.append(", ");
352: msg.append("classNameId=" + classNameId);
353:
354: msg.append(", ");
355: msg.append("classPK=" + classPK);
356:
357: msg.append(StringPool.CLOSE_CURLY_BRACE);
358:
359: if (_log.isWarnEnabled()) {
360: _log.warn(msg.toString());
361: }
362:
363: throw new NoSuchPasswordPolicyRelException(msg.toString());
364: }
365:
366: return passwordPolicyRel;
367: }
368:
369: public PasswordPolicyRel fetchByP_C_C(long passwordPolicyId,
370: long classNameId, long classPK) throws SystemException {
371: boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
372: String finderClassName = PasswordPolicyRel.class.getName();
373: String finderMethodName = "fetchByP_C_C";
374: String[] finderParams = new String[] { Long.class.getName(),
375: Long.class.getName(), Long.class.getName() };
376: Object[] finderArgs = new Object[] {
377: new Long(passwordPolicyId), new Long(classNameId),
378: new Long(classPK) };
379:
380: Object result = null;
381:
382: if (finderClassNameCacheEnabled) {
383: result = FinderCache.getResult(finderClassName,
384: finderMethodName, finderParams, finderArgs,
385: getSessionFactory());
386: }
387:
388: if (result == null) {
389: Session session = null;
390:
391: try {
392: session = openSession();
393:
394: StringMaker query = new StringMaker();
395:
396: query
397: .append("FROM com.liferay.portal.model.PasswordPolicyRel WHERE ");
398:
399: query.append("passwordPolicyId = ?");
400:
401: query.append(" AND ");
402:
403: query.append("classNameId = ?");
404:
405: query.append(" AND ");
406:
407: query.append("classPK = ?");
408:
409: query.append(" ");
410:
411: Query q = session.createQuery(query.toString());
412:
413: int queryPos = 0;
414:
415: q.setLong(queryPos++, passwordPolicyId);
416:
417: q.setLong(queryPos++, classNameId);
418:
419: q.setLong(queryPos++, classPK);
420:
421: List list = q.list();
422:
423: FinderCache.putResult(finderClassNameCacheEnabled,
424: finderClassName, finderMethodName,
425: finderParams, finderArgs, list);
426:
427: if (list.size() == 0) {
428: return null;
429: } else {
430: return (PasswordPolicyRel) list.get(0);
431: }
432: } catch (Exception e) {
433: throw HibernateUtil.processException(e);
434: } finally {
435: closeSession(session);
436: }
437: } else {
438: List list = (List) result;
439:
440: if (list.size() == 0) {
441: return null;
442: } else {
443: return (PasswordPolicyRel) list.get(0);
444: }
445: }
446: }
447:
448: public List findWithDynamicQuery(
449: DynamicQueryInitializer queryInitializer)
450: throws SystemException {
451: Session session = null;
452:
453: try {
454: session = openSession();
455:
456: DynamicQuery query = queryInitializer.initialize(session);
457:
458: return query.list();
459: } catch (Exception e) {
460: throw HibernateUtil.processException(e);
461: } finally {
462: closeSession(session);
463: }
464: }
465:
466: public List findWithDynamicQuery(
467: DynamicQueryInitializer queryInitializer, int begin, int end)
468: throws SystemException {
469: Session session = null;
470:
471: try {
472: session = openSession();
473:
474: DynamicQuery query = queryInitializer.initialize(session);
475:
476: query.setLimit(begin, end);
477:
478: return query.list();
479: } catch (Exception e) {
480: throw HibernateUtil.processException(e);
481: } finally {
482: closeSession(session);
483: }
484: }
485:
486: public List findAll() throws SystemException {
487: return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
488: }
489:
490: public List findAll(int begin, int end) throws SystemException {
491: return findAll(begin, end, null);
492: }
493:
494: public List findAll(int begin, int end, OrderByComparator obc)
495: throws SystemException {
496: boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
497: String finderClassName = PasswordPolicyRel.class.getName();
498: String finderMethodName = "findAll";
499: String[] finderParams = new String[] { "java.lang.Integer",
500: "java.lang.Integer",
501: "com.liferay.portal.kernel.util.OrderByComparator" };
502: Object[] finderArgs = new Object[] { String.valueOf(begin),
503: String.valueOf(end), String.valueOf(obc) };
504:
505: Object result = null;
506:
507: if (finderClassNameCacheEnabled) {
508: result = FinderCache.getResult(finderClassName,
509: finderMethodName, finderParams, finderArgs,
510: getSessionFactory());
511: }
512:
513: if (result == null) {
514: Session session = null;
515:
516: try {
517: session = openSession();
518:
519: StringMaker query = new StringMaker();
520:
521: query
522: .append("FROM com.liferay.portal.model.PasswordPolicyRel ");
523:
524: if (obc != null) {
525: query.append("ORDER BY ");
526: query.append(obc.getOrderBy());
527: }
528:
529: Query q = session.createQuery(query.toString());
530:
531: List list = QueryUtil.list(q, getDialect(), begin, end);
532:
533: if (obc == null) {
534: Collections.sort(list);
535: }
536:
537: FinderCache.putResult(finderClassNameCacheEnabled,
538: finderClassName, finderMethodName,
539: finderParams, finderArgs, list);
540:
541: return list;
542: } catch (Exception e) {
543: throw HibernateUtil.processException(e);
544: } finally {
545: closeSession(session);
546: }
547: } else {
548: return (List) result;
549: }
550: }
551:
552: public void removeByC_C(long classNameId, long classPK)
553: throws NoSuchPasswordPolicyRelException, SystemException {
554: PasswordPolicyRel passwordPolicyRel = findByC_C(classNameId,
555: classPK);
556:
557: remove(passwordPolicyRel);
558: }
559:
560: public void removeByP_C_C(long passwordPolicyId, long classNameId,
561: long classPK) throws NoSuchPasswordPolicyRelException,
562: SystemException {
563: PasswordPolicyRel passwordPolicyRel = findByP_C_C(
564: passwordPolicyId, classNameId, classPK);
565:
566: remove(passwordPolicyRel);
567: }
568:
569: public void removeAll() throws SystemException {
570: Iterator itr = findAll().iterator();
571:
572: while (itr.hasNext()) {
573: remove((PasswordPolicyRel) itr.next());
574: }
575: }
576:
577: public int countByC_C(long classNameId, long classPK)
578: throws SystemException {
579: boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
580: String finderClassName = PasswordPolicyRel.class.getName();
581: String finderMethodName = "countByC_C";
582: String[] finderParams = new String[] { Long.class.getName(),
583: Long.class.getName() };
584: Object[] finderArgs = new Object[] { new Long(classNameId),
585: new Long(classPK) };
586:
587: Object result = null;
588:
589: if (finderClassNameCacheEnabled) {
590: result = FinderCache.getResult(finderClassName,
591: finderMethodName, finderParams, finderArgs,
592: getSessionFactory());
593: }
594:
595: if (result == null) {
596: Session session = null;
597:
598: try {
599: session = openSession();
600:
601: StringMaker query = new StringMaker();
602:
603: query.append("SELECT COUNT(*) ");
604: query
605: .append("FROM com.liferay.portal.model.PasswordPolicyRel WHERE ");
606:
607: query.append("classNameId = ?");
608:
609: query.append(" AND ");
610:
611: query.append("classPK = ?");
612:
613: query.append(" ");
614:
615: Query q = session.createQuery(query.toString());
616:
617: int queryPos = 0;
618:
619: q.setLong(queryPos++, classNameId);
620:
621: q.setLong(queryPos++, classPK);
622:
623: Long count = null;
624:
625: Iterator itr = q.list().iterator();
626:
627: if (itr.hasNext()) {
628: count = (Long) itr.next();
629: }
630:
631: if (count == null) {
632: count = new Long(0);
633: }
634:
635: FinderCache.putResult(finderClassNameCacheEnabled,
636: finderClassName, finderMethodName,
637: finderParams, finderArgs, count);
638:
639: return count.intValue();
640: } catch (Exception e) {
641: throw HibernateUtil.processException(e);
642: } finally {
643: closeSession(session);
644: }
645: } else {
646: return ((Long) result).intValue();
647: }
648: }
649:
650: public int countByP_C_C(long passwordPolicyId, long classNameId,
651: long classPK) throws SystemException {
652: boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
653: String finderClassName = PasswordPolicyRel.class.getName();
654: String finderMethodName = "countByP_C_C";
655: String[] finderParams = new String[] { Long.class.getName(),
656: Long.class.getName(), Long.class.getName() };
657: Object[] finderArgs = new Object[] {
658: new Long(passwordPolicyId), new Long(classNameId),
659: new Long(classPK) };
660:
661: Object result = null;
662:
663: if (finderClassNameCacheEnabled) {
664: result = FinderCache.getResult(finderClassName,
665: finderMethodName, finderParams, finderArgs,
666: getSessionFactory());
667: }
668:
669: if (result == null) {
670: Session session = null;
671:
672: try {
673: session = openSession();
674:
675: StringMaker query = new StringMaker();
676:
677: query.append("SELECT COUNT(*) ");
678: query
679: .append("FROM com.liferay.portal.model.PasswordPolicyRel WHERE ");
680:
681: query.append("passwordPolicyId = ?");
682:
683: query.append(" AND ");
684:
685: query.append("classNameId = ?");
686:
687: query.append(" AND ");
688:
689: query.append("classPK = ?");
690:
691: query.append(" ");
692:
693: Query q = session.createQuery(query.toString());
694:
695: int queryPos = 0;
696:
697: q.setLong(queryPos++, passwordPolicyId);
698:
699: q.setLong(queryPos++, classNameId);
700:
701: q.setLong(queryPos++, classPK);
702:
703: Long count = null;
704:
705: Iterator itr = q.list().iterator();
706:
707: if (itr.hasNext()) {
708: count = (Long) itr.next();
709: }
710:
711: if (count == null) {
712: count = new Long(0);
713: }
714:
715: FinderCache.putResult(finderClassNameCacheEnabled,
716: finderClassName, finderMethodName,
717: finderParams, finderArgs, count);
718:
719: return count.intValue();
720: } catch (Exception e) {
721: throw HibernateUtil.processException(e);
722: } finally {
723: closeSession(session);
724: }
725: } else {
726: return ((Long) result).intValue();
727: }
728: }
729:
730: public int countAll() throws SystemException {
731: boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
732: String finderClassName = PasswordPolicyRel.class.getName();
733: String finderMethodName = "countAll";
734: String[] finderParams = new String[] {};
735: Object[] finderArgs = new Object[] {};
736:
737: Object result = null;
738:
739: if (finderClassNameCacheEnabled) {
740: result = FinderCache.getResult(finderClassName,
741: finderMethodName, finderParams, finderArgs,
742: getSessionFactory());
743: }
744:
745: if (result == null) {
746: Session session = null;
747:
748: try {
749: session = openSession();
750:
751: Query q = session
752: .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.PasswordPolicyRel");
753:
754: Long count = null;
755:
756: Iterator itr = q.list().iterator();
757:
758: if (itr.hasNext()) {
759: count = (Long) itr.next();
760: }
761:
762: if (count == null) {
763: count = new Long(0);
764: }
765:
766: FinderCache.putResult(finderClassNameCacheEnabled,
767: finderClassName, finderMethodName,
768: finderParams, finderArgs, count);
769:
770: return count.intValue();
771: } catch (Exception e) {
772: throw HibernateUtil.processException(e);
773: } finally {
774: closeSession(session);
775: }
776: } else {
777: return ((Long) result).intValue();
778: }
779: }
780:
781: protected void initDao() {
782: }
783:
784: private static ModelListener _getListener() {
785: if (Validator.isNotNull(_LISTENER)) {
786: try {
787: return (ModelListener) Class.forName(_LISTENER)
788: .newInstance();
789: } catch (Exception e) {
790: _log.error(e);
791: }
792: }
793:
794: return null;
795: }
796:
797: private static final String _LISTENER = GetterUtil
798: .getString(PropsUtil
799: .get("value.object.listener.com.liferay.portal.model.PasswordPolicyRel"));
800: private static Log _log = LogFactory
801: .getLog(PasswordPolicyRelPersistenceImpl.class);
802: }
|