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