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