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