001    /**
002     * Copyright (c) 2000-2013 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;
016    
017    import com.liferay.portal.NoSuchPasswordPolicyException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.SQLQuery;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.SetUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.UnmodifiableList;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.ModelListener;
042    import com.liferay.portal.model.PasswordPolicy;
043    import com.liferay.portal.model.impl.PasswordPolicyImpl;
044    import com.liferay.portal.model.impl.PasswordPolicyModelImpl;
045    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
046    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047    
048    import java.io.Serializable;
049    
050    import java.util.ArrayList;
051    import java.util.Collections;
052    import java.util.List;
053    import java.util.Set;
054    
055    /**
056     * The persistence implementation for the password policy service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see PasswordPolicyPersistence
064     * @see PasswordPolicyUtil
065     * @generated
066     */
067    public class PasswordPolicyPersistenceImpl extends BasePersistenceImpl<PasswordPolicy>
068            implements PasswordPolicyPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * 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.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = PasswordPolicyImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
080                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
081                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
082                            "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
084                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
085                            PasswordPolicyImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
088                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
091                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
092                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
093                            "findByUuid",
094                            new String[] {
095                                    String.class.getName(),
096                                    
097                            Integer.class.getName(), Integer.class.getName(),
098                                    OrderByComparator.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
101                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
102                            PasswordPolicyImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
104                            new String[] { String.class.getName() },
105                            PasswordPolicyModelImpl.UUID_COLUMN_BITMASK);
106            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
107                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
109                            new String[] { String.class.getName() });
110    
111            /**
112             * Returns all the password policies where uuid = &#63;.
113             *
114             * @param uuid the uuid
115             * @return the matching password policies
116             * @throws SystemException if a system exception occurred
117             */
118            public List<PasswordPolicy> findByUuid(String uuid)
119                    throws SystemException {
120                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121            }
122    
123            /**
124             * Returns a range of all the password policies where uuid = &#63;.
125             *
126             * <p>
127             * 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.
128             * </p>
129             *
130             * @param uuid the uuid
131             * @param start the lower bound of the range of password policies
132             * @param end the upper bound of the range of password policies (not inclusive)
133             * @return the range of matching password policies
134             * @throws SystemException if a system exception occurred
135             */
136            public List<PasswordPolicy> findByUuid(String uuid, int start, int end)
137                    throws SystemException {
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             * @throws SystemException if a system exception occurred
154             */
155            public List<PasswordPolicy> findByUuid(String uuid, int start, int end,
156                    OrderByComparator orderByComparator) throws SystemException {
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 = new UnmodifiableList<PasswordPolicy>(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             * @throws SystemException if a system exception occurred
274             */
275            public PasswordPolicy findByUuid_First(String uuid,
276                    OrderByComparator orderByComparator)
277                    throws NoSuchPasswordPolicyException, SystemException {
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             * @throws SystemException if a system exception occurred
304             */
305            public PasswordPolicy fetchByUuid_First(String uuid,
306                    OrderByComparator orderByComparator) throws SystemException {
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             * @throws SystemException if a system exception occurred
324             */
325            public PasswordPolicy findByUuid_Last(String uuid,
326                    OrderByComparator orderByComparator)
327                    throws NoSuchPasswordPolicyException, SystemException {
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             * @throws SystemException if a system exception occurred
353             */
354            public PasswordPolicy fetchByUuid_Last(String uuid,
355                    OrderByComparator orderByComparator) throws SystemException {
356                    int count = countByUuid(uuid);
357    
358                    List<PasswordPolicy> list = findByUuid(uuid, count - 1, count,
359                                    orderByComparator);
360    
361                    if (!list.isEmpty()) {
362                            return list.get(0);
363                    }
364    
365                    return null;
366            }
367    
368            /**
369             * Returns the password policies before and after the current password policy in the ordered set where uuid = &#63;.
370             *
371             * @param passwordPolicyId the primary key of the current password policy
372             * @param uuid the uuid
373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
374             * @return the previous, current, and next password policy
375             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
376             * @throws SystemException if a system exception occurred
377             */
378            public PasswordPolicy[] findByUuid_PrevAndNext(long passwordPolicyId,
379                    String uuid, OrderByComparator orderByComparator)
380                    throws NoSuchPasswordPolicyException, SystemException {
381                    PasswordPolicy passwordPolicy = findByPrimaryKey(passwordPolicyId);
382    
383                    Session session = null;
384    
385                    try {
386                            session = openSession();
387    
388                            PasswordPolicy[] array = new PasswordPolicyImpl[3];
389    
390                            array[0] = getByUuid_PrevAndNext(session, passwordPolicy, uuid,
391                                            orderByComparator, true);
392    
393                            array[1] = passwordPolicy;
394    
395                            array[2] = getByUuid_PrevAndNext(session, passwordPolicy, uuid,
396                                            orderByComparator, false);
397    
398                            return array;
399                    }
400                    catch (Exception e) {
401                            throw processException(e);
402                    }
403                    finally {
404                            closeSession(session);
405                    }
406            }
407    
408            protected PasswordPolicy getByUuid_PrevAndNext(Session session,
409                    PasswordPolicy passwordPolicy, String uuid,
410                    OrderByComparator orderByComparator, boolean previous) {
411                    StringBundler query = null;
412    
413                    if (orderByComparator != null) {
414                            query = new StringBundler(6 +
415                                            (orderByComparator.getOrderByFields().length * 6));
416                    }
417                    else {
418                            query = new StringBundler(3);
419                    }
420    
421                    query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
422    
423                    boolean bindUuid = false;
424    
425                    if (uuid == null) {
426                            query.append(_FINDER_COLUMN_UUID_UUID_1);
427                    }
428                    else if (uuid.equals(StringPool.BLANK)) {
429                            query.append(_FINDER_COLUMN_UUID_UUID_3);
430                    }
431                    else {
432                            bindUuid = true;
433    
434                            query.append(_FINDER_COLUMN_UUID_UUID_2);
435                    }
436    
437                    if (orderByComparator != null) {
438                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
439    
440                            if (orderByConditionFields.length > 0) {
441                                    query.append(WHERE_AND);
442                            }
443    
444                            for (int i = 0; i < orderByConditionFields.length; i++) {
445                                    query.append(_ORDER_BY_ENTITY_ALIAS);
446                                    query.append(orderByConditionFields[i]);
447    
448                                    if ((i + 1) < orderByConditionFields.length) {
449                                            if (orderByComparator.isAscending() ^ previous) {
450                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
451                                            }
452                                            else {
453                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
454                                            }
455                                    }
456                                    else {
457                                            if (orderByComparator.isAscending() ^ previous) {
458                                                    query.append(WHERE_GREATER_THAN);
459                                            }
460                                            else {
461                                                    query.append(WHERE_LESSER_THAN);
462                                            }
463                                    }
464                            }
465    
466                            query.append(ORDER_BY_CLAUSE);
467    
468                            String[] orderByFields = orderByComparator.getOrderByFields();
469    
470                            for (int i = 0; i < orderByFields.length; i++) {
471                                    query.append(_ORDER_BY_ENTITY_ALIAS);
472                                    query.append(orderByFields[i]);
473    
474                                    if ((i + 1) < orderByFields.length) {
475                                            if (orderByComparator.isAscending() ^ previous) {
476                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
477                                            }
478                                            else {
479                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
480                                            }
481                                    }
482                                    else {
483                                            if (orderByComparator.isAscending() ^ previous) {
484                                                    query.append(ORDER_BY_ASC);
485                                            }
486                                            else {
487                                                    query.append(ORDER_BY_DESC);
488                                            }
489                                    }
490                            }
491                    }
492                    else {
493                            query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
494                    }
495    
496                    String sql = query.toString();
497    
498                    Query q = session.createQuery(sql);
499    
500                    q.setFirstResult(0);
501                    q.setMaxResults(2);
502    
503                    QueryPos qPos = QueryPos.getInstance(q);
504    
505                    if (bindUuid) {
506                            qPos.add(uuid);
507                    }
508    
509                    if (orderByComparator != null) {
510                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicy);
511    
512                            for (Object value : values) {
513                                    qPos.add(value);
514                            }
515                    }
516    
517                    List<PasswordPolicy> list = q.list();
518    
519                    if (list.size() == 2) {
520                            return list.get(1);
521                    }
522                    else {
523                            return null;
524                    }
525            }
526    
527            /**
528             * Returns all the password policies that the user has permission to view where uuid = &#63;.
529             *
530             * @param uuid the uuid
531             * @return the matching password policies that the user has permission to view
532             * @throws SystemException if a system exception occurred
533             */
534            public List<PasswordPolicy> filterFindByUuid(String uuid)
535                    throws SystemException {
536                    return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
537            }
538    
539            /**
540             * Returns a range of all the password policies that the user has permission to view where uuid = &#63;.
541             *
542             * <p>
543             * 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.
544             * </p>
545             *
546             * @param uuid the uuid
547             * @param start the lower bound of the range of password policies
548             * @param end the upper bound of the range of password policies (not inclusive)
549             * @return the range of matching password policies that the user has permission to view
550             * @throws SystemException if a system exception occurred
551             */
552            public List<PasswordPolicy> filterFindByUuid(String uuid, int start, int end)
553                    throws SystemException {
554                    return filterFindByUuid(uuid, start, end, null);
555            }
556    
557            /**
558             * Returns an ordered range of all the password policies that the user has permissions to view where uuid = &#63;.
559             *
560             * <p>
561             * 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.
562             * </p>
563             *
564             * @param uuid the uuid
565             * @param start the lower bound of the range of password policies
566             * @param end the upper bound of the range of password policies (not inclusive)
567             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
568             * @return the ordered range of matching password policies that the user has permission to view
569             * @throws SystemException if a system exception occurred
570             */
571            public List<PasswordPolicy> filterFindByUuid(String uuid, int start,
572                    int end, OrderByComparator orderByComparator) throws SystemException {
573                    if (!InlineSQLHelperUtil.isEnabled()) {
574                            return findByUuid(uuid, start, end, orderByComparator);
575                    }
576    
577                    StringBundler query = null;
578    
579                    if (orderByComparator != null) {
580                            query = new StringBundler(3 +
581                                            (orderByComparator.getOrderByFields().length * 3));
582                    }
583                    else {
584                            query = new StringBundler(3);
585                    }
586    
587                    if (getDB().isSupportsInlineDistinct()) {
588                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE);
589                    }
590                    else {
591                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1);
592                    }
593    
594                    boolean bindUuid = false;
595    
596                    if (uuid == null) {
597                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
598                    }
599                    else if (uuid.equals(StringPool.BLANK)) {
600                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
601                    }
602                    else {
603                            bindUuid = true;
604    
605                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
606                    }
607    
608                    if (!getDB().isSupportsInlineDistinct()) {
609                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2);
610                    }
611    
612                    if (orderByComparator != null) {
613                            if (getDB().isSupportsInlineDistinct()) {
614                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
615                                            orderByComparator, true);
616                            }
617                            else {
618                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
619                                            orderByComparator, true);
620                            }
621                    }
622                    else {
623                            if (getDB().isSupportsInlineDistinct()) {
624                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
625                            }
626                            else {
627                                    query.append(PasswordPolicyModelImpl.ORDER_BY_SQL);
628                            }
629                    }
630    
631                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
632                                    PasswordPolicy.class.getName(),
633                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
634    
635                    Session session = null;
636    
637                    try {
638                            session = openSession();
639    
640                            SQLQuery q = session.createSQLQuery(sql);
641    
642                            if (getDB().isSupportsInlineDistinct()) {
643                                    q.addEntity(_FILTER_ENTITY_ALIAS, PasswordPolicyImpl.class);
644                            }
645                            else {
646                                    q.addEntity(_FILTER_ENTITY_TABLE, PasswordPolicyImpl.class);
647                            }
648    
649                            QueryPos qPos = QueryPos.getInstance(q);
650    
651                            if (bindUuid) {
652                                    qPos.add(uuid);
653                            }
654    
655                            return (List<PasswordPolicy>)QueryUtil.list(q, getDialect(), start,
656                                    end);
657                    }
658                    catch (Exception e) {
659                            throw processException(e);
660                    }
661                    finally {
662                            closeSession(session);
663                    }
664            }
665    
666            /**
667             * 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;.
668             *
669             * @param passwordPolicyId the primary key of the current password policy
670             * @param uuid the uuid
671             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
672             * @return the previous, current, and next password policy
673             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
674             * @throws SystemException if a system exception occurred
675             */
676            public PasswordPolicy[] filterFindByUuid_PrevAndNext(
677                    long passwordPolicyId, String uuid, OrderByComparator orderByComparator)
678                    throws NoSuchPasswordPolicyException, SystemException {
679                    if (!InlineSQLHelperUtil.isEnabled()) {
680                            return findByUuid_PrevAndNext(passwordPolicyId, uuid,
681                                    orderByComparator);
682                    }
683    
684                    PasswordPolicy passwordPolicy = findByPrimaryKey(passwordPolicyId);
685    
686                    Session session = null;
687    
688                    try {
689                            session = openSession();
690    
691                            PasswordPolicy[] array = new PasswordPolicyImpl[3];
692    
693                            array[0] = filterGetByUuid_PrevAndNext(session, passwordPolicy,
694                                            uuid, orderByComparator, true);
695    
696                            array[1] = passwordPolicy;
697    
698                            array[2] = filterGetByUuid_PrevAndNext(session, passwordPolicy,
699                                            uuid, orderByComparator, false);
700    
701                            return array;
702                    }
703                    catch (Exception e) {
704                            throw processException(e);
705                    }
706                    finally {
707                            closeSession(session);
708                    }
709            }
710    
711            protected PasswordPolicy filterGetByUuid_PrevAndNext(Session session,
712                    PasswordPolicy passwordPolicy, String uuid,
713                    OrderByComparator orderByComparator, boolean previous) {
714                    StringBundler query = null;
715    
716                    if (orderByComparator != null) {
717                            query = new StringBundler(6 +
718                                            (orderByComparator.getOrderByFields().length * 6));
719                    }
720                    else {
721                            query = new StringBundler(3);
722                    }
723    
724                    if (getDB().isSupportsInlineDistinct()) {
725                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE);
726                    }
727                    else {
728                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1);
729                    }
730    
731                    boolean bindUuid = false;
732    
733                    if (uuid == null) {
734                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
735                    }
736                    else if (uuid.equals(StringPool.BLANK)) {
737                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
738                    }
739                    else {
740                            bindUuid = true;
741    
742                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
743                    }
744    
745                    if (!getDB().isSupportsInlineDistinct()) {
746                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2);
747                    }
748    
749                    if (orderByComparator != null) {
750                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
751    
752                            if (orderByConditionFields.length > 0) {
753                                    query.append(WHERE_AND);
754                            }
755    
756                            for (int i = 0; i < orderByConditionFields.length; i++) {
757                                    if (getDB().isSupportsInlineDistinct()) {
758                                            query.append(_ORDER_BY_ENTITY_ALIAS);
759                                    }
760                                    else {
761                                            query.append(_ORDER_BY_ENTITY_TABLE);
762                                    }
763    
764                                    query.append(orderByConditionFields[i]);
765    
766                                    if ((i + 1) < orderByConditionFields.length) {
767                                            if (orderByComparator.isAscending() ^ previous) {
768                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
769                                            }
770                                            else {
771                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
772                                            }
773                                    }
774                                    else {
775                                            if (orderByComparator.isAscending() ^ previous) {
776                                                    query.append(WHERE_GREATER_THAN);
777                                            }
778                                            else {
779                                                    query.append(WHERE_LESSER_THAN);
780                                            }
781                                    }
782                            }
783    
784                            query.append(ORDER_BY_CLAUSE);
785    
786                            String[] orderByFields = orderByComparator.getOrderByFields();
787    
788                            for (int i = 0; i < orderByFields.length; i++) {
789                                    if (getDB().isSupportsInlineDistinct()) {
790                                            query.append(_ORDER_BY_ENTITY_ALIAS);
791                                    }
792                                    else {
793                                            query.append(_ORDER_BY_ENTITY_TABLE);
794                                    }
795    
796                                    query.append(orderByFields[i]);
797    
798                                    if ((i + 1) < orderByFields.length) {
799                                            if (orderByComparator.isAscending() ^ previous) {
800                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
801                                            }
802                                            else {
803                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
804                                            }
805                                    }
806                                    else {
807                                            if (orderByComparator.isAscending() ^ previous) {
808                                                    query.append(ORDER_BY_ASC);
809                                            }
810                                            else {
811                                                    query.append(ORDER_BY_DESC);
812                                            }
813                                    }
814                            }
815                    }
816                    else {
817                            if (getDB().isSupportsInlineDistinct()) {
818                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
819                            }
820                            else {
821                                    query.append(PasswordPolicyModelImpl.ORDER_BY_SQL);
822                            }
823                    }
824    
825                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
826                                    PasswordPolicy.class.getName(),
827                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
828    
829                    SQLQuery q = session.createSQLQuery(sql);
830    
831                    q.setFirstResult(0);
832                    q.setMaxResults(2);
833    
834                    if (getDB().isSupportsInlineDistinct()) {
835                            q.addEntity(_FILTER_ENTITY_ALIAS, PasswordPolicyImpl.class);
836                    }
837                    else {
838                            q.addEntity(_FILTER_ENTITY_TABLE, PasswordPolicyImpl.class);
839                    }
840    
841                    QueryPos qPos = QueryPos.getInstance(q);
842    
843                    if (bindUuid) {
844                            qPos.add(uuid);
845                    }
846    
847                    if (orderByComparator != null) {
848                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicy);
849    
850                            for (Object value : values) {
851                                    qPos.add(value);
852                            }
853                    }
854    
855                    List<PasswordPolicy> list = q.list();
856    
857                    if (list.size() == 2) {
858                            return list.get(1);
859                    }
860                    else {
861                            return null;
862                    }
863            }
864    
865            /**
866             * Removes all the password policies where uuid = &#63; from the database.
867             *
868             * @param uuid the uuid
869             * @throws SystemException if a system exception occurred
870             */
871            public void removeByUuid(String uuid) throws SystemException {
872                    for (PasswordPolicy passwordPolicy : findByUuid(uuid,
873                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
874                            remove(passwordPolicy);
875                    }
876            }
877    
878            /**
879             * Returns the number of password policies where uuid = &#63;.
880             *
881             * @param uuid the uuid
882             * @return the number of matching password policies
883             * @throws SystemException if a system exception occurred
884             */
885            public int countByUuid(String uuid) throws SystemException {
886                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
887    
888                    Object[] finderArgs = new Object[] { uuid };
889    
890                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
891                                    this);
892    
893                    if (count == null) {
894                            StringBundler query = new StringBundler(2);
895    
896                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
897    
898                            boolean bindUuid = false;
899    
900                            if (uuid == null) {
901                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
902                            }
903                            else if (uuid.equals(StringPool.BLANK)) {
904                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
905                            }
906                            else {
907                                    bindUuid = true;
908    
909                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
910                            }
911    
912                            String sql = query.toString();
913    
914                            Session session = null;
915    
916                            try {
917                                    session = openSession();
918    
919                                    Query q = session.createQuery(sql);
920    
921                                    QueryPos qPos = QueryPos.getInstance(q);
922    
923                                    if (bindUuid) {
924                                            qPos.add(uuid);
925                                    }
926    
927                                    count = (Long)q.uniqueResult();
928    
929                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
930                            }
931                            catch (Exception e) {
932                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
933    
934                                    throw processException(e);
935                            }
936                            finally {
937                                    closeSession(session);
938                            }
939                    }
940    
941                    return count.intValue();
942            }
943    
944            /**
945             * Returns the number of password policies that the user has permission to view where uuid = &#63;.
946             *
947             * @param uuid the uuid
948             * @return the number of matching password policies that the user has permission to view
949             * @throws SystemException if a system exception occurred
950             */
951            public int filterCountByUuid(String uuid) throws SystemException {
952                    if (!InlineSQLHelperUtil.isEnabled()) {
953                            return countByUuid(uuid);
954                    }
955    
956                    StringBundler query = new StringBundler(2);
957    
958                    query.append(_FILTER_SQL_COUNT_PASSWORDPOLICY_WHERE);
959    
960                    boolean bindUuid = false;
961    
962                    if (uuid == null) {
963                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
964                    }
965                    else if (uuid.equals(StringPool.BLANK)) {
966                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
967                    }
968                    else {
969                            bindUuid = true;
970    
971                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
972                    }
973    
974                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
975                                    PasswordPolicy.class.getName(),
976                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
977    
978                    Session session = null;
979    
980                    try {
981                            session = openSession();
982    
983                            SQLQuery q = session.createSQLQuery(sql);
984    
985                            q.addScalar(COUNT_COLUMN_NAME,
986                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
987    
988                            QueryPos qPos = QueryPos.getInstance(q);
989    
990                            if (bindUuid) {
991                                    qPos.add(uuid);
992                            }
993    
994                            Long count = (Long)q.uniqueResult();
995    
996                            return count.intValue();
997                    }
998                    catch (Exception e) {
999                            throw processException(e);
1000                    }
1001                    finally {
1002                            closeSession(session);
1003                    }
1004            }
1005    
1006            private static final String _FINDER_COLUMN_UUID_UUID_1 = "passwordPolicy.uuid IS NULL";
1007            private static final String _FINDER_COLUMN_UUID_UUID_2 = "passwordPolicy.uuid = ?";
1008            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(passwordPolicy.uuid IS NULL OR passwordPolicy.uuid = '')";
1009            private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "passwordPolicy.uuid_ IS NULL";
1010            private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "passwordPolicy.uuid_ = ?";
1011            private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(passwordPolicy.uuid_ IS NULL OR passwordPolicy.uuid_ = '')";
1012            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
1013                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
1014                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1015                            "findByUuid_C",
1016                            new String[] {
1017                                    String.class.getName(), Long.class.getName(),
1018                                    
1019                            Integer.class.getName(), Integer.class.getName(),
1020                                    OrderByComparator.class.getName()
1021                            });
1022            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1023                    new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
1024                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
1025                            PasswordPolicyImpl.class,
1026                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1027                            new String[] { String.class.getName(), Long.class.getName() },
1028                            PasswordPolicyModelImpl.UUID_COLUMN_BITMASK |
1029                            PasswordPolicyModelImpl.COMPANYID_COLUMN_BITMASK);
1030            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
1031                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
1032                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1033                            new String[] { String.class.getName(), Long.class.getName() });
1034    
1035            /**
1036             * Returns all the password policies where uuid = &#63; and companyId = &#63;.
1037             *
1038             * @param uuid the uuid
1039             * @param companyId the company ID
1040             * @return the matching password policies
1041             * @throws SystemException if a system exception occurred
1042             */
1043            public List<PasswordPolicy> findByUuid_C(String uuid, long companyId)
1044                    throws SystemException {
1045                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1046                            QueryUtil.ALL_POS, null);
1047            }
1048    
1049            /**
1050             * Returns a range of all the password policies where uuid = &#63; and companyId = &#63;.
1051             *
1052             * <p>
1053             * 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.
1054             * </p>
1055             *
1056             * @param uuid the uuid
1057             * @param companyId the company ID
1058             * @param start the lower bound of the range of password policies
1059             * @param end the upper bound of the range of password policies (not inclusive)
1060             * @return the range of matching password policies
1061             * @throws SystemException if a system exception occurred
1062             */
1063            public List<PasswordPolicy> findByUuid_C(String uuid, long companyId,
1064                    int start, int end) throws SystemException {
1065                    return findByUuid_C(uuid, companyId, start, end, null);
1066            }
1067    
1068            /**
1069             * Returns an ordered range of all the password policies where uuid = &#63; and companyId = &#63;.
1070             *
1071             * <p>
1072             * 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.
1073             * </p>
1074             *
1075             * @param uuid the uuid
1076             * @param companyId the company ID
1077             * @param start the lower bound of the range of password policies
1078             * @param end the upper bound of the range of password policies (not inclusive)
1079             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1080             * @return the ordered range of matching password policies
1081             * @throws SystemException if a system exception occurred
1082             */
1083            public List<PasswordPolicy> findByUuid_C(String uuid, long companyId,
1084                    int start, int end, OrderByComparator orderByComparator)
1085                    throws SystemException {
1086                    boolean pagination = true;
1087                    FinderPath finderPath = null;
1088                    Object[] finderArgs = null;
1089    
1090                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1091                                    (orderByComparator == null)) {
1092                            pagination = false;
1093                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1094                            finderArgs = new Object[] { uuid, companyId };
1095                    }
1096                    else {
1097                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1098                            finderArgs = new Object[] {
1099                                            uuid, companyId,
1100                                            
1101                                            start, end, orderByComparator
1102                                    };
1103                    }
1104    
1105                    List<PasswordPolicy> list = (List<PasswordPolicy>)FinderCacheUtil.getResult(finderPath,
1106                                    finderArgs, this);
1107    
1108                    if ((list != null) && !list.isEmpty()) {
1109                            for (PasswordPolicy passwordPolicy : list) {
1110                                    if (!Validator.equals(uuid, passwordPolicy.getUuid()) ||
1111                                                    (companyId != passwordPolicy.getCompanyId())) {
1112                                            list = null;
1113    
1114                                            break;
1115                                    }
1116                            }
1117                    }
1118    
1119                    if (list == null) {
1120                            StringBundler query = null;
1121    
1122                            if (orderByComparator != null) {
1123                                    query = new StringBundler(4 +
1124                                                    (orderByComparator.getOrderByFields().length * 3));
1125                            }
1126                            else {
1127                                    query = new StringBundler(4);
1128                            }
1129    
1130                            query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
1131    
1132                            boolean bindUuid = false;
1133    
1134                            if (uuid == null) {
1135                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1136                            }
1137                            else if (uuid.equals(StringPool.BLANK)) {
1138                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1139                            }
1140                            else {
1141                                    bindUuid = true;
1142    
1143                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1144                            }
1145    
1146                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1147    
1148                            if (orderByComparator != null) {
1149                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1150                                            orderByComparator);
1151                            }
1152                            else
1153                             if (pagination) {
1154                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
1155                            }
1156    
1157                            String sql = query.toString();
1158    
1159                            Session session = null;
1160    
1161                            try {
1162                                    session = openSession();
1163    
1164                                    Query q = session.createQuery(sql);
1165    
1166                                    QueryPos qPos = QueryPos.getInstance(q);
1167    
1168                                    if (bindUuid) {
1169                                            qPos.add(uuid);
1170                                    }
1171    
1172                                    qPos.add(companyId);
1173    
1174                                    if (!pagination) {
1175                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
1176                                                            getDialect(), start, end, false);
1177    
1178                                            Collections.sort(list);
1179    
1180                                            list = new UnmodifiableList<PasswordPolicy>(list);
1181                                    }
1182                                    else {
1183                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
1184                                                            getDialect(), start, end);
1185                                    }
1186    
1187                                    cacheResult(list);
1188    
1189                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1190                            }
1191                            catch (Exception e) {
1192                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1193    
1194                                    throw processException(e);
1195                            }
1196                            finally {
1197                                    closeSession(session);
1198                            }
1199                    }
1200    
1201                    return list;
1202            }
1203    
1204            /**
1205             * Returns the first password policy in the ordered set where uuid = &#63; and companyId = &#63;.
1206             *
1207             * @param uuid the uuid
1208             * @param companyId the company ID
1209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1210             * @return the first matching password policy
1211             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
1212             * @throws SystemException if a system exception occurred
1213             */
1214            public PasswordPolicy findByUuid_C_First(String uuid, long companyId,
1215                    OrderByComparator orderByComparator)
1216                    throws NoSuchPasswordPolicyException, SystemException {
1217                    PasswordPolicy passwordPolicy = fetchByUuid_C_First(uuid, companyId,
1218                                    orderByComparator);
1219    
1220                    if (passwordPolicy != null) {
1221                            return passwordPolicy;
1222                    }
1223    
1224                    StringBundler msg = new StringBundler(6);
1225    
1226                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1227    
1228                    msg.append("uuid=");
1229                    msg.append(uuid);
1230    
1231                    msg.append(", companyId=");
1232                    msg.append(companyId);
1233    
1234                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1235    
1236                    throw new NoSuchPasswordPolicyException(msg.toString());
1237            }
1238    
1239            /**
1240             * Returns the first password policy in the ordered set where uuid = &#63; and companyId = &#63;.
1241             *
1242             * @param uuid the uuid
1243             * @param companyId the company ID
1244             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1245             * @return the first matching password policy, or <code>null</code> if a matching password policy could not be found
1246             * @throws SystemException if a system exception occurred
1247             */
1248            public PasswordPolicy fetchByUuid_C_First(String uuid, long companyId,
1249                    OrderByComparator orderByComparator) throws SystemException {
1250                    List<PasswordPolicy> list = findByUuid_C(uuid, companyId, 0, 1,
1251                                    orderByComparator);
1252    
1253                    if (!list.isEmpty()) {
1254                            return list.get(0);
1255                    }
1256    
1257                    return null;
1258            }
1259    
1260            /**
1261             * Returns the last password policy in the ordered set where uuid = &#63; and companyId = &#63;.
1262             *
1263             * @param uuid the uuid
1264             * @param companyId the company ID
1265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1266             * @return the last matching password policy
1267             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
1268             * @throws SystemException if a system exception occurred
1269             */
1270            public PasswordPolicy findByUuid_C_Last(String uuid, long companyId,
1271                    OrderByComparator orderByComparator)
1272                    throws NoSuchPasswordPolicyException, SystemException {
1273                    PasswordPolicy passwordPolicy = fetchByUuid_C_Last(uuid, companyId,
1274                                    orderByComparator);
1275    
1276                    if (passwordPolicy != null) {
1277                            return passwordPolicy;
1278                    }
1279    
1280                    StringBundler msg = new StringBundler(6);
1281    
1282                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1283    
1284                    msg.append("uuid=");
1285                    msg.append(uuid);
1286    
1287                    msg.append(", companyId=");
1288                    msg.append(companyId);
1289    
1290                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1291    
1292                    throw new NoSuchPasswordPolicyException(msg.toString());
1293            }
1294    
1295            /**
1296             * Returns the last password policy in the ordered set where uuid = &#63; and companyId = &#63;.
1297             *
1298             * @param uuid the uuid
1299             * @param companyId the company ID
1300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1301             * @return the last matching password policy, or <code>null</code> if a matching password policy could not be found
1302             * @throws SystemException if a system exception occurred
1303             */
1304            public PasswordPolicy fetchByUuid_C_Last(String uuid, long companyId,
1305                    OrderByComparator orderByComparator) throws SystemException {
1306                    int count = countByUuid_C(uuid, companyId);
1307    
1308                    List<PasswordPolicy> list = findByUuid_C(uuid, companyId, count - 1,
1309                                    count, orderByComparator);
1310    
1311                    if (!list.isEmpty()) {
1312                            return list.get(0);
1313                    }
1314    
1315                    return null;
1316            }
1317    
1318            /**
1319             * Returns the password policies before and after the current password policy in the ordered set where uuid = &#63; and companyId = &#63;.
1320             *
1321             * @param passwordPolicyId the primary key of the current password policy
1322             * @param uuid the uuid
1323             * @param companyId the company ID
1324             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1325             * @return the previous, current, and next password policy
1326             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
1327             * @throws SystemException if a system exception occurred
1328             */
1329            public PasswordPolicy[] findByUuid_C_PrevAndNext(long passwordPolicyId,
1330                    String uuid, long companyId, OrderByComparator orderByComparator)
1331                    throws NoSuchPasswordPolicyException, SystemException {
1332                    PasswordPolicy passwordPolicy = findByPrimaryKey(passwordPolicyId);
1333    
1334                    Session session = null;
1335    
1336                    try {
1337                            session = openSession();
1338    
1339                            PasswordPolicy[] array = new PasswordPolicyImpl[3];
1340    
1341                            array[0] = getByUuid_C_PrevAndNext(session, passwordPolicy, uuid,
1342                                            companyId, orderByComparator, true);
1343    
1344                            array[1] = passwordPolicy;
1345    
1346                            array[2] = getByUuid_C_PrevAndNext(session, passwordPolicy, uuid,
1347                                            companyId, orderByComparator, false);
1348    
1349                            return array;
1350                    }
1351                    catch (Exception e) {
1352                            throw processException(e);
1353                    }
1354                    finally {
1355                            closeSession(session);
1356                    }
1357            }
1358    
1359            protected PasswordPolicy getByUuid_C_PrevAndNext(Session session,
1360                    PasswordPolicy passwordPolicy, String uuid, long companyId,
1361                    OrderByComparator orderByComparator, boolean previous) {
1362                    StringBundler query = null;
1363    
1364                    if (orderByComparator != null) {
1365                            query = new StringBundler(6 +
1366                                            (orderByComparator.getOrderByFields().length * 6));
1367                    }
1368                    else {
1369                            query = new StringBundler(3);
1370                    }
1371    
1372                    query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
1373    
1374                    boolean bindUuid = false;
1375    
1376                    if (uuid == null) {
1377                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1378                    }
1379                    else if (uuid.equals(StringPool.BLANK)) {
1380                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1381                    }
1382                    else {
1383                            bindUuid = true;
1384    
1385                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1386                    }
1387    
1388                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1389    
1390                    if (orderByComparator != null) {
1391                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1392    
1393                            if (orderByConditionFields.length > 0) {
1394                                    query.append(WHERE_AND);
1395                            }
1396    
1397                            for (int i = 0; i < orderByConditionFields.length; i++) {
1398                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1399                                    query.append(orderByConditionFields[i]);
1400    
1401                                    if ((i + 1) < orderByConditionFields.length) {
1402                                            if (orderByComparator.isAscending() ^ previous) {
1403                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1404                                            }
1405                                            else {
1406                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1407                                            }
1408                                    }
1409                                    else {
1410                                            if (orderByComparator.isAscending() ^ previous) {
1411                                                    query.append(WHERE_GREATER_THAN);
1412                                            }
1413                                            else {
1414                                                    query.append(WHERE_LESSER_THAN);
1415                                            }
1416                                    }
1417                            }
1418    
1419                            query.append(ORDER_BY_CLAUSE);
1420    
1421                            String[] orderByFields = orderByComparator.getOrderByFields();
1422    
1423                            for (int i = 0; i < orderByFields.length; i++) {
1424                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1425                                    query.append(orderByFields[i]);
1426    
1427                                    if ((i + 1) < orderByFields.length) {
1428                                            if (orderByComparator.isAscending() ^ previous) {
1429                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1430                                            }
1431                                            else {
1432                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1433                                            }
1434                                    }
1435                                    else {
1436                                            if (orderByComparator.isAscending() ^ previous) {
1437                                                    query.append(ORDER_BY_ASC);
1438                                            }
1439                                            else {
1440                                                    query.append(ORDER_BY_DESC);
1441                                            }
1442                                    }
1443                            }
1444                    }
1445                    else {
1446                            query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
1447                    }
1448    
1449                    String sql = query.toString();
1450    
1451                    Query q = session.createQuery(sql);
1452    
1453                    q.setFirstResult(0);
1454                    q.setMaxResults(2);
1455    
1456                    QueryPos qPos = QueryPos.getInstance(q);
1457    
1458                    if (bindUuid) {
1459                            qPos.add(uuid);
1460                    }
1461    
1462                    qPos.add(companyId);
1463    
1464                    if (orderByComparator != null) {
1465                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicy);
1466    
1467                            for (Object value : values) {
1468                                    qPos.add(value);
1469                            }
1470                    }
1471    
1472                    List<PasswordPolicy> list = q.list();
1473    
1474                    if (list.size() == 2) {
1475                            return list.get(1);
1476                    }
1477                    else {
1478                            return null;
1479                    }
1480            }
1481    
1482            /**
1483             * Returns all the password policies that the user has permission to view where uuid = &#63; and companyId = &#63;.
1484             *
1485             * @param uuid the uuid
1486             * @param companyId the company ID
1487             * @return the matching password policies that the user has permission to view
1488             * @throws SystemException if a system exception occurred
1489             */
1490            public List<PasswordPolicy> filterFindByUuid_C(String uuid, long companyId)
1491                    throws SystemException {
1492                    return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1493                            QueryUtil.ALL_POS, null);
1494            }
1495    
1496            /**
1497             * Returns a range of all the password policies that the user has permission to view where uuid = &#63; and companyId = &#63;.
1498             *
1499             * <p>
1500             * 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.
1501             * </p>
1502             *
1503             * @param uuid the uuid
1504             * @param companyId the company ID
1505             * @param start the lower bound of the range of password policies
1506             * @param end the upper bound of the range of password policies (not inclusive)
1507             * @return the range of matching password policies that the user has permission to view
1508             * @throws SystemException if a system exception occurred
1509             */
1510            public List<PasswordPolicy> filterFindByUuid_C(String uuid, long companyId,
1511                    int start, int end) throws SystemException {
1512                    return filterFindByUuid_C(uuid, companyId, start, end, null);
1513            }
1514    
1515            /**
1516             * Returns an ordered range of all the password policies that the user has permissions to view where uuid = &#63; and companyId = &#63;.
1517             *
1518             * <p>
1519             * 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.
1520             * </p>
1521             *
1522             * @param uuid the uuid
1523             * @param companyId the company ID
1524             * @param start the lower bound of the range of password policies
1525             * @param end the upper bound of the range of password policies (not inclusive)
1526             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1527             * @return the ordered range of matching password policies that the user has permission to view
1528             * @throws SystemException if a system exception occurred
1529             */
1530            public List<PasswordPolicy> filterFindByUuid_C(String uuid, long companyId,
1531                    int start, int end, OrderByComparator orderByComparator)
1532                    throws SystemException {
1533                    if (!InlineSQLHelperUtil.isEnabled()) {
1534                            return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1535                    }
1536    
1537                    StringBundler query = null;
1538    
1539                    if (orderByComparator != null) {
1540                            query = new StringBundler(4 +
1541                                            (orderByComparator.getOrderByFields().length * 3));
1542                    }
1543                    else {
1544                            query = new StringBundler(4);
1545                    }
1546    
1547                    if (getDB().isSupportsInlineDistinct()) {
1548                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE);
1549                    }
1550                    else {
1551                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1);
1552                    }
1553    
1554                    boolean bindUuid = false;
1555    
1556                    if (uuid == null) {
1557                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1558                    }
1559                    else if (uuid.equals(StringPool.BLANK)) {
1560                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1561                    }
1562                    else {
1563                            bindUuid = true;
1564    
1565                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1566                    }
1567    
1568                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1569    
1570                    if (!getDB().isSupportsInlineDistinct()) {
1571                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2);
1572                    }
1573    
1574                    if (orderByComparator != null) {
1575                            if (getDB().isSupportsInlineDistinct()) {
1576                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1577                                            orderByComparator, true);
1578                            }
1579                            else {
1580                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1581                                            orderByComparator, true);
1582                            }
1583                    }
1584                    else {
1585                            if (getDB().isSupportsInlineDistinct()) {
1586                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
1587                            }
1588                            else {
1589                                    query.append(PasswordPolicyModelImpl.ORDER_BY_SQL);
1590                            }
1591                    }
1592    
1593                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1594                                    PasswordPolicy.class.getName(),
1595                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1596    
1597                    Session session = null;
1598    
1599                    try {
1600                            session = openSession();
1601    
1602                            SQLQuery q = session.createSQLQuery(sql);
1603    
1604                            if (getDB().isSupportsInlineDistinct()) {
1605                                    q.addEntity(_FILTER_ENTITY_ALIAS, PasswordPolicyImpl.class);
1606                            }
1607                            else {
1608                                    q.addEntity(_FILTER_ENTITY_TABLE, PasswordPolicyImpl.class);
1609                            }
1610    
1611                            QueryPos qPos = QueryPos.getInstance(q);
1612    
1613                            if (bindUuid) {
1614                                    qPos.add(uuid);
1615                            }
1616    
1617                            qPos.add(companyId);
1618    
1619                            return (List<PasswordPolicy>)QueryUtil.list(q, getDialect(), start,
1620                                    end);
1621                    }
1622                    catch (Exception e) {
1623                            throw processException(e);
1624                    }
1625                    finally {
1626                            closeSession(session);
1627                    }
1628            }
1629    
1630            /**
1631             * 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;.
1632             *
1633             * @param passwordPolicyId the primary key of the current password policy
1634             * @param uuid the uuid
1635             * @param companyId the company ID
1636             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1637             * @return the previous, current, and next password policy
1638             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
1639             * @throws SystemException if a system exception occurred
1640             */
1641            public PasswordPolicy[] filterFindByUuid_C_PrevAndNext(
1642                    long passwordPolicyId, String uuid, long companyId,
1643                    OrderByComparator orderByComparator)
1644                    throws NoSuchPasswordPolicyException, SystemException {
1645                    if (!InlineSQLHelperUtil.isEnabled()) {
1646                            return findByUuid_C_PrevAndNext(passwordPolicyId, uuid, companyId,
1647                                    orderByComparator);
1648                    }
1649    
1650                    PasswordPolicy passwordPolicy = findByPrimaryKey(passwordPolicyId);
1651    
1652                    Session session = null;
1653    
1654                    try {
1655                            session = openSession();
1656    
1657                            PasswordPolicy[] array = new PasswordPolicyImpl[3];
1658    
1659                            array[0] = filterGetByUuid_C_PrevAndNext(session, passwordPolicy,
1660                                            uuid, companyId, orderByComparator, true);
1661    
1662                            array[1] = passwordPolicy;
1663    
1664                            array[2] = filterGetByUuid_C_PrevAndNext(session, passwordPolicy,
1665                                            uuid, companyId, orderByComparator, false);
1666    
1667                            return array;
1668                    }
1669                    catch (Exception e) {
1670                            throw processException(e);
1671                    }
1672                    finally {
1673                            closeSession(session);
1674                    }
1675            }
1676    
1677            protected PasswordPolicy filterGetByUuid_C_PrevAndNext(Session session,
1678                    PasswordPolicy passwordPolicy, String uuid, long companyId,
1679                    OrderByComparator orderByComparator, boolean previous) {
1680                    StringBundler query = null;
1681    
1682                    if (orderByComparator != null) {
1683                            query = new StringBundler(6 +
1684                                            (orderByComparator.getOrderByFields().length * 6));
1685                    }
1686                    else {
1687                            query = new StringBundler(3);
1688                    }
1689    
1690                    if (getDB().isSupportsInlineDistinct()) {
1691                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE);
1692                    }
1693                    else {
1694                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1);
1695                    }
1696    
1697                    boolean bindUuid = false;
1698    
1699                    if (uuid == null) {
1700                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1701                    }
1702                    else if (uuid.equals(StringPool.BLANK)) {
1703                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1704                    }
1705                    else {
1706                            bindUuid = true;
1707    
1708                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1709                    }
1710    
1711                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1712    
1713                    if (!getDB().isSupportsInlineDistinct()) {
1714                            query.append(_FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2);
1715                    }
1716    
1717                    if (orderByComparator != null) {
1718                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1719    
1720                            if (orderByConditionFields.length > 0) {
1721                                    query.append(WHERE_AND);
1722                            }
1723    
1724                            for (int i = 0; i < orderByConditionFields.length; i++) {
1725                                    if (getDB().isSupportsInlineDistinct()) {
1726                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1727                                    }
1728                                    else {
1729                                            query.append(_ORDER_BY_ENTITY_TABLE);
1730                                    }
1731    
1732                                    query.append(orderByConditionFields[i]);
1733    
1734                                    if ((i + 1) < orderByConditionFields.length) {
1735                                            if (orderByComparator.isAscending() ^ previous) {
1736                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1737                                            }
1738                                            else {
1739                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1740                                            }
1741                                    }
1742                                    else {
1743                                            if (orderByComparator.isAscending() ^ previous) {
1744                                                    query.append(WHERE_GREATER_THAN);
1745                                            }
1746                                            else {
1747                                                    query.append(WHERE_LESSER_THAN);
1748                                            }
1749                                    }
1750                            }
1751    
1752                            query.append(ORDER_BY_CLAUSE);
1753    
1754                            String[] orderByFields = orderByComparator.getOrderByFields();
1755    
1756                            for (int i = 0; i < orderByFields.length; i++) {
1757                                    if (getDB().isSupportsInlineDistinct()) {
1758                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1759                                    }
1760                                    else {
1761                                            query.append(_ORDER_BY_ENTITY_TABLE);
1762                                    }
1763    
1764                                    query.append(orderByFields[i]);
1765    
1766                                    if ((i + 1) < orderByFields.length) {
1767                                            if (orderByComparator.isAscending() ^ previous) {
1768                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1769                                            }
1770                                            else {
1771                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1772                                            }
1773                                    }
1774                                    else {
1775                                            if (orderByComparator.isAscending() ^ previous) {
1776                                                    query.append(ORDER_BY_ASC);
1777                                            }
1778                                            else {
1779                                                    query.append(ORDER_BY_DESC);
1780                                            }
1781                                    }
1782                            }
1783                    }
1784                    else {
1785                            if (getDB().isSupportsInlineDistinct()) {
1786                                    query.append(PasswordPolicyModelImpl.ORDER_BY_JPQL);
1787                            }
1788                            else {
1789                                    query.append(PasswordPolicyModelImpl.ORDER_BY_SQL);
1790                            }
1791                    }
1792    
1793                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1794                                    PasswordPolicy.class.getName(),
1795                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1796    
1797                    SQLQuery q = session.createSQLQuery(sql);
1798    
1799                    q.setFirstResult(0);
1800                    q.setMaxResults(2);
1801    
1802                    if (getDB().isSupportsInlineDistinct()) {
1803                            q.addEntity(_FILTER_ENTITY_ALIAS, PasswordPolicyImpl.class);
1804                    }
1805                    else {
1806                            q.addEntity(_FILTER_ENTITY_TABLE, PasswordPolicyImpl.class);
1807                    }
1808    
1809                    QueryPos qPos = QueryPos.getInstance(q);
1810    
1811                    if (bindUuid) {
1812                            qPos.add(uuid);
1813                    }
1814    
1815                    qPos.add(companyId);
1816    
1817                    if (orderByComparator != null) {
1818                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicy);
1819    
1820                            for (Object value : values) {
1821                                    qPos.add(value);
1822                            }
1823                    }
1824    
1825                    List<PasswordPolicy> list = q.list();
1826    
1827                    if (list.size() == 2) {
1828                            return list.get(1);
1829                    }
1830                    else {
1831                            return null;
1832                    }
1833            }
1834    
1835            /**
1836             * Removes all the password policies where uuid = &#63; and companyId = &#63; from the database.
1837             *
1838             * @param uuid the uuid
1839             * @param companyId the company ID
1840             * @throws SystemException if a system exception occurred
1841             */
1842            public void removeByUuid_C(String uuid, long companyId)
1843                    throws SystemException {
1844                    for (PasswordPolicy passwordPolicy : findByUuid_C(uuid, companyId,
1845                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1846                            remove(passwordPolicy);
1847                    }
1848            }
1849    
1850            /**
1851             * Returns the number of password policies where uuid = &#63; and companyId = &#63;.
1852             *
1853             * @param uuid the uuid
1854             * @param companyId the company ID
1855             * @return the number of matching password policies
1856             * @throws SystemException if a system exception occurred
1857             */
1858            public int countByUuid_C(String uuid, long companyId)
1859                    throws SystemException {
1860                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1861    
1862                    Object[] finderArgs = new Object[] { uuid, companyId };
1863    
1864                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1865                                    this);
1866    
1867                    if (count == null) {
1868                            StringBundler query = new StringBundler(3);
1869    
1870                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
1871    
1872                            boolean bindUuid = false;
1873    
1874                            if (uuid == null) {
1875                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1876                            }
1877                            else if (uuid.equals(StringPool.BLANK)) {
1878                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1879                            }
1880                            else {
1881                                    bindUuid = true;
1882    
1883                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1884                            }
1885    
1886                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1887    
1888                            String sql = query.toString();
1889    
1890                            Session session = null;
1891    
1892                            try {
1893                                    session = openSession();
1894    
1895                                    Query q = session.createQuery(sql);
1896    
1897                                    QueryPos qPos = QueryPos.getInstance(q);
1898    
1899                                    if (bindUuid) {
1900                                            qPos.add(uuid);
1901                                    }
1902    
1903                                    qPos.add(companyId);
1904    
1905                                    count = (Long)q.uniqueResult();
1906    
1907                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1908                            }
1909                            catch (Exception e) {
1910                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1911    
1912                                    throw processException(e);
1913                            }
1914                            finally {
1915                                    closeSession(session);
1916                            }
1917                    }
1918    
1919                    return count.intValue();
1920            }
1921    
1922            /**
1923             * Returns the number of password policies that the user has permission to view where uuid = &#63; and companyId = &#63;.
1924             *
1925             * @param uuid the uuid
1926             * @param companyId the company ID
1927             * @return the number of matching password policies that the user has permission to view
1928             * @throws SystemException if a system exception occurred
1929             */
1930            public int filterCountByUuid_C(String uuid, long companyId)
1931                    throws SystemException {
1932                    if (!InlineSQLHelperUtil.isEnabled()) {
1933                            return countByUuid_C(uuid, companyId);
1934                    }
1935    
1936                    StringBundler query = new StringBundler(3);
1937    
1938                    query.append(_FILTER_SQL_COUNT_PASSWORDPOLICY_WHERE);
1939    
1940                    boolean bindUuid = false;
1941    
1942                    if (uuid == null) {
1943                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1944                    }
1945                    else if (uuid.equals(StringPool.BLANK)) {
1946                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1947                    }
1948                    else {
1949                            bindUuid = true;
1950    
1951                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1952                    }
1953    
1954                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1955    
1956                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1957                                    PasswordPolicy.class.getName(),
1958                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1959    
1960                    Session session = null;
1961    
1962                    try {
1963                            session = openSession();
1964    
1965                            SQLQuery q = session.createSQLQuery(sql);
1966    
1967                            q.addScalar(COUNT_COLUMN_NAME,
1968                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1969    
1970                            QueryPos qPos = QueryPos.getInstance(q);
1971    
1972                            if (bindUuid) {
1973                                    qPos.add(uuid);
1974                            }
1975    
1976                            qPos.add(companyId);
1977    
1978                            Long count = (Long)q.uniqueResult();
1979    
1980                            return count.intValue();
1981                    }
1982                    catch (Exception e) {
1983                            throw processException(e);
1984                    }
1985                    finally {
1986                            closeSession(session);
1987                    }
1988            }
1989    
1990            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "passwordPolicy.uuid IS NULL AND ";
1991            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "passwordPolicy.uuid = ? AND ";
1992            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(passwordPolicy.uuid IS NULL OR passwordPolicy.uuid = '') AND ";
1993            private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "passwordPolicy.uuid_ IS NULL AND ";
1994            private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "passwordPolicy.uuid_ = ? AND ";
1995            private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(passwordPolicy.uuid_ IS NULL OR passwordPolicy.uuid_ = '') AND ";
1996            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "passwordPolicy.companyId = ?";
1997            public static final FinderPath FINDER_PATH_FETCH_BY_C_DP = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
1998                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
1999                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_DP",
2000                            new String[] { Long.class.getName(), Boolean.class.getName() },
2001                            PasswordPolicyModelImpl.COMPANYID_COLUMN_BITMASK |
2002                            PasswordPolicyModelImpl.DEFAULTPOLICY_COLUMN_BITMASK);
2003            public static final FinderPath FINDER_PATH_COUNT_BY_C_DP = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2004                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
2005                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_DP",
2006                            new String[] { Long.class.getName(), Boolean.class.getName() });
2007    
2008            /**
2009             * Returns the password policy where companyId = &#63; and defaultPolicy = &#63; or throws a {@link com.liferay.portal.NoSuchPasswordPolicyException} if it could not be found.
2010             *
2011             * @param companyId the company ID
2012             * @param defaultPolicy the default policy
2013             * @return the matching password policy
2014             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
2015             * @throws SystemException if a system exception occurred
2016             */
2017            public PasswordPolicy findByC_DP(long companyId, boolean defaultPolicy)
2018                    throws NoSuchPasswordPolicyException, SystemException {
2019                    PasswordPolicy passwordPolicy = fetchByC_DP(companyId, defaultPolicy);
2020    
2021                    if (passwordPolicy == null) {
2022                            StringBundler msg = new StringBundler(6);
2023    
2024                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2025    
2026                            msg.append("companyId=");
2027                            msg.append(companyId);
2028    
2029                            msg.append(", defaultPolicy=");
2030                            msg.append(defaultPolicy);
2031    
2032                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2033    
2034                            if (_log.isWarnEnabled()) {
2035                                    _log.warn(msg.toString());
2036                            }
2037    
2038                            throw new NoSuchPasswordPolicyException(msg.toString());
2039                    }
2040    
2041                    return passwordPolicy;
2042            }
2043    
2044            /**
2045             * 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.
2046             *
2047             * @param companyId the company ID
2048             * @param defaultPolicy the default policy
2049             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
2050             * @throws SystemException if a system exception occurred
2051             */
2052            public PasswordPolicy fetchByC_DP(long companyId, boolean defaultPolicy)
2053                    throws SystemException {
2054                    return fetchByC_DP(companyId, defaultPolicy, true);
2055            }
2056    
2057            /**
2058             * 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.
2059             *
2060             * @param companyId the company ID
2061             * @param defaultPolicy the default policy
2062             * @param retrieveFromCache whether to use the finder cache
2063             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
2064             * @throws SystemException if a system exception occurred
2065             */
2066            public PasswordPolicy fetchByC_DP(long companyId, boolean defaultPolicy,
2067                    boolean retrieveFromCache) throws SystemException {
2068                    Object[] finderArgs = new Object[] { companyId, defaultPolicy };
2069    
2070                    Object result = null;
2071    
2072                    if (retrieveFromCache) {
2073                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_DP,
2074                                            finderArgs, this);
2075                    }
2076    
2077                    if (result instanceof PasswordPolicy) {
2078                            PasswordPolicy passwordPolicy = (PasswordPolicy)result;
2079    
2080                            if ((companyId != passwordPolicy.getCompanyId()) ||
2081                                            (defaultPolicy != passwordPolicy.getDefaultPolicy())) {
2082                                    result = null;
2083                            }
2084                    }
2085    
2086                    if (result == null) {
2087                            StringBundler query = new StringBundler(4);
2088    
2089                            query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
2090    
2091                            query.append(_FINDER_COLUMN_C_DP_COMPANYID_2);
2092    
2093                            query.append(_FINDER_COLUMN_C_DP_DEFAULTPOLICY_2);
2094    
2095                            String sql = query.toString();
2096    
2097                            Session session = null;
2098    
2099                            try {
2100                                    session = openSession();
2101    
2102                                    Query q = session.createQuery(sql);
2103    
2104                                    QueryPos qPos = QueryPos.getInstance(q);
2105    
2106                                    qPos.add(companyId);
2107    
2108                                    qPos.add(defaultPolicy);
2109    
2110                                    List<PasswordPolicy> list = q.list();
2111    
2112                                    if (list.isEmpty()) {
2113                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
2114                                                    finderArgs, list);
2115                                    }
2116                                    else {
2117                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2118                                                    _log.warn(
2119                                                            "PasswordPolicyPersistenceImpl.fetchByC_DP(long, boolean, boolean) with parameters (" +
2120                                                            StringUtil.merge(finderArgs) +
2121                                                            ") 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.");
2122                                            }
2123    
2124                                            PasswordPolicy passwordPolicy = list.get(0);
2125    
2126                                            result = passwordPolicy;
2127    
2128                                            cacheResult(passwordPolicy);
2129    
2130                                            if ((passwordPolicy.getCompanyId() != companyId) ||
2131                                                            (passwordPolicy.getDefaultPolicy() != defaultPolicy)) {
2132                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
2133                                                            finderArgs, passwordPolicy);
2134                                            }
2135                                    }
2136                            }
2137                            catch (Exception e) {
2138                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP,
2139                                            finderArgs);
2140    
2141                                    throw processException(e);
2142                            }
2143                            finally {
2144                                    closeSession(session);
2145                            }
2146                    }
2147    
2148                    if (result instanceof List<?>) {
2149                            return null;
2150                    }
2151                    else {
2152                            return (PasswordPolicy)result;
2153                    }
2154            }
2155    
2156            /**
2157             * Removes the password policy where companyId = &#63; and defaultPolicy = &#63; from the database.
2158             *
2159             * @param companyId the company ID
2160             * @param defaultPolicy the default policy
2161             * @return the password policy that was removed
2162             * @throws SystemException if a system exception occurred
2163             */
2164            public PasswordPolicy removeByC_DP(long companyId, boolean defaultPolicy)
2165                    throws NoSuchPasswordPolicyException, SystemException {
2166                    PasswordPolicy passwordPolicy = findByC_DP(companyId, defaultPolicy);
2167    
2168                    return remove(passwordPolicy);
2169            }
2170    
2171            /**
2172             * Returns the number of password policies where companyId = &#63; and defaultPolicy = &#63;.
2173             *
2174             * @param companyId the company ID
2175             * @param defaultPolicy the default policy
2176             * @return the number of matching password policies
2177             * @throws SystemException if a system exception occurred
2178             */
2179            public int countByC_DP(long companyId, boolean defaultPolicy)
2180                    throws SystemException {
2181                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_DP;
2182    
2183                    Object[] finderArgs = new Object[] { companyId, defaultPolicy };
2184    
2185                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2186                                    this);
2187    
2188                    if (count == null) {
2189                            StringBundler query = new StringBundler(3);
2190    
2191                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
2192    
2193                            query.append(_FINDER_COLUMN_C_DP_COMPANYID_2);
2194    
2195                            query.append(_FINDER_COLUMN_C_DP_DEFAULTPOLICY_2);
2196    
2197                            String sql = query.toString();
2198    
2199                            Session session = null;
2200    
2201                            try {
2202                                    session = openSession();
2203    
2204                                    Query q = session.createQuery(sql);
2205    
2206                                    QueryPos qPos = QueryPos.getInstance(q);
2207    
2208                                    qPos.add(companyId);
2209    
2210                                    qPos.add(defaultPolicy);
2211    
2212                                    count = (Long)q.uniqueResult();
2213    
2214                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2215                            }
2216                            catch (Exception e) {
2217                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2218    
2219                                    throw processException(e);
2220                            }
2221                            finally {
2222                                    closeSession(session);
2223                            }
2224                    }
2225    
2226                    return count.intValue();
2227            }
2228    
2229            private static final String _FINDER_COLUMN_C_DP_COMPANYID_2 = "passwordPolicy.companyId = ? AND ";
2230            private static final String _FINDER_COLUMN_C_DP_DEFAULTPOLICY_2 = "passwordPolicy.defaultPolicy = ?";
2231            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2232                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED,
2233                            PasswordPolicyImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
2234                            new String[] { Long.class.getName(), String.class.getName() },
2235                            PasswordPolicyModelImpl.COMPANYID_COLUMN_BITMASK |
2236                            PasswordPolicyModelImpl.NAME_COLUMN_BITMASK);
2237            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2238                            PasswordPolicyModelImpl.FINDER_CACHE_ENABLED, Long.class,
2239                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
2240                            new String[] { Long.class.getName(), String.class.getName() });
2241    
2242            /**
2243             * Returns the password policy where companyId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchPasswordPolicyException} if it could not be found.
2244             *
2245             * @param companyId the company ID
2246             * @param name the name
2247             * @return the matching password policy
2248             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a matching password policy could not be found
2249             * @throws SystemException if a system exception occurred
2250             */
2251            public PasswordPolicy findByC_N(long companyId, String name)
2252                    throws NoSuchPasswordPolicyException, SystemException {
2253                    PasswordPolicy passwordPolicy = fetchByC_N(companyId, name);
2254    
2255                    if (passwordPolicy == null) {
2256                            StringBundler msg = new StringBundler(6);
2257    
2258                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2259    
2260                            msg.append("companyId=");
2261                            msg.append(companyId);
2262    
2263                            msg.append(", name=");
2264                            msg.append(name);
2265    
2266                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2267    
2268                            if (_log.isWarnEnabled()) {
2269                                    _log.warn(msg.toString());
2270                            }
2271    
2272                            throw new NoSuchPasswordPolicyException(msg.toString());
2273                    }
2274    
2275                    return passwordPolicy;
2276            }
2277    
2278            /**
2279             * 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.
2280             *
2281             * @param companyId the company ID
2282             * @param name the name
2283             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
2284             * @throws SystemException if a system exception occurred
2285             */
2286            public PasswordPolicy fetchByC_N(long companyId, String name)
2287                    throws SystemException {
2288                    return fetchByC_N(companyId, name, true);
2289            }
2290    
2291            /**
2292             * 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.
2293             *
2294             * @param companyId the company ID
2295             * @param name the name
2296             * @param retrieveFromCache whether to use the finder cache
2297             * @return the matching password policy, or <code>null</code> if a matching password policy could not be found
2298             * @throws SystemException if a system exception occurred
2299             */
2300            public PasswordPolicy fetchByC_N(long companyId, String name,
2301                    boolean retrieveFromCache) throws SystemException {
2302                    Object[] finderArgs = new Object[] { companyId, name };
2303    
2304                    Object result = null;
2305    
2306                    if (retrieveFromCache) {
2307                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
2308                                            finderArgs, this);
2309                    }
2310    
2311                    if (result instanceof PasswordPolicy) {
2312                            PasswordPolicy passwordPolicy = (PasswordPolicy)result;
2313    
2314                            if ((companyId != passwordPolicy.getCompanyId()) ||
2315                                            !Validator.equals(name, passwordPolicy.getName())) {
2316                                    result = null;
2317                            }
2318                    }
2319    
2320                    if (result == null) {
2321                            StringBundler query = new StringBundler(4);
2322    
2323                            query.append(_SQL_SELECT_PASSWORDPOLICY_WHERE);
2324    
2325                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2326    
2327                            boolean bindName = false;
2328    
2329                            if (name == null) {
2330                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
2331                            }
2332                            else if (name.equals(StringPool.BLANK)) {
2333                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
2334                            }
2335                            else {
2336                                    bindName = true;
2337    
2338                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
2339                            }
2340    
2341                            String sql = query.toString();
2342    
2343                            Session session = null;
2344    
2345                            try {
2346                                    session = openSession();
2347    
2348                                    Query q = session.createQuery(sql);
2349    
2350                                    QueryPos qPos = QueryPos.getInstance(q);
2351    
2352                                    qPos.add(companyId);
2353    
2354                                    if (bindName) {
2355                                            qPos.add(name);
2356                                    }
2357    
2358                                    List<PasswordPolicy> list = q.list();
2359    
2360                                    if (list.isEmpty()) {
2361                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2362                                                    finderArgs, list);
2363                                    }
2364                                    else {
2365                                            PasswordPolicy passwordPolicy = list.get(0);
2366    
2367                                            result = passwordPolicy;
2368    
2369                                            cacheResult(passwordPolicy);
2370    
2371                                            if ((passwordPolicy.getCompanyId() != companyId) ||
2372                                                            (passwordPolicy.getName() == null) ||
2373                                                            !passwordPolicy.getName().equals(name)) {
2374                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2375                                                            finderArgs, passwordPolicy);
2376                                            }
2377                                    }
2378                            }
2379                            catch (Exception e) {
2380                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
2381                                            finderArgs);
2382    
2383                                    throw processException(e);
2384                            }
2385                            finally {
2386                                    closeSession(session);
2387                            }
2388                    }
2389    
2390                    if (result instanceof List<?>) {
2391                            return null;
2392                    }
2393                    else {
2394                            return (PasswordPolicy)result;
2395                    }
2396            }
2397    
2398            /**
2399             * Removes the password policy where companyId = &#63; and name = &#63; from the database.
2400             *
2401             * @param companyId the company ID
2402             * @param name the name
2403             * @return the password policy that was removed
2404             * @throws SystemException if a system exception occurred
2405             */
2406            public PasswordPolicy removeByC_N(long companyId, String name)
2407                    throws NoSuchPasswordPolicyException, SystemException {
2408                    PasswordPolicy passwordPolicy = findByC_N(companyId, name);
2409    
2410                    return remove(passwordPolicy);
2411            }
2412    
2413            /**
2414             * Returns the number of password policies where companyId = &#63; and name = &#63;.
2415             *
2416             * @param companyId the company ID
2417             * @param name the name
2418             * @return the number of matching password policies
2419             * @throws SystemException if a system exception occurred
2420             */
2421            public int countByC_N(long companyId, String name)
2422                    throws SystemException {
2423                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
2424    
2425                    Object[] finderArgs = new Object[] { companyId, name };
2426    
2427                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2428                                    this);
2429    
2430                    if (count == null) {
2431                            StringBundler query = new StringBundler(3);
2432    
2433                            query.append(_SQL_COUNT_PASSWORDPOLICY_WHERE);
2434    
2435                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2436    
2437                            boolean bindName = false;
2438    
2439                            if (name == null) {
2440                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
2441                            }
2442                            else if (name.equals(StringPool.BLANK)) {
2443                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
2444                            }
2445                            else {
2446                                    bindName = true;
2447    
2448                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
2449                            }
2450    
2451                            String sql = query.toString();
2452    
2453                            Session session = null;
2454    
2455                            try {
2456                                    session = openSession();
2457    
2458                                    Query q = session.createQuery(sql);
2459    
2460                                    QueryPos qPos = QueryPos.getInstance(q);
2461    
2462                                    qPos.add(companyId);
2463    
2464                                    if (bindName) {
2465                                            qPos.add(name);
2466                                    }
2467    
2468                                    count = (Long)q.uniqueResult();
2469    
2470                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2471                            }
2472                            catch (Exception e) {
2473                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2474    
2475                                    throw processException(e);
2476                            }
2477                            finally {
2478                                    closeSession(session);
2479                            }
2480                    }
2481    
2482                    return count.intValue();
2483            }
2484    
2485            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "passwordPolicy.companyId = ? AND ";
2486            private static final String _FINDER_COLUMN_C_N_NAME_1 = "passwordPolicy.name IS NULL";
2487            private static final String _FINDER_COLUMN_C_N_NAME_2 = "passwordPolicy.name = ?";
2488            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(passwordPolicy.name IS NULL OR passwordPolicy.name = '')";
2489    
2490            /**
2491             * Caches the password policy in the entity cache if it is enabled.
2492             *
2493             * @param passwordPolicy the password policy
2494             */
2495            public void cacheResult(PasswordPolicy passwordPolicy) {
2496                    EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2497                            PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey(),
2498                            passwordPolicy);
2499    
2500                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP,
2501                            new Object[] {
2502                                    passwordPolicy.getCompanyId(), passwordPolicy.getDefaultPolicy()
2503                            }, passwordPolicy);
2504    
2505                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2506                            new Object[] { passwordPolicy.getCompanyId(), passwordPolicy.getName() },
2507                            passwordPolicy);
2508    
2509                    passwordPolicy.resetOriginalValues();
2510            }
2511    
2512            /**
2513             * Caches the password policies in the entity cache if it is enabled.
2514             *
2515             * @param passwordPolicies the password policies
2516             */
2517            public void cacheResult(List<PasswordPolicy> passwordPolicies) {
2518                    for (PasswordPolicy passwordPolicy : passwordPolicies) {
2519                            if (EntityCacheUtil.getResult(
2520                                                    PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2521                                                    PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey()) == null) {
2522                                    cacheResult(passwordPolicy);
2523                            }
2524                            else {
2525                                    passwordPolicy.resetOriginalValues();
2526                            }
2527                    }
2528            }
2529    
2530            /**
2531             * Clears the cache for all password policies.
2532             *
2533             * <p>
2534             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2535             * </p>
2536             */
2537            @Override
2538            public void clearCache() {
2539                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2540                            CacheRegistryUtil.clear(PasswordPolicyImpl.class.getName());
2541                    }
2542    
2543                    EntityCacheUtil.clearCache(PasswordPolicyImpl.class.getName());
2544    
2545                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2546                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2547                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2548            }
2549    
2550            /**
2551             * Clears the cache for the password policy.
2552             *
2553             * <p>
2554             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2555             * </p>
2556             */
2557            @Override
2558            public void clearCache(PasswordPolicy passwordPolicy) {
2559                    EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2560                            PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey());
2561    
2562                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2563                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2564    
2565                    clearUniqueFindersCache(passwordPolicy);
2566            }
2567    
2568            @Override
2569            public void clearCache(List<PasswordPolicy> passwordPolicies) {
2570                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2571                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2572    
2573                    for (PasswordPolicy passwordPolicy : passwordPolicies) {
2574                            EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2575                                    PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey());
2576    
2577                            clearUniqueFindersCache(passwordPolicy);
2578                    }
2579            }
2580    
2581            protected void cacheUniqueFindersCache(PasswordPolicy passwordPolicy) {
2582                    if (passwordPolicy.isNew()) {
2583                            Object[] args = new Object[] {
2584                                            passwordPolicy.getCompanyId(),
2585                                            passwordPolicy.getDefaultPolicy()
2586                                    };
2587    
2588                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_DP, args,
2589                                    Long.valueOf(1));
2590                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP, args,
2591                                    passwordPolicy);
2592    
2593                            args = new Object[] {
2594                                            passwordPolicy.getCompanyId(), passwordPolicy.getName()
2595                                    };
2596    
2597                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
2598                                    Long.valueOf(1));
2599                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
2600                                    passwordPolicy);
2601                    }
2602                    else {
2603                            PasswordPolicyModelImpl passwordPolicyModelImpl = (PasswordPolicyModelImpl)passwordPolicy;
2604    
2605                            if ((passwordPolicyModelImpl.getColumnBitmask() &
2606                                            FINDER_PATH_FETCH_BY_C_DP.getColumnBitmask()) != 0) {
2607                                    Object[] args = new Object[] {
2608                                                    passwordPolicy.getCompanyId(),
2609                                                    passwordPolicy.getDefaultPolicy()
2610                                            };
2611    
2612                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_DP, args,
2613                                            Long.valueOf(1));
2614                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DP, args,
2615                                            passwordPolicy);
2616                            }
2617    
2618                            if ((passwordPolicyModelImpl.getColumnBitmask() &
2619                                            FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
2620                                    Object[] args = new Object[] {
2621                                                    passwordPolicy.getCompanyId(), passwordPolicy.getName()
2622                                            };
2623    
2624                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
2625                                            Long.valueOf(1));
2626                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
2627                                            passwordPolicy);
2628                            }
2629                    }
2630            }
2631    
2632            protected void clearUniqueFindersCache(PasswordPolicy passwordPolicy) {
2633                    PasswordPolicyModelImpl passwordPolicyModelImpl = (PasswordPolicyModelImpl)passwordPolicy;
2634    
2635                    Object[] args = new Object[] {
2636                                    passwordPolicy.getCompanyId(), passwordPolicy.getDefaultPolicy()
2637                            };
2638    
2639                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_DP, args);
2640                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP, args);
2641    
2642                    if ((passwordPolicyModelImpl.getColumnBitmask() &
2643                                    FINDER_PATH_FETCH_BY_C_DP.getColumnBitmask()) != 0) {
2644                            args = new Object[] {
2645                                            passwordPolicyModelImpl.getOriginalCompanyId(),
2646                                            passwordPolicyModelImpl.getOriginalDefaultPolicy()
2647                                    };
2648    
2649                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_DP, args);
2650                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DP, args);
2651                    }
2652    
2653                    args = new Object[] {
2654                                    passwordPolicy.getCompanyId(), passwordPolicy.getName()
2655                            };
2656    
2657                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
2658                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
2659    
2660                    if ((passwordPolicyModelImpl.getColumnBitmask() &
2661                                    FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
2662                            args = new Object[] {
2663                                            passwordPolicyModelImpl.getOriginalCompanyId(),
2664                                            passwordPolicyModelImpl.getOriginalName()
2665                                    };
2666    
2667                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
2668                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
2669                    }
2670            }
2671    
2672            /**
2673             * Creates a new password policy with the primary key. Does not add the password policy to the database.
2674             *
2675             * @param passwordPolicyId the primary key for the new password policy
2676             * @return the new password policy
2677             */
2678            public PasswordPolicy create(long passwordPolicyId) {
2679                    PasswordPolicy passwordPolicy = new PasswordPolicyImpl();
2680    
2681                    passwordPolicy.setNew(true);
2682                    passwordPolicy.setPrimaryKey(passwordPolicyId);
2683    
2684                    String uuid = PortalUUIDUtil.generate();
2685    
2686                    passwordPolicy.setUuid(uuid);
2687    
2688                    return passwordPolicy;
2689            }
2690    
2691            /**
2692             * Removes the password policy with the primary key from the database. Also notifies the appropriate model listeners.
2693             *
2694             * @param passwordPolicyId the primary key of the password policy
2695             * @return the password policy that was removed
2696             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
2697             * @throws SystemException if a system exception occurred
2698             */
2699            public PasswordPolicy remove(long passwordPolicyId)
2700                    throws NoSuchPasswordPolicyException, SystemException {
2701                    return remove((Serializable)passwordPolicyId);
2702            }
2703    
2704            /**
2705             * Removes the password policy with the primary key from the database. Also notifies the appropriate model listeners.
2706             *
2707             * @param primaryKey the primary key of the password policy
2708             * @return the password policy that was removed
2709             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
2710             * @throws SystemException if a system exception occurred
2711             */
2712            @Override
2713            public PasswordPolicy remove(Serializable primaryKey)
2714                    throws NoSuchPasswordPolicyException, SystemException {
2715                    Session session = null;
2716    
2717                    try {
2718                            session = openSession();
2719    
2720                            PasswordPolicy passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
2721                                            primaryKey);
2722    
2723                            if (passwordPolicy == null) {
2724                                    if (_log.isWarnEnabled()) {
2725                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2726                                    }
2727    
2728                                    throw new NoSuchPasswordPolicyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2729                                            primaryKey);
2730                            }
2731    
2732                            return remove(passwordPolicy);
2733                    }
2734                    catch (NoSuchPasswordPolicyException nsee) {
2735                            throw nsee;
2736                    }
2737                    catch (Exception e) {
2738                            throw processException(e);
2739                    }
2740                    finally {
2741                            closeSession(session);
2742                    }
2743            }
2744    
2745            @Override
2746            protected PasswordPolicy removeImpl(PasswordPolicy passwordPolicy)
2747                    throws SystemException {
2748                    passwordPolicy = toUnwrappedModel(passwordPolicy);
2749    
2750                    Session session = null;
2751    
2752                    try {
2753                            session = openSession();
2754    
2755                            if (!session.contains(passwordPolicy)) {
2756                                    passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
2757                                                    passwordPolicy.getPrimaryKeyObj());
2758                            }
2759    
2760                            if (passwordPolicy != null) {
2761                                    session.delete(passwordPolicy);
2762                            }
2763                    }
2764                    catch (Exception e) {
2765                            throw processException(e);
2766                    }
2767                    finally {
2768                            closeSession(session);
2769                    }
2770    
2771                    if (passwordPolicy != null) {
2772                            clearCache(passwordPolicy);
2773                    }
2774    
2775                    return passwordPolicy;
2776            }
2777    
2778            @Override
2779            public PasswordPolicy updateImpl(
2780                    com.liferay.portal.model.PasswordPolicy passwordPolicy)
2781                    throws SystemException {
2782                    passwordPolicy = toUnwrappedModel(passwordPolicy);
2783    
2784                    boolean isNew = passwordPolicy.isNew();
2785    
2786                    PasswordPolicyModelImpl passwordPolicyModelImpl = (PasswordPolicyModelImpl)passwordPolicy;
2787    
2788                    if (Validator.isNull(passwordPolicy.getUuid())) {
2789                            String uuid = PortalUUIDUtil.generate();
2790    
2791                            passwordPolicy.setUuid(uuid);
2792                    }
2793    
2794                    Session session = null;
2795    
2796                    try {
2797                            session = openSession();
2798    
2799                            if (passwordPolicy.isNew()) {
2800                                    session.save(passwordPolicy);
2801    
2802                                    passwordPolicy.setNew(false);
2803                            }
2804                            else {
2805                                    session.merge(passwordPolicy);
2806                            }
2807                    }
2808                    catch (Exception e) {
2809                            throw processException(e);
2810                    }
2811                    finally {
2812                            closeSession(session);
2813                    }
2814    
2815                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2816    
2817                    if (isNew || !PasswordPolicyModelImpl.COLUMN_BITMASK_ENABLED) {
2818                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2819                    }
2820    
2821                    else {
2822                            if ((passwordPolicyModelImpl.getColumnBitmask() &
2823                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2824                                    Object[] args = new Object[] {
2825                                                    passwordPolicyModelImpl.getOriginalUuid()
2826                                            };
2827    
2828                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2829                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2830                                            args);
2831    
2832                                    args = new Object[] { passwordPolicyModelImpl.getUuid() };
2833    
2834                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2835                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2836                                            args);
2837                            }
2838    
2839                            if ((passwordPolicyModelImpl.getColumnBitmask() &
2840                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2841                                    Object[] args = new Object[] {
2842                                                    passwordPolicyModelImpl.getOriginalUuid(),
2843                                                    passwordPolicyModelImpl.getOriginalCompanyId()
2844                                            };
2845    
2846                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2847                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2848                                            args);
2849    
2850                                    args = new Object[] {
2851                                                    passwordPolicyModelImpl.getUuid(),
2852                                                    passwordPolicyModelImpl.getCompanyId()
2853                                            };
2854    
2855                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2856                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2857                                            args);
2858                            }
2859                    }
2860    
2861                    EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2862                            PasswordPolicyImpl.class, passwordPolicy.getPrimaryKey(),
2863                            passwordPolicy);
2864    
2865                    clearUniqueFindersCache(passwordPolicy);
2866                    cacheUniqueFindersCache(passwordPolicy);
2867    
2868                    return passwordPolicy;
2869            }
2870    
2871            protected PasswordPolicy toUnwrappedModel(PasswordPolicy passwordPolicy) {
2872                    if (passwordPolicy instanceof PasswordPolicyImpl) {
2873                            return passwordPolicy;
2874                    }
2875    
2876                    PasswordPolicyImpl passwordPolicyImpl = new PasswordPolicyImpl();
2877    
2878                    passwordPolicyImpl.setNew(passwordPolicy.isNew());
2879                    passwordPolicyImpl.setPrimaryKey(passwordPolicy.getPrimaryKey());
2880    
2881                    passwordPolicyImpl.setUuid(passwordPolicy.getUuid());
2882                    passwordPolicyImpl.setPasswordPolicyId(passwordPolicy.getPasswordPolicyId());
2883                    passwordPolicyImpl.setCompanyId(passwordPolicy.getCompanyId());
2884                    passwordPolicyImpl.setUserId(passwordPolicy.getUserId());
2885                    passwordPolicyImpl.setUserName(passwordPolicy.getUserName());
2886                    passwordPolicyImpl.setCreateDate(passwordPolicy.getCreateDate());
2887                    passwordPolicyImpl.setModifiedDate(passwordPolicy.getModifiedDate());
2888                    passwordPolicyImpl.setDefaultPolicy(passwordPolicy.isDefaultPolicy());
2889                    passwordPolicyImpl.setName(passwordPolicy.getName());
2890                    passwordPolicyImpl.setDescription(passwordPolicy.getDescription());
2891                    passwordPolicyImpl.setChangeable(passwordPolicy.isChangeable());
2892                    passwordPolicyImpl.setChangeRequired(passwordPolicy.isChangeRequired());
2893                    passwordPolicyImpl.setMinAge(passwordPolicy.getMinAge());
2894                    passwordPolicyImpl.setCheckSyntax(passwordPolicy.isCheckSyntax());
2895                    passwordPolicyImpl.setAllowDictionaryWords(passwordPolicy.isAllowDictionaryWords());
2896                    passwordPolicyImpl.setMinAlphanumeric(passwordPolicy.getMinAlphanumeric());
2897                    passwordPolicyImpl.setMinLength(passwordPolicy.getMinLength());
2898                    passwordPolicyImpl.setMinLowerCase(passwordPolicy.getMinLowerCase());
2899                    passwordPolicyImpl.setMinNumbers(passwordPolicy.getMinNumbers());
2900                    passwordPolicyImpl.setMinSymbols(passwordPolicy.getMinSymbols());
2901                    passwordPolicyImpl.setMinUpperCase(passwordPolicy.getMinUpperCase());
2902                    passwordPolicyImpl.setRegex(passwordPolicy.getRegex());
2903                    passwordPolicyImpl.setHistory(passwordPolicy.isHistory());
2904                    passwordPolicyImpl.setHistoryCount(passwordPolicy.getHistoryCount());
2905                    passwordPolicyImpl.setExpireable(passwordPolicy.isExpireable());
2906                    passwordPolicyImpl.setMaxAge(passwordPolicy.getMaxAge());
2907                    passwordPolicyImpl.setWarningTime(passwordPolicy.getWarningTime());
2908                    passwordPolicyImpl.setGraceLimit(passwordPolicy.getGraceLimit());
2909                    passwordPolicyImpl.setLockout(passwordPolicy.isLockout());
2910                    passwordPolicyImpl.setMaxFailure(passwordPolicy.getMaxFailure());
2911                    passwordPolicyImpl.setLockoutDuration(passwordPolicy.getLockoutDuration());
2912                    passwordPolicyImpl.setRequireUnlock(passwordPolicy.isRequireUnlock());
2913                    passwordPolicyImpl.setResetFailureCount(passwordPolicy.getResetFailureCount());
2914                    passwordPolicyImpl.setResetTicketMaxAge(passwordPolicy.getResetTicketMaxAge());
2915    
2916                    return passwordPolicyImpl;
2917            }
2918    
2919            /**
2920             * Returns the password policy with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2921             *
2922             * @param primaryKey the primary key of the password policy
2923             * @return the password policy
2924             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
2925             * @throws SystemException if a system exception occurred
2926             */
2927            @Override
2928            public PasswordPolicy findByPrimaryKey(Serializable primaryKey)
2929                    throws NoSuchPasswordPolicyException, SystemException {
2930                    PasswordPolicy passwordPolicy = fetchByPrimaryKey(primaryKey);
2931    
2932                    if (passwordPolicy == null) {
2933                            if (_log.isWarnEnabled()) {
2934                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2935                            }
2936    
2937                            throw new NoSuchPasswordPolicyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2938                                    primaryKey);
2939                    }
2940    
2941                    return passwordPolicy;
2942            }
2943    
2944            /**
2945             * Returns the password policy with the primary key or throws a {@link com.liferay.portal.NoSuchPasswordPolicyException} if it could not be found.
2946             *
2947             * @param passwordPolicyId the primary key of the password policy
2948             * @return the password policy
2949             * @throws com.liferay.portal.NoSuchPasswordPolicyException if a password policy with the primary key could not be found
2950             * @throws SystemException if a system exception occurred
2951             */
2952            public PasswordPolicy findByPrimaryKey(long passwordPolicyId)
2953                    throws NoSuchPasswordPolicyException, SystemException {
2954                    return findByPrimaryKey((Serializable)passwordPolicyId);
2955            }
2956    
2957            /**
2958             * Returns the password policy with the primary key or returns <code>null</code> if it could not be found.
2959             *
2960             * @param primaryKey the primary key of the password policy
2961             * @return the password policy, or <code>null</code> if a password policy with the primary key could not be found
2962             * @throws SystemException if a system exception occurred
2963             */
2964            @Override
2965            public PasswordPolicy fetchByPrimaryKey(Serializable primaryKey)
2966                    throws SystemException {
2967                    PasswordPolicy passwordPolicy = (PasswordPolicy)EntityCacheUtil.getResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2968                                    PasswordPolicyImpl.class, primaryKey);
2969    
2970                    if (passwordPolicy == _nullPasswordPolicy) {
2971                            return null;
2972                    }
2973    
2974                    if (passwordPolicy == null) {
2975                            Session session = null;
2976    
2977                            try {
2978                                    session = openSession();
2979    
2980                                    passwordPolicy = (PasswordPolicy)session.get(PasswordPolicyImpl.class,
2981                                                    primaryKey);
2982    
2983                                    if (passwordPolicy != null) {
2984                                            cacheResult(passwordPolicy);
2985                                    }
2986                                    else {
2987                                            EntityCacheUtil.putResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2988                                                    PasswordPolicyImpl.class, primaryKey,
2989                                                    _nullPasswordPolicy);
2990                                    }
2991                            }
2992                            catch (Exception e) {
2993                                    EntityCacheUtil.removeResult(PasswordPolicyModelImpl.ENTITY_CACHE_ENABLED,
2994                                            PasswordPolicyImpl.class, primaryKey);
2995    
2996                                    throw processException(e);
2997                            }
2998                            finally {
2999                                    closeSession(session);
3000                            }
3001                    }
3002    
3003                    return passwordPolicy;
3004            }
3005    
3006            /**
3007             * Returns the password policy with the primary key or returns <code>null</code> if it could not be found.
3008             *
3009             * @param passwordPolicyId the primary key of the password policy
3010             * @return the password policy, or <code>null</code> if a password policy with the primary key could not be found
3011             * @throws SystemException if a system exception occurred
3012             */
3013            public PasswordPolicy fetchByPrimaryKey(long passwordPolicyId)
3014                    throws SystemException {
3015                    return fetchByPrimaryKey((Serializable)passwordPolicyId);
3016            }
3017    
3018            /**
3019             * Returns all the password policies.
3020             *
3021             * @return the password policies
3022             * @throws SystemException if a system exception occurred
3023             */
3024            public List<PasswordPolicy> findAll() throws SystemException {
3025                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3026            }
3027    
3028            /**
3029             * Returns a range of all the password policies.
3030             *
3031             * <p>
3032             * 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.
3033             * </p>
3034             *
3035             * @param start the lower bound of the range of password policies
3036             * @param end the upper bound of the range of password policies (not inclusive)
3037             * @return the range of password policies
3038             * @throws SystemException if a system exception occurred
3039             */
3040            public List<PasswordPolicy> findAll(int start, int end)
3041                    throws SystemException {
3042                    return findAll(start, end, null);
3043            }
3044    
3045            /**
3046             * Returns an ordered range of all the password policies.
3047             *
3048             * <p>
3049             * 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.
3050             * </p>
3051             *
3052             * @param start the lower bound of the range of password policies
3053             * @param end the upper bound of the range of password policies (not inclusive)
3054             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3055             * @return the ordered range of password policies
3056             * @throws SystemException if a system exception occurred
3057             */
3058            public List<PasswordPolicy> findAll(int start, int end,
3059                    OrderByComparator orderByComparator) throws SystemException {
3060                    boolean pagination = true;
3061                    FinderPath finderPath = null;
3062                    Object[] finderArgs = null;
3063    
3064                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3065                                    (orderByComparator == null)) {
3066                            pagination = false;
3067                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3068                            finderArgs = FINDER_ARGS_EMPTY;
3069                    }
3070                    else {
3071                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3072                            finderArgs = new Object[] { start, end, orderByComparator };
3073                    }
3074    
3075                    List<PasswordPolicy> list = (List<PasswordPolicy>)FinderCacheUtil.getResult(finderPath,
3076                                    finderArgs, this);
3077    
3078                    if (list == null) {
3079                            StringBundler query = null;
3080                            String sql = null;
3081    
3082                            if (orderByComparator != null) {
3083                                    query = new StringBundler(2 +
3084                                                    (orderByComparator.getOrderByFields().length * 3));
3085    
3086                                    query.append(_SQL_SELECT_PASSWORDPOLICY);
3087    
3088                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3089                                            orderByComparator);
3090    
3091                                    sql = query.toString();
3092                            }
3093                            else {
3094                                    sql = _SQL_SELECT_PASSWORDPOLICY;
3095    
3096                                    if (pagination) {
3097                                            sql = sql.concat(PasswordPolicyModelImpl.ORDER_BY_JPQL);
3098                                    }
3099                            }
3100    
3101                            Session session = null;
3102    
3103                            try {
3104                                    session = openSession();
3105    
3106                                    Query q = session.createQuery(sql);
3107    
3108                                    if (!pagination) {
3109                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
3110                                                            getDialect(), start, end, false);
3111    
3112                                            Collections.sort(list);
3113    
3114                                            list = new UnmodifiableList<PasswordPolicy>(list);
3115                                    }
3116                                    else {
3117                                            list = (List<PasswordPolicy>)QueryUtil.list(q,
3118                                                            getDialect(), start, end);
3119                                    }
3120    
3121                                    cacheResult(list);
3122    
3123                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3124                            }
3125                            catch (Exception e) {
3126                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3127    
3128                                    throw processException(e);
3129                            }
3130                            finally {
3131                                    closeSession(session);
3132                            }
3133                    }
3134    
3135                    return list;
3136            }
3137    
3138            /**
3139             * Removes all the password policies from the database.
3140             *
3141             * @throws SystemException if a system exception occurred
3142             */
3143            public void removeAll() throws SystemException {
3144                    for (PasswordPolicy passwordPolicy : findAll()) {
3145                            remove(passwordPolicy);
3146                    }
3147            }
3148    
3149            /**
3150             * Returns the number of password policies.
3151             *
3152             * @return the number of password policies
3153             * @throws SystemException if a system exception occurred
3154             */
3155            public int countAll() throws SystemException {
3156                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3157                                    FINDER_ARGS_EMPTY, this);
3158    
3159                    if (count == null) {
3160                            Session session = null;
3161    
3162                            try {
3163                                    session = openSession();
3164    
3165                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDPOLICY);
3166    
3167                                    count = (Long)q.uniqueResult();
3168    
3169                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3170                                            FINDER_ARGS_EMPTY, count);
3171                            }
3172                            catch (Exception e) {
3173                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3174                                            FINDER_ARGS_EMPTY);
3175    
3176                                    throw processException(e);
3177                            }
3178                            finally {
3179                                    closeSession(session);
3180                            }
3181                    }
3182    
3183                    return count.intValue();
3184            }
3185    
3186            @Override
3187            protected Set<String> getBadColumnNames() {
3188                    return _badColumnNames;
3189            }
3190    
3191            /**
3192             * Initializes the password policy persistence.
3193             */
3194            public void afterPropertiesSet() {
3195                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3196                                            com.liferay.portal.util.PropsUtil.get(
3197                                                    "value.object.listener.com.liferay.portal.model.PasswordPolicy")));
3198    
3199                    if (listenerClassNames.length > 0) {
3200                            try {
3201                                    List<ModelListener<PasswordPolicy>> listenersList = new ArrayList<ModelListener<PasswordPolicy>>();
3202    
3203                                    for (String listenerClassName : listenerClassNames) {
3204                                            listenersList.add((ModelListener<PasswordPolicy>)InstanceFactory.newInstance(
3205                                                            getClassLoader(), listenerClassName));
3206                                    }
3207    
3208                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3209                            }
3210                            catch (Exception e) {
3211                                    _log.error(e);
3212                            }
3213                    }
3214            }
3215    
3216            public void destroy() {
3217                    EntityCacheUtil.removeCache(PasswordPolicyImpl.class.getName());
3218                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3219                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3220                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3221            }
3222    
3223            private static final String _SQL_SELECT_PASSWORDPOLICY = "SELECT passwordPolicy FROM PasswordPolicy passwordPolicy";
3224            private static final String _SQL_SELECT_PASSWORDPOLICY_WHERE = "SELECT passwordPolicy FROM PasswordPolicy passwordPolicy WHERE ";
3225            private static final String _SQL_COUNT_PASSWORDPOLICY = "SELECT COUNT(passwordPolicy) FROM PasswordPolicy passwordPolicy";
3226            private static final String _SQL_COUNT_PASSWORDPOLICY_WHERE = "SELECT COUNT(passwordPolicy) FROM PasswordPolicy passwordPolicy WHERE ";
3227            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "passwordPolicy.passwordPolicyId";
3228            private static final String _FILTER_SQL_SELECT_PASSWORDPOLICY_WHERE = "SELECT DISTINCT {passwordPolicy.*} FROM PasswordPolicy passwordPolicy WHERE ";
3229            private static final String _FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_1 =
3230                    "SELECT {PasswordPolicy.*} FROM (SELECT DISTINCT passwordPolicy.passwordPolicyId FROM PasswordPolicy passwordPolicy WHERE ";
3231            private static final String _FILTER_SQL_SELECT_PASSWORDPOLICY_NO_INLINE_DISTINCT_WHERE_2 =
3232                    ") TEMP_TABLE INNER JOIN PasswordPolicy ON TEMP_TABLE.passwordPolicyId = PasswordPolicy.passwordPolicyId";
3233            private static final String _FILTER_SQL_COUNT_PASSWORDPOLICY_WHERE = "SELECT COUNT(DISTINCT passwordPolicy.passwordPolicyId) AS COUNT_VALUE FROM PasswordPolicy passwordPolicy WHERE ";
3234            private static final String _FILTER_ENTITY_ALIAS = "passwordPolicy";
3235            private static final String _FILTER_ENTITY_TABLE = "PasswordPolicy";
3236            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordPolicy.";
3237            private static final String _ORDER_BY_ENTITY_TABLE = "PasswordPolicy.";
3238            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordPolicy exists with the primary key ";
3239            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordPolicy exists with the key {";
3240            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3241            private static Log _log = LogFactoryUtil.getLog(PasswordPolicyPersistenceImpl.class);
3242            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3243                                    "uuid"
3244                            });
3245            private static PasswordPolicy _nullPasswordPolicy = new PasswordPolicyImpl() {
3246                            @Override
3247                            public Object clone() {
3248                                    return this;
3249                            }
3250    
3251                            @Override
3252                            public CacheModel<PasswordPolicy> toCacheModel() {
3253                                    return _nullPasswordPolicyCacheModel;
3254                            }
3255                    };
3256    
3257            private static CacheModel<PasswordPolicy> _nullPasswordPolicyCacheModel = new CacheModel<PasswordPolicy>() {
3258                            public PasswordPolicy toEntityModel() {
3259                                    return _nullPasswordPolicy;
3260                            }
3261                    };
3262    }