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