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