001    /**
002     * Copyright (c) 2000-2013 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;
016    
017    import com.liferay.portal.NoSuchSubscriptionException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.ArrayUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
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.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the subscription service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see SubscriptionPersistence
059     * @see SubscriptionUtil
060     * @generated
061     */
062    public class SubscriptionPersistenceImpl extends BasePersistenceImpl<Subscription>
063            implements SubscriptionPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * 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.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = SubscriptionImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
075                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
076                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
078                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
081                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
084                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
086                            new String[] {
087                                    Long.class.getName(),
088                                    
089                            Integer.class.getName(), Integer.class.getName(),
090                                    OrderByComparator.class.getName()
091                            });
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
093                    new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
094                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
096                            new String[] { Long.class.getName() },
097                            SubscriptionModelImpl.USERID_COLUMN_BITMASK);
098            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
099                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
101                            new String[] { Long.class.getName() });
102    
103            /**
104             * Returns all the subscriptions where userId = &#63;.
105             *
106             * @param userId the user ID
107             * @return the matching subscriptions
108             * @throws SystemException if a system exception occurred
109             */
110            public List<Subscription> findByUserId(long userId)
111                    throws SystemException {
112                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
113            }
114    
115            /**
116             * Returns a range of all the subscriptions where userId = &#63;.
117             *
118             * <p>
119             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
120             * </p>
121             *
122             * @param userId the user ID
123             * @param start the lower bound of the range of subscriptions
124             * @param end the upper bound of the range of subscriptions (not inclusive)
125             * @return the range of matching subscriptions
126             * @throws SystemException if a system exception occurred
127             */
128            public List<Subscription> findByUserId(long userId, int start, int end)
129                    throws SystemException {
130                    return findByUserId(userId, start, end, null);
131            }
132    
133            /**
134             * Returns an ordered range of all the subscriptions where userId = &#63;.
135             *
136             * <p>
137             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
138             * </p>
139             *
140             * @param userId the user ID
141             * @param start the lower bound of the range of subscriptions
142             * @param end the upper bound of the range of subscriptions (not inclusive)
143             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
144             * @return the ordered range of matching subscriptions
145             * @throws SystemException if a system exception occurred
146             */
147            public List<Subscription> findByUserId(long userId, int start, int end,
148                    OrderByComparator orderByComparator) throws SystemException {
149                    boolean pagination = true;
150                    FinderPath finderPath = null;
151                    Object[] finderArgs = null;
152    
153                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
154                                    (orderByComparator == null)) {
155                            pagination = false;
156                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
157                            finderArgs = new Object[] { userId };
158                    }
159                    else {
160                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
161                            finderArgs = new Object[] { userId, start, end, orderByComparator };
162                    }
163    
164                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
165                                    finderArgs, this);
166    
167                    if ((list != null) && !list.isEmpty()) {
168                            for (Subscription subscription : list) {
169                                    if ((userId != subscription.getUserId())) {
170                                            list = null;
171    
172                                            break;
173                                    }
174                            }
175                    }
176    
177                    if (list == null) {
178                            StringBundler query = null;
179    
180                            if (orderByComparator != null) {
181                                    query = new StringBundler(3 +
182                                                    (orderByComparator.getOrderByFields().length * 3));
183                            }
184                            else {
185                                    query = new StringBundler(3);
186                            }
187    
188                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
189    
190                            query.append(_FINDER_COLUMN_USERID_USERID_2);
191    
192                            if (orderByComparator != null) {
193                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
194                                            orderByComparator);
195                            }
196                            else
197                             if (pagination) {
198                                    query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
199                            }
200    
201                            String sql = query.toString();
202    
203                            Session session = null;
204    
205                            try {
206                                    session = openSession();
207    
208                                    Query q = session.createQuery(sql);
209    
210                                    QueryPos qPos = QueryPos.getInstance(q);
211    
212                                    qPos.add(userId);
213    
214                                    if (!pagination) {
215                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
216                                                            start, end, false);
217    
218                                            Collections.sort(list);
219    
220                                            list = new UnmodifiableList<Subscription>(list);
221                                    }
222                                    else {
223                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
224                                                            start, end);
225                                    }
226    
227                                    cacheResult(list);
228    
229                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
230                            }
231                            catch (Exception e) {
232                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
233    
234                                    throw processException(e);
235                            }
236                            finally {
237                                    closeSession(session);
238                            }
239                    }
240    
241                    return list;
242            }
243    
244            /**
245             * Returns the first subscription in the ordered set where userId = &#63;.
246             *
247             * @param userId the user ID
248             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
249             * @return the first matching subscription
250             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
251             * @throws SystemException if a system exception occurred
252             */
253            public Subscription findByUserId_First(long userId,
254                    OrderByComparator orderByComparator)
255                    throws NoSuchSubscriptionException, SystemException {
256                    Subscription subscription = fetchByUserId_First(userId,
257                                    orderByComparator);
258    
259                    if (subscription != null) {
260                            return subscription;
261                    }
262    
263                    StringBundler msg = new StringBundler(4);
264    
265                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
266    
267                    msg.append("userId=");
268                    msg.append(userId);
269    
270                    msg.append(StringPool.CLOSE_CURLY_BRACE);
271    
272                    throw new NoSuchSubscriptionException(msg.toString());
273            }
274    
275            /**
276             * Returns the first subscription in the ordered set where userId = &#63;.
277             *
278             * @param userId the user ID
279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
280             * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found
281             * @throws SystemException if a system exception occurred
282             */
283            public Subscription fetchByUserId_First(long userId,
284                    OrderByComparator orderByComparator) throws SystemException {
285                    List<Subscription> list = findByUserId(userId, 0, 1, orderByComparator);
286    
287                    if (!list.isEmpty()) {
288                            return list.get(0);
289                    }
290    
291                    return null;
292            }
293    
294            /**
295             * Returns the last subscription in the ordered set where userId = &#63;.
296             *
297             * @param userId the user ID
298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
299             * @return the last matching subscription
300             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
301             * @throws SystemException if a system exception occurred
302             */
303            public Subscription findByUserId_Last(long userId,
304                    OrderByComparator orderByComparator)
305                    throws NoSuchSubscriptionException, SystemException {
306                    Subscription subscription = fetchByUserId_Last(userId, orderByComparator);
307    
308                    if (subscription != null) {
309                            return subscription;
310                    }
311    
312                    StringBundler msg = new StringBundler(4);
313    
314                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
315    
316                    msg.append("userId=");
317                    msg.append(userId);
318    
319                    msg.append(StringPool.CLOSE_CURLY_BRACE);
320    
321                    throw new NoSuchSubscriptionException(msg.toString());
322            }
323    
324            /**
325             * Returns the last subscription in the ordered set where userId = &#63;.
326             *
327             * @param userId the user ID
328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
329             * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found
330             * @throws SystemException if a system exception occurred
331             */
332            public Subscription fetchByUserId_Last(long userId,
333                    OrderByComparator orderByComparator) throws SystemException {
334                    int count = countByUserId(userId);
335    
336                    List<Subscription> list = findByUserId(userId, count - 1, count,
337                                    orderByComparator);
338    
339                    if (!list.isEmpty()) {
340                            return list.get(0);
341                    }
342    
343                    return null;
344            }
345    
346            /**
347             * Returns the subscriptions before and after the current subscription in the ordered set where userId = &#63;.
348             *
349             * @param subscriptionId the primary key of the current subscription
350             * @param userId the user ID
351             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
352             * @return the previous, current, and next subscription
353             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
354             * @throws SystemException if a system exception occurred
355             */
356            public Subscription[] findByUserId_PrevAndNext(long subscriptionId,
357                    long userId, OrderByComparator orderByComparator)
358                    throws NoSuchSubscriptionException, SystemException {
359                    Subscription subscription = findByPrimaryKey(subscriptionId);
360    
361                    Session session = null;
362    
363                    try {
364                            session = openSession();
365    
366                            Subscription[] array = new SubscriptionImpl[3];
367    
368                            array[0] = getByUserId_PrevAndNext(session, subscription, userId,
369                                            orderByComparator, true);
370    
371                            array[1] = subscription;
372    
373                            array[2] = getByUserId_PrevAndNext(session, subscription, userId,
374                                            orderByComparator, false);
375    
376                            return array;
377                    }
378                    catch (Exception e) {
379                            throw processException(e);
380                    }
381                    finally {
382                            closeSession(session);
383                    }
384            }
385    
386            protected Subscription getByUserId_PrevAndNext(Session session,
387                    Subscription subscription, long userId,
388                    OrderByComparator orderByComparator, boolean previous) {
389                    StringBundler query = null;
390    
391                    if (orderByComparator != null) {
392                            query = new StringBundler(6 +
393                                            (orderByComparator.getOrderByFields().length * 6));
394                    }
395                    else {
396                            query = new StringBundler(3);
397                    }
398    
399                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
400    
401                    query.append(_FINDER_COLUMN_USERID_USERID_2);
402    
403                    if (orderByComparator != null) {
404                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
405    
406                            if (orderByConditionFields.length > 0) {
407                                    query.append(WHERE_AND);
408                            }
409    
410                            for (int i = 0; i < orderByConditionFields.length; i++) {
411                                    query.append(_ORDER_BY_ENTITY_ALIAS);
412                                    query.append(orderByConditionFields[i]);
413    
414                                    if ((i + 1) < orderByConditionFields.length) {
415                                            if (orderByComparator.isAscending() ^ previous) {
416                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
417                                            }
418                                            else {
419                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
420                                            }
421                                    }
422                                    else {
423                                            if (orderByComparator.isAscending() ^ previous) {
424                                                    query.append(WHERE_GREATER_THAN);
425                                            }
426                                            else {
427                                                    query.append(WHERE_LESSER_THAN);
428                                            }
429                                    }
430                            }
431    
432                            query.append(ORDER_BY_CLAUSE);
433    
434                            String[] orderByFields = orderByComparator.getOrderByFields();
435    
436                            for (int i = 0; i < orderByFields.length; i++) {
437                                    query.append(_ORDER_BY_ENTITY_ALIAS);
438                                    query.append(orderByFields[i]);
439    
440                                    if ((i + 1) < orderByFields.length) {
441                                            if (orderByComparator.isAscending() ^ previous) {
442                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
443                                            }
444                                            else {
445                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
446                                            }
447                                    }
448                                    else {
449                                            if (orderByComparator.isAscending() ^ previous) {
450                                                    query.append(ORDER_BY_ASC);
451                                            }
452                                            else {
453                                                    query.append(ORDER_BY_DESC);
454                                            }
455                                    }
456                            }
457                    }
458                    else {
459                            query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
460                    }
461    
462                    String sql = query.toString();
463    
464                    Query q = session.createQuery(sql);
465    
466                    q.setFirstResult(0);
467                    q.setMaxResults(2);
468    
469                    QueryPos qPos = QueryPos.getInstance(q);
470    
471                    qPos.add(userId);
472    
473                    if (orderByComparator != null) {
474                            Object[] values = orderByComparator.getOrderByConditionValues(subscription);
475    
476                            for (Object value : values) {
477                                    qPos.add(value);
478                            }
479                    }
480    
481                    List<Subscription> list = q.list();
482    
483                    if (list.size() == 2) {
484                            return list.get(1);
485                    }
486                    else {
487                            return null;
488                    }
489            }
490    
491            /**
492             * Removes all the subscriptions where userId = &#63; from the database.
493             *
494             * @param userId the user ID
495             * @throws SystemException if a system exception occurred
496             */
497            public void removeByUserId(long userId) throws SystemException {
498                    for (Subscription subscription : findByUserId(userId,
499                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
500                            remove(subscription);
501                    }
502            }
503    
504            /**
505             * Returns the number of subscriptions where userId = &#63;.
506             *
507             * @param userId the user ID
508             * @return the number of matching subscriptions
509             * @throws SystemException if a system exception occurred
510             */
511            public int countByUserId(long userId) throws SystemException {
512                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
513    
514                    Object[] finderArgs = new Object[] { userId };
515    
516                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
517                                    this);
518    
519                    if (count == null) {
520                            StringBundler query = new StringBundler(2);
521    
522                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
523    
524                            query.append(_FINDER_COLUMN_USERID_USERID_2);
525    
526                            String sql = query.toString();
527    
528                            Session session = null;
529    
530                            try {
531                                    session = openSession();
532    
533                                    Query q = session.createQuery(sql);
534    
535                                    QueryPos qPos = QueryPos.getInstance(q);
536    
537                                    qPos.add(userId);
538    
539                                    count = (Long)q.uniqueResult();
540    
541                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
542                            }
543                            catch (Exception e) {
544                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
545    
546                                    throw processException(e);
547                            }
548                            finally {
549                                    closeSession(session);
550                            }
551                    }
552    
553                    return count.intValue();
554            }
555    
556            private static final String _FINDER_COLUMN_USERID_USERID_2 = "subscription.userId = ?";
557            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
558                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
559                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
560                            new String[] {
561                                    Long.class.getName(), Long.class.getName(),
562                                    
563                            Integer.class.getName(), Integer.class.getName(),
564                                    OrderByComparator.class.getName()
565                            });
566            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
567                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
568                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
569                            new String[] { Long.class.getName(), Long.class.getName() },
570                            SubscriptionModelImpl.USERID_COLUMN_BITMASK |
571                            SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK);
572            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
573                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
574                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
575                            new String[] { Long.class.getName(), Long.class.getName() });
576    
577            /**
578             * Returns all the subscriptions where userId = &#63; and classNameId = &#63;.
579             *
580             * @param userId the user ID
581             * @param classNameId the class name ID
582             * @return the matching subscriptions
583             * @throws SystemException if a system exception occurred
584             */
585            public List<Subscription> findByU_C(long userId, long classNameId)
586                    throws SystemException {
587                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
588                            QueryUtil.ALL_POS, null);
589            }
590    
591            /**
592             * Returns a range of all the subscriptions where userId = &#63; and classNameId = &#63;.
593             *
594             * <p>
595             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
596             * </p>
597             *
598             * @param userId the user ID
599             * @param classNameId the class name ID
600             * @param start the lower bound of the range of subscriptions
601             * @param end the upper bound of the range of subscriptions (not inclusive)
602             * @return the range of matching subscriptions
603             * @throws SystemException if a system exception occurred
604             */
605            public List<Subscription> findByU_C(long userId, long classNameId,
606                    int start, int end) throws SystemException {
607                    return findByU_C(userId, classNameId, start, end, null);
608            }
609    
610            /**
611             * Returns an ordered range of all the subscriptions where userId = &#63; and classNameId = &#63;.
612             *
613             * <p>
614             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
615             * </p>
616             *
617             * @param userId the user ID
618             * @param classNameId the class name ID
619             * @param start the lower bound of the range of subscriptions
620             * @param end the upper bound of the range of subscriptions (not inclusive)
621             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
622             * @return the ordered range of matching subscriptions
623             * @throws SystemException if a system exception occurred
624             */
625            public List<Subscription> findByU_C(long userId, long classNameId,
626                    int start, int end, OrderByComparator orderByComparator)
627                    throws SystemException {
628                    boolean pagination = true;
629                    FinderPath finderPath = null;
630                    Object[] finderArgs = null;
631    
632                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
633                                    (orderByComparator == null)) {
634                            pagination = false;
635                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
636                            finderArgs = new Object[] { userId, classNameId };
637                    }
638                    else {
639                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
640                            finderArgs = new Object[] {
641                                            userId, classNameId,
642                                            
643                                            start, end, orderByComparator
644                                    };
645                    }
646    
647                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
648                                    finderArgs, this);
649    
650                    if ((list != null) && !list.isEmpty()) {
651                            for (Subscription subscription : list) {
652                                    if ((userId != subscription.getUserId()) ||
653                                                    (classNameId != subscription.getClassNameId())) {
654                                            list = null;
655    
656                                            break;
657                                    }
658                            }
659                    }
660    
661                    if (list == null) {
662                            StringBundler query = null;
663    
664                            if (orderByComparator != null) {
665                                    query = new StringBundler(4 +
666                                                    (orderByComparator.getOrderByFields().length * 3));
667                            }
668                            else {
669                                    query = new StringBundler(4);
670                            }
671    
672                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
673    
674                            query.append(_FINDER_COLUMN_U_C_USERID_2);
675    
676                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
677    
678                            if (orderByComparator != null) {
679                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
680                                            orderByComparator);
681                            }
682                            else
683                             if (pagination) {
684                                    query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
685                            }
686    
687                            String sql = query.toString();
688    
689                            Session session = null;
690    
691                            try {
692                                    session = openSession();
693    
694                                    Query q = session.createQuery(sql);
695    
696                                    QueryPos qPos = QueryPos.getInstance(q);
697    
698                                    qPos.add(userId);
699    
700                                    qPos.add(classNameId);
701    
702                                    if (!pagination) {
703                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
704                                                            start, end, false);
705    
706                                            Collections.sort(list);
707    
708                                            list = new UnmodifiableList<Subscription>(list);
709                                    }
710                                    else {
711                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
712                                                            start, end);
713                                    }
714    
715                                    cacheResult(list);
716    
717                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
718                            }
719                            catch (Exception e) {
720                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
721    
722                                    throw processException(e);
723                            }
724                            finally {
725                                    closeSession(session);
726                            }
727                    }
728    
729                    return list;
730            }
731    
732            /**
733             * Returns the first subscription in the ordered set where userId = &#63; and classNameId = &#63;.
734             *
735             * @param userId the user ID
736             * @param classNameId the class name ID
737             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
738             * @return the first matching subscription
739             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
740             * @throws SystemException if a system exception occurred
741             */
742            public Subscription findByU_C_First(long userId, long classNameId,
743                    OrderByComparator orderByComparator)
744                    throws NoSuchSubscriptionException, SystemException {
745                    Subscription subscription = fetchByU_C_First(userId, classNameId,
746                                    orderByComparator);
747    
748                    if (subscription != null) {
749                            return subscription;
750                    }
751    
752                    StringBundler msg = new StringBundler(6);
753    
754                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
755    
756                    msg.append("userId=");
757                    msg.append(userId);
758    
759                    msg.append(", classNameId=");
760                    msg.append(classNameId);
761    
762                    msg.append(StringPool.CLOSE_CURLY_BRACE);
763    
764                    throw new NoSuchSubscriptionException(msg.toString());
765            }
766    
767            /**
768             * Returns the first subscription in the ordered set where userId = &#63; and classNameId = &#63;.
769             *
770             * @param userId the user ID
771             * @param classNameId the class name ID
772             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
773             * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found
774             * @throws SystemException if a system exception occurred
775             */
776            public Subscription fetchByU_C_First(long userId, long classNameId,
777                    OrderByComparator orderByComparator) throws SystemException {
778                    List<Subscription> list = findByU_C(userId, classNameId, 0, 1,
779                                    orderByComparator);
780    
781                    if (!list.isEmpty()) {
782                            return list.get(0);
783                    }
784    
785                    return null;
786            }
787    
788            /**
789             * Returns the last subscription in the ordered set where userId = &#63; and classNameId = &#63;.
790             *
791             * @param userId the user ID
792             * @param classNameId the class name ID
793             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
794             * @return the last matching subscription
795             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
796             * @throws SystemException if a system exception occurred
797             */
798            public Subscription findByU_C_Last(long userId, long classNameId,
799                    OrderByComparator orderByComparator)
800                    throws NoSuchSubscriptionException, SystemException {
801                    Subscription subscription = fetchByU_C_Last(userId, classNameId,
802                                    orderByComparator);
803    
804                    if (subscription != null) {
805                            return subscription;
806                    }
807    
808                    StringBundler msg = new StringBundler(6);
809    
810                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
811    
812                    msg.append("userId=");
813                    msg.append(userId);
814    
815                    msg.append(", classNameId=");
816                    msg.append(classNameId);
817    
818                    msg.append(StringPool.CLOSE_CURLY_BRACE);
819    
820                    throw new NoSuchSubscriptionException(msg.toString());
821            }
822    
823            /**
824             * Returns the last subscription in the ordered set where userId = &#63; and classNameId = &#63;.
825             *
826             * @param userId the user ID
827             * @param classNameId the class name ID
828             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
829             * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found
830             * @throws SystemException if a system exception occurred
831             */
832            public Subscription fetchByU_C_Last(long userId, long classNameId,
833                    OrderByComparator orderByComparator) throws SystemException {
834                    int count = countByU_C(userId, classNameId);
835    
836                    List<Subscription> list = findByU_C(userId, classNameId, count - 1,
837                                    count, orderByComparator);
838    
839                    if (!list.isEmpty()) {
840                            return list.get(0);
841                    }
842    
843                    return null;
844            }
845    
846            /**
847             * Returns the subscriptions before and after the current subscription in the ordered set where userId = &#63; and classNameId = &#63;.
848             *
849             * @param subscriptionId the primary key of the current subscription
850             * @param userId the user ID
851             * @param classNameId the class name ID
852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
853             * @return the previous, current, and next subscription
854             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
855             * @throws SystemException if a system exception occurred
856             */
857            public Subscription[] findByU_C_PrevAndNext(long subscriptionId,
858                    long userId, long classNameId, OrderByComparator orderByComparator)
859                    throws NoSuchSubscriptionException, SystemException {
860                    Subscription subscription = findByPrimaryKey(subscriptionId);
861    
862                    Session session = null;
863    
864                    try {
865                            session = openSession();
866    
867                            Subscription[] array = new SubscriptionImpl[3];
868    
869                            array[0] = getByU_C_PrevAndNext(session, subscription, userId,
870                                            classNameId, orderByComparator, true);
871    
872                            array[1] = subscription;
873    
874                            array[2] = getByU_C_PrevAndNext(session, subscription, userId,
875                                            classNameId, orderByComparator, false);
876    
877                            return array;
878                    }
879                    catch (Exception e) {
880                            throw processException(e);
881                    }
882                    finally {
883                            closeSession(session);
884                    }
885            }
886    
887            protected Subscription getByU_C_PrevAndNext(Session session,
888                    Subscription subscription, long userId, long classNameId,
889                    OrderByComparator orderByComparator, boolean previous) {
890                    StringBundler query = null;
891    
892                    if (orderByComparator != null) {
893                            query = new StringBundler(6 +
894                                            (orderByComparator.getOrderByFields().length * 6));
895                    }
896                    else {
897                            query = new StringBundler(3);
898                    }
899    
900                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
901    
902                    query.append(_FINDER_COLUMN_U_C_USERID_2);
903    
904                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
905    
906                    if (orderByComparator != null) {
907                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
908    
909                            if (orderByConditionFields.length > 0) {
910                                    query.append(WHERE_AND);
911                            }
912    
913                            for (int i = 0; i < orderByConditionFields.length; i++) {
914                                    query.append(_ORDER_BY_ENTITY_ALIAS);
915                                    query.append(orderByConditionFields[i]);
916    
917                                    if ((i + 1) < orderByConditionFields.length) {
918                                            if (orderByComparator.isAscending() ^ previous) {
919                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
920                                            }
921                                            else {
922                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
923                                            }
924                                    }
925                                    else {
926                                            if (orderByComparator.isAscending() ^ previous) {
927                                                    query.append(WHERE_GREATER_THAN);
928                                            }
929                                            else {
930                                                    query.append(WHERE_LESSER_THAN);
931                                            }
932                                    }
933                            }
934    
935                            query.append(ORDER_BY_CLAUSE);
936    
937                            String[] orderByFields = orderByComparator.getOrderByFields();
938    
939                            for (int i = 0; i < orderByFields.length; i++) {
940                                    query.append(_ORDER_BY_ENTITY_ALIAS);
941                                    query.append(orderByFields[i]);
942    
943                                    if ((i + 1) < orderByFields.length) {
944                                            if (orderByComparator.isAscending() ^ previous) {
945                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
946                                            }
947                                            else {
948                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
949                                            }
950                                    }
951                                    else {
952                                            if (orderByComparator.isAscending() ^ previous) {
953                                                    query.append(ORDER_BY_ASC);
954                                            }
955                                            else {
956                                                    query.append(ORDER_BY_DESC);
957                                            }
958                                    }
959                            }
960                    }
961                    else {
962                            query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
963                    }
964    
965                    String sql = query.toString();
966    
967                    Query q = session.createQuery(sql);
968    
969                    q.setFirstResult(0);
970                    q.setMaxResults(2);
971    
972                    QueryPos qPos = QueryPos.getInstance(q);
973    
974                    qPos.add(userId);
975    
976                    qPos.add(classNameId);
977    
978                    if (orderByComparator != null) {
979                            Object[] values = orderByComparator.getOrderByConditionValues(subscription);
980    
981                            for (Object value : values) {
982                                    qPos.add(value);
983                            }
984                    }
985    
986                    List<Subscription> list = q.list();
987    
988                    if (list.size() == 2) {
989                            return list.get(1);
990                    }
991                    else {
992                            return null;
993                    }
994            }
995    
996            /**
997             * Removes all the subscriptions where userId = &#63; and classNameId = &#63; from the database.
998             *
999             * @param userId the user ID
1000             * @param classNameId the class name ID
1001             * @throws SystemException if a system exception occurred
1002             */
1003            public void removeByU_C(long userId, long classNameId)
1004                    throws SystemException {
1005                    for (Subscription subscription : findByU_C(userId, classNameId,
1006                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1007                            remove(subscription);
1008                    }
1009            }
1010    
1011            /**
1012             * Returns the number of subscriptions where userId = &#63; and classNameId = &#63;.
1013             *
1014             * @param userId the user ID
1015             * @param classNameId the class name ID
1016             * @return the number of matching subscriptions
1017             * @throws SystemException if a system exception occurred
1018             */
1019            public int countByU_C(long userId, long classNameId)
1020                    throws SystemException {
1021                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
1022    
1023                    Object[] finderArgs = new Object[] { userId, classNameId };
1024    
1025                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1026                                    this);
1027    
1028                    if (count == null) {
1029                            StringBundler query = new StringBundler(3);
1030    
1031                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1032    
1033                            query.append(_FINDER_COLUMN_U_C_USERID_2);
1034    
1035                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1036    
1037                            String sql = query.toString();
1038    
1039                            Session session = null;
1040    
1041                            try {
1042                                    session = openSession();
1043    
1044                                    Query q = session.createQuery(sql);
1045    
1046                                    QueryPos qPos = QueryPos.getInstance(q);
1047    
1048                                    qPos.add(userId);
1049    
1050                                    qPos.add(classNameId);
1051    
1052                                    count = (Long)q.uniqueResult();
1053    
1054                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1055                            }
1056                            catch (Exception e) {
1057                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1058    
1059                                    throw processException(e);
1060                            }
1061                            finally {
1062                                    closeSession(session);
1063                            }
1064                    }
1065    
1066                    return count.intValue();
1067            }
1068    
1069            private static final String _FINDER_COLUMN_U_C_USERID_2 = "subscription.userId = ? AND ";
1070            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "subscription.classNameId = ?";
1071            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1072                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1073                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_C",
1074                            new String[] {
1075                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1076                                    
1077                            Integer.class.getName(), Integer.class.getName(),
1078                                    OrderByComparator.class.getName()
1079                            });
1080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1081                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_C",
1083                            new String[] {
1084                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
1085                            },
1086                            SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1087                            SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1088                            SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1089            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1090                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
1092                            new String[] {
1093                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
1094                            });
1095    
1096            /**
1097             * Returns all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1098             *
1099             * @param companyId the company ID
1100             * @param classNameId the class name ID
1101             * @param classPK the class p k
1102             * @return the matching subscriptions
1103             * @throws SystemException if a system exception occurred
1104             */
1105            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1106                    long classPK) throws SystemException {
1107                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1108                            QueryUtil.ALL_POS, null);
1109            }
1110    
1111            /**
1112             * Returns a range of all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1113             *
1114             * <p>
1115             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
1116             * </p>
1117             *
1118             * @param companyId the company ID
1119             * @param classNameId the class name ID
1120             * @param classPK the class p k
1121             * @param start the lower bound of the range of subscriptions
1122             * @param end the upper bound of the range of subscriptions (not inclusive)
1123             * @return the range of matching subscriptions
1124             * @throws SystemException if a system exception occurred
1125             */
1126            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1127                    long classPK, int start, int end) throws SystemException {
1128                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1129            }
1130    
1131            /**
1132             * Returns an ordered range of all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1133             *
1134             * <p>
1135             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
1136             * </p>
1137             *
1138             * @param companyId the company ID
1139             * @param classNameId the class name ID
1140             * @param classPK the class p k
1141             * @param start the lower bound of the range of subscriptions
1142             * @param end the upper bound of the range of subscriptions (not inclusive)
1143             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1144             * @return the ordered range of matching subscriptions
1145             * @throws SystemException if a system exception occurred
1146             */
1147            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1148                    long classPK, int start, int end, OrderByComparator orderByComparator)
1149                    throws SystemException {
1150                    boolean pagination = true;
1151                    FinderPath finderPath = null;
1152                    Object[] finderArgs = null;
1153    
1154                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1155                                    (orderByComparator == null)) {
1156                            pagination = false;
1157                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C;
1158                            finderArgs = new Object[] { companyId, classNameId, classPK };
1159                    }
1160                    else {
1161                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_C;
1162                            finderArgs = new Object[] {
1163                                            companyId, classNameId, classPK,
1164                                            
1165                                            start, end, orderByComparator
1166                                    };
1167                    }
1168    
1169                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
1170                                    finderArgs, this);
1171    
1172                    if ((list != null) && !list.isEmpty()) {
1173                            for (Subscription subscription : list) {
1174                                    if ((companyId != subscription.getCompanyId()) ||
1175                                                    (classNameId != subscription.getClassNameId()) ||
1176                                                    (classPK != subscription.getClassPK())) {
1177                                            list = null;
1178    
1179                                            break;
1180                                    }
1181                            }
1182                    }
1183    
1184                    if (list == null) {
1185                            StringBundler query = null;
1186    
1187                            if (orderByComparator != null) {
1188                                    query = new StringBundler(5 +
1189                                                    (orderByComparator.getOrderByFields().length * 3));
1190                            }
1191                            else {
1192                                    query = new StringBundler(5);
1193                            }
1194    
1195                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1196    
1197                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1198    
1199                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1200    
1201                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1202    
1203                            if (orderByComparator != null) {
1204                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1205                                            orderByComparator);
1206                            }
1207                            else
1208                             if (pagination) {
1209                                    query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1210                            }
1211    
1212                            String sql = query.toString();
1213    
1214                            Session session = null;
1215    
1216                            try {
1217                                    session = openSession();
1218    
1219                                    Query q = session.createQuery(sql);
1220    
1221                                    QueryPos qPos = QueryPos.getInstance(q);
1222    
1223                                    qPos.add(companyId);
1224    
1225                                    qPos.add(classNameId);
1226    
1227                                    qPos.add(classPK);
1228    
1229                                    if (!pagination) {
1230                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1231                                                            start, end, false);
1232    
1233                                            Collections.sort(list);
1234    
1235                                            list = new UnmodifiableList<Subscription>(list);
1236                                    }
1237                                    else {
1238                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1239                                                            start, end);
1240                                    }
1241    
1242                                    cacheResult(list);
1243    
1244                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1245                            }
1246                            catch (Exception e) {
1247                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1248    
1249                                    throw processException(e);
1250                            }
1251                            finally {
1252                                    closeSession(session);
1253                            }
1254                    }
1255    
1256                    return list;
1257            }
1258    
1259            /**
1260             * Returns the first subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1261             *
1262             * @param companyId the company ID
1263             * @param classNameId the class name ID
1264             * @param classPK the class p k
1265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1266             * @return the first matching subscription
1267             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
1268             * @throws SystemException if a system exception occurred
1269             */
1270            public Subscription findByC_C_C_First(long companyId, long classNameId,
1271                    long classPK, OrderByComparator orderByComparator)
1272                    throws NoSuchSubscriptionException, SystemException {
1273                    Subscription subscription = fetchByC_C_C_First(companyId, classNameId,
1274                                    classPK, orderByComparator);
1275    
1276                    if (subscription != null) {
1277                            return subscription;
1278                    }
1279    
1280                    StringBundler msg = new StringBundler(8);
1281    
1282                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1283    
1284                    msg.append("companyId=");
1285                    msg.append(companyId);
1286    
1287                    msg.append(", classNameId=");
1288                    msg.append(classNameId);
1289    
1290                    msg.append(", classPK=");
1291                    msg.append(classPK);
1292    
1293                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1294    
1295                    throw new NoSuchSubscriptionException(msg.toString());
1296            }
1297    
1298            /**
1299             * Returns the first subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1300             *
1301             * @param companyId the company ID
1302             * @param classNameId the class name ID
1303             * @param classPK the class p k
1304             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1305             * @return the first matching subscription, or <code>null</code> if a matching subscription could not be found
1306             * @throws SystemException if a system exception occurred
1307             */
1308            public Subscription fetchByC_C_C_First(long companyId, long classNameId,
1309                    long classPK, OrderByComparator orderByComparator)
1310                    throws SystemException {
1311                    List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1312                                    0, 1, orderByComparator);
1313    
1314                    if (!list.isEmpty()) {
1315                            return list.get(0);
1316                    }
1317    
1318                    return null;
1319            }
1320    
1321            /**
1322             * Returns the last subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1323             *
1324             * @param companyId the company ID
1325             * @param classNameId the class name ID
1326             * @param classPK the class p k
1327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1328             * @return the last matching subscription
1329             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
1330             * @throws SystemException if a system exception occurred
1331             */
1332            public Subscription findByC_C_C_Last(long companyId, long classNameId,
1333                    long classPK, OrderByComparator orderByComparator)
1334                    throws NoSuchSubscriptionException, SystemException {
1335                    Subscription subscription = fetchByC_C_C_Last(companyId, classNameId,
1336                                    classPK, orderByComparator);
1337    
1338                    if (subscription != null) {
1339                            return subscription;
1340                    }
1341    
1342                    StringBundler msg = new StringBundler(8);
1343    
1344                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1345    
1346                    msg.append("companyId=");
1347                    msg.append(companyId);
1348    
1349                    msg.append(", classNameId=");
1350                    msg.append(classNameId);
1351    
1352                    msg.append(", classPK=");
1353                    msg.append(classPK);
1354    
1355                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1356    
1357                    throw new NoSuchSubscriptionException(msg.toString());
1358            }
1359    
1360            /**
1361             * Returns the last subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1362             *
1363             * @param companyId the company ID
1364             * @param classNameId the class name ID
1365             * @param classPK the class p k
1366             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1367             * @return the last matching subscription, or <code>null</code> if a matching subscription could not be found
1368             * @throws SystemException if a system exception occurred
1369             */
1370            public Subscription fetchByC_C_C_Last(long companyId, long classNameId,
1371                    long classPK, OrderByComparator orderByComparator)
1372                    throws SystemException {
1373                    int count = countByC_C_C(companyId, classNameId, classPK);
1374    
1375                    List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1376                                    count - 1, count, orderByComparator);
1377    
1378                    if (!list.isEmpty()) {
1379                            return list.get(0);
1380                    }
1381    
1382                    return null;
1383            }
1384    
1385            /**
1386             * Returns the subscriptions before and after the current subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1387             *
1388             * @param subscriptionId the primary key of the current subscription
1389             * @param companyId the company ID
1390             * @param classNameId the class name ID
1391             * @param classPK the class p k
1392             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1393             * @return the previous, current, and next subscription
1394             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
1395             * @throws SystemException if a system exception occurred
1396             */
1397            public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId,
1398                    long companyId, long classNameId, long classPK,
1399                    OrderByComparator orderByComparator)
1400                    throws NoSuchSubscriptionException, SystemException {
1401                    Subscription subscription = findByPrimaryKey(subscriptionId);
1402    
1403                    Session session = null;
1404    
1405                    try {
1406                            session = openSession();
1407    
1408                            Subscription[] array = new SubscriptionImpl[3];
1409    
1410                            array[0] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1411                                            classNameId, classPK, orderByComparator, true);
1412    
1413                            array[1] = subscription;
1414    
1415                            array[2] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1416                                            classNameId, classPK, orderByComparator, false);
1417    
1418                            return array;
1419                    }
1420                    catch (Exception e) {
1421                            throw processException(e);
1422                    }
1423                    finally {
1424                            closeSession(session);
1425                    }
1426            }
1427    
1428            protected Subscription getByC_C_C_PrevAndNext(Session session,
1429                    Subscription subscription, long companyId, long classNameId,
1430                    long classPK, OrderByComparator orderByComparator, boolean previous) {
1431                    StringBundler query = null;
1432    
1433                    if (orderByComparator != null) {
1434                            query = new StringBundler(6 +
1435                                            (orderByComparator.getOrderByFields().length * 6));
1436                    }
1437                    else {
1438                            query = new StringBundler(3);
1439                    }
1440    
1441                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1442    
1443                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1444    
1445                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1446    
1447                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1448    
1449                    if (orderByComparator != null) {
1450                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1451    
1452                            if (orderByConditionFields.length > 0) {
1453                                    query.append(WHERE_AND);
1454                            }
1455    
1456                            for (int i = 0; i < orderByConditionFields.length; i++) {
1457                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1458                                    query.append(orderByConditionFields[i]);
1459    
1460                                    if ((i + 1) < orderByConditionFields.length) {
1461                                            if (orderByComparator.isAscending() ^ previous) {
1462                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1463                                            }
1464                                            else {
1465                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1466                                            }
1467                                    }
1468                                    else {
1469                                            if (orderByComparator.isAscending() ^ previous) {
1470                                                    query.append(WHERE_GREATER_THAN);
1471                                            }
1472                                            else {
1473                                                    query.append(WHERE_LESSER_THAN);
1474                                            }
1475                                    }
1476                            }
1477    
1478                            query.append(ORDER_BY_CLAUSE);
1479    
1480                            String[] orderByFields = orderByComparator.getOrderByFields();
1481    
1482                            for (int i = 0; i < orderByFields.length; i++) {
1483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1484                                    query.append(orderByFields[i]);
1485    
1486                                    if ((i + 1) < orderByFields.length) {
1487                                            if (orderByComparator.isAscending() ^ previous) {
1488                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1489                                            }
1490                                            else {
1491                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1492                                            }
1493                                    }
1494                                    else {
1495                                            if (orderByComparator.isAscending() ^ previous) {
1496                                                    query.append(ORDER_BY_ASC);
1497                                            }
1498                                            else {
1499                                                    query.append(ORDER_BY_DESC);
1500                                            }
1501                                    }
1502                            }
1503                    }
1504                    else {
1505                            query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1506                    }
1507    
1508                    String sql = query.toString();
1509    
1510                    Query q = session.createQuery(sql);
1511    
1512                    q.setFirstResult(0);
1513                    q.setMaxResults(2);
1514    
1515                    QueryPos qPos = QueryPos.getInstance(q);
1516    
1517                    qPos.add(companyId);
1518    
1519                    qPos.add(classNameId);
1520    
1521                    qPos.add(classPK);
1522    
1523                    if (orderByComparator != null) {
1524                            Object[] values = orderByComparator.getOrderByConditionValues(subscription);
1525    
1526                            for (Object value : values) {
1527                                    qPos.add(value);
1528                            }
1529                    }
1530    
1531                    List<Subscription> list = q.list();
1532    
1533                    if (list.size() == 2) {
1534                            return list.get(1);
1535                    }
1536                    else {
1537                            return null;
1538                    }
1539            }
1540    
1541            /**
1542             * Removes all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
1543             *
1544             * @param companyId the company ID
1545             * @param classNameId the class name ID
1546             * @param classPK the class p k
1547             * @throws SystemException if a system exception occurred
1548             */
1549            public void removeByC_C_C(long companyId, long classNameId, long classPK)
1550                    throws SystemException {
1551                    for (Subscription subscription : findByC_C_C(companyId, classNameId,
1552                                    classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1553                            remove(subscription);
1554                    }
1555            }
1556    
1557            /**
1558             * Returns the number of subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1559             *
1560             * @param companyId the company ID
1561             * @param classNameId the class name ID
1562             * @param classPK the class p k
1563             * @return the number of matching subscriptions
1564             * @throws SystemException if a system exception occurred
1565             */
1566            public int countByC_C_C(long companyId, long classNameId, long classPK)
1567                    throws SystemException {
1568                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
1569    
1570                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
1571    
1572                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1573                                    this);
1574    
1575                    if (count == null) {
1576                            StringBundler query = new StringBundler(4);
1577    
1578                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1579    
1580                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1581    
1582                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1583    
1584                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1585    
1586                            String sql = query.toString();
1587    
1588                            Session session = null;
1589    
1590                            try {
1591                                    session = openSession();
1592    
1593                                    Query q = session.createQuery(sql);
1594    
1595                                    QueryPos qPos = QueryPos.getInstance(q);
1596    
1597                                    qPos.add(companyId);
1598    
1599                                    qPos.add(classNameId);
1600    
1601                                    qPos.add(classPK);
1602    
1603                                    count = (Long)q.uniqueResult();
1604    
1605                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1606                            }
1607                            catch (Exception e) {
1608                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1609    
1610                                    throw processException(e);
1611                            }
1612                            finally {
1613                                    closeSession(session);
1614                            }
1615                    }
1616    
1617                    return count.intValue();
1618            }
1619    
1620            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
1621            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
1622            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "subscription.classPK = ?";
1623            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1624                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1625                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_U_C_C",
1626                            new String[] {
1627                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1628                                    Long.class.getName(),
1629                                    
1630                            Integer.class.getName(), Integer.class.getName(),
1631                                    OrderByComparator.class.getName()
1632                            });
1633            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C =
1634                    new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1635                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1636                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_U_C_C",
1637                            new String[] {
1638                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1639                                    Long.class.getName()
1640                            },
1641                            SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1642                            SubscriptionModelImpl.USERID_COLUMN_BITMASK |
1643                            SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1644                            SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1645            public static final FinderPath FINDER_PATH_FETCH_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1646                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, SubscriptionImpl.class,
1647                            FINDER_CLASS_NAME_ENTITY, "fetchByC_U_C_C",
1648                            new String[] {
1649                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1650                                    Long.class.getName()
1651                            },
1652                            SubscriptionModelImpl.COMPANYID_COLUMN_BITMASK |
1653                            SubscriptionModelImpl.USERID_COLUMN_BITMASK |
1654                            SubscriptionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1655                            SubscriptionModelImpl.CLASSPK_COLUMN_BITMASK);
1656            public static final FinderPath FINDER_PATH_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1657                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1658                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_U_C_C",
1659                            new String[] {
1660                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1661                                    Long.class.getName()
1662                            });
1663            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
1664                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1665                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_U_C_C",
1666                            new String[] {
1667                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1668                                    Long.class.getName()
1669                            });
1670    
1671            /**
1672             * Returns all the subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = any &#63;.
1673             *
1674             * <p>
1675             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
1676             * </p>
1677             *
1678             * @param companyId the company ID
1679             * @param userId the user ID
1680             * @param classNameId the class name ID
1681             * @param classPKs the class p ks
1682             * @return the matching subscriptions
1683             * @throws SystemException if a system exception occurred
1684             */
1685            public List<Subscription> findByC_U_C_C(long companyId, long userId,
1686                    long classNameId, long[] classPKs) throws SystemException {
1687                    return findByC_U_C_C(companyId, userId, classNameId, classPKs,
1688                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1689            }
1690    
1691            /**
1692             * Returns a range of all the subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = any &#63;.
1693             *
1694             * <p>
1695             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
1696             * </p>
1697             *
1698             * @param companyId the company ID
1699             * @param userId the user ID
1700             * @param classNameId the class name ID
1701             * @param classPKs the class p ks
1702             * @param start the lower bound of the range of subscriptions
1703             * @param end the upper bound of the range of subscriptions (not inclusive)
1704             * @return the range of matching subscriptions
1705             * @throws SystemException if a system exception occurred
1706             */
1707            public List<Subscription> findByC_U_C_C(long companyId, long userId,
1708                    long classNameId, long[] classPKs, int start, int end)
1709                    throws SystemException {
1710                    return findByC_U_C_C(companyId, userId, classNameId, classPKs, start,
1711                            end, null);
1712            }
1713    
1714            /**
1715             * Returns an ordered range of all the subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = any &#63;.
1716             *
1717             * <p>
1718             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
1719             * </p>
1720             *
1721             * @param companyId the company ID
1722             * @param userId the user ID
1723             * @param classNameId the class name ID
1724             * @param classPKs the class p ks
1725             * @param start the lower bound of the range of subscriptions
1726             * @param end the upper bound of the range of subscriptions (not inclusive)
1727             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1728             * @return the ordered range of matching subscriptions
1729             * @throws SystemException if a system exception occurred
1730             */
1731            public List<Subscription> findByC_U_C_C(long companyId, long userId,
1732                    long classNameId, long[] classPKs, int start, int end,
1733                    OrderByComparator orderByComparator) throws SystemException {
1734                    if ((classPKs != null) && (classPKs.length == 1)) {
1735                            Subscription subscription = fetchByC_U_C_C(companyId, userId,
1736                                            classNameId, classPKs[0]);
1737    
1738                            if (subscription == null) {
1739                                    return Collections.emptyList();
1740                            }
1741                            else {
1742                                    List<Subscription> list = new ArrayList<Subscription>(1);
1743    
1744                                    list.add(subscription);
1745    
1746                                    return list;
1747                            }
1748                    }
1749    
1750                    boolean pagination = true;
1751                    Object[] finderArgs = null;
1752    
1753                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1754                                    (orderByComparator == null)) {
1755                            pagination = false;
1756                            finderArgs = new Object[] {
1757                                            companyId, userId, classNameId, StringUtil.merge(classPKs)
1758                                    };
1759                    }
1760                    else {
1761                            finderArgs = new Object[] {
1762                                            companyId, userId, classNameId, StringUtil.merge(classPKs),
1763                                            
1764                                            start, end, orderByComparator
1765                                    };
1766                    }
1767    
1768                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
1769                                    finderArgs, this);
1770    
1771                    if ((list != null) && !list.isEmpty()) {
1772                            for (Subscription subscription : list) {
1773                                    if ((companyId != subscription.getCompanyId()) ||
1774                                                    (userId != subscription.getUserId()) ||
1775                                                    (classNameId != subscription.getClassNameId()) ||
1776                                                    !ArrayUtil.contains(classPKs, subscription.getClassPK())) {
1777                                            list = null;
1778    
1779                                            break;
1780                                    }
1781                            }
1782                    }
1783    
1784                    if (list == null) {
1785                            StringBundler query = new StringBundler();
1786    
1787                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1788    
1789                            boolean conjunctionable = false;
1790    
1791                            if (conjunctionable) {
1792                                    query.append(WHERE_AND);
1793                            }
1794    
1795                            query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_5);
1796    
1797                            conjunctionable = true;
1798    
1799                            if (conjunctionable) {
1800                                    query.append(WHERE_AND);
1801                            }
1802    
1803                            query.append(_FINDER_COLUMN_C_U_C_C_USERID_5);
1804    
1805                            conjunctionable = true;
1806    
1807                            if (conjunctionable) {
1808                                    query.append(WHERE_AND);
1809                            }
1810    
1811                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_5);
1812    
1813                            conjunctionable = true;
1814    
1815                            if ((classPKs == null) || (classPKs.length > 0)) {
1816                                    if (conjunctionable) {
1817                                            query.append(WHERE_AND);
1818                                    }
1819    
1820                                    query.append(StringPool.OPEN_PARENTHESIS);
1821    
1822                                    for (int i = 0; i < classPKs.length; i++) {
1823                                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_5);
1824    
1825                                            if ((i + 1) < classPKs.length) {
1826                                                    query.append(WHERE_OR);
1827                                            }
1828                                    }
1829    
1830                                    query.append(StringPool.CLOSE_PARENTHESIS);
1831    
1832                                    conjunctionable = true;
1833                            }
1834    
1835                            if (orderByComparator != null) {
1836                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1837                                            orderByComparator);
1838                            }
1839                            else
1840                             if (pagination) {
1841                                    query.append(SubscriptionModelImpl.ORDER_BY_JPQL);
1842                            }
1843    
1844                            String sql = query.toString();
1845    
1846                            Session session = null;
1847    
1848                            try {
1849                                    session = openSession();
1850    
1851                                    Query q = session.createQuery(sql);
1852    
1853                                    QueryPos qPos = QueryPos.getInstance(q);
1854    
1855                                    qPos.add(companyId);
1856    
1857                                    qPos.add(userId);
1858    
1859                                    qPos.add(classNameId);
1860    
1861                                    if (classPKs != null) {
1862                                            qPos.add(classPKs);
1863                                    }
1864    
1865                                    if (!pagination) {
1866                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1867                                                            start, end, false);
1868    
1869                                            Collections.sort(list);
1870    
1871                                            list = new UnmodifiableList<Subscription>(list);
1872                                    }
1873                                    else {
1874                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1875                                                            start, end);
1876                                    }
1877    
1878                                    cacheResult(list);
1879    
1880                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
1881                                            finderArgs, list);
1882                            }
1883                            catch (Exception e) {
1884                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_U_C_C,
1885                                            finderArgs);
1886    
1887                                    throw processException(e);
1888                            }
1889                            finally {
1890                                    closeSession(session);
1891                            }
1892                    }
1893    
1894                    return list;
1895            }
1896    
1897            /**
1898             * Returns the subscription where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; or throws a {@link com.liferay.portal.NoSuchSubscriptionException} if it could not be found.
1899             *
1900             * @param companyId the company ID
1901             * @param userId the user ID
1902             * @param classNameId the class name ID
1903             * @param classPK the class p k
1904             * @return the matching subscription
1905             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
1906             * @throws SystemException if a system exception occurred
1907             */
1908            public Subscription findByC_U_C_C(long companyId, long userId,
1909                    long classNameId, long classPK)
1910                    throws NoSuchSubscriptionException, SystemException {
1911                    Subscription subscription = fetchByC_U_C_C(companyId, userId,
1912                                    classNameId, classPK);
1913    
1914                    if (subscription == null) {
1915                            StringBundler msg = new StringBundler(10);
1916    
1917                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1918    
1919                            msg.append("companyId=");
1920                            msg.append(companyId);
1921    
1922                            msg.append(", userId=");
1923                            msg.append(userId);
1924    
1925                            msg.append(", classNameId=");
1926                            msg.append(classNameId);
1927    
1928                            msg.append(", classPK=");
1929                            msg.append(classPK);
1930    
1931                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1932    
1933                            if (_log.isWarnEnabled()) {
1934                                    _log.warn(msg.toString());
1935                            }
1936    
1937                            throw new NoSuchSubscriptionException(msg.toString());
1938                    }
1939    
1940                    return subscription;
1941            }
1942    
1943            /**
1944             * 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.
1945             *
1946             * @param companyId the company ID
1947             * @param userId the user ID
1948             * @param classNameId the class name ID
1949             * @param classPK the class p k
1950             * @return the matching subscription, or <code>null</code> if a matching subscription could not be found
1951             * @throws SystemException if a system exception occurred
1952             */
1953            public Subscription fetchByC_U_C_C(long companyId, long userId,
1954                    long classNameId, long classPK) throws SystemException {
1955                    return fetchByC_U_C_C(companyId, userId, classNameId, classPK, true);
1956            }
1957    
1958            /**
1959             * 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.
1960             *
1961             * @param companyId the company ID
1962             * @param userId the user ID
1963             * @param classNameId the class name ID
1964             * @param classPK the class p k
1965             * @param retrieveFromCache whether to use the finder cache
1966             * @return the matching subscription, or <code>null</code> if a matching subscription could not be found
1967             * @throws SystemException if a system exception occurred
1968             */
1969            public Subscription fetchByC_U_C_C(long companyId, long userId,
1970                    long classNameId, long classPK, boolean retrieveFromCache)
1971                    throws SystemException {
1972                    Object[] finderArgs = new Object[] {
1973                                    companyId, userId, classNameId, classPK
1974                            };
1975    
1976                    Object result = null;
1977    
1978                    if (retrieveFromCache) {
1979                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1980                                            finderArgs, this);
1981                    }
1982    
1983                    if (result instanceof Subscription) {
1984                            Subscription subscription = (Subscription)result;
1985    
1986                            if ((companyId != subscription.getCompanyId()) ||
1987                                            (userId != subscription.getUserId()) ||
1988                                            (classNameId != subscription.getClassNameId()) ||
1989                                            (classPK != subscription.getClassPK())) {
1990                                    result = null;
1991                            }
1992                    }
1993    
1994                    if (result == null) {
1995                            StringBundler query = new StringBundler(6);
1996    
1997                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1998    
1999                            query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2000    
2001                            query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2002    
2003                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2004    
2005                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2006    
2007                            String sql = query.toString();
2008    
2009                            Session session = null;
2010    
2011                            try {
2012                                    session = openSession();
2013    
2014                                    Query q = session.createQuery(sql);
2015    
2016                                    QueryPos qPos = QueryPos.getInstance(q);
2017    
2018                                    qPos.add(companyId);
2019    
2020                                    qPos.add(userId);
2021    
2022                                    qPos.add(classNameId);
2023    
2024                                    qPos.add(classPK);
2025    
2026                                    List<Subscription> list = q.list();
2027    
2028                                    if (list.isEmpty()) {
2029                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2030                                                    finderArgs, list);
2031                                    }
2032                                    else {
2033                                            Subscription subscription = list.get(0);
2034    
2035                                            result = subscription;
2036    
2037                                            cacheResult(subscription);
2038    
2039                                            if ((subscription.getCompanyId() != companyId) ||
2040                                                            (subscription.getUserId() != userId) ||
2041                                                            (subscription.getClassNameId() != classNameId) ||
2042                                                            (subscription.getClassPK() != classPK)) {
2043                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2044                                                            finderArgs, subscription);
2045                                            }
2046                                    }
2047                            }
2048                            catch (Exception e) {
2049                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2050                                            finderArgs);
2051    
2052                                    throw processException(e);
2053                            }
2054                            finally {
2055                                    closeSession(session);
2056                            }
2057                    }
2058    
2059                    if (result instanceof List<?>) {
2060                            return null;
2061                    }
2062                    else {
2063                            return (Subscription)result;
2064                    }
2065            }
2066    
2067            /**
2068             * Removes the subscription where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
2069             *
2070             * @param companyId the company ID
2071             * @param userId the user ID
2072             * @param classNameId the class name ID
2073             * @param classPK the class p k
2074             * @return the subscription that was removed
2075             * @throws SystemException if a system exception occurred
2076             */
2077            public Subscription removeByC_U_C_C(long companyId, long userId,
2078                    long classNameId, long classPK)
2079                    throws NoSuchSubscriptionException, SystemException {
2080                    Subscription subscription = findByC_U_C_C(companyId, userId,
2081                                    classNameId, classPK);
2082    
2083                    return remove(subscription);
2084            }
2085    
2086            /**
2087             * Returns the number of subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63;.
2088             *
2089             * @param companyId the company ID
2090             * @param userId the user ID
2091             * @param classNameId the class name ID
2092             * @param classPK the class p k
2093             * @return the number of matching subscriptions
2094             * @throws SystemException if a system exception occurred
2095             */
2096            public int countByC_U_C_C(long companyId, long userId, long classNameId,
2097                    long classPK) throws SystemException {
2098                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U_C_C;
2099    
2100                    Object[] finderArgs = new Object[] {
2101                                    companyId, userId, classNameId, classPK
2102                            };
2103    
2104                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2105                                    this);
2106    
2107                    if (count == null) {
2108                            StringBundler query = new StringBundler(5);
2109    
2110                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2111    
2112                            query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2113    
2114                            query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2115    
2116                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2117    
2118                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2119    
2120                            String sql = query.toString();
2121    
2122                            Session session = null;
2123    
2124                            try {
2125                                    session = openSession();
2126    
2127                                    Query q = session.createQuery(sql);
2128    
2129                                    QueryPos qPos = QueryPos.getInstance(q);
2130    
2131                                    qPos.add(companyId);
2132    
2133                                    qPos.add(userId);
2134    
2135                                    qPos.add(classNameId);
2136    
2137                                    qPos.add(classPK);
2138    
2139                                    count = (Long)q.uniqueResult();
2140    
2141                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2142                            }
2143                            catch (Exception e) {
2144                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2145    
2146                                    throw processException(e);
2147                            }
2148                            finally {
2149                                    closeSession(session);
2150                            }
2151                    }
2152    
2153                    return count.intValue();
2154            }
2155    
2156            /**
2157             * Returns the number of subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = any &#63;.
2158             *
2159             * @param companyId the company ID
2160             * @param userId the user ID
2161             * @param classNameId the class name ID
2162             * @param classPKs the class p ks
2163             * @return the number of matching subscriptions
2164             * @throws SystemException if a system exception occurred
2165             */
2166            public int countByC_U_C_C(long companyId, long userId, long classNameId,
2167                    long[] classPKs) throws SystemException {
2168                    Object[] finderArgs = new Object[] {
2169                                    companyId, userId, classNameId, StringUtil.merge(classPKs)
2170                            };
2171    
2172                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2173                                    finderArgs, this);
2174    
2175                    if (count == null) {
2176                            StringBundler query = new StringBundler();
2177    
2178                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2179    
2180                            boolean conjunctionable = false;
2181    
2182                            if (conjunctionable) {
2183                                    query.append(WHERE_AND);
2184                            }
2185    
2186                            query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_5);
2187    
2188                            conjunctionable = true;
2189    
2190                            if (conjunctionable) {
2191                                    query.append(WHERE_AND);
2192                            }
2193    
2194                            query.append(_FINDER_COLUMN_C_U_C_C_USERID_5);
2195    
2196                            conjunctionable = true;
2197    
2198                            if (conjunctionable) {
2199                                    query.append(WHERE_AND);
2200                            }
2201    
2202                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_5);
2203    
2204                            conjunctionable = true;
2205    
2206                            if ((classPKs == null) || (classPKs.length > 0)) {
2207                                    if (conjunctionable) {
2208                                            query.append(WHERE_AND);
2209                                    }
2210    
2211                                    query.append(StringPool.OPEN_PARENTHESIS);
2212    
2213                                    for (int i = 0; i < classPKs.length; i++) {
2214                                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_5);
2215    
2216                                            if ((i + 1) < classPKs.length) {
2217                                                    query.append(WHERE_OR);
2218                                            }
2219                                    }
2220    
2221                                    query.append(StringPool.CLOSE_PARENTHESIS);
2222    
2223                                    conjunctionable = true;
2224                            }
2225    
2226                            String sql = query.toString();
2227    
2228                            Session session = null;
2229    
2230                            try {
2231                                    session = openSession();
2232    
2233                                    Query q = session.createQuery(sql);
2234    
2235                                    QueryPos qPos = QueryPos.getInstance(q);
2236    
2237                                    qPos.add(companyId);
2238    
2239                                    qPos.add(userId);
2240    
2241                                    qPos.add(classNameId);
2242    
2243                                    if (classPKs != null) {
2244                                            qPos.add(classPKs);
2245                                    }
2246    
2247                                    count = (Long)q.uniqueResult();
2248    
2249                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2250                                            finderArgs, count);
2251                            }
2252                            catch (Exception e) {
2253                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_U_C_C,
2254                                            finderArgs);
2255    
2256                                    throw processException(e);
2257                            }
2258                            finally {
2259                                    closeSession(session);
2260                            }
2261                    }
2262    
2263                    return count.intValue();
2264            }
2265    
2266            private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2267            private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_5 = "(" +
2268                    removeConjunction(_FINDER_COLUMN_C_U_C_C_COMPANYID_2) + ")";
2269            private static final String _FINDER_COLUMN_C_U_C_C_USERID_2 = "subscription.userId = ? AND ";
2270            private static final String _FINDER_COLUMN_C_U_C_C_USERID_5 = "(" +
2271                    removeConjunction(_FINDER_COLUMN_C_U_C_C_USERID_2) + ")";
2272            private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2273            private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_5 = "(" +
2274                    removeConjunction(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2) + ")";
2275            private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_2 = "subscription.classPK = ?";
2276            private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_5 = "(" +
2277                    removeConjunction(_FINDER_COLUMN_C_U_C_C_CLASSPK_2) + ")";
2278    
2279            /**
2280             * Caches the subscription in the entity cache if it is enabled.
2281             *
2282             * @param subscription the subscription
2283             */
2284            public void cacheResult(Subscription subscription) {
2285                    EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2286                            SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
2287    
2288                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
2289                            new Object[] {
2290                                    subscription.getCompanyId(), subscription.getUserId(),
2291                                    subscription.getClassNameId(), subscription.getClassPK()
2292                            }, subscription);
2293    
2294                    subscription.resetOriginalValues();
2295            }
2296    
2297            /**
2298             * Caches the subscriptions in the entity cache if it is enabled.
2299             *
2300             * @param subscriptions the subscriptions
2301             */
2302            public void cacheResult(List<Subscription> subscriptions) {
2303                    for (Subscription subscription : subscriptions) {
2304                            if (EntityCacheUtil.getResult(
2305                                                    SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2306                                                    SubscriptionImpl.class, subscription.getPrimaryKey()) == null) {
2307                                    cacheResult(subscription);
2308                            }
2309                            else {
2310                                    subscription.resetOriginalValues();
2311                            }
2312                    }
2313            }
2314    
2315            /**
2316             * Clears the cache for all subscriptions.
2317             *
2318             * <p>
2319             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2320             * </p>
2321             */
2322            @Override
2323            public void clearCache() {
2324                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2325                            CacheRegistryUtil.clear(SubscriptionImpl.class.getName());
2326                    }
2327    
2328                    EntityCacheUtil.clearCache(SubscriptionImpl.class.getName());
2329    
2330                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2331                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2332                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2333            }
2334    
2335            /**
2336             * Clears the cache for the subscription.
2337             *
2338             * <p>
2339             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2340             * </p>
2341             */
2342            @Override
2343            public void clearCache(Subscription subscription) {
2344                    EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2345                            SubscriptionImpl.class, subscription.getPrimaryKey());
2346    
2347                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2348                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2349    
2350                    clearUniqueFindersCache(subscription);
2351            }
2352    
2353            @Override
2354            public void clearCache(List<Subscription> subscriptions) {
2355                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2356                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2357    
2358                    for (Subscription subscription : subscriptions) {
2359                            EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2360                                    SubscriptionImpl.class, subscription.getPrimaryKey());
2361    
2362                            clearUniqueFindersCache(subscription);
2363                    }
2364            }
2365    
2366            protected void cacheUniqueFindersCache(Subscription subscription) {
2367                    if (subscription.isNew()) {
2368                            Object[] args = new Object[] {
2369                                            subscription.getCompanyId(), subscription.getUserId(),
2370                                            subscription.getClassNameId(), subscription.getClassPK()
2371                                    };
2372    
2373                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2374                                    Long.valueOf(1));
2375                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2376                                    subscription);
2377                    }
2378                    else {
2379                            SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2380    
2381                            if ((subscriptionModelImpl.getColumnBitmask() &
2382                                            FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2383                                    Object[] args = new Object[] {
2384                                                    subscription.getCompanyId(), subscription.getUserId(),
2385                                                    subscription.getClassNameId(), subscription.getClassPK()
2386                                            };
2387    
2388                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C, args,
2389                                            Long.valueOf(1));
2390                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C, args,
2391                                            subscription);
2392                            }
2393                    }
2394            }
2395    
2396            protected void clearUniqueFindersCache(Subscription subscription) {
2397                    SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2398    
2399                    Object[] args = new Object[] {
2400                                    subscription.getCompanyId(), subscription.getUserId(),
2401                                    subscription.getClassNameId(), subscription.getClassPK()
2402                            };
2403    
2404                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2405                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
2406    
2407                    if ((subscriptionModelImpl.getColumnBitmask() &
2408                                    FINDER_PATH_FETCH_BY_C_U_C_C.getColumnBitmask()) != 0) {
2409                            args = new Object[] {
2410                                            subscriptionModelImpl.getOriginalCompanyId(),
2411                                            subscriptionModelImpl.getOriginalUserId(),
2412                                            subscriptionModelImpl.getOriginalClassNameId(),
2413                                            subscriptionModelImpl.getOriginalClassPK()
2414                                    };
2415    
2416                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2417                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C, args);
2418                    }
2419            }
2420    
2421            /**
2422             * Creates a new subscription with the primary key. Does not add the subscription to the database.
2423             *
2424             * @param subscriptionId the primary key for the new subscription
2425             * @return the new subscription
2426             */
2427            public Subscription create(long subscriptionId) {
2428                    Subscription subscription = new SubscriptionImpl();
2429    
2430                    subscription.setNew(true);
2431                    subscription.setPrimaryKey(subscriptionId);
2432    
2433                    return subscription;
2434            }
2435    
2436            /**
2437             * Removes the subscription with the primary key from the database. Also notifies the appropriate model listeners.
2438             *
2439             * @param subscriptionId the primary key of the subscription
2440             * @return the subscription that was removed
2441             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
2442             * @throws SystemException if a system exception occurred
2443             */
2444            public Subscription remove(long subscriptionId)
2445                    throws NoSuchSubscriptionException, SystemException {
2446                    return remove((Serializable)subscriptionId);
2447            }
2448    
2449            /**
2450             * Removes the subscription with the primary key from the database. Also notifies the appropriate model listeners.
2451             *
2452             * @param primaryKey the primary key of the subscription
2453             * @return the subscription that was removed
2454             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
2455             * @throws SystemException if a system exception occurred
2456             */
2457            @Override
2458            public Subscription remove(Serializable primaryKey)
2459                    throws NoSuchSubscriptionException, SystemException {
2460                    Session session = null;
2461    
2462                    try {
2463                            session = openSession();
2464    
2465                            Subscription subscription = (Subscription)session.get(SubscriptionImpl.class,
2466                                            primaryKey);
2467    
2468                            if (subscription == null) {
2469                                    if (_log.isWarnEnabled()) {
2470                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2471                                    }
2472    
2473                                    throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2474                                            primaryKey);
2475                            }
2476    
2477                            return remove(subscription);
2478                    }
2479                    catch (NoSuchSubscriptionException nsee) {
2480                            throw nsee;
2481                    }
2482                    catch (Exception e) {
2483                            throw processException(e);
2484                    }
2485                    finally {
2486                            closeSession(session);
2487                    }
2488            }
2489    
2490            @Override
2491            protected Subscription removeImpl(Subscription subscription)
2492                    throws SystemException {
2493                    subscription = toUnwrappedModel(subscription);
2494    
2495                    Session session = null;
2496    
2497                    try {
2498                            session = openSession();
2499    
2500                            if (!session.contains(subscription)) {
2501                                    subscription = (Subscription)session.get(SubscriptionImpl.class,
2502                                                    subscription.getPrimaryKeyObj());
2503                            }
2504    
2505                            if (subscription != null) {
2506                                    session.delete(subscription);
2507                            }
2508                    }
2509                    catch (Exception e) {
2510                            throw processException(e);
2511                    }
2512                    finally {
2513                            closeSession(session);
2514                    }
2515    
2516                    if (subscription != null) {
2517                            clearCache(subscription);
2518                    }
2519    
2520                    return subscription;
2521            }
2522    
2523            @Override
2524            public Subscription updateImpl(
2525                    com.liferay.portal.model.Subscription subscription)
2526                    throws SystemException {
2527                    subscription = toUnwrappedModel(subscription);
2528    
2529                    boolean isNew = subscription.isNew();
2530    
2531                    SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
2532    
2533                    Session session = null;
2534    
2535                    try {
2536                            session = openSession();
2537    
2538                            if (subscription.isNew()) {
2539                                    session.save(subscription);
2540    
2541                                    subscription.setNew(false);
2542                            }
2543                            else {
2544                                    session.merge(subscription);
2545                            }
2546                    }
2547                    catch (Exception e) {
2548                            throw processException(e);
2549                    }
2550                    finally {
2551                            closeSession(session);
2552                    }
2553    
2554                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2555    
2556                    if (isNew || !SubscriptionModelImpl.COLUMN_BITMASK_ENABLED) {
2557                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2558                    }
2559    
2560                    else {
2561                            if ((subscriptionModelImpl.getColumnBitmask() &
2562                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2563                                    Object[] args = new Object[] {
2564                                                    subscriptionModelImpl.getOriginalUserId()
2565                                            };
2566    
2567                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2568                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2569                                            args);
2570    
2571                                    args = new Object[] { subscriptionModelImpl.getUserId() };
2572    
2573                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2574                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2575                                            args);
2576                            }
2577    
2578                            if ((subscriptionModelImpl.getColumnBitmask() &
2579                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
2580                                    Object[] args = new Object[] {
2581                                                    subscriptionModelImpl.getOriginalUserId(),
2582                                                    subscriptionModelImpl.getOriginalClassNameId()
2583                                            };
2584    
2585                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
2586                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
2587                                            args);
2588    
2589                                    args = new Object[] {
2590                                                    subscriptionModelImpl.getUserId(),
2591                                                    subscriptionModelImpl.getClassNameId()
2592                                            };
2593    
2594                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
2595                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
2596                                            args);
2597                            }
2598    
2599                            if ((subscriptionModelImpl.getColumnBitmask() &
2600                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C.getColumnBitmask()) != 0) {
2601                                    Object[] args = new Object[] {
2602                                                    subscriptionModelImpl.getOriginalCompanyId(),
2603                                                    subscriptionModelImpl.getOriginalClassNameId(),
2604                                                    subscriptionModelImpl.getOriginalClassPK()
2605                                            };
2606    
2607                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2608                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2609                                            args);
2610    
2611                                    args = new Object[] {
2612                                                    subscriptionModelImpl.getCompanyId(),
2613                                                    subscriptionModelImpl.getClassNameId(),
2614                                                    subscriptionModelImpl.getClassPK()
2615                                            };
2616    
2617                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
2618                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_C,
2619                                            args);
2620                            }
2621    
2622                            if ((subscriptionModelImpl.getColumnBitmask() &
2623                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C.getColumnBitmask()) != 0) {
2624                                    Object[] args = new Object[] {
2625                                                    subscriptionModelImpl.getOriginalCompanyId(),
2626                                                    subscriptionModelImpl.getOriginalUserId(),
2627                                                    subscriptionModelImpl.getOriginalClassNameId(),
2628                                                    subscriptionModelImpl.getOriginalClassPK()
2629                                            };
2630    
2631                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2632                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
2633                                            args);
2634    
2635                                    args = new Object[] {
2636                                                    subscriptionModelImpl.getCompanyId(),
2637                                                    subscriptionModelImpl.getUserId(),
2638                                                    subscriptionModelImpl.getClassNameId(),
2639                                                    subscriptionModelImpl.getClassPK()
2640                                            };
2641    
2642                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_C_C, args);
2643                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_U_C_C,
2644                                            args);
2645                            }
2646                    }
2647    
2648                    EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2649                            SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
2650    
2651                    clearUniqueFindersCache(subscription);
2652                    cacheUniqueFindersCache(subscription);
2653    
2654                    return subscription;
2655            }
2656    
2657            protected Subscription toUnwrappedModel(Subscription subscription) {
2658                    if (subscription instanceof SubscriptionImpl) {
2659                            return subscription;
2660                    }
2661    
2662                    SubscriptionImpl subscriptionImpl = new SubscriptionImpl();
2663    
2664                    subscriptionImpl.setNew(subscription.isNew());
2665                    subscriptionImpl.setPrimaryKey(subscription.getPrimaryKey());
2666    
2667                    subscriptionImpl.setSubscriptionId(subscription.getSubscriptionId());
2668                    subscriptionImpl.setCompanyId(subscription.getCompanyId());
2669                    subscriptionImpl.setUserId(subscription.getUserId());
2670                    subscriptionImpl.setUserName(subscription.getUserName());
2671                    subscriptionImpl.setCreateDate(subscription.getCreateDate());
2672                    subscriptionImpl.setModifiedDate(subscription.getModifiedDate());
2673                    subscriptionImpl.setClassNameId(subscription.getClassNameId());
2674                    subscriptionImpl.setClassPK(subscription.getClassPK());
2675                    subscriptionImpl.setFrequency(subscription.getFrequency());
2676    
2677                    return subscriptionImpl;
2678            }
2679    
2680            /**
2681             * Returns the subscription with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2682             *
2683             * @param primaryKey the primary key of the subscription
2684             * @return the subscription
2685             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
2686             * @throws SystemException if a system exception occurred
2687             */
2688            @Override
2689            public Subscription findByPrimaryKey(Serializable primaryKey)
2690                    throws NoSuchSubscriptionException, SystemException {
2691                    Subscription subscription = fetchByPrimaryKey(primaryKey);
2692    
2693                    if (subscription == null) {
2694                            if (_log.isWarnEnabled()) {
2695                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2696                            }
2697    
2698                            throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2699                                    primaryKey);
2700                    }
2701    
2702                    return subscription;
2703            }
2704    
2705            /**
2706             * Returns the subscription with the primary key or throws a {@link com.liferay.portal.NoSuchSubscriptionException} if it could not be found.
2707             *
2708             * @param subscriptionId the primary key of the subscription
2709             * @return the subscription
2710             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
2711             * @throws SystemException if a system exception occurred
2712             */
2713            public Subscription findByPrimaryKey(long subscriptionId)
2714                    throws NoSuchSubscriptionException, SystemException {
2715                    return findByPrimaryKey((Serializable)subscriptionId);
2716            }
2717    
2718            /**
2719             * Returns the subscription with the primary key or returns <code>null</code> if it could not be found.
2720             *
2721             * @param primaryKey the primary key of the subscription
2722             * @return the subscription, or <code>null</code> if a subscription with the primary key could not be found
2723             * @throws SystemException if a system exception occurred
2724             */
2725            @Override
2726            public Subscription fetchByPrimaryKey(Serializable primaryKey)
2727                    throws SystemException {
2728                    Subscription subscription = (Subscription)EntityCacheUtil.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2729                                    SubscriptionImpl.class, primaryKey);
2730    
2731                    if (subscription == _nullSubscription) {
2732                            return null;
2733                    }
2734    
2735                    if (subscription == null) {
2736                            Session session = null;
2737    
2738                            try {
2739                                    session = openSession();
2740    
2741                                    subscription = (Subscription)session.get(SubscriptionImpl.class,
2742                                                    primaryKey);
2743    
2744                                    if (subscription != null) {
2745                                            cacheResult(subscription);
2746                                    }
2747                                    else {
2748                                            EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2749                                                    SubscriptionImpl.class, primaryKey, _nullSubscription);
2750                                    }
2751                            }
2752                            catch (Exception e) {
2753                                    EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
2754                                            SubscriptionImpl.class, primaryKey);
2755    
2756                                    throw processException(e);
2757                            }
2758                            finally {
2759                                    closeSession(session);
2760                            }
2761                    }
2762    
2763                    return subscription;
2764            }
2765    
2766            /**
2767             * Returns the subscription with the primary key or returns <code>null</code> if it could not be found.
2768             *
2769             * @param subscriptionId the primary key of the subscription
2770             * @return the subscription, or <code>null</code> if a subscription with the primary key could not be found
2771             * @throws SystemException if a system exception occurred
2772             */
2773            public Subscription fetchByPrimaryKey(long subscriptionId)
2774                    throws SystemException {
2775                    return fetchByPrimaryKey((Serializable)subscriptionId);
2776            }
2777    
2778            /**
2779             * Returns all the subscriptions.
2780             *
2781             * @return the subscriptions
2782             * @throws SystemException if a system exception occurred
2783             */
2784            public List<Subscription> findAll() throws SystemException {
2785                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2786            }
2787    
2788            /**
2789             * Returns a range of all the subscriptions.
2790             *
2791             * <p>
2792             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
2793             * </p>
2794             *
2795             * @param start the lower bound of the range of subscriptions
2796             * @param end the upper bound of the range of subscriptions (not inclusive)
2797             * @return the range of subscriptions
2798             * @throws SystemException if a system exception occurred
2799             */
2800            public List<Subscription> findAll(int start, int end)
2801                    throws SystemException {
2802                    return findAll(start, end, null);
2803            }
2804    
2805            /**
2806             * Returns an ordered range of all the subscriptions.
2807             *
2808             * <p>
2809             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.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.
2810             * </p>
2811             *
2812             * @param start the lower bound of the range of subscriptions
2813             * @param end the upper bound of the range of subscriptions (not inclusive)
2814             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2815             * @return the ordered range of subscriptions
2816             * @throws SystemException if a system exception occurred
2817             */
2818            public List<Subscription> findAll(int start, int end,
2819                    OrderByComparator orderByComparator) throws SystemException {
2820                    boolean pagination = true;
2821                    FinderPath finderPath = null;
2822                    Object[] finderArgs = null;
2823    
2824                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2825                                    (orderByComparator == null)) {
2826                            pagination = false;
2827                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2828                            finderArgs = FINDER_ARGS_EMPTY;
2829                    }
2830                    else {
2831                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2832                            finderArgs = new Object[] { start, end, orderByComparator };
2833                    }
2834    
2835                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(finderPath,
2836                                    finderArgs, this);
2837    
2838                    if (list == null) {
2839                            StringBundler query = null;
2840                            String sql = null;
2841    
2842                            if (orderByComparator != null) {
2843                                    query = new StringBundler(2 +
2844                                                    (orderByComparator.getOrderByFields().length * 3));
2845    
2846                                    query.append(_SQL_SELECT_SUBSCRIPTION);
2847    
2848                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2849                                            orderByComparator);
2850    
2851                                    sql = query.toString();
2852                            }
2853                            else {
2854                                    sql = _SQL_SELECT_SUBSCRIPTION;
2855    
2856                                    if (pagination) {
2857                                            sql = sql.concat(SubscriptionModelImpl.ORDER_BY_JPQL);
2858                                    }
2859                            }
2860    
2861                            Session session = null;
2862    
2863                            try {
2864                                    session = openSession();
2865    
2866                                    Query q = session.createQuery(sql);
2867    
2868                                    if (!pagination) {
2869                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2870                                                            start, end, false);
2871    
2872                                            Collections.sort(list);
2873    
2874                                            list = new UnmodifiableList<Subscription>(list);
2875                                    }
2876                                    else {
2877                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
2878                                                            start, end);
2879                                    }
2880    
2881                                    cacheResult(list);
2882    
2883                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2884                            }
2885                            catch (Exception e) {
2886                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2887    
2888                                    throw processException(e);
2889                            }
2890                            finally {
2891                                    closeSession(session);
2892                            }
2893                    }
2894    
2895                    return list;
2896            }
2897    
2898            /**
2899             * Removes all the subscriptions from the database.
2900             *
2901             * @throws SystemException if a system exception occurred
2902             */
2903            public void removeAll() throws SystemException {
2904                    for (Subscription subscription : findAll()) {
2905                            remove(subscription);
2906                    }
2907            }
2908    
2909            /**
2910             * Returns the number of subscriptions.
2911             *
2912             * @return the number of subscriptions
2913             * @throws SystemException if a system exception occurred
2914             */
2915            public int countAll() throws SystemException {
2916                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2917                                    FINDER_ARGS_EMPTY, this);
2918    
2919                    if (count == null) {
2920                            Session session = null;
2921    
2922                            try {
2923                                    session = openSession();
2924    
2925                                    Query q = session.createQuery(_SQL_COUNT_SUBSCRIPTION);
2926    
2927                                    count = (Long)q.uniqueResult();
2928    
2929                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2930                                            FINDER_ARGS_EMPTY, count);
2931                            }
2932                            catch (Exception e) {
2933                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2934                                            FINDER_ARGS_EMPTY);
2935    
2936                                    throw processException(e);
2937                            }
2938                            finally {
2939                                    closeSession(session);
2940                            }
2941                    }
2942    
2943                    return count.intValue();
2944            }
2945    
2946            /**
2947             * Initializes the subscription persistence.
2948             */
2949            public void afterPropertiesSet() {
2950                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2951                                            com.liferay.portal.util.PropsUtil.get(
2952                                                    "value.object.listener.com.liferay.portal.model.Subscription")));
2953    
2954                    if (listenerClassNames.length > 0) {
2955                            try {
2956                                    List<ModelListener<Subscription>> listenersList = new ArrayList<ModelListener<Subscription>>();
2957    
2958                                    for (String listenerClassName : listenerClassNames) {
2959                                            listenersList.add((ModelListener<Subscription>)InstanceFactory.newInstance(
2960                                                            getClassLoader(), listenerClassName));
2961                                    }
2962    
2963                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2964                            }
2965                            catch (Exception e) {
2966                                    _log.error(e);
2967                            }
2968                    }
2969            }
2970    
2971            public void destroy() {
2972                    EntityCacheUtil.removeCache(SubscriptionImpl.class.getName());
2973                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2974                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2975                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2976            }
2977    
2978            private static final String _SQL_SELECT_SUBSCRIPTION = "SELECT subscription FROM Subscription subscription";
2979            private static final String _SQL_SELECT_SUBSCRIPTION_WHERE = "SELECT subscription FROM Subscription subscription WHERE ";
2980            private static final String _SQL_COUNT_SUBSCRIPTION = "SELECT COUNT(subscription) FROM Subscription subscription";
2981            private static final String _SQL_COUNT_SUBSCRIPTION_WHERE = "SELECT COUNT(subscription) FROM Subscription subscription WHERE ";
2982            private static final String _ORDER_BY_ENTITY_ALIAS = "subscription.";
2983            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Subscription exists with the primary key ";
2984            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Subscription exists with the key {";
2985            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2986            private static Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class);
2987            private static Subscription _nullSubscription = new SubscriptionImpl() {
2988                            @Override
2989                            public Object clone() {
2990                                    return this;
2991                            }
2992    
2993                            @Override
2994                            public CacheModel<Subscription> toCacheModel() {
2995                                    return _nullSubscriptionCacheModel;
2996                            }
2997                    };
2998    
2999            private static CacheModel<Subscription> _nullSubscriptionCacheModel = new CacheModel<Subscription>() {
3000                            public Subscription toEntityModel() {
3001                                    return _nullSubscription;
3002                            }
3003                    };
3004    }