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