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