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 * 2));
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(4 +
448                                            (orderByComparator.getOrderByConditionFields().length * 3) +
449                                            (orderByComparator.getOrderByFields().length * 3));
450                    }
451                    else {
452                            query = new StringBundler(3);
453                    }
454    
455                    query.append(_SQL_SELECT_PASSWORDPOLICYREL_WHERE);
456    
457                    query.append(_FINDER_COLUMN_PASSWORDPOLICYID_PASSWORDPOLICYID_2);
458    
459                    if (orderByComparator != null) {
460                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
461    
462                            if (orderByConditionFields.length > 0) {
463                                    query.append(WHERE_AND);
464                            }
465    
466                            for (int i = 0; i < orderByConditionFields.length; i++) {
467                                    query.append(_ORDER_BY_ENTITY_ALIAS);
468                                    query.append(orderByConditionFields[i]);
469    
470                                    if ((i + 1) < orderByConditionFields.length) {
471                                            if (orderByComparator.isAscending() ^ previous) {
472                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
473                                            }
474                                            else {
475                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
476                                            }
477                                    }
478                                    else {
479                                            if (orderByComparator.isAscending() ^ previous) {
480                                                    query.append(WHERE_GREATER_THAN);
481                                            }
482                                            else {
483                                                    query.append(WHERE_LESSER_THAN);
484                                            }
485                                    }
486                            }
487    
488                            query.append(ORDER_BY_CLAUSE);
489    
490                            String[] orderByFields = orderByComparator.getOrderByFields();
491    
492                            for (int i = 0; i < orderByFields.length; i++) {
493                                    query.append(_ORDER_BY_ENTITY_ALIAS);
494                                    query.append(orderByFields[i]);
495    
496                                    if ((i + 1) < orderByFields.length) {
497                                            if (orderByComparator.isAscending() ^ previous) {
498                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
499                                            }
500                                            else {
501                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
502                                            }
503                                    }
504                                    else {
505                                            if (orderByComparator.isAscending() ^ previous) {
506                                                    query.append(ORDER_BY_ASC);
507                                            }
508                                            else {
509                                                    query.append(ORDER_BY_DESC);
510                                            }
511                                    }
512                            }
513                    }
514                    else {
515                            query.append(PasswordPolicyRelModelImpl.ORDER_BY_JPQL);
516                    }
517    
518                    String sql = query.toString();
519    
520                    Query q = session.createQuery(sql);
521    
522                    q.setFirstResult(0);
523                    q.setMaxResults(2);
524    
525                    QueryPos qPos = QueryPos.getInstance(q);
526    
527                    qPos.add(passwordPolicyId);
528    
529                    if (orderByComparator != null) {
530                            Object[] values = orderByComparator.getOrderByConditionValues(passwordPolicyRel);
531    
532                            for (Object value : values) {
533                                    qPos.add(value);
534                            }
535                    }
536    
537                    List<PasswordPolicyRel> list = q.list();
538    
539                    if (list.size() == 2) {
540                            return list.get(1);
541                    }
542                    else {
543                            return null;
544                    }
545            }
546    
547            /**
548             * Removes all the password policy rels where passwordPolicyId = &#63; from the database.
549             *
550             * @param passwordPolicyId the password policy ID
551             */
552            @Override
553            public void removeByPasswordPolicyId(long passwordPolicyId) {
554                    for (PasswordPolicyRel passwordPolicyRel : findByPasswordPolicyId(
555                                    passwordPolicyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
556                            remove(passwordPolicyRel);
557                    }
558            }
559    
560            /**
561             * Returns the number of password policy rels where passwordPolicyId = &#63;.
562             *
563             * @param passwordPolicyId the password policy ID
564             * @return the number of matching password policy rels
565             */
566            @Override
567            public int countByPasswordPolicyId(long passwordPolicyId) {
568                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PASSWORDPOLICYID;
569    
570                    Object[] finderArgs = new Object[] { passwordPolicyId };
571    
572                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
573    
574                    if (count == null) {
575                            StringBundler query = new StringBundler(2);
576    
577                            query.append(_SQL_COUNT_PASSWORDPOLICYREL_WHERE);
578    
579                            query.append(_FINDER_COLUMN_PASSWORDPOLICYID_PASSWORDPOLICYID_2);
580    
581                            String sql = query.toString();
582    
583                            Session session = null;
584    
585                            try {
586                                    session = openSession();
587    
588                                    Query q = session.createQuery(sql);
589    
590                                    QueryPos qPos = QueryPos.getInstance(q);
591    
592                                    qPos.add(passwordPolicyId);
593    
594                                    count = (Long)q.uniqueResult();
595    
596                                    finderCache.putResult(finderPath, finderArgs, count);
597                            }
598                            catch (Exception e) {
599                                    finderCache.removeResult(finderPath, finderArgs);
600    
601                                    throw processException(e);
602                            }
603                            finally {
604                                    closeSession(session);
605                            }
606                    }
607    
608                    return count.intValue();
609            }
610    
611            private static final String _FINDER_COLUMN_PASSWORDPOLICYID_PASSWORDPOLICYID_2 =
612                    "passwordPolicyRel.passwordPolicyId = ?";
613            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
614                            PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED,
615                            PasswordPolicyRelImpl.class, FINDER_CLASS_NAME_ENTITY,
616                            "fetchByC_C",
617                            new String[] { Long.class.getName(), Long.class.getName() },
618                            PasswordPolicyRelModelImpl.CLASSNAMEID_COLUMN_BITMASK |
619                            PasswordPolicyRelModelImpl.CLASSPK_COLUMN_BITMASK);
620            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
621                            PasswordPolicyRelModelImpl.FINDER_CACHE_ENABLED, Long.class,
622                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
623                            new String[] { Long.class.getName(), Long.class.getName() });
624    
625            /**
626             * Returns the password policy rel where classNameId = &#63; and classPK = &#63; or throws a {@link NoSuchPasswordPolicyRelException} if it could not be found.
627             *
628             * @param classNameId the class name ID
629             * @param classPK the class p k
630             * @return the matching password policy rel
631             * @throws NoSuchPasswordPolicyRelException if a matching password policy rel could not be found
632             */
633            @Override
634            public PasswordPolicyRel findByC_C(long classNameId, long classPK)
635                    throws NoSuchPasswordPolicyRelException {
636                    PasswordPolicyRel passwordPolicyRel = fetchByC_C(classNameId, classPK);
637    
638                    if (passwordPolicyRel == null) {
639                            StringBundler msg = new StringBundler(6);
640    
641                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
642    
643                            msg.append("classNameId=");
644                            msg.append(classNameId);
645    
646                            msg.append(", classPK=");
647                            msg.append(classPK);
648    
649                            msg.append(StringPool.CLOSE_CURLY_BRACE);
650    
651                            if (_log.isWarnEnabled()) {
652                                    _log.warn(msg.toString());
653                            }
654    
655                            throw new NoSuchPasswordPolicyRelException(msg.toString());
656                    }
657    
658                    return passwordPolicyRel;
659            }
660    
661            /**
662             * 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.
663             *
664             * @param classNameId the class name ID
665             * @param classPK the class p k
666             * @return the matching password policy rel, or <code>null</code> if a matching password policy rel could not be found
667             */
668            @Override
669            public PasswordPolicyRel fetchByC_C(long classNameId, long classPK) {
670                    return fetchByC_C(classNameId, classPK, true);
671            }
672    
673            /**
674             * 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.
675             *
676             * @param classNameId the class name ID
677             * @param classPK the class p k
678             * @param retrieveFromCache whether to retrieve from the finder cache
679             * @return the matching password policy rel, or <code>null</code> if a matching password policy rel could not be found
680             */
681            @Override
682            public PasswordPolicyRel fetchByC_C(long classNameId, long classPK,
683                    boolean retrieveFromCache) {
684                    Object[] finderArgs = new Object[] { classNameId, classPK };
685    
686                    Object result = null;
687    
688                    if (retrieveFromCache) {
689                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C,
690                                            finderArgs, this);
691                    }
692    
693                    if (result instanceof PasswordPolicyRel) {
694                            PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)result;
695    
696                            if ((classNameId != passwordPolicyRel.getClassNameId()) ||
697                                            (classPK != passwordPolicyRel.getClassPK())) {
698                                    result = null;
699                            }
700                    }
701    
702                    if (result == null) {
703                            StringBundler query = new StringBundler(4);
704    
705                            query.append(_SQL_SELECT_PASSWORDPOLICYREL_WHERE);
706    
707                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
708    
709                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
710    
711                            String sql = query.toString();
712    
713                            Session session = null;
714    
715                            try {
716                                    session = openSession();
717    
718                                    Query q = session.createQuery(sql);
719    
720                                    QueryPos qPos = QueryPos.getInstance(q);
721    
722                                    qPos.add(classNameId);
723    
724                                    qPos.add(classPK);
725    
726                                    List<PasswordPolicyRel> list = q.list();
727    
728                                    if (list.isEmpty()) {
729                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, finderArgs,
730                                                    list);
731                                    }
732                                    else {
733                                            PasswordPolicyRel passwordPolicyRel = list.get(0);
734    
735                                            result = passwordPolicyRel;
736    
737                                            cacheResult(passwordPolicyRel);
738    
739                                            if ((passwordPolicyRel.getClassNameId() != classNameId) ||
740                                                            (passwordPolicyRel.getClassPK() != classPK)) {
741                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
742                                                            finderArgs, passwordPolicyRel);
743                                            }
744                                    }
745                            }
746                            catch (Exception e) {
747                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, finderArgs);
748    
749                                    throw processException(e);
750                            }
751                            finally {
752                                    closeSession(session);
753                            }
754                    }
755    
756                    if (result instanceof List<?>) {
757                            return null;
758                    }
759                    else {
760                            return (PasswordPolicyRel)result;
761                    }
762            }
763    
764            /**
765             * Removes the password policy rel where classNameId = &#63; and classPK = &#63; from the database.
766             *
767             * @param classNameId the class name ID
768             * @param classPK the class p k
769             * @return the password policy rel that was removed
770             */
771            @Override
772            public PasswordPolicyRel removeByC_C(long classNameId, long classPK)
773                    throws NoSuchPasswordPolicyRelException {
774                    PasswordPolicyRel passwordPolicyRel = findByC_C(classNameId, classPK);
775    
776                    return remove(passwordPolicyRel);
777            }
778    
779            /**
780             * Returns the number of password policy rels where classNameId = &#63; and classPK = &#63;.
781             *
782             * @param classNameId the class name ID
783             * @param classPK the class p k
784             * @return the number of matching password policy rels
785             */
786            @Override
787            public int countByC_C(long classNameId, long classPK) {
788                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
789    
790                    Object[] finderArgs = new Object[] { classNameId, classPK };
791    
792                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
793    
794                    if (count == null) {
795                            StringBundler query = new StringBundler(3);
796    
797                            query.append(_SQL_COUNT_PASSWORDPOLICYREL_WHERE);
798    
799                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
800    
801                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
802    
803                            String sql = query.toString();
804    
805                            Session session = null;
806    
807                            try {
808                                    session = openSession();
809    
810                                    Query q = session.createQuery(sql);
811    
812                                    QueryPos qPos = QueryPos.getInstance(q);
813    
814                                    qPos.add(classNameId);
815    
816                                    qPos.add(classPK);
817    
818                                    count = (Long)q.uniqueResult();
819    
820                                    finderCache.putResult(finderPath, finderArgs, count);
821                            }
822                            catch (Exception e) {
823                                    finderCache.removeResult(finderPath, finderArgs);
824    
825                                    throw processException(e);
826                            }
827                            finally {
828                                    closeSession(session);
829                            }
830                    }
831    
832                    return count.intValue();
833            }
834    
835            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "passwordPolicyRel.classNameId = ? AND ";
836            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "passwordPolicyRel.classPK = ?";
837    
838            public PasswordPolicyRelPersistenceImpl() {
839                    setModelClass(PasswordPolicyRel.class);
840            }
841    
842            /**
843             * Caches the password policy rel in the entity cache if it is enabled.
844             *
845             * @param passwordPolicyRel the password policy rel
846             */
847            @Override
848            public void cacheResult(PasswordPolicyRel passwordPolicyRel) {
849                    entityCache.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
850                            PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey(),
851                            passwordPolicyRel);
852    
853                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
854                            new Object[] {
855                                    passwordPolicyRel.getClassNameId(),
856                                    passwordPolicyRel.getClassPK()
857                            }, passwordPolicyRel);
858    
859                    passwordPolicyRel.resetOriginalValues();
860            }
861    
862            /**
863             * Caches the password policy rels in the entity cache if it is enabled.
864             *
865             * @param passwordPolicyRels the password policy rels
866             */
867            @Override
868            public void cacheResult(List<PasswordPolicyRel> passwordPolicyRels) {
869                    for (PasswordPolicyRel passwordPolicyRel : passwordPolicyRels) {
870                            if (entityCache.getResult(
871                                                    PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
872                                                    PasswordPolicyRelImpl.class,
873                                                    passwordPolicyRel.getPrimaryKey()) == null) {
874                                    cacheResult(passwordPolicyRel);
875                            }
876                            else {
877                                    passwordPolicyRel.resetOriginalValues();
878                            }
879                    }
880            }
881    
882            /**
883             * Clears the cache for all password policy rels.
884             *
885             * <p>
886             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
887             * </p>
888             */
889            @Override
890            public void clearCache() {
891                    entityCache.clearCache(PasswordPolicyRelImpl.class);
892    
893                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
894                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
895                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
896            }
897    
898            /**
899             * Clears the cache for the password policy rel.
900             *
901             * <p>
902             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
903             * </p>
904             */
905            @Override
906            public void clearCache(PasswordPolicyRel passwordPolicyRel) {
907                    entityCache.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
908                            PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey());
909    
910                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
911                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
912    
913                    clearUniqueFindersCache((PasswordPolicyRelModelImpl)passwordPolicyRel);
914            }
915    
916            @Override
917            public void clearCache(List<PasswordPolicyRel> passwordPolicyRels) {
918                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
919                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
920    
921                    for (PasswordPolicyRel passwordPolicyRel : passwordPolicyRels) {
922                            entityCache.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
923                                    PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey());
924    
925                            clearUniqueFindersCache((PasswordPolicyRelModelImpl)passwordPolicyRel);
926                    }
927            }
928    
929            protected void cacheUniqueFindersCache(
930                    PasswordPolicyRelModelImpl passwordPolicyRelModelImpl, boolean isNew) {
931                    if (isNew) {
932                            Object[] args = new Object[] {
933                                            passwordPolicyRelModelImpl.getClassNameId(),
934                                            passwordPolicyRelModelImpl.getClassPK()
935                                    };
936    
937                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
938                                    Long.valueOf(1));
939                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
940                                    passwordPolicyRelModelImpl);
941                    }
942                    else {
943                            if ((passwordPolicyRelModelImpl.getColumnBitmask() &
944                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
945                                    Object[] args = new Object[] {
946                                                    passwordPolicyRelModelImpl.getClassNameId(),
947                                                    passwordPolicyRelModelImpl.getClassPK()
948                                            };
949    
950                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
951                                            Long.valueOf(1));
952                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
953                                            passwordPolicyRelModelImpl);
954                            }
955                    }
956            }
957    
958            protected void clearUniqueFindersCache(
959                    PasswordPolicyRelModelImpl passwordPolicyRelModelImpl) {
960                    Object[] args = new Object[] {
961                                    passwordPolicyRelModelImpl.getClassNameId(),
962                                    passwordPolicyRelModelImpl.getClassPK()
963                            };
964    
965                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
966                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
967    
968                    if ((passwordPolicyRelModelImpl.getColumnBitmask() &
969                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
970                            args = new Object[] {
971                                            passwordPolicyRelModelImpl.getOriginalClassNameId(),
972                                            passwordPolicyRelModelImpl.getOriginalClassPK()
973                                    };
974    
975                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
976                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
977                    }
978            }
979    
980            /**
981             * Creates a new password policy rel with the primary key. Does not add the password policy rel to the database.
982             *
983             * @param passwordPolicyRelId the primary key for the new password policy rel
984             * @return the new password policy rel
985             */
986            @Override
987            public PasswordPolicyRel create(long passwordPolicyRelId) {
988                    PasswordPolicyRel passwordPolicyRel = new PasswordPolicyRelImpl();
989    
990                    passwordPolicyRel.setNew(true);
991                    passwordPolicyRel.setPrimaryKey(passwordPolicyRelId);
992    
993                    passwordPolicyRel.setCompanyId(companyProvider.getCompanyId());
994    
995                    return passwordPolicyRel;
996            }
997    
998            /**
999             * Removes the password policy rel with the primary key from the database. Also notifies the appropriate model listeners.
1000             *
1001             * @param passwordPolicyRelId the primary key of the password policy rel
1002             * @return the password policy rel that was removed
1003             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1004             */
1005            @Override
1006            public PasswordPolicyRel remove(long passwordPolicyRelId)
1007                    throws NoSuchPasswordPolicyRelException {
1008                    return remove((Serializable)passwordPolicyRelId);
1009            }
1010    
1011            /**
1012             * Removes the password policy rel with the primary key from the database. Also notifies the appropriate model listeners.
1013             *
1014             * @param primaryKey the primary key of the password policy rel
1015             * @return the password policy rel that was removed
1016             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1017             */
1018            @Override
1019            public PasswordPolicyRel remove(Serializable primaryKey)
1020                    throws NoSuchPasswordPolicyRelException {
1021                    Session session = null;
1022    
1023                    try {
1024                            session = openSession();
1025    
1026                            PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
1027                                            primaryKey);
1028    
1029                            if (passwordPolicyRel == null) {
1030                                    if (_log.isWarnEnabled()) {
1031                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1032                                    }
1033    
1034                                    throw new NoSuchPasswordPolicyRelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1035                                            primaryKey);
1036                            }
1037    
1038                            return remove(passwordPolicyRel);
1039                    }
1040                    catch (NoSuchPasswordPolicyRelException nsee) {
1041                            throw nsee;
1042                    }
1043                    catch (Exception e) {
1044                            throw processException(e);
1045                    }
1046                    finally {
1047                            closeSession(session);
1048                    }
1049            }
1050    
1051            @Override
1052            protected PasswordPolicyRel removeImpl(PasswordPolicyRel passwordPolicyRel) {
1053                    passwordPolicyRel = toUnwrappedModel(passwordPolicyRel);
1054    
1055                    Session session = null;
1056    
1057                    try {
1058                            session = openSession();
1059    
1060                            if (!session.contains(passwordPolicyRel)) {
1061                                    passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
1062                                                    passwordPolicyRel.getPrimaryKeyObj());
1063                            }
1064    
1065                            if (passwordPolicyRel != null) {
1066                                    session.delete(passwordPolicyRel);
1067                            }
1068                    }
1069                    catch (Exception e) {
1070                            throw processException(e);
1071                    }
1072                    finally {
1073                            closeSession(session);
1074                    }
1075    
1076                    if (passwordPolicyRel != null) {
1077                            clearCache(passwordPolicyRel);
1078                    }
1079    
1080                    return passwordPolicyRel;
1081            }
1082    
1083            @Override
1084            public PasswordPolicyRel updateImpl(PasswordPolicyRel passwordPolicyRel) {
1085                    passwordPolicyRel = toUnwrappedModel(passwordPolicyRel);
1086    
1087                    boolean isNew = passwordPolicyRel.isNew();
1088    
1089                    PasswordPolicyRelModelImpl passwordPolicyRelModelImpl = (PasswordPolicyRelModelImpl)passwordPolicyRel;
1090    
1091                    Session session = null;
1092    
1093                    try {
1094                            session = openSession();
1095    
1096                            if (passwordPolicyRel.isNew()) {
1097                                    session.save(passwordPolicyRel);
1098    
1099                                    passwordPolicyRel.setNew(false);
1100                            }
1101                            else {
1102                                    passwordPolicyRel = (PasswordPolicyRel)session.merge(passwordPolicyRel);
1103                            }
1104                    }
1105                    catch (Exception e) {
1106                            throw processException(e);
1107                    }
1108                    finally {
1109                            closeSession(session);
1110                    }
1111    
1112                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1113    
1114                    if (isNew || !PasswordPolicyRelModelImpl.COLUMN_BITMASK_ENABLED) {
1115                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1116                    }
1117    
1118                    else {
1119                            if ((passwordPolicyRelModelImpl.getColumnBitmask() &
1120                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID.getColumnBitmask()) != 0) {
1121                                    Object[] args = new Object[] {
1122                                                    passwordPolicyRelModelImpl.getOriginalPasswordPolicyId()
1123                                            };
1124    
1125                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PASSWORDPOLICYID,
1126                                            args);
1127                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID,
1128                                            args);
1129    
1130                                    args = new Object[] {
1131                                                    passwordPolicyRelModelImpl.getPasswordPolicyId()
1132                                            };
1133    
1134                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PASSWORDPOLICYID,
1135                                            args);
1136                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PASSWORDPOLICYID,
1137                                            args);
1138                            }
1139                    }
1140    
1141                    entityCache.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1142                            PasswordPolicyRelImpl.class, passwordPolicyRel.getPrimaryKey(),
1143                            passwordPolicyRel, false);
1144    
1145                    clearUniqueFindersCache(passwordPolicyRelModelImpl);
1146                    cacheUniqueFindersCache(passwordPolicyRelModelImpl, isNew);
1147    
1148                    passwordPolicyRel.resetOriginalValues();
1149    
1150                    return passwordPolicyRel;
1151            }
1152    
1153            protected PasswordPolicyRel toUnwrappedModel(
1154                    PasswordPolicyRel passwordPolicyRel) {
1155                    if (passwordPolicyRel instanceof PasswordPolicyRelImpl) {
1156                            return passwordPolicyRel;
1157                    }
1158    
1159                    PasswordPolicyRelImpl passwordPolicyRelImpl = new PasswordPolicyRelImpl();
1160    
1161                    passwordPolicyRelImpl.setNew(passwordPolicyRel.isNew());
1162                    passwordPolicyRelImpl.setPrimaryKey(passwordPolicyRel.getPrimaryKey());
1163    
1164                    passwordPolicyRelImpl.setMvccVersion(passwordPolicyRel.getMvccVersion());
1165                    passwordPolicyRelImpl.setPasswordPolicyRelId(passwordPolicyRel.getPasswordPolicyRelId());
1166                    passwordPolicyRelImpl.setCompanyId(passwordPolicyRel.getCompanyId());
1167                    passwordPolicyRelImpl.setPasswordPolicyId(passwordPolicyRel.getPasswordPolicyId());
1168                    passwordPolicyRelImpl.setClassNameId(passwordPolicyRel.getClassNameId());
1169                    passwordPolicyRelImpl.setClassPK(passwordPolicyRel.getClassPK());
1170    
1171                    return passwordPolicyRelImpl;
1172            }
1173    
1174            /**
1175             * Returns the password policy rel with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
1176             *
1177             * @param primaryKey the primary key of the password policy rel
1178             * @return the password policy rel
1179             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1180             */
1181            @Override
1182            public PasswordPolicyRel findByPrimaryKey(Serializable primaryKey)
1183                    throws NoSuchPasswordPolicyRelException {
1184                    PasswordPolicyRel passwordPolicyRel = fetchByPrimaryKey(primaryKey);
1185    
1186                    if (passwordPolicyRel == null) {
1187                            if (_log.isWarnEnabled()) {
1188                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1189                            }
1190    
1191                            throw new NoSuchPasswordPolicyRelException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1192                                    primaryKey);
1193                    }
1194    
1195                    return passwordPolicyRel;
1196            }
1197    
1198            /**
1199             * Returns the password policy rel with the primary key or throws a {@link NoSuchPasswordPolicyRelException} if it could not be found.
1200             *
1201             * @param passwordPolicyRelId the primary key of the password policy rel
1202             * @return the password policy rel
1203             * @throws NoSuchPasswordPolicyRelException if a password policy rel with the primary key could not be found
1204             */
1205            @Override
1206            public PasswordPolicyRel findByPrimaryKey(long passwordPolicyRelId)
1207                    throws NoSuchPasswordPolicyRelException {
1208                    return findByPrimaryKey((Serializable)passwordPolicyRelId);
1209            }
1210    
1211            /**
1212             * Returns the password policy rel with the primary key or returns <code>null</code> if it could not be found.
1213             *
1214             * @param primaryKey the primary key of the password policy rel
1215             * @return the password policy rel, or <code>null</code> if a password policy rel with the primary key could not be found
1216             */
1217            @Override
1218            public PasswordPolicyRel fetchByPrimaryKey(Serializable primaryKey) {
1219                    PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)entityCache.getResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1220                                    PasswordPolicyRelImpl.class, primaryKey);
1221    
1222                    if (passwordPolicyRel == _nullPasswordPolicyRel) {
1223                            return null;
1224                    }
1225    
1226                    if (passwordPolicyRel == null) {
1227                            Session session = null;
1228    
1229                            try {
1230                                    session = openSession();
1231    
1232                                    passwordPolicyRel = (PasswordPolicyRel)session.get(PasswordPolicyRelImpl.class,
1233                                                    primaryKey);
1234    
1235                                    if (passwordPolicyRel != null) {
1236                                            cacheResult(passwordPolicyRel);
1237                                    }
1238                                    else {
1239                                            entityCache.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1240                                                    PasswordPolicyRelImpl.class, primaryKey,
1241                                                    _nullPasswordPolicyRel);
1242                                    }
1243                            }
1244                            catch (Exception e) {
1245                                    entityCache.removeResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1246                                            PasswordPolicyRelImpl.class, primaryKey);
1247    
1248                                    throw processException(e);
1249                            }
1250                            finally {
1251                                    closeSession(session);
1252                            }
1253                    }
1254    
1255                    return passwordPolicyRel;
1256            }
1257    
1258            /**
1259             * Returns the password policy rel with the primary key or returns <code>null</code> if it could not be found.
1260             *
1261             * @param passwordPolicyRelId the primary key of the password policy rel
1262             * @return the password policy rel, or <code>null</code> if a password policy rel with the primary key could not be found
1263             */
1264            @Override
1265            public PasswordPolicyRel fetchByPrimaryKey(long passwordPolicyRelId) {
1266                    return fetchByPrimaryKey((Serializable)passwordPolicyRelId);
1267            }
1268    
1269            @Override
1270            public Map<Serializable, PasswordPolicyRel> fetchByPrimaryKeys(
1271                    Set<Serializable> primaryKeys) {
1272                    if (primaryKeys.isEmpty()) {
1273                            return Collections.emptyMap();
1274                    }
1275    
1276                    Map<Serializable, PasswordPolicyRel> map = new HashMap<Serializable, PasswordPolicyRel>();
1277    
1278                    if (primaryKeys.size() == 1) {
1279                            Iterator<Serializable> iterator = primaryKeys.iterator();
1280    
1281                            Serializable primaryKey = iterator.next();
1282    
1283                            PasswordPolicyRel passwordPolicyRel = fetchByPrimaryKey(primaryKey);
1284    
1285                            if (passwordPolicyRel != null) {
1286                                    map.put(primaryKey, passwordPolicyRel);
1287                            }
1288    
1289                            return map;
1290                    }
1291    
1292                    Set<Serializable> uncachedPrimaryKeys = null;
1293    
1294                    for (Serializable primaryKey : primaryKeys) {
1295                            PasswordPolicyRel passwordPolicyRel = (PasswordPolicyRel)entityCache.getResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1296                                            PasswordPolicyRelImpl.class, primaryKey);
1297    
1298                            if (passwordPolicyRel == null) {
1299                                    if (uncachedPrimaryKeys == null) {
1300                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1301                                    }
1302    
1303                                    uncachedPrimaryKeys.add(primaryKey);
1304                            }
1305                            else {
1306                                    map.put(primaryKey, passwordPolicyRel);
1307                            }
1308                    }
1309    
1310                    if (uncachedPrimaryKeys == null) {
1311                            return map;
1312                    }
1313    
1314                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1315                                    1);
1316    
1317                    query.append(_SQL_SELECT_PASSWORDPOLICYREL_WHERE_PKS_IN);
1318    
1319                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1320                            query.append(String.valueOf(primaryKey));
1321    
1322                            query.append(StringPool.COMMA);
1323                    }
1324    
1325                    query.setIndex(query.index() - 1);
1326    
1327                    query.append(StringPool.CLOSE_PARENTHESIS);
1328    
1329                    String sql = query.toString();
1330    
1331                    Session session = null;
1332    
1333                    try {
1334                            session = openSession();
1335    
1336                            Query q = session.createQuery(sql);
1337    
1338                            for (PasswordPolicyRel passwordPolicyRel : (List<PasswordPolicyRel>)q.list()) {
1339                                    map.put(passwordPolicyRel.getPrimaryKeyObj(), passwordPolicyRel);
1340    
1341                                    cacheResult(passwordPolicyRel);
1342    
1343                                    uncachedPrimaryKeys.remove(passwordPolicyRel.getPrimaryKeyObj());
1344                            }
1345    
1346                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1347                                    entityCache.putResult(PasswordPolicyRelModelImpl.ENTITY_CACHE_ENABLED,
1348                                            PasswordPolicyRelImpl.class, primaryKey,
1349                                            _nullPasswordPolicyRel);
1350                            }
1351                    }
1352                    catch (Exception e) {
1353                            throw processException(e);
1354                    }
1355                    finally {
1356                            closeSession(session);
1357                    }
1358    
1359                    return map;
1360            }
1361    
1362            /**
1363             * Returns all the password policy rels.
1364             *
1365             * @return the password policy rels
1366             */
1367            @Override
1368            public List<PasswordPolicyRel> findAll() {
1369                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1370            }
1371    
1372            /**
1373             * Returns a range of all the password policy rels.
1374             *
1375             * <p>
1376             * 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.
1377             * </p>
1378             *
1379             * @param start the lower bound of the range of password policy rels
1380             * @param end the upper bound of the range of password policy rels (not inclusive)
1381             * @return the range of password policy rels
1382             */
1383            @Override
1384            public List<PasswordPolicyRel> findAll(int start, int end) {
1385                    return findAll(start, end, null);
1386            }
1387    
1388            /**
1389             * Returns an ordered range of all the password policy rels.
1390             *
1391             * <p>
1392             * 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.
1393             * </p>
1394             *
1395             * @param start the lower bound of the range of password policy rels
1396             * @param end the upper bound of the range of password policy rels (not inclusive)
1397             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1398             * @return the ordered range of password policy rels
1399             */
1400            @Override
1401            public List<PasswordPolicyRel> findAll(int start, int end,
1402                    OrderByComparator<PasswordPolicyRel> orderByComparator) {
1403                    return findAll(start, end, orderByComparator, true);
1404            }
1405    
1406            /**
1407             * Returns an ordered range of all the password policy rels.
1408             *
1409             * <p>
1410             * 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.
1411             * </p>
1412             *
1413             * @param start the lower bound of the range of password policy rels
1414             * @param end the upper bound of the range of password policy rels (not inclusive)
1415             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1416             * @param retrieveFromCache whether to retrieve from the finder cache
1417             * @return the ordered range of password policy rels
1418             */
1419            @Override
1420            public List<PasswordPolicyRel> findAll(int start, int end,
1421                    OrderByComparator<PasswordPolicyRel> orderByComparator,
1422                    boolean retrieveFromCache) {
1423                    boolean pagination = true;
1424                    FinderPath finderPath = null;
1425                    Object[] finderArgs = null;
1426    
1427                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1428                                    (orderByComparator == null)) {
1429                            pagination = false;
1430                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1431                            finderArgs = FINDER_ARGS_EMPTY;
1432                    }
1433                    else {
1434                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1435                            finderArgs = new Object[] { start, end, orderByComparator };
1436                    }
1437    
1438                    List<PasswordPolicyRel> list = null;
1439    
1440                    if (retrieveFromCache) {
1441                            list = (List<PasswordPolicyRel>)finderCache.getResult(finderPath,
1442                                            finderArgs, this);
1443                    }
1444    
1445                    if (list == null) {
1446                            StringBundler query = null;
1447                            String sql = null;
1448    
1449                            if (orderByComparator != null) {
1450                                    query = new StringBundler(2 +
1451                                                    (orderByComparator.getOrderByFields().length * 2));
1452    
1453                                    query.append(_SQL_SELECT_PASSWORDPOLICYREL);
1454    
1455                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1456                                            orderByComparator);
1457    
1458                                    sql = query.toString();
1459                            }
1460                            else {
1461                                    sql = _SQL_SELECT_PASSWORDPOLICYREL;
1462    
1463                                    if (pagination) {
1464                                            sql = sql.concat(PasswordPolicyRelModelImpl.ORDER_BY_JPQL);
1465                                    }
1466                            }
1467    
1468                            Session session = null;
1469    
1470                            try {
1471                                    session = openSession();
1472    
1473                                    Query q = session.createQuery(sql);
1474    
1475                                    if (!pagination) {
1476                                            list = (List<PasswordPolicyRel>)QueryUtil.list(q,
1477                                                            getDialect(), start, end, false);
1478    
1479                                            Collections.sort(list);
1480    
1481                                            list = Collections.unmodifiableList(list);
1482                                    }
1483                                    else {
1484                                            list = (List<PasswordPolicyRel>)QueryUtil.list(q,
1485                                                            getDialect(), start, end);
1486                                    }
1487    
1488                                    cacheResult(list);
1489    
1490                                    finderCache.putResult(finderPath, finderArgs, list);
1491                            }
1492                            catch (Exception e) {
1493                                    finderCache.removeResult(finderPath, finderArgs);
1494    
1495                                    throw processException(e);
1496                            }
1497                            finally {
1498                                    closeSession(session);
1499                            }
1500                    }
1501    
1502                    return list;
1503            }
1504    
1505            /**
1506             * Removes all the password policy rels from the database.
1507             *
1508             */
1509            @Override
1510            public void removeAll() {
1511                    for (PasswordPolicyRel passwordPolicyRel : findAll()) {
1512                            remove(passwordPolicyRel);
1513                    }
1514            }
1515    
1516            /**
1517             * Returns the number of password policy rels.
1518             *
1519             * @return the number of password policy rels
1520             */
1521            @Override
1522            public int countAll() {
1523                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1524                                    FINDER_ARGS_EMPTY, this);
1525    
1526                    if (count == null) {
1527                            Session session = null;
1528    
1529                            try {
1530                                    session = openSession();
1531    
1532                                    Query q = session.createQuery(_SQL_COUNT_PASSWORDPOLICYREL);
1533    
1534                                    count = (Long)q.uniqueResult();
1535    
1536                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1537                                            count);
1538                            }
1539                            catch (Exception e) {
1540                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1541                                            FINDER_ARGS_EMPTY);
1542    
1543                                    throw processException(e);
1544                            }
1545                            finally {
1546                                    closeSession(session);
1547                            }
1548                    }
1549    
1550                    return count.intValue();
1551            }
1552    
1553            @Override
1554            protected Map<String, Integer> getTableColumnsMap() {
1555                    return PasswordPolicyRelModelImpl.TABLE_COLUMNS_MAP;
1556            }
1557    
1558            /**
1559             * Initializes the password policy rel persistence.
1560             */
1561            public void afterPropertiesSet() {
1562            }
1563    
1564            public void destroy() {
1565                    entityCache.removeCache(PasswordPolicyRelImpl.class.getName());
1566                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1567                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1568                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1569            }
1570    
1571            @BeanReference(type = CompanyProviderWrapper.class)
1572            protected CompanyProvider companyProvider;
1573            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1574            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1575            private static final String _SQL_SELECT_PASSWORDPOLICYREL = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel";
1576            private static final String _SQL_SELECT_PASSWORDPOLICYREL_WHERE_PKS_IN = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel WHERE passwordPolicyRelId IN (";
1577            private static final String _SQL_SELECT_PASSWORDPOLICYREL_WHERE = "SELECT passwordPolicyRel FROM PasswordPolicyRel passwordPolicyRel WHERE ";
1578            private static final String _SQL_COUNT_PASSWORDPOLICYREL = "SELECT COUNT(passwordPolicyRel) FROM PasswordPolicyRel passwordPolicyRel";
1579            private static final String _SQL_COUNT_PASSWORDPOLICYREL_WHERE = "SELECT COUNT(passwordPolicyRel) FROM PasswordPolicyRel passwordPolicyRel WHERE ";
1580            private static final String _ORDER_BY_ENTITY_ALIAS = "passwordPolicyRel.";
1581            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PasswordPolicyRel exists with the primary key ";
1582            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PasswordPolicyRel exists with the key {";
1583            private static final Log _log = LogFactoryUtil.getLog(PasswordPolicyRelPersistenceImpl.class);
1584            private static final PasswordPolicyRel _nullPasswordPolicyRel = new PasswordPolicyRelImpl() {
1585                            @Override
1586                            public Object clone() {
1587                                    return this;
1588                            }
1589    
1590                            @Override
1591                            public CacheModel<PasswordPolicyRel> toCacheModel() {
1592                                    return _nullPasswordPolicyRelCacheModel;
1593                            }
1594                    };
1595    
1596            private static final CacheModel<PasswordPolicyRel> _nullPasswordPolicyRelCacheModel =
1597                    new NullCacheModel();
1598    
1599            private static class NullCacheModel implements CacheModel<PasswordPolicyRel>,
1600                    MVCCModel {
1601                    @Override
1602                    public long getMvccVersion() {
1603                            return -1;
1604                    }
1605    
1606                    @Override
1607                    public void setMvccVersion(long mvccVersion) {
1608                    }
1609    
1610                    @Override
1611                    public PasswordPolicyRel toEntityModel() {
1612                            return _nullPasswordPolicyRel;
1613                    }
1614            }
1615    }