001    /**
002     * Copyright (c) 2000-2013 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.SQLQuery;
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.SetUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.UnmodifiableList;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.ModelListener;
042    import com.liferay.portal.model.PasswordPolicy;
043    import com.liferay.portal.model.impl.PasswordPolicyImpl;
044    import com.liferay.portal.model.impl.PasswordPolicyModelImpl;
045    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
046    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047    
048    import java.io.Serializable;
049    
050    import java.util.ArrayList;
051    import java.util.Collections;
052    import java.util.List;
053    import java.util.Set;
054    
055    /**
056     * The persistence implementation for the password policy service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see PasswordPolicyPersistence
064     * @see PasswordPolicyUtil
065     * @generated
066     */
067    public class PasswordPolicyPersistenceImpl extends BasePersistenceImpl<PasswordPolicy>
068            implements PasswordPolicyPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * 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.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = PasswordPolicyImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
080                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
081                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
082                            "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
084                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
085                            PasswordPolicyImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
088                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
091                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
092                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
093                            "findByUuid",
094                            new String[] {
095                                    String.class.getName(),
096                                    
097                            Integer.class.getName(), Integer.class.getName(),
098                                    OrderByComparator.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
101                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
102                            PasswordPolicyImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
104                            new String[] { String.class.getName() },
105                            PasswordPolicyModelImpl.UUID_COLUMN_BITMASK);
106            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
107                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
109                            new String[] { String.class.getName() });
110    
111            /**
112             * Returns all the password policies where uuid = &#63;.
113             *
114             * @param uuid the uuid
115             * @return the matching password policies
116             * @throws SystemException if a system exception occurred
117             */
118            @Override
119            public List<PasswordPolicy> findByUuid(String uuid)
120                    throws SystemException {
121                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the password policies where uuid = &#63;.
126             *
127             * <p>
128             * 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.
129             * </p>
130             *
131             * @param uuid the uuid
132             * @param start the lower bound of the range of password policies
133             * @param end the upper bound of the range of password policies (not inclusive)
134             * @return the range of matching password policies
135             * @throws SystemException if a system exception occurred
136             */
137            @Override
138            public List<PasswordPolicy> findByUuid(String uuid, int start, int end)
139                    throws SystemException {
140                    return findByUuid(uuid, start, end, null);
141            }
142    
143            /**
144             * Returns an ordered range of all the password policies where uuid = &#63;.
145             *
146             * <p>
147             * 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.
148             * </p>
149             *
150             * @param uuid the uuid
151             * @param start the lower bound of the range of password policies
152             * @param end the upper bound of the range of password policies (not inclusive)
153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
154             * @return the ordered range of matching password policies
155             * @throws SystemException if a system exception occurred
156             */
157            @Override
158            public List<PasswordPolicy> findByUuid(String uuid, int start, int end,
159                    OrderByComparator orderByComparator) throws SystemException {
160                    boolean pagination = true;
161                    FinderPath finderPath = null;
162                    Object[] finderArgs = null;
163    
164                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165                                    (orderByComparator == null)) {
166                            pagination = false;
167                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
168                            finderArgs = new Object[] { uuid };
169                    }
170                    else {
171                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
172                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
173                    }
174    
175                    List<PasswordPolicy> list = (List<PasswordPolicy>)FinderCacheUtil.getResult(finderPath,
176                                    finderArgs, this);
177    
178                    if ((list != null) && !list.isEmpty()) {
179                            for (PasswordPolicy passwordPolicy : list) {
180                                    if (!Validator.equals(uuid, passwordPolicy.getUuid())) {
181                                            list = null;
182    
183                                            break;
184                                    }
185                            }
186                    }
187    
188                    if (list == null) {
189                            StringBundler query = null;
190    
191                            if (orderByComparator != null) {
192                                    query = new StringBundler(3 +
193                                                    (orderByComparator.getOrderByFields().length * 3));
194                            }
195                            else {
196                                    query = new StringBundler(3);
197                            }
198    
199                            query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
200    
201                            boolean bindUuid = false;
202    
203                            if (uuid == null) {
204                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
205                            }
206                            else if (uuid.equals(StringPool.BLANK)) {
207                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
208                            }
209                            else {
210                                    bindUuid = true;
211    
212                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
213                            }
214    
215                            if (orderByComparator != null) {
216                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
217                                            orderByComparator);
218                            }
219                            else
220                             if (pagination) {
221                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
222                            }
223    
224                            String sql = query.toString();
225    
226                            Session session = null;
227    
228                            try {
229                                    session = openSession();
230    
231                                    Query q = session.createQuery(sql);
232    
233                                    QueryPos qPos = QueryPos.getInstance(q);
234    
235                                    if (bindUuid) {
236                                            qPos.add(uuid);
237                                    }
238    
239                                    if (!pagination) {
240                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
241                                                            getDialect(), start, end, false);
242    
243                                            Collections.sort(list);
244    
245                                            list = new UnmodifiableList<PasswordPolicy>(list);
246                                    }
247                                    else {
248                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
249                                                            getDialect(), start, end);
250                                    }
251    
252                                    cacheResult(list);
253    
254                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
255                            }
256                            catch (Exception e) {
257                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
258    
259                                    throw processException(e);
260                            }
261                            finally {
262                                    closeSession(session);
263                            }
264                    }
265    
266                    return list;
267            }
268    
269            /**
270             * Returns the first password policy in the ordered set where uuid = &#63;.
271             *
272             * @param uuid the uuid
273             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
274             * @return the first matching password policy
275             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
276             * @throws SystemException if a system exception occurred
277             */
278            @Override
279            public PasswordPolicy findByUuid_First(String uuid,
280                    OrderByComparator orderByComparator)
281                    throws NoSuchPasswordPolicyException, SystemException {
282                    PasswordPolicy passwordPolicy = fetchByUuid_First(uuid,
283                                    orderByComparator);
284    
285                    if (passwordPolicy != null) {
286                            return passwordPolicy;
287                    }
288    
289                    StringBundler msg = new StringBundler(4);
290    
291                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
292    
293                    msg.append("uuid=");
294                    msg.append(uuid);
295    
296                    msg.append(StringPool.CLOSE_CURLY_BRACE);
297    
298                    throw new NoSuchPasswordPolicyException(msg.toString());
299            }
300    
301            /**
302             * Returns the first password policy in the ordered set where uuid = &#63;.
303             *
304             * @param uuid the uuid
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the first matching password policy, or <code>null</code> if a matching password policy could not be found
307             * @throws SystemException if a system exception occurred
308             */
309            @Override
310            public PasswordPolicy fetchByUuid_First(String uuid,
311                    OrderByComparator orderByComparator) throws SystemException {
312                    List<PasswordPolicy> list = findByUuid(uuid, 0, 1, orderByComparator);
313    
314                    if (!list.isEmpty()) {
315                            return list.get(0);
316                    }
317    
318                    return null;
319            }
320    
321            /**
322             * Returns the last password policy in the ordered set where uuid = &#63;.
323             *
324             * @param uuid the uuid
325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
326             * @return the last matching password policy
327             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
328             * @throws SystemException if a system exception occurred
329             */
330            @Override
331            public PasswordPolicy findByUuid_Last(String uuid,
332                    OrderByComparator orderByComparator)
333                    throws NoSuchPasswordPolicyException, SystemException {
334                    PasswordPolicy passwordPolicy = fetchByUuid_Last(uuid, orderByComparator);
335    
336                    if (passwordPolicy != null) {
337                            return passwordPolicy;
338                    }
339    
340                    StringBundler msg = new StringBundler(4);
341    
342                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343    
344                    msg.append("uuid=");
345                    msg.append(uuid);
346    
347                    msg.append(StringPool.CLOSE_CURLY_BRACE);
348    
349                    throw new NoSuchPasswordPolicyException(msg.toString());
350            }
351    
352            /**
353             * Returns the last password policy in the ordered set where uuid = &#63;.
354             *
355             * @param uuid the uuid
356             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
357             * @return the last matching password policy, or <code>null</code> if a matching password policy could not be found
358             * @throws SystemException if a system exception occurred
359             */
360            @Override
361            public PasswordPolicy fetchByUuid_Last(String uuid,
362                    OrderByComparator orderByComparator) throws SystemException {
363                    int count = countByUuid(uuid);
364    
365                    if (count == 0) {
366                            return null;
367                    }
368    
369                    List<PasswordPolicy> list = findByUuid(uuid, count - 1, count,
370                                    orderByComparator);
371    
372                    if (!list.isEmpty()) {
373                            return list.get(0);
374                    }
375    
376                    return null;
377            }
378    
379            /**
380             * Returns the password policies before and after the current password policy in the ordered set where uuid = &#63;.
381             *
382             * @param passwordPolicyId the primary key of the current password policy
383             * @param uuid the uuid
384             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
385             * @return the previous, current, and next password policy
386             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
387             * @throws SystemException if a system exception occurred
388             */
389            @Override
390            public PasswordPolicy[] findByUuid_PrevAndNext(long passwordPolicyId,
391                    String uuid, OrderByComparator orderByComparator)
392                    throws NoSuchPasswordPolicyException, SystemException {
393                    PasswordPolicy passwordPolicy = findByPrimaryKey(passwordPolicyId);
394    
395                    Session session = null;
396    
397                    try {
398                            session = openSession();
399    
400                            PasswordPolicy[] array = new PasswordPolicyImpl[3];
401    
402                            array[0] = getByUuid_PrevAndNext(session, passwordPolicy, uuid,
403                                            orderByComparator, true);
404    
405                            array[1] = passwordPolicy;
406    
407                            array[2] = getByUuid_PrevAndNext(session, passwordPolicy, uuid,
408                                            orderByComparator, false);
409    
410                            return array;
411                    }
412                    catch (Exception e) {
413                            throw processException(e);
414                    }
415                    finally {
416                            closeSession(session);
417                    }
418            }
419    
420            protected PasswordPolicy getByUuid_PrevAndNext(Session session,
421                    PasswordPolicy passwordPolicy, String uuid,
422                    OrderByComparator orderByComparator, boolean previous) {
423                    StringBundler query = null;
424    
425                    if (orderByComparator != null) {
426                            query = new StringBundler(6 +
427                                            (orderByComparator.getOrderByFields().length * 6));
428                    }
429                    else {
430                            query = new StringBundler(3);
431                    }
432    
433                    query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
434    
435                    boolean bindUuid = false;
436    
437                    if (uuid == null) {
438                            query.append(_FINDER_COLUMN_UUID_UUID_1);
439                    }
440                    else if (uuid.equals(StringPool.BLANK)) {
441                            query.append(_FINDER_COLUMN_UUID_UUID_3);
442                    }
443                    else {
444                            bindUuid = true;
445    
446                            query.append(_FINDER_COLUMN_UUID_UUID_2);
447                    }
448    
449                    if (orderByComparator != null) {
450                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
451    
452                            if (orderByConditionFields.length > 0) {
453                                    query.append(WHERE_AND);
454                            }
455    
456                            for (int i = 0; i < orderByConditionFields.length; i++) {
457                                    query.append(_ORDER_BY_ENTITY_ALIAS);
458                                    query.append(orderByConditionFields[i]);
459    
460                                    if ((i + 1) < orderByConditionFields.length) {
461                                            if (orderByComparator.isAscending() ^ previous) {
462                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
463                                            }
464                                            else {
465                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
466                                            }
467                                    }
468                                    else {
469                                            if (orderByComparator.isAscending() ^ previous) {
470                                                    query.append(WHERE_GREATER_THAN);
471                                            }
472                                            else {
473                                                    query.append(WHERE_LESSER_THAN);
474                                            }
475                                    }
476                            }
477    
478                            query.append(ORDER_BY_CLAUSE);
479    
480                            String[] orderByFields = orderByComparator.getOrderByFields();
481    
482                            for (int i = 0; i < orderByFields.length; i++) {
483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
484                                    query.append(orderByFields[i]);
485    
486                                    if ((i + 1) < orderByFields.length) {
487                                            if (orderByComparator.isAscending() ^ previous) {
488                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
489                                            }
490                                            else {
491                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
492                                            }
493                                    }
494                                    else {
495                                            if (orderByComparator.isAscending() ^ previous) {
496                                                    query.append(ORDER_BY_ASC);
497                                            }
498                                            else {
499                                                    query.append(ORDER_BY_DESC);
500                                            }
501                                    }
502                            }
503                    }
504                    else {
505                            query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
506                    }
507    
508                    String sql = query.toString();
509    
510                    Query q = session.createQuery(sql);
511    
512                    q.setFirstResult(0);
513                    q.setMaxResults(2);
514    
515                    QueryPos qPos = QueryPos.getInstance(q);
516    
517                    if (bindUuid) {
518                            qPos.add(uuid);
519                    }
520    
521                    if (orderByComparator != null) {
522                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicy);
523    
524                            for (Object value : values) {
525                                    qPos.add(value);
526                            }
527                    }
528    
529                    List<PasswordPolicy> list = q.list();
530    
531                    if (list.size() == 2) {
532                            return list.get(1);
533                    }
534                    else {
535                            return null;
536                    }
537            }
538    
539            /**
540             * Returns all the password policies that the user has permission to view where uuid = &#63;.
541             *
542             * @param uuid the uuid
543             * @return the matching password policies that the user has permission to view
544             * @throws SystemException if a system exception occurred
545             */
546            @Override
547            public List<PasswordPolicy> filterFindByUuid(String uuid)
548                    throws SystemException {
549                    return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
550            }
551    
552            /**
553             * Returns a range of all the password policies that the user has permission to view where uuid = &#63;.
554             *
555             * <p>
556             * 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.
557             * </p>
558             *
559             * @param uuid the uuid
560             * @param start the lower bound of the range of password policies
561             * @param end the upper bound of the range of password policies (not inclusive)
562             * @return the range of matching password policies that the user has permission to view
563             * @throws SystemException if a system exception occurred
564             */
565            @Override
566            public List<PasswordPolicy> filterFindByUuid(String uuid, int start, int end)
567                    throws SystemException {
568                    return filterFindByUuid(uuid, start, end, null);
569            }
570    
571            /**
572             * Returns an ordered range of all the password policies that the user has permissions to view where uuid = &#63;.
573             *
574             * <p>
575             * 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.
576             * </p>
577             *
578             * @param uuid the uuid
579             * @param start the lower bound of the range of password policies
580             * @param end the upper bound of the range of password policies (not inclusive)
581             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
582             * @return the ordered range of matching password policies that the user has permission to view
583             * @throws SystemException if a system exception occurred
584             */
585            @Override
586            public List<PasswordPolicy> filterFindByUuid(String uuid, int start,
587                    int end, OrderByComparator orderByComparator) throws SystemException {
588                    if (!InlineSQLHelperUtil.isEnabled()) {
589                            return findByUuid(uuid, start, end, orderByComparator);
590                    }
591    
592                    StringBundler query = null;
593    
594                    if (orderByComparator != null) {
595                            query = new StringBundler(3 +
596                                            (orderByComparator.getOrderByFields().length * 3));
597                    }
598                    else {
599                            query = new StringBundler(3);
600                    }
601    
602                    if (getDB().isSupportsInlineDistinct()) {
603                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE);
604                    }
605                    else {
606                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1);
607                    }
608    
609                    boolean bindUuid = false;
610    
611                    if (uuid == null) {
612                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
613                    }
614                    else if (uuid.equals(StringPool.BLANK)) {
615                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
616                    }
617                    else {
618                            bindUuid = true;
619    
620                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
621                    }
622    
623                    if (!getDB().isSupportsInlineDistinct()) {
624                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2);
625                    }
626    
627                    if (orderByComparator != null) {
628                            if (getDB().isSupportsInlineDistinct()) {
629                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
630                                            orderByComparator, true);
631                            }
632                            else {
633                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
634                                            orderByComparator, true);
635                            }
636                    }
637                    else {
638                            if (getDB().isSupportsInlineDistinct()) {
639                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
640                            }
641                            else {
642                                    query.append(PasswordPolicyModelImpl.ORDER_BY_SQL);
643                            }
644                    }
645    
646                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
647                                    PasswordPolicy.class.getName(),
648                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
649    
650                    Session session = null;
651    
652                    try {
653                            session = openSession();
654    
655                            SQLQuery q = session.createSQLQuery(sql);
656    
657                            if (getDB().isSupportsInlineDistinct()) {
658                                    q.addEntity(_FILTER_ENTITY_ALIAS, PasswordPolicyImpl.class);
659                            }
660                            else {
661                                    q.addEntity(_FILTER_ENTITY_TABLE, PasswordPolicyImpl.class);
662                            }
663    
664                            QueryPos qPos = QueryPos.getInstance(q);
665    
666                            if (bindUuid) {
667                                    qPos.add(uuid);
668                            }
669    
670                            return (List<PasswordPolicy>)QueryUtil.list(q, getDialect(), start,
671                                    end);
672                    }
673                    catch (Exception e) {
674                            throw processException(e);
675                    }
676                    finally {
677                            closeSession(session);
678                    }
679            }
680    
681            /**
682             * Returns the password policies before and after the current password policy in the ordered set of password policies that the user has permission to view where uuid = &#63;.
683             *
684             * @param passwordPolicyId the primary key of the current password policy
685             * @param uuid the uuid
686             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
687             * @return the previous, current, and next password policy
688             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
689             * @throws SystemException if a system exception occurred
690             */
691            @Override
692            public PasswordPolicy[] filterFindByUuid_PrevAndNext(
693                    long passwordPolicyId, String uuid, OrderByComparator orderByComparator)
694                    throws NoSuchPasswordPolicyException, SystemException {
695                    if (!InlineSQLHelperUtil.isEnabled()) {
696                            return findByUuid_PrevAndNext(passwordPolicyId, uuid,
697                                    orderByComparator);
698                    }
699    
700                    PasswordPolicy passwordPolicy = findByPrimaryKey(passwordPolicyId);
701    
702                    Session session = null;
703    
704                    try {
705                            session = openSession();
706    
707                            PasswordPolicy[] array = new PasswordPolicyImpl[3];
708    
709                            array[0] = filterGetByUuid_PrevAndNext(session, passwordPolicy,
710                                            uuid, orderByComparator, true);
711    
712                            array[1] = passwordPolicy;
713    
714                            array[2] = filterGetByUuid_PrevAndNext(session, passwordPolicy,
715                                            uuid, orderByComparator, false);
716    
717                            return array;
718                    }
719                    catch (Exception e) {
720                            throw processException(e);
721                    }
722                    finally {
723                            closeSession(session);
724                    }
725            }
726    
727            protected PasswordPolicy filterGetByUuid_PrevAndNext(Session session,
728                    PasswordPolicy passwordPolicy, String uuid,
729                    OrderByComparator orderByComparator, boolean previous) {
730                    StringBundler query = null;
731    
732                    if (orderByComparator != null) {
733                            query = new StringBundler(6 +
734                                            (orderByComparator.getOrderByFields().length * 6));
735                    }
736                    else {
737                            query = new StringBundler(3);
738                    }
739    
740                    if (getDB().isSupportsInlineDistinct()) {
741                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE);
742                    }
743                    else {
744                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1);
745                    }
746    
747                    boolean bindUuid = false;
748    
749                    if (uuid == null) {
750                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
751                    }
752                    else if (uuid.equals(StringPool.BLANK)) {
753                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
754                    }
755                    else {
756                            bindUuid = true;
757    
758                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
759                    }
760    
761                    if (!getDB().isSupportsInlineDistinct()) {
762                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2);
763                    }
764    
765                    if (orderByComparator != null) {
766                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
767    
768                            if (orderByConditionFields.length > 0) {
769                                    query.append(WHERE_AND);
770                            }
771    
772                            for (int i = 0; i < orderByConditionFields.length; i++) {
773                                    if (getDB().isSupportsInlineDistinct()) {
774                                            query.append(_ORDER_BY_ENTITY_ALIAS);
775                                    }
776                                    else {
777                                            query.append(_ORDER_BY_ENTITY_TABLE);
778                                    }
779    
780                                    query.append(orderByConditionFields[i]);
781    
782                                    if ((i + 1) < orderByConditionFields.length) {
783                                            if (orderByComparator.isAscending() ^ previous) {
784                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
785                                            }
786                                            else {
787                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
788                                            }
789                                    }
790                                    else {
791                                            if (orderByComparator.isAscending() ^ previous) {
792                                                    query.append(WHERE_GREATER_THAN);
793                                            }
794                                            else {
795                                                    query.append(WHERE_LESSER_THAN);
796                                            }
797                                    }
798                            }
799    
800                            query.append(ORDER_BY_CLAUSE);
801    
802                            String[] orderByFields = orderByComparator.getOrderByFields();
803    
804                            for (int i = 0; i < orderByFields.length; i++) {
805                                    if (getDB().isSupportsInlineDistinct()) {
806                                            query.append(_ORDER_BY_ENTITY_ALIAS);
807                                    }
808                                    else {
809                                            query.append(_ORDER_BY_ENTITY_TABLE);
810                                    }
811    
812                                    query.append(orderByFields[i]);
813    
814                                    if ((i + 1) < orderByFields.length) {
815                                            if (orderByComparator.isAscending() ^ previous) {
816                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
817                                            }
818                                            else {
819                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
820                                            }
821                                    }
822                                    else {
823                                            if (orderByComparator.isAscending() ^ previous) {
824                                                    query.append(ORDER_BY_ASC);
825                                            }
826                                            else {
827                                                    query.append(ORDER_BY_DESC);
828                                            }
829                                    }
830                            }
831                    }
832                    else {
833                            if (getDB().isSupportsInlineDistinct()) {
834                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
835                            }
836                            else {
837                                    query.append(PasswordPolicyModelImpl.ORDER_BY_SQL);
838                            }
839                    }
840    
841                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
842                                    PasswordPolicy.class.getName(),
843                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
844    
845                    SQLQuery q = session.createSQLQuery(sql);
846    
847                    q.setFirstResult(0);
848                    q.setMaxResults(2);
849    
850                    if (getDB().isSupportsInlineDistinct()) {
851                            q.addEntity(_FILTER_ENTITY_ALIAS, PasswordPolicyImpl.class);
852                    }
853                    else {
854                            q.addEntity(_FILTER_ENTITY_TABLE, PasswordPolicyImpl.class);
855                    }
856    
857                    QueryPos qPos = QueryPos.getInstance(q);
858    
859                    if (bindUuid) {
860                            qPos.add(uuid);
861                    }
862    
863                    if (orderByComparator != null) {
864                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicy);
865    
866                            for (Object value : values) {
867                                    qPos.add(value);
868                            }
869                    }
870    
871                    List<PasswordPolicy> list = q.list();
872    
873                    if (list.size() == 2) {
874                            return list.get(1);
875                    }
876                    else {
877                            return null;
878                    }
879            }
880    
881            /**
882             * Removes all the password policies where uuid = &#63; from the database.
883             *
884             * @param uuid the uuid
885             * @throws SystemException if a system exception occurred
886             */
887            @Override
888            public void removeByUuid(String uuid) throws SystemException {
889                    for (PasswordPolicy passwordPolicy : findByUuid(uuid,
890                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
891                            remove(passwordPolicy);
892                    }
893            }
894    
895            /**
896             * Returns the number of password policies where uuid = &#63;.
897             *
898             * @param uuid the uuid
899             * @return the number of matching password policies
900             * @throws SystemException if a system exception occurred
901             */
902            @Override
903            public int countByUuid(String uuid) throws SystemException {
904                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
905    
906                    Object[] finderArgs = new Object[] { uuid };
907    
908                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
909                                    this);
910    
911                    if (count == null) {
912                            StringBundler query = new StringBundler(2);
913    
914                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
915    
916                            boolean bindUuid = false;
917    
918                            if (uuid == null) {
919                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
920                            }
921                            else if (uuid.equals(StringPool.BLANK)) {
922                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
923                            }
924                            else {
925                                    bindUuid = true;
926    
927                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
928                            }
929    
930                            String sql = query.toString();
931    
932                            Session session = null;
933    
934                            try {
935                                    session = openSession();
936    
937                                    Query q = session.createQuery(sql);
938    
939                                    QueryPos qPos = QueryPos.getInstance(q);
940    
941                                    if (bindUuid) {
942                                            qPos.add(uuid);
943                                    }
944    
945                                    count = (Long)q.uniqueResult();
946    
947                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
948                            }
949                            catch (Exception e) {
950                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
951    
952                                    throw processException(e);
953                            }
954                            finally {
955                                    closeSession(session);
956                            }
957                    }
958    
959                    return count.intValue();
960            }
961    
962            /**
963             * Returns the number of password policies that the user has permission to view where uuid = &#63;.
964             *
965             * @param uuid the uuid
966             * @return the number of matching password policies that the user has permission to view
967             * @throws SystemException if a system exception occurred
968             */
969            @Override
970            public int filterCountByUuid(String uuid) throws SystemException {
971                    if (!InlineSQLHelperUtil.isEnabled()) {
972                            return countByUuid(uuid);
973                    }
974    
975                    StringBundler query = new StringBundler(2);
976    
977                    query.append(_FILTER_SQL_COUNT_PASSWORDPOLICY_WHERE);
978    
979                    boolean bindUuid = false;
980    
981                    if (uuid == null) {
982                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
983                    }
984                    else if (uuid.equals(StringPool.BLANK)) {
985                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
986                    }
987                    else {
988                            bindUuid = true;
989    
990                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
991                    }
992    
993                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
994                                    PasswordPolicy.class.getName(),
995                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
996    
997                    Session session = null;
998    
999                    try {
1000                            session = openSession();
1001    
1002                            SQLQuery q = session.createSQLQuery(sql);
1003    
1004                            q.addScalar(COUNT_COLUMN_NAME,
1005                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1006    
1007                            QueryPos qPos = QueryPos.getInstance(q);
1008    
1009                            if (bindUuid) {
1010                                    qPos.add(uuid);
1011                            }
1012    
1013                            Long count = (Long)q.uniqueResult();
1014    
1015                            return count.intValue();
1016                    }
1017                    catch (Exception e) {
1018                            throw processException(e);
1019                    }
1020                    finally {
1021                            closeSession(session);
1022                    }
1023            }
1024    
1025            private static final String _FINDER_COLUMN_UUID_UUID_1 = "passwordPolicy.uuid IS NULL";
1026            private static final String _FINDER_COLUMN_UUID_UUID_2 = "passwordPolicy.uuid = ?";
1027            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(passwordPolicy.uuid IS NULL OR passwordPolicy.uuid = '')";
1028            private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "passwordPolicy.uuid_ IS NULL";
1029            private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "passwordPolicy.uuid_ = ?";
1030            private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(passwordPolicy.uuid_ IS NULL OR passwordPolicy.uuid_ = '')";
1031            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
1032                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
1033                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1034                            "findByUuid_C",
1035                            new String[] {
1036                                    String.class.getName(), Long.class.getName(),
1037                                    
1038                            Integer.class.getName(), Integer.class.getName(),
1039                                    OrderByComparator.class.getName()
1040                            });
1041            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1042                    new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
1043                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
1044                            PasswordPolicyImpl.class,
1045                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1046                            new String[] { String.class.getName(), Long.class.getName() },
1047                            PasswordPolicyModelImpl.UUID_COLUMN_BITMASK |
1048                            PasswordPolicyModelImpl.COMPANYID_COLUMN_BITMASK);
1049            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
1050                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
1051                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1052                            new String[] { String.class.getName(), Long.class.getName() });
1053    
1054            /**
1055             * Returns all the password policies where uuid = &#63; and companyId = &#63;.
1056             *
1057             * @param uuid the uuid
1058             * @param companyId the company ID
1059             * @return the matching password policies
1060             * @throws SystemException if a system exception occurred
1061             */
1062            @Override
1063            public List<PasswordPolicy> findByUuid_C(String uuid, long companyId)
1064                    throws SystemException {
1065                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1066                            QueryUtil.ALL_POS, null);
1067            }
1068    
1069            /**
1070             * Returns a range of all the password policies where uuid = &#63; and companyId = &#63;.
1071             *
1072             * <p>
1073             * 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.
1074             * </p>
1075             *
1076             * @param uuid the uuid
1077             * @param companyId the company ID
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 matching password policies
1081             * @throws SystemException if a system exception occurred
1082             */
1083            @Override
1084            public List<PasswordPolicy> findByUuid_C(String uuid, long companyId,
1085                    int start, int end) throws SystemException {
1086                    return findByUuid_C(uuid, companyId, start, end, null);
1087            }
1088    
1089            /**
1090             * Returns an ordered range of all the password policies where uuid = &#63; and companyId = &#63;.
1091             *
1092             * <p>
1093             * 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.
1094             * </p>
1095             *
1096             * @param uuid the uuid
1097             * @param companyId the company ID
1098             * @param start the lower bound of the range of password policies
1099             * @param end the upper bound of the range of password policies (not inclusive)
1100             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1101             * @return the ordered range of matching password policies
1102             * @throws SystemException if a system exception occurred
1103             */
1104            @Override
1105            public List<PasswordPolicy> findByUuid_C(String uuid, long companyId,
1106                    int start, int end, OrderByComparator orderByComparator)
1107                    throws SystemException {
1108                    boolean pagination = true;
1109                    FinderPath finderPath = null;
1110                    Object[] finderArgs = null;
1111    
1112                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1113                                    (orderByComparator == null)) {
1114                            pagination = false;
1115                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1116                            finderArgs = new Object[] { uuid, companyId };
1117                    }
1118                    else {
1119                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1120                            finderArgs = new Object[] {
1121                                            uuid, companyId,
1122                                            
1123                                            start, end, orderByComparator
1124                                    };
1125                    }
1126    
1127                    List<PasswordPolicy> list = (List<PasswordPolicy>)FinderCacheUtil.getResult(finderPath,
1128                                    finderArgs, this);
1129    
1130                    if ((list != null) && !list.isEmpty()) {
1131                            for (PasswordPolicy passwordPolicy : list) {
1132                                    if (!Validator.equals(uuid, passwordPolicy.getUuid()) ||
1133                                                    (companyId != passwordPolicy.getCompanyId())) {
1134                                            list = null;
1135    
1136                                            break;
1137                                    }
1138                            }
1139                    }
1140    
1141                    if (list == null) {
1142                            StringBundler query = null;
1143    
1144                            if (orderByComparator != null) {
1145                                    query = new StringBundler(4 +
1146                                                    (orderByComparator.getOrderByFields().length * 3));
1147                            }
1148                            else {
1149                                    query = new StringBundler(4);
1150                            }
1151    
1152                            query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
1153    
1154                            boolean bindUuid = false;
1155    
1156                            if (uuid == null) {
1157                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1158                            }
1159                            else if (uuid.equals(StringPool.BLANK)) {
1160                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1161                            }
1162                            else {
1163                                    bindUuid = true;
1164    
1165                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1166                            }
1167    
1168                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1169    
1170                            if (orderByComparator != null) {
1171                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1172                                            orderByComparator);
1173                            }
1174                            else
1175                             if (pagination) {
1176                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
1177                            }
1178    
1179                            String sql = query.toString();
1180    
1181                            Session session = null;
1182    
1183                            try {
1184                                    session = openSession();
1185    
1186                                    Query q = session.createQuery(sql);
1187    
1188                                    QueryPos qPos = QueryPos.getInstance(q);
1189    
1190                                    if (bindUuid) {
1191                                            qPos.add(uuid);
1192                                    }
1193    
1194                                    qPos.add(companyId);
1195    
1196                                    if (!pagination) {
1197                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
1198                                                            getDialect(), start, end, false);
1199    
1200                                            Collections.sort(list);
1201    
1202                                            list = new UnmodifiableList<PasswordPolicy>(list);
1203                                    }
1204                                    else {
1205                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
1206                                                            getDialect(), start, end);
1207                                    }
1208    
1209                                    cacheResult(list);
1210    
1211                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1212                            }
1213                            catch (Exception e) {
1214                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1215    
1216                                    throw processException(e);
1217                            }
1218                            finally {
1219                                    closeSession(session);
1220                            }
1221                    }
1222    
1223                    return list;
1224            }
1225    
1226            /**
1227             * Returns the first password policy in the ordered set where uuid = &#63; and companyId = &#63;.
1228             *
1229             * @param uuid the uuid
1230             * @param companyId the company ID
1231             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1232             * @return the first matching password policy
1233             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
1234             * @throws SystemException if a system exception occurred
1235             */
1236            @Override
1237            public PasswordPolicy findByUuid_C_First(String uuid, long companyId,
1238                    OrderByComparator orderByComparator)
1239                    throws NoSuchPasswordPolicyException, SystemException {
1240                    PasswordPolicy passwordPolicy = fetchByUuid_C_First(uuid, companyId,
1241                                    orderByComparator);
1242    
1243                    if (passwordPolicy != null) {
1244                            return passwordPolicy;
1245                    }
1246    
1247                    StringBundler msg = new StringBundler(6);
1248    
1249                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1250    
1251                    msg.append("uuid=");
1252                    msg.append(uuid);
1253    
1254                    msg.append(", companyId=");
1255                    msg.append(companyId);
1256    
1257                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1258    
1259                    throw new NoSuchPasswordPolicyException(msg.toString());
1260            }
1261    
1262            /**
1263             * Returns the first password policy in the ordered set where uuid = &#63; and companyId = &#63;.
1264             *
1265             * @param uuid the uuid
1266             * @param companyId the company ID
1267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1268             * @return the first matching password policy, or <code>null</code> if a matching password policy could not be found
1269             * @throws SystemException if a system exception occurred
1270             */
1271            @Override
1272            public PasswordPolicy fetchByUuid_C_First(String uuid, long companyId,
1273                    OrderByComparator orderByComparator) throws SystemException {
1274                    List<PasswordPolicy> list = findByUuid_C(uuid, companyId, 0, 1,
1275                                    orderByComparator);
1276    
1277                    if (!list.isEmpty()) {
1278                            return list.get(0);
1279                    }
1280    
1281                    return null;
1282            }
1283    
1284            /**
1285             * Returns the last password policy in the ordered set where uuid = &#63; and companyId = &#63;.
1286             *
1287             * @param uuid the uuid
1288             * @param companyId the company ID
1289             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1290             * @return the last matching password policy
1291             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
1292             * @throws SystemException if a system exception occurred
1293             */
1294            @Override
1295            public PasswordPolicy findByUuid_C_Last(String uuid, long companyId,
1296                    OrderByComparator orderByComparator)
1297                    throws NoSuchPasswordPolicyException, SystemException {
1298                    PasswordPolicy passwordPolicy = fetchByUuid_C_Last(uuid, companyId,
1299                                    orderByComparator);
1300    
1301                    if (passwordPolicy != null) {
1302                            return passwordPolicy;
1303                    }
1304    
1305                    StringBundler msg = new StringBundler(6);
1306    
1307                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1308    
1309                    msg.append("uuid=");
1310                    msg.append(uuid);
1311    
1312                    msg.append(", companyId=");
1313                    msg.append(companyId);
1314    
1315                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1316    
1317                    throw new NoSuchPasswordPolicyException(msg.toString());
1318            }
1319    
1320            /**
1321             * Returns the last password policy in the ordered set where uuid = &#63; and companyId = &#63;.
1322             *
1323             * @param uuid the uuid
1324             * @param companyId the company ID
1325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1326             * @return the last matching password policy, or <code>null</code> if a matching password policy could not be found
1327             * @throws SystemException if a system exception occurred
1328             */
1329            @Override
1330            public PasswordPolicy fetchByUuid_C_Last(String uuid, long companyId,
1331                    OrderByComparator orderByComparator) throws SystemException {
1332                    int count = countByUuid_C(uuid, companyId);
1333    
1334                    if (count == 0) {
1335                            return null;
1336                    }
1337    
1338                    List<PasswordPolicy> list = findByUuid_C(uuid, companyId, count - 1,
1339                                    count, orderByComparator);
1340    
1341                    if (!list.isEmpty()) {
1342                            return list.get(0);
1343                    }
1344    
1345                    return null;
1346            }
1347    
1348            /**
1349             * Returns the password policies before and after the current password policy in the ordered set where uuid = &#63; and companyId = &#63;.
1350             *
1351             * @param passwordPolicyId the primary key of the current password policy
1352             * @param uuid the uuid
1353             * @param companyId the company ID
1354             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1355             * @return the previous, current, and next password policy
1356             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
1357             * @throws SystemException if a system exception occurred
1358             */
1359            @Override
1360            public PasswordPolicy[] findByUuid_C_PrevAndNext(long passwordPolicyId,
1361                    String uuid, long companyId, OrderByComparator orderByComparator)
1362                    throws NoSuchPasswordPolicyException, SystemException {
1363                    PasswordPolicy passwordPolicy = findByPrimaryKey(passwordPolicyId);
1364    
1365                    Session session = null;
1366    
1367                    try {
1368                            session = openSession();
1369    
1370                            PasswordPolicy[] array = new PasswordPolicyImpl[3];
1371    
1372                            array[0] = getByUuid_C_PrevAndNext(session, passwordPolicy, uuid,
1373                                            companyId, orderByComparator, true);
1374    
1375                            array[1] = passwordPolicy;
1376    
1377                            array[2] = getByUuid_C_PrevAndNext(session, passwordPolicy, uuid,
1378                                            companyId, orderByComparator, false);
1379    
1380                            return array;
1381                    }
1382                    catch (Exception e) {
1383                            throw processException(e);
1384                    }
1385                    finally {
1386                            closeSession(session);
1387                    }
1388            }
1389    
1390            protected PasswordPolicy getByUuid_C_PrevAndNext(Session session,
1391                    PasswordPolicy passwordPolicy, String uuid, long companyId,
1392                    OrderByComparator orderByComparator, boolean previous) {
1393                    StringBundler query = null;
1394    
1395                    if (orderByComparator != null) {
1396                            query = new StringBundler(6 +
1397                                            (orderByComparator.getOrderByFields().length * 6));
1398                    }
1399                    else {
1400                            query = new StringBundler(3);
1401                    }
1402    
1403                    query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
1404    
1405                    boolean bindUuid = false;
1406    
1407                    if (uuid == null) {
1408                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1409                    }
1410                    else if (uuid.equals(StringPool.BLANK)) {
1411                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1412                    }
1413                    else {
1414                            bindUuid = true;
1415    
1416                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1417                    }
1418    
1419                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1420    
1421                    if (orderByComparator != null) {
1422                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1423    
1424                            if (orderByConditionFields.length > 0) {
1425                                    query.append(WHERE_AND);
1426                            }
1427    
1428                            for (int i = 0; i < orderByConditionFields.length; i++) {
1429                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1430                                    query.append(orderByConditionFields[i]);
1431    
1432                                    if ((i + 1) < orderByConditionFields.length) {
1433                                            if (orderByComparator.isAscending() ^ previous) {
1434                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1435                                            }
1436                                            else {
1437                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1438                                            }
1439                                    }
1440                                    else {
1441                                            if (orderByComparator.isAscending() ^ previous) {
1442                                                    query.append(WHERE_GREATER_THAN);
1443                                            }
1444                                            else {
1445                                                    query.append(WHERE_LESSER_THAN);
1446                                            }
1447                                    }
1448                            }
1449    
1450                            query.append(ORDER_BY_CLAUSE);
1451    
1452                            String[] orderByFields = orderByComparator.getOrderByFields();
1453    
1454                            for (int i = 0; i < orderByFields.length; i++) {
1455                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1456                                    query.append(orderByFields[i]);
1457    
1458                                    if ((i + 1) < orderByFields.length) {
1459                                            if (orderByComparator.isAscending() ^ previous) {
1460                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1461                                            }
1462                                            else {
1463                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1464                                            }
1465                                    }
1466                                    else {
1467                                            if (orderByComparator.isAscending() ^ previous) {
1468                                                    query.append(ORDER_BY_ASC);
1469                                            }
1470                                            else {
1471                                                    query.append(ORDER_BY_DESC);
1472                                            }
1473                                    }
1474                            }
1475                    }
1476                    else {
1477                            query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
1478                    }
1479    
1480                    String sql = query.toString();
1481    
1482                    Query q = session.createQuery(sql);
1483    
1484                    q.setFirstResult(0);
1485                    q.setMaxResults(2);
1486    
1487                    QueryPos qPos = QueryPos.getInstance(q);
1488    
1489                    if (bindUuid) {
1490                            qPos.add(uuid);
1491                    }
1492    
1493                    qPos.add(companyId);
1494    
1495                    if (orderByComparator != null) {
1496                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicy);
1497    
1498                            for (Object value : values) {
1499                                    qPos.add(value);
1500                            }
1501                    }
1502    
1503                    List<PasswordPolicy> list = q.list();
1504    
1505                    if (list.size() == 2) {
1506                            return list.get(1);
1507                    }
1508                    else {
1509                            return null;
1510                    }
1511            }
1512    
1513            /**
1514             * Returns all the password policies that the user has permission to view where uuid = &#63; and companyId = &#63;.
1515             *
1516             * @param uuid the uuid
1517             * @param companyId the company ID
1518             * @return the matching password policies that the user has permission to view
1519             * @throws SystemException if a system exception occurred
1520             */
1521            @Override
1522            public List<PasswordPolicy> filterFindByUuid_C(String uuid, long companyId)
1523                    throws SystemException {
1524                    return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1525                            QueryUtil.ALL_POS, null);
1526            }
1527    
1528            /**
1529             * Returns a range of all the password policies that the user has permission to view where uuid = &#63; and companyId = &#63;.
1530             *
1531             * <p>
1532             * 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.
1533             * </p>
1534             *
1535             * @param uuid the uuid
1536             * @param companyId the company ID
1537             * @param start the lower bound of the range of password policies
1538             * @param end the upper bound of the range of password policies (not inclusive)
1539             * @return the range of matching password policies that the user has permission to view
1540             * @throws SystemException if a system exception occurred
1541             */
1542            @Override
1543            public List<PasswordPolicy> filterFindByUuid_C(String uuid, long companyId,
1544                    int start, int end) throws SystemException {
1545                    return filterFindByUuid_C(uuid, companyId, start, end, null);
1546            }
1547    
1548            /**
1549             * Returns an ordered range of all the password policies that the user has permissions to view where uuid = &#63; and companyId = &#63;.
1550             *
1551             * <p>
1552             * 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.
1553             * </p>
1554             *
1555             * @param uuid the uuid
1556             * @param companyId the company ID
1557             * @param start the lower bound of the range of password policies
1558             * @param end the upper bound of the range of password policies (not inclusive)
1559             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1560             * @return the ordered range of matching password policies that the user has permission to view
1561             * @throws SystemException if a system exception occurred
1562             */
1563            @Override
1564            public List<PasswordPolicy> filterFindByUuid_C(String uuid, long companyId,
1565                    int start, int end, OrderByComparator orderByComparator)
1566                    throws SystemException {
1567                    if (!InlineSQLHelperUtil.isEnabled()) {
1568                            return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1569                    }
1570    
1571                    StringBundler query = null;
1572    
1573                    if (orderByComparator != null) {
1574                            query = new StringBundler(4 +
1575                                            (orderByComparator.getOrderByFields().length * 3));
1576                    }
1577                    else {
1578                            query = new StringBundler(4);
1579                    }
1580    
1581                    if (getDB().isSupportsInlineDistinct()) {
1582                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE);
1583                    }
1584                    else {
1585                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1);
1586                    }
1587    
1588                    boolean bindUuid = false;
1589    
1590                    if (uuid == null) {
1591                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1592                    }
1593                    else if (uuid.equals(StringPool.BLANK)) {
1594                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1595                    }
1596                    else {
1597                            bindUuid = true;
1598    
1599                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1600                    }
1601    
1602                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1603    
1604                    if (!getDB().isSupportsInlineDistinct()) {
1605                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2);
1606                    }
1607    
1608                    if (orderByComparator != null) {
1609                            if (getDB().isSupportsInlineDistinct()) {
1610                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1611                                            orderByComparator, true);
1612                            }
1613                            else {
1614                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1615                                            orderByComparator, true);
1616                            }
1617                    }
1618                    else {
1619                            if (getDB().isSupportsInlineDistinct()) {
1620                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
1621                            }
1622                            else {
1623                                    query.append(PasswordPolicyModelImpl.ORDER_BY_SQL);
1624                            }
1625                    }
1626    
1627                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1628                                    PasswordPolicy.class.getName(),
1629                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1630    
1631                    Session session = null;
1632    
1633                    try {
1634                            session = openSession();
1635    
1636                            SQLQuery q = session.createSQLQuery(sql);
1637    
1638                            if (getDB().isSupportsInlineDistinct()) {
1639                                    q.addEntity(_FILTER_ENTITY_ALIAS, PasswordPolicyImpl.class);
1640                            }
1641                            else {
1642                                    q.addEntity(_FILTER_ENTITY_TABLE, PasswordPolicyImpl.class);
1643                            }
1644    
1645                            QueryPos qPos = QueryPos.getInstance(q);
1646    
1647                            if (bindUuid) {
1648                                    qPos.add(uuid);
1649                            }
1650    
1651                            qPos.add(companyId);
1652    
1653                            return (List<PasswordPolicy>)QueryUtil.list(q, getDialect(), start,
1654                                    end);
1655                    }
1656                    catch (Exception e) {
1657                            throw processException(e);
1658                    }
1659                    finally {
1660                            closeSession(session);
1661                    }
1662            }
1663    
1664            /**
1665             * Returns the password policies before and after the current password policy in the ordered set of password policies that the user has permission to view where uuid = &#63; and companyId = &#63;.
1666             *
1667             * @param passwordPolicyId the primary key of the current password policy
1668             * @param uuid the uuid
1669             * @param companyId the company ID
1670             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1671             * @return the previous, current, and next password policy
1672             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
1673             * @throws SystemException if a system exception occurred
1674             */
1675            @Override
1676            public PasswordPolicy[] filterFindByUuid_C_PrevAndNext(
1677                    long passwordPolicyId, String uuid, long companyId,
1678                    OrderByComparator orderByComparator)
1679                    throws NoSuchPasswordPolicyException, SystemException {
1680                    if (!InlineSQLHelperUtil.isEnabled()) {
1681                            return findByUuid_C_PrevAndNext(passwordPolicyId, uuid, companyId,
1682                                    orderByComparator);
1683                    }
1684    
1685                    PasswordPolicy passwordPolicy = findByPrimaryKey(passwordPolicyId);
1686    
1687                    Session session = null;
1688    
1689                    try {
1690                            session = openSession();
1691    
1692                            PasswordPolicy[] array = new PasswordPolicyImpl[3];
1693    
1694                            array[0] = filterGetByUuid_C_PrevAndNext(session, passwordPolicy,
1695                                            uuid, companyId, orderByComparator, true);
1696    
1697                            array[1] = passwordPolicy;
1698    
1699                            array[2] = filterGetByUuid_C_PrevAndNext(session, passwordPolicy,
1700                                            uuid, companyId, orderByComparator, false);
1701    
1702                            return array;
1703                    }
1704                    catch (Exception e) {
1705                            throw processException(e);
1706                    }
1707                    finally {
1708                            closeSession(session);
1709                    }
1710            }
1711    
1712            protected PasswordPolicy filterGetByUuid_C_PrevAndNext(Session session,
1713                    PasswordPolicy passwordPolicy, String uuid, long companyId,
1714                    OrderByComparator orderByComparator, boolean previous) {
1715                    StringBundler query = null;
1716    
1717                    if (orderByComparator != null) {
1718                            query = new StringBundler(6 +
1719                                            (orderByComparator.getOrderByFields().length * 6));
1720                    }
1721                    else {
1722                            query = new StringBundler(3);
1723                    }
1724    
1725                    if (getDB().isSupportsInlineDistinct()) {
1726                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE);
1727                    }
1728                    else {
1729                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1);
1730                    }
1731    
1732                    boolean bindUuid = false;
1733    
1734                    if (uuid == null) {
1735                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1736                    }
1737                    else if (uuid.equals(StringPool.BLANK)) {
1738                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1739                    }
1740                    else {
1741                            bindUuid = true;
1742    
1743                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1744                    }
1745    
1746                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1747    
1748                    if (!getDB().isSupportsInlineDistinct()) {
1749                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2);
1750                    }
1751    
1752                    if (orderByComparator != null) {
1753                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1754    
1755                            if (orderByConditionFields.length > 0) {
1756                                    query.append(WHERE_AND);
1757                            }
1758    
1759                            for (int i = 0; i < orderByConditionFields.length; i++) {
1760                                    if (getDB().isSupportsInlineDistinct()) {
1761                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1762                                    }
1763                                    else {
1764                                            query.append(_ORDER_BY_ENTITY_TABLE);
1765                                    }
1766    
1767                                    query.append(orderByConditionFields[i]);
1768    
1769                                    if ((i + 1) < orderByConditionFields.length) {
1770                                            if (orderByComparator.isAscending() ^ previous) {
1771                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1772                                            }
1773                                            else {
1774                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1775                                            }
1776                                    }
1777                                    else {
1778                                            if (orderByComparator.isAscending() ^ previous) {
1779                                                    query.append(WHERE_GREATER_THAN);
1780                                            }
1781                                            else {
1782                                                    query.append(WHERE_LESSER_THAN);
1783                                            }
1784                                    }
1785                            }
1786    
1787                            query.append(ORDER_BY_CLAUSE);
1788    
1789                            String[] orderByFields = orderByComparator.getOrderByFields();
1790    
1791                            for (int i = 0; i < orderByFields.length; i++) {
1792                                    if (getDB().isSupportsInlineDistinct()) {
1793                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1794                                    }
1795                                    else {
1796                                            query.append(_ORDER_BY_ENTITY_TABLE);
1797                                    }
1798    
1799                                    query.append(orderByFields[i]);
1800    
1801                                    if ((i + 1) < orderByFields.length) {
1802                                            if (orderByComparator.isAscending() ^ previous) {
1803                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1804                                            }
1805                                            else {
1806                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1807                                            }
1808                                    }
1809                                    else {
1810                                            if (orderByComparator.isAscending() ^ previous) {
1811                                                    query.append(ORDER_BY_ASC);
1812                                            }
1813                                            else {
1814                                                    query.append(ORDER_BY_DESC);
1815                                            }
1816                                    }
1817                            }
1818                    }
1819                    else {
1820                            if (getDB().isSupportsInlineDistinct()) {
1821                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
1822                            }
1823                            else {
1824                                    query.append(PasswordPolicyModelImpl.ORDER_BY_SQL);
1825                            }
1826                    }
1827    
1828                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1829                                    PasswordPolicy.class.getName(),
1830                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1831    
1832                    SQLQuery q = session.createSQLQuery(sql);
1833    
1834                    q.setFirstResult(0);
1835                    q.setMaxResults(2);
1836    
1837                    if (getDB().isSupportsInlineDistinct()) {
1838                            q.addEntity(_FILTER_ENTITY_ALIAS, PasswordPolicyImpl.class);
1839                    }
1840                    else {
1841                            q.addEntity(_FILTER_ENTITY_TABLE, PasswordPolicyImpl.class);
1842                    }
1843    
1844                    QueryPos qPos = QueryPos.getInstance(q);
1845    
1846                    if (bindUuid) {
1847                            qPos.add(uuid);
1848                    }
1849    
1850                    qPos.add(companyId);
1851    
1852                    if (orderByComparator != null) {
1853                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicy);
1854    
1855                            for (Object value : values) {
1856                                    qPos.add(value);
1857                            }
1858                    }
1859    
1860                    List<PasswordPolicy> list = q.list();
1861    
1862                    if (list.size() == 2) {
1863                            return list.get(1);
1864                    }
1865                    else {
1866                            return null;
1867                    }
1868            }
1869    
1870            /**
1871             * Removes all the password policies where uuid = &#63; and companyId = &#63; from the database.
1872             *
1873             * @param uuid the uuid
1874             * @param companyId the company ID
1875             * @throws SystemException if a system exception occurred
1876             */
1877            @Override
1878            public void removeByUuid_C(String uuid, long companyId)
1879                    throws SystemException {
1880                    for (PasswordPolicy passwordPolicy : findByUuid_C(uuid, companyId,
1881                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1882                            remove(passwordPolicy);
1883                    }
1884            }
1885    
1886            /**
1887             * Returns the number of password policies where uuid = &#63; and companyId = &#63;.
1888             *
1889             * @param uuid the uuid
1890             * @param companyId the company ID
1891             * @return the number of matching password policies
1892             * @throws SystemException if a system exception occurred
1893             */
1894            @Override
1895            public int countByUuid_C(String uuid, long companyId)
1896                    throws SystemException {
1897                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1898    
1899                    Object[] finderArgs = new Object[] { uuid, companyId };
1900    
1901                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1902                                    this);
1903    
1904                    if (count == null) {
1905                            StringBundler query = new StringBundler(3);
1906    
1907                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
1908    
1909                            boolean bindUuid = false;
1910    
1911                            if (uuid == null) {
1912                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1913                            }
1914                            else if (uuid.equals(StringPool.BLANK)) {
1915                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1916                            }
1917                            else {
1918                                    bindUuid = true;
1919    
1920                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1921                            }
1922    
1923                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1924    
1925                            String sql = query.toString();
1926    
1927                            Session session = null;
1928    
1929                            try {
1930                                    session = openSession();
1931    
1932                                    Query q = session.createQuery(sql);
1933    
1934                                    QueryPos qPos = QueryPos.getInstance(q);
1935    
1936                                    if (bindUuid) {
1937                                            qPos.add(uuid);
1938                                    }
1939    
1940                                    qPos.add(companyId);
1941    
1942                                    count = (Long)q.uniqueResult();
1943    
1944                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1945                            }
1946                            catch (Exception e) {
1947                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1948    
1949                                    throw processException(e);
1950                            }
1951                            finally {
1952                                    closeSession(session);
1953                            }
1954                    }
1955    
1956                    return count.intValue();
1957            }
1958    
1959            /**
1960             * Returns the number of password policies that the user has permission to view where uuid = &#63; and companyId = &#63;.
1961             *
1962             * @param uuid the uuid
1963             * @param companyId the company ID
1964             * @return the number of matching password policies that the user has permission to view
1965             * @throws SystemException if a system exception occurred
1966             */
1967            @Override
1968            public int filterCountByUuid_C(String uuid, long companyId)
1969                    throws SystemException {
1970                    if (!InlineSQLHelperUtil.isEnabled()) {
1971                            return countByUuid_C(uuid, companyId);
1972                    }
1973    
1974                    StringBundler query = new StringBundler(3);
1975    
1976                    query.append(_FILTER_SQL_COUNT_PASSWORDPOLICY_WHERE);
1977    
1978                    boolean bindUuid = false;
1979    
1980                    if (uuid == null) {
1981                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1982                    }
1983                    else if (uuid.equals(StringPool.BLANK)) {
1984                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1985                    }
1986                    else {
1987                            bindUuid = true;
1988    
1989                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1990                    }
1991    
1992                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1993    
1994                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1995                                    PasswordPolicy.class.getName(),
1996                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1997    
1998                    Session session = null;
1999    
2000                    try {
2001                            session = openSession();
2002    
2003                            SQLQuery q = session.createSQLQuery(sql);
2004    
2005                            q.addScalar(COUNT_COLUMN_NAME,
2006                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2007    
2008                            QueryPos qPos = QueryPos.getInstance(q);
2009    
2010                            if (bindUuid) {
2011                                    qPos.add(uuid);
2012                            }
2013    
2014                            qPos.add(companyId);
2015    
2016                            Long count = (Long)q.uniqueResult();
2017    
2018                            return count.intValue();
2019                    }
2020                    catch (Exception e) {
2021                            throw processException(e);
2022                    }
2023                    finally {
2024                            closeSession(session);
2025                    }
2026            }
2027    
2028            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "passwordPolicy.uuid IS NULL AND ";
2029            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "passwordPolicy.uuid = ? AND ";
2030            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(passwordPolicy.uuid IS NULL OR passwordPolicy.uuid = '') AND ";
2031            private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "passwordPolicy.uuid_ IS NULL AND ";
2032            private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "passwordPolicy.uuid_ = ? AND ";
2033            private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(passwordPolicy.uuid_ IS NULL OR passwordPolicy.uuid_ = '') AND ";
2034            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "passwordPolicy.companyId = ?";
2035            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2036                    new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2037                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
2038                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2039                            "findByCompanyId",
2040                            new String[] {
2041                                    Long.class.getName(),
2042                                    
2043                            Integer.class.getName(), Integer.class.getName(),
2044                                    OrderByComparator.class.getName()
2045                            });
2046            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2047                    new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2048                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
2049                            PasswordPolicyImpl.class,
2050                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2051                            new String[] { Long.class.getName() },
2052                            PasswordPolicyModelImpl.COMPANYID_COLUMN_BITMASK);
2053            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2054                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
2055                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2056                            new String[] { Long.class.getName() });
2057    
2058            /**
2059             * Returns all the password policies where companyId = &#63;.
2060             *
2061             * @param companyId the company ID
2062             * @return the matching password policies
2063             * @throws SystemException if a system exception occurred
2064             */
2065            @Override
2066            public List<PasswordPolicy> findByCompanyId(long companyId)
2067                    throws SystemException {
2068                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2069                            null);
2070            }
2071    
2072            /**
2073             * Returns a range of all the password policies where companyId = &#63;.
2074             *
2075             * <p>
2076             * 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.
2077             * </p>
2078             *
2079             * @param companyId the company ID
2080             * @param start the lower bound of the range of password policies
2081             * @param end the upper bound of the range of password policies (not inclusive)
2082             * @return the range of matching password policies
2083             * @throws SystemException if a system exception occurred
2084             */
2085            @Override
2086            public List<PasswordPolicy> findByCompanyId(long companyId, int start,
2087                    int end) throws SystemException {
2088                    return findByCompanyId(companyId, start, end, null);
2089            }
2090    
2091            /**
2092             * Returns an ordered range of all the password policies where companyId = &#63;.
2093             *
2094             * <p>
2095             * 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.
2096             * </p>
2097             *
2098             * @param companyId the company ID
2099             * @param start the lower bound of the range of password policies
2100             * @param end the upper bound of the range of password policies (not inclusive)
2101             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2102             * @return the ordered range of matching password policies
2103             * @throws SystemException if a system exception occurred
2104             */
2105            @Override
2106            public List<PasswordPolicy> findByCompanyId(long companyId, int start,
2107                    int end, OrderByComparator orderByComparator) throws SystemException {
2108                    boolean pagination = true;
2109                    FinderPath finderPath = null;
2110                    Object[] finderArgs = null;
2111    
2112                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2113                                    (orderByComparator == null)) {
2114                            pagination = false;
2115                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2116                            finderArgs = new Object[] { companyId };
2117                    }
2118                    else {
2119                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2120                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2121                    }
2122    
2123                    List<PasswordPolicy> list = (List<PasswordPolicy>)FinderCacheUtil.getResult(finderPath,
2124                                    finderArgs, this);
2125    
2126                    if ((list != null) && !list.isEmpty()) {
2127                            for (PasswordPolicy passwordPolicy : list) {
2128                                    if ((companyId != passwordPolicy.getCompanyId())) {
2129                                            list = null;
2130    
2131                                            break;
2132                                    }
2133                            }
2134                    }
2135    
2136                    if (list == null) {
2137                            StringBundler query = null;
2138    
2139                            if (orderByComparator != null) {
2140                                    query = new StringBundler(3 +
2141                                                    (orderByComparator.getOrderByFields().length * 3));
2142                            }
2143                            else {
2144                                    query = new StringBundler(3);
2145                            }
2146    
2147                            query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
2148    
2149                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2150    
2151                            if (orderByComparator != null) {
2152                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2153                                            orderByComparator);
2154                            }
2155                            else
2156                             if (pagination) {
2157                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
2158                            }
2159    
2160                            String sql = query.toString();
2161    
2162                            Session session = null;
2163    
2164                            try {
2165                                    session = openSession();
2166    
2167                                    Query q = session.createQuery(sql);
2168    
2169                                    QueryPos qPos = QueryPos.getInstance(q);
2170    
2171                                    qPos.add(companyId);
2172    
2173                                    if (!pagination) {
2174                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
2175                                                            getDialect(), start, end, false);
2176    
2177                                            Collections.sort(list);
2178    
2179                                            list = new UnmodifiableList<PasswordPolicy>(list);
2180                                    }
2181                                    else {
2182                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
2183                                                            getDialect(), start, end);
2184                                    }
2185    
2186                                    cacheResult(list);
2187    
2188                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2189                            }
2190                            catch (Exception e) {
2191                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2192    
2193                                    throw processException(e);
2194                            }
2195                            finally {
2196                                    closeSession(session);
2197                            }
2198                    }
2199    
2200                    return list;
2201            }
2202    
2203            /**
2204             * Returns the first password policy in the ordered set where companyId = &#63;.
2205             *
2206             * @param companyId the company ID
2207             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2208             * @return the first matching password policy
2209             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
2210             * @throws SystemException if a system exception occurred
2211             */
2212            @Override
2213            public PasswordPolicy findByCompanyId_First(long companyId,
2214                    OrderByComparator orderByComparator)
2215                    throws NoSuchPasswordPolicyException, SystemException {
2216                    PasswordPolicy passwordPolicy = fetchByCompanyId_First(companyId,
2217                                    orderByComparator);
2218    
2219                    if (passwordPolicy != null) {
2220                            return passwordPolicy;
2221                    }
2222    
2223                    StringBundler msg = new StringBundler(4);
2224    
2225                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2226    
2227                    msg.append("companyId=");
2228                    msg.append(companyId);
2229    
2230                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2231    
2232                    throw new NoSuchPasswordPolicyException(msg.toString());
2233            }
2234    
2235            /**
2236             * Returns the first password policy in the ordered set where companyId = &#63;.
2237             *
2238             * @param companyId the company ID
2239             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2240             * @return the first matching password policy, or <code>null</code> if a matching password policy could not be found
2241             * @throws SystemException if a system exception occurred
2242             */
2243            @Override
2244            public PasswordPolicy fetchByCompanyId_First(long companyId,
2245                    OrderByComparator orderByComparator) throws SystemException {
2246                    List<PasswordPolicy> list = findByCompanyId(companyId, 0, 1,
2247                                    orderByComparator);
2248    
2249                    if (!list.isEmpty()) {
2250                            return list.get(0);
2251                    }
2252    
2253                    return null;
2254            }
2255    
2256            /**
2257             * Returns the last password policy in the ordered set where companyId = &#63;.
2258             *
2259             * @param companyId the company ID
2260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2261             * @return the last matching password policy
2262             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
2263             * @throws SystemException if a system exception occurred
2264             */
2265            @Override
2266            public PasswordPolicy findByCompanyId_Last(long companyId,
2267                    OrderByComparator orderByComparator)
2268                    throws NoSuchPasswordPolicyException, SystemException {
2269                    PasswordPolicy passwordPolicy = fetchByCompanyId_Last(companyId,
2270                                    orderByComparator);
2271    
2272                    if (passwordPolicy != null) {
2273                            return passwordPolicy;
2274                    }
2275    
2276                    StringBundler msg = new StringBundler(4);
2277    
2278                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2279    
2280                    msg.append("companyId=");
2281                    msg.append(companyId);
2282    
2283                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2284    
2285                    throw new NoSuchPasswordPolicyException(msg.toString());
2286            }
2287    
2288            /**
2289             * Returns the last password policy in the ordered set where companyId = &#63;.
2290             *
2291             * @param companyId the company ID
2292             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2293             * @return the last matching password policy, or <code>null</code> if a matching password policy could not be found
2294             * @throws SystemException if a system exception occurred
2295             */
2296            @Override
2297            public PasswordPolicy fetchByCompanyId_Last(long companyId,
2298                    OrderByComparator orderByComparator) throws SystemException {
2299                    int count = countByCompanyId(companyId);
2300    
2301                    if (count == 0) {
2302                            return null;
2303                    }
2304    
2305                    List<PasswordPolicy> list = findByCompanyId(companyId, count - 1,
2306                                    count, orderByComparator);
2307    
2308                    if (!list.isEmpty()) {
2309                            return list.get(0);
2310                    }
2311    
2312                    return null;
2313            }
2314    
2315            /**
2316             * Returns the password policies before and after the current password policy in the ordered set where companyId = &#63;.
2317             *
2318             * @param passwordPolicyId the primary key of the current password policy
2319             * @param companyId the company ID
2320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2321             * @return the previous, current, and next password policy
2322             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
2323             * @throws SystemException if a system exception occurred
2324             */
2325            @Override
2326            public PasswordPolicy[] findByCompanyId_PrevAndNext(long passwordPolicyId,
2327                    long companyId, OrderByComparator orderByComparator)
2328                    throws NoSuchPasswordPolicyException, SystemException {
2329                    PasswordPolicy passwordPolicy = findByPrimaryKey(passwordPolicyId);
2330    
2331                    Session session = null;
2332    
2333                    try {
2334                            session = openSession();
2335    
2336                            PasswordPolicy[] array = new PasswordPolicyImpl[3];
2337    
2338                            array[0] = getByCompanyId_PrevAndNext(session, passwordPolicy,
2339                                            companyId, orderByComparator, true);
2340    
2341                            array[1] = passwordPolicy;
2342    
2343                            array[2] = getByCompanyId_PrevAndNext(session, passwordPolicy,
2344                                            companyId, orderByComparator, false);
2345    
2346                            return array;
2347                    }
2348                    catch (Exception e) {
2349                            throw processException(e);
2350                    }
2351                    finally {
2352                            closeSession(session);
2353                    }
2354            }
2355    
2356            protected PasswordPolicy getByCompanyId_PrevAndNext(Session session,
2357                    PasswordPolicy passwordPolicy, long companyId,
2358                    OrderByComparator orderByComparator, boolean previous) {
2359                    StringBundler query = null;
2360    
2361                    if (orderByComparator != null) {
2362                            query = new StringBundler(6 +
2363                                            (orderByComparator.getOrderByFields().length * 6));
2364                    }
2365                    else {
2366                            query = new StringBundler(3);
2367                    }
2368    
2369                    query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
2370    
2371                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2372    
2373                    if (orderByComparator != null) {
2374                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2375    
2376                            if (orderByConditionFields.length > 0) {
2377                                    query.append(WHERE_AND);
2378                            }
2379    
2380                            for (int i = 0; i < orderByConditionFields.length; i++) {
2381                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2382                                    query.append(orderByConditionFields[i]);
2383    
2384                                    if ((i + 1) < orderByConditionFields.length) {
2385                                            if (orderByComparator.isAscending() ^ previous) {
2386                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2387                                            }
2388                                            else {
2389                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2390                                            }
2391                                    }
2392                                    else {
2393                                            if (orderByComparator.isAscending() ^ previous) {
2394                                                    query.append(WHERE_GREATER_THAN);
2395                                            }
2396                                            else {
2397                                                    query.append(WHERE_LESSER_THAN);
2398                                            }
2399                                    }
2400                            }
2401    
2402                            query.append(ORDER_BY_CLAUSE);
2403    
2404                            String[] orderByFields = orderByComparator.getOrderByFields();
2405    
2406                            for (int i = 0; i < orderByFields.length; i++) {
2407                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2408                                    query.append(orderByFields[i]);
2409    
2410                                    if ((i + 1) < orderByFields.length) {
2411                                            if (orderByComparator.isAscending() ^ previous) {
2412                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2413                                            }
2414                                            else {
2415                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2416                                            }
2417                                    }
2418                                    else {
2419                                            if (orderByComparator.isAscending() ^ previous) {
2420                                                    query.append(ORDER_BY_ASC);
2421                                            }
2422                                            else {
2423                                                    query.append(ORDER_BY_DESC);
2424                                            }
2425                                    }
2426                            }
2427                    }
2428                    else {
2429                            query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
2430                    }
2431    
2432                    String sql = query.toString();
2433    
2434                    Query q = session.createQuery(sql);
2435    
2436                    q.setFirstResult(0);
2437                    q.setMaxResults(2);
2438    
2439                    QueryPos qPos = QueryPos.getInstance(q);
2440    
2441                    qPos.add(companyId);
2442    
2443                    if (orderByComparator != null) {
2444                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicy);
2445    
2446                            for (Object value : values) {
2447                                    qPos.add(value);
2448                            }
2449                    }
2450    
2451                    List<PasswordPolicy> list = q.list();
2452    
2453                    if (list.size() == 2) {
2454                            return list.get(1);
2455                    }
2456                    else {
2457                            return null;
2458                    }
2459            }
2460    
2461            /**
2462             * Returns all the password policies that the user has permission to view where companyId = &#63;.
2463             *
2464             * @param companyId the company ID
2465             * @return the matching password policies that the user has permission to view
2466             * @throws SystemException if a system exception occurred
2467             */
2468            @Override
2469            public List<PasswordPolicy> filterFindByCompanyId(long companyId)
2470                    throws SystemException {
2471                    return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2472                            QueryUtil.ALL_POS, null);
2473            }
2474    
2475            /**
2476             * Returns a range of all the password policies that the user has permission to view where companyId = &#63;.
2477             *
2478             * <p>
2479             * 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.
2480             * </p>
2481             *
2482             * @param companyId the company ID
2483             * @param start the lower bound of the range of password policies
2484             * @param end the upper bound of the range of password policies (not inclusive)
2485             * @return the range of matching password policies that the user has permission to view
2486             * @throws SystemException if a system exception occurred
2487             */
2488            @Override
2489            public List<PasswordPolicy> filterFindByCompanyId(long companyId,
2490                    int start, int end) throws SystemException {
2491                    return filterFindByCompanyId(companyId, start, end, null);
2492            }
2493    
2494            /**
2495             * Returns an ordered range of all the password policies that the user has permissions to view where companyId = &#63;.
2496             *
2497             * <p>
2498             * 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.
2499             * </p>
2500             *
2501             * @param companyId the company ID
2502             * @param start the lower bound of the range of password policies
2503             * @param end the upper bound of the range of password policies (not inclusive)
2504             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2505             * @return the ordered range of matching password policies that the user has permission to view
2506             * @throws SystemException if a system exception occurred
2507             */
2508            @Override
2509            public List<PasswordPolicy> filterFindByCompanyId(long companyId,
2510                    int start, int end, OrderByComparator orderByComparator)
2511                    throws SystemException {
2512                    if (!InlineSQLHelperUtil.isEnabled()) {
2513                            return findByCompanyId(companyId, start, end, orderByComparator);
2514                    }
2515    
2516                    StringBundler query = null;
2517    
2518                    if (orderByComparator != null) {
2519                            query = new StringBundler(3 +
2520                                            (orderByComparator.getOrderByFields().length * 3));
2521                    }
2522                    else {
2523                            query = new StringBundler(3);
2524                    }
2525    
2526                    if (getDB().isSupportsInlineDistinct()) {
2527                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE);
2528                    }
2529                    else {
2530                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1);
2531                    }
2532    
2533                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2534    
2535                    if (!getDB().isSupportsInlineDistinct()) {
2536                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2);
2537                    }
2538    
2539                    if (orderByComparator != null) {
2540                            if (getDB().isSupportsInlineDistinct()) {
2541                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2542                                            orderByComparator, true);
2543                            }
2544                            else {
2545                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2546                                            orderByComparator, true);
2547                            }
2548                    }
2549                    else {
2550                            if (getDB().isSupportsInlineDistinct()) {
2551                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
2552                            }
2553                            else {
2554                                    query.append(PasswordPolicyModelImpl.ORDER_BY_SQL);
2555                            }
2556                    }
2557    
2558                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2559                                    PasswordPolicy.class.getName(),
2560                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2561    
2562                    Session session = null;
2563    
2564                    try {
2565                            session = openSession();
2566    
2567                            SQLQuery q = session.createSQLQuery(sql);
2568    
2569                            if (getDB().isSupportsInlineDistinct()) {
2570                                    q.addEntity(_FILTER_ENTITY_ALIAS, PasswordPolicyImpl.class);
2571                            }
2572                            else {
2573                                    q.addEntity(_FILTER_ENTITY_TABLE, PasswordPolicyImpl.class);
2574                            }
2575    
2576                            QueryPos qPos = QueryPos.getInstance(q);
2577    
2578                            qPos.add(companyId);
2579    
2580                            return (List<PasswordPolicy>)QueryUtil.list(q, getDialect(), start,
2581                                    end);
2582                    }
2583                    catch (Exception e) {
2584                            throw processException(e);
2585                    }
2586                    finally {
2587                            closeSession(session);
2588                    }
2589            }
2590    
2591            /**
2592             * Returns the password policies before and after the current password policy in the ordered set of password policies that the user has permission to view where companyId = &#63;.
2593             *
2594             * @param passwordPolicyId the primary key of the current password policy
2595             * @param companyId the company ID
2596             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2597             * @return the previous, current, and next password policy
2598             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
2599             * @throws SystemException if a system exception occurred
2600             */
2601            @Override
2602            public PasswordPolicy[] filterFindByCompanyId_PrevAndNext(
2603                    long passwordPolicyId, long companyId,
2604                    OrderByComparator orderByComparator)
2605                    throws NoSuchPasswordPolicyException, SystemException {
2606                    if (!InlineSQLHelperUtil.isEnabled()) {
2607                            return findByCompanyId_PrevAndNext(passwordPolicyId, companyId,
2608                                    orderByComparator);
2609                    }
2610    
2611                    PasswordPolicy passwordPolicy = findByPrimaryKey(passwordPolicyId);
2612    
2613                    Session session = null;
2614    
2615                    try {
2616                            session = openSession();
2617    
2618                            PasswordPolicy[] array = new PasswordPolicyImpl[3];
2619    
2620                            array[0] = filterGetByCompanyId_PrevAndNext(session,
2621                                            passwordPolicy, companyId, orderByComparator, true);
2622    
2623                            array[1] = passwordPolicy;
2624    
2625                            array[2] = filterGetByCompanyId_PrevAndNext(session,
2626                                            passwordPolicy, companyId, orderByComparator, false);
2627    
2628                            return array;
2629                    }
2630                    catch (Exception e) {
2631                            throw processException(e);
2632                    }
2633                    finally {
2634                            closeSession(session);
2635                    }
2636            }
2637    
2638            protected PasswordPolicy filterGetByCompanyId_PrevAndNext(Session session,
2639                    PasswordPolicy passwordPolicy, long companyId,
2640                    OrderByComparator orderByComparator, boolean previous) {
2641                    StringBundler query = null;
2642    
2643                    if (orderByComparator != null) {
2644                            query = new StringBundler(6 +
2645                                            (orderByComparator.getOrderByFields().length * 6));
2646                    }
2647                    else {
2648                            query = new StringBundler(3);
2649                    }
2650    
2651                    if (getDB().isSupportsInlineDistinct()) {
2652                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE);
2653                    }
2654                    else {
2655                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1);
2656                    }
2657    
2658                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2659    
2660                    if (!getDB().isSupportsInlineDistinct()) {
2661                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2);
2662                    }
2663    
2664                    if (orderByComparator != null) {
2665                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2666    
2667                            if (orderByConditionFields.length > 0) {
2668                                    query.append(WHERE_AND);
2669                            }
2670    
2671                            for (int i = 0; i < orderByConditionFields.length; i++) {
2672                                    if (getDB().isSupportsInlineDistinct()) {
2673                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2674                                    }
2675                                    else {
2676                                            query.append(_ORDER_BY_ENTITY_TABLE);
2677                                    }
2678    
2679                                    query.append(orderByConditionFields[i]);
2680    
2681                                    if ((i + 1) < orderByConditionFields.length) {
2682                                            if (orderByComparator.isAscending() ^ previous) {
2683                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2684                                            }
2685                                            else {
2686                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2687                                            }
2688                                    }
2689                                    else {
2690                                            if (orderByComparator.isAscending() ^ previous) {
2691                                                    query.append(WHERE_GREATER_THAN);
2692                                            }
2693                                            else {
2694                                                    query.append(WHERE_LESSER_THAN);
2695                                            }
2696                                    }
2697                            }
2698    
2699                            query.append(ORDER_BY_CLAUSE);
2700    
2701                            String[] orderByFields = orderByComparator.getOrderByFields();
2702    
2703                            for (int i = 0; i < orderByFields.length; i++) {
2704                                    if (getDB().isSupportsInlineDistinct()) {
2705                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2706                                    }
2707                                    else {
2708                                            query.append(_ORDER_BY_ENTITY_TABLE);
2709                                    }
2710    
2711                                    query.append(orderByFields[i]);
2712    
2713                                    if ((i + 1) < orderByFields.length) {
2714                                            if (orderByComparator.isAscending() ^ previous) {
2715                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2716                                            }
2717                                            else {
2718                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2719                                            }
2720                                    }
2721                                    else {
2722                                            if (orderByComparator.isAscending() ^ previous) {
2723                                                    query.append(ORDER_BY_ASC);
2724                                            }
2725                                            else {
2726                                                    query.append(ORDER_BY_DESC);
2727                                            }
2728                                    }
2729                            }
2730                    }
2731                    else {
2732                            if (getDB().isSupportsInlineDistinct()) {
2733                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
2734                            }
2735                            else {
2736                                    query.append(PasswordPolicyModelImpl.ORDER_BY_SQL);
2737                            }
2738                    }
2739    
2740                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2741                                    PasswordPolicy.class.getName(),
2742                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2743    
2744                    SQLQuery q = session.createSQLQuery(sql);
2745    
2746                    q.setFirstResult(0);
2747                    q.setMaxResults(2);
2748    
2749                    if (getDB().isSupportsInlineDistinct()) {
2750                            q.addEntity(_FILTER_ENTITY_ALIAS, PasswordPolicyImpl.class);
2751                    }
2752                    else {
2753                            q.addEntity(_FILTER_ENTITY_TABLE, PasswordPolicyImpl.class);
2754                    }
2755    
2756                    QueryPos qPos = QueryPos.getInstance(q);
2757    
2758                    qPos.add(companyId);
2759    
2760                    if (orderByComparator != null) {
2761                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicy);
2762    
2763                            for (Object value : values) {
2764                                    qPos.add(value);
2765                            }
2766                    }
2767    
2768                    List<PasswordPolicy> list = q.list();
2769    
2770                    if (list.size() == 2) {
2771                            return list.get(1);
2772                    }
2773                    else {
2774                            return null;
2775                    }
2776            }
2777    
2778            /**
2779             * Removes all the password policies where companyId = &#63; from the database.
2780             *
2781             * @param companyId the company ID
2782             * @throws SystemException if a system exception occurred
2783             */
2784            @Override
2785            public void removeByCompanyId(long companyId) throws SystemException {
2786                    for (PasswordPolicy passwordPolicy : findByCompanyId(companyId,
2787                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2788                            remove(passwordPolicy);
2789                    }
2790            }
2791    
2792            /**
2793             * Returns the number of password policies where companyId = &#63;.
2794             *
2795             * @param companyId the company ID
2796             * @return the number of matching password policies
2797             * @throws SystemException if a system exception occurred
2798             */
2799            @Override
2800            public int countByCompanyId(long companyId) throws SystemException {
2801                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2802    
2803                    Object[] finderArgs = new Object[] { companyId };
2804    
2805                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2806                                    this);
2807    
2808                    if (count == null) {
2809                            StringBundler query = new StringBundler(2);
2810    
2811                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
2812    
2813                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2814    
2815                            String sql = query.toString();
2816    
2817                            Session session = null;
2818    
2819                            try {
2820                                    session = openSession();
2821    
2822                                    Query q = session.createQuery(sql);
2823    
2824                                    QueryPos qPos = QueryPos.getInstance(q);
2825    
2826                                    qPos.add(companyId);
2827    
2828                                    count = (Long)q.uniqueResult();
2829    
2830                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2831                            }
2832                            catch (Exception e) {
2833                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2834    
2835                                    throw processException(e);
2836                            }
2837                            finally {
2838                                    closeSession(session);
2839                            }
2840                    }
2841    
2842                    return count.intValue();
2843            }
2844    
2845            /**
2846             * Returns the number of password policies that the user has permission to view where companyId = &#63;.
2847             *
2848             * @param companyId the company ID
2849             * @return the number of matching password policies that the user has permission to view
2850             * @throws SystemException if a system exception occurred
2851             */
2852            @Override
2853            public int filterCountByCompanyId(long companyId) throws SystemException {
2854                    if (!InlineSQLHelperUtil.isEnabled()) {
2855                            return countByCompanyId(companyId);
2856                    }
2857    
2858                    StringBundler query = new StringBundler(2);
2859    
2860                    query.append(_FILTER_SQL_COUNT_PASSWORDPOLICY_WHERE);
2861    
2862                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2863    
2864                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2865                                    PasswordPolicy.class.getName(),
2866                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2867    
2868                    Session session = null;
2869    
2870                    try {
2871                            session = openSession();
2872    
2873                            SQLQuery q = session.createSQLQuery(sql);
2874    
2875                            q.addScalar(COUNT_COLUMN_NAME,
2876                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2877    
2878                            QueryPos qPos = QueryPos.getInstance(q);
2879    
2880                            qPos.add(companyId);
2881    
2882                            Long count = (Long)q.uniqueResult();
2883    
2884                            return count.intValue();
2885                    }
2886                    catch (Exception e) {
2887                            throw processException(e);
2888                    }
2889                    finally {
2890                            closeSession(session);
2891                    }
2892            }
2893    
2894            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "passwordPolicy.companyId = ?";
2895            public static final FinderPath FINDER_PATH_FETCH_BY_C_DP = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2896                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
2897                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_DP",
2898                            new String[] { Long.class.getName(), Boolean.class.getName() },
2899                            PasswordPolicyModelImpl.COMPANYID_COLUMN_BITMASK |
2900                            PasswordPolicyModelImpl.DEFAULTPOLICY_COLUMN_BITMASK);
2901            public static final FinderPath FINDER_PATH_COUNT_BY_C_DP = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2902                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
2903                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_DP",
2904                            new String[] { Long.class.getName(), Boolean.class.getName() });
2905    
2906            /**
2907             * Returns the password policy where companyId = &#63; and defaultPolicy = &#63; or throws a {@link com.liferay.portal.NoSuchPasswordPolicyException} if it could not be found.
2908             *
2909             * @param companyId the company ID
2910             * @param defaultPolicy the default policy
2911             * @return the matching password policy
2912             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
2913             * @throws SystemException if a system exception occurred
2914             */
2915            @Override
2916            public PasswordPolicy findByC_DP(long companyId, boolean defaultPolicy)
2917                    throws NoSuchPasswordPolicyException, SystemException {
2918                    PasswordPolicy passwordPolicy = fetchByC_DP(companyId, defaultPolicy);
2919    
2920                    if (passwordPolicy == null) {
2921                            StringBundler msg = new StringBundler(6);
2922    
2923                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2924    
2925                            msg.append("companyId=");
2926                            msg.append(companyId);
2927    
2928                            msg.append(", defaultPolicy=");
2929                            msg.append(defaultPolicy);
2930    
2931                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2932    
2933                            if (_log.isWarnEnabled()) {
2934                                    _log.warn(msg.toString());
2935                            }
2936    
2937                            throw new NoSuchPasswordPolicyException(msg.toString());
2938                    }
2939    
2940                    return passwordPolicy;
2941            }
2942    
2943            /**
2944             * 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.
2945             *
2946             * @param companyId the company ID
2947             * @param defaultPolicy the default policy
2948             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
2949             * @throws SystemException if a system exception occurred
2950             */
2951            @Override
2952            public PasswordPolicy fetchByC_DP(long companyId, boolean defaultPolicy)
2953                    throws SystemException {
2954                    return fetchByC_DP(companyId, defaultPolicy, true);
2955            }
2956    
2957            /**
2958             * 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.
2959             *
2960             * @param companyId the company ID
2961             * @param defaultPolicy the default policy
2962             * @param retrieveFromCache whether to use the finder cache
2963             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
2964             * @throws SystemException if a system exception occurred
2965             */
2966            @Override
2967            public PasswordPolicy fetchByC_DP(long companyId, boolean defaultPolicy,
2968                    boolean retrieveFromCache) throws SystemException {
2969                    Object[] finderArgs = new Object[] { companyId, defaultPolicy };
2970    
2971                    Object result = null;
2972    
2973                    if (retrieveFromCache) {
2974                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_DP,
2975                                            finderArgs, this);
2976                    }
2977    
2978                    if (result instanceof PasswordPolicy) {
2979                            PasswordPolicy passwordPolicy = (PasswordPolicy)result;
2980    
2981                            if ((companyId != passwordPolicy.getCompanyId()) ||
2982                                            (defaultPolicy != passwordPolicy.getDefaultPolicy())) {
2983                                    result = null;
2984                            }
2985                    }
2986    
2987                    if (result == null) {
2988                            StringBundler query = new StringBundler(4);
2989    
2990                            query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
2991    
2992                            query.append(_FINDER_COLUMN_C_DP_COMPANYID_2);
2993    
2994                            query.append(_FINDER_COLUMN_C_DP_DEFAULTPOLICY_2);
2995    
2996                            String sql = query.toString();
2997    
2998                            Session session = null;
2999    
3000                            try {
3001                                    session = openSession();
3002    
3003                                    Query q = session.createQuery(sql);
3004    
3005                                    QueryPos qPos = QueryPos.getInstance(q);
3006    
3007                                    qPos.add(companyId);
3008    
3009                                    qPos.add(defaultPolicy);
3010    
3011                                    List<PasswordPolicy> list = q.list();
3012    
3013                                    if (list.isEmpty()) {
3014                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
3015                                                    finderArgs, list);
3016                                    }
3017                                    else {
3018                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
3019                                                    _log.warn(
3020                                                            "PasswordPolicyPersistenceImpl.fetchByC_DP(long, boolean, boolean) with parameters (" +
3021                                                            StringUtil.merge(finderArgs) +
3022                                                            ") 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.");
3023                                            }
3024    
3025                                            PasswordPolicy passwordPolicy = list.get(0);
3026    
3027                                            result = passwordPolicy;
3028    
3029                                            cacheResult(passwordPolicy);
3030    
3031                                            if ((passwordPolicy.getCompanyId() != companyId) ||
3032                                                            (passwordPolicy.getDefaultPolicy() != defaultPolicy)) {
3033                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
3034                                                            finderArgs, passwordPolicy);
3035                                            }
3036                                    }
3037                            }
3038                            catch (Exception e) {
3039                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP,
3040                                            finderArgs);
3041    
3042                                    throw processException(e);
3043                            }
3044                            finally {
3045                                    closeSession(session);
3046                            }
3047                    }
3048    
3049                    if (result instanceof List<?>) {
3050                            return null;
3051                    }
3052                    else {
3053                            return (PasswordPolicy)result;
3054                    }
3055            }
3056    
3057            /**
3058             * Removes the password policy where companyId = &#63; and defaultPolicy = &#63; from the database.
3059             *
3060             * @param companyId the company ID
3061             * @param defaultPolicy the default policy
3062             * @return the password policy that was removed
3063             * @throws SystemException if a system exception occurred
3064             */
3065            @Override
3066            public PasswordPolicy removeByC_DP(long companyId, boolean defaultPolicy)
3067                    throws NoSuchPasswordPolicyException, SystemException {
3068                    PasswordPolicy passwordPolicy = findByC_DP(companyId, defaultPolicy);
3069    
3070                    return remove(passwordPolicy);
3071            }
3072    
3073            /**
3074             * Returns the number of password policies where companyId = &#63; and defaultPolicy = &#63;.
3075             *
3076             * @param companyId the company ID
3077             * @param defaultPolicy the default policy
3078             * @return the number of matching password policies
3079             * @throws SystemException if a system exception occurred
3080             */
3081            @Override
3082            public int countByC_DP(long companyId, boolean defaultPolicy)
3083                    throws SystemException {
3084                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_DP;
3085    
3086                    Object[] finderArgs = new Object[] { companyId, defaultPolicy };
3087    
3088                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3089                                    this);
3090    
3091                    if (count == null) {
3092                            StringBundler query = new StringBundler(3);
3093    
3094                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
3095    
3096                            query.append(_FINDER_COLUMN_C_DP_COMPANYID_2);
3097    
3098                            query.append(_FINDER_COLUMN_C_DP_DEFAULTPOLICY_2);
3099    
3100                            String sql = query.toString();
3101    
3102                            Session session = null;
3103    
3104                            try {
3105                                    session = openSession();
3106    
3107                                    Query q = session.createQuery(sql);
3108    
3109                                    QueryPos qPos = QueryPos.getInstance(q);
3110    
3111                                    qPos.add(companyId);
3112    
3113                                    qPos.add(defaultPolicy);
3114    
3115                                    count = (Long)q.uniqueResult();
3116    
3117                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3118                            }
3119                            catch (Exception e) {
3120                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3121    
3122                                    throw processException(e);
3123                            }
3124                            finally {
3125                                    closeSession(session);
3126                            }
3127                    }
3128    
3129                    return count.intValue();
3130            }
3131    
3132            private static final String _FINDER_COLUMN_C_DP_COMPANYID_2 = "passwordPolicy.companyId = ? AND ";
3133            private static final String _FINDER_COLUMN_C_DP_DEFAULTPOLICY_2 = "passwordPolicy.defaultPolicy = ?";
3134            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
3135                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
3136                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
3137                            new String[] { Long.class.getName(), String.class.getName() },
3138                            PasswordPolicyModelImpl.COMPANYID_COLUMN_BITMASK |
3139                            PasswordPolicyModelImpl.NAME_COLUMN_BITMASK);
3140            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
3141                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
3142                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
3143                            new String[] { Long.class.getName(), String.class.getName() });
3144    
3145            /**
3146             * Returns the password policy where companyId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchPasswordPolicyException} if it could not be found.
3147             *
3148             * @param companyId the company ID
3149             * @param name the name
3150             * @return the matching password policy
3151             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
3152             * @throws SystemException if a system exception occurred
3153             */
3154            @Override
3155            public PasswordPolicy findByC_N(long companyId, String name)
3156                    throws NoSuchPasswordPolicyException, SystemException {
3157                    PasswordPolicy passwordPolicy = fetchByC_N(companyId, name);
3158    
3159                    if (passwordPolicy == null) {
3160                            StringBundler msg = new StringBundler(6);
3161    
3162                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3163    
3164                            msg.append("companyId=");
3165                            msg.append(companyId);
3166    
3167                            msg.append(", name=");
3168                            msg.append(name);
3169    
3170                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3171    
3172                            if (_log.isWarnEnabled()) {
3173                                    _log.warn(msg.toString());
3174                            }
3175    
3176                            throw new NoSuchPasswordPolicyException(msg.toString());
3177                    }
3178    
3179                    return passwordPolicy;
3180            }
3181    
3182            /**
3183             * 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.
3184             *
3185             * @param companyId the company ID
3186             * @param name the name
3187             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
3188             * @throws SystemException if a system exception occurred
3189             */
3190            @Override
3191            public PasswordPolicy fetchByC_N(long companyId, String name)
3192                    throws SystemException {
3193                    return fetchByC_N(companyId, name, true);
3194            }
3195    
3196            /**
3197             * 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.
3198             *
3199             * @param companyId the company ID
3200             * @param name the name
3201             * @param retrieveFromCache whether to use the finder cache
3202             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
3203             * @throws SystemException if a system exception occurred
3204             */
3205            @Override
3206            public PasswordPolicy fetchByC_N(long companyId, String name,
3207                    boolean retrieveFromCache) throws SystemException {
3208                    Object[] finderArgs = new Object[] { companyId, name };
3209    
3210                    Object result = null;
3211    
3212                    if (retrieveFromCache) {
3213                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
3214                                            finderArgs, this);
3215                    }
3216    
3217                    if (result instanceof PasswordPolicy) {
3218                            PasswordPolicy passwordPolicy = (PasswordPolicy)result;
3219    
3220                            if ((companyId != passwordPolicy.getCompanyId()) ||
3221                                            !Validator.equals(name, passwordPolicy.getName())) {
3222                                    result = null;
3223                            }
3224                    }
3225    
3226                    if (result == null) {
3227                            StringBundler query = new StringBundler(4);
3228    
3229                            query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
3230    
3231                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
3232    
3233                            boolean bindName = false;
3234    
3235                            if (name == null) {
3236                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
3237                            }
3238                            else if (name.equals(StringPool.BLANK)) {
3239                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
3240                            }
3241                            else {
3242                                    bindName = true;
3243    
3244                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
3245                            }
3246    
3247                            String sql = query.toString();
3248    
3249                            Session session = null;
3250    
3251                            try {
3252                                    session = openSession();
3253    
3254                                    Query q = session.createQuery(sql);
3255    
3256                                    QueryPos qPos = QueryPos.getInstance(q);
3257    
3258                                    qPos.add(companyId);
3259    
3260                                    if (bindName) {
3261                                            qPos.add(name);
3262                                    }
3263    
3264                                    List<PasswordPolicy> list = q.list();
3265    
3266                                    if (list.isEmpty()) {
3267                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
3268                                                    finderArgs, list);
3269                                    }
3270                                    else {
3271                                            PasswordPolicy passwordPolicy = list.get(0);
3272    
3273                                            result = passwordPolicy;
3274    
3275                                            cacheResult(passwordPolicy);
3276    
3277                                            if ((passwordPolicy.getCompanyId() != companyId) ||
3278                                                            (passwordPolicy.getName() == null) ||
3279                                                            !passwordPolicy.getName().equals(name)) {
3280                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
3281                                                            finderArgs, passwordPolicy);
3282                                            }
3283                                    }
3284                            }
3285                            catch (Exception e) {
3286                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
3287                                            finderArgs);
3288    
3289                                    throw processException(e);
3290                            }
3291                            finally {
3292                                    closeSession(session);
3293                            }
3294                    }
3295    
3296                    if (result instanceof List<?>) {
3297                            return null;
3298                    }
3299                    else {
3300                            return (PasswordPolicy)result;
3301                    }
3302            }
3303    
3304            /**
3305             * Removes the password policy where companyId = &#63; and name = &#63; from the database.
3306             *
3307             * @param companyId the company ID
3308             * @param name the name
3309             * @return the password policy that was removed
3310             * @throws SystemException if a system exception occurred
3311             */
3312            @Override
3313            public PasswordPolicy removeByC_N(long companyId, String name)
3314                    throws NoSuchPasswordPolicyException, SystemException {
3315                    PasswordPolicy passwordPolicy = findByC_N(companyId, name);
3316    
3317                    return remove(passwordPolicy);
3318            }
3319    
3320            /**
3321             * Returns the number of password policies where companyId = &#63; and name = &#63;.
3322             *
3323             * @param companyId the company ID
3324             * @param name the name
3325             * @return the number of matching password policies
3326             * @throws SystemException if a system exception occurred
3327             */
3328            @Override
3329            public int countByC_N(long companyId, String name)
3330                    throws SystemException {
3331                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
3332    
3333                    Object[] finderArgs = new Object[] { companyId, name };
3334    
3335                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3336                                    this);
3337    
3338                    if (count == null) {
3339                            StringBundler query = new StringBundler(3);
3340    
3341                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
3342    
3343                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
3344    
3345                            boolean bindName = false;
3346    
3347                            if (name == null) {
3348                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
3349                            }
3350                            else if (name.equals(StringPool.BLANK)) {
3351                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
3352                            }
3353                            else {
3354                                    bindName = true;
3355    
3356                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
3357                            }
3358    
3359                            String sql = query.toString();
3360    
3361                            Session session = null;
3362    
3363                            try {
3364                                    session = openSession();
3365    
3366                                    Query q = session.createQuery(sql);
3367    
3368                                    QueryPos qPos = QueryPos.getInstance(q);
3369    
3370                                    qPos.add(companyId);
3371    
3372                                    if (bindName) {
3373                                            qPos.add(name);
3374                                    }
3375    
3376                                    count = (Long)q.uniqueResult();
3377    
3378                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3379                            }
3380                            catch (Exception e) {
3381                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3382    
3383                                    throw processException(e);
3384                            }
3385                            finally {
3386                                    closeSession(session);
3387                            }
3388                    }
3389    
3390                    return count.intValue();
3391            }
3392    
3393            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "passwordPolicy.companyId = ? AND ";
3394            private static final String _FINDER_COLUMN_C_N_NAME_1 = "passwordPolicy.name IS NULL";
3395            private static final String _FINDER_COLUMN_C_N_NAME_2 = "passwordPolicy.name = ?";
3396            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(passwordPolicy.name IS NULL OR passwordPolicy.name = '')";
3397    
3398            public PasswordPolicyPersistenceImpl() {
3399                    setModelClass(PasswordPolicy.class);
3400            }
3401    
3402            /**
3403             * Caches the password policy in the entity cache if it is enabled.
3404             *
3405             * @param passwordPolicy the password policy
3406             */
3407            @Override
3408            public void cacheResult(PasswordPolicy passwordPolicy) {
3409                    EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
3410                            PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey(),
3411                            passwordPolicy);
3412    
3413                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
3414                            new Object[] {
3415                                    passwordPolicy.getCompanyId(), passwordPolicy.getDefaultPolicy()
3416                            }, passwordPolicy);
3417    
3418                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
3419                            new Object[] { passwordPolicy.getCompanyId(), passwordPolicy.getName() },
3420                            passwordPolicy);
3421    
3422                    passwordPolicy.resetOriginalValues();
3423            }
3424    
3425            /**
3426             * Caches the password policies in the entity cache if it is enabled.
3427             *
3428             * @param passwordPolicies the password policies
3429             */
3430            @Override
3431            public void cacheResult(List<PasswordPolicy> passwordPolicies) {
3432                    for (PasswordPolicy passwordPolicy : passwordPolicies) {
3433                            if (EntityCacheUtil.getResult(
3434                                                    PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
3435                                                    PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey()) == null) {
3436                                    cacheResult(passwordPolicy);
3437                            }
3438                            else {
3439                                    passwordPolicy.resetOriginalValues();
3440                            }
3441                    }
3442            }
3443    
3444            /**
3445             * Clears the cache for all password policies.
3446             *
3447             * <p>
3448             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3449             * </p>
3450             */
3451            @Override
3452            public void clearCache() {
3453                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
3454                            CacheRegistryUtil.clear(PasswordPolicyImpl.class.getName());
3455                    }
3456    
3457                    EntityCacheUtil.clearCache(PasswordPolicyImpl.class.getName());
3458    
3459                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3460                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3461                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3462            }
3463    
3464            /**
3465             * Clears the cache for the password policy.
3466             *
3467             * <p>
3468             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3469             * </p>
3470             */
3471            @Override
3472            public void clearCache(PasswordPolicy passwordPolicy) {
3473                    EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
3474                            PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey());
3475    
3476                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3477                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3478    
3479                    clearUniqueFindersCache(passwordPolicy);
3480            }
3481    
3482            @Override
3483            public void clearCache(List<PasswordPolicy> passwordPolicies) {
3484                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3485                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3486    
3487                    for (PasswordPolicy passwordPolicy : passwordPolicies) {
3488                            EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
3489                                    PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey());
3490    
3491                            clearUniqueFindersCache(passwordPolicy);
3492                    }
3493            }
3494    
3495            protected void cacheUniqueFindersCache(PasswordPolicy passwordPolicy) {
3496                    if (passwordPolicy.isNew()) {
3497                            Object[] args = new Object[] {
3498                                            passwordPolicy.getCompanyId(),
3499                                            passwordPolicy.getDefaultPolicy()
3500                                    };
3501    
3502                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_DP, args,
3503                                    Long.valueOf(1));
3504                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP, args,
3505                                    passwordPolicy);
3506    
3507                            args = new Object[] {
3508                                            passwordPolicy.getCompanyId(), passwordPolicy.getName()
3509                                    };
3510    
3511                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
3512                                    Long.valueOf(1));
3513                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
3514                                    passwordPolicy);
3515                    }
3516                    else {
3517                            PasswordPolicyModelImpl passwordPolicyModelImpl = (PasswordPolicyModelImpl)passwordPolicy;
3518    
3519                            if ((passwordPolicyModelImpl.getColumnBitmask() &
3520                                            FINDER_PATH_FETCH_BY_C_DP.getColumnBitmask()) != 0) {
3521                                    Object[] args = new Object[] {
3522                                                    passwordPolicy.getCompanyId(),
3523                                                    passwordPolicy.getDefaultPolicy()
3524                                            };
3525    
3526                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_DP, args,
3527                                            Long.valueOf(1));
3528                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP, args,
3529                                            passwordPolicy);
3530                            }
3531    
3532                            if ((passwordPolicyModelImpl.getColumnBitmask() &
3533                                            FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
3534                                    Object[] args = new Object[] {
3535                                                    passwordPolicy.getCompanyId(), passwordPolicy.getName()
3536                                            };
3537    
3538                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
3539                                            Long.valueOf(1));
3540                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
3541                                            passwordPolicy);
3542                            }
3543                    }
3544            }
3545    
3546            protected void clearUniqueFindersCache(PasswordPolicy passwordPolicy) {
3547                    PasswordPolicyModelImpl passwordPolicyModelImpl = (PasswordPolicyModelImpl)passwordPolicy;
3548    
3549                    Object[] args = new Object[] {
3550                                    passwordPolicy.getCompanyId(), passwordPolicy.getDefaultPolicy()
3551                            };
3552    
3553                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_DP, args);
3554                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP, args);
3555    
3556                    if ((passwordPolicyModelImpl.getColumnBitmask() &
3557                                    FINDER_PATH_FETCH_BY_C_DP.getColumnBitmask()) != 0) {
3558                            args = new Object[] {
3559                                            passwordPolicyModelImpl.getOriginalCompanyId(),
3560                                            passwordPolicyModelImpl.getOriginalDefaultPolicy()
3561                                    };
3562    
3563                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_DP, args);
3564                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP, args);
3565                    }
3566    
3567                    args = new Object[] {
3568                                    passwordPolicy.getCompanyId(), passwordPolicy.getName()
3569                            };
3570    
3571                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
3572                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
3573    
3574                    if ((passwordPolicyModelImpl.getColumnBitmask() &
3575                                    FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
3576                            args = new Object[] {
3577                                            passwordPolicyModelImpl.getOriginalCompanyId(),
3578                                            passwordPolicyModelImpl.getOriginalName()
3579                                    };
3580    
3581                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
3582                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
3583                    }
3584            }
3585    
3586            /**
3587             * Creates a new password policy with the primary key. Does not add the password policy to the database.
3588             *
3589             * @param passwordPolicyId the primary key for the new password policy
3590             * @return the new password policy
3591             */
3592            @Override
3593            public PasswordPolicy create(long passwordPolicyId) {
3594                    PasswordPolicy passwordPolicy = new PasswordPolicyImpl();
3595    
3596                    passwordPolicy.setNew(true);
3597                    passwordPolicy.setPrimaryKey(passwordPolicyId);
3598    
3599                    String uuid = PortalUUIDUtil.generate();
3600    
3601                    passwordPolicy.setUuid(uuid);
3602    
3603                    return passwordPolicy;
3604            }
3605    
3606            /**
3607             * Removes the password policy with the primary key from the database. Also notifies the appropriate model listeners.
3608             *
3609             * @param passwordPolicyId the primary key of the password policy
3610             * @return the password policy that was removed
3611             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
3612             * @throws SystemException if a system exception occurred
3613             */
3614            @Override
3615            public PasswordPolicy remove(long passwordPolicyId)
3616                    throws NoSuchPasswordPolicyException, SystemException {
3617                    return remove((Serializable)passwordPolicyId);
3618            }
3619    
3620            /**
3621             * Removes the password policy with the primary key from the database. Also notifies the appropriate model listeners.
3622             *
3623             * @param primaryKey the primary key of the password policy
3624             * @return the password policy that was removed
3625             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
3626             * @throws SystemException if a system exception occurred
3627             */
3628            @Override
3629            public PasswordPolicy remove(Serializable primaryKey)
3630                    throws NoSuchPasswordPolicyException, SystemException {
3631                    Session session = null;
3632    
3633                    try {
3634                            session = openSession();
3635    
3636                            PasswordPolicy passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
3637                                            primaryKey);
3638    
3639                            if (passwordPolicy == null) {
3640                                    if (_log.isWarnEnabled()) {
3641                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3642                                    }
3643    
3644                                    throw new NoSuchPasswordPolicyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3645                                            primaryKey);
3646                            }
3647    
3648                            return remove(passwordPolicy);
3649                    }
3650                    catch (NoSuchPasswordPolicyException nsee) {
3651                            throw nsee;
3652                    }
3653                    catch (Exception e) {
3654                            throw processException(e);
3655                    }
3656                    finally {
3657                            closeSession(session);
3658                    }
3659            }
3660    
3661            @Override
3662            protected PasswordPolicy removeImpl(PasswordPolicy passwordPolicy)
3663                    throws SystemException {
3664                    passwordPolicy = toUnwrappedModel(passwordPolicy);
3665    
3666                    Session session = null;
3667    
3668                    try {
3669                            session = openSession();
3670    
3671                            if (!session.contains(passwordPolicy)) {
3672                                    passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
3673                                                    passwordPolicy.getPrimaryKeyObj());
3674                            }
3675    
3676                            if (passwordPolicy != null) {
3677                                    session.delete(passwordPolicy);
3678                            }
3679                    }
3680                    catch (Exception e) {
3681                            throw processException(e);
3682                    }
3683                    finally {
3684                            closeSession(session);
3685                    }
3686    
3687                    if (passwordPolicy != null) {
3688                            clearCache(passwordPolicy);
3689                    }
3690    
3691                    return passwordPolicy;
3692            }
3693    
3694            @Override
3695            public PasswordPolicy updateImpl(
3696                    com.liferay.portal.model.PasswordPolicy passwordPolicy)
3697                    throws SystemException {
3698                    passwordPolicy = toUnwrappedModel(passwordPolicy);
3699    
3700                    boolean isNew = passwordPolicy.isNew();
3701    
3702                    PasswordPolicyModelImpl passwordPolicyModelImpl = (PasswordPolicyModelImpl)passwordPolicy;
3703    
3704                    if (Validator.isNull(passwordPolicy.getUuid())) {
3705                            String uuid = PortalUUIDUtil.generate();
3706    
3707                            passwordPolicy.setUuid(uuid);
3708                    }
3709    
3710                    Session session = null;
3711    
3712                    try {
3713                            session = openSession();
3714    
3715                            if (passwordPolicy.isNew()) {
3716                                    session.save(passwordPolicy);
3717    
3718                                    passwordPolicy.setNew(false);
3719                            }
3720                            else {
3721                                    session.merge(passwordPolicy);
3722                            }
3723                    }
3724                    catch (Exception e) {
3725                            throw processException(e);
3726                    }
3727                    finally {
3728                            closeSession(session);
3729                    }
3730    
3731                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3732    
3733                    if (isNew || !PasswordPolicyModelImpl.COLUMN_BITMASK_ENABLED) {
3734                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3735                    }
3736    
3737                    else {
3738                            if ((passwordPolicyModelImpl.getColumnBitmask() &
3739                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
3740                                    Object[] args = new Object[] {
3741                                                    passwordPolicyModelImpl.getOriginalUuid()
3742                                            };
3743    
3744                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
3745                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
3746                                            args);
3747    
3748                                    args = new Object[] { passwordPolicyModelImpl.getUuid() };
3749    
3750                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
3751                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
3752                                            args);
3753                            }
3754    
3755                            if ((passwordPolicyModelImpl.getColumnBitmask() &
3756                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
3757                                    Object[] args = new Object[] {
3758                                                    passwordPolicyModelImpl.getOriginalUuid(),
3759                                                    passwordPolicyModelImpl.getOriginalCompanyId()
3760                                            };
3761    
3762                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
3763                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
3764                                            args);
3765    
3766                                    args = new Object[] {
3767                                                    passwordPolicyModelImpl.getUuid(),
3768                                                    passwordPolicyModelImpl.getCompanyId()
3769                                            };
3770    
3771                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
3772                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
3773                                            args);
3774                            }
3775    
3776                            if ((passwordPolicyModelImpl.getColumnBitmask() &
3777                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
3778                                    Object[] args = new Object[] {
3779                                                    passwordPolicyModelImpl.getOriginalCompanyId()
3780                                            };
3781    
3782                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
3783                                            args);
3784                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
3785                                            args);
3786    
3787                                    args = new Object[] { passwordPolicyModelImpl.getCompanyId() };
3788    
3789                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
3790                                            args);
3791                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
3792                                            args);
3793                            }
3794                    }
3795    
3796                    EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
3797                            PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey(),
3798                            passwordPolicy);
3799    
3800                    clearUniqueFindersCache(passwordPolicy);
3801                    cacheUniqueFindersCache(passwordPolicy);
3802    
3803                    return passwordPolicy;
3804            }
3805    
3806            protected PasswordPolicy toUnwrappedModel(PasswordPolicy passwordPolicy) {
3807                    if (passwordPolicy instanceof PasswordPolicyImpl) {
3808                            return passwordPolicy;
3809                    }
3810    
3811                    PasswordPolicyImpl passwordPolicyImpl = new PasswordPolicyImpl();
3812    
3813                    passwordPolicyImpl.setNew(passwordPolicy.isNew());
3814                    passwordPolicyImpl.setPrimaryKey(passwordPolicy.getPrimaryKey());
3815    
3816                    passwordPolicyImpl.setUuid(passwordPolicy.getUuid());
3817                    passwordPolicyImpl.setPasswordPolicyId(passwordPolicy.getPasswordPolicyId());
3818                    passwordPolicyImpl.setCompanyId(passwordPolicy.getCompanyId());
3819                    passwordPolicyImpl.setUserId(passwordPolicy.getUserId());
3820                    passwordPolicyImpl.setUserName(passwordPolicy.getUserName());
3821                    passwordPolicyImpl.setCreateDate(passwordPolicy.getCreateDate());
3822                    passwordPolicyImpl.setModifiedDate(passwordPolicy.getModifiedDate());
3823                    passwordPolicyImpl.setDefaultPolicy(passwordPolicy.isDefaultPolicy());
3824                    passwordPolicyImpl.setName(passwordPolicy.getName());
3825                    passwordPolicyImpl.setDescription(passwordPolicy.getDescription());
3826                    passwordPolicyImpl.setChangeable(passwordPolicy.isChangeable());
3827                    passwordPolicyImpl.setChangeRequired(passwordPolicy.isChangeRequired());
3828                    passwordPolicyImpl.setMinAge(passwordPolicy.getMinAge());
3829                    passwordPolicyImpl.setCheckSyntax(passwordPolicy.isCheckSyntax());
3830                    passwordPolicyImpl.setAllowDictionaryWords(passwordPolicy.isAllowDictionaryWords());
3831                    passwordPolicyImpl.setMinAlphanumeric(passwordPolicy.getMinAlphanumeric());
3832                    passwordPolicyImpl.setMinLength(passwordPolicy.getMinLength());
3833                    passwordPolicyImpl.setMinLowerCase(passwordPolicy.getMinLowerCase());
3834                    passwordPolicyImpl.setMinNumbers(passwordPolicy.getMinNumbers());
3835                    passwordPolicyImpl.setMinSymbols(passwordPolicy.getMinSymbols());
3836                    passwordPolicyImpl.setMinUpperCase(passwordPolicy.getMinUpperCase());
3837                    passwordPolicyImpl.setRegex(passwordPolicy.getRegex());
3838                    passwordPolicyImpl.setHistory(passwordPolicy.isHistory());
3839                    passwordPolicyImpl.setHistoryCount(passwordPolicy.getHistoryCount());
3840                    passwordPolicyImpl.setExpireable(passwordPolicy.isExpireable());
3841                    passwordPolicyImpl.setMaxAge(passwordPolicy.getMaxAge());
3842                    passwordPolicyImpl.setWarningTime(passwordPolicy.getWarningTime());
3843                    passwordPolicyImpl.setGraceLimit(passwordPolicy.getGraceLimit());
3844                    passwordPolicyImpl.setLockout(passwordPolicy.isLockout());
3845                    passwordPolicyImpl.setMaxFailure(passwordPolicy.getMaxFailure());
3846                    passwordPolicyImpl.setLockoutDuration(passwordPolicy.getLockoutDuration());
3847                    passwordPolicyImpl.setRequireUnlock(passwordPolicy.isRequireUnlock());
3848                    passwordPolicyImpl.setResetFailureCount(passwordPolicy.getResetFailureCount());
3849                    passwordPolicyImpl.setResetTicketMaxAge(passwordPolicy.getResetTicketMaxAge());
3850    
3851                    return passwordPolicyImpl;
3852            }
3853    
3854            /**
3855             * Returns the password policy with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
3856             *
3857             * @param primaryKey the primary key of the password policy
3858             * @return the password policy
3859             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
3860             * @throws SystemException if a system exception occurred
3861             */
3862            @Override
3863            public PasswordPolicy findByPrimaryKey(Serializable primaryKey)
3864                    throws NoSuchPasswordPolicyException, SystemException {
3865                    PasswordPolicy passwordPolicy = fetchByPrimaryKey(primaryKey);
3866    
3867                    if (passwordPolicy == null) {
3868                            if (_log.isWarnEnabled()) {
3869                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3870                            }
3871    
3872                            throw new NoSuchPasswordPolicyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3873                                    primaryKey);
3874                    }
3875    
3876                    return passwordPolicy;
3877            }
3878    
3879            /**
3880             * Returns the password policy with the primary key or throws a {@link com.liferay.portal.NoSuchPasswordPolicyException} if it could not be found.
3881             *
3882             * @param passwordPolicyId the primary key of the password policy
3883             * @return the password policy
3884             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
3885             * @throws SystemException if a system exception occurred
3886             */
3887            @Override
3888            public PasswordPolicy findByPrimaryKey(long passwordPolicyId)
3889                    throws NoSuchPasswordPolicyException, SystemException {
3890                    return findByPrimaryKey((Serializable)passwordPolicyId);
3891            }
3892    
3893            /**
3894             * Returns the password policy with the primary key or returns <code>null</code> if it could not be found.
3895             *
3896             * @param primaryKey the primary key of the password policy
3897             * @return the password policy, or <code>null</code> if a password policy with the primary key could not be found
3898             * @throws SystemException if a system exception occurred
3899             */
3900            @Override
3901            public PasswordPolicy fetchByPrimaryKey(Serializable primaryKey)
3902                    throws SystemException {
3903                    PasswordPolicy passwordPolicy = (PasswordPolicy)EntityCacheUtil.getResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
3904                                    PasswordPolicyImpl.class, primaryKey);
3905    
3906                    if (passwordPolicy == _nullPasswordPolicy) {
3907                            return null;
3908                    }
3909    
3910                    if (passwordPolicy == null) {
3911                            Session session = null;
3912    
3913                            try {
3914                                    session = openSession();
3915    
3916                                    passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
3917                                                    primaryKey);
3918    
3919                                    if (passwordPolicy != null) {
3920                                            cacheResult(passwordPolicy);
3921                                    }
3922                                    else {
3923                                            EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
3924                                                    PasswordPolicyImpl.class, primaryKey,
3925                                                    _nullPasswordPolicy);
3926                                    }
3927                            }
3928                            catch (Exception e) {
3929                                    EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
3930                                            PasswordPolicyImpl.class, primaryKey);
3931    
3932                                    throw processException(e);
3933                            }
3934                            finally {
3935                                    closeSession(session);
3936                            }
3937                    }
3938    
3939                    return passwordPolicy;
3940            }
3941    
3942            /**
3943             * Returns the password policy with the primary key or returns <code>null</code> if it could not be found.
3944             *
3945             * @param passwordPolicyId the primary key of the password policy
3946             * @return the password policy, or <code>null</code> if a password policy with the primary key could not be found
3947             * @throws SystemException if a system exception occurred
3948             */
3949            @Override
3950            public PasswordPolicy fetchByPrimaryKey(long passwordPolicyId)
3951                    throws SystemException {
3952                    return fetchByPrimaryKey((Serializable)passwordPolicyId);
3953            }
3954    
3955            /**
3956             * Returns all the password policies.
3957             *
3958             * @return the password policies
3959             * @throws SystemException if a system exception occurred
3960             */
3961            @Override
3962            public List<PasswordPolicy> findAll() throws SystemException {
3963                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3964            }
3965    
3966            /**
3967             * Returns a range of all the password policies.
3968             *
3969             * <p>
3970             * 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.
3971             * </p>
3972             *
3973             * @param start the lower bound of the range of password policies
3974             * @param end the upper bound of the range of password policies (not inclusive)
3975             * @return the range of password policies
3976             * @throws SystemException if a system exception occurred
3977             */
3978            @Override
3979            public List<PasswordPolicy> findAll(int start, int end)
3980                    throws SystemException {
3981                    return findAll(start, end, null);
3982            }
3983    
3984            /**
3985             * Returns an ordered range of all the password policies.
3986             *
3987             * <p>
3988             * 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.
3989             * </p>
3990             *
3991             * @param start the lower bound of the range of password policies
3992             * @param end the upper bound of the range of password policies (not inclusive)
3993             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3994             * @return the ordered range of password policies
3995             * @throws SystemException if a system exception occurred
3996             */
3997            @Override
3998            public List<PasswordPolicy> findAll(int start, int end,
3999                    OrderByComparator orderByComparator) throws SystemException {
4000                    boolean pagination = true;
4001                    FinderPath finderPath = null;
4002                    Object[] finderArgs = null;
4003    
4004                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4005                                    (orderByComparator == null)) {
4006                            pagination = false;
4007                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4008                            finderArgs = FINDER_ARGS_EMPTY;
4009                    }
4010                    else {
4011                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4012                            finderArgs = new Object[] { start, end, orderByComparator };
4013                    }
4014    
4015                    List<PasswordPolicy> list = (List<PasswordPolicy>)FinderCacheUtil.getResult(finderPath,
4016                                    finderArgs, this);
4017    
4018                    if (list == null) {
4019                            StringBundler query = null;
4020                            String sql = null;
4021    
4022                            if (orderByComparator != null) {
4023                                    query = new StringBundler(2 +
4024                                                    (orderByComparator.getOrderByFields().length * 3));
4025    
4026                                    query.append(_SQL_SELECT_PASSWORDPOLICY);
4027    
4028                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4029                                            orderByComparator);
4030    
4031                                    sql = query.toString();
4032                            }
4033                            else {
4034                                    sql = _SQL_SELECT_PASSWORDPOLICY;
4035    
4036                                    if (pagination) {
4037                                            sql = sql.concat(PasswordPolicyModelImpl.ORDER_BY_JPQL);
4038                                    }
4039                            }
4040    
4041                            Session session = null;
4042    
4043                            try {
4044                                    session = openSession();
4045    
4046                                    Query q = session.createQuery(sql);
4047    
4048                                    if (!pagination) {
4049                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
4050                                                            getDialect(), start, end, false);
4051    
4052                                            Collections.sort(list);
4053    
4054                                            list = new UnmodifiableList<PasswordPolicy>(list);
4055                                    }
4056                                    else {
4057                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
4058                                                            getDialect(), start, end);
4059                                    }
4060    
4061                                    cacheResult(list);
4062    
4063                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4064                            }
4065                            catch (Exception e) {
4066                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4067    
4068                                    throw processException(e);
4069                            }
4070                            finally {
4071                                    closeSession(session);
4072                            }
4073                    }
4074    
4075                    return list;
4076            }
4077    
4078            /**
4079             * Removes all the password policies from the database.
4080             *
4081             * @throws SystemException if a system exception occurred
4082             */
4083            @Override
4084            public void removeAll() throws SystemException {
4085                    for (PasswordPolicy passwordPolicy : findAll()) {
4086                            remove(passwordPolicy);
4087                    }
4088            }
4089    
4090            /**
4091             * Returns the number of password policies.
4092             *
4093             * @return the number of password policies
4094             * @throws SystemException if a system exception occurred
4095             */
4096            @Override
4097            public int countAll() throws SystemException {
4098                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4099                                    FINDER_ARGS_EMPTY, this);
4100    
4101                    if (count == null) {
4102                            Session session = null;
4103    
4104                            try {
4105                                    session = openSession();
4106    
4107                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDPOLICY);
4108    
4109                                    count = (Long)q.uniqueResult();
4110    
4111                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4112                                            FINDER_ARGS_EMPTY, count);
4113                            }
4114                            catch (Exception e) {
4115                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
4116                                            FINDER_ARGS_EMPTY);
4117    
4118                                    throw processException(e);
4119                            }
4120                            finally {
4121                                    closeSession(session);
4122                            }
4123                    }
4124    
4125                    return count.intValue();
4126            }
4127    
4128            @Override
4129            protected Set<String> getBadColumnNames() {
4130                    return _badColumnNames;
4131            }
4132    
4133            /**
4134             * Initializes the password policy persistence.
4135             */
4136            public void afterPropertiesSet() {
4137                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4138                                            com.liferay.portal.util.PropsUtil.get(
4139                                                    "value.object.listener.com.liferay.portal.model.PasswordPolicy")));
4140    
4141                    if (listenerClassNames.length > 0) {
4142                            try {
4143                                    List<ModelListener<PasswordPolicy>> listenersList = new ArrayList<ModelListener<PasswordPolicy>>();
4144    
4145                                    for (String listenerClassName : listenerClassNames) {
4146                                            listenersList.add((ModelListener<PasswordPolicy>)InstanceFactory.newInstance(
4147                                                            getClassLoader(), listenerClassName));
4148                                    }
4149    
4150                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4151                            }
4152                            catch (Exception e) {
4153                                    _log.error(e);
4154                            }
4155                    }
4156            }
4157    
4158            public void destroy() {
4159                    EntityCacheUtil.removeCache(PasswordPolicyImpl.class.getName());
4160                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4161                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4162                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4163            }
4164    
4165            private static final String _SQL_SELECT_PASSWORDPOLICY = "SELECT passwordPolicy FROM PasswordPolicy passwordPolicy";
4166            private static final String _SQL_SELECT_PASSWORDPOLICY_WHERE = "SELECT passwordPolicy FROM PasswordPolicy passwordPolicy WHERE ";
4167            private static final String _SQL_COUNT_PASSWORDPOLICY = "SELECT COUNT(passwordPolicy) FROM PasswordPolicy passwordPolicy";
4168            private static final String _SQL_COUNT_PASSWORDPOLICY_WHERE = "SELECT COUNT(passwordPolicy) FROM PasswordPolicy passwordPolicy WHERE ";
4169            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "passwordPolicy.passwordPolicyId";
4170            private static final String _FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE = "SELECT DISTINCT {passwordPolicy.*} FROM PasswordPolicy passwordPolicy WHERE ";
4171            private static final String _FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1 =
4172                    "SELECT {PasswordPolicy.*} FROM (SELECT DISTINCT passwordPolicy.passwordPolicyId FROM PasswordPolicy passwordPolicy WHERE ";
4173            private static final String _FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2 =
4174                    ") TEMP_TABLE INNER JOIN PasswordPolicy ON TEMP_TABLE.passwordPolicyId = PasswordPolicy.passwordPolicyId";
4175            private static final String _FILTER_SQL_COUNT_PASSWORDPOLICY_WHERE = "SELECT COUNT(DISTINCT passwordPolicy.passwordPolicyId) AS COUNT_VALUE FROM PasswordPolicy passwordPolicy WHERE ";
4176            private static final String _FILTER_ENTITY_ALIAS = "passwordPolicy";
4177            private static final String _FILTER_ENTITY_TABLE = "PasswordPolicy";
4178            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordPolicy.";
4179            private static final String _ORDER_BY_ENTITY_TABLE = "PasswordPolicy.";
4180            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordPolicy exists with the primary key ";
4181            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordPolicy exists with the key {";
4182            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4183            private static Log _log = LogFactoryUtil.getLog(PasswordPolicyPersistenceImpl.class);
4184            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
4185                                    "uuid"
4186                            });
4187            private static PasswordPolicy _nullPasswordPolicy = new PasswordPolicyImpl() {
4188                            @Override
4189                            public Object clone() {
4190                                    return this;
4191                            }
4192    
4193                            @Override
4194                            public CacheModel<PasswordPolicy> toCacheModel() {
4195                                    return _nullPasswordPolicyCacheModel;
4196                            }
4197                    };
4198    
4199            private static CacheModel<PasswordPolicy> _nullPasswordPolicyCacheModel = new CacheModel<PasswordPolicy>() {
4200                            @Override
4201                            public PasswordPolicy toEntityModel() {
4202                                    return _nullPasswordPolicy;
4203                            }
4204                    };
4205    }