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