001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchPasswordPolicyRelException;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.model.MVCCModel;
036    import com.liferay.portal.model.PasswordPolicyRel;
037    import com.liferay.portal.model.impl.PasswordPolicyRelImpl;
038    import com.liferay.portal.model.impl.PasswordPolicyRelModelImpl;
039    import com.liferay.portal.service.persistence.PasswordPolicyRelPersistence;
040    
041    import java.io.Serializable;
042    
043    import java.util.Collections;
044    import java.util.HashMap;
045    import java.util.HashSet;
046    import java.util.Iterator;
047    import java.util.List;
048    import java.util.Map;
049    import java.util.Set;
050    
051    /**
052     * The persistence implementation for the password policy rel service.
053     *
054     * <p>
055     * Caching information and settings can be found in <code>portal.properties</code>
056     * </p>
057     *
058     * @author Brian Wing Shun Chan
059     * @see PasswordPolicyRelPersistence
060     * @see com.liferay.portal.service.persistence.PasswordPolicyRelUtil
061     * @generated
062     */
063    @ProviderType
064    public class PasswordPolicyRelPersistenceImpl extends BasePersistenceImpl<PasswordPolicyRel>
065            implements PasswordPolicyRelPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link PasswordPolicyRelUtil} to access the password policy rel persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = PasswordPolicyRelImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
077                            PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
078                            PasswordPolicyRelImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
081                            PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
082                            PasswordPolicyRelImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
085                            PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PASSWORDPOLICYID =
088                    new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
089                            PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
090                            PasswordPolicyRelImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByPasswordPolicyId",
092                            new String[] {
093                                    Long.class.getName(),
094                                    
095                            Integer.class.getName(), Integer.class.getName(),
096                                    OrderByComparator.class.getName()
097                            });
098            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID =
099                    new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
100                            PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
101                            PasswordPolicyRelImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
103                            "findByPasswordPolicyId", new String[] { Long.class.getName() },
104                            PasswordPolicyRelModelImpl.PASSWORDPOLICYID_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_PASSWORDPOLICYID = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
106                            PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
108                            "countByPasswordPolicyId", new String[] { Long.class.getName() });
109    
110            /**
111             * Returns all the password policy rels where passwordPolicyId = &#63;.
112             *
113             * @param passwordPolicyId the password policy ID
114             * @return the matching password policy rels
115             */
116            @Override
117            public List<PasswordPolicyRel> findByPasswordPolicyId(long passwordPolicyId) {
118                    return findByPasswordPolicyId(passwordPolicyId, QueryUtil.ALL_POS,
119                            QueryUtil.ALL_POS, null);
120            }
121    
122            /**
123             * Returns a range of all the password policy rels where passwordPolicyId = &#63;.
124             *
125             * <p>
126             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link PasswordPolicyRelModelImpl}. 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.
127             * </p>
128             *
129             * @param passwordPolicyId the password policy ID
130             * @param start the lower bound of the range of password policy rels
131             * @param end the upper bound of the range of password policy rels (not inclusive)
132             * @return the range of matching password policy rels
133             */
134            @Override
135            public List<PasswordPolicyRel> findByPasswordPolicyId(
136                    long passwordPolicyId, int start, int end) {
137                    return findByPasswordPolicyId(passwordPolicyId, start, end, null);
138            }
139    
140            /**
141             * Returns an ordered range of all the password policy rels where passwordPolicyId = &#63;.
142             *
143             * <p>
144             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link PasswordPolicyRelModelImpl}. 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.
145             * </p>
146             *
147             * @param passwordPolicyId the password policy ID
148             * @param start the lower bound of the range of password policy rels
149             * @param end the upper bound of the range of password policy rels (not inclusive)
150             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
151             * @return the ordered range of matching password policy rels
152             */
153            @Override
154            public List<PasswordPolicyRel> findByPasswordPolicyId(
155                    long passwordPolicyId, int start, int end,
156                    OrderByComparator<PasswordPolicyRel> orderByComparator) {
157                    return findByPasswordPolicyId(passwordPolicyId, start, end,
158                            orderByComparator, true);
159            }
160    
161            /**
162             * Returns an ordered range of all the password policy rels where passwordPolicyId = &#63;.
163             *
164             * <p>
165             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link PasswordPolicyRelModelImpl}. 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.
166             * </p>
167             *
168             * @param passwordPolicyId the password policy ID
169             * @param start the lower bound of the range of password policy rels
170             * @param end the upper bound of the range of password policy rels (not inclusive)
171             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
172             * @param retrieveFromCache whether to retrieve from the finder cache
173             * @return the ordered range of matching password policy rels
174             */
175            @Override
176            public List<PasswordPolicyRel> findByPasswordPolicyId(
177                    long passwordPolicyId, int start, int end,
178                    OrderByComparator<PasswordPolicyRel> orderByComparator,
179                    boolean retrieveFromCache) {
180                    boolean pagination = true;
181                    FinderPath finderPath = null;
182                    Object[] finderArgs = null;
183    
184                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
185                                    (orderByComparator == null)) {
186                            pagination = false;
187                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID;
188                            finderArgs = new Object[] { passwordPolicyId };
189                    }
190                    else {
191                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PASSWORDPOLICYID;
192                            finderArgs = new Object[] {
193                                            passwordPolicyId,
194                                            
195                                            start, end, orderByComparator
196                                    };
197                    }
198    
199                    List<PasswordPolicyRel> list = null;
200    
201                    if (retrieveFromCache) {
202                            list = (List<PasswordPolicyRel>)finderCache.getResult(finderPath,
203                                            finderArgs, this);
204    
205                            if ((list != null) && !list.isEmpty()) {
206                                    for (PasswordPolicyRel passwordPolicyRel : list) {
207                                            if ((passwordPolicyId != passwordPolicyRel.getPasswordPolicyId())) {
208                                                    list = null;
209    
210                                                    break;
211                                            }
212                                    }
213                            }
214                    }
215    
216                    if (list == null) {
217                            StringBundler query = null;
218    
219                            if (orderByComparator != null) {
220                                    query = new StringBundler(3 +
221                                                    (orderByComparator.getOrderByFields().length * 3));
222                            }
223                            else {
224                                    query = new StringBundler(3);
225                            }
226    
227                            query.append(_SQL_SELECT_PASSWORDPOLICYREL_WHERE);
228    
229                            query.append(_FINDER_COLUMN_PASSWORDPOLICYID_PASSWORDPOLICYID_2);
230    
231                            if (orderByComparator != null) {
232                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
233                                            orderByComparator);
234                            }
235                            else
236                             if (pagination) {
237                                    query.append(PasswordPolicyRelModelImpl.ORDER_BY_JPQL);
238                            }
239    
240                            String sql = query.toString();
241    
242                            Session session = null;
243    
244                            try {
245                                    session = openSession();
246    
247                                    Query q = session.createQuery(sql);
248    
249                                    QueryPos qPos = QueryPos.getInstance(q);
250    
251                                    qPos.add(passwordPolicyId);
252    
253                                    if (!pagination) {
254                                            list = (List<PasswordPolicyRel>)QueryUtil.list(q,
255                                                            getDialect(), start, end, false);
256    
257                                            Collections.sort(list);
258    
259                                            list = Collections.unmodifiableList(list);
260                                    }
261                                    else {
262                                            list = (List<PasswordPolicyRel>)QueryUtil.list(q,
263                                                            getDialect(), start, end);
264                                    }
265    
266                                    cacheResult(list);
267    
268                                    finderCache.putResult(finderPath, finderArgs, list);
269                            }
270                            catch (Exception e) {
271                                    finderCache.removeResult(finderPath, finderArgs);
272    
273                                    throw processException(e);
274                            }
275                            finally {
276                                    closeSession(session);
277                            }
278                    }
279    
280                    return list;
281            }
282    
283            /**
284             * Returns the first password policy rel in the ordered set where passwordPolicyId = &#63;.
285             *
286             * @param passwordPolicyId the password policy ID
287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
288             * @return the first matching password policy rel
289             * @throws NoSuchPasswordPolicyRelException if a matching password policy rel could not be found
290             */
291            @Override
292            public PasswordPolicyRel findByPasswordPolicyId_First(
293                    long passwordPolicyId,
294                    OrderByComparator<PasswordPolicyRel> orderByComparator)
295                    throws NoSuchPasswordPolicyRelException {
296                    PasswordPolicyRel passwordPolicyRel = fetchByPasswordPolicyId_First(passwordPolicyId,
297                                    orderByComparator);
298    
299                    if (passwordPolicyRel != null) {
300                            return passwordPolicyRel;
301                    }
302    
303                    StringBundler msg = new StringBundler(4);
304    
305                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
306    
307                    msg.append("passwordPolicyId=");
308                    msg.append(passwordPolicyId);
309    
310                    msg.append(StringPool.CLOSE_CURLY_BRACE);
311    
312                    throw new NoSuchPasswordPolicyRelException(msg.toString());
313            }
314    
315            /**
316             * Returns the first password policy rel in the ordered set where passwordPolicyId = &#63;.
317             *
318             * @param passwordPolicyId the password policy ID
319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
320             * @return the first matching password policy rel, or <code>null</code> if a matching password policy rel could not be found
321             */
322            @Override
323            public PasswordPolicyRel fetchByPasswordPolicyId_First(
324                    long passwordPolicyId,
325                    OrderByComparator<PasswordPolicyRel> orderByComparator) {
326                    List<PasswordPolicyRel> list = findByPasswordPolicyId(passwordPolicyId,
327                                    0, 1, orderByComparator);
328    
329                    if (!list.isEmpty()) {
330                            return list.get(0);
331                    }
332    
333                    return null;
334            }
335    
336            /**
337             * Returns the last password policy rel in the ordered set where passwordPolicyId = &#63;.
338             *
339             * @param passwordPolicyId the password policy ID
340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
341             * @return the last matching password policy rel
342             * @throws NoSuchPasswordPolicyRelException if a matching password policy rel could not be found
343             */
344            @Override
345            public PasswordPolicyRel findByPasswordPolicyId_Last(
346                    long passwordPolicyId,
347                    OrderByComparator<PasswordPolicyRel> orderByComparator)
348                    throws NoSuchPasswordPolicyRelException {
349                    PasswordPolicyRel passwordPolicyRel = fetchByPasswordPolicyId_Last(passwordPolicyId,
350                                    orderByComparator);
351    
352                    if (passwordPolicyRel != null) {
353                            return passwordPolicyRel;
354                    }
355    
356                    StringBundler msg = new StringBundler(4);
357    
358                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
359    
360                    msg.append("passwordPolicyId=");
361                    msg.append(passwordPolicyId);
362    
363                    msg.append(StringPool.CLOSE_CURLY_BRACE);
364    
365                    throw new NoSuchPasswordPolicyRelException(msg.toString());
366            }
367    
368            /**
369             * Returns the last password policy rel in the ordered set where passwordPolicyId = &#63;.
370             *
371             * @param passwordPolicyId the password policy ID
372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
373             * @return the last matching password policy rel, or <code>null</code> if a matching password policy rel could not be found
374             */
375            @Override
376            public PasswordPolicyRel fetchByPasswordPolicyId_Last(
377                    long passwordPolicyId,
378                    OrderByComparator<PasswordPolicyRel> orderByComparator) {
379                    int count = countByPasswordPolicyId(passwordPolicyId);
380    
381                    if (count == 0) {
382                            return null;
383                    }
384    
385                    List<PasswordPolicyRel> list = findByPasswordPolicyId(passwordPolicyId,
386                                    count - 1, count, orderByComparator);
387    
388                    if (!list.isEmpty()) {
389                            return list.get(0);
390                    }
391    
392                    return null;
393            }
394    
395            /**
396             * Returns the password policy rels before and after the current password policy rel in the ordered set where passwordPolicyId = &#63;.
397             *
398             * @param passwordPolicyRelId the primary key of the current password policy rel
399             * @param passwordPolicyId the password policy ID
400             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
401             * @return the previous, current, and next password policy rel
402             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
403             */
404            @Override
405            public PasswordPolicyRel[] findByPasswordPolicyId_PrevAndNext(
406                    long passwordPolicyRelId, long passwordPolicyId,
407                    OrderByComparator<PasswordPolicyRel> orderByComparator)
408                    throws NoSuchPasswordPolicyRelException {
409                    PasswordPolicyRel passwordPolicyRel = findByPrimaryKey(passwordPolicyRelId);
410    
411                    Session session = null;
412    
413                    try {
414                            session = openSession();
415    
416                            PasswordPolicyRel[] array = new PasswordPolicyRelImpl[3];
417    
418                            array[0] = getByPasswordPolicyId_PrevAndNext(session,
419                                            passwordPolicyRel, passwordPolicyId, orderByComparator, true);
420    
421                            array[1] = passwordPolicyRel;
422    
423                            array[2] = getByPasswordPolicyId_PrevAndNext(session,
424                                            passwordPolicyRel, passwordPolicyId, orderByComparator,
425                                            false);
426    
427                            return array;
428                    }
429                    catch (Exception e) {
430                            throw processException(e);
431                    }
432                    finally {
433                            closeSession(session);
434                    }
435            }
436    
437            protected PasswordPolicyRel getByPasswordPolicyId_PrevAndNext(
438                    Session session, PasswordPolicyRel passwordPolicyRel,
439                    long passwordPolicyId,
440                    OrderByComparator<PasswordPolicyRel> orderByComparator, boolean previous) {
441                    StringBundler query = null;
442    
443                    if (orderByComparator != null) {
444                            query = new StringBundler(6 +
445                                            (orderByComparator.getOrderByFields().length * 6));
446                    }
447                    else {
448                            query = new StringBundler(3);
449                    }
450    
451                    query.append(_SQL_SELECT_PASSWORDPOLICYREL_WHERE);
452    
453                    query.append(_FINDER_COLUMN_PASSWORDPOLICYID_PASSWORDPOLICYID_2);
454    
455                    if (orderByComparator != null) {
456                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
457    
458                            if (orderByConditionFields.length > 0) {
459                                    query.append(WHERE_AND);
460                            }
461    
462                            for (int i = 0; i < orderByConditionFields.length; i++) {
463                                    query.append(_ORDER_BY_ENTITY_ALIAS);
464                                    query.append(orderByConditionFields[i]);
465    
466                                    if ((i + 1) < orderByConditionFields.length) {
467                                            if (orderByComparator.isAscending() ^ previous) {
468                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
469                                            }
470                                            else {
471                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
472                                            }
473                                    }
474                                    else {
475                                            if (orderByComparator.isAscending() ^ previous) {
476                                                    query.append(WHERE_GREATER_THAN);
477                                            }
478                                            else {
479                                                    query.append(WHERE_LESSER_THAN);
480                                            }
481                                    }
482                            }
483    
484                            query.append(ORDER_BY_CLAUSE);
485    
486                            String[] orderByFields = orderByComparator.getOrderByFields();
487    
488                            for (int i = 0; i < orderByFields.length; i++) {
489                                    query.append(_ORDER_BY_ENTITY_ALIAS);
490                                    query.append(orderByFields[i]);
491    
492                                    if ((i + 1) < orderByFields.length) {
493                                            if (orderByComparator.isAscending() ^ previous) {
494                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
495                                            }
496                                            else {
497                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
498                                            }
499                                    }
500                                    else {
501                                            if (orderByComparator.isAscending() ^ previous) {
502                                                    query.append(ORDER_BY_ASC);
503                                            }
504                                            else {
505                                                    query.append(ORDER_BY_DESC);
506                                            }
507                                    }
508                            }
509                    }
510                    else {
511                            query.append(PasswordPolicyRelModelImpl.ORDER_BY_JPQL);
512                    }
513    
514                    String sql = query.toString();
515    
516                    Query q = session.createQuery(sql);
517    
518                    q.setFirstResult(0);
519                    q.setMaxResults(2);
520    
521                    QueryPos qPos = QueryPos.getInstance(q);
522    
523                    qPos.add(passwordPolicyId);
524    
525                    if (orderByComparator != null) {
526                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicyRel);
527    
528                            for (Object value : values) {
529                                    qPos.add(value);
530                            }
531                    }
532    
533                    List<PasswordPolicyRel> list = q.list();
534    
535                    if (list.size() == 2) {
536                            return list.get(1);
537                    }
538                    else {
539                            return null;
540                    }
541            }
542    
543            /**
544             * Removes all the password policy rels where passwordPolicyId = &#63; from the database.
545             *
546             * @param passwordPolicyId the password policy ID
547             */
548            @Override
549            public void removeByPasswordPolicyId(long passwordPolicyId) {
550                    for (PasswordPolicyRel passwordPolicyRel : findByPasswordPolicyId(
551                                    passwordPolicyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
552                            remove(passwordPolicyRel);
553                    }
554            }
555    
556            /**
557             * Returns the number of password policy rels where passwordPolicyId = &#63;.
558             *
559             * @param passwordPolicyId the password policy ID
560             * @return the number of matching password policy rels
561             */
562            @Override
563            public int countByPasswordPolicyId(long passwordPolicyId) {
564                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PASSWORDPOLICYID;
565    
566                    Object[] finderArgs = new Object[] { passwordPolicyId };
567    
568                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
569    
570                    if (count == null) {
571                            StringBundler query = new StringBundler(2);
572    
573                            query.append(_SQL_COUNT_PASSWORDPOLICYREL_WHERE);
574    
575                            query.append(_FINDER_COLUMN_PASSWORDPOLICYID_PASSWORDPOLICYID_2);
576    
577                            String sql = query.toString();
578    
579                            Session session = null;
580    
581                            try {
582                                    session = openSession();
583    
584                                    Query q = session.createQuery(sql);
585    
586                                    QueryPos qPos = QueryPos.getInstance(q);
587    
588                                    qPos.add(passwordPolicyId);
589    
590                                    count = (Long)q.uniqueResult();
591    
592                                    finderCache.putResult(finderPath, finderArgs, count);
593                            }
594                            catch (Exception e) {
595                                    finderCache.removeResult(finderPath, finderArgs);
596    
597                                    throw processException(e);
598                            }
599                            finally {
600                                    closeSession(session);
601                            }
602                    }
603    
604                    return count.intValue();
605            }
606    
607            private static final String _FINDER_COLUMN_PASSWORDPOLICYID_PASSWORDPOLICYID_2 =
608                    "passwordPolicyRel.passwordPolicyId = ?";
609            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
610                            PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
611                            PasswordPolicyRelImpl.class, FINDER_CLASS_NAME_ENTITY,
612                            "fetchByC_C",
613                            new String[] { Long.class.getName(), Long.class.getName() },
614                            PasswordPolicyRelModelImpl.CLASSNAMEID_COLUMN_BITMASK |
615                            PasswordPolicyRelModelImpl.CLASSPK_COLUMN_BITMASK);
616            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
617                            PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED, Long.class,
618                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
619                            new String[] { Long.class.getName(), Long.class.getName() });
620    
621            /**
622             * Returns the password policy rel where classNameId = &#63; and classPK = &#63; or throws a {@link NoSuchPasswordPolicyRelException} if it could not be found.
623             *
624             * @param classNameId the class name ID
625             * @param classPK the class p k
626             * @return the matching password policy rel
627             * @throws NoSuchPasswordPolicyRelException if a matching password policy rel could not be found
628             */
629            @Override
630            public PasswordPolicyRel findByC_C(long classNameId, long classPK)
631                    throws NoSuchPasswordPolicyRelException {
632                    PasswordPolicyRel passwordPolicyRel = fetchByC_C(classNameId, classPK);
633    
634                    if (passwordPolicyRel == null) {
635                            StringBundler msg = new StringBundler(6);
636    
637                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
638    
639                            msg.append("classNameId=");
640                            msg.append(classNameId);
641    
642                            msg.append(", classPK=");
643                            msg.append(classPK);
644    
645                            msg.append(StringPool.CLOSE_CURLY_BRACE);
646    
647                            if (_log.isWarnEnabled()) {
648                                    _log.warn(msg.toString());
649                            }
650    
651                            throw new NoSuchPasswordPolicyRelException(msg.toString());
652                    }
653    
654                    return passwordPolicyRel;
655            }
656    
657            /**
658             * Returns the password policy rel where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
659             *
660             * @param classNameId the class name ID
661             * @param classPK the class p k
662             * @return the matching password policy rel, or <code>null</code> if a matching password policy rel could not be found
663             */
664            @Override
665            public PasswordPolicyRel fetchByC_C(long classNameId, long classPK) {
666                    return fetchByC_C(classNameId, classPK, true);
667            }
668    
669            /**
670             * Returns the password policy rel where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
671             *
672             * @param classNameId the class name ID
673             * @param classPK the class p k
674             * @param retrieveFromCache whether to retrieve from the finder cache
675             * @return the matching password policy rel, or <code>null</code> if a matching password policy rel could not be found
676             */
677            @Override
678            public PasswordPolicyRel fetchByC_C(long classNameId, long classPK,
679                    boolean retrieveFromCache) {
680                    Object[] finderArgs = new Object[] { classNameId, classPK };
681    
682                    Object result = null;
683    
684                    if (retrieveFromCache) {
685                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C,
686                                            finderArgs, this);
687                    }
688    
689                    if (result instanceof PasswordPolicyRel) {
690                            PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)result;
691    
692                            if ((classNameId != passwordPolicyRel.getClassNameId()) ||
693                                            (classPK != passwordPolicyRel.getClassPK())) {
694                                    result = null;
695                            }
696                    }
697    
698                    if (result == null) {
699                            StringBundler query = new StringBundler(4);
700    
701                            query.append(_SQL_SELECT_PASSWORDPOLICYREL_WHERE);
702    
703                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
704    
705                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
706    
707                            String sql = query.toString();
708    
709                            Session session = null;
710    
711                            try {
712                                    session = openSession();
713    
714                                    Query q = session.createQuery(sql);
715    
716                                    QueryPos qPos = QueryPos.getInstance(q);
717    
718                                    qPos.add(classNameId);
719    
720                                    qPos.add(classPK);
721    
722                                    List<PasswordPolicyRel> list = q.list();
723    
724                                    if (list.isEmpty()) {
725                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, finderArgs,
726                                                    list);
727                                    }
728                                    else {
729                                            PasswordPolicyRel passwordPolicyRel = list.get(0);
730    
731                                            result = passwordPolicyRel;
732    
733                                            cacheResult(passwordPolicyRel);
734    
735                                            if ((passwordPolicyRel.getClassNameId() != classNameId) ||
736                                                            (passwordPolicyRel.getClassPK() != classPK)) {
737                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
738                                                            finderArgs, passwordPolicyRel);
739                                            }
740                                    }
741                            }
742                            catch (Exception e) {
743                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, finderArgs);
744    
745                                    throw processException(e);
746                            }
747                            finally {
748                                    closeSession(session);
749                            }
750                    }
751    
752                    if (result instanceof List<?>) {
753                            return null;
754                    }
755                    else {
756                            return (PasswordPolicyRel)result;
757                    }
758            }
759    
760            /**
761             * Removes the password policy rel where classNameId = &#63; and classPK = &#63; from the database.
762             *
763             * @param classNameId the class name ID
764             * @param classPK the class p k
765             * @return the password policy rel that was removed
766             */
767            @Override
768            public PasswordPolicyRel removeByC_C(long classNameId, long classPK)
769                    throws NoSuchPasswordPolicyRelException {
770                    PasswordPolicyRel passwordPolicyRel = findByC_C(classNameId, classPK);
771    
772                    return remove(passwordPolicyRel);
773            }
774    
775            /**
776             * Returns the number of password policy rels where classNameId = &#63; and classPK = &#63;.
777             *
778             * @param classNameId the class name ID
779             * @param classPK the class p k
780             * @return the number of matching password policy rels
781             */
782            @Override
783            public int countByC_C(long classNameId, long classPK) {
784                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
785    
786                    Object[] finderArgs = new Object[] { classNameId, classPK };
787    
788                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
789    
790                    if (count == null) {
791                            StringBundler query = new StringBundler(3);
792    
793                            query.append(_SQL_COUNT_PASSWORDPOLICYREL_WHERE);
794    
795                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
796    
797                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
798    
799                            String sql = query.toString();
800    
801                            Session session = null;
802    
803                            try {
804                                    session = openSession();
805    
806                                    Query q = session.createQuery(sql);
807    
808                                    QueryPos qPos = QueryPos.getInstance(q);
809    
810                                    qPos.add(classNameId);
811    
812                                    qPos.add(classPK);
813    
814                                    count = (Long)q.uniqueResult();
815    
816                                    finderCache.putResult(finderPath, finderArgs, count);
817                            }
818                            catch (Exception e) {
819                                    finderCache.removeResult(finderPath, finderArgs);
820    
821                                    throw processException(e);
822                            }
823                            finally {
824                                    closeSession(session);
825                            }
826                    }
827    
828                    return count.intValue();
829            }
830    
831            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "passwordPolicyRel.classNameId = ? AND ";
832            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "passwordPolicyRel.classPK = ?";
833    
834            public PasswordPolicyRelPersistenceImpl() {
835                    setModelClass(PasswordPolicyRel.class);
836            }
837    
838            /**
839             * Caches the password policy rel in the entity cache if it is enabled.
840             *
841             * @param passwordPolicyRel the password policy rel
842             */
843            @Override
844            public void cacheResult(PasswordPolicyRel passwordPolicyRel) {
845                    entityCache.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
846                            PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey(),
847                            passwordPolicyRel);
848    
849                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
850                            new Object[] {
851                                    passwordPolicyRel.getClassNameId(),
852                                    passwordPolicyRel.getClassPK()
853                            }, passwordPolicyRel);
854    
855                    passwordPolicyRel.resetOriginalValues();
856            }
857    
858            /**
859             * Caches the password policy rels in the entity cache if it is enabled.
860             *
861             * @param passwordPolicyRels the password policy rels
862             */
863            @Override
864            public void cacheResult(List<PasswordPolicyRel> passwordPolicyRels) {
865                    for (PasswordPolicyRel passwordPolicyRel : passwordPolicyRels) {
866                            if (entityCache.getResult(
867                                                    PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
868                                                    PasswordPolicyRelImpl.class,
869                                                    passwordPolicyRel.getPrimaryKey()) == null) {
870                                    cacheResult(passwordPolicyRel);
871                            }
872                            else {
873                                    passwordPolicyRel.resetOriginalValues();
874                            }
875                    }
876            }
877    
878            /**
879             * Clears the cache for all password policy rels.
880             *
881             * <p>
882             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
883             * </p>
884             */
885            @Override
886            public void clearCache() {
887                    entityCache.clearCache(PasswordPolicyRelImpl.class);
888    
889                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
890                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
891                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
892            }
893    
894            /**
895             * Clears the cache for the password policy rel.
896             *
897             * <p>
898             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
899             * </p>
900             */
901            @Override
902            public void clearCache(PasswordPolicyRel passwordPolicyRel) {
903                    entityCache.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
904                            PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey());
905    
906                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
907                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
908    
909                    clearUniqueFindersCache((PasswordPolicyRelModelImpl)passwordPolicyRel);
910            }
911    
912            @Override
913            public void clearCache(List<PasswordPolicyRel> passwordPolicyRels) {
914                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
915                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
916    
917                    for (PasswordPolicyRel passwordPolicyRel : passwordPolicyRels) {
918                            entityCache.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
919                                    PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey());
920    
921                            clearUniqueFindersCache((PasswordPolicyRelModelImpl)passwordPolicyRel);
922                    }
923            }
924    
925            protected void cacheUniqueFindersCache(
926                    PasswordPolicyRelModelImpl passwordPolicyRelModelImpl, boolean isNew) {
927                    if (isNew) {
928                            Object[] args = new Object[] {
929                                            passwordPolicyRelModelImpl.getClassNameId(),
930                                            passwordPolicyRelModelImpl.getClassPK()
931                                    };
932    
933                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
934                                    Long.valueOf(1));
935                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
936                                    passwordPolicyRelModelImpl);
937                    }
938                    else {
939                            if ((passwordPolicyRelModelImpl.getColumnBitmask() &
940                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
941                                    Object[] args = new Object[] {
942                                                    passwordPolicyRelModelImpl.getClassNameId(),
943                                                    passwordPolicyRelModelImpl.getClassPK()
944                                            };
945    
946                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
947                                            Long.valueOf(1));
948                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
949                                            passwordPolicyRelModelImpl);
950                            }
951                    }
952            }
953    
954            protected void clearUniqueFindersCache(
955                    PasswordPolicyRelModelImpl passwordPolicyRelModelImpl) {
956                    Object[] args = new Object[] {
957                                    passwordPolicyRelModelImpl.getClassNameId(),
958                                    passwordPolicyRelModelImpl.getClassPK()
959                            };
960    
961                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
962                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
963    
964                    if ((passwordPolicyRelModelImpl.getColumnBitmask() &
965                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
966                            args = new Object[] {
967                                            passwordPolicyRelModelImpl.getOriginalClassNameId(),
968                                            passwordPolicyRelModelImpl.getOriginalClassPK()
969                                    };
970    
971                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
972                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
973                    }
974            }
975    
976            /**
977             * Creates a new password policy rel with the primary key. Does not add the password policy rel to the database.
978             *
979             * @param passwordPolicyRelId the primary key for the new password policy rel
980             * @return the new password policy rel
981             */
982            @Override
983            public PasswordPolicyRel create(long passwordPolicyRelId) {
984                    PasswordPolicyRel passwordPolicyRel = new PasswordPolicyRelImpl();
985    
986                    passwordPolicyRel.setNew(true);
987                    passwordPolicyRel.setPrimaryKey(passwordPolicyRelId);
988    
989                    return passwordPolicyRel;
990            }
991    
992            /**
993             * Removes the password policy rel with the primary key from the database. Also notifies the appropriate model listeners.
994             *
995             * @param passwordPolicyRelId the primary key of the password policy rel
996             * @return the password policy rel that was removed
997             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
998             */
999            @Override
1000            public PasswordPolicyRel remove(long passwordPolicyRelId)
1001                    throws NoSuchPasswordPolicyRelException {
1002                    return remove((Serializable)passwordPolicyRelId);
1003            }
1004    
1005            /**
1006             * Removes the password policy rel with the primary key from the database. Also notifies the appropriate model listeners.
1007             *
1008             * @param primaryKey the primary key of the password policy rel
1009             * @return the password policy rel that was removed
1010             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1011             */
1012            @Override
1013            public PasswordPolicyRel remove(Serializable primaryKey)
1014                    throws NoSuchPasswordPolicyRelException {
1015                    Session session = null;
1016    
1017                    try {
1018                            session = openSession();
1019    
1020                            PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
1021                                            primaryKey);
1022    
1023                            if (passwordPolicyRel == null) {
1024                                    if (_log.isWarnEnabled()) {
1025                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1026                                    }
1027    
1028                                    throw new NoSuchPasswordPolicyRelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1029                                            primaryKey);
1030                            }
1031    
1032                            return remove(passwordPolicyRel);
1033                    }
1034                    catch (NoSuchPasswordPolicyRelException nsee) {
1035                            throw nsee;
1036                    }
1037                    catch (Exception e) {
1038                            throw processException(e);
1039                    }
1040                    finally {
1041                            closeSession(session);
1042                    }
1043            }
1044    
1045            @Override
1046            protected PasswordPolicyRel removeImpl(PasswordPolicyRel passwordPolicyRel) {
1047                    passwordPolicyRel = toUnwrappedModel(passwordPolicyRel);
1048    
1049                    Session session = null;
1050    
1051                    try {
1052                            session = openSession();
1053    
1054                            if (!session.contains(passwordPolicyRel)) {
1055                                    passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
1056                                                    passwordPolicyRel.getPrimaryKeyObj());
1057                            }
1058    
1059                            if (passwordPolicyRel != null) {
1060                                    session.delete(passwordPolicyRel);
1061                            }
1062                    }
1063                    catch (Exception e) {
1064                            throw processException(e);
1065                    }
1066                    finally {
1067                            closeSession(session);
1068                    }
1069    
1070                    if (passwordPolicyRel != null) {
1071                            clearCache(passwordPolicyRel);
1072                    }
1073    
1074                    return passwordPolicyRel;
1075            }
1076    
1077            @Override
1078            public PasswordPolicyRel updateImpl(PasswordPolicyRel passwordPolicyRel) {
1079                    passwordPolicyRel = toUnwrappedModel(passwordPolicyRel);
1080    
1081                    boolean isNew = passwordPolicyRel.isNew();
1082    
1083                    PasswordPolicyRelModelImpl passwordPolicyRelModelImpl = (PasswordPolicyRelModelImpl)passwordPolicyRel;
1084    
1085                    Session session = null;
1086    
1087                    try {
1088                            session = openSession();
1089    
1090                            if (passwordPolicyRel.isNew()) {
1091                                    session.save(passwordPolicyRel);
1092    
1093                                    passwordPolicyRel.setNew(false);
1094                            }
1095                            else {
1096                                    passwordPolicyRel = (PasswordPolicyRel)session.merge(passwordPolicyRel);
1097                            }
1098                    }
1099                    catch (Exception e) {
1100                            throw processException(e);
1101                    }
1102                    finally {
1103                            closeSession(session);
1104                    }
1105    
1106                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1107    
1108                    if (isNew || !PasswordPolicyRelModelImpl.COLUMN_BITMASK_ENABLED) {
1109                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1110                    }
1111    
1112                    else {
1113                            if ((passwordPolicyRelModelImpl.getColumnBitmask() &
1114                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID.getColumnBitmask()) != 0) {
1115                                    Object[] args = new Object[] {
1116                                                    passwordPolicyRelModelImpl.getOriginalPasswordPolicyId()
1117                                            };
1118    
1119                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PASSWORDPOLICYID,
1120                                            args);
1121                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID,
1122                                            args);
1123    
1124                                    args = new Object[] {
1125                                                    passwordPolicyRelModelImpl.getPasswordPolicyId()
1126                                            };
1127    
1128                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PASSWORDPOLICYID,
1129                                            args);
1130                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID,
1131                                            args);
1132                            }
1133                    }
1134    
1135                    entityCache.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1136                            PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey(),
1137                            passwordPolicyRel, false);
1138    
1139                    clearUniqueFindersCache(passwordPolicyRelModelImpl);
1140                    cacheUniqueFindersCache(passwordPolicyRelModelImpl, isNew);
1141    
1142                    passwordPolicyRel.resetOriginalValues();
1143    
1144                    return passwordPolicyRel;
1145            }
1146    
1147            protected PasswordPolicyRel toUnwrappedModel(
1148                    PasswordPolicyRel passwordPolicyRel) {
1149                    if (passwordPolicyRel instanceof PasswordPolicyRelImpl) {
1150                            return passwordPolicyRel;
1151                    }
1152    
1153                    PasswordPolicyRelImpl passwordPolicyRelImpl = new PasswordPolicyRelImpl();
1154    
1155                    passwordPolicyRelImpl.setNew(passwordPolicyRel.isNew());
1156                    passwordPolicyRelImpl.setPrimaryKey(passwordPolicyRel.getPrimaryKey());
1157    
1158                    passwordPolicyRelImpl.setMvccVersion(passwordPolicyRel.getMvccVersion());
1159                    passwordPolicyRelImpl.setPasswordPolicyRelId(passwordPolicyRel.getPasswordPolicyRelId());
1160                    passwordPolicyRelImpl.setPasswordPolicyId(passwordPolicyRel.getPasswordPolicyId());
1161                    passwordPolicyRelImpl.setClassNameId(passwordPolicyRel.getClassNameId());
1162                    passwordPolicyRelImpl.setClassPK(passwordPolicyRel.getClassPK());
1163    
1164                    return passwordPolicyRelImpl;
1165            }
1166    
1167            /**
1168             * Returns the password policy rel with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1169             *
1170             * @param primaryKey the primary key of the password policy rel
1171             * @return the password policy rel
1172             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1173             */
1174            @Override
1175            public PasswordPolicyRel findByPrimaryKey(Serializable primaryKey)
1176                    throws NoSuchPasswordPolicyRelException {
1177                    PasswordPolicyRel passwordPolicyRel = fetchByPrimaryKey(primaryKey);
1178    
1179                    if (passwordPolicyRel == null) {
1180                            if (_log.isWarnEnabled()) {
1181                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1182                            }
1183    
1184                            throw new NoSuchPasswordPolicyRelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1185                                    primaryKey);
1186                    }
1187    
1188                    return passwordPolicyRel;
1189            }
1190    
1191            /**
1192             * Returns the password policy rel with the primary key or throws a {@link NoSuchPasswordPolicyRelException} if it could not be found.
1193             *
1194             * @param passwordPolicyRelId the primary key of the password policy rel
1195             * @return the password policy rel
1196             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1197             */
1198            @Override
1199            public PasswordPolicyRel findByPrimaryKey(long passwordPolicyRelId)
1200                    throws NoSuchPasswordPolicyRelException {
1201                    return findByPrimaryKey((Serializable)passwordPolicyRelId);
1202            }
1203    
1204            /**
1205             * Returns the password policy rel with the primary key or returns <code>null</code> if it could not be found.
1206             *
1207             * @param primaryKey the primary key of the password policy rel
1208             * @return the password policy rel, or <code>null</code> if a password policy rel with the primary key could not be found
1209             */
1210            @Override
1211            public PasswordPolicyRel fetchByPrimaryKey(Serializable primaryKey) {
1212                    PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)entityCache.getResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1213                                    PasswordPolicyRelImpl.class, primaryKey);
1214    
1215                    if (passwordPolicyRel == _nullPasswordPolicyRel) {
1216                            return null;
1217                    }
1218    
1219                    if (passwordPolicyRel == null) {
1220                            Session session = null;
1221    
1222                            try {
1223                                    session = openSession();
1224    
1225                                    passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
1226                                                    primaryKey);
1227    
1228                                    if (passwordPolicyRel != null) {
1229                                            cacheResult(passwordPolicyRel);
1230                                    }
1231                                    else {
1232                                            entityCache.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1233                                                    PasswordPolicyRelImpl.class, primaryKey,
1234                                                    _nullPasswordPolicyRel);
1235                                    }
1236                            }
1237                            catch (Exception e) {
1238                                    entityCache.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1239                                            PasswordPolicyRelImpl.class, primaryKey);
1240    
1241                                    throw processException(e);
1242                            }
1243                            finally {
1244                                    closeSession(session);
1245                            }
1246                    }
1247    
1248                    return passwordPolicyRel;
1249            }
1250    
1251            /**
1252             * Returns the password policy rel with the primary key or returns <code>null</code> if it could not be found.
1253             *
1254             * @param passwordPolicyRelId the primary key of the password policy rel
1255             * @return the password policy rel, or <code>null</code> if a password policy rel with the primary key could not be found
1256             */
1257            @Override
1258            public PasswordPolicyRel fetchByPrimaryKey(long passwordPolicyRelId) {
1259                    return fetchByPrimaryKey((Serializable)passwordPolicyRelId);
1260            }
1261    
1262            @Override
1263            public Map<Serializable, PasswordPolicyRel> fetchByPrimaryKeys(
1264                    Set<Serializable> primaryKeys) {
1265                    if (primaryKeys.isEmpty()) {
1266                            return Collections.emptyMap();
1267                    }
1268    
1269                    Map<Serializable, PasswordPolicyRel> map = new HashMap<Serializable, PasswordPolicyRel>();
1270    
1271                    if (primaryKeys.size() == 1) {
1272                            Iterator<Serializable> iterator = primaryKeys.iterator();
1273    
1274                            Serializable primaryKey = iterator.next();
1275    
1276                            PasswordPolicyRel passwordPolicyRel = fetchByPrimaryKey(primaryKey);
1277    
1278                            if (passwordPolicyRel != null) {
1279                                    map.put(primaryKey, passwordPolicyRel);
1280                            }
1281    
1282                            return map;
1283                    }
1284    
1285                    Set<Serializable> uncachedPrimaryKeys = null;
1286    
1287                    for (Serializable primaryKey : primaryKeys) {
1288                            PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)entityCache.getResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1289                                            PasswordPolicyRelImpl.class, primaryKey);
1290    
1291                            if (passwordPolicyRel == null) {
1292                                    if (uncachedPrimaryKeys == null) {
1293                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1294                                    }
1295    
1296                                    uncachedPrimaryKeys.add(primaryKey);
1297                            }
1298                            else {
1299                                    map.put(primaryKey, passwordPolicyRel);
1300                            }
1301                    }
1302    
1303                    if (uncachedPrimaryKeys == null) {
1304                            return map;
1305                    }
1306    
1307                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1308                                    1);
1309    
1310                    query.append(_SQL_SELECT_PASSWORDPOLICYREL_WHERE_PKS_IN);
1311    
1312                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1313                            query.append(String.valueOf(primaryKey));
1314    
1315                            query.append(StringPool.COMMA);
1316                    }
1317    
1318                    query.setIndex(query.index() - 1);
1319    
1320                    query.append(StringPool.CLOSE_PARENTHESIS);
1321    
1322                    String sql = query.toString();
1323    
1324                    Session session = null;
1325    
1326                    try {
1327                            session = openSession();
1328    
1329                            Query q = session.createQuery(sql);
1330    
1331                            for (PasswordPolicyRel passwordPolicyRel : (List<PasswordPolicyRel>)q.list()) {
1332                                    map.put(passwordPolicyRel.getPrimaryKeyObj(), passwordPolicyRel);
1333    
1334                                    cacheResult(passwordPolicyRel);
1335    
1336                                    uncachedPrimaryKeys.remove(passwordPolicyRel.getPrimaryKeyObj());
1337                            }
1338    
1339                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1340                                    entityCache.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1341                                            PasswordPolicyRelImpl.class, primaryKey,
1342                                            _nullPasswordPolicyRel);
1343                            }
1344                    }
1345                    catch (Exception e) {
1346                            throw processException(e);
1347                    }
1348                    finally {
1349                            closeSession(session);
1350                    }
1351    
1352                    return map;
1353            }
1354    
1355            /**
1356             * Returns all the password policy rels.
1357             *
1358             * @return the password policy rels
1359             */
1360            @Override
1361            public List<PasswordPolicyRel> findAll() {
1362                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1363            }
1364    
1365            /**
1366             * Returns a range of all the password policy rels.
1367             *
1368             * <p>
1369             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link PasswordPolicyRelModelImpl}. 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.
1370             * </p>
1371             *
1372             * @param start the lower bound of the range of password policy rels
1373             * @param end the upper bound of the range of password policy rels (not inclusive)
1374             * @return the range of password policy rels
1375             */
1376            @Override
1377            public List<PasswordPolicyRel> findAll(int start, int end) {
1378                    return findAll(start, end, null);
1379            }
1380    
1381            /**
1382             * Returns an ordered range of all the password policy rels.
1383             *
1384             * <p>
1385             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link PasswordPolicyRelModelImpl}. 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.
1386             * </p>
1387             *
1388             * @param start the lower bound of the range of password policy rels
1389             * @param end the upper bound of the range of password policy rels (not inclusive)
1390             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1391             * @return the ordered range of password policy rels
1392             */
1393            @Override
1394            public List<PasswordPolicyRel> findAll(int start, int end,
1395                    OrderByComparator<PasswordPolicyRel> orderByComparator) {
1396                    return findAll(start, end, orderByComparator, true);
1397            }
1398    
1399            /**
1400             * Returns an ordered range of all the password policy rels.
1401             *
1402             * <p>
1403             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link PasswordPolicyRelModelImpl}. 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.
1404             * </p>
1405             *
1406             * @param start the lower bound of the range of password policy rels
1407             * @param end the upper bound of the range of password policy rels (not inclusive)
1408             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1409             * @param retrieveFromCache whether to retrieve from the finder cache
1410             * @return the ordered range of password policy rels
1411             */
1412            @Override
1413            public List<PasswordPolicyRel> findAll(int start, int end,
1414                    OrderByComparator<PasswordPolicyRel> orderByComparator,
1415                    boolean retrieveFromCache) {
1416                    boolean pagination = true;
1417                    FinderPath finderPath = null;
1418                    Object[] finderArgs = null;
1419    
1420                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1421                                    (orderByComparator == null)) {
1422                            pagination = false;
1423                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1424                            finderArgs = FINDER_ARGS_EMPTY;
1425                    }
1426                    else {
1427                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1428                            finderArgs = new Object[] { start, end, orderByComparator };
1429                    }
1430    
1431                    List<PasswordPolicyRel> list = null;
1432    
1433                    if (retrieveFromCache) {
1434                            list = (List<PasswordPolicyRel>)finderCache.getResult(finderPath,
1435                                            finderArgs, this);
1436                    }
1437    
1438                    if (list == null) {
1439                            StringBundler query = null;
1440                            String sql = null;
1441    
1442                            if (orderByComparator != null) {
1443                                    query = new StringBundler(2 +
1444                                                    (orderByComparator.getOrderByFields().length * 3));
1445    
1446                                    query.append(_SQL_SELECT_PASSWORDPOLICYREL);
1447    
1448                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1449                                            orderByComparator);
1450    
1451                                    sql = query.toString();
1452                            }
1453                            else {
1454                                    sql = _SQL_SELECT_PASSWORDPOLICYREL;
1455    
1456                                    if (pagination) {
1457                                            sql = sql.concat(PasswordPolicyRelModelImpl.ORDER_BY_JPQL);
1458                                    }
1459                            }
1460    
1461                            Session session = null;
1462    
1463                            try {
1464                                    session = openSession();
1465    
1466                                    Query q = session.createQuery(sql);
1467    
1468                                    if (!pagination) {
1469                                            list = (List<PasswordPolicyRel>)QueryUtil.list(q,
1470                                                            getDialect(), start, end, false);
1471    
1472                                            Collections.sort(list);
1473    
1474                                            list = Collections.unmodifiableList(list);
1475                                    }
1476                                    else {
1477                                            list = (List<PasswordPolicyRel>)QueryUtil.list(q,
1478                                                            getDialect(), start, end);
1479                                    }
1480    
1481                                    cacheResult(list);
1482    
1483                                    finderCache.putResult(finderPath, finderArgs, list);
1484                            }
1485                            catch (Exception e) {
1486                                    finderCache.removeResult(finderPath, finderArgs);
1487    
1488                                    throw processException(e);
1489                            }
1490                            finally {
1491                                    closeSession(session);
1492                            }
1493                    }
1494    
1495                    return list;
1496            }
1497    
1498            /**
1499             * Removes all the password policy rels from the database.
1500             *
1501             */
1502            @Override
1503            public void removeAll() {
1504                    for (PasswordPolicyRel passwordPolicyRel : findAll()) {
1505                            remove(passwordPolicyRel);
1506                    }
1507            }
1508    
1509            /**
1510             * Returns the number of password policy rels.
1511             *
1512             * @return the number of password policy rels
1513             */
1514            @Override
1515            public int countAll() {
1516                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1517                                    FINDER_ARGS_EMPTY, this);
1518    
1519                    if (count == null) {
1520                            Session session = null;
1521    
1522                            try {
1523                                    session = openSession();
1524    
1525                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDPOLICYREL);
1526    
1527                                    count = (Long)q.uniqueResult();
1528    
1529                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1530                                            count);
1531                            }
1532                            catch (Exception e) {
1533                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1534                                            FINDER_ARGS_EMPTY);
1535    
1536                                    throw processException(e);
1537                            }
1538                            finally {
1539                                    closeSession(session);
1540                            }
1541                    }
1542    
1543                    return count.intValue();
1544            }
1545    
1546            @Override
1547            protected Map<String, Integer> getTableColumnsMap() {
1548                    return PasswordPolicyRelModelImpl.TABLE_COLUMNS_MAP;
1549            }
1550    
1551            /**
1552             * Initializes the password policy rel persistence.
1553             */
1554            public void afterPropertiesSet() {
1555            }
1556    
1557            public void destroy() {
1558                    entityCache.removeCache(PasswordPolicyRelImpl.class.getName());
1559                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1560                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1561                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1562            }
1563    
1564            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1565            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1566            private static final String _SQL_SELECT_PASSWORDPOLICYREL = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel";
1567            private static final String _SQL_SELECT_PASSWORDPOLICYREL_WHERE_PKS_IN = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel WHERE passwordPolicyRelId IN (";
1568            private static final String _SQL_SELECT_PASSWORDPOLICYREL_WHERE = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel WHERE ";
1569            private static final String _SQL_COUNT_PASSWORDPOLICYREL = "SELECT COUNT(passwordPolicyRel) FROM PasswordPolicyRel passwordPolicyRel";
1570            private static final String _SQL_COUNT_PASSWORDPOLICYREL_WHERE = "SELECT COUNT(passwordPolicyRel) FROM PasswordPolicyRel passwordPolicyRel WHERE ";
1571            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordPolicyRel.";
1572            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordPolicyRel exists with the primary key ";
1573            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordPolicyRel exists with the key {";
1574            private static final Log _log = LogFactoryUtil.getLog(PasswordPolicyRelPersistenceImpl.class);
1575            private static final PasswordPolicyRel _nullPasswordPolicyRel = new PasswordPolicyRelImpl() {
1576                            @Override
1577                            public Object clone() {
1578                                    return this;
1579                            }
1580    
1581                            @Override
1582                            public CacheModel<PasswordPolicyRel> toCacheModel() {
1583                                    return _nullPasswordPolicyRelCacheModel;
1584                            }
1585                    };
1586    
1587            private static final CacheModel<PasswordPolicyRel> _nullPasswordPolicyRelCacheModel =
1588                    new NullCacheModel();
1589    
1590            private static class NullCacheModel implements CacheModel<PasswordPolicyRel>,
1591                    MVCCModel {
1592                    @Override
1593                    public long getMvccVersion() {
1594                            return -1;
1595                    }
1596    
1597                    @Override
1598                    public void setMvccVersion(long mvccVersion) {
1599                    }
1600    
1601                    @Override
1602                    public PasswordPolicyRel toEntityModel() {
1603                            return _nullPasswordPolicyRel;
1604                    }
1605            }
1606    }