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