001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchPasswordPolicyException;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.PasswordPolicy;
041    import com.liferay.portal.model.impl.PasswordPolicyImpl;
042    import com.liferay.portal.model.impl.PasswordPolicyModelImpl;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.List;
050    
051    /**
052     * The persistence implementation for the password policy service.
053     *
054     * <p>
055     * Caching information and settings can be found in <code>portal.properties</code>
056     * </p>
057     *
058     * @author Brian Wing Shun Chan
059     * @see PasswordPolicyPersistence
060     * @see PasswordPolicyUtil
061     * @generated
062     */
063    public class PasswordPolicyPersistenceImpl extends BasePersistenceImpl<PasswordPolicy>
064            implements PasswordPolicyPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link PasswordPolicyUtil} to access the password policy persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = PasswordPolicyImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
076                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
077                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
078                            "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
080                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
081                            PasswordPolicyImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
084                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086            public static final FinderPath FINDER_PATH_FETCH_BY_C_DP = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
087                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
088                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_DP",
089                            new String[] { Long.class.getName(), Boolean.class.getName() },
090                            PasswordPolicyModelImpl.COMPANYID_COLUMN_BITMASK |
091                            PasswordPolicyModelImpl.DEFAULTPOLICY_COLUMN_BITMASK);
092            public static final FinderPath FINDER_PATH_COUNT_BY_C_DP = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
093                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_DP",
095                            new String[] { Long.class.getName(), Boolean.class.getName() });
096    
097            /**
098             * Returns the password policy where companyId = &#63; and defaultPolicy = &#63; or throws a {@link com.liferay.portal.NoSuchPasswordPolicyException} if it could not be found.
099             *
100             * @param companyId the company ID
101             * @param defaultPolicy the default policy
102             * @return the matching password policy
103             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
104             * @throws SystemException if a system exception occurred
105             */
106            public PasswordPolicy findByC_DP(long companyId, boolean defaultPolicy)
107                    throws NoSuchPasswordPolicyException, SystemException {
108                    PasswordPolicy passwordPolicy = fetchByC_DP(companyId, defaultPolicy);
109    
110                    if (passwordPolicy == null) {
111                            StringBundler msg = new StringBundler(6);
112    
113                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
114    
115                            msg.append("companyId=");
116                            msg.append(companyId);
117    
118                            msg.append(", defaultPolicy=");
119                            msg.append(defaultPolicy);
120    
121                            msg.append(StringPool.CLOSE_CURLY_BRACE);
122    
123                            if (_log.isWarnEnabled()) {
124                                    _log.warn(msg.toString());
125                            }
126    
127                            throw new NoSuchPasswordPolicyException(msg.toString());
128                    }
129    
130                    return passwordPolicy;
131            }
132    
133            /**
134             * Returns the password policy where companyId = &#63; and defaultPolicy = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
135             *
136             * @param companyId the company ID
137             * @param defaultPolicy the default policy
138             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
139             * @throws SystemException if a system exception occurred
140             */
141            public PasswordPolicy fetchByC_DP(long companyId, boolean defaultPolicy)
142                    throws SystemException {
143                    return fetchByC_DP(companyId, defaultPolicy, true);
144            }
145    
146            /**
147             * Returns the password policy where companyId = &#63; and defaultPolicy = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
148             *
149             * @param companyId the company ID
150             * @param defaultPolicy the default policy
151             * @param retrieveFromCache whether to use the finder cache
152             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
153             * @throws SystemException if a system exception occurred
154             */
155            public PasswordPolicy fetchByC_DP(long companyId, boolean defaultPolicy,
156                    boolean retrieveFromCache) throws SystemException {
157                    Object[] finderArgs = new Object[] { companyId, defaultPolicy };
158    
159                    Object result = null;
160    
161                    if (retrieveFromCache) {
162                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_DP,
163                                            finderArgs, this);
164                    }
165    
166                    if (result instanceof PasswordPolicy) {
167                            PasswordPolicy passwordPolicy = (PasswordPolicy)result;
168    
169                            if ((companyId != passwordPolicy.getCompanyId()) ||
170                                            (defaultPolicy != passwordPolicy.getDefaultPolicy())) {
171                                    result = null;
172                            }
173                    }
174    
175                    if (result == null) {
176                            StringBundler query = new StringBundler(4);
177    
178                            query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
179    
180                            query.append(_FINDER_COLUMN_C_DP_COMPANYID_2);
181    
182                            query.append(_FINDER_COLUMN_C_DP_DEFAULTPOLICY_2);
183    
184                            String sql = query.toString();
185    
186                            Session session = null;
187    
188                            try {
189                                    session = openSession();
190    
191                                    Query q = session.createQuery(sql);
192    
193                                    QueryPos qPos = QueryPos.getInstance(q);
194    
195                                    qPos.add(companyId);
196    
197                                    qPos.add(defaultPolicy);
198    
199                                    List<PasswordPolicy> list = q.list();
200    
201                                    if (list.isEmpty()) {
202                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
203                                                    finderArgs, list);
204                                    }
205                                    else {
206                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
207                                                    _log.warn(
208                                                            "PasswordPolicyPersistenceImpl.fetchByC_DP(long, boolean, boolean) with parameters (" +
209                                                            StringUtil.merge(finderArgs) +
210                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
211                                            }
212    
213                                            PasswordPolicy passwordPolicy = list.get(0);
214    
215                                            result = passwordPolicy;
216    
217                                            cacheResult(passwordPolicy);
218    
219                                            if ((passwordPolicy.getCompanyId() != companyId) ||
220                                                            (passwordPolicy.getDefaultPolicy() != defaultPolicy)) {
221                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
222                                                            finderArgs, passwordPolicy);
223                                            }
224                                    }
225                            }
226                            catch (Exception e) {
227                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP,
228                                            finderArgs);
229    
230                                    throw processException(e);
231                            }
232                            finally {
233                                    closeSession(session);
234                            }
235                    }
236    
237                    if (result instanceof List<?>) {
238                            return null;
239                    }
240                    else {
241                            return (PasswordPolicy)result;
242                    }
243            }
244    
245            /**
246             * Removes the password policy where companyId = &#63; and defaultPolicy = &#63; from the database.
247             *
248             * @param companyId the company ID
249             * @param defaultPolicy the default policy
250             * @return the password policy that was removed
251             * @throws SystemException if a system exception occurred
252             */
253            public PasswordPolicy removeByC_DP(long companyId, boolean defaultPolicy)
254                    throws NoSuchPasswordPolicyException, SystemException {
255                    PasswordPolicy passwordPolicy = findByC_DP(companyId, defaultPolicy);
256    
257                    return remove(passwordPolicy);
258            }
259    
260            /**
261             * Returns the number of password policies where companyId = &#63; and defaultPolicy = &#63;.
262             *
263             * @param companyId the company ID
264             * @param defaultPolicy the default policy
265             * @return the number of matching password policies
266             * @throws SystemException if a system exception occurred
267             */
268            public int countByC_DP(long companyId, boolean defaultPolicy)
269                    throws SystemException {
270                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_DP;
271    
272                    Object[] finderArgs = new Object[] { companyId, defaultPolicy };
273    
274                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
275                                    this);
276    
277                    if (count == null) {
278                            StringBundler query = new StringBundler(3);
279    
280                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
281    
282                            query.append(_FINDER_COLUMN_C_DP_COMPANYID_2);
283    
284                            query.append(_FINDER_COLUMN_C_DP_DEFAULTPOLICY_2);
285    
286                            String sql = query.toString();
287    
288                            Session session = null;
289    
290                            try {
291                                    session = openSession();
292    
293                                    Query q = session.createQuery(sql);
294    
295                                    QueryPos qPos = QueryPos.getInstance(q);
296    
297                                    qPos.add(companyId);
298    
299                                    qPos.add(defaultPolicy);
300    
301                                    count = (Long)q.uniqueResult();
302    
303                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
304                            }
305                            catch (Exception e) {
306                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
307    
308                                    throw processException(e);
309                            }
310                            finally {
311                                    closeSession(session);
312                            }
313                    }
314    
315                    return count.intValue();
316            }
317    
318            private static final String _FINDER_COLUMN_C_DP_COMPANYID_2 = "passwordPolicy.companyId = ? AND ";
319            private static final String _FINDER_COLUMN_C_DP_DEFAULTPOLICY_2 = "passwordPolicy.defaultPolicy = ?";
320            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
321                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
322                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
323                            new String[] { Long.class.getName(), String.class.getName() },
324                            PasswordPolicyModelImpl.COMPANYID_COLUMN_BITMASK |
325                            PasswordPolicyModelImpl.NAME_COLUMN_BITMASK);
326            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
327                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
328                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
329                            new String[] { Long.class.getName(), String.class.getName() });
330    
331            /**
332             * Returns the password policy where companyId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchPasswordPolicyException} if it could not be found.
333             *
334             * @param companyId the company ID
335             * @param name the name
336             * @return the matching password policy
337             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
338             * @throws SystemException if a system exception occurred
339             */
340            public PasswordPolicy findByC_N(long companyId, String name)
341                    throws NoSuchPasswordPolicyException, SystemException {
342                    PasswordPolicy passwordPolicy = fetchByC_N(companyId, name);
343    
344                    if (passwordPolicy == null) {
345                            StringBundler msg = new StringBundler(6);
346    
347                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
348    
349                            msg.append("companyId=");
350                            msg.append(companyId);
351    
352                            msg.append(", name=");
353                            msg.append(name);
354    
355                            msg.append(StringPool.CLOSE_CURLY_BRACE);
356    
357                            if (_log.isWarnEnabled()) {
358                                    _log.warn(msg.toString());
359                            }
360    
361                            throw new NoSuchPasswordPolicyException(msg.toString());
362                    }
363    
364                    return passwordPolicy;
365            }
366    
367            /**
368             * Returns the password policy where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
369             *
370             * @param companyId the company ID
371             * @param name the name
372             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
373             * @throws SystemException if a system exception occurred
374             */
375            public PasswordPolicy fetchByC_N(long companyId, String name)
376                    throws SystemException {
377                    return fetchByC_N(companyId, name, true);
378            }
379    
380            /**
381             * Returns the password policy where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
382             *
383             * @param companyId the company ID
384             * @param name the name
385             * @param retrieveFromCache whether to use the finder cache
386             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
387             * @throws SystemException if a system exception occurred
388             */
389            public PasswordPolicy fetchByC_N(long companyId, String name,
390                    boolean retrieveFromCache) throws SystemException {
391                    Object[] finderArgs = new Object[] { companyId, name };
392    
393                    Object result = null;
394    
395                    if (retrieveFromCache) {
396                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
397                                            finderArgs, this);
398                    }
399    
400                    if (result instanceof PasswordPolicy) {
401                            PasswordPolicy passwordPolicy = (PasswordPolicy)result;
402    
403                            if ((companyId != passwordPolicy.getCompanyId()) ||
404                                            !Validator.equals(name, passwordPolicy.getName())) {
405                                    result = null;
406                            }
407                    }
408    
409                    if (result == null) {
410                            StringBundler query = new StringBundler(4);
411    
412                            query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
413    
414                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
415    
416                            if (name == null) {
417                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
418                            }
419                            else {
420                                    if (name.equals(StringPool.BLANK)) {
421                                            query.append(_FINDER_COLUMN_C_N_NAME_3);
422                                    }
423                                    else {
424                                            query.append(_FINDER_COLUMN_C_N_NAME_2);
425                                    }
426                            }
427    
428                            String sql = query.toString();
429    
430                            Session session = null;
431    
432                            try {
433                                    session = openSession();
434    
435                                    Query q = session.createQuery(sql);
436    
437                                    QueryPos qPos = QueryPos.getInstance(q);
438    
439                                    qPos.add(companyId);
440    
441                                    if (name != null) {
442                                            qPos.add(name);
443                                    }
444    
445                                    List<PasswordPolicy> list = q.list();
446    
447                                    if (list.isEmpty()) {
448                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
449                                                    finderArgs, list);
450                                    }
451                                    else {
452                                            PasswordPolicy passwordPolicy = list.get(0);
453    
454                                            result = passwordPolicy;
455    
456                                            cacheResult(passwordPolicy);
457    
458                                            if ((passwordPolicy.getCompanyId() != companyId) ||
459                                                            (passwordPolicy.getName() == null) ||
460                                                            !passwordPolicy.getName().equals(name)) {
461                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
462                                                            finderArgs, passwordPolicy);
463                                            }
464                                    }
465                            }
466                            catch (Exception e) {
467                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
468                                            finderArgs);
469    
470                                    throw processException(e);
471                            }
472                            finally {
473                                    closeSession(session);
474                            }
475                    }
476    
477                    if (result instanceof List<?>) {
478                            return null;
479                    }
480                    else {
481                            return (PasswordPolicy)result;
482                    }
483            }
484    
485            /**
486             * Removes the password policy where companyId = &#63; and name = &#63; from the database.
487             *
488             * @param companyId the company ID
489             * @param name the name
490             * @return the password policy that was removed
491             * @throws SystemException if a system exception occurred
492             */
493            public PasswordPolicy removeByC_N(long companyId, String name)
494                    throws NoSuchPasswordPolicyException, SystemException {
495                    PasswordPolicy passwordPolicy = findByC_N(companyId, name);
496    
497                    return remove(passwordPolicy);
498            }
499    
500            /**
501             * Returns the number of password policies where companyId = &#63; and name = &#63;.
502             *
503             * @param companyId the company ID
504             * @param name the name
505             * @return the number of matching password policies
506             * @throws SystemException if a system exception occurred
507             */
508            public int countByC_N(long companyId, String name)
509                    throws SystemException {
510                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
511    
512                    Object[] finderArgs = new Object[] { companyId, name };
513    
514                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
515                                    this);
516    
517                    if (count == null) {
518                            StringBundler query = new StringBundler(3);
519    
520                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
521    
522                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
523    
524                            if (name == null) {
525                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
526                            }
527                            else {
528                                    if (name.equals(StringPool.BLANK)) {
529                                            query.append(_FINDER_COLUMN_C_N_NAME_3);
530                                    }
531                                    else {
532                                            query.append(_FINDER_COLUMN_C_N_NAME_2);
533                                    }
534                            }
535    
536                            String sql = query.toString();
537    
538                            Session session = null;
539    
540                            try {
541                                    session = openSession();
542    
543                                    Query q = session.createQuery(sql);
544    
545                                    QueryPos qPos = QueryPos.getInstance(q);
546    
547                                    qPos.add(companyId);
548    
549                                    if (name != null) {
550                                            qPos.add(name);
551                                    }
552    
553                                    count = (Long)q.uniqueResult();
554    
555                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
556                            }
557                            catch (Exception e) {
558                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
559    
560                                    throw processException(e);
561                            }
562                            finally {
563                                    closeSession(session);
564                            }
565                    }
566    
567                    return count.intValue();
568            }
569    
570            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "passwordPolicy.companyId = ? AND ";
571            private static final String _FINDER_COLUMN_C_N_NAME_1 = "passwordPolicy.name IS NULL";
572            private static final String _FINDER_COLUMN_C_N_NAME_2 = "passwordPolicy.name = ?";
573            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(passwordPolicy.name IS NULL OR passwordPolicy.name = ?)";
574    
575            /**
576             * Caches the password policy in the entity cache if it is enabled.
577             *
578             * @param passwordPolicy the password policy
579             */
580            public void cacheResult(PasswordPolicy passwordPolicy) {
581                    EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
582                            PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey(),
583                            passwordPolicy);
584    
585                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
586                            new Object[] {
587                                    Long.valueOf(passwordPolicy.getCompanyId()),
588                                    Boolean.valueOf(passwordPolicy.getDefaultPolicy())
589                            }, passwordPolicy);
590    
591                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
592                            new Object[] {
593                                    Long.valueOf(passwordPolicy.getCompanyId()),
594                                    
595                            passwordPolicy.getName()
596                            }, passwordPolicy);
597    
598                    passwordPolicy.resetOriginalValues();
599            }
600    
601            /**
602             * Caches the password policies in the entity cache if it is enabled.
603             *
604             * @param passwordPolicies the password policies
605             */
606            public void cacheResult(List<PasswordPolicy> passwordPolicies) {
607                    for (PasswordPolicy passwordPolicy : passwordPolicies) {
608                            if (EntityCacheUtil.getResult(
609                                                    PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
610                                                    PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey()) == null) {
611                                    cacheResult(passwordPolicy);
612                            }
613                            else {
614                                    passwordPolicy.resetOriginalValues();
615                            }
616                    }
617            }
618    
619            /**
620             * Clears the cache for all password policies.
621             *
622             * <p>
623             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
624             * </p>
625             */
626            @Override
627            public void clearCache() {
628                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
629                            CacheRegistryUtil.clear(PasswordPolicyImpl.class.getName());
630                    }
631    
632                    EntityCacheUtil.clearCache(PasswordPolicyImpl.class.getName());
633    
634                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
635                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
636                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
637            }
638    
639            /**
640             * Clears the cache for the password policy.
641             *
642             * <p>
643             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
644             * </p>
645             */
646            @Override
647            public void clearCache(PasswordPolicy passwordPolicy) {
648                    EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
649                            PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey());
650    
651                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
652                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
653    
654                    clearUniqueFindersCache(passwordPolicy);
655            }
656    
657            @Override
658            public void clearCache(List<PasswordPolicy> passwordPolicies) {
659                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
660                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
661    
662                    for (PasswordPolicy passwordPolicy : passwordPolicies) {
663                            EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
664                                    PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey());
665    
666                            clearUniqueFindersCache(passwordPolicy);
667                    }
668            }
669    
670            protected void cacheUniqueFindersCache(PasswordPolicy passwordPolicy) {
671                    if (passwordPolicy.isNew()) {
672                            Object[] args = new Object[] {
673                                            Long.valueOf(passwordPolicy.getCompanyId()),
674                                            Boolean.valueOf(passwordPolicy.getDefaultPolicy())
675                                    };
676    
677                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_DP, args,
678                                    Long.valueOf(1));
679                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP, args,
680                                    passwordPolicy);
681    
682                            args = new Object[] {
683                                            Long.valueOf(passwordPolicy.getCompanyId()),
684                                            
685                                            passwordPolicy.getName()
686                                    };
687    
688                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
689                                    Long.valueOf(1));
690                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
691                                    passwordPolicy);
692                    }
693                    else {
694                            PasswordPolicyModelImpl passwordPolicyModelImpl = (PasswordPolicyModelImpl)passwordPolicy;
695    
696                            if ((passwordPolicyModelImpl.getColumnBitmask() &
697                                            FINDER_PATH_FETCH_BY_C_DP.getColumnBitmask()) != 0) {
698                                    Object[] args = new Object[] {
699                                                    Long.valueOf(passwordPolicy.getCompanyId()),
700                                                    Boolean.valueOf(passwordPolicy.getDefaultPolicy())
701                                            };
702    
703                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_DP, args,
704                                            Long.valueOf(1));
705                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP, args,
706                                            passwordPolicy);
707                            }
708    
709                            if ((passwordPolicyModelImpl.getColumnBitmask() &
710                                            FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
711                                    Object[] args = new Object[] {
712                                                    Long.valueOf(passwordPolicy.getCompanyId()),
713                                                    
714                                                    passwordPolicy.getName()
715                                            };
716    
717                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
718                                            Long.valueOf(1));
719                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
720                                            passwordPolicy);
721                            }
722                    }
723            }
724    
725            protected void clearUniqueFindersCache(PasswordPolicy passwordPolicy) {
726                    PasswordPolicyModelImpl passwordPolicyModelImpl = (PasswordPolicyModelImpl)passwordPolicy;
727    
728                    Object[] args = new Object[] {
729                                    Long.valueOf(passwordPolicy.getCompanyId()),
730                                    Boolean.valueOf(passwordPolicy.getDefaultPolicy())
731                            };
732    
733                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_DP, args);
734                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP, args);
735    
736                    if ((passwordPolicyModelImpl.getColumnBitmask() &
737                                    FINDER_PATH_FETCH_BY_C_DP.getColumnBitmask()) != 0) {
738                            args = new Object[] {
739                                            Long.valueOf(passwordPolicyModelImpl.getOriginalCompanyId()),
740                                            Boolean.valueOf(passwordPolicyModelImpl.getOriginalDefaultPolicy())
741                                    };
742    
743                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_DP, args);
744                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP, args);
745                    }
746    
747                    args = new Object[] {
748                                    Long.valueOf(passwordPolicy.getCompanyId()),
749                                    
750                                    passwordPolicy.getName()
751                            };
752    
753                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
754                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
755    
756                    if ((passwordPolicyModelImpl.getColumnBitmask() &
757                                    FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
758                            args = new Object[] {
759                                            Long.valueOf(passwordPolicyModelImpl.getOriginalCompanyId()),
760                                            
761                                            passwordPolicyModelImpl.getOriginalName()
762                                    };
763    
764                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
765                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
766                    }
767            }
768    
769            /**
770             * Creates a new password policy with the primary key. Does not add the password policy to the database.
771             *
772             * @param passwordPolicyId the primary key for the new password policy
773             * @return the new password policy
774             */
775            public PasswordPolicy create(long passwordPolicyId) {
776                    PasswordPolicy passwordPolicy = new PasswordPolicyImpl();
777    
778                    passwordPolicy.setNew(true);
779                    passwordPolicy.setPrimaryKey(passwordPolicyId);
780    
781                    return passwordPolicy;
782            }
783    
784            /**
785             * Removes the password policy with the primary key from the database. Also notifies the appropriate model listeners.
786             *
787             * @param passwordPolicyId the primary key of the password policy
788             * @return the password policy that was removed
789             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
790             * @throws SystemException if a system exception occurred
791             */
792            public PasswordPolicy remove(long passwordPolicyId)
793                    throws NoSuchPasswordPolicyException, SystemException {
794                    return remove(Long.valueOf(passwordPolicyId));
795            }
796    
797            /**
798             * Removes the password policy with the primary key from the database. Also notifies the appropriate model listeners.
799             *
800             * @param primaryKey the primary key of the password policy
801             * @return the password policy that was removed
802             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
803             * @throws SystemException if a system exception occurred
804             */
805            @Override
806            public PasswordPolicy remove(Serializable primaryKey)
807                    throws NoSuchPasswordPolicyException, SystemException {
808                    Session session = null;
809    
810                    try {
811                            session = openSession();
812    
813                            PasswordPolicy passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
814                                            primaryKey);
815    
816                            if (passwordPolicy == null) {
817                                    if (_log.isWarnEnabled()) {
818                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
819                                    }
820    
821                                    throw new NoSuchPasswordPolicyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
822                                            primaryKey);
823                            }
824    
825                            return remove(passwordPolicy);
826                    }
827                    catch (NoSuchPasswordPolicyException nsee) {
828                            throw nsee;
829                    }
830                    catch (Exception e) {
831                            throw processException(e);
832                    }
833                    finally {
834                            closeSession(session);
835                    }
836            }
837    
838            @Override
839            protected PasswordPolicy removeImpl(PasswordPolicy passwordPolicy)
840                    throws SystemException {
841                    passwordPolicy = toUnwrappedModel(passwordPolicy);
842    
843                    Session session = null;
844    
845                    try {
846                            session = openSession();
847    
848                            if (!session.contains(passwordPolicy)) {
849                                    passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
850                                                    passwordPolicy.getPrimaryKeyObj());
851                            }
852    
853                            if (passwordPolicy != null) {
854                                    session.delete(passwordPolicy);
855                            }
856                    }
857                    catch (Exception e) {
858                            throw processException(e);
859                    }
860                    finally {
861                            closeSession(session);
862                    }
863    
864                    if (passwordPolicy != null) {
865                            clearCache(passwordPolicy);
866                    }
867    
868                    return passwordPolicy;
869            }
870    
871            @Override
872            public PasswordPolicy updateImpl(
873                    com.liferay.portal.model.PasswordPolicy passwordPolicy)
874                    throws SystemException {
875                    passwordPolicy = toUnwrappedModel(passwordPolicy);
876    
877                    boolean isNew = passwordPolicy.isNew();
878    
879                    Session session = null;
880    
881                    try {
882                            session = openSession();
883    
884                            if (passwordPolicy.isNew()) {
885                                    session.save(passwordPolicy);
886    
887                                    passwordPolicy.setNew(false);
888                            }
889                            else {
890                                    session.merge(passwordPolicy);
891                            }
892                    }
893                    catch (Exception e) {
894                            throw processException(e);
895                    }
896                    finally {
897                            closeSession(session);
898                    }
899    
900                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
901    
902                    if (isNew || !PasswordPolicyModelImpl.COLUMN_BITMASK_ENABLED) {
903                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
904                    }
905    
906                    EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
907                            PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey(),
908                            passwordPolicy);
909    
910                    clearUniqueFindersCache(passwordPolicy);
911                    cacheUniqueFindersCache(passwordPolicy);
912    
913                    return passwordPolicy;
914            }
915    
916            protected PasswordPolicy toUnwrappedModel(PasswordPolicy passwordPolicy) {
917                    if (passwordPolicy instanceof PasswordPolicyImpl) {
918                            return passwordPolicy;
919                    }
920    
921                    PasswordPolicyImpl passwordPolicyImpl = new PasswordPolicyImpl();
922    
923                    passwordPolicyImpl.setNew(passwordPolicy.isNew());
924                    passwordPolicyImpl.setPrimaryKey(passwordPolicy.getPrimaryKey());
925    
926                    passwordPolicyImpl.setPasswordPolicyId(passwordPolicy.getPasswordPolicyId());
927                    passwordPolicyImpl.setCompanyId(passwordPolicy.getCompanyId());
928                    passwordPolicyImpl.setUserId(passwordPolicy.getUserId());
929                    passwordPolicyImpl.setUserName(passwordPolicy.getUserName());
930                    passwordPolicyImpl.setCreateDate(passwordPolicy.getCreateDate());
931                    passwordPolicyImpl.setModifiedDate(passwordPolicy.getModifiedDate());
932                    passwordPolicyImpl.setDefaultPolicy(passwordPolicy.isDefaultPolicy());
933                    passwordPolicyImpl.setName(passwordPolicy.getName());
934                    passwordPolicyImpl.setDescription(passwordPolicy.getDescription());
935                    passwordPolicyImpl.setChangeable(passwordPolicy.isChangeable());
936                    passwordPolicyImpl.setChangeRequired(passwordPolicy.isChangeRequired());
937                    passwordPolicyImpl.setMinAge(passwordPolicy.getMinAge());
938                    passwordPolicyImpl.setCheckSyntax(passwordPolicy.isCheckSyntax());
939                    passwordPolicyImpl.setAllowDictionaryWords(passwordPolicy.isAllowDictionaryWords());
940                    passwordPolicyImpl.setMinAlphanumeric(passwordPolicy.getMinAlphanumeric());
941                    passwordPolicyImpl.setMinLength(passwordPolicy.getMinLength());
942                    passwordPolicyImpl.setMinLowerCase(passwordPolicy.getMinLowerCase());
943                    passwordPolicyImpl.setMinNumbers(passwordPolicy.getMinNumbers());
944                    passwordPolicyImpl.setMinSymbols(passwordPolicy.getMinSymbols());
945                    passwordPolicyImpl.setMinUpperCase(passwordPolicy.getMinUpperCase());
946                    passwordPolicyImpl.setHistory(passwordPolicy.isHistory());
947                    passwordPolicyImpl.setHistoryCount(passwordPolicy.getHistoryCount());
948                    passwordPolicyImpl.setExpireable(passwordPolicy.isExpireable());
949                    passwordPolicyImpl.setMaxAge(passwordPolicy.getMaxAge());
950                    passwordPolicyImpl.setWarningTime(passwordPolicy.getWarningTime());
951                    passwordPolicyImpl.setGraceLimit(passwordPolicy.getGraceLimit());
952                    passwordPolicyImpl.setLockout(passwordPolicy.isLockout());
953                    passwordPolicyImpl.setMaxFailure(passwordPolicy.getMaxFailure());
954                    passwordPolicyImpl.setLockoutDuration(passwordPolicy.getLockoutDuration());
955                    passwordPolicyImpl.setRequireUnlock(passwordPolicy.isRequireUnlock());
956                    passwordPolicyImpl.setResetFailureCount(passwordPolicy.getResetFailureCount());
957                    passwordPolicyImpl.setResetTicketMaxAge(passwordPolicy.getResetTicketMaxAge());
958    
959                    return passwordPolicyImpl;
960            }
961    
962            /**
963             * Returns the password policy with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
964             *
965             * @param primaryKey the primary key of the password policy
966             * @return the password policy
967             * @throws com.liferay.portal.NoSuchModelException if a password policy with the primary key could not be found
968             * @throws SystemException if a system exception occurred
969             */
970            @Override
971            public PasswordPolicy findByPrimaryKey(Serializable primaryKey)
972                    throws NoSuchModelException, SystemException {
973                    return findByPrimaryKey(((Long)primaryKey).longValue());
974            }
975    
976            /**
977             * Returns the password policy with the primary key or throws a {@link com.liferay.portal.NoSuchPasswordPolicyException} if it could not be found.
978             *
979             * @param passwordPolicyId the primary key of the password policy
980             * @return the password policy
981             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
982             * @throws SystemException if a system exception occurred
983             */
984            public PasswordPolicy findByPrimaryKey(long passwordPolicyId)
985                    throws NoSuchPasswordPolicyException, SystemException {
986                    PasswordPolicy passwordPolicy = fetchByPrimaryKey(passwordPolicyId);
987    
988                    if (passwordPolicy == null) {
989                            if (_log.isWarnEnabled()) {
990                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + passwordPolicyId);
991                            }
992    
993                            throw new NoSuchPasswordPolicyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
994                                    passwordPolicyId);
995                    }
996    
997                    return passwordPolicy;
998            }
999    
1000            /**
1001             * Returns the password policy with the primary key or returns <code>null</code> if it could not be found.
1002             *
1003             * @param primaryKey the primary key of the password policy
1004             * @return the password policy, or <code>null</code> if a password policy with the primary key could not be found
1005             * @throws SystemException if a system exception occurred
1006             */
1007            @Override
1008            public PasswordPolicy fetchByPrimaryKey(Serializable primaryKey)
1009                    throws SystemException {
1010                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
1011            }
1012    
1013            /**
1014             * Returns the password policy with the primary key or returns <code>null</code> if it could not be found.
1015             *
1016             * @param passwordPolicyId the primary key of the password policy
1017             * @return the password policy, or <code>null</code> if a password policy with the primary key could not be found
1018             * @throws SystemException if a system exception occurred
1019             */
1020            public PasswordPolicy fetchByPrimaryKey(long passwordPolicyId)
1021                    throws SystemException {
1022                    PasswordPolicy passwordPolicy = (PasswordPolicy)EntityCacheUtil.getResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
1023                                    PasswordPolicyImpl.class, passwordPolicyId);
1024    
1025                    if (passwordPolicy == _nullPasswordPolicy) {
1026                            return null;
1027                    }
1028    
1029                    if (passwordPolicy == null) {
1030                            Session session = null;
1031    
1032                            try {
1033                                    session = openSession();
1034    
1035                                    passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
1036                                                    Long.valueOf(passwordPolicyId));
1037    
1038                                    if (passwordPolicy != null) {
1039                                            cacheResult(passwordPolicy);
1040                                    }
1041                                    else {
1042                                            EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
1043                                                    PasswordPolicyImpl.class, passwordPolicyId,
1044                                                    _nullPasswordPolicy);
1045                                    }
1046                            }
1047                            catch (Exception e) {
1048                                    EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
1049                                            PasswordPolicyImpl.class, passwordPolicyId);
1050    
1051                                    throw processException(e);
1052                            }
1053                            finally {
1054                                    closeSession(session);
1055                            }
1056                    }
1057    
1058                    return passwordPolicy;
1059            }
1060    
1061            /**
1062             * Returns all the password policies.
1063             *
1064             * @return the password policies
1065             * @throws SystemException if a system exception occurred
1066             */
1067            public List<PasswordPolicy> findAll() throws SystemException {
1068                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1069            }
1070    
1071            /**
1072             * Returns a range of all the password policies.
1073             *
1074             * <p>
1075             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.PasswordPolicyModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1076             * </p>
1077             *
1078             * @param start the lower bound of the range of password policies
1079             * @param end the upper bound of the range of password policies (not inclusive)
1080             * @return the range of password policies
1081             * @throws SystemException if a system exception occurred
1082             */
1083            public List<PasswordPolicy> findAll(int start, int end)
1084                    throws SystemException {
1085                    return findAll(start, end, null);
1086            }
1087    
1088            /**
1089             * Returns an ordered range of all the password policies.
1090             *
1091             * <p>
1092             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.PasswordPolicyModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1093             * </p>
1094             *
1095             * @param start the lower bound of the range of password policies
1096             * @param end the upper bound of the range of password policies (not inclusive)
1097             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1098             * @return the ordered range of password policies
1099             * @throws SystemException if a system exception occurred
1100             */
1101            public List<PasswordPolicy> findAll(int start, int end,
1102                    OrderByComparator orderByComparator) throws SystemException {
1103                    boolean pagination = true;
1104                    FinderPath finderPath = null;
1105                    Object[] finderArgs = null;
1106    
1107                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1108                                    (orderByComparator == null)) {
1109                            pagination = false;
1110                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1111                            finderArgs = FINDER_ARGS_EMPTY;
1112                    }
1113                    else {
1114                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1115                            finderArgs = new Object[] { start, end, orderByComparator };
1116                    }
1117    
1118                    List<PasswordPolicy> list = (List<PasswordPolicy>)FinderCacheUtil.getResult(finderPath,
1119                                    finderArgs, this);
1120    
1121                    if (list == null) {
1122                            StringBundler query = null;
1123                            String sql = null;
1124    
1125                            if (orderByComparator != null) {
1126                                    query = new StringBundler(2 +
1127                                                    (orderByComparator.getOrderByFields().length * 3));
1128    
1129                                    query.append(_SQL_SELECT_PASSWORDPOLICY);
1130    
1131                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1132                                            orderByComparator);
1133    
1134                                    sql = query.toString();
1135                            }
1136                            else {
1137                                    sql = _SQL_SELECT_PASSWORDPOLICY;
1138    
1139                                    if (pagination) {
1140                                            sql = sql.concat(PasswordPolicyModelImpl.ORDER_BY_JPQL);
1141                                    }
1142                            }
1143    
1144                            Session session = null;
1145    
1146                            try {
1147                                    session = openSession();
1148    
1149                                    Query q = session.createQuery(sql);
1150    
1151                                    if (!pagination) {
1152                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
1153                                                            getDialect(), start, end, false);
1154    
1155                                            Collections.sort(list);
1156    
1157                                            list = new UnmodifiableList<PasswordPolicy>(list);
1158                                    }
1159                                    else {
1160                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
1161                                                            getDialect(), start, end);
1162                                    }
1163    
1164                                    cacheResult(list);
1165    
1166                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1167                            }
1168                            catch (Exception e) {
1169                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1170    
1171                                    throw processException(e);
1172                            }
1173                            finally {
1174                                    closeSession(session);
1175                            }
1176                    }
1177    
1178                    return list;
1179            }
1180    
1181            /**
1182             * Removes all the password policies from the database.
1183             *
1184             * @throws SystemException if a system exception occurred
1185             */
1186            public void removeAll() throws SystemException {
1187                    for (PasswordPolicy passwordPolicy : findAll()) {
1188                            remove(passwordPolicy);
1189                    }
1190            }
1191    
1192            /**
1193             * Returns the number of password policies.
1194             *
1195             * @return the number of password policies
1196             * @throws SystemException if a system exception occurred
1197             */
1198            public int countAll() throws SystemException {
1199                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1200                                    FINDER_ARGS_EMPTY, this);
1201    
1202                    if (count == null) {
1203                            Session session = null;
1204    
1205                            try {
1206                                    session = openSession();
1207    
1208                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDPOLICY);
1209    
1210                                    count = (Long)q.uniqueResult();
1211    
1212                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1213                                            FINDER_ARGS_EMPTY, count);
1214                            }
1215                            catch (Exception e) {
1216                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1217                                            FINDER_ARGS_EMPTY);
1218    
1219                                    throw processException(e);
1220                            }
1221                            finally {
1222                                    closeSession(session);
1223                            }
1224                    }
1225    
1226                    return count.intValue();
1227            }
1228    
1229            /**
1230             * Initializes the password policy persistence.
1231             */
1232            public void afterPropertiesSet() {
1233                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1234                                            com.liferay.portal.util.PropsUtil.get(
1235                                                    "value.object.listener.com.liferay.portal.model.PasswordPolicy")));
1236    
1237                    if (listenerClassNames.length > 0) {
1238                            try {
1239                                    List<ModelListener<PasswordPolicy>> listenersList = new ArrayList<ModelListener<PasswordPolicy>>();
1240    
1241                                    for (String listenerClassName : listenerClassNames) {
1242                                            listenersList.add((ModelListener<PasswordPolicy>)InstanceFactory.newInstance(
1243                                                            listenerClassName));
1244                                    }
1245    
1246                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1247                            }
1248                            catch (Exception e) {
1249                                    _log.error(e);
1250                            }
1251                    }
1252            }
1253    
1254            public void destroy() {
1255                    EntityCacheUtil.removeCache(PasswordPolicyImpl.class.getName());
1256                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1257                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1258                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1259            }
1260    
1261            private static final String _SQL_SELECT_PASSWORDPOLICY = "SELECT passwordPolicy FROM PasswordPolicy passwordPolicy";
1262            private static final String _SQL_SELECT_PASSWORDPOLICY_WHERE = "SELECT passwordPolicy FROM PasswordPolicy passwordPolicy WHERE ";
1263            private static final String _SQL_COUNT_PASSWORDPOLICY = "SELECT COUNT(passwordPolicy) FROM PasswordPolicy passwordPolicy";
1264            private static final String _SQL_COUNT_PASSWORDPOLICY_WHERE = "SELECT COUNT(passwordPolicy) FROM PasswordPolicy passwordPolicy WHERE ";
1265            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordPolicy.";
1266            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordPolicy exists with the primary key ";
1267            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordPolicy exists with the key {";
1268            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1269            private static Log _log = LogFactoryUtil.getLog(PasswordPolicyPersistenceImpl.class);
1270            private static PasswordPolicy _nullPasswordPolicy = new PasswordPolicyImpl() {
1271                            @Override
1272                            public Object clone() {
1273                                    return this;
1274                            }
1275    
1276                            @Override
1277                            public CacheModel<PasswordPolicy> toCacheModel() {
1278                                    return _nullPasswordPolicyCacheModel;
1279                            }
1280                    };
1281    
1282            private static CacheModel<PasswordPolicy> _nullPasswordPolicyCacheModel = new CacheModel<PasswordPolicy>() {
1283                            public PasswordPolicy toEntityModel() {
1284                                    return _nullPasswordPolicy;
1285                            }
1286                    };
1287    }