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