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