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