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