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