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