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