001    /**
002     * Copyright (c) 2000-2011 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.NoSuchModelException;
018    import com.liferay.portal.NoSuchSubscriptionException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.model.Subscription;
039    import com.liferay.portal.model.impl.SubscriptionImpl;
040    import com.liferay.portal.model.impl.SubscriptionModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence implementation for the subscription service.
051     *
052     * <p>
053     * 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.
054     * </p>
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see SubscriptionPersistence
062     * @see SubscriptionUtil
063     * @generated
064     */
065    public class SubscriptionPersistenceImpl extends BasePersistenceImpl<Subscription>
066            implements SubscriptionPersistence {
067            public static final String FINDER_CLASS_NAME_ENTITY = SubscriptionImpl.class.getName();
068            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069                    ".List";
070            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
071                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
072                            "findByUserId",
073                            new String[] {
074                                    Long.class.getName(),
075                                    
076                            "java.lang.Integer", "java.lang.Integer",
077                                    "com.liferay.portal.kernel.util.OrderByComparator"
078                            });
079            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
080                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
081                            "countByUserId", new String[] { Long.class.getName() });
082            public static final FinderPath FINDER_PATH_FIND_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
083                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
084                            "findByU_C",
085                            new String[] {
086                                    Long.class.getName(), Long.class.getName(),
087                                    
088                            "java.lang.Integer", "java.lang.Integer",
089                                    "com.liferay.portal.kernel.util.OrderByComparator"
090                            });
091            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
092                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093                            "countByU_C",
094                            new String[] { Long.class.getName(), Long.class.getName() });
095            public static final FinderPath FINDER_PATH_FIND_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
096                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097                            "findByC_C_C",
098                            new String[] {
099                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
100                                    
101                            "java.lang.Integer", "java.lang.Integer",
102                                    "com.liferay.portal.kernel.util.OrderByComparator"
103                            });
104            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
105                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106                            "countByC_C_C",
107                            new String[] {
108                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
109                            });
110            public static final FinderPath FINDER_PATH_FETCH_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
111                            SubscriptionModelImpl.FINDER_CACHE_ENABLED,
112                            FINDER_CLASS_NAME_ENTITY, "fetchByC_U_C_C",
113                            new String[] {
114                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
115                                    Long.class.getName()
116                            });
117            public static final FinderPath FINDER_PATH_COUNT_BY_C_U_C_C = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
118                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
119                            "countByC_U_C_C",
120                            new String[] {
121                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
122                                    Long.class.getName()
123                            });
124            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
125                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
126                            "findAll", new String[0]);
127            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
128                            SubscriptionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
129                            "countAll", new String[0]);
130    
131            /**
132             * Caches the subscription in the entity cache if it is enabled.
133             *
134             * @param subscription the subscription to cache
135             */
136            public void cacheResult(Subscription subscription) {
137                    EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
138                            SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
139    
140                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
141                            new Object[] {
142                                    new Long(subscription.getCompanyId()),
143                                    new Long(subscription.getUserId()),
144                                    new Long(subscription.getClassNameId()),
145                                    new Long(subscription.getClassPK())
146                            }, subscription);
147            }
148    
149            /**
150             * Caches the subscriptions in the entity cache if it is enabled.
151             *
152             * @param subscriptions the subscriptions to cache
153             */
154            public void cacheResult(List<Subscription> subscriptions) {
155                    for (Subscription subscription : subscriptions) {
156                            if (EntityCacheUtil.getResult(
157                                                    SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
158                                                    SubscriptionImpl.class, subscription.getPrimaryKey(),
159                                                    this) == null) {
160                                    cacheResult(subscription);
161                            }
162                    }
163            }
164    
165            /**
166             * Clears the cache for all subscriptions.
167             *
168             * <p>
169             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
170             * </p>
171             */
172            public void clearCache() {
173                    CacheRegistryUtil.clear(SubscriptionImpl.class.getName());
174                    EntityCacheUtil.clearCache(SubscriptionImpl.class.getName());
175                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
176                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
177            }
178    
179            /**
180             * Clears the cache for the subscription.
181             *
182             * <p>
183             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
184             * </p>
185             */
186            public void clearCache(Subscription subscription) {
187                    EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
188                            SubscriptionImpl.class, subscription.getPrimaryKey());
189    
190                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
191                            new Object[] {
192                                    new Long(subscription.getCompanyId()),
193                                    new Long(subscription.getUserId()),
194                                    new Long(subscription.getClassNameId()),
195                                    new Long(subscription.getClassPK())
196                            });
197            }
198    
199            /**
200             * Creates a new subscription with the primary key. Does not add the subscription to the database.
201             *
202             * @param subscriptionId the primary key for the new subscription
203             * @return the new subscription
204             */
205            public Subscription create(long subscriptionId) {
206                    Subscription subscription = new SubscriptionImpl();
207    
208                    subscription.setNew(true);
209                    subscription.setPrimaryKey(subscriptionId);
210    
211                    return subscription;
212            }
213    
214            /**
215             * Removes the subscription with the primary key from the database. Also notifies the appropriate model listeners.
216             *
217             * @param primaryKey the primary key of the subscription to remove
218             * @return the subscription that was removed
219             * @throws com.liferay.portal.NoSuchModelException if a subscription with the primary key could not be found
220             * @throws SystemException if a system exception occurred
221             */
222            public Subscription remove(Serializable primaryKey)
223                    throws NoSuchModelException, SystemException {
224                    return remove(((Long)primaryKey).longValue());
225            }
226    
227            /**
228             * Removes the subscription with the primary key from the database. Also notifies the appropriate model listeners.
229             *
230             * @param subscriptionId the primary key of the subscription to remove
231             * @return the subscription that was removed
232             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
233             * @throws SystemException if a system exception occurred
234             */
235            public Subscription remove(long subscriptionId)
236                    throws NoSuchSubscriptionException, SystemException {
237                    Session session = null;
238    
239                    try {
240                            session = openSession();
241    
242                            Subscription subscription = (Subscription)session.get(SubscriptionImpl.class,
243                                            new Long(subscriptionId));
244    
245                            if (subscription == null) {
246                                    if (_log.isWarnEnabled()) {
247                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
248                                                    subscriptionId);
249                                    }
250    
251                                    throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
252                                            subscriptionId);
253                            }
254    
255                            return remove(subscription);
256                    }
257                    catch (NoSuchSubscriptionException nsee) {
258                            throw nsee;
259                    }
260                    catch (Exception e) {
261                            throw processException(e);
262                    }
263                    finally {
264                            closeSession(session);
265                    }
266            }
267    
268            protected Subscription removeImpl(Subscription subscription)
269                    throws SystemException {
270                    subscription = toUnwrappedModel(subscription);
271    
272                    Session session = null;
273    
274                    try {
275                            session = openSession();
276    
277                            BatchSessionUtil.delete(session, subscription);
278                    }
279                    catch (Exception e) {
280                            throw processException(e);
281                    }
282                    finally {
283                            closeSession(session);
284                    }
285    
286                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
287    
288                    SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
289    
290                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
291                            new Object[] {
292                                    new Long(subscriptionModelImpl.getCompanyId()),
293                                    new Long(subscriptionModelImpl.getUserId()),
294                                    new Long(subscriptionModelImpl.getClassNameId()),
295                                    new Long(subscriptionModelImpl.getClassPK())
296                            });
297    
298                    EntityCacheUtil.removeResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
299                            SubscriptionImpl.class, subscription.getPrimaryKey());
300    
301                    return subscription;
302            }
303    
304            public Subscription updateImpl(
305                    com.liferay.portal.model.Subscription subscription, boolean merge)
306                    throws SystemException {
307                    subscription = toUnwrappedModel(subscription);
308    
309                    boolean isNew = subscription.isNew();
310    
311                    SubscriptionModelImpl subscriptionModelImpl = (SubscriptionModelImpl)subscription;
312    
313                    Session session = null;
314    
315                    try {
316                            session = openSession();
317    
318                            BatchSessionUtil.update(session, subscription, merge);
319    
320                            subscription.setNew(false);
321                    }
322                    catch (Exception e) {
323                            throw processException(e);
324                    }
325                    finally {
326                            closeSession(session);
327                    }
328    
329                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
330    
331                    EntityCacheUtil.putResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
332                            SubscriptionImpl.class, subscription.getPrimaryKey(), subscription);
333    
334                    if (!isNew &&
335                                    ((subscription.getCompanyId() != subscriptionModelImpl.getOriginalCompanyId()) ||
336                                    (subscription.getUserId() != subscriptionModelImpl.getOriginalUserId()) ||
337                                    (subscription.getClassNameId() != subscriptionModelImpl.getOriginalClassNameId()) ||
338                                    (subscription.getClassPK() != subscriptionModelImpl.getOriginalClassPK()))) {
339                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
340                                    new Object[] {
341                                            new Long(subscriptionModelImpl.getOriginalCompanyId()),
342                                            new Long(subscriptionModelImpl.getOriginalUserId()),
343                                            new Long(subscriptionModelImpl.getOriginalClassNameId()),
344                                            new Long(subscriptionModelImpl.getOriginalClassPK())
345                                    });
346                    }
347    
348                    if (isNew ||
349                                    ((subscription.getCompanyId() != subscriptionModelImpl.getOriginalCompanyId()) ||
350                                    (subscription.getUserId() != subscriptionModelImpl.getOriginalUserId()) ||
351                                    (subscription.getClassNameId() != subscriptionModelImpl.getOriginalClassNameId()) ||
352                                    (subscription.getClassPK() != subscriptionModelImpl.getOriginalClassPK()))) {
353                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
354                                    new Object[] {
355                                            new Long(subscription.getCompanyId()),
356                                            new Long(subscription.getUserId()),
357                                            new Long(subscription.getClassNameId()),
358                                            new Long(subscription.getClassPK())
359                                    }, subscription);
360                    }
361    
362                    return subscription;
363            }
364    
365            protected Subscription toUnwrappedModel(Subscription subscription) {
366                    if (subscription instanceof SubscriptionImpl) {
367                            return subscription;
368                    }
369    
370                    SubscriptionImpl subscriptionImpl = new SubscriptionImpl();
371    
372                    subscriptionImpl.setNew(subscription.isNew());
373                    subscriptionImpl.setPrimaryKey(subscription.getPrimaryKey());
374    
375                    subscriptionImpl.setSubscriptionId(subscription.getSubscriptionId());
376                    subscriptionImpl.setCompanyId(subscription.getCompanyId());
377                    subscriptionImpl.setUserId(subscription.getUserId());
378                    subscriptionImpl.setUserName(subscription.getUserName());
379                    subscriptionImpl.setCreateDate(subscription.getCreateDate());
380                    subscriptionImpl.setModifiedDate(subscription.getModifiedDate());
381                    subscriptionImpl.setClassNameId(subscription.getClassNameId());
382                    subscriptionImpl.setClassPK(subscription.getClassPK());
383                    subscriptionImpl.setFrequency(subscription.getFrequency());
384    
385                    return subscriptionImpl;
386            }
387    
388            /**
389             * Finds the subscription with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
390             *
391             * @param primaryKey the primary key of the subscription to find
392             * @return the subscription
393             * @throws com.liferay.portal.NoSuchModelException if a subscription with the primary key could not be found
394             * @throws SystemException if a system exception occurred
395             */
396            public Subscription findByPrimaryKey(Serializable primaryKey)
397                    throws NoSuchModelException, SystemException {
398                    return findByPrimaryKey(((Long)primaryKey).longValue());
399            }
400    
401            /**
402             * Finds the subscription with the primary key or throws a {@link com.liferay.portal.NoSuchSubscriptionException} if it could not be found.
403             *
404             * @param subscriptionId the primary key of the subscription to find
405             * @return the subscription
406             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
407             * @throws SystemException if a system exception occurred
408             */
409            public Subscription findByPrimaryKey(long subscriptionId)
410                    throws NoSuchSubscriptionException, SystemException {
411                    Subscription subscription = fetchByPrimaryKey(subscriptionId);
412    
413                    if (subscription == null) {
414                            if (_log.isWarnEnabled()) {
415                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + subscriptionId);
416                            }
417    
418                            throw new NoSuchSubscriptionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
419                                    subscriptionId);
420                    }
421    
422                    return subscription;
423            }
424    
425            /**
426             * Finds the subscription with the primary key or returns <code>null</code> if it could not be found.
427             *
428             * @param primaryKey the primary key of the subscription to find
429             * @return the subscription, or <code>null</code> if a subscription with the primary key could not be found
430             * @throws SystemException if a system exception occurred
431             */
432            public Subscription fetchByPrimaryKey(Serializable primaryKey)
433                    throws SystemException {
434                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
435            }
436    
437            /**
438             * Finds the subscription with the primary key or returns <code>null</code> if it could not be found.
439             *
440             * @param subscriptionId the primary key of the subscription to find
441             * @return the subscription, or <code>null</code> if a subscription with the primary key could not be found
442             * @throws SystemException if a system exception occurred
443             */
444            public Subscription fetchByPrimaryKey(long subscriptionId)
445                    throws SystemException {
446                    Subscription subscription = (Subscription)EntityCacheUtil.getResult(SubscriptionModelImpl.ENTITY_CACHE_ENABLED,
447                                    SubscriptionImpl.class, subscriptionId, this);
448    
449                    if (subscription == null) {
450                            Session session = null;
451    
452                            try {
453                                    session = openSession();
454    
455                                    subscription = (Subscription)session.get(SubscriptionImpl.class,
456                                                    new Long(subscriptionId));
457                            }
458                            catch (Exception e) {
459                                    throw processException(e);
460                            }
461                            finally {
462                                    if (subscription != null) {
463                                            cacheResult(subscription);
464                                    }
465    
466                                    closeSession(session);
467                            }
468                    }
469    
470                    return subscription;
471            }
472    
473            /**
474             * Finds all the subscriptions where userId = &#63;.
475             *
476             * @param userId the user id to search with
477             * @return the matching subscriptions
478             * @throws SystemException if a system exception occurred
479             */
480            public List<Subscription> findByUserId(long userId)
481                    throws SystemException {
482                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
483            }
484    
485            /**
486             * Finds a range of all the subscriptions where userId = &#63;.
487             *
488             * <p>
489             * 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.
490             * </p>
491             *
492             * @param userId the user id to search with
493             * @param start the lower bound of the range of subscriptions to return
494             * @param end the upper bound of the range of subscriptions to return (not inclusive)
495             * @return the range of matching subscriptions
496             * @throws SystemException if a system exception occurred
497             */
498            public List<Subscription> findByUserId(long userId, int start, int end)
499                    throws SystemException {
500                    return findByUserId(userId, start, end, null);
501            }
502    
503            /**
504             * Finds an ordered range of all the subscriptions where userId = &#63;.
505             *
506             * <p>
507             * 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.
508             * </p>
509             *
510             * @param userId the user id to search with
511             * @param start the lower bound of the range of subscriptions to return
512             * @param end the upper bound of the range of subscriptions to return (not inclusive)
513             * @param orderByComparator the comparator to order the results by
514             * @return the ordered range of matching subscriptions
515             * @throws SystemException if a system exception occurred
516             */
517            public List<Subscription> findByUserId(long userId, int start, int end,
518                    OrderByComparator orderByComparator) throws SystemException {
519                    Object[] finderArgs = new Object[] {
520                                    userId,
521                                    
522                                    String.valueOf(start), String.valueOf(end),
523                                    String.valueOf(orderByComparator)
524                            };
525    
526                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
527                                    finderArgs, this);
528    
529                    if (list == null) {
530                            StringBundler query = null;
531    
532                            if (orderByComparator != null) {
533                                    query = new StringBundler(3 +
534                                                    (orderByComparator.getOrderByFields().length * 3));
535                            }
536                            else {
537                                    query = new StringBundler(2);
538                            }
539    
540                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
541    
542                            query.append(_FINDER_COLUMN_USERID_USERID_2);
543    
544                            if (orderByComparator != null) {
545                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
546                                            orderByComparator);
547                            }
548    
549                            String sql = query.toString();
550    
551                            Session session = null;
552    
553                            try {
554                                    session = openSession();
555    
556                                    Query q = session.createQuery(sql);
557    
558                                    QueryPos qPos = QueryPos.getInstance(q);
559    
560                                    qPos.add(userId);
561    
562                                    list = (List<Subscription>)QueryUtil.list(q, getDialect(),
563                                                    start, end);
564                            }
565                            catch (Exception e) {
566                                    throw processException(e);
567                            }
568                            finally {
569                                    if (list == null) {
570                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID,
571                                                    finderArgs);
572                                    }
573                                    else {
574                                            cacheResult(list);
575    
576                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
577                                                    finderArgs, list);
578                                    }
579    
580                                    closeSession(session);
581                            }
582                    }
583    
584                    return list;
585            }
586    
587            /**
588             * Finds the first subscription in the ordered set where userId = &#63;.
589             *
590             * <p>
591             * 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.
592             * </p>
593             *
594             * @param userId the user id to search with
595             * @param orderByComparator the comparator to order the set by
596             * @return the first matching subscription
597             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
598             * @throws SystemException if a system exception occurred
599             */
600            public Subscription findByUserId_First(long userId,
601                    OrderByComparator orderByComparator)
602                    throws NoSuchSubscriptionException, SystemException {
603                    List<Subscription> list = findByUserId(userId, 0, 1, orderByComparator);
604    
605                    if (list.isEmpty()) {
606                            StringBundler msg = new StringBundler(4);
607    
608                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
609    
610                            msg.append("userId=");
611                            msg.append(userId);
612    
613                            msg.append(StringPool.CLOSE_CURLY_BRACE);
614    
615                            throw new NoSuchSubscriptionException(msg.toString());
616                    }
617                    else {
618                            return list.get(0);
619                    }
620            }
621    
622            /**
623             * Finds the last subscription in the ordered set where userId = &#63;.
624             *
625             * <p>
626             * 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.
627             * </p>
628             *
629             * @param userId the user id to search with
630             * @param orderByComparator the comparator to order the set by
631             * @return the last matching subscription
632             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
633             * @throws SystemException if a system exception occurred
634             */
635            public Subscription findByUserId_Last(long userId,
636                    OrderByComparator orderByComparator)
637                    throws NoSuchSubscriptionException, SystemException {
638                    int count = countByUserId(userId);
639    
640                    List<Subscription> list = findByUserId(userId, count - 1, count,
641                                    orderByComparator);
642    
643                    if (list.isEmpty()) {
644                            StringBundler msg = new StringBundler(4);
645    
646                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
647    
648                            msg.append("userId=");
649                            msg.append(userId);
650    
651                            msg.append(StringPool.CLOSE_CURLY_BRACE);
652    
653                            throw new NoSuchSubscriptionException(msg.toString());
654                    }
655                    else {
656                            return list.get(0);
657                    }
658            }
659    
660            /**
661             * Finds the subscriptions before and after the current subscription in the ordered set where userId = &#63;.
662             *
663             * <p>
664             * 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.
665             * </p>
666             *
667             * @param subscriptionId the primary key of the current subscription
668             * @param userId the user id to search with
669             * @param orderByComparator the comparator to order the set by
670             * @return the previous, current, and next subscription
671             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
672             * @throws SystemException if a system exception occurred
673             */
674            public Subscription[] findByUserId_PrevAndNext(long subscriptionId,
675                    long userId, OrderByComparator orderByComparator)
676                    throws NoSuchSubscriptionException, SystemException {
677                    Subscription subscription = findByPrimaryKey(subscriptionId);
678    
679                    Session session = null;
680    
681                    try {
682                            session = openSession();
683    
684                            Subscription[] array = new SubscriptionImpl[3];
685    
686                            array[0] = getByUserId_PrevAndNext(session, subscription, userId,
687                                            orderByComparator, true);
688    
689                            array[1] = subscription;
690    
691                            array[2] = getByUserId_PrevAndNext(session, subscription, userId,
692                                            orderByComparator, false);
693    
694                            return array;
695                    }
696                    catch (Exception e) {
697                            throw processException(e);
698                    }
699                    finally {
700                            closeSession(session);
701                    }
702            }
703    
704            protected Subscription getByUserId_PrevAndNext(Session session,
705                    Subscription subscription, long userId,
706                    OrderByComparator orderByComparator, boolean previous) {
707                    StringBundler query = null;
708    
709                    if (orderByComparator != null) {
710                            query = new StringBundler(6 +
711                                            (orderByComparator.getOrderByFields().length * 6));
712                    }
713                    else {
714                            query = new StringBundler(3);
715                    }
716    
717                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
718    
719                    query.append(_FINDER_COLUMN_USERID_USERID_2);
720    
721                    if (orderByComparator != null) {
722                            String[] orderByFields = orderByComparator.getOrderByFields();
723    
724                            if (orderByFields.length > 0) {
725                                    query.append(WHERE_AND);
726                            }
727    
728                            for (int i = 0; i < orderByFields.length; i++) {
729                                    query.append(_ORDER_BY_ENTITY_ALIAS);
730                                    query.append(orderByFields[i]);
731    
732                                    if ((i + 1) < orderByFields.length) {
733                                            if (orderByComparator.isAscending() ^ previous) {
734                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
735                                            }
736                                            else {
737                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
738                                            }
739                                    }
740                                    else {
741                                            if (orderByComparator.isAscending() ^ previous) {
742                                                    query.append(WHERE_GREATER_THAN);
743                                            }
744                                            else {
745                                                    query.append(WHERE_LESSER_THAN);
746                                            }
747                                    }
748                            }
749    
750                            query.append(ORDER_BY_CLAUSE);
751    
752                            for (int i = 0; i < orderByFields.length; i++) {
753                                    query.append(_ORDER_BY_ENTITY_ALIAS);
754                                    query.append(orderByFields[i]);
755    
756                                    if ((i + 1) < orderByFields.length) {
757                                            if (orderByComparator.isAscending() ^ previous) {
758                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
759                                            }
760                                            else {
761                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
762                                            }
763                                    }
764                                    else {
765                                            if (orderByComparator.isAscending() ^ previous) {
766                                                    query.append(ORDER_BY_ASC);
767                                            }
768                                            else {
769                                                    query.append(ORDER_BY_DESC);
770                                            }
771                                    }
772                            }
773                    }
774    
775                    String sql = query.toString();
776    
777                    Query q = session.createQuery(sql);
778    
779                    q.setFirstResult(0);
780                    q.setMaxResults(2);
781    
782                    QueryPos qPos = QueryPos.getInstance(q);
783    
784                    qPos.add(userId);
785    
786                    if (orderByComparator != null) {
787                            Object[] values = orderByComparator.getOrderByValues(subscription);
788    
789                            for (Object value : values) {
790                                    qPos.add(value);
791                            }
792                    }
793    
794                    List<Subscription> list = q.list();
795    
796                    if (list.size() == 2) {
797                            return list.get(1);
798                    }
799                    else {
800                            return null;
801                    }
802            }
803    
804            /**
805             * Finds all the subscriptions where userId = &#63; and classNameId = &#63;.
806             *
807             * @param userId the user id to search with
808             * @param classNameId the class name id to search with
809             * @return the matching subscriptions
810             * @throws SystemException if a system exception occurred
811             */
812            public List<Subscription> findByU_C(long userId, long classNameId)
813                    throws SystemException {
814                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
815                            QueryUtil.ALL_POS, null);
816            }
817    
818            /**
819             * Finds a range of all the subscriptions where userId = &#63; and classNameId = &#63;.
820             *
821             * <p>
822             * 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.
823             * </p>
824             *
825             * @param userId the user id to search with
826             * @param classNameId the class name id to search with
827             * @param start the lower bound of the range of subscriptions to return
828             * @param end the upper bound of the range of subscriptions to return (not inclusive)
829             * @return the range of matching subscriptions
830             * @throws SystemException if a system exception occurred
831             */
832            public List<Subscription> findByU_C(long userId, long classNameId,
833                    int start, int end) throws SystemException {
834                    return findByU_C(userId, classNameId, start, end, null);
835            }
836    
837            /**
838             * Finds an ordered range of all the subscriptions where userId = &#63; and classNameId = &#63;.
839             *
840             * <p>
841             * 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.
842             * </p>
843             *
844             * @param userId the user id to search with
845             * @param classNameId the class name id to search with
846             * @param start the lower bound of the range of subscriptions to return
847             * @param end the upper bound of the range of subscriptions to return (not inclusive)
848             * @param orderByComparator the comparator to order the results by
849             * @return the ordered range of matching subscriptions
850             * @throws SystemException if a system exception occurred
851             */
852            public List<Subscription> findByU_C(long userId, long classNameId,
853                    int start, int end, OrderByComparator orderByComparator)
854                    throws SystemException {
855                    Object[] finderArgs = new Object[] {
856                                    userId, classNameId,
857                                    
858                                    String.valueOf(start), String.valueOf(end),
859                                    String.valueOf(orderByComparator)
860                            };
861    
862                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_C,
863                                    finderArgs, this);
864    
865                    if (list == null) {
866                            StringBundler query = null;
867    
868                            if (orderByComparator != null) {
869                                    query = new StringBundler(4 +
870                                                    (orderByComparator.getOrderByFields().length * 3));
871                            }
872                            else {
873                                    query = new StringBundler(3);
874                            }
875    
876                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
877    
878                            query.append(_FINDER_COLUMN_U_C_USERID_2);
879    
880                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
881    
882                            if (orderByComparator != null) {
883                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
884                                            orderByComparator);
885                            }
886    
887                            String sql = query.toString();
888    
889                            Session session = null;
890    
891                            try {
892                                    session = openSession();
893    
894                                    Query q = session.createQuery(sql);
895    
896                                    QueryPos qPos = QueryPos.getInstance(q);
897    
898                                    qPos.add(userId);
899    
900                                    qPos.add(classNameId);
901    
902                                    list = (List<Subscription>)QueryUtil.list(q, getDialect(),
903                                                    start, end);
904                            }
905                            catch (Exception e) {
906                                    throw processException(e);
907                            }
908                            finally {
909                                    if (list == null) {
910                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_U_C,
911                                                    finderArgs);
912                                    }
913                                    else {
914                                            cacheResult(list);
915    
916                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_C,
917                                                    finderArgs, list);
918                                    }
919    
920                                    closeSession(session);
921                            }
922                    }
923    
924                    return list;
925            }
926    
927            /**
928             * Finds the first subscription in the ordered set where userId = &#63; and classNameId = &#63;.
929             *
930             * <p>
931             * 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.
932             * </p>
933             *
934             * @param userId the user id to search with
935             * @param classNameId the class name id to search with
936             * @param orderByComparator the comparator to order the set by
937             * @return the first matching subscription
938             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
939             * @throws SystemException if a system exception occurred
940             */
941            public Subscription findByU_C_First(long userId, long classNameId,
942                    OrderByComparator orderByComparator)
943                    throws NoSuchSubscriptionException, SystemException {
944                    List<Subscription> list = findByU_C(userId, classNameId, 0, 1,
945                                    orderByComparator);
946    
947                    if (list.isEmpty()) {
948                            StringBundler msg = new StringBundler(6);
949    
950                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
951    
952                            msg.append("userId=");
953                            msg.append(userId);
954    
955                            msg.append(", classNameId=");
956                            msg.append(classNameId);
957    
958                            msg.append(StringPool.CLOSE_CURLY_BRACE);
959    
960                            throw new NoSuchSubscriptionException(msg.toString());
961                    }
962                    else {
963                            return list.get(0);
964                    }
965            }
966    
967            /**
968             * Finds the last subscription in the ordered set where userId = &#63; and classNameId = &#63;.
969             *
970             * <p>
971             * 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.
972             * </p>
973             *
974             * @param userId the user id to search with
975             * @param classNameId the class name id to search with
976             * @param orderByComparator the comparator to order the set by
977             * @return the last matching subscription
978             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
979             * @throws SystemException if a system exception occurred
980             */
981            public Subscription findByU_C_Last(long userId, long classNameId,
982                    OrderByComparator orderByComparator)
983                    throws NoSuchSubscriptionException, SystemException {
984                    int count = countByU_C(userId, classNameId);
985    
986                    List<Subscription> list = findByU_C(userId, classNameId, count - 1,
987                                    count, orderByComparator);
988    
989                    if (list.isEmpty()) {
990                            StringBundler msg = new StringBundler(6);
991    
992                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
993    
994                            msg.append("userId=");
995                            msg.append(userId);
996    
997                            msg.append(", classNameId=");
998                            msg.append(classNameId);
999    
1000                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1001    
1002                            throw new NoSuchSubscriptionException(msg.toString());
1003                    }
1004                    else {
1005                            return list.get(0);
1006                    }
1007            }
1008    
1009            /**
1010             * Finds the subscriptions before and after the current subscription in the ordered set where userId = &#63; and classNameId = &#63;.
1011             *
1012             * <p>
1013             * 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.
1014             * </p>
1015             *
1016             * @param subscriptionId the primary key of the current subscription
1017             * @param userId the user id to search with
1018             * @param classNameId the class name id to search with
1019             * @param orderByComparator the comparator to order the set by
1020             * @return the previous, current, and next subscription
1021             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
1022             * @throws SystemException if a system exception occurred
1023             */
1024            public Subscription[] findByU_C_PrevAndNext(long subscriptionId,
1025                    long userId, long classNameId, OrderByComparator orderByComparator)
1026                    throws NoSuchSubscriptionException, SystemException {
1027                    Subscription subscription = findByPrimaryKey(subscriptionId);
1028    
1029                    Session session = null;
1030    
1031                    try {
1032                            session = openSession();
1033    
1034                            Subscription[] array = new SubscriptionImpl[3];
1035    
1036                            array[0] = getByU_C_PrevAndNext(session, subscription, userId,
1037                                            classNameId, orderByComparator, true);
1038    
1039                            array[1] = subscription;
1040    
1041                            array[2] = getByU_C_PrevAndNext(session, subscription, userId,
1042                                            classNameId, orderByComparator, false);
1043    
1044                            return array;
1045                    }
1046                    catch (Exception e) {
1047                            throw processException(e);
1048                    }
1049                    finally {
1050                            closeSession(session);
1051                    }
1052            }
1053    
1054            protected Subscription getByU_C_PrevAndNext(Session session,
1055                    Subscription subscription, long userId, long classNameId,
1056                    OrderByComparator orderByComparator, boolean previous) {
1057                    StringBundler query = null;
1058    
1059                    if (orderByComparator != null) {
1060                            query = new StringBundler(6 +
1061                                            (orderByComparator.getOrderByFields().length * 6));
1062                    }
1063                    else {
1064                            query = new StringBundler(3);
1065                    }
1066    
1067                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1068    
1069                    query.append(_FINDER_COLUMN_U_C_USERID_2);
1070    
1071                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1072    
1073                    if (orderByComparator != null) {
1074                            String[] orderByFields = orderByComparator.getOrderByFields();
1075    
1076                            if (orderByFields.length > 0) {
1077                                    query.append(WHERE_AND);
1078                            }
1079    
1080                            for (int i = 0; i < orderByFields.length; i++) {
1081                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1082                                    query.append(orderByFields[i]);
1083    
1084                                    if ((i + 1) < orderByFields.length) {
1085                                            if (orderByComparator.isAscending() ^ previous) {
1086                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1087                                            }
1088                                            else {
1089                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1090                                            }
1091                                    }
1092                                    else {
1093                                            if (orderByComparator.isAscending() ^ previous) {
1094                                                    query.append(WHERE_GREATER_THAN);
1095                                            }
1096                                            else {
1097                                                    query.append(WHERE_LESSER_THAN);
1098                                            }
1099                                    }
1100                            }
1101    
1102                            query.append(ORDER_BY_CLAUSE);
1103    
1104                            for (int i = 0; i < orderByFields.length; i++) {
1105                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1106                                    query.append(orderByFields[i]);
1107    
1108                                    if ((i + 1) < orderByFields.length) {
1109                                            if (orderByComparator.isAscending() ^ previous) {
1110                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1111                                            }
1112                                            else {
1113                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1114                                            }
1115                                    }
1116                                    else {
1117                                            if (orderByComparator.isAscending() ^ previous) {
1118                                                    query.append(ORDER_BY_ASC);
1119                                            }
1120                                            else {
1121                                                    query.append(ORDER_BY_DESC);
1122                                            }
1123                                    }
1124                            }
1125                    }
1126    
1127                    String sql = query.toString();
1128    
1129                    Query q = session.createQuery(sql);
1130    
1131                    q.setFirstResult(0);
1132                    q.setMaxResults(2);
1133    
1134                    QueryPos qPos = QueryPos.getInstance(q);
1135    
1136                    qPos.add(userId);
1137    
1138                    qPos.add(classNameId);
1139    
1140                    if (orderByComparator != null) {
1141                            Object[] values = orderByComparator.getOrderByValues(subscription);
1142    
1143                            for (Object value : values) {
1144                                    qPos.add(value);
1145                            }
1146                    }
1147    
1148                    List<Subscription> list = q.list();
1149    
1150                    if (list.size() == 2) {
1151                            return list.get(1);
1152                    }
1153                    else {
1154                            return null;
1155                    }
1156            }
1157    
1158            /**
1159             * Finds all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1160             *
1161             * @param companyId the company id to search with
1162             * @param classNameId the class name id to search with
1163             * @param classPK the class p k to search with
1164             * @return the matching subscriptions
1165             * @throws SystemException if a system exception occurred
1166             */
1167            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1168                    long classPK) throws SystemException {
1169                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1170                            QueryUtil.ALL_POS, null);
1171            }
1172    
1173            /**
1174             * Finds a range of all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1175             *
1176             * <p>
1177             * 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.
1178             * </p>
1179             *
1180             * @param companyId the company id to search with
1181             * @param classNameId the class name id to search with
1182             * @param classPK the class p k to search with
1183             * @param start the lower bound of the range of subscriptions to return
1184             * @param end the upper bound of the range of subscriptions to return (not inclusive)
1185             * @return the range of matching subscriptions
1186             * @throws SystemException if a system exception occurred
1187             */
1188            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1189                    long classPK, int start, int end) throws SystemException {
1190                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1191            }
1192    
1193            /**
1194             * Finds an ordered range of all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1195             *
1196             * <p>
1197             * 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.
1198             * </p>
1199             *
1200             * @param companyId the company id to search with
1201             * @param classNameId the class name id to search with
1202             * @param classPK the class p k to search with
1203             * @param start the lower bound of the range of subscriptions to return
1204             * @param end the upper bound of the range of subscriptions to return (not inclusive)
1205             * @param orderByComparator the comparator to order the results by
1206             * @return the ordered range of matching subscriptions
1207             * @throws SystemException if a system exception occurred
1208             */
1209            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1210                    long classPK, int start, int end, OrderByComparator orderByComparator)
1211                    throws SystemException {
1212                    Object[] finderArgs = new Object[] {
1213                                    companyId, classNameId, classPK,
1214                                    
1215                                    String.valueOf(start), String.valueOf(end),
1216                                    String.valueOf(orderByComparator)
1217                            };
1218    
1219                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C,
1220                                    finderArgs, this);
1221    
1222                    if (list == null) {
1223                            StringBundler query = null;
1224    
1225                            if (orderByComparator != null) {
1226                                    query = new StringBundler(5 +
1227                                                    (orderByComparator.getOrderByFields().length * 3));
1228                            }
1229                            else {
1230                                    query = new StringBundler(4);
1231                            }
1232    
1233                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1234    
1235                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1236    
1237                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1238    
1239                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1240    
1241                            if (orderByComparator != null) {
1242                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1243                                            orderByComparator);
1244                            }
1245    
1246                            String sql = query.toString();
1247    
1248                            Session session = null;
1249    
1250                            try {
1251                                    session = openSession();
1252    
1253                                    Query q = session.createQuery(sql);
1254    
1255                                    QueryPos qPos = QueryPos.getInstance(q);
1256    
1257                                    qPos.add(companyId);
1258    
1259                                    qPos.add(classNameId);
1260    
1261                                    qPos.add(classPK);
1262    
1263                                    list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1264                                                    start, end);
1265                            }
1266                            catch (Exception e) {
1267                                    throw processException(e);
1268                            }
1269                            finally {
1270                                    if (list == null) {
1271                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_C_C_C,
1272                                                    finderArgs);
1273                                    }
1274                                    else {
1275                                            cacheResult(list);
1276    
1277                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C,
1278                                                    finderArgs, list);
1279                                    }
1280    
1281                                    closeSession(session);
1282                            }
1283                    }
1284    
1285                    return list;
1286            }
1287    
1288            /**
1289             * Finds the first subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1290             *
1291             * <p>
1292             * 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.
1293             * </p>
1294             *
1295             * @param companyId the company id to search with
1296             * @param classNameId the class name id to search with
1297             * @param classPK the class p k to search with
1298             * @param orderByComparator the comparator to order the set by
1299             * @return the first matching subscription
1300             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
1301             * @throws SystemException if a system exception occurred
1302             */
1303            public Subscription findByC_C_C_First(long companyId, long classNameId,
1304                    long classPK, OrderByComparator orderByComparator)
1305                    throws NoSuchSubscriptionException, SystemException {
1306                    List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1307                                    0, 1, orderByComparator);
1308    
1309                    if (list.isEmpty()) {
1310                            StringBundler msg = new StringBundler(8);
1311    
1312                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1313    
1314                            msg.append("companyId=");
1315                            msg.append(companyId);
1316    
1317                            msg.append(", classNameId=");
1318                            msg.append(classNameId);
1319    
1320                            msg.append(", classPK=");
1321                            msg.append(classPK);
1322    
1323                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1324    
1325                            throw new NoSuchSubscriptionException(msg.toString());
1326                    }
1327                    else {
1328                            return list.get(0);
1329                    }
1330            }
1331    
1332            /**
1333             * Finds the last subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1334             *
1335             * <p>
1336             * 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.
1337             * </p>
1338             *
1339             * @param companyId the company id to search with
1340             * @param classNameId the class name id to search with
1341             * @param classPK the class p k to search with
1342             * @param orderByComparator the comparator to order the set by
1343             * @return the last matching subscription
1344             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
1345             * @throws SystemException if a system exception occurred
1346             */
1347            public Subscription findByC_C_C_Last(long companyId, long classNameId,
1348                    long classPK, OrderByComparator orderByComparator)
1349                    throws NoSuchSubscriptionException, SystemException {
1350                    int count = countByC_C_C(companyId, classNameId, classPK);
1351    
1352                    List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1353                                    count - 1, count, orderByComparator);
1354    
1355                    if (list.isEmpty()) {
1356                            StringBundler msg = new StringBundler(8);
1357    
1358                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1359    
1360                            msg.append("companyId=");
1361                            msg.append(companyId);
1362    
1363                            msg.append(", classNameId=");
1364                            msg.append(classNameId);
1365    
1366                            msg.append(", classPK=");
1367                            msg.append(classPK);
1368    
1369                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1370    
1371                            throw new NoSuchSubscriptionException(msg.toString());
1372                    }
1373                    else {
1374                            return list.get(0);
1375                    }
1376            }
1377    
1378            /**
1379             * Finds the subscriptions before and after the current subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1380             *
1381             * <p>
1382             * 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.
1383             * </p>
1384             *
1385             * @param subscriptionId the primary key of the current subscription
1386             * @param companyId the company id to search with
1387             * @param classNameId the class name id to search with
1388             * @param classPK the class p k to search with
1389             * @param orderByComparator the comparator to order the set by
1390             * @return the previous, current, and next subscription
1391             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
1392             * @throws SystemException if a system exception occurred
1393             */
1394            public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId,
1395                    long companyId, long classNameId, long classPK,
1396                    OrderByComparator orderByComparator)
1397                    throws NoSuchSubscriptionException, SystemException {
1398                    Subscription subscription = findByPrimaryKey(subscriptionId);
1399    
1400                    Session session = null;
1401    
1402                    try {
1403                            session = openSession();
1404    
1405                            Subscription[] array = new SubscriptionImpl[3];
1406    
1407                            array[0] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1408                                            classNameId, classPK, orderByComparator, true);
1409    
1410                            array[1] = subscription;
1411    
1412                            array[2] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1413                                            classNameId, classPK, orderByComparator, false);
1414    
1415                            return array;
1416                    }
1417                    catch (Exception e) {
1418                            throw processException(e);
1419                    }
1420                    finally {
1421                            closeSession(session);
1422                    }
1423            }
1424    
1425            protected Subscription getByC_C_C_PrevAndNext(Session session,
1426                    Subscription subscription, long companyId, long classNameId,
1427                    long classPK, OrderByComparator orderByComparator, boolean previous) {
1428                    StringBundler query = null;
1429    
1430                    if (orderByComparator != null) {
1431                            query = new StringBundler(6 +
1432                                            (orderByComparator.getOrderByFields().length * 6));
1433                    }
1434                    else {
1435                            query = new StringBundler(3);
1436                    }
1437    
1438                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1439    
1440                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1441    
1442                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1443    
1444                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1445    
1446                    if (orderByComparator != null) {
1447                            String[] orderByFields = orderByComparator.getOrderByFields();
1448    
1449                            if (orderByFields.length > 0) {
1450                                    query.append(WHERE_AND);
1451                            }
1452    
1453                            for (int i = 0; i < orderByFields.length; i++) {
1454                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1455                                    query.append(orderByFields[i]);
1456    
1457                                    if ((i + 1) < orderByFields.length) {
1458                                            if (orderByComparator.isAscending() ^ previous) {
1459                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1460                                            }
1461                                            else {
1462                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1463                                            }
1464                                    }
1465                                    else {
1466                                            if (orderByComparator.isAscending() ^ previous) {
1467                                                    query.append(WHERE_GREATER_THAN);
1468                                            }
1469                                            else {
1470                                                    query.append(WHERE_LESSER_THAN);
1471                                            }
1472                                    }
1473                            }
1474    
1475                            query.append(ORDER_BY_CLAUSE);
1476    
1477                            for (int i = 0; i < orderByFields.length; i++) {
1478                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1479                                    query.append(orderByFields[i]);
1480    
1481                                    if ((i + 1) < orderByFields.length) {
1482                                            if (orderByComparator.isAscending() ^ previous) {
1483                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1484                                            }
1485                                            else {
1486                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1487                                            }
1488                                    }
1489                                    else {
1490                                            if (orderByComparator.isAscending() ^ previous) {
1491                                                    query.append(ORDER_BY_ASC);
1492                                            }
1493                                            else {
1494                                                    query.append(ORDER_BY_DESC);
1495                                            }
1496                                    }
1497                            }
1498                    }
1499    
1500                    String sql = query.toString();
1501    
1502                    Query q = session.createQuery(sql);
1503    
1504                    q.setFirstResult(0);
1505                    q.setMaxResults(2);
1506    
1507                    QueryPos qPos = QueryPos.getInstance(q);
1508    
1509                    qPos.add(companyId);
1510    
1511                    qPos.add(classNameId);
1512    
1513                    qPos.add(classPK);
1514    
1515                    if (orderByComparator != null) {
1516                            Object[] values = orderByComparator.getOrderByValues(subscription);
1517    
1518                            for (Object value : values) {
1519                                    qPos.add(value);
1520                            }
1521                    }
1522    
1523                    List<Subscription> list = q.list();
1524    
1525                    if (list.size() == 2) {
1526                            return list.get(1);
1527                    }
1528                    else {
1529                            return null;
1530                    }
1531            }
1532    
1533            /**
1534             * Finds 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.
1535             *
1536             * @param companyId the company id to search with
1537             * @param userId the user id to search with
1538             * @param classNameId the class name id to search with
1539             * @param classPK the class p k to search with
1540             * @return the matching subscription
1541             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
1542             * @throws SystemException if a system exception occurred
1543             */
1544            public Subscription findByC_U_C_C(long companyId, long userId,
1545                    long classNameId, long classPK)
1546                    throws NoSuchSubscriptionException, SystemException {
1547                    Subscription subscription = fetchByC_U_C_C(companyId, userId,
1548                                    classNameId, classPK);
1549    
1550                    if (subscription == null) {
1551                            StringBundler msg = new StringBundler(10);
1552    
1553                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1554    
1555                            msg.append("companyId=");
1556                            msg.append(companyId);
1557    
1558                            msg.append(", userId=");
1559                            msg.append(userId);
1560    
1561                            msg.append(", classNameId=");
1562                            msg.append(classNameId);
1563    
1564                            msg.append(", classPK=");
1565                            msg.append(classPK);
1566    
1567                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1568    
1569                            if (_log.isWarnEnabled()) {
1570                                    _log.warn(msg.toString());
1571                            }
1572    
1573                            throw new NoSuchSubscriptionException(msg.toString());
1574                    }
1575    
1576                    return subscription;
1577            }
1578    
1579            /**
1580             * Finds 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.
1581             *
1582             * @param companyId the company id to search with
1583             * @param userId the user id to search with
1584             * @param classNameId the class name id to search with
1585             * @param classPK the class p k to search with
1586             * @return the matching subscription, or <code>null</code> if a matching subscription could not be found
1587             * @throws SystemException if a system exception occurred
1588             */
1589            public Subscription fetchByC_U_C_C(long companyId, long userId,
1590                    long classNameId, long classPK) throws SystemException {
1591                    return fetchByC_U_C_C(companyId, userId, classNameId, classPK, true);
1592            }
1593    
1594            /**
1595             * Finds 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.
1596             *
1597             * @param companyId the company id to search with
1598             * @param userId the user id to search with
1599             * @param classNameId the class name id to search with
1600             * @param classPK the class p k to search with
1601             * @return the matching subscription, or <code>null</code> if a matching subscription could not be found
1602             * @throws SystemException if a system exception occurred
1603             */
1604            public Subscription fetchByC_U_C_C(long companyId, long userId,
1605                    long classNameId, long classPK, boolean retrieveFromCache)
1606                    throws SystemException {
1607                    Object[] finderArgs = new Object[] {
1608                                    companyId, userId, classNameId, classPK
1609                            };
1610    
1611                    Object result = null;
1612    
1613                    if (retrieveFromCache) {
1614                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1615                                            finderArgs, this);
1616                    }
1617    
1618                    if (result == null) {
1619                            StringBundler query = new StringBundler(5);
1620    
1621                            query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1622    
1623                            query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
1624    
1625                            query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
1626    
1627                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
1628    
1629                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
1630    
1631                            String sql = query.toString();
1632    
1633                            Session session = null;
1634    
1635                            try {
1636                                    session = openSession();
1637    
1638                                    Query q = session.createQuery(sql);
1639    
1640                                    QueryPos qPos = QueryPos.getInstance(q);
1641    
1642                                    qPos.add(companyId);
1643    
1644                                    qPos.add(userId);
1645    
1646                                    qPos.add(classNameId);
1647    
1648                                    qPos.add(classPK);
1649    
1650                                    List<Subscription> list = q.list();
1651    
1652                                    result = list;
1653    
1654                                    Subscription subscription = null;
1655    
1656                                    if (list.isEmpty()) {
1657                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1658                                                    finderArgs, list);
1659                                    }
1660                                    else {
1661                                            subscription = list.get(0);
1662    
1663                                            cacheResult(subscription);
1664    
1665                                            if ((subscription.getCompanyId() != companyId) ||
1666                                                            (subscription.getUserId() != userId) ||
1667                                                            (subscription.getClassNameId() != classNameId) ||
1668                                                            (subscription.getClassPK() != classPK)) {
1669                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1670                                                            finderArgs, subscription);
1671                                            }
1672                                    }
1673    
1674                                    return subscription;
1675                            }
1676                            catch (Exception e) {
1677                                    throw processException(e);
1678                            }
1679                            finally {
1680                                    if (result == null) {
1681                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1682                                                    finderArgs);
1683                                    }
1684    
1685                                    closeSession(session);
1686                            }
1687                    }
1688                    else {
1689                            if (result instanceof List<?>) {
1690                                    return null;
1691                            }
1692                            else {
1693                                    return (Subscription)result;
1694                            }
1695                    }
1696            }
1697    
1698            /**
1699             * Finds all the subscriptions.
1700             *
1701             * @return the subscriptions
1702             * @throws SystemException if a system exception occurred
1703             */
1704            public List<Subscription> findAll() throws SystemException {
1705                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1706            }
1707    
1708            /**
1709             * Finds a range of all the subscriptions.
1710             *
1711             * <p>
1712             * 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.
1713             * </p>
1714             *
1715             * @param start the lower bound of the range of subscriptions to return
1716             * @param end the upper bound of the range of subscriptions to return (not inclusive)
1717             * @return the range of subscriptions
1718             * @throws SystemException if a system exception occurred
1719             */
1720            public List<Subscription> findAll(int start, int end)
1721                    throws SystemException {
1722                    return findAll(start, end, null);
1723            }
1724    
1725            /**
1726             * Finds an ordered range of all the subscriptions.
1727             *
1728             * <p>
1729             * 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.
1730             * </p>
1731             *
1732             * @param start the lower bound of the range of subscriptions to return
1733             * @param end the upper bound of the range of subscriptions to return (not inclusive)
1734             * @param orderByComparator the comparator to order the results by
1735             * @return the ordered range of subscriptions
1736             * @throws SystemException if a system exception occurred
1737             */
1738            public List<Subscription> findAll(int start, int end,
1739                    OrderByComparator orderByComparator) throws SystemException {
1740                    Object[] finderArgs = new Object[] {
1741                                    String.valueOf(start), String.valueOf(end),
1742                                    String.valueOf(orderByComparator)
1743                            };
1744    
1745                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1746                                    finderArgs, this);
1747    
1748                    if (list == null) {
1749                            StringBundler query = null;
1750                            String sql = null;
1751    
1752                            if (orderByComparator != null) {
1753                                    query = new StringBundler(2 +
1754                                                    (orderByComparator.getOrderByFields().length * 3));
1755    
1756                                    query.append(_SQL_SELECT_SUBSCRIPTION);
1757    
1758                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1759                                            orderByComparator);
1760    
1761                                    sql = query.toString();
1762                            }
1763                            else {
1764                                    sql = _SQL_SELECT_SUBSCRIPTION;
1765                            }
1766    
1767                            Session session = null;
1768    
1769                            try {
1770                                    session = openSession();
1771    
1772                                    Query q = session.createQuery(sql);
1773    
1774                                    if (orderByComparator == null) {
1775                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1776                                                            start, end, false);
1777    
1778                                            Collections.sort(list);
1779                                    }
1780                                    else {
1781                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1782                                                            start, end);
1783                                    }
1784                            }
1785                            catch (Exception e) {
1786                                    throw processException(e);
1787                            }
1788                            finally {
1789                                    if (list == null) {
1790                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1791                                                    finderArgs);
1792                                    }
1793                                    else {
1794                                            cacheResult(list);
1795    
1796                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1797                                                    list);
1798                                    }
1799    
1800                                    closeSession(session);
1801                            }
1802                    }
1803    
1804                    return list;
1805            }
1806    
1807            /**
1808             * Removes all the subscriptions where userId = &#63; from the database.
1809             *
1810             * @param userId the user id to search with
1811             * @throws SystemException if a system exception occurred
1812             */
1813            public void removeByUserId(long userId) throws SystemException {
1814                    for (Subscription subscription : findByUserId(userId)) {
1815                            remove(subscription);
1816                    }
1817            }
1818    
1819            /**
1820             * Removes all the subscriptions where userId = &#63; and classNameId = &#63; from the database.
1821             *
1822             * @param userId the user id to search with
1823             * @param classNameId the class name id to search with
1824             * @throws SystemException if a system exception occurred
1825             */
1826            public void removeByU_C(long userId, long classNameId)
1827                    throws SystemException {
1828                    for (Subscription subscription : findByU_C(userId, classNameId)) {
1829                            remove(subscription);
1830                    }
1831            }
1832    
1833            /**
1834             * Removes all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
1835             *
1836             * @param companyId the company id to search with
1837             * @param classNameId the class name id to search with
1838             * @param classPK the class p k to search with
1839             * @throws SystemException if a system exception occurred
1840             */
1841            public void removeByC_C_C(long companyId, long classNameId, long classPK)
1842                    throws SystemException {
1843                    for (Subscription subscription : findByC_C_C(companyId, classNameId,
1844                                    classPK)) {
1845                            remove(subscription);
1846                    }
1847            }
1848    
1849            /**
1850             * Removes the subscription where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
1851             *
1852             * @param companyId the company id to search with
1853             * @param userId the user id to search with
1854             * @param classNameId the class name id to search with
1855             * @param classPK the class p k to search with
1856             * @throws SystemException if a system exception occurred
1857             */
1858            public void removeByC_U_C_C(long companyId, long userId, long classNameId,
1859                    long classPK) throws NoSuchSubscriptionException, SystemException {
1860                    Subscription subscription = findByC_U_C_C(companyId, userId,
1861                                    classNameId, classPK);
1862    
1863                    remove(subscription);
1864            }
1865    
1866            /**
1867             * Removes all the subscriptions from the database.
1868             *
1869             * @throws SystemException if a system exception occurred
1870             */
1871            public void removeAll() throws SystemException {
1872                    for (Subscription subscription : findAll()) {
1873                            remove(subscription);
1874                    }
1875            }
1876    
1877            /**
1878             * Counts all the subscriptions where userId = &#63;.
1879             *
1880             * @param userId the user id to search with
1881             * @return the number of matching subscriptions
1882             * @throws SystemException if a system exception occurred
1883             */
1884            public int countByUserId(long userId) throws SystemException {
1885                    Object[] finderArgs = new Object[] { userId };
1886    
1887                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1888                                    finderArgs, this);
1889    
1890                    if (count == null) {
1891                            StringBundler query = new StringBundler(2);
1892    
1893                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1894    
1895                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1896    
1897                            String sql = query.toString();
1898    
1899                            Session session = null;
1900    
1901                            try {
1902                                    session = openSession();
1903    
1904                                    Query q = session.createQuery(sql);
1905    
1906                                    QueryPos qPos = QueryPos.getInstance(q);
1907    
1908                                    qPos.add(userId);
1909    
1910                                    count = (Long)q.uniqueResult();
1911                            }
1912                            catch (Exception e) {
1913                                    throw processException(e);
1914                            }
1915                            finally {
1916                                    if (count == null) {
1917                                            count = Long.valueOf(0);
1918                                    }
1919    
1920                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1921                                            finderArgs, count);
1922    
1923                                    closeSession(session);
1924                            }
1925                    }
1926    
1927                    return count.intValue();
1928            }
1929    
1930            /**
1931             * Counts all the subscriptions where userId = &#63; and classNameId = &#63;.
1932             *
1933             * @param userId the user id to search with
1934             * @param classNameId the class name id to search with
1935             * @return the number of matching subscriptions
1936             * @throws SystemException if a system exception occurred
1937             */
1938            public int countByU_C(long userId, long classNameId)
1939                    throws SystemException {
1940                    Object[] finderArgs = new Object[] { userId, classNameId };
1941    
1942                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C,
1943                                    finderArgs, this);
1944    
1945                    if (count == null) {
1946                            StringBundler query = new StringBundler(3);
1947    
1948                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1949    
1950                            query.append(_FINDER_COLUMN_U_C_USERID_2);
1951    
1952                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1953    
1954                            String sql = query.toString();
1955    
1956                            Session session = null;
1957    
1958                            try {
1959                                    session = openSession();
1960    
1961                                    Query q = session.createQuery(sql);
1962    
1963                                    QueryPos qPos = QueryPos.getInstance(q);
1964    
1965                                    qPos.add(userId);
1966    
1967                                    qPos.add(classNameId);
1968    
1969                                    count = (Long)q.uniqueResult();
1970                            }
1971                            catch (Exception e) {
1972                                    throw processException(e);
1973                            }
1974                            finally {
1975                                    if (count == null) {
1976                                            count = Long.valueOf(0);
1977                                    }
1978    
1979                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C, finderArgs,
1980                                            count);
1981    
1982                                    closeSession(session);
1983                            }
1984                    }
1985    
1986                    return count.intValue();
1987            }
1988    
1989            /**
1990             * Counts all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1991             *
1992             * @param companyId the company id to search with
1993             * @param classNameId the class name id to search with
1994             * @param classPK the class p k to search with
1995             * @return the number of matching subscriptions
1996             * @throws SystemException if a system exception occurred
1997             */
1998            public int countByC_C_C(long companyId, long classNameId, long classPK)
1999                    throws SystemException {
2000                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
2001    
2002                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
2003                                    finderArgs, this);
2004    
2005                    if (count == null) {
2006                            StringBundler query = new StringBundler(4);
2007    
2008                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2009    
2010                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2011    
2012                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2013    
2014                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2015    
2016                            String sql = query.toString();
2017    
2018                            Session session = null;
2019    
2020                            try {
2021                                    session = openSession();
2022    
2023                                    Query q = session.createQuery(sql);
2024    
2025                                    QueryPos qPos = QueryPos.getInstance(q);
2026    
2027                                    qPos.add(companyId);
2028    
2029                                    qPos.add(classNameId);
2030    
2031                                    qPos.add(classPK);
2032    
2033                                    count = (Long)q.uniqueResult();
2034                            }
2035                            catch (Exception e) {
2036                                    throw processException(e);
2037                            }
2038                            finally {
2039                                    if (count == null) {
2040                                            count = Long.valueOf(0);
2041                                    }
2042    
2043                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
2044                                            finderArgs, count);
2045    
2046                                    closeSession(session);
2047                            }
2048                    }
2049    
2050                    return count.intValue();
2051            }
2052    
2053            /**
2054             * Counts all the subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63;.
2055             *
2056             * @param companyId the company id to search with
2057             * @param userId the user id to search with
2058             * @param classNameId the class name id to search with
2059             * @param classPK the class p k to search with
2060             * @return the number of matching subscriptions
2061             * @throws SystemException if a system exception occurred
2062             */
2063            public int countByC_U_C_C(long companyId, long userId, long classNameId,
2064                    long classPK) throws SystemException {
2065                    Object[] finderArgs = new Object[] {
2066                                    companyId, userId, classNameId, classPK
2067                            };
2068    
2069                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_U_C_C,
2070                                    finderArgs, this);
2071    
2072                    if (count == null) {
2073                            StringBundler query = new StringBundler(5);
2074    
2075                            query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2076    
2077                            query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2078    
2079                            query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2080    
2081                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2082    
2083                            query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2084    
2085                            String sql = query.toString();
2086    
2087                            Session session = null;
2088    
2089                            try {
2090                                    session = openSession();
2091    
2092                                    Query q = session.createQuery(sql);
2093    
2094                                    QueryPos qPos = QueryPos.getInstance(q);
2095    
2096                                    qPos.add(companyId);
2097    
2098                                    qPos.add(userId);
2099    
2100                                    qPos.add(classNameId);
2101    
2102                                    qPos.add(classPK);
2103    
2104                                    count = (Long)q.uniqueResult();
2105                            }
2106                            catch (Exception e) {
2107                                    throw processException(e);
2108                            }
2109                            finally {
2110                                    if (count == null) {
2111                                            count = Long.valueOf(0);
2112                                    }
2113    
2114                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C,
2115                                            finderArgs, count);
2116    
2117                                    closeSession(session);
2118                            }
2119                    }
2120    
2121                    return count.intValue();
2122            }
2123    
2124            /**
2125             * Counts all the subscriptions.
2126             *
2127             * @return the number of subscriptions
2128             * @throws SystemException if a system exception occurred
2129             */
2130            public int countAll() throws SystemException {
2131                    Object[] finderArgs = new Object[0];
2132    
2133                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2134                                    finderArgs, this);
2135    
2136                    if (count == null) {
2137                            Session session = null;
2138    
2139                            try {
2140                                    session = openSession();
2141    
2142                                    Query q = session.createQuery(_SQL_COUNT_SUBSCRIPTION);
2143    
2144                                    count = (Long)q.uniqueResult();
2145                            }
2146                            catch (Exception e) {
2147                                    throw processException(e);
2148                            }
2149                            finally {
2150                                    if (count == null) {
2151                                            count = Long.valueOf(0);
2152                                    }
2153    
2154                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2155                                            count);
2156    
2157                                    closeSession(session);
2158                            }
2159                    }
2160    
2161                    return count.intValue();
2162            }
2163    
2164            /**
2165             * Initializes the subscription persistence.
2166             */
2167            public void afterPropertiesSet() {
2168                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2169                                            com.liferay.portal.util.PropsUtil.get(
2170                                                    "value.object.listener.com.liferay.portal.model.Subscription")));
2171    
2172                    if (listenerClassNames.length > 0) {
2173                            try {
2174                                    List<ModelListener<Subscription>> listenersList = new ArrayList<ModelListener<Subscription>>();
2175    
2176                                    for (String listenerClassName : listenerClassNames) {
2177                                            listenersList.add((ModelListener<Subscription>)InstanceFactory.newInstance(
2178                                                            listenerClassName));
2179                                    }
2180    
2181                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2182                            }
2183                            catch (Exception e) {
2184                                    _log.error(e);
2185                            }
2186                    }
2187            }
2188    
2189            public void destroy() {
2190                    EntityCacheUtil.removeCache(SubscriptionImpl.class.getName());
2191                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2192                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2193            }
2194    
2195            @BeanReference(type = AccountPersistence.class)
2196            protected AccountPersistence accountPersistence;
2197            @BeanReference(type = AddressPersistence.class)
2198            protected AddressPersistence addressPersistence;
2199            @BeanReference(type = BrowserTrackerPersistence.class)
2200            protected BrowserTrackerPersistence browserTrackerPersistence;
2201            @BeanReference(type = ClassNamePersistence.class)
2202            protected ClassNamePersistence classNamePersistence;
2203            @BeanReference(type = ClusterGroupPersistence.class)
2204            protected ClusterGroupPersistence clusterGroupPersistence;
2205            @BeanReference(type = CompanyPersistence.class)
2206            protected CompanyPersistence companyPersistence;
2207            @BeanReference(type = ContactPersistence.class)
2208            protected ContactPersistence contactPersistence;
2209            @BeanReference(type = CountryPersistence.class)
2210            protected CountryPersistence countryPersistence;
2211            @BeanReference(type = EmailAddressPersistence.class)
2212            protected EmailAddressPersistence emailAddressPersistence;
2213            @BeanReference(type = GroupPersistence.class)
2214            protected GroupPersistence groupPersistence;
2215            @BeanReference(type = ImagePersistence.class)
2216            protected ImagePersistence imagePersistence;
2217            @BeanReference(type = LayoutPersistence.class)
2218            protected LayoutPersistence layoutPersistence;
2219            @BeanReference(type = LayoutPrototypePersistence.class)
2220            protected LayoutPrototypePersistence layoutPrototypePersistence;
2221            @BeanReference(type = LayoutSetPersistence.class)
2222            protected LayoutSetPersistence layoutSetPersistence;
2223            @BeanReference(type = LayoutSetPrototypePersistence.class)
2224            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2225            @BeanReference(type = ListTypePersistence.class)
2226            protected ListTypePersistence listTypePersistence;
2227            @BeanReference(type = LockPersistence.class)
2228            protected LockPersistence lockPersistence;
2229            @BeanReference(type = MembershipRequestPersistence.class)
2230            protected MembershipRequestPersistence membershipRequestPersistence;
2231            @BeanReference(type = OrganizationPersistence.class)
2232            protected OrganizationPersistence organizationPersistence;
2233            @BeanReference(type = OrgGroupPermissionPersistence.class)
2234            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2235            @BeanReference(type = OrgGroupRolePersistence.class)
2236            protected OrgGroupRolePersistence orgGroupRolePersistence;
2237            @BeanReference(type = OrgLaborPersistence.class)
2238            protected OrgLaborPersistence orgLaborPersistence;
2239            @BeanReference(type = PasswordPolicyPersistence.class)
2240            protected PasswordPolicyPersistence passwordPolicyPersistence;
2241            @BeanReference(type = PasswordPolicyRelPersistence.class)
2242            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2243            @BeanReference(type = PasswordTrackerPersistence.class)
2244            protected PasswordTrackerPersistence passwordTrackerPersistence;
2245            @BeanReference(type = PermissionPersistence.class)
2246            protected PermissionPersistence permissionPersistence;
2247            @BeanReference(type = PhonePersistence.class)
2248            protected PhonePersistence phonePersistence;
2249            @BeanReference(type = PluginSettingPersistence.class)
2250            protected PluginSettingPersistence pluginSettingPersistence;
2251            @BeanReference(type = PortletPersistence.class)
2252            protected PortletPersistence portletPersistence;
2253            @BeanReference(type = PortletItemPersistence.class)
2254            protected PortletItemPersistence portletItemPersistence;
2255            @BeanReference(type = PortletPreferencesPersistence.class)
2256            protected PortletPreferencesPersistence portletPreferencesPersistence;
2257            @BeanReference(type = RegionPersistence.class)
2258            protected RegionPersistence regionPersistence;
2259            @BeanReference(type = ReleasePersistence.class)
2260            protected ReleasePersistence releasePersistence;
2261            @BeanReference(type = ResourcePersistence.class)
2262            protected ResourcePersistence resourcePersistence;
2263            @BeanReference(type = ResourceActionPersistence.class)
2264            protected ResourceActionPersistence resourceActionPersistence;
2265            @BeanReference(type = ResourceCodePersistence.class)
2266            protected ResourceCodePersistence resourceCodePersistence;
2267            @BeanReference(type = ResourcePermissionPersistence.class)
2268            protected ResourcePermissionPersistence resourcePermissionPersistence;
2269            @BeanReference(type = RolePersistence.class)
2270            protected RolePersistence rolePersistence;
2271            @BeanReference(type = ServiceComponentPersistence.class)
2272            protected ServiceComponentPersistence serviceComponentPersistence;
2273            @BeanReference(type = ShardPersistence.class)
2274            protected ShardPersistence shardPersistence;
2275            @BeanReference(type = SubscriptionPersistence.class)
2276            protected SubscriptionPersistence subscriptionPersistence;
2277            @BeanReference(type = TicketPersistence.class)
2278            protected TicketPersistence ticketPersistence;
2279            @BeanReference(type = TeamPersistence.class)
2280            protected TeamPersistence teamPersistence;
2281            @BeanReference(type = UserPersistence.class)
2282            protected UserPersistence userPersistence;
2283            @BeanReference(type = UserGroupPersistence.class)
2284            protected UserGroupPersistence userGroupPersistence;
2285            @BeanReference(type = UserGroupGroupRolePersistence.class)
2286            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2287            @BeanReference(type = UserGroupRolePersistence.class)
2288            protected UserGroupRolePersistence userGroupRolePersistence;
2289            @BeanReference(type = UserIdMapperPersistence.class)
2290            protected UserIdMapperPersistence userIdMapperPersistence;
2291            @BeanReference(type = UserTrackerPersistence.class)
2292            protected UserTrackerPersistence userTrackerPersistence;
2293            @BeanReference(type = UserTrackerPathPersistence.class)
2294            protected UserTrackerPathPersistence userTrackerPathPersistence;
2295            @BeanReference(type = WebDAVPropsPersistence.class)
2296            protected WebDAVPropsPersistence webDAVPropsPersistence;
2297            @BeanReference(type = WebsitePersistence.class)
2298            protected WebsitePersistence websitePersistence;
2299            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2300            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2301            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2302            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2303            private static final String _SQL_SELECT_SUBSCRIPTION = "SELECT subscription FROM Subscription subscription";
2304            private static final String _SQL_SELECT_SUBSCRIPTION_WHERE = "SELECT subscription FROM Subscription subscription WHERE ";
2305            private static final String _SQL_COUNT_SUBSCRIPTION = "SELECT COUNT(subscription) FROM Subscription subscription";
2306            private static final String _SQL_COUNT_SUBSCRIPTION_WHERE = "SELECT COUNT(subscription) FROM Subscription subscription WHERE ";
2307            private static final String _FINDER_COLUMN_USERID_USERID_2 = "subscription.userId = ?";
2308            private static final String _FINDER_COLUMN_U_C_USERID_2 = "subscription.userId = ? AND ";
2309            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "subscription.classNameId = ?";
2310            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2311            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2312            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "subscription.classPK = ?";
2313            private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2314            private static final String _FINDER_COLUMN_C_U_C_C_USERID_2 = "subscription.userId = ? AND ";
2315            private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2316            private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_2 = "subscription.classPK = ?";
2317            private static final String _ORDER_BY_ENTITY_ALIAS = "subscription.";
2318            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Subscription exists with the primary key ";
2319            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Subscription exists with the key {";
2320            private static Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class);
2321    }