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