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.setCompanyId(passwordPolicyRel.getCompanyId());
1161                    passwordPolicyRelImpl.setPasswordPolicyId(passwordPolicyRel.getPasswordPolicyId());
1162                    passwordPolicyRelImpl.setClassNameId(passwordPolicyRel.getClassNameId());
1163                    passwordPolicyRelImpl.setClassPK(passwordPolicyRel.getClassPK());
1164    
1165                    return passwordPolicyRelImpl;
1166            }
1167    
1168            /**
1169             * Returns the password policy rel with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1170             *
1171             * @param primaryKey the primary key of the password policy rel
1172             * @return the password policy rel
1173             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1174             */
1175            @Override
1176            public PasswordPolicyRel findByPrimaryKey(Serializable primaryKey)
1177                    throws NoSuchPasswordPolicyRelException {
1178                    PasswordPolicyRel passwordPolicyRel = fetchByPrimaryKey(primaryKey);
1179    
1180                    if (passwordPolicyRel == null) {
1181                            if (_log.isWarnEnabled()) {
1182                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1183                            }
1184    
1185                            throw new NoSuchPasswordPolicyRelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1186                                    primaryKey);
1187                    }
1188    
1189                    return passwordPolicyRel;
1190            }
1191    
1192            /**
1193             * Returns the password policy rel with the primary key or throws a {@link NoSuchPasswordPolicyRelException} if it could not be found.
1194             *
1195             * @param passwordPolicyRelId the primary key of the password policy rel
1196             * @return the password policy rel
1197             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1198             */
1199            @Override
1200            public PasswordPolicyRel findByPrimaryKey(long passwordPolicyRelId)
1201                    throws NoSuchPasswordPolicyRelException {
1202                    return findByPrimaryKey((Serializable)passwordPolicyRelId);
1203            }
1204    
1205            /**
1206             * Returns the password policy rel with the primary key or returns <code>null</code> if it could not be found.
1207             *
1208             * @param primaryKey the primary key of the password policy rel
1209             * @return the password policy rel, or <code>null</code> if a password policy rel with the primary key could not be found
1210             */
1211            @Override
1212            public PasswordPolicyRel fetchByPrimaryKey(Serializable primaryKey) {
1213                    PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)entityCache.getResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1214                                    PasswordPolicyRelImpl.class, primaryKey);
1215    
1216                    if (passwordPolicyRel == _nullPasswordPolicyRel) {
1217                            return null;
1218                    }
1219    
1220                    if (passwordPolicyRel == null) {
1221                            Session session = null;
1222    
1223                            try {
1224                                    session = openSession();
1225    
1226                                    passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
1227                                                    primaryKey);
1228    
1229                                    if (passwordPolicyRel != null) {
1230                                            cacheResult(passwordPolicyRel);
1231                                    }
1232                                    else {
1233                                            entityCache.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1234                                                    PasswordPolicyRelImpl.class, primaryKey,
1235                                                    _nullPasswordPolicyRel);
1236                                    }
1237                            }
1238                            catch (Exception e) {
1239                                    entityCache.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1240                                            PasswordPolicyRelImpl.class, primaryKey);
1241    
1242                                    throw processException(e);
1243                            }
1244                            finally {
1245                                    closeSession(session);
1246                            }
1247                    }
1248    
1249                    return passwordPolicyRel;
1250            }
1251    
1252            /**
1253             * Returns the password policy rel with the primary key or returns <code>null</code> if it could not be found.
1254             *
1255             * @param passwordPolicyRelId the primary key of the password policy rel
1256             * @return the password policy rel, or <code>null</code> if a password policy rel with the primary key could not be found
1257             */
1258            @Override
1259            public PasswordPolicyRel fetchByPrimaryKey(long passwordPolicyRelId) {
1260                    return fetchByPrimaryKey((Serializable)passwordPolicyRelId);
1261            }
1262    
1263            @Override
1264            public Map<Serializable, PasswordPolicyRel> fetchByPrimaryKeys(
1265                    Set<Serializable> primaryKeys) {
1266                    if (primaryKeys.isEmpty()) {
1267                            return Collections.emptyMap();
1268                    }
1269    
1270                    Map<Serializable, PasswordPolicyRel> map = new HashMap<Serializable, PasswordPolicyRel>();
1271    
1272                    if (primaryKeys.size() == 1) {
1273                            Iterator<Serializable> iterator = primaryKeys.iterator();
1274    
1275                            Serializable primaryKey = iterator.next();
1276    
1277                            PasswordPolicyRel passwordPolicyRel = fetchByPrimaryKey(primaryKey);
1278    
1279                            if (passwordPolicyRel != null) {
1280                                    map.put(primaryKey, passwordPolicyRel);
1281                            }
1282    
1283                            return map;
1284                    }
1285    
1286                    Set<Serializable> uncachedPrimaryKeys = null;
1287    
1288                    for (Serializable primaryKey : primaryKeys) {
1289                            PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)entityCache.getResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1290                                            PasswordPolicyRelImpl.class, primaryKey);
1291    
1292                            if (passwordPolicyRel == null) {
1293                                    if (uncachedPrimaryKeys == null) {
1294                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1295                                    }
1296    
1297                                    uncachedPrimaryKeys.add(primaryKey);
1298                            }
1299                            else {
1300                                    map.put(primaryKey, passwordPolicyRel);
1301                            }
1302                    }
1303    
1304                    if (uncachedPrimaryKeys == null) {
1305                            return map;
1306                    }
1307    
1308                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1309                                    1);
1310    
1311                    query.append(_SQL_SELECT_PASSWORDPOLICYREL_WHERE_PKS_IN);
1312    
1313                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1314                            query.append(String.valueOf(primaryKey));
1315    
1316                            query.append(StringPool.COMMA);
1317                    }
1318    
1319                    query.setIndex(query.index() - 1);
1320    
1321                    query.append(StringPool.CLOSE_PARENTHESIS);
1322    
1323                    String sql = query.toString();
1324    
1325                    Session session = null;
1326    
1327                    try {
1328                            session = openSession();
1329    
1330                            Query q = session.createQuery(sql);
1331    
1332                            for (PasswordPolicyRel passwordPolicyRel : (List<PasswordPolicyRel>)q.list()) {
1333                                    map.put(passwordPolicyRel.getPrimaryKeyObj(), passwordPolicyRel);
1334    
1335                                    cacheResult(passwordPolicyRel);
1336    
1337                                    uncachedPrimaryKeys.remove(passwordPolicyRel.getPrimaryKeyObj());
1338                            }
1339    
1340                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1341                                    entityCache.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1342                                            PasswordPolicyRelImpl.class, primaryKey,
1343                                            _nullPasswordPolicyRel);
1344                            }
1345                    }
1346                    catch (Exception e) {
1347                            throw processException(e);
1348                    }
1349                    finally {
1350                            closeSession(session);
1351                    }
1352    
1353                    return map;
1354            }
1355    
1356            /**
1357             * Returns all the password policy rels.
1358             *
1359             * @return the password policy rels
1360             */
1361            @Override
1362            public List<PasswordPolicyRel> findAll() {
1363                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1364            }
1365    
1366            /**
1367             * Returns a range of all the password policy rels.
1368             *
1369             * <p>
1370             * 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.
1371             * </p>
1372             *
1373             * @param start the lower bound of the range of password policy rels
1374             * @param end the upper bound of the range of password policy rels (not inclusive)
1375             * @return the range of password policy rels
1376             */
1377            @Override
1378            public List<PasswordPolicyRel> findAll(int start, int end) {
1379                    return findAll(start, end, null);
1380            }
1381    
1382            /**
1383             * Returns an ordered range of all the password policy rels.
1384             *
1385             * <p>
1386             * 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.
1387             * </p>
1388             *
1389             * @param start the lower bound of the range of password policy rels
1390             * @param end the upper bound of the range of password policy rels (not inclusive)
1391             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1392             * @return the ordered range of password policy rels
1393             */
1394            @Override
1395            public List<PasswordPolicyRel> findAll(int start, int end,
1396                    OrderByComparator<PasswordPolicyRel> orderByComparator) {
1397                    return findAll(start, end, orderByComparator, true);
1398            }
1399    
1400            /**
1401             * Returns an ordered range of all the password policy rels.
1402             *
1403             * <p>
1404             * 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.
1405             * </p>
1406             *
1407             * @param start the lower bound of the range of password policy rels
1408             * @param end the upper bound of the range of password policy rels (not inclusive)
1409             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1410             * @param retrieveFromCache whether to retrieve from the finder cache
1411             * @return the ordered range of password policy rels
1412             */
1413            @Override
1414            public List<PasswordPolicyRel> findAll(int start, int end,
1415                    OrderByComparator<PasswordPolicyRel> orderByComparator,
1416                    boolean retrieveFromCache) {
1417                    boolean pagination = true;
1418                    FinderPath finderPath = null;
1419                    Object[] finderArgs = null;
1420    
1421                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1422                                    (orderByComparator == null)) {
1423                            pagination = false;
1424                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1425                            finderArgs = FINDER_ARGS_EMPTY;
1426                    }
1427                    else {
1428                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1429                            finderArgs = new Object[] { start, end, orderByComparator };
1430                    }
1431    
1432                    List<PasswordPolicyRel> list = null;
1433    
1434                    if (retrieveFromCache) {
1435                            list = (List<PasswordPolicyRel>)finderCache.getResult(finderPath,
1436                                            finderArgs, this);
1437                    }
1438    
1439                    if (list == null) {
1440                            StringBundler query = null;
1441                            String sql = null;
1442    
1443                            if (orderByComparator != null) {
1444                                    query = new StringBundler(2 +
1445                                                    (orderByComparator.getOrderByFields().length * 3));
1446    
1447                                    query.append(_SQL_SELECT_PASSWORDPOLICYREL);
1448    
1449                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1450                                            orderByComparator);
1451    
1452                                    sql = query.toString();
1453                            }
1454                            else {
1455                                    sql = _SQL_SELECT_PASSWORDPOLICYREL;
1456    
1457                                    if (pagination) {
1458                                            sql = sql.concat(PasswordPolicyRelModelImpl.ORDER_BY_JPQL);
1459                                    }
1460                            }
1461    
1462                            Session session = null;
1463    
1464                            try {
1465                                    session = openSession();
1466    
1467                                    Query q = session.createQuery(sql);
1468    
1469                                    if (!pagination) {
1470                                            list = (List<PasswordPolicyRel>)QueryUtil.list(q,
1471                                                            getDialect(), start, end, false);
1472    
1473                                            Collections.sort(list);
1474    
1475                                            list = Collections.unmodifiableList(list);
1476                                    }
1477                                    else {
1478                                            list = (List<PasswordPolicyRel>)QueryUtil.list(q,
1479                                                            getDialect(), start, end);
1480                                    }
1481    
1482                                    cacheResult(list);
1483    
1484                                    finderCache.putResult(finderPath, finderArgs, list);
1485                            }
1486                            catch (Exception e) {
1487                                    finderCache.removeResult(finderPath, finderArgs);
1488    
1489                                    throw processException(e);
1490                            }
1491                            finally {
1492                                    closeSession(session);
1493                            }
1494                    }
1495    
1496                    return list;
1497            }
1498    
1499            /**
1500             * Removes all the password policy rels from the database.
1501             *
1502             */
1503            @Override
1504            public void removeAll() {
1505                    for (PasswordPolicyRel passwordPolicyRel : findAll()) {
1506                            remove(passwordPolicyRel);
1507                    }
1508            }
1509    
1510            /**
1511             * Returns the number of password policy rels.
1512             *
1513             * @return the number of password policy rels
1514             */
1515            @Override
1516            public int countAll() {
1517                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1518                                    FINDER_ARGS_EMPTY, this);
1519    
1520                    if (count == null) {
1521                            Session session = null;
1522    
1523                            try {
1524                                    session = openSession();
1525    
1526                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDPOLICYREL);
1527    
1528                                    count = (Long)q.uniqueResult();
1529    
1530                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1531                                            count);
1532                            }
1533                            catch (Exception e) {
1534                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1535                                            FINDER_ARGS_EMPTY);
1536    
1537                                    throw processException(e);
1538                            }
1539                            finally {
1540                                    closeSession(session);
1541                            }
1542                    }
1543    
1544                    return count.intValue();
1545            }
1546    
1547            @Override
1548            protected Map<String, Integer> getTableColumnsMap() {
1549                    return PasswordPolicyRelModelImpl.TABLE_COLUMNS_MAP;
1550            }
1551    
1552            /**
1553             * Initializes the password policy rel persistence.
1554             */
1555            public void afterPropertiesSet() {
1556            }
1557    
1558            public void destroy() {
1559                    entityCache.removeCache(PasswordPolicyRelImpl.class.getName());
1560                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1561                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1562                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1563            }
1564    
1565            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1566            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1567            private static final String _SQL_SELECT_PASSWORDPOLICYREL = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel";
1568            private static final String _SQL_SELECT_PASSWORDPOLICYREL_WHERE_PKS_IN = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel WHERE passwordPolicyRelId IN (";
1569            private static final String _SQL_SELECT_PASSWORDPOLICYREL_WHERE = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel WHERE ";
1570            private static final String _SQL_COUNT_PASSWORDPOLICYREL = "SELECT COUNT(passwordPolicyRel) FROM PasswordPolicyRel passwordPolicyRel";
1571            private static final String _SQL_COUNT_PASSWORDPOLICYREL_WHERE = "SELECT COUNT(passwordPolicyRel) FROM PasswordPolicyRel passwordPolicyRel WHERE ";
1572            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordPolicyRel.";
1573            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordPolicyRel exists with the primary key ";
1574            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordPolicyRel exists with the key {";
1575            private static final Log _log = LogFactoryUtil.getLog(PasswordPolicyRelPersistenceImpl.class);
1576            private static final PasswordPolicyRel _nullPasswordPolicyRel = new PasswordPolicyRelImpl() {
1577                            @Override
1578                            public Object clone() {
1579                                    return this;
1580                            }
1581    
1582                            @Override
1583                            public CacheModel<PasswordPolicyRel> toCacheModel() {
1584                                    return _nullPasswordPolicyRelCacheModel;
1585                            }
1586                    };
1587    
1588            private static final CacheModel<PasswordPolicyRel> _nullPasswordPolicyRelCacheModel =
1589                    new NullCacheModel();
1590    
1591            private static class NullCacheModel implements CacheModel<PasswordPolicyRel>,
1592                    MVCCModel {
1593                    @Override
1594                    public long getMvccVersion() {
1595                            return -1;
1596                    }
1597    
1598                    @Override
1599                    public void setMvccVersion(long mvccVersion) {
1600                    }
1601    
1602                    @Override
1603                    public PasswordPolicyRel toEntityModel() {
1604                            return _nullPasswordPolicyRel;
1605                    }
1606            }
1607    }