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             session.delete(passwordPolicyRel);
131 
132             session.flush();
133 
134             return passwordPolicyRel;
135         }
136         catch (Exception e) {
137             throw processException(e);
138         }
139         finally {
140             closeSession(session);
141 
142             FinderCacheUtil.clearCache(PasswordPolicyRel.class.getName());
143         }
144     }
145 
146     /**
147      * @deprecated Use <code>update(PasswordPolicyRel passwordPolicyRel, boolean merge)</code>.
148      */
149     public PasswordPolicyRel update(PasswordPolicyRel passwordPolicyRel)
150         throws SystemException {
151         if (_log.isWarnEnabled()) {
152             _log.warn(
153                 "Using the deprecated update(PasswordPolicyRel passwordPolicyRel) method. Use update(PasswordPolicyRel passwordPolicyRel, boolean merge) instead.");
154         }
155 
156         return update(passwordPolicyRel, false);
157     }
158 
159     /**
160      * Add, update, or merge, the entity. This method also calls the model
161      * listeners to trigger the proper events associated with adding, deleting,
162      * or updating an entity.
163      *
164      * @param        passwordPolicyRel the entity to add, update, or merge
165      * @param        merge boolean value for whether to merge the entity. The
166      *                default value is false. Setting merge to true is more
167      *                expensive and should only be true when passwordPolicyRel is
168      *                transient. See LEP-5473 for a detailed discussion of this
169      *                method.
170      * @return        true if the portlet can be displayed via Ajax
171      */
172     public PasswordPolicyRel update(PasswordPolicyRel passwordPolicyRel,
173         boolean merge) throws SystemException {
174         boolean isNew = passwordPolicyRel.isNew();
175 
176         if (_listeners.length > 0) {
177             for (ModelListener listener : _listeners) {
178                 if (isNew) {
179                     listener.onBeforeCreate(passwordPolicyRel);
180                 }
181                 else {
182                     listener.onBeforeUpdate(passwordPolicyRel);
183                 }
184             }
185         }
186 
187         passwordPolicyRel = updateImpl(passwordPolicyRel, merge);
188 
189         if (_listeners.length > 0) {
190             for (ModelListener listener : _listeners) {
191                 if (isNew) {
192                     listener.onAfterCreate(passwordPolicyRel);
193                 }
194                 else {
195                     listener.onAfterUpdate(passwordPolicyRel);
196                 }
197             }
198         }
199 
200         return passwordPolicyRel;
201     }
202 
203     public PasswordPolicyRel updateImpl(
204         com.liferay.portal.model.PasswordPolicyRel passwordPolicyRel,
205         boolean merge) throws SystemException {
206         Session session = null;
207 
208         try {
209             session = openSession();
210 
211             if (merge) {
212                 session.merge(passwordPolicyRel);
213             }
214             else {
215                 if (passwordPolicyRel.isNew()) {
216                     session.save(passwordPolicyRel);
217                 }
218             }
219 
220             session.flush();
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 = (List<PasswordPolicyRel>)QueryUtil.list(q,
579                         getDialect(), start, end);
580 
581                 if (obc == null) {
582                     Collections.sort(list);
583                 }
584 
585                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
586                     finderClassName, finderMethodName, finderParams,
587                     finderArgs, list);
588 
589                 return list;
590             }
591             catch (Exception e) {
592                 throw processException(e);
593             }
594             finally {
595                 closeSession(session);
596             }
597         }
598         else {
599             return (List<PasswordPolicyRel>)result;
600         }
601     }
602 
603     public void removeByC_C(long classNameId, long classPK)
604         throws NoSuchPasswordPolicyRelException, SystemException {
605         PasswordPolicyRel passwordPolicyRel = findByC_C(classNameId, classPK);
606 
607         remove(passwordPolicyRel);
608     }
609 
610     public void removeByP_C_C(long passwordPolicyId, long classNameId,
611         long classPK) throws NoSuchPasswordPolicyRelException, SystemException {
612         PasswordPolicyRel passwordPolicyRel = findByP_C_C(passwordPolicyId,
613                 classNameId, classPK);
614 
615         remove(passwordPolicyRel);
616     }
617 
618     public void removeAll() throws SystemException {
619         for (PasswordPolicyRel passwordPolicyRel : findAll()) {
620             remove(passwordPolicyRel);
621         }
622     }
623 
624     public int countByC_C(long classNameId, long classPK)
625         throws SystemException {
626         boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
627         String finderClassName = PasswordPolicyRel.class.getName();
628         String finderMethodName = "countByC_C";
629         String[] finderParams = new String[] {
630                 Long.class.getName(), Long.class.getName()
631             };
632         Object[] finderArgs = new Object[] {
633                 new Long(classNameId), new Long(classPK)
634             };
635 
636         Object result = null;
637 
638         if (finderClassNameCacheEnabled) {
639             result = FinderCacheUtil.getResult(finderClassName,
640                     finderMethodName, finderParams, finderArgs, this);
641         }
642 
643         if (result == null) {
644             Session session = null;
645 
646             try {
647                 session = openSession();
648 
649                 StringBuilder query = new StringBuilder();
650 
651                 query.append("SELECT COUNT(*) ");
652                 query.append(
653                     "FROM com.liferay.portal.model.PasswordPolicyRel WHERE ");
654 
655                 query.append("classNameId = ?");
656 
657                 query.append(" AND ");
658 
659                 query.append("classPK = ?");
660 
661                 query.append(" ");
662 
663                 Query q = session.createQuery(query.toString());
664 
665                 QueryPos qPos = QueryPos.getInstance(q);
666 
667                 qPos.add(classNameId);
668 
669                 qPos.add(classPK);
670 
671                 Long count = null;
672 
673                 Iterator<Long> itr = q.list().iterator();
674 
675                 if (itr.hasNext()) {
676                     count = itr.next();
677                 }
678 
679                 if (count == null) {
680                     count = new Long(0);
681                 }
682 
683                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
684                     finderClassName, finderMethodName, finderParams,
685                     finderArgs, count);
686 
687                 return count.intValue();
688             }
689             catch (Exception e) {
690                 throw processException(e);
691             }
692             finally {
693                 closeSession(session);
694             }
695         }
696         else {
697             return ((Long)result).intValue();
698         }
699     }
700 
701     public int countByP_C_C(long passwordPolicyId, long classNameId,
702         long classPK) throws SystemException {
703         boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
704         String finderClassName = PasswordPolicyRel.class.getName();
705         String finderMethodName = "countByP_C_C";
706         String[] finderParams = new String[] {
707                 Long.class.getName(), Long.class.getName(), Long.class.getName()
708             };
709         Object[] finderArgs = new Object[] {
710                 new Long(passwordPolicyId), new Long(classNameId),
711                 new Long(classPK)
712             };
713 
714         Object result = null;
715 
716         if (finderClassNameCacheEnabled) {
717             result = FinderCacheUtil.getResult(finderClassName,
718                     finderMethodName, finderParams, finderArgs, this);
719         }
720 
721         if (result == null) {
722             Session session = null;
723 
724             try {
725                 session = openSession();
726 
727                 StringBuilder query = new StringBuilder();
728 
729                 query.append("SELECT COUNT(*) ");
730                 query.append(
731                     "FROM com.liferay.portal.model.PasswordPolicyRel WHERE ");
732 
733                 query.append("passwordPolicyId = ?");
734 
735                 query.append(" AND ");
736 
737                 query.append("classNameId = ?");
738 
739                 query.append(" AND ");
740 
741                 query.append("classPK = ?");
742 
743                 query.append(" ");
744 
745                 Query q = session.createQuery(query.toString());
746 
747                 QueryPos qPos = QueryPos.getInstance(q);
748 
749                 qPos.add(passwordPolicyId);
750 
751                 qPos.add(classNameId);
752 
753                 qPos.add(classPK);
754 
755                 Long count = null;
756 
757                 Iterator<Long> itr = q.list().iterator();
758 
759                 if (itr.hasNext()) {
760                     count = itr.next();
761                 }
762 
763                 if (count == null) {
764                     count = new Long(0);
765                 }
766 
767                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
768                     finderClassName, finderMethodName, finderParams,
769                     finderArgs, count);
770 
771                 return count.intValue();
772             }
773             catch (Exception e) {
774                 throw processException(e);
775             }
776             finally {
777                 closeSession(session);
778             }
779         }
780         else {
781             return ((Long)result).intValue();
782         }
783     }
784 
785     public int countAll() throws SystemException {
786         boolean finderClassNameCacheEnabled = PasswordPolicyRelModelImpl.CACHE_ENABLED;
787         String finderClassName = PasswordPolicyRel.class.getName();
788         String finderMethodName = "countAll";
789         String[] finderParams = new String[] {  };
790         Object[] finderArgs = new Object[] {  };
791 
792         Object result = null;
793 
794         if (finderClassNameCacheEnabled) {
795             result = FinderCacheUtil.getResult(finderClassName,
796                     finderMethodName, finderParams, finderArgs, this);
797         }
798 
799         if (result == null) {
800             Session session = null;
801 
802             try {
803                 session = openSession();
804 
805                 Query q = session.createQuery(
806                         "SELECT COUNT(*) FROM com.liferay.portal.model.PasswordPolicyRel");
807 
808                 Long count = null;
809 
810                 Iterator<Long> itr = q.list().iterator();
811 
812                 if (itr.hasNext()) {
813                     count = itr.next();
814                 }
815 
816                 if (count == null) {
817                     count = new Long(0);
818                 }
819 
820                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
821                     finderClassName, finderMethodName, finderParams,
822                     finderArgs, count);
823 
824                 return count.intValue();
825             }
826             catch (Exception e) {
827                 throw processException(e);
828             }
829             finally {
830                 closeSession(session);
831             }
832         }
833         else {
834             return ((Long)result).intValue();
835         }
836     }
837 
838     public void registerListener(ModelListener listener) {
839         List<ModelListener> listeners = ListUtil.fromArray(_listeners);
840 
841         listeners.add(listener);
842 
843         _listeners = listeners.toArray(new ModelListener[listeners.size()]);
844     }
845 
846     public void unregisterListener(ModelListener listener) {
847         List<ModelListener> listeners = ListUtil.fromArray(_listeners);
848 
849         listeners.remove(listener);
850 
851         _listeners = listeners.toArray(new ModelListener[listeners.size()]);
852     }
853 
854     public void afterPropertiesSet() {
855         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
856                     com.liferay.portal.util.PropsUtil.get(
857                         "value.object.listener.com.liferay.portal.model.PasswordPolicyRel")));
858 
859         if (listenerClassNames.length > 0) {
860             try {
861                 List<ModelListener> listeners = new ArrayList<ModelListener>();
862 
863                 for (String listenerClassName : listenerClassNames) {
864                     listeners.add((ModelListener)Class.forName(
865                             listenerClassName).newInstance());
866                 }
867 
868                 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
869             }
870             catch (Exception e) {
871                 _log.error(e);
872             }
873         }
874     }
875 
876     private static Log _log = LogFactory.getLog(PasswordPolicyRelPersistenceImpl.class);
877     private ModelListener[] _listeners = new ModelListener[0];
878 }