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