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