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.NoSuchSubscriptionException;
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.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.ArrayUtil;
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.kernel.util.StringUtil;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.MVCCModel;
038    import com.liferay.portal.model.Subscription;
039    import com.liferay.portal.model.impl.SubscriptionImpl;
040    import com.liferay.portal.model.impl.SubscriptionModelImpl;
041    import com.liferay.portal.service.ServiceContext;
042    import com.liferay.portal.service.ServiceContextThreadLocal;
043    import com.liferay.portal.service.persistence.SubscriptionPersistence;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Arrays;
049    import java.util.Collections;
050    import java.util.Date;
051    import java.util.HashMap;
052    import java.util.HashSet;
053    import java.util.Iterator;
054    import java.util.List;
055    import java.util.Map;
056    import java.util.Set;
057    
058    /**
059     * The persistence implementation for the subscription service.
060     *
061     * <p>
062     * Caching information and settings can be found in <code>portal.properties</code>
063     * </p>
064     *
065     * @author Brian Wing Shun Chan
066     * @see SubscriptionPersistence
067     * @see com.liferay.portal.service.persistence.SubscriptionUtil
068     * @generated
069     */
070    @ProviderType
071    public class SubscriptionPersistenceImpl extends BasePersistenceImpl<Subscription>
072            implements SubscriptionPersistence {
073            /*
074             * NOTE FOR DEVELOPERS:
075             *
076             * Never modify or reference this class directly. Always use {@link SubscriptionUtil} to access the subscription persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
077             */
078            public static final String FINDER_CLASS_NAME_ENTITY = SubscriptionImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List1";
081            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List2";
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
084                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
087                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
090                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
093                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
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_USERID =
102                    new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
103                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
105                            new String[] { Long.class.getName() },
106                            SubscriptionModelImpl.USERID_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
108                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
110                            new String[] { Long.class.getName() });
111    
112            /**
113             * Returns all the subscriptions where userId = &#63;.
114             *
115             * @param userId the user ID
116             * @return the matching subscriptions
117             */
118            @Override
119            public List<Subscription> findByUserId(long userId) {
120                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121            }
122    
123            /**
124             * Returns a range of all the subscriptions where userId = &#63;.
125             *
126             * <p>
127             * 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 SubscriptionModelImpl}. 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.
128             * </p>
129             *
130             * @param userId the user ID
131             * @param start the lower bound of the range of subscriptions
132             * @param end the upper bound of the range of subscriptions (not inclusive)
133             * @return the range of matching subscriptions
134             */
135            @Override
136            public List<Subscription> findByUserId(long userId, int start, int end) {
137                    return findByUserId(userId, start, end, null);
138            }
139    
140            /**
141             * Returns an ordered range of all the subscriptions where userId = &#63;.
142             *
143             * <p>
144             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 SubscriptionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
145             * </p>
146             *
147             * @param userId the user ID
148             * @param start the lower bound of the range of subscriptions
149             * @param end the upper bound of the range of subscriptions (not inclusive)
150             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
151             * @return the ordered range of matching subscriptions
152             */
153            @Override
154            public List<Subscription> findByUserId(long userId, int start, int end,
155                    OrderByComparator<Subscription> orderByComparator) {
156                    return findByUserId(userId, start, end, orderByComparator, true);
157            }
158    
159            /**
160             * Returns an ordered range of all the subscriptions where userId = &#63;.
161             *
162             * <p>
163             * 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 SubscriptionModelImpl}. 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.
164             * </p>
165             *
166             * @param userId the user ID
167             * @param start the lower bound of the range of subscriptions
168             * @param end the upper bound of the range of subscriptions (not inclusive)
169             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
170             * @param retrieveFromCache whether to retrieve from the finder cache
171             * @return the ordered range of matching subscriptions
172             */
173            @Override
174            public List<Subscription> findByUserId(long userId, int start, int end,
175                    OrderByComparator<Subscription> orderByComparator,
176                    boolean retrieveFromCache) {
177                    boolean pagination = true;
178                    FinderPath finderPath = null;
179                    Object[] finderArgs = null;
180    
181                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
182                                    (orderByComparator == null)) {
183                            pagination = false;
184                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
185                            finderArgs = new Object[] { userId };
186                    }
187                    else {
188                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
189                            finderArgs = new Object[] { userId, start, end, orderByComparator };
190                    }
191    
192                    List<Subscription> list = null;
193    
194                    if (retrieveFromCache) {
195                            list = (List<Subscription>)finderCache.getResult(finderPath,
196                                            finderArgs, this);
197    
198                            if ((list != null) && !list.isEmpty()) {
199                                    for (Subscription subscription : list) {
200                                            if ((userId != subscription.getUserId())) {
201                                                    list = null;
202    
203                                                    break;
204                                            }
205                                    }
206                            }
207                    }
208    
209                    if (list == null) {
210                            StringBundler query = null;
211    
212                            if (orderByComparator != null) {
213                                    query = new StringBundler(3 +
214                                                    (orderByComparator.getOrderByFields().length * 3));
215                            }
216                            else {
217                                    query = new StringBundler(3);
218                            }
219    
220                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
221    
222                            query.append(_FINDER_COLUMN_USERID_USERID_2);
223    
224                            if (orderByComparator != null) {
225                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
226                                            orderByComparator);
227                            }
228                            else
229                             if (pagination) {
230                                    query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
231                            }
232    
233                            String sql = query.toString();
234    
235                            Session session = null;
236    
237                            try {
238                                    session = openSession();
239    
240                                    Query q = session.createQuery(sql);
241    
242                                    QueryPos qPos = QueryPos.getInstance(q);
243    
244                                    qPos.add(userId);
245    
246                                    if (!pagination) {
247                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
248                                                            start, end, false);
249    
250                                            Collections.sort(list);
251    
252                                            list = Collections.unmodifiableList(list);
253                                    }
254                                    else {
255                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
256                                                            start, end);
257                                    }
258    
259                                    cacheResult(list);
260    
261                                    finderCache.putResult(finderPath, finderArgs, list);
262                            }
263                            catch (Exception e) {
264                                    finderCache.removeResult(finderPath, finderArgs);
265    
266                                    throw processException(e);
267                            }
268                            finally {
269                                    closeSession(session);
270                            }
271                    }
272    
273                    return list;
274            }
275    
276            /**
277             * Returns the first subscription in the ordered set where userId = &#63;.
278             *
279             * @param userId the user ID
280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
281             * @return the first matching subscription
282             * @throws NoSuchSubscriptionException if a matching subscription could not be found
283             */
284            @Override
285            public Subscription findByUserId_First(long userId,
286                    OrderByComparator<Subscription> orderByComparator)
287                    throws NoSuchSubscriptionException {
288                    Subscription subscription = fetchByUserId_First(userId,
289                                    orderByComparator);
290    
291                    if (subscription != null) {
292                            return subscription;
293                    }
294    
295                    StringBundler msg = new StringBundler(4);
296    
297                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
298    
299                    msg.append("userId=");
300                    msg.append(userId);
301    
302                    msg.append(StringPool.CLOSE_CURLY_BRACE);
303    
304                    throw new NoSuchSubscriptionException(msg.toString());
305            }
306    
307            /**
308             * Returns the first subscription in the ordered set where userId = &#63;.
309             *
310             * @param userId the user ID
311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
312             * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found
313             */
314            @Override
315            public Subscription fetchByUserId_First(long userId,
316                    OrderByComparator<Subscription> orderByComparator) {
317                    List<Subscription> list = findByUserId(userId, 0, 1, orderByComparator);
318    
319                    if (!list.isEmpty()) {
320                            return list.get(0);
321                    }
322    
323                    return null;
324            }
325    
326            /**
327             * Returns the last subscription in the ordered set where userId = &#63;.
328             *
329             * @param userId the user ID
330             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
331             * @return the last matching subscription
332             * @throws NoSuchSubscriptionException if a matching subscription could not be found
333             */
334            @Override
335            public Subscription findByUserId_Last(long userId,
336                    OrderByComparator<Subscription> orderByComparator)
337                    throws NoSuchSubscriptionException {
338                    Subscription subscription = fetchByUserId_Last(userId, orderByComparator);
339    
340                    if (subscription != null) {
341                            return subscription;
342                    }
343    
344                    StringBundler msg = new StringBundler(4);
345    
346                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
347    
348                    msg.append("userId=");
349                    msg.append(userId);
350    
351                    msg.append(StringPool.CLOSE_CURLY_BRACE);
352    
353                    throw new NoSuchSubscriptionException(msg.toString());
354            }
355    
356            /**
357             * Returns the last subscription in the ordered set where userId = &#63;.
358             *
359             * @param userId the user ID
360             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
361             * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found
362             */
363            @Override
364            public Subscription fetchByUserId_Last(long userId,
365                    OrderByComparator<Subscription> orderByComparator) {
366                    int count = countByUserId(userId);
367    
368                    if (count == 0) {
369                            return null;
370                    }
371    
372                    List<Subscription> list = findByUserId(userId, count - 1, count,
373                                    orderByComparator);
374    
375                    if (!list.isEmpty()) {
376                            return list.get(0);
377                    }
378    
379                    return null;
380            }
381    
382            /**
383             * Returns the subscriptions before and after the current subscription in the ordered set where userId = &#63;.
384             *
385             * @param subscriptionId the primary key of the current subscription
386             * @param userId the user ID
387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
388             * @return the previous, current, and next subscription
389             * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found
390             */
391            @Override
392            public Subscription[] findByUserId_PrevAndNext(long subscriptionId,
393                    long userId, OrderByComparator<Subscription> orderByComparator)
394                    throws NoSuchSubscriptionException {
395                    Subscription subscription = findByPrimaryKey(subscriptionId);
396    
397                    Session session = null;
398    
399                    try {
400                            session = openSession();
401    
402                            Subscription[] array = new SubscriptionImpl[3];
403    
404                            array[0] = getByUserId_PrevAndNext(session, subscription, userId,
405                                            orderByComparator, true);
406    
407                            array[1] = subscription;
408    
409                            array[2] = getByUserId_PrevAndNext(session, subscription, userId,
410                                            orderByComparator, false);
411    
412                            return array;
413                    }
414                    catch (Exception e) {
415                            throw processException(e);
416                    }
417                    finally {
418                            closeSession(session);
419                    }
420            }
421    
422            protected Subscription getByUserId_PrevAndNext(Session session,
423                    Subscription subscription, long userId,
424                    OrderByComparator<Subscription> orderByComparator, boolean previous) {
425                    StringBundler query = null;
426    
427                    if (orderByComparator != null) {
428                            query = new StringBundler(6 +
429                                            (orderByComparator.getOrderByFields().length * 6));
430                    }
431                    else {
432                            query = new StringBundler(3);
433                    }
434    
435                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
436    
437                    query.append(_FINDER_COLUMN_USERID_USERID_2);
438    
439                    if (orderByComparator != null) {
440                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
441    
442                            if (orderByConditionFields.length > 0) {
443                                    query.append(WHERE_AND);
444                            }
445    
446                            for (int i = 0; i < orderByConditionFields.length; i++) {
447                                    query.append(_ORDER_BY_ENTITY_ALIAS);
448                                    query.append(orderByConditionFields[i]);
449    
450                                    if ((i + 1) < orderByConditionFields.length) {
451                                            if (orderByComparator.isAscending() ^ previous) {
452                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
453                                            }
454                                            else {
455                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
456                                            }
457                                    }
458                                    else {
459                                            if (orderByComparator.isAscending() ^ previous) {
460                                                    query.append(WHERE_GREATER_THAN);
461                                            }
462                                            else {
463                                                    query.append(WHERE_LESSER_THAN);
464                                            }
465                                    }
466                            }
467    
468                            query.append(ORDER_BY_CLAUSE);
469    
470                            String[] orderByFields = orderByComparator.getOrderByFields();
471    
472                            for (int i = 0; i < orderByFields.length; i++) {
473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
474                                    query.append(orderByFields[i]);
475    
476                                    if ((i + 1) < orderByFields.length) {
477                                            if (orderByComparator.isAscending() ^ previous) {
478                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
479                                            }
480                                            else {
481                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
482                                            }
483                                    }
484                                    else {
485                                            if (orderByComparator.isAscending() ^ previous) {
486                                                    query.append(ORDER_BY_ASC);
487                                            }
488                                            else {
489                                                    query.append(ORDER_BY_DESC);
490                                            }
491                                    }
492                            }
493                    }
494                    else {
495                            query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
496                    }
497    
498                    String sql = query.toString();
499    
500                    Query q = session.createQuery(sql);
501    
502                    q.setFirstResult(0);
503                    q.setMaxResults(2);
504    
505                    QueryPos qPos = QueryPos.getInstance(q);
506    
507                    qPos.add(userId);
508    
509                    if (orderByComparator != null) {
510                            Object[] values = orderByComparator.getOrderByConditionValues(subscription);
511    
512                            for (Object value : values) {
513                                    qPos.add(value);
514                            }
515                    }
516    
517                    List<Subscription> list = q.list();
518    
519                    if (list.size() == 2) {
520                            return list.get(1);
521                    }
522                    else {
523                            return null;
524                    }
525            }
526    
527            /**
528             * Removes all the subscriptions where userId = &#63; from the database.
529             *
530             * @param userId the user ID
531             */
532            @Override
533            public void removeByUserId(long userId) {
534                    for (Subscription subscription : findByUserId(userId,
535                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
536                            remove(subscription);
537                    }
538            }
539    
540            /**
541             * Returns the number of subscriptions where userId = &#63;.
542             *
543             * @param userId the user ID
544             * @return the number of matching subscriptions
545             */
546            @Override
547            public int countByUserId(long userId) {
548                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
549    
550                    Object[] finderArgs = new Object[] { userId };
551    
552                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
553    
554                    if (count == null) {
555                            StringBundler query = new StringBundler(2);
556    
557                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
558    
559                            query.append(_FINDER_COLUMN_USERID_USERID_2);
560    
561                            String sql = query.toString();
562    
563                            Session session = null;
564    
565                            try {
566                                    session = openSession();
567    
568                                    Query q = session.createQuery(sql);
569    
570                                    QueryPos qPos = QueryPos.getInstance(q);
571    
572                                    qPos.add(userId);
573    
574                                    count = (Long)q.uniqueResult();
575    
576                                    finderCache.putResult(finderPath, finderArgs, count);
577                            }
578                            catch (Exception e) {
579                                    finderCache.removeResult(finderPath, finderArgs);
580    
581                                    throw processException(e);
582                            }
583                            finally {
584                                    closeSession(session);
585                            }
586                    }
587    
588                    return count.intValue();
589            }
590    
591            private static final String _FINDER_COLUMN_USERID_USERID_2 = "subscription.userId = ?";
592            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
593                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
594                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
595                            new String[] {
596                                    Long.class.getName(), Long.class.getName(),
597                                    
598                            Integer.class.getName(), Integer.class.getName(),
599                                    OrderByComparator.class.getName()
600                            });
601            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
602                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
603                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
604                            new String[] { Long.class.getName(), Long.class.getName() },
605                            SubscriptionModelImpl.GROUPID_COLUMN_BITMASK |
606                            SubscriptionModelImpl.USERID_COLUMN_BITMASK);
607            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
608                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
609                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
610                            new String[] { Long.class.getName(), Long.class.getName() });
611    
612            /**
613             * Returns all the subscriptions where groupId = &#63; and userId = &#63;.
614             *
615             * @param groupId the group ID
616             * @param userId the user ID
617             * @return the matching subscriptions
618             */
619            @Override
620            public List<Subscription> findByG_U(long groupId, long userId) {
621                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
622                            null);
623            }
624    
625            /**
626             * Returns a range of all the subscriptions where groupId = &#63; and userId = &#63;.
627             *
628             * <p>
629             * 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 SubscriptionModelImpl}. 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.
630             * </p>
631             *
632             * @param groupId the group ID
633             * @param userId the user ID
634             * @param start the lower bound of the range of subscriptions
635             * @param end the upper bound of the range of subscriptions (not inclusive)
636             * @return the range of matching subscriptions
637             */
638            @Override
639            public List<Subscription> findByG_U(long groupId, long userId, int start,
640                    int end) {
641                    return findByG_U(groupId, userId, start, end, null);
642            }
643    
644            /**
645             * Returns an ordered range of all the subscriptions where groupId = &#63; and userId = &#63;.
646             *
647             * <p>
648             * 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 SubscriptionModelImpl}. 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.
649             * </p>
650             *
651             * @param groupId the group ID
652             * @param userId the user ID
653             * @param start the lower bound of the range of subscriptions
654             * @param end the upper bound of the range of subscriptions (not inclusive)
655             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
656             * @return the ordered range of matching subscriptions
657             */
658            @Override
659            public List<Subscription> findByG_U(long groupId, long userId, int start,
660                    int end, OrderByComparator<Subscription> orderByComparator) {
661                    return findByG_U(groupId, userId, start, end, orderByComparator, true);
662            }
663    
664            /**
665             * Returns an ordered range of all the subscriptions where groupId = &#63; and userId = &#63;.
666             *
667             * <p>
668             * 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 SubscriptionModelImpl}. 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.
669             * </p>
670             *
671             * @param groupId the group ID
672             * @param userId the user ID
673             * @param start the lower bound of the range of subscriptions
674             * @param end the upper bound of the range of subscriptions (not inclusive)
675             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
676             * @param retrieveFromCache whether to retrieve from the finder cache
677             * @return the ordered range of matching subscriptions
678             */
679            @Override
680            public List<Subscription> findByG_U(long groupId, long userId, int start,
681                    int end, OrderByComparator<Subscription> orderByComparator,
682                    boolean retrieveFromCache) {
683                    boolean pagination = true;
684                    FinderPath finderPath = null;
685                    Object[] finderArgs = null;
686    
687                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
688                                    (orderByComparator == null)) {
689                            pagination = false;
690                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
691                            finderArgs = new Object[] { groupId, userId };
692                    }
693                    else {
694                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
695                            finderArgs = new Object[] {
696                                            groupId, userId,
697                                            
698                                            start, end, orderByComparator
699                                    };
700                    }
701    
702                    List<Subscription> list = null;
703    
704                    if (retrieveFromCache) {
705                            list = (List<Subscription>)finderCache.getResult(finderPath,
706                                            finderArgs, this);
707    
708                            if ((list != null) && !list.isEmpty()) {
709                                    for (Subscription subscription : list) {
710                                            if ((groupId != subscription.getGroupId()) ||
711                                                            (userId != subscription.getUserId())) {
712                                                    list = null;
713    
714                                                    break;
715                                            }
716                                    }
717                            }
718                    }
719    
720                    if (list == null) {
721                            StringBundler query = null;
722    
723                            if (orderByComparator != null) {
724                                    query = new StringBundler(4 +
725                                                    (orderByComparator.getOrderByFields().length * 3));
726                            }
727                            else {
728                                    query = new StringBundler(4);
729                            }
730    
731                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
732    
733                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
734    
735                            query.append(_FINDER_COLUMN_G_U_USERID_2);
736    
737                            if (orderByComparator != null) {
738                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
739                                            orderByComparator);
740                            }
741                            else
742                             if (pagination) {
743                                    query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
744                            }
745    
746                            String sql = query.toString();
747    
748                            Session session = null;
749    
750                            try {
751                                    session = openSession();
752    
753                                    Query q = session.createQuery(sql);
754    
755                                    QueryPos qPos = QueryPos.getInstance(q);
756    
757                                    qPos.add(groupId);
758    
759                                    qPos.add(userId);
760    
761                                    if (!pagination) {
762                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
763                                                            start, end, false);
764    
765                                            Collections.sort(list);
766    
767                                            list = Collections.unmodifiableList(list);
768                                    }
769                                    else {
770                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
771                                                            start, end);
772                                    }
773    
774                                    cacheResult(list);
775    
776                                    finderCache.putResult(finderPath, finderArgs, list);
777                            }
778                            catch (Exception e) {
779                                    finderCache.removeResult(finderPath, finderArgs);
780    
781                                    throw processException(e);
782                            }
783                            finally {
784                                    closeSession(session);
785                            }
786                    }
787    
788                    return list;
789            }
790    
791            /**
792             * Returns the first subscription in the ordered set where groupId = &#63; and userId = &#63;.
793             *
794             * @param groupId the group ID
795             * @param userId the user ID
796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
797             * @return the first matching subscription
798             * @throws NoSuchSubscriptionException if a matching subscription could not be found
799             */
800            @Override
801            public Subscription findByG_U_First(long groupId, long userId,
802                    OrderByComparator<Subscription> orderByComparator)
803                    throws NoSuchSubscriptionException {
804                    Subscription subscription = fetchByG_U_First(groupId, userId,
805                                    orderByComparator);
806    
807                    if (subscription != null) {
808                            return subscription;
809                    }
810    
811                    StringBundler msg = new StringBundler(6);
812    
813                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
814    
815                    msg.append("groupId=");
816                    msg.append(groupId);
817    
818                    msg.append(", userId=");
819                    msg.append(userId);
820    
821                    msg.append(StringPool.CLOSE_CURLY_BRACE);
822    
823                    throw new NoSuchSubscriptionException(msg.toString());
824            }
825    
826            /**
827             * Returns the first subscription in the ordered set where groupId = &#63; and userId = &#63;.
828             *
829             * @param groupId the group ID
830             * @param userId the user ID
831             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
832             * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found
833             */
834            @Override
835            public Subscription fetchByG_U_First(long groupId, long userId,
836                    OrderByComparator<Subscription> orderByComparator) {
837                    List<Subscription> list = findByG_U(groupId, userId, 0, 1,
838                                    orderByComparator);
839    
840                    if (!list.isEmpty()) {
841                            return list.get(0);
842                    }
843    
844                    return null;
845            }
846    
847            /**
848             * Returns the last subscription in the ordered set where groupId = &#63; and userId = &#63;.
849             *
850             * @param groupId the group ID
851             * @param userId the user ID
852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
853             * @return the last matching subscription
854             * @throws NoSuchSubscriptionException if a matching subscription could not be found
855             */
856            @Override
857            public Subscription findByG_U_Last(long groupId, long userId,
858                    OrderByComparator<Subscription> orderByComparator)
859                    throws NoSuchSubscriptionException {
860                    Subscription subscription = fetchByG_U_Last(groupId, userId,
861                                    orderByComparator);
862    
863                    if (subscription != null) {
864                            return subscription;
865                    }
866    
867                    StringBundler msg = new StringBundler(6);
868    
869                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
870    
871                    msg.append("groupId=");
872                    msg.append(groupId);
873    
874                    msg.append(", userId=");
875                    msg.append(userId);
876    
877                    msg.append(StringPool.CLOSE_CURLY_BRACE);
878    
879                    throw new NoSuchSubscriptionException(msg.toString());
880            }
881    
882            /**
883             * Returns the last subscription in the ordered set where groupId = &#63; and userId = &#63;.
884             *
885             * @param groupId the group ID
886             * @param userId the user ID
887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
888             * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found
889             */
890            @Override
891            public Subscription fetchByG_U_Last(long groupId, long userId,
892                    OrderByComparator<Subscription> orderByComparator) {
893                    int count = countByG_U(groupId, userId);
894    
895                    if (count == 0) {
896                            return null;
897                    }
898    
899                    List<Subscription> list = findByG_U(groupId, userId, count - 1, count,
900                                    orderByComparator);
901    
902                    if (!list.isEmpty()) {
903                            return list.get(0);
904                    }
905    
906                    return null;
907            }
908    
909            /**
910             * Returns the subscriptions before and after the current subscription in the ordered set where groupId = &#63; and userId = &#63;.
911             *
912             * @param subscriptionId the primary key of the current subscription
913             * @param groupId the group ID
914             * @param userId the user ID
915             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
916             * @return the previous, current, and next subscription
917             * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found
918             */
919            @Override
920            public Subscription[] findByG_U_PrevAndNext(long subscriptionId,
921                    long groupId, long userId,
922                    OrderByComparator<Subscription> orderByComparator)
923                    throws NoSuchSubscriptionException {
924                    Subscription subscription = findByPrimaryKey(subscriptionId);
925    
926                    Session session = null;
927    
928                    try {
929                            session = openSession();
930    
931                            Subscription[] array = new SubscriptionImpl[3];
932    
933                            array[0] = getByG_U_PrevAndNext(session, subscription, groupId,
934                                            userId, orderByComparator, true);
935    
936                            array[1] = subscription;
937    
938                            array[2] = getByG_U_PrevAndNext(session, subscription, groupId,
939                                            userId, orderByComparator, false);
940    
941                            return array;
942                    }
943                    catch (Exception e) {
944                            throw processException(e);
945                    }
946                    finally {
947                            closeSession(session);
948                    }
949            }
950    
951            protected Subscription getByG_U_PrevAndNext(Session session,
952                    Subscription subscription, long groupId, long userId,
953                    OrderByComparator<Subscription> orderByComparator, boolean previous) {
954                    StringBundler query = null;
955    
956                    if (orderByComparator != null) {
957                            query = new StringBundler(6 +
958                                            (orderByComparator.getOrderByFields().length * 6));
959                    }
960                    else {
961                            query = new StringBundler(3);
962                    }
963    
964                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
965    
966                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
967    
968                    query.append(_FINDER_COLUMN_G_U_USERID_2);
969    
970                    if (orderByComparator != null) {
971                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
972    
973                            if (orderByConditionFields.length > 0) {
974                                    query.append(WHERE_AND);
975                            }
976    
977                            for (int i = 0; i < orderByConditionFields.length; i++) {
978                                    query.append(_ORDER_BY_ENTITY_ALIAS);
979                                    query.append(orderByConditionFields[i]);
980    
981                                    if ((i + 1) < orderByConditionFields.length) {
982                                            if (orderByComparator.isAscending() ^ previous) {
983                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
984                                            }
985                                            else {
986                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
987                                            }
988                                    }
989                                    else {
990                                            if (orderByComparator.isAscending() ^ previous) {
991                                                    query.append(WHERE_GREATER_THAN);
992                                            }
993                                            else {
994                                                    query.append(WHERE_LESSER_THAN);
995                                            }
996                                    }
997                            }
998    
999                            query.append(ORDER_BY_CLAUSE);
1000    
1001                            String[] orderByFields = orderByComparator.getOrderByFields();
1002    
1003                            for (int i = 0; i < orderByFields.length; i++) {
1004                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1005                                    query.append(orderByFields[i]);
1006    
1007                                    if ((i + 1) < orderByFields.length) {
1008                                            if (orderByComparator.isAscending() ^ previous) {
1009                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1010                                            }
1011                                            else {
1012                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1013                                            }
1014                                    }
1015                                    else {
1016                                            if (orderByComparator.isAscending() ^ previous) {
1017                                                    query.append(ORDER_BY_ASC);
1018                                            }
1019                                            else {
1020                                                    query.append(ORDER_BY_DESC);
1021                                            }
1022                                    }
1023                            }
1024                    }
1025                    else {
1026                            query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1027                    }
1028    
1029                    String sql = query.toString();
1030    
1031                    Query q = session.createQuery(sql);
1032    
1033                    q.setFirstResult(0);
1034                    q.setMaxResults(2);
1035    
1036                    QueryPos qPos = QueryPos.getInstance(q);
1037    
1038                    qPos.add(groupId);
1039    
1040                    qPos.add(userId);
1041    
1042                    if (orderByComparator != null) {
1043                            Object[] values = orderByComparator.getOrderByConditionValues(subscription);
1044    
1045                            for (Object value : values) {
1046                                    qPos.add(value);
1047                            }
1048                    }
1049    
1050                    List<Subscription> list = q.list();
1051    
1052                    if (list.size() == 2) {
1053                            return list.get(1);
1054                    }
1055                    else {
1056                            return null;
1057                    }
1058            }
1059    
1060            /**
1061             * Removes all the subscriptions where groupId = &#63; and userId = &#63; from the database.
1062             *
1063             * @param groupId the group ID
1064             * @param userId the user ID
1065             */
1066            @Override
1067            public void removeByG_U(long groupId, long userId) {
1068                    for (Subscription subscription : findByG_U(groupId, userId,
1069                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1070                            remove(subscription);
1071                    }
1072            }
1073    
1074            /**
1075             * Returns the number of subscriptions where groupId = &#63; and userId = &#63;.
1076             *
1077             * @param groupId the group ID
1078             * @param userId the user ID
1079             * @return the number of matching subscriptions
1080             */
1081            @Override
1082            public int countByG_U(long groupId, long userId) {
1083                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
1084    
1085                    Object[] finderArgs = new Object[] { groupId, userId };
1086    
1087                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1088    
1089                    if (count == null) {
1090                            StringBundler query = new StringBundler(3);
1091    
1092                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1093    
1094                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1095    
1096                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1097    
1098                            String sql = query.toString();
1099    
1100                            Session session = null;
1101    
1102                            try {
1103                                    session = openSession();
1104    
1105                                    Query q = session.createQuery(sql);
1106    
1107                                    QueryPos qPos = QueryPos.getInstance(q);
1108    
1109                                    qPos.add(groupId);
1110    
1111                                    qPos.add(userId);
1112    
1113                                    count = (Long)q.uniqueResult();
1114    
1115                                    finderCache.putResult(finderPath, finderArgs, count);
1116                            }
1117                            catch (Exception e) {
1118                                    finderCache.removeResult(finderPath, finderArgs);
1119    
1120                                    throw processException(e);
1121                            }
1122                            finally {
1123                                    closeSession(session);
1124                            }
1125                    }
1126    
1127                    return count.intValue();
1128            }
1129    
1130            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "subscription.groupId = ? AND ";
1131            private static final String _FINDER_COLUMN_G_U_USERID_2 = "subscription.userId = ?";
1132            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1133                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1134                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
1135                            new String[] {
1136                                    Long.class.getName(), Long.class.getName(),
1137                                    
1138                            Integer.class.getName(), Integer.class.getName(),
1139                                    OrderByComparator.class.getName()
1140                            });
1141            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1142                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1143                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
1144                            new String[] { Long.class.getName(), Long.class.getName() },
1145                            SubscriptionModelImpl.USERID_COLUMN_BITMASK |
1146                            SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK);
1147            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1148                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1149                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
1150                            new String[] { Long.class.getName(), Long.class.getName() });
1151    
1152            /**
1153             * Returns all the subscriptions where userId = &#63; and classNameId = &#63;.
1154             *
1155             * @param userId the user ID
1156             * @param classNameId the class name ID
1157             * @return the matching subscriptions
1158             */
1159            @Override
1160            public List<Subscription> findByU_C(long userId, long classNameId) {
1161                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
1162                            QueryUtil.ALL_POS, null);
1163            }
1164    
1165            /**
1166             * Returns a range of all the subscriptions where userId = &#63; and classNameId = &#63;.
1167             *
1168             * <p>
1169             * 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 SubscriptionModelImpl}. 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.
1170             * </p>
1171             *
1172             * @param userId the user ID
1173             * @param classNameId the class name ID
1174             * @param start the lower bound of the range of subscriptions
1175             * @param end the upper bound of the range of subscriptions (not inclusive)
1176             * @return the range of matching subscriptions
1177             */
1178            @Override
1179            public List<Subscription> findByU_C(long userId, long classNameId,
1180                    int start, int end) {
1181                    return findByU_C(userId, classNameId, start, end, null);
1182            }
1183    
1184            /**
1185             * Returns an ordered range of all the subscriptions where userId = &#63; and classNameId = &#63;.
1186             *
1187             * <p>
1188             * 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 SubscriptionModelImpl}. 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.
1189             * </p>
1190             *
1191             * @param userId the user ID
1192             * @param classNameId the class name ID
1193             * @param start the lower bound of the range of subscriptions
1194             * @param end the upper bound of the range of subscriptions (not inclusive)
1195             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1196             * @return the ordered range of matching subscriptions
1197             */
1198            @Override
1199            public List<Subscription> findByU_C(long userId, long classNameId,
1200                    int start, int end, OrderByComparator<Subscription> orderByComparator) {
1201                    return findByU_C(userId, classNameId, start, end, orderByComparator,
1202                            true);
1203            }
1204    
1205            /**
1206             * Returns an ordered range of all the subscriptions where userId = &#63; and classNameId = &#63;.
1207             *
1208             * <p>
1209             * 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 SubscriptionModelImpl}. 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.
1210             * </p>
1211             *
1212             * @param userId the user ID
1213             * @param classNameId the class name ID
1214             * @param start the lower bound of the range of subscriptions
1215             * @param end the upper bound of the range of subscriptions (not inclusive)
1216             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1217             * @param retrieveFromCache whether to retrieve from the finder cache
1218             * @return the ordered range of matching subscriptions
1219             */
1220            @Override
1221            public List<Subscription> findByU_C(long userId, long classNameId,
1222                    int start, int end, OrderByComparator<Subscription> orderByComparator,
1223                    boolean retrieveFromCache) {
1224                    boolean pagination = true;
1225                    FinderPath finderPath = null;
1226                    Object[] finderArgs = null;
1227    
1228                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1229                                    (orderByComparator == null)) {
1230                            pagination = false;
1231                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
1232                            finderArgs = new Object[] { userId, classNameId };
1233                    }
1234                    else {
1235                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
1236                            finderArgs = new Object[] {
1237                                            userId, classNameId,
1238                                            
1239                                            start, end, orderByComparator
1240                                    };
1241                    }
1242    
1243                    List<Subscription> list = null;
1244    
1245                    if (retrieveFromCache) {
1246                            list = (List<Subscription>)finderCache.getResult(finderPath,
1247                                            finderArgs, this);
1248    
1249                            if ((list != null) && !list.isEmpty()) {
1250                                    for (Subscription subscription : list) {
1251                                            if ((userId != subscription.getUserId()) ||
1252                                                            (classNameId != subscription.getClassNameId())) {
1253                                                    list = null;
1254    
1255                                                    break;
1256                                            }
1257                                    }
1258                            }
1259                    }
1260    
1261                    if (list == null) {
1262                            StringBundler query = null;
1263    
1264                            if (orderByComparator != null) {
1265                                    query = new StringBundler(4 +
1266                                                    (orderByComparator.getOrderByFields().length * 3));
1267                            }
1268                            else {
1269                                    query = new StringBundler(4);
1270                            }
1271    
1272                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1273    
1274                            query.append(_FINDER_COLUMN_U_C_USERID_2);
1275    
1276                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1277    
1278                            if (orderByComparator != null) {
1279                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1280                                            orderByComparator);
1281                            }
1282                            else
1283                             if (pagination) {
1284                                    query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1285                            }
1286    
1287                            String sql = query.toString();
1288    
1289                            Session session = null;
1290    
1291                            try {
1292                                    session = openSession();
1293    
1294                                    Query q = session.createQuery(sql);
1295    
1296                                    QueryPos qPos = QueryPos.getInstance(q);
1297    
1298                                    qPos.add(userId);
1299    
1300                                    qPos.add(classNameId);
1301    
1302                                    if (!pagination) {
1303                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1304                                                            start, end, false);
1305    
1306                                            Collections.sort(list);
1307    
1308                                            list = Collections.unmodifiableList(list);
1309                                    }
1310                                    else {
1311                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1312                                                            start, end);
1313                                    }
1314    
1315                                    cacheResult(list);
1316    
1317                                    finderCache.putResult(finderPath, finderArgs, list);
1318                            }
1319                            catch (Exception e) {
1320                                    finderCache.removeResult(finderPath, finderArgs);
1321    
1322                                    throw processException(e);
1323                            }
1324                            finally {
1325                                    closeSession(session);
1326                            }
1327                    }
1328    
1329                    return list;
1330            }
1331    
1332            /**
1333             * Returns the first subscription in the ordered set where userId = &#63; and classNameId = &#63;.
1334             *
1335             * @param userId the user ID
1336             * @param classNameId the class name ID
1337             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1338             * @return the first matching subscription
1339             * @throws NoSuchSubscriptionException if a matching subscription could not be found
1340             */
1341            @Override
1342            public Subscription findByU_C_First(long userId, long classNameId,
1343                    OrderByComparator<Subscription> orderByComparator)
1344                    throws NoSuchSubscriptionException {
1345                    Subscription subscription = fetchByU_C_First(userId, classNameId,
1346                                    orderByComparator);
1347    
1348                    if (subscription != null) {
1349                            return subscription;
1350                    }
1351    
1352                    StringBundler msg = new StringBundler(6);
1353    
1354                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1355    
1356                    msg.append("userId=");
1357                    msg.append(userId);
1358    
1359                    msg.append(", classNameId=");
1360                    msg.append(classNameId);
1361    
1362                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1363    
1364                    throw new NoSuchSubscriptionException(msg.toString());
1365            }
1366    
1367            /**
1368             * Returns the first subscription in the ordered set where userId = &#63; and classNameId = &#63;.
1369             *
1370             * @param userId the user ID
1371             * @param classNameId the class name ID
1372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1373             * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found
1374             */
1375            @Override
1376            public Subscription fetchByU_C_First(long userId, long classNameId,
1377                    OrderByComparator<Subscription> orderByComparator) {
1378                    List<Subscription> list = findByU_C(userId, classNameId, 0, 1,
1379                                    orderByComparator);
1380    
1381                    if (!list.isEmpty()) {
1382                            return list.get(0);
1383                    }
1384    
1385                    return null;
1386            }
1387    
1388            /**
1389             * Returns the last subscription in the ordered set where userId = &#63; and classNameId = &#63;.
1390             *
1391             * @param userId the user ID
1392             * @param classNameId the class name ID
1393             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1394             * @return the last matching subscription
1395             * @throws NoSuchSubscriptionException if a matching subscription could not be found
1396             */
1397            @Override
1398            public Subscription findByU_C_Last(long userId, long classNameId,
1399                    OrderByComparator<Subscription> orderByComparator)
1400                    throws NoSuchSubscriptionException {
1401                    Subscription subscription = fetchByU_C_Last(userId, classNameId,
1402                                    orderByComparator);
1403    
1404                    if (subscription != null) {
1405                            return subscription;
1406                    }
1407    
1408                    StringBundler msg = new StringBundler(6);
1409    
1410                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1411    
1412                    msg.append("userId=");
1413                    msg.append(userId);
1414    
1415                    msg.append(", classNameId=");
1416                    msg.append(classNameId);
1417    
1418                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1419    
1420                    throw new NoSuchSubscriptionException(msg.toString());
1421            }
1422    
1423            /**
1424             * Returns the last subscription in the ordered set where userId = &#63; and classNameId = &#63;.
1425             *
1426             * @param userId the user ID
1427             * @param classNameId the class name ID
1428             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1429             * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found
1430             */
1431            @Override
1432            public Subscription fetchByU_C_Last(long userId, long classNameId,
1433                    OrderByComparator<Subscription> orderByComparator) {
1434                    int count = countByU_C(userId, classNameId);
1435    
1436                    if (count == 0) {
1437                            return null;
1438                    }
1439    
1440                    List<Subscription> list = findByU_C(userId, classNameId, count - 1,
1441                                    count, orderByComparator);
1442    
1443                    if (!list.isEmpty()) {
1444                            return list.get(0);
1445                    }
1446    
1447                    return null;
1448            }
1449    
1450            /**
1451             * Returns the subscriptions before and after the current subscription in the ordered set where userId = &#63; and classNameId = &#63;.
1452             *
1453             * @param subscriptionId the primary key of the current subscription
1454             * @param userId the user ID
1455             * @param classNameId the class name ID
1456             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1457             * @return the previous, current, and next subscription
1458             * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found
1459             */
1460            @Override
1461            public Subscription[] findByU_C_PrevAndNext(long subscriptionId,
1462                    long userId, long classNameId,
1463                    OrderByComparator<Subscription> orderByComparator)
1464                    throws NoSuchSubscriptionException {
1465                    Subscription subscription = findByPrimaryKey(subscriptionId);
1466    
1467                    Session session = null;
1468    
1469                    try {
1470                            session = openSession();
1471    
1472                            Subscription[] array = new SubscriptionImpl[3];
1473    
1474                            array[0] = getByU_C_PrevAndNext(session, subscription, userId,
1475                                            classNameId, orderByComparator, true);
1476    
1477                            array[1] = subscription;
1478    
1479                            array[2] = getByU_C_PrevAndNext(session, subscription, userId,
1480                                            classNameId, orderByComparator, false);
1481    
1482                            return array;
1483                    }
1484                    catch (Exception e) {
1485                            throw processException(e);
1486                    }
1487                    finally {
1488                            closeSession(session);
1489                    }
1490            }
1491    
1492            protected Subscription getByU_C_PrevAndNext(Session session,
1493                    Subscription subscription, long userId, long classNameId,
1494                    OrderByComparator<Subscription> orderByComparator, boolean previous) {
1495                    StringBundler query = null;
1496    
1497                    if (orderByComparator != null) {
1498                            query = new StringBundler(6 +
1499                                            (orderByComparator.getOrderByFields().length * 6));
1500                    }
1501                    else {
1502                            query = new StringBundler(3);
1503                    }
1504    
1505                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1506    
1507                    query.append(_FINDER_COLUMN_U_C_USERID_2);
1508    
1509                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1510    
1511                    if (orderByComparator != null) {
1512                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1513    
1514                            if (orderByConditionFields.length > 0) {
1515                                    query.append(WHERE_AND);
1516                            }
1517    
1518                            for (int i = 0; i < orderByConditionFields.length; i++) {
1519                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1520                                    query.append(orderByConditionFields[i]);
1521    
1522                                    if ((i + 1) < orderByConditionFields.length) {
1523                                            if (orderByComparator.isAscending() ^ previous) {
1524                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1525                                            }
1526                                            else {
1527                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1528                                            }
1529                                    }
1530                                    else {
1531                                            if (orderByComparator.isAscending() ^ previous) {
1532                                                    query.append(WHERE_GREATER_THAN);
1533                                            }
1534                                            else {
1535                                                    query.append(WHERE_LESSER_THAN);
1536                                            }
1537                                    }
1538                            }
1539    
1540                            query.append(ORDER_BY_CLAUSE);
1541    
1542                            String[] orderByFields = orderByComparator.getOrderByFields();
1543    
1544                            for (int i = 0; i < orderByFields.length; i++) {
1545                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1546                                    query.append(orderByFields[i]);
1547    
1548                                    if ((i + 1) < orderByFields.length) {
1549                                            if (orderByComparator.isAscending() ^ previous) {
1550                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1551                                            }
1552                                            else {
1553                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1554                                            }
1555                                    }
1556                                    else {
1557                                            if (orderByComparator.isAscending() ^ previous) {
1558                                                    query.append(ORDER_BY_ASC);
1559                                            }
1560                                            else {
1561                                                    query.append(ORDER_BY_DESC);
1562                                            }
1563                                    }
1564                            }
1565                    }
1566                    else {
1567                            query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1568                    }
1569    
1570                    String sql = query.toString();
1571    
1572                    Query q = session.createQuery(sql);
1573    
1574                    q.setFirstResult(0);
1575                    q.setMaxResults(2);
1576    
1577                    QueryPos qPos = QueryPos.getInstance(q);
1578    
1579                    qPos.add(userId);
1580    
1581                    qPos.add(classNameId);
1582    
1583                    if (orderByComparator != null) {
1584                            Object[] values = orderByComparator.getOrderByConditionValues(subscription);
1585    
1586                            for (Object value : values) {
1587                                    qPos.add(value);
1588                            }
1589                    }
1590    
1591                    List<Subscription> list = q.list();
1592    
1593                    if (list.size() == 2) {
1594                            return list.get(1);
1595                    }
1596                    else {
1597                            return null;
1598                    }
1599            }
1600    
1601            /**
1602             * Removes all the subscriptions where userId = &#63; and classNameId = &#63; from the database.
1603             *
1604             * @param userId the user ID
1605             * @param classNameId the class name ID
1606             */
1607            @Override
1608            public void removeByU_C(long userId, long classNameId) {
1609                    for (Subscription subscription : findByU_C(userId, classNameId,
1610                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1611                            remove(subscription);
1612                    }
1613            }
1614    
1615            /**
1616             * Returns the number of subscriptions where userId = &#63; and classNameId = &#63;.
1617             *
1618             * @param userId the user ID
1619             * @param classNameId the class name ID
1620             * @return the number of matching subscriptions
1621             */
1622            @Override
1623            public int countByU_C(long userId, long classNameId) {
1624                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
1625    
1626                    Object[] finderArgs = new Object[] { userId, classNameId };
1627    
1628                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1629    
1630                    if (count == null) {
1631                            StringBundler query = new StringBundler(3);
1632    
1633                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1634    
1635                            query.append(_FINDER_COLUMN_U_C_USERID_2);
1636    
1637                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1638    
1639                            String sql = query.toString();
1640    
1641                            Session session = null;
1642    
1643                            try {
1644                                    session = openSession();
1645    
1646                                    Query q = session.createQuery(sql);
1647    
1648                                    QueryPos qPos = QueryPos.getInstance(q);
1649    
1650                                    qPos.add(userId);
1651    
1652                                    qPos.add(classNameId);
1653    
1654                                    count = (Long)q.uniqueResult();
1655    
1656                                    finderCache.putResult(finderPath, finderArgs, count);
1657                            }
1658                            catch (Exception e) {
1659                                    finderCache.removeResult(finderPath, finderArgs);
1660    
1661                                    throw processException(e);
1662                            }
1663                            finally {
1664                                    closeSession(session);
1665                            }
1666                    }
1667    
1668                    return count.intValue();
1669            }
1670    
1671            private static final String _FINDER_COLUMN_U_C_USERID_2 = "subscription.userId = ? AND ";
1672            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "subscription.classNameId = ?";
1673            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1674                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1675                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
1676                            new String[] {
1677                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1678                                    
1679                            Integer.class.getName(), Integer.class.getName(),
1680                                    OrderByComparator.class.getName()
1681                            });
1682            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1683                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1684                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
1685                            new String[] {
1686                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
1687                            },
1688                            SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1689                            SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1690                            SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1691            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1692                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1693                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
1694                            new String[] {
1695                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
1696                            });
1697    
1698            /**
1699             * Returns all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1700             *
1701             * @param companyId the company ID
1702             * @param classNameId the class name ID
1703             * @param classPK the class p k
1704             * @return the matching subscriptions
1705             */
1706            @Override
1707            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1708                    long classPK) {
1709                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1710                            QueryUtil.ALL_POS, null);
1711            }
1712    
1713            /**
1714             * Returns a range of all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1715             *
1716             * <p>
1717             * 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 SubscriptionModelImpl}. 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.
1718             * </p>
1719             *
1720             * @param companyId the company ID
1721             * @param classNameId the class name ID
1722             * @param classPK the class p k
1723             * @param start the lower bound of the range of subscriptions
1724             * @param end the upper bound of the range of subscriptions (not inclusive)
1725             * @return the range of matching subscriptions
1726             */
1727            @Override
1728            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1729                    long classPK, int start, int end) {
1730                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1731            }
1732    
1733            /**
1734             * Returns an ordered range of all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1735             *
1736             * <p>
1737             * 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 SubscriptionModelImpl}. 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.
1738             * </p>
1739             *
1740             * @param companyId the company ID
1741             * @param classNameId the class name ID
1742             * @param classPK the class p k
1743             * @param start the lower bound of the range of subscriptions
1744             * @param end the upper bound of the range of subscriptions (not inclusive)
1745             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1746             * @return the ordered range of matching subscriptions
1747             */
1748            @Override
1749            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1750                    long classPK, int start, int end,
1751                    OrderByComparator<Subscription> orderByComparator) {
1752                    return findByC_C_C(companyId, classNameId, classPK, start, end,
1753                            orderByComparator, true);
1754            }
1755    
1756            /**
1757             * Returns an ordered range of all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1758             *
1759             * <p>
1760             * 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 SubscriptionModelImpl}. 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.
1761             * </p>
1762             *
1763             * @param companyId the company ID
1764             * @param classNameId the class name ID
1765             * @param classPK the class p k
1766             * @param start the lower bound of the range of subscriptions
1767             * @param end the upper bound of the range of subscriptions (not inclusive)
1768             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1769             * @param retrieveFromCache whether to retrieve from the finder cache
1770             * @return the ordered range of matching subscriptions
1771             */
1772            @Override
1773            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1774                    long classPK, int start, int end,
1775                    OrderByComparator<Subscription> orderByComparator,
1776                    boolean retrieveFromCache) {
1777                    boolean pagination = true;
1778                    FinderPath finderPath = null;
1779                    Object[] finderArgs = null;
1780    
1781                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1782                                    (orderByComparator == null)) {
1783                            pagination = false;
1784                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
1785                            finderArgs = new Object[] { companyId, classNameId, classPK };
1786                    }
1787                    else {
1788                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
1789                            finderArgs = new Object[] {
1790                                            companyId, classNameId, classPK,
1791                                            
1792                                            start, end, orderByComparator
1793                                    };
1794                    }
1795    
1796                    List<Subscription> list = null;
1797    
1798                    if (retrieveFromCache) {
1799                            list = (List<Subscription>)finderCache.getResult(finderPath,
1800                                            finderArgs, this);
1801    
1802                            if ((list != null) && !list.isEmpty()) {
1803                                    for (Subscription subscription : list) {
1804                                            if ((companyId != subscription.getCompanyId()) ||
1805                                                            (classNameId != subscription.getClassNameId()) ||
1806                                                            (classPK != subscription.getClassPK())) {
1807                                                    list = null;
1808    
1809                                                    break;
1810                                            }
1811                                    }
1812                            }
1813                    }
1814    
1815                    if (list == null) {
1816                            StringBundler query = null;
1817    
1818                            if (orderByComparator != null) {
1819                                    query = new StringBundler(5 +
1820                                                    (orderByComparator.getOrderByFields().length * 3));
1821                            }
1822                            else {
1823                                    query = new StringBundler(5);
1824                            }
1825    
1826                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1827    
1828                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1829    
1830                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1831    
1832                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1833    
1834                            if (orderByComparator != null) {
1835                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1836                                            orderByComparator);
1837                            }
1838                            else
1839                             if (pagination) {
1840                                    query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1841                            }
1842    
1843                            String sql = query.toString();
1844    
1845                            Session session = null;
1846    
1847                            try {
1848                                    session = openSession();
1849    
1850                                    Query q = session.createQuery(sql);
1851    
1852                                    QueryPos qPos = QueryPos.getInstance(q);
1853    
1854                                    qPos.add(companyId);
1855    
1856                                    qPos.add(classNameId);
1857    
1858                                    qPos.add(classPK);
1859    
1860                                    if (!pagination) {
1861                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1862                                                            start, end, false);
1863    
1864                                            Collections.sort(list);
1865    
1866                                            list = Collections.unmodifiableList(list);
1867                                    }
1868                                    else {
1869                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1870                                                            start, end);
1871                                    }
1872    
1873                                    cacheResult(list);
1874    
1875                                    finderCache.putResult(finderPath, finderArgs, list);
1876                            }
1877                            catch (Exception e) {
1878                                    finderCache.removeResult(finderPath, finderArgs);
1879    
1880                                    throw processException(e);
1881                            }
1882                            finally {
1883                                    closeSession(session);
1884                            }
1885                    }
1886    
1887                    return list;
1888            }
1889    
1890            /**
1891             * Returns the first subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1892             *
1893             * @param companyId the company ID
1894             * @param classNameId the class name ID
1895             * @param classPK the class p k
1896             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1897             * @return the first matching subscription
1898             * @throws NoSuchSubscriptionException if a matching subscription could not be found
1899             */
1900            @Override
1901            public Subscription findByC_C_C_First(long companyId, long classNameId,
1902                    long classPK, OrderByComparator<Subscription> orderByComparator)
1903                    throws NoSuchSubscriptionException {
1904                    Subscription subscription = fetchByC_C_C_First(companyId, classNameId,
1905                                    classPK, orderByComparator);
1906    
1907                    if (subscription != null) {
1908                            return subscription;
1909                    }
1910    
1911                    StringBundler msg = new StringBundler(8);
1912    
1913                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1914    
1915                    msg.append("companyId=");
1916                    msg.append(companyId);
1917    
1918                    msg.append(", classNameId=");
1919                    msg.append(classNameId);
1920    
1921                    msg.append(", classPK=");
1922                    msg.append(classPK);
1923    
1924                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1925    
1926                    throw new NoSuchSubscriptionException(msg.toString());
1927            }
1928    
1929            /**
1930             * Returns the first subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1931             *
1932             * @param companyId the company ID
1933             * @param classNameId the class name ID
1934             * @param classPK the class p k
1935             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1936             * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found
1937             */
1938            @Override
1939            public Subscription fetchByC_C_C_First(long companyId, long classNameId,
1940                    long classPK, OrderByComparator<Subscription> orderByComparator) {
1941                    List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1942                                    0, 1, orderByComparator);
1943    
1944                    if (!list.isEmpty()) {
1945                            return list.get(0);
1946                    }
1947    
1948                    return null;
1949            }
1950    
1951            /**
1952             * Returns the last subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1953             *
1954             * @param companyId the company ID
1955             * @param classNameId the class name ID
1956             * @param classPK the class p k
1957             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1958             * @return the last matching subscription
1959             * @throws NoSuchSubscriptionException if a matching subscription could not be found
1960             */
1961            @Override
1962            public Subscription findByC_C_C_Last(long companyId, long classNameId,
1963                    long classPK, OrderByComparator<Subscription> orderByComparator)
1964                    throws NoSuchSubscriptionException {
1965                    Subscription subscription = fetchByC_C_C_Last(companyId, classNameId,
1966                                    classPK, orderByComparator);
1967    
1968                    if (subscription != null) {
1969                            return subscription;
1970                    }
1971    
1972                    StringBundler msg = new StringBundler(8);
1973    
1974                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1975    
1976                    msg.append("companyId=");
1977                    msg.append(companyId);
1978    
1979                    msg.append(", classNameId=");
1980                    msg.append(classNameId);
1981    
1982                    msg.append(", classPK=");
1983                    msg.append(classPK);
1984    
1985                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1986    
1987                    throw new NoSuchSubscriptionException(msg.toString());
1988            }
1989    
1990            /**
1991             * Returns the last subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1992             *
1993             * @param companyId the company ID
1994             * @param classNameId the class name ID
1995             * @param classPK the class p k
1996             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1997             * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found
1998             */
1999            @Override
2000            public Subscription fetchByC_C_C_Last(long companyId, long classNameId,
2001                    long classPK, OrderByComparator<Subscription> orderByComparator) {
2002                    int count = countByC_C_C(companyId, classNameId, classPK);
2003    
2004                    if (count == 0) {
2005                            return null;
2006                    }
2007    
2008                    List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
2009                                    count - 1, count, orderByComparator);
2010    
2011                    if (!list.isEmpty()) {
2012                            return list.get(0);
2013                    }
2014    
2015                    return null;
2016            }
2017    
2018            /**
2019             * Returns the subscriptions before and after the current subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2020             *
2021             * @param subscriptionId the primary key of the current subscription
2022             * @param companyId the company ID
2023             * @param classNameId the class name ID
2024             * @param classPK the class p k
2025             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2026             * @return the previous, current, and next subscription
2027             * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found
2028             */
2029            @Override
2030            public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId,
2031                    long companyId, long classNameId, long classPK,
2032                    OrderByComparator<Subscription> orderByComparator)
2033                    throws NoSuchSubscriptionException {
2034                    Subscription subscription = findByPrimaryKey(subscriptionId);
2035    
2036                    Session session = null;
2037    
2038                    try {
2039                            session = openSession();
2040    
2041                            Subscription[] array = new SubscriptionImpl[3];
2042    
2043                            array[0] = getByC_C_C_PrevAndNext(session, subscription, companyId,
2044                                            classNameId, classPK, orderByComparator, true);
2045    
2046                            array[1] = subscription;
2047    
2048                            array[2] = getByC_C_C_PrevAndNext(session, subscription, companyId,
2049                                            classNameId, classPK, orderByComparator, false);
2050    
2051                            return array;
2052                    }
2053                    catch (Exception e) {
2054                            throw processException(e);
2055                    }
2056                    finally {
2057                            closeSession(session);
2058                    }
2059            }
2060    
2061            protected Subscription getByC_C_C_PrevAndNext(Session session,
2062                    Subscription subscription, long companyId, long classNameId,
2063                    long classPK, OrderByComparator<Subscription> orderByComparator,
2064                    boolean previous) {
2065                    StringBundler query = null;
2066    
2067                    if (orderByComparator != null) {
2068                            query = new StringBundler(6 +
2069                                            (orderByComparator.getOrderByFields().length * 6));
2070                    }
2071                    else {
2072                            query = new StringBundler(3);
2073                    }
2074    
2075                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
2076    
2077                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2078    
2079                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2080    
2081                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2082    
2083                    if (orderByComparator != null) {
2084                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2085    
2086                            if (orderByConditionFields.length > 0) {
2087                                    query.append(WHERE_AND);
2088                            }
2089    
2090                            for (int i = 0; i < orderByConditionFields.length; i++) {
2091                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2092                                    query.append(orderByConditionFields[i]);
2093    
2094                                    if ((i + 1) < orderByConditionFields.length) {
2095                                            if (orderByComparator.isAscending() ^ previous) {
2096                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2097                                            }
2098                                            else {
2099                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2100                                            }
2101                                    }
2102                                    else {
2103                                            if (orderByComparator.isAscending() ^ previous) {
2104                                                    query.append(WHERE_GREATER_THAN);
2105                                            }
2106                                            else {
2107                                                    query.append(WHERE_LESSER_THAN);
2108                                            }
2109                                    }
2110                            }
2111    
2112                            query.append(ORDER_BY_CLAUSE);
2113    
2114                            String[] orderByFields = orderByComparator.getOrderByFields();
2115    
2116                            for (int i = 0; i < orderByFields.length; i++) {
2117                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2118                                    query.append(orderByFields[i]);
2119    
2120                                    if ((i + 1) < orderByFields.length) {
2121                                            if (orderByComparator.isAscending() ^ previous) {
2122                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2123                                            }
2124                                            else {
2125                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2126                                            }
2127                                    }
2128                                    else {
2129                                            if (orderByComparator.isAscending() ^ previous) {
2130                                                    query.append(ORDER_BY_ASC);
2131                                            }
2132                                            else {
2133                                                    query.append(ORDER_BY_DESC);
2134                                            }
2135                                    }
2136                            }
2137                    }
2138                    else {
2139                            query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
2140                    }
2141    
2142                    String sql = query.toString();
2143    
2144                    Query q = session.createQuery(sql);
2145    
2146                    q.setFirstResult(0);
2147                    q.setMaxResults(2);
2148    
2149                    QueryPos qPos = QueryPos.getInstance(q);
2150    
2151                    qPos.add(companyId);
2152    
2153                    qPos.add(classNameId);
2154    
2155                    qPos.add(classPK);
2156    
2157                    if (orderByComparator != null) {
2158                            Object[] values = orderByComparator.getOrderByConditionValues(subscription);
2159    
2160                            for (Object value : values) {
2161                                    qPos.add(value);
2162                            }
2163                    }
2164    
2165                    List<Subscription> list = q.list();
2166    
2167                    if (list.size() == 2) {
2168                            return list.get(1);
2169                    }
2170                    else {
2171                            return null;
2172                    }
2173            }
2174    
2175            /**
2176             * Removes all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
2177             *
2178             * @param companyId the company ID
2179             * @param classNameId the class name ID
2180             * @param classPK the class p k
2181             */
2182            @Override
2183            public void removeByC_C_C(long companyId, long classNameId, long classPK) {
2184                    for (Subscription subscription : findByC_C_C(companyId, classNameId,
2185                                    classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2186                            remove(subscription);
2187                    }
2188            }
2189    
2190            /**
2191             * Returns the number of subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2192             *
2193             * @param companyId the company ID
2194             * @param classNameId the class name ID
2195             * @param classPK the class p k
2196             * @return the number of matching subscriptions
2197             */
2198            @Override
2199            public int countByC_C_C(long companyId, long classNameId, long classPK) {
2200                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
2201    
2202                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
2203    
2204                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2205    
2206                    if (count == null) {
2207                            StringBundler query = new StringBundler(4);
2208    
2209                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2210    
2211                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2212    
2213                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2214    
2215                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2216    
2217                            String sql = query.toString();
2218    
2219                            Session session = null;
2220    
2221                            try {
2222                                    session = openSession();
2223    
2224                                    Query q = session.createQuery(sql);
2225    
2226                                    QueryPos qPos = QueryPos.getInstance(q);
2227    
2228                                    qPos.add(companyId);
2229    
2230                                    qPos.add(classNameId);
2231    
2232                                    qPos.add(classPK);
2233    
2234                                    count = (Long)q.uniqueResult();
2235    
2236                                    finderCache.putResult(finderPath, finderArgs, count);
2237                            }
2238                            catch (Exception e) {
2239                                    finderCache.removeResult(finderPath, finderArgs);
2240    
2241                                    throw processException(e);
2242                            }
2243                            finally {
2244                                    closeSession(session);
2245                            }
2246                    }
2247    
2248                    return count.intValue();
2249            }
2250    
2251            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2252            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2253            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "subscription.classPK = ?";
2254            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2255                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
2256                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_U_C_C",
2257                            new String[] {
2258                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2259                                    Long.class.getName(),
2260                                    
2261                            Integer.class.getName(), Integer.class.getName(),
2262                                    OrderByComparator.class.getName()
2263                            });
2264            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C =
2265                    new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2266                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
2267                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_U_C_C",
2268                            new String[] {
2269                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2270                                    Long.class.getName()
2271                            },
2272                            SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
2273                            SubscriptionModelImpl.USERID_COLUMN_BITMASK |
2274                            SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2275                            SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
2276            public static final FinderPath FINDER_PATH_FETCH_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2277                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
2278                            FINDER_CLASS_NAME_ENTITY, "fetchByC_U_C_C",
2279                            new String[] {
2280                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2281                                    Long.class.getName()
2282                            },
2283                            SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
2284                            SubscriptionModelImpl.USERID_COLUMN_BITMASK |
2285                            SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2286                            SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
2287            public static final FinderPath FINDER_PATH_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2288                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2289                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_U_C_C",
2290                            new String[] {
2291                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2292                                    Long.class.getName()
2293                            });
2294            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2295                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2296                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_U_C_C",
2297                            new String[] {
2298                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
2299                                    Long.class.getName()
2300                            });
2301    
2302            /**
2303             * Returns all the subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = any &#63;.
2304             *
2305             * <p>
2306             * 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 SubscriptionModelImpl}. 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.
2307             * </p>
2308             *
2309             * @param companyId the company ID
2310             * @param userId the user ID
2311             * @param classNameId the class name ID
2312             * @param classPKs the class p ks
2313             * @return the matching subscriptions
2314             */
2315            @Override
2316            public List<Subscription> findByC_U_C_C(long companyId, long userId,
2317                    long classNameId, long[] classPKs) {
2318                    return findByC_U_C_C(companyId, userId, classNameId, classPKs,
2319                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2320            }
2321    
2322            /**
2323             * Returns a range of all the subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = any &#63;.
2324             *
2325             * <p>
2326             * 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 SubscriptionModelImpl}. 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.
2327             * </p>
2328             *
2329             * @param companyId the company ID
2330             * @param userId the user ID
2331             * @param classNameId the class name ID
2332             * @param classPKs the class p ks
2333             * @param start the lower bound of the range of subscriptions
2334             * @param end the upper bound of the range of subscriptions (not inclusive)
2335             * @return the range of matching subscriptions
2336             */
2337            @Override
2338            public List<Subscription> findByC_U_C_C(long companyId, long userId,
2339                    long classNameId, long[] classPKs, int start, int end) {
2340                    return findByC_U_C_C(companyId, userId, classNameId, classPKs, start,
2341                            end, null);
2342            }
2343    
2344            /**
2345             * Returns an ordered range of all the subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = any &#63;.
2346             *
2347             * <p>
2348             * 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 SubscriptionModelImpl}. 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.
2349             * </p>
2350             *
2351             * @param companyId the company ID
2352             * @param userId the user ID
2353             * @param classNameId the class name ID
2354             * @param classPKs the class p ks
2355             * @param start the lower bound of the range of subscriptions
2356             * @param end the upper bound of the range of subscriptions (not inclusive)
2357             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2358             * @return the ordered range of matching subscriptions
2359             */
2360            @Override
2361            public List<Subscription> findByC_U_C_C(long companyId, long userId,
2362                    long classNameId, long[] classPKs, int start, int end,
2363                    OrderByComparator<Subscription> orderByComparator) {
2364                    return findByC_U_C_C(companyId, userId, classNameId, classPKs, start,
2365                            end, orderByComparator, true);
2366            }
2367    
2368            /**
2369             * Returns an ordered range of all the subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63;, optionally using the finder cache.
2370             *
2371             * <p>
2372             * 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 SubscriptionModelImpl}. 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.
2373             * </p>
2374             *
2375             * @param companyId the company ID
2376             * @param userId the user ID
2377             * @param classNameId the class name ID
2378             * @param classPK the class p k
2379             * @param start the lower bound of the range of subscriptions
2380             * @param end the upper bound of the range of subscriptions (not inclusive)
2381             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2382             * @param retrieveFromCache whether to retrieve from the finder cache
2383             * @return the ordered range of matching subscriptions
2384             */
2385            @Override
2386            public List<Subscription> findByC_U_C_C(long companyId, long userId,
2387                    long classNameId, long[] classPKs, int start, int end,
2388                    OrderByComparator<Subscription> orderByComparator,
2389                    boolean retrieveFromCache) {
2390                    if (classPKs == null) {
2391                            classPKs = new long[0];
2392                    }
2393                    else if (classPKs.length > 1) {
2394                            classPKs = ArrayUtil.unique(classPKs);
2395    
2396                            Arrays.sort(classPKs);
2397                    }
2398    
2399                    if (classPKs.length == 1) {
2400                            Subscription subscription = fetchByC_U_C_C(companyId, userId,
2401                                            classNameId, classPKs[0]);
2402    
2403                            if (subscription == null) {
2404                                    return Collections.emptyList();
2405                            }
2406                            else {
2407                                    List<Subscription> list = new ArrayList<Subscription>(1);
2408    
2409                                    list.add(subscription);
2410    
2411                                    return list;
2412                            }
2413                    }
2414    
2415                    boolean pagination = true;
2416                    Object[] finderArgs = null;
2417    
2418                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2419                                    (orderByComparator == null)) {
2420                            pagination = false;
2421                            finderArgs = new Object[] {
2422                                            companyId, userId, classNameId, StringUtil.merge(classPKs)
2423                                    };
2424                    }
2425                    else {
2426                            finderArgs = new Object[] {
2427                                            companyId, userId, classNameId, StringUtil.merge(classPKs),
2428                                            
2429                                            start, end, orderByComparator
2430                                    };
2431                    }
2432    
2433                    List<Subscription> list = null;
2434    
2435                    if (retrieveFromCache) {
2436                            list = (List<Subscription>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
2437                                            finderArgs, this);
2438    
2439                            if ((list != null) && !list.isEmpty()) {
2440                                    for (Subscription subscription : list) {
2441                                            if ((companyId != subscription.getCompanyId()) ||
2442                                                            (userId != subscription.getUserId()) ||
2443                                                            (classNameId != subscription.getClassNameId()) ||
2444                                                            !ArrayUtil.contains(classPKs,
2445                                                                    subscription.getClassPK())) {
2446                                                    list = null;
2447    
2448                                                    break;
2449                                            }
2450                                    }
2451                            }
2452                    }
2453    
2454                    if (list == null) {
2455                            StringBundler query = new StringBundler();
2456    
2457                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
2458    
2459                            query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2460    
2461                            query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2462    
2463                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2464    
2465                            if (classPKs.length > 0) {
2466                                    query.append(StringPool.OPEN_PARENTHESIS);
2467    
2468                                    query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_7);
2469    
2470                                    query.append(StringUtil.merge(classPKs));
2471    
2472                                    query.append(StringPool.CLOSE_PARENTHESIS);
2473    
2474                                    query.append(StringPool.CLOSE_PARENTHESIS);
2475                            }
2476    
2477                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
2478                                                    1)), query.index() - 1);
2479    
2480                            if (orderByComparator != null) {
2481                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2482                                            orderByComparator);
2483                            }
2484                            else
2485                             if (pagination) {
2486                                    query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
2487                            }
2488    
2489                            String sql = query.toString();
2490    
2491                            Session session = null;
2492    
2493                            try {
2494                                    session = openSession();
2495    
2496                                    Query q = session.createQuery(sql);
2497    
2498                                    QueryPos qPos = QueryPos.getInstance(q);
2499    
2500                                    qPos.add(companyId);
2501    
2502                                    qPos.add(userId);
2503    
2504                                    qPos.add(classNameId);
2505    
2506                                    if (!pagination) {
2507                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2508                                                            start, end, false);
2509    
2510                                            Collections.sort(list);
2511    
2512                                            list = Collections.unmodifiableList(list);
2513                                    }
2514                                    else {
2515                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2516                                                            start, end);
2517                                    }
2518    
2519                                    cacheResult(list);
2520    
2521                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
2522                                            finderArgs, list);
2523                            }
2524                            catch (Exception e) {
2525                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
2526                                            finderArgs);
2527    
2528                                    throw processException(e);
2529                            }
2530                            finally {
2531                                    closeSession(session);
2532                            }
2533                    }
2534    
2535                    return list;
2536            }
2537    
2538            /**
2539             * Returns the subscription where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; or throws a {@link NoSuchSubscriptionException} if it could not be found.
2540             *
2541             * @param companyId the company ID
2542             * @param userId the user ID
2543             * @param classNameId the class name ID
2544             * @param classPK the class p k
2545             * @return the matching subscription
2546             * @throws NoSuchSubscriptionException if a matching subscription could not be found
2547             */
2548            @Override
2549            public Subscription findByC_U_C_C(long companyId, long userId,
2550                    long classNameId, long classPK) throws NoSuchSubscriptionException {
2551                    Subscription subscription = fetchByC_U_C_C(companyId, userId,
2552                                    classNameId, classPK);
2553    
2554                    if (subscription == null) {
2555                            StringBundler msg = new StringBundler(10);
2556    
2557                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2558    
2559                            msg.append("companyId=");
2560                            msg.append(companyId);
2561    
2562                            msg.append(", userId=");
2563                            msg.append(userId);
2564    
2565                            msg.append(", classNameId=");
2566                            msg.append(classNameId);
2567    
2568                            msg.append(", classPK=");
2569                            msg.append(classPK);
2570    
2571                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2572    
2573                            if (_log.isWarnEnabled()) {
2574                                    _log.warn(msg.toString());
2575                            }
2576    
2577                            throw new NoSuchSubscriptionException(msg.toString());
2578                    }
2579    
2580                    return subscription;
2581            }
2582    
2583            /**
2584             * Returns the subscription where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2585             *
2586             * @param companyId the company ID
2587             * @param userId the user ID
2588             * @param classNameId the class name ID
2589             * @param classPK the class p k
2590             * @return the matching subscription, or <code>null</code> if a matching subscription could not be found
2591             */
2592            @Override
2593            public Subscription fetchByC_U_C_C(long companyId, long userId,
2594                    long classNameId, long classPK) {
2595                    return fetchByC_U_C_C(companyId, userId, classNameId, classPK, true);
2596            }
2597    
2598            /**
2599             * Returns the subscription where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2600             *
2601             * @param companyId the company ID
2602             * @param userId the user ID
2603             * @param classNameId the class name ID
2604             * @param classPK the class p k
2605             * @param retrieveFromCache whether to retrieve from the finder cache
2606             * @return the matching subscription, or <code>null</code> if a matching subscription could not be found
2607             */
2608            @Override
2609            public Subscription fetchByC_U_C_C(long companyId, long userId,
2610                    long classNameId, long classPK, boolean retrieveFromCache) {
2611                    Object[] finderArgs = new Object[] {
2612                                    companyId, userId, classNameId, classPK
2613                            };
2614    
2615                    Object result = null;
2616    
2617                    if (retrieveFromCache) {
2618                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2619                                            finderArgs, this);
2620                    }
2621    
2622                    if (result instanceof Subscription) {
2623                            Subscription subscription = (Subscription)result;
2624    
2625                            if ((companyId != subscription.getCompanyId()) ||
2626                                            (userId != subscription.getUserId()) ||
2627                                            (classNameId != subscription.getClassNameId()) ||
2628                                            (classPK != subscription.getClassPK())) {
2629                                    result = null;
2630                            }
2631                    }
2632    
2633                    if (result == null) {
2634                            StringBundler query = new StringBundler(6);
2635    
2636                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
2637    
2638                            query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2639    
2640                            query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2641    
2642                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2643    
2644                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2645    
2646                            String sql = query.toString();
2647    
2648                            Session session = null;
2649    
2650                            try {
2651                                    session = openSession();
2652    
2653                                    Query q = session.createQuery(sql);
2654    
2655                                    QueryPos qPos = QueryPos.getInstance(q);
2656    
2657                                    qPos.add(companyId);
2658    
2659                                    qPos.add(userId);
2660    
2661                                    qPos.add(classNameId);
2662    
2663                                    qPos.add(classPK);
2664    
2665                                    List<Subscription> list = q.list();
2666    
2667                                    if (list.isEmpty()) {
2668                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2669                                                    finderArgs, list);
2670                                    }
2671                                    else {
2672                                            Subscription subscription = list.get(0);
2673    
2674                                            result = subscription;
2675    
2676                                            cacheResult(subscription);
2677    
2678                                            if ((subscription.getCompanyId() != companyId) ||
2679                                                            (subscription.getUserId() != userId) ||
2680                                                            (subscription.getClassNameId() != classNameId) ||
2681                                                            (subscription.getClassPK() != classPK)) {
2682                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2683                                                            finderArgs, subscription);
2684                                            }
2685                                    }
2686                            }
2687                            catch (Exception e) {
2688                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2689                                            finderArgs);
2690    
2691                                    throw processException(e);
2692                            }
2693                            finally {
2694                                    closeSession(session);
2695                            }
2696                    }
2697    
2698                    if (result instanceof List<?>) {
2699                            return null;
2700                    }
2701                    else {
2702                            return (Subscription)result;
2703                    }
2704            }
2705    
2706            /**
2707             * Removes the subscription where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
2708             *
2709             * @param companyId the company ID
2710             * @param userId the user ID
2711             * @param classNameId the class name ID
2712             * @param classPK the class p k
2713             * @return the subscription that was removed
2714             */
2715            @Override
2716            public Subscription removeByC_U_C_C(long companyId, long userId,
2717                    long classNameId, long classPK) throws NoSuchSubscriptionException {
2718                    Subscription subscription = findByC_U_C_C(companyId, userId,
2719                                    classNameId, classPK);
2720    
2721                    return remove(subscription);
2722            }
2723    
2724            /**
2725             * Returns the number of subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63;.
2726             *
2727             * @param companyId the company ID
2728             * @param userId the user ID
2729             * @param classNameId the class name ID
2730             * @param classPK the class p k
2731             * @return the number of matching subscriptions
2732             */
2733            @Override
2734            public int countByC_U_C_C(long companyId, long userId, long classNameId,
2735                    long classPK) {
2736                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U_C_C;
2737    
2738                    Object[] finderArgs = new Object[] {
2739                                    companyId, userId, classNameId, classPK
2740                            };
2741    
2742                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2743    
2744                    if (count == null) {
2745                            StringBundler query = new StringBundler(5);
2746    
2747                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2748    
2749                            query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2750    
2751                            query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2752    
2753                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2754    
2755                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2756    
2757                            String sql = query.toString();
2758    
2759                            Session session = null;
2760    
2761                            try {
2762                                    session = openSession();
2763    
2764                                    Query q = session.createQuery(sql);
2765    
2766                                    QueryPos qPos = QueryPos.getInstance(q);
2767    
2768                                    qPos.add(companyId);
2769    
2770                                    qPos.add(userId);
2771    
2772                                    qPos.add(classNameId);
2773    
2774                                    qPos.add(classPK);
2775    
2776                                    count = (Long)q.uniqueResult();
2777    
2778                                    finderCache.putResult(finderPath, finderArgs, count);
2779                            }
2780                            catch (Exception e) {
2781                                    finderCache.removeResult(finderPath, finderArgs);
2782    
2783                                    throw processException(e);
2784                            }
2785                            finally {
2786                                    closeSession(session);
2787                            }
2788                    }
2789    
2790                    return count.intValue();
2791            }
2792    
2793            /**
2794             * Returns the number of subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = any &#63;.
2795             *
2796             * @param companyId the company ID
2797             * @param userId the user ID
2798             * @param classNameId the class name ID
2799             * @param classPKs the class p ks
2800             * @return the number of matching subscriptions
2801             */
2802            @Override
2803            public int countByC_U_C_C(long companyId, long userId, long classNameId,
2804                    long[] classPKs) {
2805                    if (classPKs == null) {
2806                            classPKs = new long[0];
2807                    }
2808                    else if (classPKs.length > 1) {
2809                            classPKs = ArrayUtil.unique(classPKs);
2810    
2811                            Arrays.sort(classPKs);
2812                    }
2813    
2814                    Object[] finderArgs = new Object[] {
2815                                    companyId, userId, classNameId, StringUtil.merge(classPKs)
2816                            };
2817    
2818                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2819                                    finderArgs, this);
2820    
2821                    if (count == null) {
2822                            StringBundler query = new StringBundler();
2823    
2824                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2825    
2826                            query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2827    
2828                            query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2829    
2830                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2831    
2832                            if (classPKs.length > 0) {
2833                                    query.append(StringPool.OPEN_PARENTHESIS);
2834    
2835                                    query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_7);
2836    
2837                                    query.append(StringUtil.merge(classPKs));
2838    
2839                                    query.append(StringPool.CLOSE_PARENTHESIS);
2840    
2841                                    query.append(StringPool.CLOSE_PARENTHESIS);
2842                            }
2843    
2844                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
2845                                                    1)), query.index() - 1);
2846    
2847                            String sql = query.toString();
2848    
2849                            Session session = null;
2850    
2851                            try {
2852                                    session = openSession();
2853    
2854                                    Query q = session.createQuery(sql);
2855    
2856                                    QueryPos qPos = QueryPos.getInstance(q);
2857    
2858                                    qPos.add(companyId);
2859    
2860                                    qPos.add(userId);
2861    
2862                                    qPos.add(classNameId);
2863    
2864                                    count = (Long)q.uniqueResult();
2865    
2866                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2867                                            finderArgs, count);
2868                            }
2869                            catch (Exception e) {
2870                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2871                                            finderArgs);
2872    
2873                                    throw processException(e);
2874                            }
2875                            finally {
2876                                    closeSession(session);
2877                            }
2878                    }
2879    
2880                    return count.intValue();
2881            }
2882    
2883            private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2884            private static final String _FINDER_COLUMN_C_U_C_C_USERID_2 = "subscription.userId = ? AND ";
2885            private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2886            private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_2 = "subscription.classPK = ?";
2887            private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_7 = "subscription.classPK IN (";
2888    
2889            public SubscriptionPersistenceImpl() {
2890                    setModelClass(Subscription.class);
2891            }
2892    
2893            /**
2894             * Caches the subscription in the entity cache if it is enabled.
2895             *
2896             * @param subscription the subscription
2897             */
2898            @Override
2899            public void cacheResult(Subscription subscription) {
2900                    entityCache.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2901                            SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
2902    
2903                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2904                            new Object[] {
2905                                    subscription.getCompanyId(), subscription.getUserId(),
2906                                    subscription.getClassNameId(), subscription.getClassPK()
2907                            }, subscription);
2908    
2909                    subscription.resetOriginalValues();
2910            }
2911    
2912            /**
2913             * Caches the subscriptions in the entity cache if it is enabled.
2914             *
2915             * @param subscriptions the subscriptions
2916             */
2917            @Override
2918            public void cacheResult(List<Subscription> subscriptions) {
2919                    for (Subscription subscription : subscriptions) {
2920                            if (entityCache.getResult(
2921                                                    SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2922                                                    SubscriptionImpl.class, subscription.getPrimaryKey()) == null) {
2923                                    cacheResult(subscription);
2924                            }
2925                            else {
2926                                    subscription.resetOriginalValues();
2927                            }
2928                    }
2929            }
2930    
2931            /**
2932             * Clears the cache for all subscriptions.
2933             *
2934             * <p>
2935             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
2936             * </p>
2937             */
2938            @Override
2939            public void clearCache() {
2940                    entityCache.clearCache(SubscriptionImpl.class);
2941    
2942                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
2943                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2944                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2945            }
2946    
2947            /**
2948             * Clears the cache for the subscription.
2949             *
2950             * <p>
2951             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
2952             * </p>
2953             */
2954            @Override
2955            public void clearCache(Subscription subscription) {
2956                    entityCache.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2957                            SubscriptionImpl.class, subscription.getPrimaryKey());
2958    
2959                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2960                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2961    
2962                    clearUniqueFindersCache((SubscriptionModelImpl)subscription);
2963            }
2964    
2965            @Override
2966            public void clearCache(List<Subscription> subscriptions) {
2967                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2968                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2969    
2970                    for (Subscription subscription : subscriptions) {
2971                            entityCache.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2972                                    SubscriptionImpl.class, subscription.getPrimaryKey());
2973    
2974                            clearUniqueFindersCache((SubscriptionModelImpl)subscription);
2975                    }
2976            }
2977    
2978            protected void cacheUniqueFindersCache(
2979                    SubscriptionModelImpl subscriptionModelImpl, boolean isNew) {
2980                    if (isNew) {
2981                            Object[] args = new Object[] {
2982                                            subscriptionModelImpl.getCompanyId(),
2983                                            subscriptionModelImpl.getUserId(),
2984                                            subscriptionModelImpl.getClassNameId(),
2985                                            subscriptionModelImpl.getClassPK()
2986                                    };
2987    
2988                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2989                                    Long.valueOf(1));
2990                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2991                                    subscriptionModelImpl);
2992                    }
2993                    else {
2994                            if ((subscriptionModelImpl.getColumnBitmask() &
2995                                            FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2996                                    Object[] args = new Object[] {
2997                                                    subscriptionModelImpl.getCompanyId(),
2998                                                    subscriptionModelImpl.getUserId(),
2999                                                    subscriptionModelImpl.getClassNameId(),
3000                                                    subscriptionModelImpl.getClassPK()
3001                                            };
3002    
3003                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
3004                                            Long.valueOf(1));
3005                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
3006                                            subscriptionModelImpl);
3007                            }
3008                    }
3009            }
3010    
3011            protected void clearUniqueFindersCache(
3012                    SubscriptionModelImpl subscriptionModelImpl) {
3013                    Object[] args = new Object[] {
3014                                    subscriptionModelImpl.getCompanyId(),
3015                                    subscriptionModelImpl.getUserId(),
3016                                    subscriptionModelImpl.getClassNameId(),
3017                                    subscriptionModelImpl.getClassPK()
3018                            };
3019    
3020                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
3021                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
3022    
3023                    if ((subscriptionModelImpl.getColumnBitmask() &
3024                                    FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
3025                            args = new Object[] {
3026                                            subscriptionModelImpl.getOriginalCompanyId(),
3027                                            subscriptionModelImpl.getOriginalUserId(),
3028                                            subscriptionModelImpl.getOriginalClassNameId(),
3029                                            subscriptionModelImpl.getOriginalClassPK()
3030                                    };
3031    
3032                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
3033                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
3034                    }
3035            }
3036    
3037            /**
3038             * Creates a new subscription with the primary key. Does not add the subscription to the database.
3039             *
3040             * @param subscriptionId the primary key for the new subscription
3041             * @return the new subscription
3042             */
3043            @Override
3044            public Subscription create(long subscriptionId) {
3045                    Subscription subscription = new SubscriptionImpl();
3046    
3047                    subscription.setNew(true);
3048                    subscription.setPrimaryKey(subscriptionId);
3049    
3050                    return subscription;
3051            }
3052    
3053            /**
3054             * Removes the subscription with the primary key from the database. Also notifies the appropriate model listeners.
3055             *
3056             * @param subscriptionId the primary key of the subscription
3057             * @return the subscription that was removed
3058             * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found
3059             */
3060            @Override
3061            public Subscription remove(long subscriptionId)
3062                    throws NoSuchSubscriptionException {
3063                    return remove((Serializable)subscriptionId);
3064            }
3065    
3066            /**
3067             * Removes the subscription with the primary key from the database. Also notifies the appropriate model listeners.
3068             *
3069             * @param primaryKey the primary key of the subscription
3070             * @return the subscription that was removed
3071             * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found
3072             */
3073            @Override
3074            public Subscription remove(Serializable primaryKey)
3075                    throws NoSuchSubscriptionException {
3076                    Session session = null;
3077    
3078                    try {
3079                            session = openSession();
3080    
3081                            Subscription subscription = (Subscription)session.get(SubscriptionImpl.class,
3082                                            primaryKey);
3083    
3084                            if (subscription == null) {
3085                                    if (_log.isWarnEnabled()) {
3086                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3087                                    }
3088    
3089                                    throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3090                                            primaryKey);
3091                            }
3092    
3093                            return remove(subscription);
3094                    }
3095                    catch (NoSuchSubscriptionException nsee) {
3096                            throw nsee;
3097                    }
3098                    catch (Exception e) {
3099                            throw processException(e);
3100                    }
3101                    finally {
3102                            closeSession(session);
3103                    }
3104            }
3105    
3106            @Override
3107            protected Subscription removeImpl(Subscription subscription) {
3108                    subscription = toUnwrappedModel(subscription);
3109    
3110                    Session session = null;
3111    
3112                    try {
3113                            session = openSession();
3114    
3115                            if (!session.contains(subscription)) {
3116                                    subscription = (Subscription)session.get(SubscriptionImpl.class,
3117                                                    subscription.getPrimaryKeyObj());
3118                            }
3119    
3120                            if (subscription != null) {
3121                                    session.delete(subscription);
3122                            }
3123                    }
3124                    catch (Exception e) {
3125                            throw processException(e);
3126                    }
3127                    finally {
3128                            closeSession(session);
3129                    }
3130    
3131                    if (subscription != null) {
3132                            clearCache(subscription);
3133                    }
3134    
3135                    return subscription;
3136            }
3137    
3138            @Override
3139            public Subscription updateImpl(Subscription subscription) {
3140                    subscription = toUnwrappedModel(subscription);
3141    
3142                    boolean isNew = subscription.isNew();
3143    
3144                    SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
3145    
3146                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
3147    
3148                    Date now = new Date();
3149    
3150                    if (isNew && (subscription.getCreateDate() == null)) {
3151                            if (serviceContext == null) {
3152                                    subscription.setCreateDate(now);
3153                            }
3154                            else {
3155                                    subscription.setCreateDate(serviceContext.getCreateDate(now));
3156                            }
3157                    }
3158    
3159                    if (!subscriptionModelImpl.hasSetModifiedDate()) {
3160                            if (serviceContext == null) {
3161                                    subscription.setModifiedDate(now);
3162                            }
3163                            else {
3164                                    subscription.setModifiedDate(serviceContext.getModifiedDate(now));
3165                            }
3166                    }
3167    
3168                    Session session = null;
3169    
3170                    try {
3171                            session = openSession();
3172    
3173                            if (subscription.isNew()) {
3174                                    session.save(subscription);
3175    
3176                                    subscription.setNew(false);
3177                            }
3178                            else {
3179                                    subscription = (Subscription)session.merge(subscription);
3180                            }
3181                    }
3182                    catch (Exception e) {
3183                            throw processException(e);
3184                    }
3185                    finally {
3186                            closeSession(session);
3187                    }
3188    
3189                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3190    
3191                    if (isNew || !SubscriptionModelImpl.COLUMN_BITMASK_ENABLED) {
3192                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3193                    }
3194    
3195                    else {
3196                            if ((subscriptionModelImpl.getColumnBitmask() &
3197                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
3198                                    Object[] args = new Object[] {
3199                                                    subscriptionModelImpl.getOriginalUserId()
3200                                            };
3201    
3202                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
3203                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
3204                                            args);
3205    
3206                                    args = new Object[] { subscriptionModelImpl.getUserId() };
3207    
3208                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
3209                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
3210                                            args);
3211                            }
3212    
3213                            if ((subscriptionModelImpl.getColumnBitmask() &
3214                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
3215                                    Object[] args = new Object[] {
3216                                                    subscriptionModelImpl.getOriginalGroupId(),
3217                                                    subscriptionModelImpl.getOriginalUserId()
3218                                            };
3219    
3220                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
3221                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
3222                                            args);
3223    
3224                                    args = new Object[] {
3225                                                    subscriptionModelImpl.getGroupId(),
3226                                                    subscriptionModelImpl.getUserId()
3227                                            };
3228    
3229                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
3230                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
3231                                            args);
3232                            }
3233    
3234                            if ((subscriptionModelImpl.getColumnBitmask() &
3235                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
3236                                    Object[] args = new Object[] {
3237                                                    subscriptionModelImpl.getOriginalUserId(),
3238                                                    subscriptionModelImpl.getOriginalClassNameId()
3239                                            };
3240    
3241                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
3242                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
3243                                            args);
3244    
3245                                    args = new Object[] {
3246                                                    subscriptionModelImpl.getUserId(),
3247                                                    subscriptionModelImpl.getClassNameId()
3248                                            };
3249    
3250                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
3251                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
3252                                            args);
3253                            }
3254    
3255                            if ((subscriptionModelImpl.getColumnBitmask() &
3256                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
3257                                    Object[] args = new Object[] {
3258                                                    subscriptionModelImpl.getOriginalCompanyId(),
3259                                                    subscriptionModelImpl.getOriginalClassNameId(),
3260                                                    subscriptionModelImpl.getOriginalClassPK()
3261                                            };
3262    
3263                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
3264                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
3265                                            args);
3266    
3267                                    args = new Object[] {
3268                                                    subscriptionModelImpl.getCompanyId(),
3269                                                    subscriptionModelImpl.getClassNameId(),
3270                                                    subscriptionModelImpl.getClassPK()
3271                                            };
3272    
3273                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
3274                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
3275                                            args);
3276                            }
3277    
3278                            if ((subscriptionModelImpl.getColumnBitmask() &
3279                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C.getColumnBitmask()) != 0) {
3280                                    Object[] args = new Object[] {
3281                                                    subscriptionModelImpl.getOriginalCompanyId(),
3282                                                    subscriptionModelImpl.getOriginalUserId(),
3283                                                    subscriptionModelImpl.getOriginalClassNameId(),
3284                                                    subscriptionModelImpl.getOriginalClassPK()
3285                                            };
3286    
3287                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
3288                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
3289                                            args);
3290    
3291                                    args = new Object[] {
3292                                                    subscriptionModelImpl.getCompanyId(),
3293                                                    subscriptionModelImpl.getUserId(),
3294                                                    subscriptionModelImpl.getClassNameId(),
3295                                                    subscriptionModelImpl.getClassPK()
3296                                            };
3297    
3298                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
3299                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
3300                                            args);
3301                            }
3302                    }
3303    
3304                    entityCache.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3305                            SubscriptionImpl.class, subscription.getPrimaryKey(), subscription,
3306                            false);
3307    
3308                    clearUniqueFindersCache(subscriptionModelImpl);
3309                    cacheUniqueFindersCache(subscriptionModelImpl, isNew);
3310    
3311                    subscription.resetOriginalValues();
3312    
3313                    return subscription;
3314            }
3315    
3316            protected Subscription toUnwrappedModel(Subscription subscription) {
3317                    if (subscription instanceof SubscriptionImpl) {
3318                            return subscription;
3319                    }
3320    
3321                    SubscriptionImpl subscriptionImpl = new SubscriptionImpl();
3322    
3323                    subscriptionImpl.setNew(subscription.isNew());
3324                    subscriptionImpl.setPrimaryKey(subscription.getPrimaryKey());
3325    
3326                    subscriptionImpl.setMvccVersion(subscription.getMvccVersion());
3327                    subscriptionImpl.setSubscriptionId(subscription.getSubscriptionId());
3328                    subscriptionImpl.setGroupId(subscription.getGroupId());
3329                    subscriptionImpl.setCompanyId(subscription.getCompanyId());
3330                    subscriptionImpl.setUserId(subscription.getUserId());
3331                    subscriptionImpl.setUserName(subscription.getUserName());
3332                    subscriptionImpl.setCreateDate(subscription.getCreateDate());
3333                    subscriptionImpl.setModifiedDate(subscription.getModifiedDate());
3334                    subscriptionImpl.setClassNameId(subscription.getClassNameId());
3335                    subscriptionImpl.setClassPK(subscription.getClassPK());
3336                    subscriptionImpl.setFrequency(subscription.getFrequency());
3337    
3338                    return subscriptionImpl;
3339            }
3340    
3341            /**
3342             * Returns the subscription with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
3343             *
3344             * @param primaryKey the primary key of the subscription
3345             * @return the subscription
3346             * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found
3347             */
3348            @Override
3349            public Subscription findByPrimaryKey(Serializable primaryKey)
3350                    throws NoSuchSubscriptionException {
3351                    Subscription subscription = fetchByPrimaryKey(primaryKey);
3352    
3353                    if (subscription == null) {
3354                            if (_log.isWarnEnabled()) {
3355                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3356                            }
3357    
3358                            throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3359                                    primaryKey);
3360                    }
3361    
3362                    return subscription;
3363            }
3364    
3365            /**
3366             * Returns the subscription with the primary key or throws a {@link NoSuchSubscriptionException} if it could not be found.
3367             *
3368             * @param subscriptionId the primary key of the subscription
3369             * @return the subscription
3370             * @throws NoSuchSubscriptionException if a subscription with the primary key could not be found
3371             */
3372            @Override
3373            public Subscription findByPrimaryKey(long subscriptionId)
3374                    throws NoSuchSubscriptionException {
3375                    return findByPrimaryKey((Serializable)subscriptionId);
3376            }
3377    
3378            /**
3379             * Returns the subscription with the primary key or returns <code>null</code> if it could not be found.
3380             *
3381             * @param primaryKey the primary key of the subscription
3382             * @return the subscription, or <code>null</code> if a subscription with the primary key could not be found
3383             */
3384            @Override
3385            public Subscription fetchByPrimaryKey(Serializable primaryKey) {
3386                    Subscription subscription = (Subscription)entityCache.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3387                                    SubscriptionImpl.class, primaryKey);
3388    
3389                    if (subscription == _nullSubscription) {
3390                            return null;
3391                    }
3392    
3393                    if (subscription == null) {
3394                            Session session = null;
3395    
3396                            try {
3397                                    session = openSession();
3398    
3399                                    subscription = (Subscription)session.get(SubscriptionImpl.class,
3400                                                    primaryKey);
3401    
3402                                    if (subscription != null) {
3403                                            cacheResult(subscription);
3404                                    }
3405                                    else {
3406                                            entityCache.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3407                                                    SubscriptionImpl.class, primaryKey, _nullSubscription);
3408                                    }
3409                            }
3410                            catch (Exception e) {
3411                                    entityCache.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3412                                            SubscriptionImpl.class, primaryKey);
3413    
3414                                    throw processException(e);
3415                            }
3416                            finally {
3417                                    closeSession(session);
3418                            }
3419                    }
3420    
3421                    return subscription;
3422            }
3423    
3424            /**
3425             * Returns the subscription with the primary key or returns <code>null</code> if it could not be found.
3426             *
3427             * @param subscriptionId the primary key of the subscription
3428             * @return the subscription, or <code>null</code> if a subscription with the primary key could not be found
3429             */
3430            @Override
3431            public Subscription fetchByPrimaryKey(long subscriptionId) {
3432                    return fetchByPrimaryKey((Serializable)subscriptionId);
3433            }
3434    
3435            @Override
3436            public Map<Serializable, Subscription> fetchByPrimaryKeys(
3437                    Set<Serializable> primaryKeys) {
3438                    if (primaryKeys.isEmpty()) {
3439                            return Collections.emptyMap();
3440                    }
3441    
3442                    Map<Serializable, Subscription> map = new HashMap<Serializable, Subscription>();
3443    
3444                    if (primaryKeys.size() == 1) {
3445                            Iterator<Serializable> iterator = primaryKeys.iterator();
3446    
3447                            Serializable primaryKey = iterator.next();
3448    
3449                            Subscription subscription = fetchByPrimaryKey(primaryKey);
3450    
3451                            if (subscription != null) {
3452                                    map.put(primaryKey, subscription);
3453                            }
3454    
3455                            return map;
3456                    }
3457    
3458                    Set<Serializable> uncachedPrimaryKeys = null;
3459    
3460                    for (Serializable primaryKey : primaryKeys) {
3461                            Subscription subscription = (Subscription)entityCache.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3462                                            SubscriptionImpl.class, primaryKey);
3463    
3464                            if (subscription == null) {
3465                                    if (uncachedPrimaryKeys == null) {
3466                                            uncachedPrimaryKeys = new HashSet<Serializable>();
3467                                    }
3468    
3469                                    uncachedPrimaryKeys.add(primaryKey);
3470                            }
3471                            else {
3472                                    map.put(primaryKey, subscription);
3473                            }
3474                    }
3475    
3476                    if (uncachedPrimaryKeys == null) {
3477                            return map;
3478                    }
3479    
3480                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3481                                    1);
3482    
3483                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE_PKS_IN);
3484    
3485                    for (Serializable primaryKey : uncachedPrimaryKeys) {
3486                            query.append(String.valueOf(primaryKey));
3487    
3488                            query.append(StringPool.COMMA);
3489                    }
3490    
3491                    query.setIndex(query.index() - 1);
3492    
3493                    query.append(StringPool.CLOSE_PARENTHESIS);
3494    
3495                    String sql = query.toString();
3496    
3497                    Session session = null;
3498    
3499                    try {
3500                            session = openSession();
3501    
3502                            Query q = session.createQuery(sql);
3503    
3504                            for (Subscription subscription : (List<Subscription>)q.list()) {
3505                                    map.put(subscription.getPrimaryKeyObj(), subscription);
3506    
3507                                    cacheResult(subscription);
3508    
3509                                    uncachedPrimaryKeys.remove(subscription.getPrimaryKeyObj());
3510                            }
3511    
3512                            for (Serializable primaryKey : uncachedPrimaryKeys) {
3513                                    entityCache.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
3514                                            SubscriptionImpl.class, primaryKey, _nullSubscription);
3515                            }
3516                    }
3517                    catch (Exception e) {
3518                            throw processException(e);
3519                    }
3520                    finally {
3521                            closeSession(session);
3522                    }
3523    
3524                    return map;
3525            }
3526    
3527            /**
3528             * Returns all the subscriptions.
3529             *
3530             * @return the subscriptions
3531             */
3532            @Override
3533            public List<Subscription> findAll() {
3534                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3535            }
3536    
3537            /**
3538             * Returns a range of all the subscriptions.
3539             *
3540             * <p>
3541             * 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 SubscriptionModelImpl}. 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.
3542             * </p>
3543             *
3544             * @param start the lower bound of the range of subscriptions
3545             * @param end the upper bound of the range of subscriptions (not inclusive)
3546             * @return the range of subscriptions
3547             */
3548            @Override
3549            public List<Subscription> findAll(int start, int end) {
3550                    return findAll(start, end, null);
3551            }
3552    
3553            /**
3554             * Returns an ordered range of all the subscriptions.
3555             *
3556             * <p>
3557             * 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 SubscriptionModelImpl}. 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.
3558             * </p>
3559             *
3560             * @param start the lower bound of the range of subscriptions
3561             * @param end the upper bound of the range of subscriptions (not inclusive)
3562             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3563             * @return the ordered range of subscriptions
3564             */
3565            @Override
3566            public List<Subscription> findAll(int start, int end,
3567                    OrderByComparator<Subscription> orderByComparator) {
3568                    return findAll(start, end, orderByComparator, true);
3569            }
3570    
3571            /**
3572             * Returns an ordered range of all the subscriptions.
3573             *
3574             * <p>
3575             * 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 SubscriptionModelImpl}. 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.
3576             * </p>
3577             *
3578             * @param start the lower bound of the range of subscriptions
3579             * @param end the upper bound of the range of subscriptions (not inclusive)
3580             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3581             * @param retrieveFromCache whether to retrieve from the finder cache
3582             * @return the ordered range of subscriptions
3583             */
3584            @Override
3585            public List<Subscription> findAll(int start, int end,
3586                    OrderByComparator<Subscription> orderByComparator,
3587                    boolean retrieveFromCache) {
3588                    boolean pagination = true;
3589                    FinderPath finderPath = null;
3590                    Object[] finderArgs = null;
3591    
3592                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3593                                    (orderByComparator == null)) {
3594                            pagination = false;
3595                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3596                            finderArgs = FINDER_ARGS_EMPTY;
3597                    }
3598                    else {
3599                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3600                            finderArgs = new Object[] { start, end, orderByComparator };
3601                    }
3602    
3603                    List<Subscription> list = null;
3604    
3605                    if (retrieveFromCache) {
3606                            list = (List<Subscription>)finderCache.getResult(finderPath,
3607                                            finderArgs, this);
3608                    }
3609    
3610                    if (list == null) {
3611                            StringBundler query = null;
3612                            String sql = null;
3613    
3614                            if (orderByComparator != null) {
3615                                    query = new StringBundler(2 +
3616                                                    (orderByComparator.getOrderByFields().length * 3));
3617    
3618                                    query.append(_SQL_SELECT_SUBSCRIPTION);
3619    
3620                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3621                                            orderByComparator);
3622    
3623                                    sql = query.toString();
3624                            }
3625                            else {
3626                                    sql = _SQL_SELECT_SUBSCRIPTION;
3627    
3628                                    if (pagination) {
3629                                            sql = sql.concat(SubscriptionModelImpl.ORDER_BY_JPQL);
3630                                    }
3631                            }
3632    
3633                            Session session = null;
3634    
3635                            try {
3636                                    session = openSession();
3637    
3638                                    Query q = session.createQuery(sql);
3639    
3640                                    if (!pagination) {
3641                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
3642                                                            start, end, false);
3643    
3644                                            Collections.sort(list);
3645    
3646                                            list = Collections.unmodifiableList(list);
3647                                    }
3648                                    else {
3649                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
3650                                                            start, end);
3651                                    }
3652    
3653                                    cacheResult(list);
3654    
3655                                    finderCache.putResult(finderPath, finderArgs, list);
3656                            }
3657                            catch (Exception e) {
3658                                    finderCache.removeResult(finderPath, finderArgs);
3659    
3660                                    throw processException(e);
3661                            }
3662                            finally {
3663                                    closeSession(session);
3664                            }
3665                    }
3666    
3667                    return list;
3668            }
3669    
3670            /**
3671             * Removes all the subscriptions from the database.
3672             *
3673             */
3674            @Override
3675            public void removeAll() {
3676                    for (Subscription subscription : findAll()) {
3677                            remove(subscription);
3678                    }
3679            }
3680    
3681            /**
3682             * Returns the number of subscriptions.
3683             *
3684             * @return the number of subscriptions
3685             */
3686            @Override
3687            public int countAll() {
3688                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3689                                    FINDER_ARGS_EMPTY, this);
3690    
3691                    if (count == null) {
3692                            Session session = null;
3693    
3694                            try {
3695                                    session = openSession();
3696    
3697                                    Query q = session.createQuery(_SQL_COUNT_SUBSCRIPTION);
3698    
3699                                    count = (Long)q.uniqueResult();
3700    
3701                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3702                                            count);
3703                            }
3704                            catch (Exception e) {
3705                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3706                                            FINDER_ARGS_EMPTY);
3707    
3708                                    throw processException(e);
3709                            }
3710                            finally {
3711                                    closeSession(session);
3712                            }
3713                    }
3714    
3715                    return count.intValue();
3716            }
3717    
3718            @Override
3719            protected Map<String, Integer> getTableColumnsMap() {
3720                    return SubscriptionModelImpl.TABLE_COLUMNS_MAP;
3721            }
3722    
3723            /**
3724             * Initializes the subscription persistence.
3725             */
3726            public void afterPropertiesSet() {
3727            }
3728    
3729            public void destroy() {
3730                    entityCache.removeCache(SubscriptionImpl.class.getName());
3731                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3732                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3733                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3734            }
3735    
3736            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3737            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3738            private static final String _SQL_SELECT_SUBSCRIPTION = "SELECT subscription FROM Subscription subscription";
3739            private static final String _SQL_SELECT_SUBSCRIPTION_WHERE_PKS_IN = "SELECT subscription FROM Subscription subscription WHERE subscriptionId IN (";
3740            private static final String _SQL_SELECT_SUBSCRIPTION_WHERE = "SELECT subscription FROM Subscription subscription WHERE ";
3741            private static final String _SQL_COUNT_SUBSCRIPTION = "SELECT COUNT(subscription) FROM Subscription subscription";
3742            private static final String _SQL_COUNT_SUBSCRIPTION_WHERE = "SELECT COUNT(subscription) FROM Subscription subscription WHERE ";
3743            private static final String _ORDER_BY_ENTITY_ALIAS = "subscription.";
3744            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Subscription exists with the primary key ";
3745            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Subscription exists with the key {";
3746            private static final Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class);
3747            private static final Subscription _nullSubscription = new SubscriptionImpl() {
3748                            @Override
3749                            public Object clone() {
3750                                    return this;
3751                            }
3752    
3753                            @Override
3754                            public CacheModel<Subscription> toCacheModel() {
3755                                    return _nullSubscriptionCacheModel;
3756                            }
3757                    };
3758    
3759            private static final CacheModel<Subscription> _nullSubscriptionCacheModel = new NullCacheModel();
3760    
3761            private static class NullCacheModel implements CacheModel<Subscription>,
3762                    MVCCModel {
3763                    @Override
3764                    public long getMvccVersion() {
3765                            return -1;
3766                    }
3767    
3768                    @Override
3769                    public void setMvccVersion(long mvccVersion) {
3770                    }
3771    
3772                    @Override
3773                    public Subscription toEntityModel() {
3774                            return _nullSubscription;
3775                    }
3776            }
3777    }