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