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