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            public PasswordPolicyRelPersistenceImpl() {
826                    setModelClass(PasswordPolicyRel.class);
827            }
828    
829            /**
830             * Caches the password policy rel in the entity cache if it is enabled.
831             *
832             * @param passwordPolicyRel the password policy rel
833             */
834            @Override
835            public void cacheResult(PasswordPolicyRel passwordPolicyRel) {
836                    EntityCacheUtil.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
837                            PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey(),
838                            passwordPolicyRel);
839    
840                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
841                            new Object[] {
842                                    passwordPolicyRel.getClassNameId(),
843                                    passwordPolicyRel.getClassPK()
844                            }, passwordPolicyRel);
845    
846                    passwordPolicyRel.resetOriginalValues();
847            }
848    
849            /**
850             * Caches the password policy rels in the entity cache if it is enabled.
851             *
852             * @param passwordPolicyRels the password policy rels
853             */
854            @Override
855            public void cacheResult(List<PasswordPolicyRel> passwordPolicyRels) {
856                    for (PasswordPolicyRel passwordPolicyRel : passwordPolicyRels) {
857                            if (EntityCacheUtil.getResult(
858                                                    PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
859                                                    PasswordPolicyRelImpl.class,
860                                                    passwordPolicyRel.getPrimaryKey()) == null) {
861                                    cacheResult(passwordPolicyRel);
862                            }
863                            else {
864                                    passwordPolicyRel.resetOriginalValues();
865                            }
866                    }
867            }
868    
869            /**
870             * Clears the cache for all password policy rels.
871             *
872             * <p>
873             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
874             * </p>
875             */
876            @Override
877            public void clearCache() {
878                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
879                            CacheRegistryUtil.clear(PasswordPolicyRelImpl.class.getName());
880                    }
881    
882                    EntityCacheUtil.clearCache(PasswordPolicyRelImpl.class.getName());
883    
884                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
885                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
886                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
887            }
888    
889            /**
890             * Clears the cache for the password policy rel.
891             *
892             * <p>
893             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
894             * </p>
895             */
896            @Override
897            public void clearCache(PasswordPolicyRel passwordPolicyRel) {
898                    EntityCacheUtil.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
899                            PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey());
900    
901                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
902                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
903    
904                    clearUniqueFindersCache(passwordPolicyRel);
905            }
906    
907            @Override
908            public void clearCache(List<PasswordPolicyRel> passwordPolicyRels) {
909                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
910                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
911    
912                    for (PasswordPolicyRel passwordPolicyRel : passwordPolicyRels) {
913                            EntityCacheUtil.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
914                                    PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey());
915    
916                            clearUniqueFindersCache(passwordPolicyRel);
917                    }
918            }
919    
920            protected void cacheUniqueFindersCache(PasswordPolicyRel passwordPolicyRel) {
921                    if (passwordPolicyRel.isNew()) {
922                            Object[] args = new Object[] {
923                                            passwordPolicyRel.getClassNameId(),
924                                            passwordPolicyRel.getClassPK()
925                                    };
926    
927                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
928                                    Long.valueOf(1));
929                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
930                                    passwordPolicyRel);
931                    }
932                    else {
933                            PasswordPolicyRelModelImpl passwordPolicyRelModelImpl = (PasswordPolicyRelModelImpl)passwordPolicyRel;
934    
935                            if ((passwordPolicyRelModelImpl.getColumnBitmask() &
936                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
937                                    Object[] args = new Object[] {
938                                                    passwordPolicyRel.getClassNameId(),
939                                                    passwordPolicyRel.getClassPK()
940                                            };
941    
942                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
943                                            Long.valueOf(1));
944                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
945                                            passwordPolicyRel);
946                            }
947                    }
948            }
949    
950            protected void clearUniqueFindersCache(PasswordPolicyRel passwordPolicyRel) {
951                    PasswordPolicyRelModelImpl passwordPolicyRelModelImpl = (PasswordPolicyRelModelImpl)passwordPolicyRel;
952    
953                    Object[] args = new Object[] {
954                                    passwordPolicyRel.getClassNameId(),
955                                    passwordPolicyRel.getClassPK()
956                            };
957    
958                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
959                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
960    
961                    if ((passwordPolicyRelModelImpl.getColumnBitmask() &
962                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
963                            args = new Object[] {
964                                            passwordPolicyRelModelImpl.getOriginalClassNameId(),
965                                            passwordPolicyRelModelImpl.getOriginalClassPK()
966                                    };
967    
968                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
969                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
970                    }
971            }
972    
973            /**
974             * Creates a new password policy rel with the primary key. Does not add the password policy rel to the database.
975             *
976             * @param passwordPolicyRelId the primary key for the new password policy rel
977             * @return the new password policy rel
978             */
979            @Override
980            public PasswordPolicyRel create(long passwordPolicyRelId) {
981                    PasswordPolicyRel passwordPolicyRel = new PasswordPolicyRelImpl();
982    
983                    passwordPolicyRel.setNew(true);
984                    passwordPolicyRel.setPrimaryKey(passwordPolicyRelId);
985    
986                    return passwordPolicyRel;
987            }
988    
989            /**
990             * Removes the password policy rel with the primary key from the database. Also notifies the appropriate model listeners.
991             *
992             * @param passwordPolicyRelId the primary key of the password policy rel
993             * @return the password policy rel that was removed
994             * @throws com.liferay.portal.NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
995             * @throws SystemException if a system exception occurred
996             */
997            @Override
998            public PasswordPolicyRel remove(long passwordPolicyRelId)
999                    throws NoSuchPasswordPolicyRelException, SystemException {
1000                    return remove((Serializable)passwordPolicyRelId);
1001            }
1002    
1003            /**
1004             * Removes the password policy rel with the primary key from the database. Also notifies the appropriate model listeners.
1005             *
1006             * @param primaryKey the primary key of the password policy rel
1007             * @return the password policy rel that was removed
1008             * @throws com.liferay.portal.NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1009             * @throws SystemException if a system exception occurred
1010             */
1011            @Override
1012            public PasswordPolicyRel remove(Serializable primaryKey)
1013                    throws NoSuchPasswordPolicyRelException, SystemException {
1014                    Session session = null;
1015    
1016                    try {
1017                            session = openSession();
1018    
1019                            PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
1020                                            primaryKey);
1021    
1022                            if (passwordPolicyRel == null) {
1023                                    if (_log.isWarnEnabled()) {
1024                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1025                                    }
1026    
1027                                    throw new NoSuchPasswordPolicyRelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1028                                            primaryKey);
1029                            }
1030    
1031                            return remove(passwordPolicyRel);
1032                    }
1033                    catch (NoSuchPasswordPolicyRelException nsee) {
1034                            throw nsee;
1035                    }
1036                    catch (Exception e) {
1037                            throw processException(e);
1038                    }
1039                    finally {
1040                            closeSession(session);
1041                    }
1042            }
1043    
1044            @Override
1045            protected PasswordPolicyRel removeImpl(PasswordPolicyRel passwordPolicyRel)
1046                    throws SystemException {
1047                    passwordPolicyRel = toUnwrappedModel(passwordPolicyRel);
1048    
1049                    Session session = null;
1050    
1051                    try {
1052                            session = openSession();
1053    
1054                            if (!session.contains(passwordPolicyRel)) {
1055                                    passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
1056                                                    passwordPolicyRel.getPrimaryKeyObj());
1057                            }
1058    
1059                            if (passwordPolicyRel != null) {
1060                                    session.delete(passwordPolicyRel);
1061                            }
1062                    }
1063                    catch (Exception e) {
1064                            throw processException(e);
1065                    }
1066                    finally {
1067                            closeSession(session);
1068                    }
1069    
1070                    if (passwordPolicyRel != null) {
1071                            clearCache(passwordPolicyRel);
1072                    }
1073    
1074                    return passwordPolicyRel;
1075            }
1076    
1077            @Override
1078            public PasswordPolicyRel updateImpl(
1079                    com.liferay.portal.model.PasswordPolicyRel passwordPolicyRel)
1080                    throws SystemException {
1081                    passwordPolicyRel = toUnwrappedModel(passwordPolicyRel);
1082    
1083                    boolean isNew = passwordPolicyRel.isNew();
1084    
1085                    PasswordPolicyRelModelImpl passwordPolicyRelModelImpl = (PasswordPolicyRelModelImpl)passwordPolicyRel;
1086    
1087                    Session session = null;
1088    
1089                    try {
1090                            session = openSession();
1091    
1092                            if (passwordPolicyRel.isNew()) {
1093                                    session.save(passwordPolicyRel);
1094    
1095                                    passwordPolicyRel.setNew(false);
1096                            }
1097                            else {
1098                                    session.merge(passwordPolicyRel);
1099                            }
1100                    }
1101                    catch (Exception e) {
1102                            throw processException(e);
1103                    }
1104                    finally {
1105                            closeSession(session);
1106                    }
1107    
1108                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1109    
1110                    if (isNew || !PasswordPolicyRelModelImpl.COLUMN_BITMASK_ENABLED) {
1111                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1112                    }
1113    
1114                    else {
1115                            if ((passwordPolicyRelModelImpl.getColumnBitmask() &
1116                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID.getColumnBitmask()) != 0) {
1117                                    Object[] args = new Object[] {
1118                                                    passwordPolicyRelModelImpl.getOriginalPasswordPolicyId()
1119                                            };
1120    
1121                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PASSWORDPOLICYID,
1122                                            args);
1123                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID,
1124                                            args);
1125    
1126                                    args = new Object[] {
1127                                                    passwordPolicyRelModelImpl.getPasswordPolicyId()
1128                                            };
1129    
1130                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PASSWORDPOLICYID,
1131                                            args);
1132                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID,
1133                                            args);
1134                            }
1135                    }
1136    
1137                    EntityCacheUtil.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1138                            PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey(),
1139                            passwordPolicyRel);
1140    
1141                    clearUniqueFindersCache(passwordPolicyRel);
1142                    cacheUniqueFindersCache(passwordPolicyRel);
1143    
1144                    return passwordPolicyRel;
1145            }
1146    
1147            protected PasswordPolicyRel toUnwrappedModel(
1148                    PasswordPolicyRel passwordPolicyRel) {
1149                    if (passwordPolicyRel instanceof PasswordPolicyRelImpl) {
1150                            return passwordPolicyRel;
1151                    }
1152    
1153                    PasswordPolicyRelImpl passwordPolicyRelImpl = new PasswordPolicyRelImpl();
1154    
1155                    passwordPolicyRelImpl.setNew(passwordPolicyRel.isNew());
1156                    passwordPolicyRelImpl.setPrimaryKey(passwordPolicyRel.getPrimaryKey());
1157    
1158                    passwordPolicyRelImpl.setPasswordPolicyRelId(passwordPolicyRel.getPasswordPolicyRelId());
1159                    passwordPolicyRelImpl.setPasswordPolicyId(passwordPolicyRel.getPasswordPolicyId());
1160                    passwordPolicyRelImpl.setClassNameId(passwordPolicyRel.getClassNameId());
1161                    passwordPolicyRelImpl.setClassPK(passwordPolicyRel.getClassPK());
1162    
1163                    return passwordPolicyRelImpl;
1164            }
1165    
1166            /**
1167             * Returns the password policy rel with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1168             *
1169             * @param primaryKey the primary key of the password policy rel
1170             * @return the password policy rel
1171             * @throws com.liferay.portal.NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1172             * @throws SystemException if a system exception occurred
1173             */
1174            @Override
1175            public PasswordPolicyRel findByPrimaryKey(Serializable primaryKey)
1176                    throws NoSuchPasswordPolicyRelException, SystemException {
1177                    PasswordPolicyRel passwordPolicyRel = fetchByPrimaryKey(primaryKey);
1178    
1179                    if (passwordPolicyRel == null) {
1180                            if (_log.isWarnEnabled()) {
1181                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1182                            }
1183    
1184                            throw new NoSuchPasswordPolicyRelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1185                                    primaryKey);
1186                    }
1187    
1188                    return passwordPolicyRel;
1189            }
1190    
1191            /**
1192             * Returns the password policy rel with the primary key or throws a {@link com.liferay.portal.NoSuchPasswordPolicyRelException} if it could not be found.
1193             *
1194             * @param passwordPolicyRelId the primary key of the password policy rel
1195             * @return the password policy rel
1196             * @throws com.liferay.portal.NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1197             * @throws SystemException if a system exception occurred
1198             */
1199            @Override
1200            public PasswordPolicyRel findByPrimaryKey(long passwordPolicyRelId)
1201                    throws NoSuchPasswordPolicyRelException, SystemException {
1202                    return findByPrimaryKey((Serializable)passwordPolicyRelId);
1203            }
1204    
1205            /**
1206             * Returns the password policy rel with the primary key or returns <code>null</code> if it could not be found.
1207             *
1208             * @param primaryKey the primary key of the password policy rel
1209             * @return the password policy rel, or <code>null</code> if a password policy rel with the primary key could not be found
1210             * @throws SystemException if a system exception occurred
1211             */
1212            @Override
1213            public PasswordPolicyRel fetchByPrimaryKey(Serializable primaryKey)
1214                    throws SystemException {
1215                    PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)EntityCacheUtil.getResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1216                                    PasswordPolicyRelImpl.class, primaryKey);
1217    
1218                    if (passwordPolicyRel == _nullPasswordPolicyRel) {
1219                            return null;
1220                    }
1221    
1222                    if (passwordPolicyRel == null) {
1223                            Session session = null;
1224    
1225                            try {
1226                                    session = openSession();
1227    
1228                                    passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
1229                                                    primaryKey);
1230    
1231                                    if (passwordPolicyRel != null) {
1232                                            cacheResult(passwordPolicyRel);
1233                                    }
1234                                    else {
1235                                            EntityCacheUtil.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1236                                                    PasswordPolicyRelImpl.class, primaryKey,
1237                                                    _nullPasswordPolicyRel);
1238                                    }
1239                            }
1240                            catch (Exception e) {
1241                                    EntityCacheUtil.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1242                                            PasswordPolicyRelImpl.class, primaryKey);
1243    
1244                                    throw processException(e);
1245                            }
1246                            finally {
1247                                    closeSession(session);
1248                            }
1249                    }
1250    
1251                    return passwordPolicyRel;
1252            }
1253    
1254            /**
1255             * Returns the password policy rel with the primary key or returns <code>null</code> if it could not be found.
1256             *
1257             * @param passwordPolicyRelId the primary key of the password policy rel
1258             * @return the password policy rel, or <code>null</code> if a password policy rel with the primary key could not be found
1259             * @throws SystemException if a system exception occurred
1260             */
1261            @Override
1262            public PasswordPolicyRel fetchByPrimaryKey(long passwordPolicyRelId)
1263                    throws SystemException {
1264                    return fetchByPrimaryKey((Serializable)passwordPolicyRelId);
1265            }
1266    
1267            /**
1268             * Returns all the password policy rels.
1269             *
1270             * @return the password policy rels
1271             * @throws SystemException if a system exception occurred
1272             */
1273            @Override
1274            public List<PasswordPolicyRel> findAll() throws SystemException {
1275                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1276            }
1277    
1278            /**
1279             * Returns a range of all the password policy rels.
1280             *
1281             * <p>
1282             * 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.
1283             * </p>
1284             *
1285             * @param start the lower bound of the range of password policy rels
1286             * @param end the upper bound of the range of password policy rels (not inclusive)
1287             * @return the range of password policy rels
1288             * @throws SystemException if a system exception occurred
1289             */
1290            @Override
1291            public List<PasswordPolicyRel> findAll(int start, int end)
1292                    throws SystemException {
1293                    return findAll(start, end, null);
1294            }
1295    
1296            /**
1297             * Returns an ordered range of all the password policy rels.
1298             *
1299             * <p>
1300             * 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.
1301             * </p>
1302             *
1303             * @param start the lower bound of the range of password policy rels
1304             * @param end the upper bound of the range of password policy rels (not inclusive)
1305             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1306             * @return the ordered range of password policy rels
1307             * @throws SystemException if a system exception occurred
1308             */
1309            @Override
1310            public List<PasswordPolicyRel> findAll(int start, int end,
1311                    OrderByComparator orderByComparator) throws SystemException {
1312                    boolean pagination = true;
1313                    FinderPath finderPath = null;
1314                    Object[] finderArgs = null;
1315    
1316                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1317                                    (orderByComparator == null)) {
1318                            pagination = false;
1319                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1320                            finderArgs = FINDER_ARGS_EMPTY;
1321                    }
1322                    else {
1323                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1324                            finderArgs = new Object[] { start, end, orderByComparator };
1325                    }
1326    
1327                    List<PasswordPolicyRel> list = (List<PasswordPolicyRel>)FinderCacheUtil.getResult(finderPath,
1328                                    finderArgs, this);
1329    
1330                    if (list == null) {
1331                            StringBundler query = null;
1332                            String sql = null;
1333    
1334                            if (orderByComparator != null) {
1335                                    query = new StringBundler(2 +
1336                                                    (orderByComparator.getOrderByFields().length * 3));
1337    
1338                                    query.append(_SQL_SELECT_PASSWORDPOLICYREL);
1339    
1340                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1341                                            orderByComparator);
1342    
1343                                    sql = query.toString();
1344                            }
1345                            else {
1346                                    sql = _SQL_SELECT_PASSWORDPOLICYREL;
1347    
1348                                    if (pagination) {
1349                                            sql = sql.concat(PasswordPolicyRelModelImpl.ORDER_BY_JPQL);
1350                                    }
1351                            }
1352    
1353                            Session session = null;
1354    
1355                            try {
1356                                    session = openSession();
1357    
1358                                    Query q = session.createQuery(sql);
1359    
1360                                    if (!pagination) {
1361                                            list = (List<PasswordPolicyRel>)QueryUtil.list(q,
1362                                                            getDialect(), start, end, false);
1363    
1364                                            Collections.sort(list);
1365    
1366                                            list = new UnmodifiableList<PasswordPolicyRel>(list);
1367                                    }
1368                                    else {
1369                                            list = (List<PasswordPolicyRel>)QueryUtil.list(q,
1370                                                            getDialect(), start, end);
1371                                    }
1372    
1373                                    cacheResult(list);
1374    
1375                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1376                            }
1377                            catch (Exception e) {
1378                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1379    
1380                                    throw processException(e);
1381                            }
1382                            finally {
1383                                    closeSession(session);
1384                            }
1385                    }
1386    
1387                    return list;
1388            }
1389    
1390            /**
1391             * Removes all the password policy rels from the database.
1392             *
1393             * @throws SystemException if a system exception occurred
1394             */
1395            @Override
1396            public void removeAll() throws SystemException {
1397                    for (PasswordPolicyRel passwordPolicyRel : findAll()) {
1398                            remove(passwordPolicyRel);
1399                    }
1400            }
1401    
1402            /**
1403             * Returns the number of password policy rels.
1404             *
1405             * @return the number of password policy rels
1406             * @throws SystemException if a system exception occurred
1407             */
1408            @Override
1409            public int countAll() throws SystemException {
1410                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1411                                    FINDER_ARGS_EMPTY, this);
1412    
1413                    if (count == null) {
1414                            Session session = null;
1415    
1416                            try {
1417                                    session = openSession();
1418    
1419                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDPOLICYREL);
1420    
1421                                    count = (Long)q.uniqueResult();
1422    
1423                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1424                                            FINDER_ARGS_EMPTY, count);
1425                            }
1426                            catch (Exception e) {
1427                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1428                                            FINDER_ARGS_EMPTY);
1429    
1430                                    throw processException(e);
1431                            }
1432                            finally {
1433                                    closeSession(session);
1434                            }
1435                    }
1436    
1437                    return count.intValue();
1438            }
1439    
1440            /**
1441             * Initializes the password policy rel persistence.
1442             */
1443            public void afterPropertiesSet() {
1444                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1445                                            com.liferay.portal.util.PropsUtil.get(
1446                                                    "value.object.listener.com.liferay.portal.model.PasswordPolicyRel")));
1447    
1448                    if (listenerClassNames.length > 0) {
1449                            try {
1450                                    List<ModelListener<PasswordPolicyRel>> listenersList = new ArrayList<ModelListener<PasswordPolicyRel>>();
1451    
1452                                    for (String listenerClassName : listenerClassNames) {
1453                                            listenersList.add((ModelListener<PasswordPolicyRel>)InstanceFactory.newInstance(
1454                                                            getClassLoader(), listenerClassName));
1455                                    }
1456    
1457                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1458                            }
1459                            catch (Exception e) {
1460                                    _log.error(e);
1461                            }
1462                    }
1463            }
1464    
1465            public void destroy() {
1466                    EntityCacheUtil.removeCache(PasswordPolicyRelImpl.class.getName());
1467                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1468                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1469                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1470            }
1471    
1472            private static final String _SQL_SELECT_PASSWORDPOLICYREL = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel";
1473            private static final String _SQL_SELECT_PASSWORDPOLICYREL_WHERE = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel WHERE ";
1474            private static final String _SQL_COUNT_PASSWORDPOLICYREL = "SELECT COUNT(passwordPolicyRel) FROM PasswordPolicyRel passwordPolicyRel";
1475            private static final String _SQL_COUNT_PASSWORDPOLICYREL_WHERE = "SELECT COUNT(passwordPolicyRel) FROM PasswordPolicyRel passwordPolicyRel WHERE ";
1476            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordPolicyRel.";
1477            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordPolicyRel exists with the primary key ";
1478            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordPolicyRel exists with the key {";
1479            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1480            private static Log _log = LogFactoryUtil.getLog(PasswordPolicyRelPersistenceImpl.class);
1481            private static PasswordPolicyRel _nullPasswordPolicyRel = new PasswordPolicyRelImpl() {
1482                            @Override
1483                            public Object clone() {
1484                                    return this;
1485                            }
1486    
1487                            @Override
1488                            public CacheModel<PasswordPolicyRel> toCacheModel() {
1489                                    return _nullPasswordPolicyRelCacheModel;
1490                            }
1491                    };
1492    
1493            private static CacheModel<PasswordPolicyRel> _nullPasswordPolicyRelCacheModel =
1494                    new CacheModel<PasswordPolicyRel>() {
1495                            @Override
1496                            public PasswordPolicyRel toEntityModel() {
1497                                    return _nullPasswordPolicyRel;
1498                            }
1499                    };
1500    }