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