1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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.StringUtil;
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.ArrayList;
51  import java.util.Collections;
52  import java.util.Iterator;
53  import java.util.List;
54  
55  /**
56   * <a href="PasswordPolicyRelPersistenceImpl.java.html"><b><i>View Source</i></b></a>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   */
61  public class PasswordPolicyRelPersistenceImpl extends BasePersistence
62      implements PasswordPolicyRelPersistence {
63      public PasswordPolicyRel create(long passwordPolicyRelId) {
64          PasswordPolicyRel passwordPolicyRel = new PasswordPolicyRelImpl();
65  
66          passwordPolicyRel.setNew(true);
67          passwordPolicyRel.setPrimaryKey(passwordPolicyRelId);
68  
69          return passwordPolicyRel;
70      }
71  
72      public PasswordPolicyRel remove(long passwordPolicyRelId)
73          throws NoSuchPasswordPolicyRelException, SystemException {
74          Session session = null;
75  
76          try {
77              session = openSession();
78  
79              PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
80                      new Long(passwordPolicyRelId));
81  
82              if (passwordPolicyRel == null) {
83                  if (_log.isWarnEnabled()) {
84                      _log.warn(
85                          "No PasswordPolicyRel exists with the primary key " +
86                          passwordPolicyRelId);
87                  }
88  
89                  throw new NoSuchPasswordPolicyRelException(
90                      "No PasswordPolicyRel exists with the primary key " +
91                      passwordPolicyRelId);
92              }
93  
94              return remove(passwordPolicyRel);
95          }
96          catch (NoSuchPasswordPolicyRelException nsee) {
97              throw nsee;
98          }
99          catch (Exception e) {
100             throw HibernateUtil.processException(e);
101         }
102         finally {
103             closeSession(session);
104         }
105     }
106 
107     public PasswordPolicyRel remove(PasswordPolicyRel passwordPolicyRel)
108         throws SystemException {
109         if (_listeners != null) {
110             for (ModelListener listener : _listeners) {
111                 listener.onBeforeRemove(passwordPolicyRel);
112             }
113         }
114 
115         passwordPolicyRel = removeImpl(passwordPolicyRel);
116 
117         if (_listeners != null) {
118             for (ModelListener listener : _listeners) {
119                 listener.onAfterRemove(passwordPolicyRel);
120             }
121         }
122 
123         return passwordPolicyRel;
124     }
125 
126     protected PasswordPolicyRel removeImpl(PasswordPolicyRel passwordPolicyRel)
127         throws SystemException {
128         Session session = null;
129 
130         try {
131             session = openSession();
132 
133             session.delete(passwordPolicyRel);
134 
135             session.flush();
136 
137             return passwordPolicyRel;
138         }
139         catch (Exception e) {
140             throw HibernateUtil.processException(e);
141         }
142         finally {
143             closeSession(session);
144 
145             FinderCache.clearCache(PasswordPolicyRel.class.getName());
146         }
147     }
148 
149     /**
150      * @deprecated Use <code>update(PasswordPolicyRel passwordPolicyRel, boolean merge)</code>.
151      */
152     public PasswordPolicyRel update(PasswordPolicyRel passwordPolicyRel)
153         throws SystemException {
154         if (_log.isWarnEnabled()) {
155             _log.warn(
156                 "Using the deprecated update(PasswordPolicyRel passwordPolicyRel) method. Use update(PasswordPolicyRel passwordPolicyRel, boolean merge) instead.");
157         }
158 
159         return update(passwordPolicyRel, false);
160     }
161 
162     /**
163      * Add, update, or merge, the entity. This method also calls the model
164      * listeners to trigger the proper events associated with adding, deleting,
165      * or updating an entity.
166      *
167      * @param        passwordPolicyRel the entity to add, update, or merge
168      * @param        merge boolean value for whether to merge the entity. The
169      *                default value is false. Setting merge to true is more
170      *                expensive and should only be true when passwordPolicyRel is
171      *                transient. See LEP-5473 for a detailed discussion of this
172      *                method.
173      * @return        true if the portlet can be displayed via Ajax
174      */
175     public PasswordPolicyRel update(PasswordPolicyRel passwordPolicyRel,
176         boolean merge) throws SystemException {
177         boolean isNew = passwordPolicyRel.isNew();
178 
179         if (_listeners != null) {
180             for (ModelListener listener : _listeners) {
181                 if (isNew) {
182                     listener.onBeforeCreate(passwordPolicyRel);
183                 }
184                 else {
185                     listener.onBeforeUpdate(passwordPolicyRel);
186                 }
187             }
188         }
189 
190         passwordPolicyRel = updateImpl(passwordPolicyRel, merge);
191 
192         if (_listeners != null) {
193             for (ModelListener listener : _listeners) {
194                 if (isNew) {
195                     listener.onAfterCreate(passwordPolicyRel);
196                 }
197                 else {
198                     listener.onAfterUpdate(passwordPolicyRel);
199                 }
200             }
201         }
202 
203         return passwordPolicyRel;
204     }
205 
206     public PasswordPolicyRel updateImpl(
207         com.liferay.portal.model.PasswordPolicyRel passwordPolicyRel,
208         boolean merge) throws SystemException {
209         Session session = null;
210 
211         try {
212             session = openSession();
213 
214             if (merge) {
215                 session.merge(passwordPolicyRel);
216             }
217             else {
218                 if (passwordPolicyRel.isNew()) {
219                     session.save(passwordPolicyRel);
220                 }
221             }
222 
223             session.flush();
224 
225             passwordPolicyRel.setNew(false);
226 
227             return passwordPolicyRel;
228         }
229         catch (Exception e) {
230             throw HibernateUtil.processException(e);
231         }
232         finally {
233             closeSession(session);
234 
235             FinderCache.clearCache(PasswordPolicyRel.class.getName());
236         }
237     }
238 
239     public PasswordPolicyRel findByPrimaryKey(long passwordPolicyRelId)
240         throws NoSuchPasswordPolicyRelException, SystemException {
241         PasswordPolicyRel passwordPolicyRel = fetchByPrimaryKey(passwordPolicyRelId);
242 
243         if (passwordPolicyRel == null) {
244             if (_log.isWarnEnabled()) {
245                 _log.warn("No PasswordPolicyRel exists with the primary key " +
246                     passwordPolicyRelId);
247             }
248 
249             throw new NoSuchPasswordPolicyRelException(
250                 "No PasswordPolicyRel exists with the primary key " +
251                 passwordPolicyRelId);
252         }
253 
254         return passwordPolicyRel;
255     }
256 
257     public PasswordPolicyRel fetchByPrimaryKey(long passwordPolicyRelId)
258         throws SystemException {
259         Session session = null;
260 
261         try {
262             session = openSession();
263 
264             return (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
265                 new Long(passwordPolicyRelId));
266         }
267         catch (Exception e) {
268             throw HibernateUtil.processException(e);
269         }
270         finally {
271             closeSession(session);
272         }
273     }
274 
275     public PasswordPolicyRel findByC_C(long classNameId, long classPK)
276         throws NoSuchPasswordPolicyRelException, SystemException {
277         PasswordPolicyRel passwordPolicyRel = fetchByC_C(classNameId, classPK);
278 
279         if (passwordPolicyRel == null) {
280             StringMaker msg = new StringMaker();
281 
282             msg.append("No PasswordPolicyRel exists with the key {");
283 
284             msg.append("classNameId=" + classNameId);
285 
286             msg.append(", ");
287             msg.append("classPK=" + classPK);
288 
289             msg.append(StringPool.CLOSE_CURLY_BRACE);
290 
291             if (_log.isWarnEnabled()) {
292                 _log.warn(msg.toString());
293             }
294 
295             throw new NoSuchPasswordPolicyRelException(msg.toString());
296         }
297 
298         return passwordPolicyRel;
299     }
300 
301     public PasswordPolicyRel fetchByC_C(long classNameId, long classPK)
302         throws SystemException {
303         boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
304         String finderClassName = PasswordPolicyRel.class.getName();
305         String finderMethodName = "fetchByC_C";
306         String[] finderParams = new String[] {
307                 Long.class.getName(), Long.class.getName()
308             };
309         Object[] finderArgs = new Object[] {
310                 new Long(classNameId), new Long(classPK)
311             };
312 
313         Object result = null;
314 
315         if (finderClassNameCacheEnabled) {
316             result = FinderCache.getResult(finderClassName, finderMethodName,
317                     finderParams, finderArgs, getSessionFactory());
318         }
319 
320         if (result == null) {
321             Session session = null;
322 
323             try {
324                 session = openSession();
325 
326                 StringMaker query = new StringMaker();
327 
328                 query.append(
329                     "FROM com.liferay.portal.model.PasswordPolicyRel WHERE ");
330 
331                 query.append("classNameId = ?");
332 
333                 query.append(" AND ");
334 
335                 query.append("classPK = ?");
336 
337                 query.append(" ");
338 
339                 Query q = session.createQuery(query.toString());
340 
341                 int queryPos = 0;
342 
343                 q.setLong(queryPos++, classNameId);
344 
345                 q.setLong(queryPos++, classPK);
346 
347                 List<PasswordPolicyRel> list = q.list();
348 
349                 FinderCache.putResult(finderClassNameCacheEnabled,
350                     finderClassName, finderMethodName, finderParams,
351                     finderArgs, list);
352 
353                 if (list.size() == 0) {
354                     return null;
355                 }
356                 else {
357                     return list.get(0);
358                 }
359             }
360             catch (Exception e) {
361                 throw HibernateUtil.processException(e);
362             }
363             finally {
364                 closeSession(session);
365             }
366         }
367         else {
368             List<PasswordPolicyRel> list = (List<PasswordPolicyRel>)result;
369 
370             if (list.size() == 0) {
371                 return null;
372             }
373             else {
374                 return list.get(0);
375             }
376         }
377     }
378 
379     public PasswordPolicyRel findByP_C_C(long passwordPolicyId,
380         long classNameId, long classPK)
381         throws NoSuchPasswordPolicyRelException, SystemException {
382         PasswordPolicyRel passwordPolicyRel = fetchByP_C_C(passwordPolicyId,
383                 classNameId, classPK);
384 
385         if (passwordPolicyRel == null) {
386             StringMaker msg = new StringMaker();
387 
388             msg.append("No PasswordPolicyRel exists with the key {");
389 
390             msg.append("passwordPolicyId=" + passwordPolicyId);
391 
392             msg.append(", ");
393             msg.append("classNameId=" + classNameId);
394 
395             msg.append(", ");
396             msg.append("classPK=" + classPK);
397 
398             msg.append(StringPool.CLOSE_CURLY_BRACE);
399 
400             if (_log.isWarnEnabled()) {
401                 _log.warn(msg.toString());
402             }
403 
404             throw new NoSuchPasswordPolicyRelException(msg.toString());
405         }
406 
407         return passwordPolicyRel;
408     }
409 
410     public PasswordPolicyRel fetchByP_C_C(long passwordPolicyId,
411         long classNameId, long classPK) throws SystemException {
412         boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
413         String finderClassName = PasswordPolicyRel.class.getName();
414         String finderMethodName = "fetchByP_C_C";
415         String[] finderParams = new String[] {
416                 Long.class.getName(), Long.class.getName(), Long.class.getName()
417             };
418         Object[] finderArgs = new Object[] {
419                 new Long(passwordPolicyId), new Long(classNameId),
420                 new Long(classPK)
421             };
422 
423         Object result = null;
424 
425         if (finderClassNameCacheEnabled) {
426             result = FinderCache.getResult(finderClassName, finderMethodName,
427                     finderParams, finderArgs, getSessionFactory());
428         }
429 
430         if (result == null) {
431             Session session = null;
432 
433             try {
434                 session = openSession();
435 
436                 StringMaker query = new StringMaker();
437 
438                 query.append(
439                     "FROM com.liferay.portal.model.PasswordPolicyRel WHERE ");
440 
441                 query.append("passwordPolicyId = ?");
442 
443                 query.append(" AND ");
444 
445                 query.append("classNameId = ?");
446 
447                 query.append(" AND ");
448 
449                 query.append("classPK = ?");
450 
451                 query.append(" ");
452 
453                 Query q = session.createQuery(query.toString());
454 
455                 int queryPos = 0;
456 
457                 q.setLong(queryPos++, passwordPolicyId);
458 
459                 q.setLong(queryPos++, classNameId);
460 
461                 q.setLong(queryPos++, classPK);
462 
463                 List<PasswordPolicyRel> list = q.list();
464 
465                 FinderCache.putResult(finderClassNameCacheEnabled,
466                     finderClassName, finderMethodName, finderParams,
467                     finderArgs, list);
468 
469                 if (list.size() == 0) {
470                     return null;
471                 }
472                 else {
473                     return list.get(0);
474                 }
475             }
476             catch (Exception e) {
477                 throw HibernateUtil.processException(e);
478             }
479             finally {
480                 closeSession(session);
481             }
482         }
483         else {
484             List<PasswordPolicyRel> list = (List<PasswordPolicyRel>)result;
485 
486             if (list.size() == 0) {
487                 return null;
488             }
489             else {
490                 return list.get(0);
491             }
492         }
493     }
494 
495     public List<PasswordPolicyRel> findWithDynamicQuery(
496         DynamicQueryInitializer queryInitializer) throws SystemException {
497         Session session = null;
498 
499         try {
500             session = openSession();
501 
502             DynamicQuery query = queryInitializer.initialize(session);
503 
504             return query.list();
505         }
506         catch (Exception e) {
507             throw HibernateUtil.processException(e);
508         }
509         finally {
510             closeSession(session);
511         }
512     }
513 
514     public List<PasswordPolicyRel> findWithDynamicQuery(
515         DynamicQueryInitializer queryInitializer, int begin, int end)
516         throws SystemException {
517         Session session = null;
518 
519         try {
520             session = openSession();
521 
522             DynamicQuery query = queryInitializer.initialize(session);
523 
524             query.setLimit(begin, end);
525 
526             return query.list();
527         }
528         catch (Exception e) {
529             throw HibernateUtil.processException(e);
530         }
531         finally {
532             closeSession(session);
533         }
534     }
535 
536     public List<PasswordPolicyRel> findAll() throws SystemException {
537         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
538     }
539 
540     public List<PasswordPolicyRel> findAll(int begin, int end)
541         throws SystemException {
542         return findAll(begin, end, null);
543     }
544 
545     public List<PasswordPolicyRel> findAll(int begin, int end,
546         OrderByComparator obc) throws SystemException {
547         boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
548         String finderClassName = PasswordPolicyRel.class.getName();
549         String finderMethodName = "findAll";
550         String[] finderParams = new String[] {
551                 "java.lang.Integer", "java.lang.Integer",
552                 "com.liferay.portal.kernel.util.OrderByComparator"
553             };
554         Object[] finderArgs = new Object[] {
555                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
556             };
557 
558         Object result = null;
559 
560         if (finderClassNameCacheEnabled) {
561             result = FinderCache.getResult(finderClassName, finderMethodName,
562                     finderParams, finderArgs, getSessionFactory());
563         }
564 
565         if (result == null) {
566             Session session = null;
567 
568             try {
569                 session = openSession();
570 
571                 StringMaker query = new StringMaker();
572 
573                 query.append("FROM com.liferay.portal.model.PasswordPolicyRel ");
574 
575                 if (obc != null) {
576                     query.append("ORDER BY ");
577                     query.append(obc.getOrderBy());
578                 }
579 
580                 Query q = session.createQuery(query.toString());
581 
582                 List<PasswordPolicyRel> list = (List<PasswordPolicyRel>)QueryUtil.list(q,
583                         getDialect(), begin, end);
584 
585                 if (obc == null) {
586                     Collections.sort(list);
587                 }
588 
589                 FinderCache.putResult(finderClassNameCacheEnabled,
590                     finderClassName, finderMethodName, finderParams,
591                     finderArgs, list);
592 
593                 return list;
594             }
595             catch (Exception e) {
596                 throw HibernateUtil.processException(e);
597             }
598             finally {
599                 closeSession(session);
600             }
601         }
602         else {
603             return (List<PasswordPolicyRel>)result;
604         }
605     }
606 
607     public void removeByC_C(long classNameId, long classPK)
608         throws NoSuchPasswordPolicyRelException, SystemException {
609         PasswordPolicyRel passwordPolicyRel = findByC_C(classNameId, classPK);
610 
611         remove(passwordPolicyRel);
612     }
613 
614     public void removeByP_C_C(long passwordPolicyId, long classNameId,
615         long classPK) throws NoSuchPasswordPolicyRelException, SystemException {
616         PasswordPolicyRel passwordPolicyRel = findByP_C_C(passwordPolicyId,
617                 classNameId, classPK);
618 
619         remove(passwordPolicyRel);
620     }
621 
622     public void removeAll() throws SystemException {
623         for (PasswordPolicyRel passwordPolicyRel : findAll()) {
624             remove(passwordPolicyRel);
625         }
626     }
627 
628     public int countByC_C(long classNameId, long classPK)
629         throws SystemException {
630         boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
631         String finderClassName = PasswordPolicyRel.class.getName();
632         String finderMethodName = "countByC_C";
633         String[] finderParams = new String[] {
634                 Long.class.getName(), Long.class.getName()
635             };
636         Object[] finderArgs = new Object[] {
637                 new Long(classNameId), new Long(classPK)
638             };
639 
640         Object result = null;
641 
642         if (finderClassNameCacheEnabled) {
643             result = FinderCache.getResult(finderClassName, finderMethodName,
644                     finderParams, finderArgs, getSessionFactory());
645         }
646 
647         if (result == null) {
648             Session session = null;
649 
650             try {
651                 session = openSession();
652 
653                 StringMaker query = new StringMaker();
654 
655                 query.append("SELECT COUNT(*) ");
656                 query.append(
657                     "FROM com.liferay.portal.model.PasswordPolicyRel WHERE ");
658 
659                 query.append("classNameId = ?");
660 
661                 query.append(" AND ");
662 
663                 query.append("classPK = ?");
664 
665                 query.append(" ");
666 
667                 Query q = session.createQuery(query.toString());
668 
669                 int queryPos = 0;
670 
671                 q.setLong(queryPos++, classNameId);
672 
673                 q.setLong(queryPos++, classPK);
674 
675                 Long count = null;
676 
677                 Iterator<Long> itr = q.list().iterator();
678 
679                 if (itr.hasNext()) {
680                     count = itr.next();
681                 }
682 
683                 if (count == null) {
684                     count = new Long(0);
685                 }
686 
687                 FinderCache.putResult(finderClassNameCacheEnabled,
688                     finderClassName, finderMethodName, finderParams,
689                     finderArgs, count);
690 
691                 return count.intValue();
692             }
693             catch (Exception e) {
694                 throw HibernateUtil.processException(e);
695             }
696             finally {
697                 closeSession(session);
698             }
699         }
700         else {
701             return ((Long)result).intValue();
702         }
703     }
704 
705     public int countByP_C_C(long passwordPolicyId, long classNameId,
706         long classPK) throws SystemException {
707         boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
708         String finderClassName = PasswordPolicyRel.class.getName();
709         String finderMethodName = "countByP_C_C";
710         String[] finderParams = new String[] {
711                 Long.class.getName(), Long.class.getName(), Long.class.getName()
712             };
713         Object[] finderArgs = new Object[] {
714                 new Long(passwordPolicyId), new Long(classNameId),
715                 new Long(classPK)
716             };
717 
718         Object result = null;
719 
720         if (finderClassNameCacheEnabled) {
721             result = FinderCache.getResult(finderClassName, finderMethodName,
722                     finderParams, finderArgs, getSessionFactory());
723         }
724 
725         if (result == null) {
726             Session session = null;
727 
728             try {
729                 session = openSession();
730 
731                 StringMaker query = new StringMaker();
732 
733                 query.append("SELECT COUNT(*) ");
734                 query.append(
735                     "FROM com.liferay.portal.model.PasswordPolicyRel WHERE ");
736 
737                 query.append("passwordPolicyId = ?");
738 
739                 query.append(" AND ");
740 
741                 query.append("classNameId = ?");
742 
743                 query.append(" AND ");
744 
745                 query.append("classPK = ?");
746 
747                 query.append(" ");
748 
749                 Query q = session.createQuery(query.toString());
750 
751                 int queryPos = 0;
752 
753                 q.setLong(queryPos++, passwordPolicyId);
754 
755                 q.setLong(queryPos++, classNameId);
756 
757                 q.setLong(queryPos++, classPK);
758 
759                 Long count = null;
760 
761                 Iterator<Long> itr = q.list().iterator();
762 
763                 if (itr.hasNext()) {
764                     count = itr.next();
765                 }
766 
767                 if (count == null) {
768                     count = new Long(0);
769                 }
770 
771                 FinderCache.putResult(finderClassNameCacheEnabled,
772                     finderClassName, finderMethodName, finderParams,
773                     finderArgs, count);
774 
775                 return count.intValue();
776             }
777             catch (Exception e) {
778                 throw HibernateUtil.processException(e);
779             }
780             finally {
781                 closeSession(session);
782             }
783         }
784         else {
785             return ((Long)result).intValue();
786         }
787     }
788 
789     public int countAll() throws SystemException {
790         boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
791         String finderClassName = PasswordPolicyRel.class.getName();
792         String finderMethodName = "countAll";
793         String[] finderParams = new String[] {  };
794         Object[] finderArgs = new Object[] {  };
795 
796         Object result = null;
797 
798         if (finderClassNameCacheEnabled) {
799             result = FinderCache.getResult(finderClassName, finderMethodName,
800                     finderParams, finderArgs, getSessionFactory());
801         }
802 
803         if (result == null) {
804             Session session = null;
805 
806             try {
807                 session = openSession();
808 
809                 Query q = session.createQuery(
810                         "SELECT COUNT(*) FROM com.liferay.portal.model.PasswordPolicyRel");
811 
812                 Long count = null;
813 
814                 Iterator<Long> itr = q.list().iterator();
815 
816                 if (itr.hasNext()) {
817                     count = itr.next();
818                 }
819 
820                 if (count == null) {
821                     count = new Long(0);
822                 }
823 
824                 FinderCache.putResult(finderClassNameCacheEnabled,
825                     finderClassName, finderMethodName, finderParams,
826                     finderArgs, count);
827 
828                 return count.intValue();
829             }
830             catch (Exception e) {
831                 throw HibernateUtil.processException(e);
832             }
833             finally {
834                 closeSession(session);
835             }
836         }
837         else {
838             return ((Long)result).intValue();
839         }
840     }
841 
842     protected void initDao() {
843         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
844                     PropsUtil.get(
845                         "value.object.listener.com.liferay.portal.model.PasswordPolicyRel")));
846 
847         if (listenerClassNames.length > 0) {
848             try {
849                 List<ModelListener> listeners = new ArrayList<ModelListener>();
850 
851                 for (String listenerClassName : listenerClassNames) {
852                     listeners.add((ModelListener)Class.forName(
853                             listenerClassName).newInstance());
854                 }
855 
856                 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
857             }
858             catch (Exception e) {
859                 _log.error(e);
860             }
861         }
862     }
863 
864     private static Log _log = LogFactory.getLog(PasswordPolicyRelPersistenceImpl.class);
865     private ModelListener[] _listeners;
866 }