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