001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.getOriginalCompanyId()),
293                                    new Long(subscriptionModelImpl.getOriginalUserId()),
294                                    new Long(subscriptionModelImpl.getOriginalClassNameId()),
295                                    new Long(subscriptionModelImpl.getOriginalClassPK())
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                            Session session = null;
531    
532                            try {
533                                    session = openSession();
534    
535                                    StringBundler query = null;
536    
537                                    if (orderByComparator != null) {
538                                            query = new StringBundler(3 +
539                                                            (orderByComparator.getOrderByFields().length * 3));
540                                    }
541                                    else {
542                                            query = new StringBundler(2);
543                                    }
544    
545                                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
546    
547                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
548    
549                                    if (orderByComparator != null) {
550                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
551                                                    orderByComparator);
552                                    }
553    
554                                    String sql = query.toString();
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                                            list = new ArrayList<Subscription>();
571                                    }
572    
573                                    cacheResult(list);
574    
575                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
576                                            finderArgs, list);
577    
578                                    closeSession(session);
579                            }
580                    }
581    
582                    return list;
583            }
584    
585            /**
586             * Finds the first subscription in the ordered set where userId = &#63;.
587             *
588             * <p>
589             * 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.
590             * </p>
591             *
592             * @param userId the user id to search with
593             * @param orderByComparator the comparator to order the set by
594             * @return the first matching subscription
595             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
596             * @throws SystemException if a system exception occurred
597             */
598            public Subscription findByUserId_First(long userId,
599                    OrderByComparator orderByComparator)
600                    throws NoSuchSubscriptionException, SystemException {
601                    List<Subscription> list = findByUserId(userId, 0, 1, orderByComparator);
602    
603                    if (list.isEmpty()) {
604                            StringBundler msg = new StringBundler(4);
605    
606                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
607    
608                            msg.append("userId=");
609                            msg.append(userId);
610    
611                            msg.append(StringPool.CLOSE_CURLY_BRACE);
612    
613                            throw new NoSuchSubscriptionException(msg.toString());
614                    }
615                    else {
616                            return list.get(0);
617                    }
618            }
619    
620            /**
621             * Finds the last subscription in the ordered set where userId = &#63;.
622             *
623             * <p>
624             * 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.
625             * </p>
626             *
627             * @param userId the user id to search with
628             * @param orderByComparator the comparator to order the set by
629             * @return the last matching subscription
630             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
631             * @throws SystemException if a system exception occurred
632             */
633            public Subscription findByUserId_Last(long userId,
634                    OrderByComparator orderByComparator)
635                    throws NoSuchSubscriptionException, SystemException {
636                    int count = countByUserId(userId);
637    
638                    List<Subscription> list = findByUserId(userId, count - 1, count,
639                                    orderByComparator);
640    
641                    if (list.isEmpty()) {
642                            StringBundler msg = new StringBundler(4);
643    
644                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
645    
646                            msg.append("userId=");
647                            msg.append(userId);
648    
649                            msg.append(StringPool.CLOSE_CURLY_BRACE);
650    
651                            throw new NoSuchSubscriptionException(msg.toString());
652                    }
653                    else {
654                            return list.get(0);
655                    }
656            }
657    
658            /**
659             * Finds the subscriptions before and after the current subscription in the ordered set where userId = &#63;.
660             *
661             * <p>
662             * 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.
663             * </p>
664             *
665             * @param subscriptionId the primary key of the current subscription
666             * @param userId the user id to search with
667             * @param orderByComparator the comparator to order the set by
668             * @return the previous, current, and next subscription
669             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
670             * @throws SystemException if a system exception occurred
671             */
672            public Subscription[] findByUserId_PrevAndNext(long subscriptionId,
673                    long userId, OrderByComparator orderByComparator)
674                    throws NoSuchSubscriptionException, SystemException {
675                    Subscription subscription = findByPrimaryKey(subscriptionId);
676    
677                    Session session = null;
678    
679                    try {
680                            session = openSession();
681    
682                            Subscription[] array = new SubscriptionImpl[3];
683    
684                            array[0] = getByUserId_PrevAndNext(session, subscription, userId,
685                                            orderByComparator, true);
686    
687                            array[1] = subscription;
688    
689                            array[2] = getByUserId_PrevAndNext(session, subscription, userId,
690                                            orderByComparator, false);
691    
692                            return array;
693                    }
694                    catch (Exception e) {
695                            throw processException(e);
696                    }
697                    finally {
698                            closeSession(session);
699                    }
700            }
701    
702            protected Subscription getByUserId_PrevAndNext(Session session,
703                    Subscription subscription, long userId,
704                    OrderByComparator orderByComparator, boolean previous) {
705                    StringBundler query = null;
706    
707                    if (orderByComparator != null) {
708                            query = new StringBundler(6 +
709                                            (orderByComparator.getOrderByFields().length * 6));
710                    }
711                    else {
712                            query = new StringBundler(3);
713                    }
714    
715                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
716    
717                    query.append(_FINDER_COLUMN_USERID_USERID_2);
718    
719                    if (orderByComparator != null) {
720                            String[] orderByFields = orderByComparator.getOrderByFields();
721    
722                            if (orderByFields.length > 0) {
723                                    query.append(WHERE_AND);
724                            }
725    
726                            for (int i = 0; i < orderByFields.length; i++) {
727                                    query.append(_ORDER_BY_ENTITY_ALIAS);
728                                    query.append(orderByFields[i]);
729    
730                                    if ((i + 1) < orderByFields.length) {
731                                            if (orderByComparator.isAscending() ^ previous) {
732                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
733                                            }
734                                            else {
735                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
736                                            }
737                                    }
738                                    else {
739                                            if (orderByComparator.isAscending() ^ previous) {
740                                                    query.append(WHERE_GREATER_THAN);
741                                            }
742                                            else {
743                                                    query.append(WHERE_LESSER_THAN);
744                                            }
745                                    }
746                            }
747    
748                            query.append(ORDER_BY_CLAUSE);
749    
750                            for (int i = 0; i < orderByFields.length; i++) {
751                                    query.append(_ORDER_BY_ENTITY_ALIAS);
752                                    query.append(orderByFields[i]);
753    
754                                    if ((i + 1) < orderByFields.length) {
755                                            if (orderByComparator.isAscending() ^ previous) {
756                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
757                                            }
758                                            else {
759                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
760                                            }
761                                    }
762                                    else {
763                                            if (orderByComparator.isAscending() ^ previous) {
764                                                    query.append(ORDER_BY_ASC);
765                                            }
766                                            else {
767                                                    query.append(ORDER_BY_DESC);
768                                            }
769                                    }
770                            }
771                    }
772    
773                    String sql = query.toString();
774    
775                    Query q = session.createQuery(sql);
776    
777                    q.setFirstResult(0);
778                    q.setMaxResults(2);
779    
780                    QueryPos qPos = QueryPos.getInstance(q);
781    
782                    qPos.add(userId);
783    
784                    if (orderByComparator != null) {
785                            Object[] values = orderByComparator.getOrderByValues(subscription);
786    
787                            for (Object value : values) {
788                                    qPos.add(value);
789                            }
790                    }
791    
792                    List<Subscription> list = q.list();
793    
794                    if (list.size() == 2) {
795                            return list.get(1);
796                    }
797                    else {
798                            return null;
799                    }
800            }
801    
802            /**
803             * Finds all the subscriptions where userId = &#63; and classNameId = &#63;.
804             *
805             * @param userId the user id to search with
806             * @param classNameId the class name id to search with
807             * @return the matching subscriptions
808             * @throws SystemException if a system exception occurred
809             */
810            public List<Subscription> findByU_C(long userId, long classNameId)
811                    throws SystemException {
812                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
813                            QueryUtil.ALL_POS, null);
814            }
815    
816            /**
817             * Finds a range of all the subscriptions where userId = &#63; and classNameId = &#63;.
818             *
819             * <p>
820             * 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.
821             * </p>
822             *
823             * @param userId the user id to search with
824             * @param classNameId the class name id to search with
825             * @param start the lower bound of the range of subscriptions to return
826             * @param end the upper bound of the range of subscriptions to return (not inclusive)
827             * @return the range of matching subscriptions
828             * @throws SystemException if a system exception occurred
829             */
830            public List<Subscription> findByU_C(long userId, long classNameId,
831                    int start, int end) throws SystemException {
832                    return findByU_C(userId, classNameId, start, end, null);
833            }
834    
835            /**
836             * Finds an ordered range of all the subscriptions where userId = &#63; and classNameId = &#63;.
837             *
838             * <p>
839             * 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.
840             * </p>
841             *
842             * @param userId the user id to search with
843             * @param classNameId the class name id to search with
844             * @param start the lower bound of the range of subscriptions to return
845             * @param end the upper bound of the range of subscriptions to return (not inclusive)
846             * @param orderByComparator the comparator to order the results by
847             * @return the ordered range of matching subscriptions
848             * @throws SystemException if a system exception occurred
849             */
850            public List<Subscription> findByU_C(long userId, long classNameId,
851                    int start, int end, OrderByComparator orderByComparator)
852                    throws SystemException {
853                    Object[] finderArgs = new Object[] {
854                                    userId, classNameId,
855                                    
856                                    String.valueOf(start), String.valueOf(end),
857                                    String.valueOf(orderByComparator)
858                            };
859    
860                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_C,
861                                    finderArgs, this);
862    
863                    if (list == null) {
864                            Session session = null;
865    
866                            try {
867                                    session = openSession();
868    
869                                    StringBundler query = null;
870    
871                                    if (orderByComparator != null) {
872                                            query = new StringBundler(4 +
873                                                            (orderByComparator.getOrderByFields().length * 3));
874                                    }
875                                    else {
876                                            query = new StringBundler(3);
877                                    }
878    
879                                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
880    
881                                    query.append(_FINDER_COLUMN_U_C_USERID_2);
882    
883                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
884    
885                                    if (orderByComparator != null) {
886                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
887                                                    orderByComparator);
888                                    }
889    
890                                    String sql = query.toString();
891    
892                                    Query q = session.createQuery(sql);
893    
894                                    QueryPos qPos = QueryPos.getInstance(q);
895    
896                                    qPos.add(userId);
897    
898                                    qPos.add(classNameId);
899    
900                                    list = (List<Subscription>)QueryUtil.list(q, getDialect(),
901                                                    start, end);
902                            }
903                            catch (Exception e) {
904                                    throw processException(e);
905                            }
906                            finally {
907                                    if (list == null) {
908                                            list = new ArrayList<Subscription>();
909                                    }
910    
911                                    cacheResult(list);
912    
913                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_C, finderArgs,
914                                            list);
915    
916                                    closeSession(session);
917                            }
918                    }
919    
920                    return list;
921            }
922    
923            /**
924             * Finds the first subscription in the ordered set where userId = &#63; and classNameId = &#63;.
925             *
926             * <p>
927             * 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.
928             * </p>
929             *
930             * @param userId the user id to search with
931             * @param classNameId the class name id to search with
932             * @param orderByComparator the comparator to order the set by
933             * @return the first matching subscription
934             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
935             * @throws SystemException if a system exception occurred
936             */
937            public Subscription findByU_C_First(long userId, long classNameId,
938                    OrderByComparator orderByComparator)
939                    throws NoSuchSubscriptionException, SystemException {
940                    List<Subscription> list = findByU_C(userId, classNameId, 0, 1,
941                                    orderByComparator);
942    
943                    if (list.isEmpty()) {
944                            StringBundler msg = new StringBundler(6);
945    
946                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
947    
948                            msg.append("userId=");
949                            msg.append(userId);
950    
951                            msg.append(", classNameId=");
952                            msg.append(classNameId);
953    
954                            msg.append(StringPool.CLOSE_CURLY_BRACE);
955    
956                            throw new NoSuchSubscriptionException(msg.toString());
957                    }
958                    else {
959                            return list.get(0);
960                    }
961            }
962    
963            /**
964             * Finds the last subscription in the ordered set where userId = &#63; and classNameId = &#63;.
965             *
966             * <p>
967             * 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.
968             * </p>
969             *
970             * @param userId the user id to search with
971             * @param classNameId the class name id to search with
972             * @param orderByComparator the comparator to order the set by
973             * @return the last matching subscription
974             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
975             * @throws SystemException if a system exception occurred
976             */
977            public Subscription findByU_C_Last(long userId, long classNameId,
978                    OrderByComparator orderByComparator)
979                    throws NoSuchSubscriptionException, SystemException {
980                    int count = countByU_C(userId, classNameId);
981    
982                    List<Subscription> list = findByU_C(userId, classNameId, count - 1,
983                                    count, orderByComparator);
984    
985                    if (list.isEmpty()) {
986                            StringBundler msg = new StringBundler(6);
987    
988                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
989    
990                            msg.append("userId=");
991                            msg.append(userId);
992    
993                            msg.append(", classNameId=");
994                            msg.append(classNameId);
995    
996                            msg.append(StringPool.CLOSE_CURLY_BRACE);
997    
998                            throw new NoSuchSubscriptionException(msg.toString());
999                    }
1000                    else {
1001                            return list.get(0);
1002                    }
1003            }
1004    
1005            /**
1006             * Finds the subscriptions before and after the current subscription in the ordered set where userId = &#63; and classNameId = &#63;.
1007             *
1008             * <p>
1009             * 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.
1010             * </p>
1011             *
1012             * @param subscriptionId the primary key of the current subscription
1013             * @param userId the user id to search with
1014             * @param classNameId the class name id to search with
1015             * @param orderByComparator the comparator to order the set by
1016             * @return the previous, current, and next subscription
1017             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
1018             * @throws SystemException if a system exception occurred
1019             */
1020            public Subscription[] findByU_C_PrevAndNext(long subscriptionId,
1021                    long userId, long classNameId, OrderByComparator orderByComparator)
1022                    throws NoSuchSubscriptionException, SystemException {
1023                    Subscription subscription = findByPrimaryKey(subscriptionId);
1024    
1025                    Session session = null;
1026    
1027                    try {
1028                            session = openSession();
1029    
1030                            Subscription[] array = new SubscriptionImpl[3];
1031    
1032                            array[0] = getByU_C_PrevAndNext(session, subscription, userId,
1033                                            classNameId, orderByComparator, true);
1034    
1035                            array[1] = subscription;
1036    
1037                            array[2] = getByU_C_PrevAndNext(session, subscription, userId,
1038                                            classNameId, orderByComparator, false);
1039    
1040                            return array;
1041                    }
1042                    catch (Exception e) {
1043                            throw processException(e);
1044                    }
1045                    finally {
1046                            closeSession(session);
1047                    }
1048            }
1049    
1050            protected Subscription getByU_C_PrevAndNext(Session session,
1051                    Subscription subscription, long userId, long classNameId,
1052                    OrderByComparator orderByComparator, boolean previous) {
1053                    StringBundler query = null;
1054    
1055                    if (orderByComparator != null) {
1056                            query = new StringBundler(6 +
1057                                            (orderByComparator.getOrderByFields().length * 6));
1058                    }
1059                    else {
1060                            query = new StringBundler(3);
1061                    }
1062    
1063                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1064    
1065                    query.append(_FINDER_COLUMN_U_C_USERID_2);
1066    
1067                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1068    
1069                    if (orderByComparator != null) {
1070                            String[] orderByFields = orderByComparator.getOrderByFields();
1071    
1072                            if (orderByFields.length > 0) {
1073                                    query.append(WHERE_AND);
1074                            }
1075    
1076                            for (int i = 0; i < orderByFields.length; i++) {
1077                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1078                                    query.append(orderByFields[i]);
1079    
1080                                    if ((i + 1) < orderByFields.length) {
1081                                            if (orderByComparator.isAscending() ^ previous) {
1082                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1083                                            }
1084                                            else {
1085                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1086                                            }
1087                                    }
1088                                    else {
1089                                            if (orderByComparator.isAscending() ^ previous) {
1090                                                    query.append(WHERE_GREATER_THAN);
1091                                            }
1092                                            else {
1093                                                    query.append(WHERE_LESSER_THAN);
1094                                            }
1095                                    }
1096                            }
1097    
1098                            query.append(ORDER_BY_CLAUSE);
1099    
1100                            for (int i = 0; i < orderByFields.length; i++) {
1101                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1102                                    query.append(orderByFields[i]);
1103    
1104                                    if ((i + 1) < orderByFields.length) {
1105                                            if (orderByComparator.isAscending() ^ previous) {
1106                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1107                                            }
1108                                            else {
1109                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1110                                            }
1111                                    }
1112                                    else {
1113                                            if (orderByComparator.isAscending() ^ previous) {
1114                                                    query.append(ORDER_BY_ASC);
1115                                            }
1116                                            else {
1117                                                    query.append(ORDER_BY_DESC);
1118                                            }
1119                                    }
1120                            }
1121                    }
1122    
1123                    String sql = query.toString();
1124    
1125                    Query q = session.createQuery(sql);
1126    
1127                    q.setFirstResult(0);
1128                    q.setMaxResults(2);
1129    
1130                    QueryPos qPos = QueryPos.getInstance(q);
1131    
1132                    qPos.add(userId);
1133    
1134                    qPos.add(classNameId);
1135    
1136                    if (orderByComparator != null) {
1137                            Object[] values = orderByComparator.getOrderByValues(subscription);
1138    
1139                            for (Object value : values) {
1140                                    qPos.add(value);
1141                            }
1142                    }
1143    
1144                    List<Subscription> list = q.list();
1145    
1146                    if (list.size() == 2) {
1147                            return list.get(1);
1148                    }
1149                    else {
1150                            return null;
1151                    }
1152            }
1153    
1154            /**
1155             * Finds all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1156             *
1157             * @param companyId the company id to search with
1158             * @param classNameId the class name id to search with
1159             * @param classPK the class p k to search with
1160             * @return the matching subscriptions
1161             * @throws SystemException if a system exception occurred
1162             */
1163            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1164                    long classPK) throws SystemException {
1165                    return findByC_C_C(companyId, classNameId, classPK, QueryUtil.ALL_POS,
1166                            QueryUtil.ALL_POS, null);
1167            }
1168    
1169            /**
1170             * Finds a range of all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1171             *
1172             * <p>
1173             * 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.
1174             * </p>
1175             *
1176             * @param companyId the company id to search with
1177             * @param classNameId the class name id to search with
1178             * @param classPK the class p k to search with
1179             * @param start the lower bound of the range of subscriptions to return
1180             * @param end the upper bound of the range of subscriptions to return (not inclusive)
1181             * @return the range of matching subscriptions
1182             * @throws SystemException if a system exception occurred
1183             */
1184            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1185                    long classPK, int start, int end) throws SystemException {
1186                    return findByC_C_C(companyId, classNameId, classPK, start, end, null);
1187            }
1188    
1189            /**
1190             * Finds an ordered range of all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1191             *
1192             * <p>
1193             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1194             * </p>
1195             *
1196             * @param companyId the company id to search with
1197             * @param classNameId the class name id to search with
1198             * @param classPK the class p k to search with
1199             * @param start the lower bound of the range of subscriptions to return
1200             * @param end the upper bound of the range of subscriptions to return (not inclusive)
1201             * @param orderByComparator the comparator to order the results by
1202             * @return the ordered range of matching subscriptions
1203             * @throws SystemException if a system exception occurred
1204             */
1205            public List<Subscription> findByC_C_C(long companyId, long classNameId,
1206                    long classPK, int start, int end, OrderByComparator orderByComparator)
1207                    throws SystemException {
1208                    Object[] finderArgs = new Object[] {
1209                                    companyId, classNameId, classPK,
1210                                    
1211                                    String.valueOf(start), String.valueOf(end),
1212                                    String.valueOf(orderByComparator)
1213                            };
1214    
1215                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_C,
1216                                    finderArgs, this);
1217    
1218                    if (list == null) {
1219                            Session session = null;
1220    
1221                            try {
1222                                    session = openSession();
1223    
1224                                    StringBundler query = null;
1225    
1226                                    if (orderByComparator != null) {
1227                                            query = new StringBundler(5 +
1228                                                            (orderByComparator.getOrderByFields().length * 3));
1229                                    }
1230                                    else {
1231                                            query = new StringBundler(4);
1232                                    }
1233    
1234                                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1235    
1236                                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1237    
1238                                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1239    
1240                                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1241    
1242                                    if (orderByComparator != null) {
1243                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1244                                                    orderByComparator);
1245                                    }
1246    
1247                                    String sql = query.toString();
1248    
1249                                    Query q = session.createQuery(sql);
1250    
1251                                    QueryPos qPos = QueryPos.getInstance(q);
1252    
1253                                    qPos.add(companyId);
1254    
1255                                    qPos.add(classNameId);
1256    
1257                                    qPos.add(classPK);
1258    
1259                                    list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1260                                                    start, end);
1261                            }
1262                            catch (Exception e) {
1263                                    throw processException(e);
1264                            }
1265                            finally {
1266                                    if (list == null) {
1267                                            list = new ArrayList<Subscription>();
1268                                    }
1269    
1270                                    cacheResult(list);
1271    
1272                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_C,
1273                                            finderArgs, list);
1274    
1275                                    closeSession(session);
1276                            }
1277                    }
1278    
1279                    return list;
1280            }
1281    
1282            /**
1283             * Finds the first subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1284             *
1285             * <p>
1286             * 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.
1287             * </p>
1288             *
1289             * @param companyId the company id to search with
1290             * @param classNameId the class name id to search with
1291             * @param classPK the class p k to search with
1292             * @param orderByComparator the comparator to order the set by
1293             * @return the first matching subscription
1294             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
1295             * @throws SystemException if a system exception occurred
1296             */
1297            public Subscription findByC_C_C_First(long companyId, long classNameId,
1298                    long classPK, OrderByComparator orderByComparator)
1299                    throws NoSuchSubscriptionException, SystemException {
1300                    List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1301                                    0, 1, orderByComparator);
1302    
1303                    if (list.isEmpty()) {
1304                            StringBundler msg = new StringBundler(8);
1305    
1306                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1307    
1308                            msg.append("companyId=");
1309                            msg.append(companyId);
1310    
1311                            msg.append(", classNameId=");
1312                            msg.append(classNameId);
1313    
1314                            msg.append(", classPK=");
1315                            msg.append(classPK);
1316    
1317                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1318    
1319                            throw new NoSuchSubscriptionException(msg.toString());
1320                    }
1321                    else {
1322                            return list.get(0);
1323                    }
1324            }
1325    
1326            /**
1327             * Finds the last subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1328             *
1329             * <p>
1330             * 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.
1331             * </p>
1332             *
1333             * @param companyId the company id to search with
1334             * @param classNameId the class name id to search with
1335             * @param classPK the class p k to search with
1336             * @param orderByComparator the comparator to order the set by
1337             * @return the last matching subscription
1338             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
1339             * @throws SystemException if a system exception occurred
1340             */
1341            public Subscription findByC_C_C_Last(long companyId, long classNameId,
1342                    long classPK, OrderByComparator orderByComparator)
1343                    throws NoSuchSubscriptionException, SystemException {
1344                    int count = countByC_C_C(companyId, classNameId, classPK);
1345    
1346                    List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
1347                                    count - 1, count, orderByComparator);
1348    
1349                    if (list.isEmpty()) {
1350                            StringBundler msg = new StringBundler(8);
1351    
1352                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1353    
1354                            msg.append("companyId=");
1355                            msg.append(companyId);
1356    
1357                            msg.append(", classNameId=");
1358                            msg.append(classNameId);
1359    
1360                            msg.append(", classPK=");
1361                            msg.append(classPK);
1362    
1363                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1364    
1365                            throw new NoSuchSubscriptionException(msg.toString());
1366                    }
1367                    else {
1368                            return list.get(0);
1369                    }
1370            }
1371    
1372            /**
1373             * Finds the subscriptions before and after the current subscription in the ordered set where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1374             *
1375             * <p>
1376             * 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.
1377             * </p>
1378             *
1379             * @param subscriptionId the primary key of the current subscription
1380             * @param companyId the company id to search with
1381             * @param classNameId the class name id to search with
1382             * @param classPK the class p k to search with
1383             * @param orderByComparator the comparator to order the set by
1384             * @return the previous, current, and next subscription
1385             * @throws com.liferay.portal.NoSuchSubscriptionException if a subscription with the primary key could not be found
1386             * @throws SystemException if a system exception occurred
1387             */
1388            public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId,
1389                    long companyId, long classNameId, long classPK,
1390                    OrderByComparator orderByComparator)
1391                    throws NoSuchSubscriptionException, SystemException {
1392                    Subscription subscription = findByPrimaryKey(subscriptionId);
1393    
1394                    Session session = null;
1395    
1396                    try {
1397                            session = openSession();
1398    
1399                            Subscription[] array = new SubscriptionImpl[3];
1400    
1401                            array[0] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1402                                            classNameId, classPK, orderByComparator, true);
1403    
1404                            array[1] = subscription;
1405    
1406                            array[2] = getByC_C_C_PrevAndNext(session, subscription, companyId,
1407                                            classNameId, classPK, orderByComparator, false);
1408    
1409                            return array;
1410                    }
1411                    catch (Exception e) {
1412                            throw processException(e);
1413                    }
1414                    finally {
1415                            closeSession(session);
1416                    }
1417            }
1418    
1419            protected Subscription getByC_C_C_PrevAndNext(Session session,
1420                    Subscription subscription, long companyId, long classNameId,
1421                    long classPK, OrderByComparator orderByComparator, boolean previous) {
1422                    StringBundler query = null;
1423    
1424                    if (orderByComparator != null) {
1425                            query = new StringBundler(6 +
1426                                            (orderByComparator.getOrderByFields().length * 6));
1427                    }
1428                    else {
1429                            query = new StringBundler(3);
1430                    }
1431    
1432                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1433    
1434                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1435    
1436                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1437    
1438                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1439    
1440                    if (orderByComparator != null) {
1441                            String[] orderByFields = orderByComparator.getOrderByFields();
1442    
1443                            if (orderByFields.length > 0) {
1444                                    query.append(WHERE_AND);
1445                            }
1446    
1447                            for (int i = 0; i < orderByFields.length; i++) {
1448                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1449                                    query.append(orderByFields[i]);
1450    
1451                                    if ((i + 1) < orderByFields.length) {
1452                                            if (orderByComparator.isAscending() ^ previous) {
1453                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1454                                            }
1455                                            else {
1456                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1457                                            }
1458                                    }
1459                                    else {
1460                                            if (orderByComparator.isAscending() ^ previous) {
1461                                                    query.append(WHERE_GREATER_THAN);
1462                                            }
1463                                            else {
1464                                                    query.append(WHERE_LESSER_THAN);
1465                                            }
1466                                    }
1467                            }
1468    
1469                            query.append(ORDER_BY_CLAUSE);
1470    
1471                            for (int i = 0; i < orderByFields.length; i++) {
1472                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1473                                    query.append(orderByFields[i]);
1474    
1475                                    if ((i + 1) < orderByFields.length) {
1476                                            if (orderByComparator.isAscending() ^ previous) {
1477                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1478                                            }
1479                                            else {
1480                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1481                                            }
1482                                    }
1483                                    else {
1484                                            if (orderByComparator.isAscending() ^ previous) {
1485                                                    query.append(ORDER_BY_ASC);
1486                                            }
1487                                            else {
1488                                                    query.append(ORDER_BY_DESC);
1489                                            }
1490                                    }
1491                            }
1492                    }
1493    
1494                    String sql = query.toString();
1495    
1496                    Query q = session.createQuery(sql);
1497    
1498                    q.setFirstResult(0);
1499                    q.setMaxResults(2);
1500    
1501                    QueryPos qPos = QueryPos.getInstance(q);
1502    
1503                    qPos.add(companyId);
1504    
1505                    qPos.add(classNameId);
1506    
1507                    qPos.add(classPK);
1508    
1509                    if (orderByComparator != null) {
1510                            Object[] values = orderByComparator.getOrderByValues(subscription);
1511    
1512                            for (Object value : values) {
1513                                    qPos.add(value);
1514                            }
1515                    }
1516    
1517                    List<Subscription> list = q.list();
1518    
1519                    if (list.size() == 2) {
1520                            return list.get(1);
1521                    }
1522                    else {
1523                            return null;
1524                    }
1525            }
1526    
1527            /**
1528             * 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.
1529             *
1530             * @param companyId the company id to search with
1531             * @param userId the user id to search with
1532             * @param classNameId the class name id to search with
1533             * @param classPK the class p k to search with
1534             * @return the matching subscription
1535             * @throws com.liferay.portal.NoSuchSubscriptionException if a matching subscription could not be found
1536             * @throws SystemException if a system exception occurred
1537             */
1538            public Subscription findByC_U_C_C(long companyId, long userId,
1539                    long classNameId, long classPK)
1540                    throws NoSuchSubscriptionException, SystemException {
1541                    Subscription subscription = fetchByC_U_C_C(companyId, userId,
1542                                    classNameId, classPK);
1543    
1544                    if (subscription == null) {
1545                            StringBundler msg = new StringBundler(10);
1546    
1547                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1548    
1549                            msg.append("companyId=");
1550                            msg.append(companyId);
1551    
1552                            msg.append(", userId=");
1553                            msg.append(userId);
1554    
1555                            msg.append(", classNameId=");
1556                            msg.append(classNameId);
1557    
1558                            msg.append(", classPK=");
1559                            msg.append(classPK);
1560    
1561                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1562    
1563                            if (_log.isWarnEnabled()) {
1564                                    _log.warn(msg.toString());
1565                            }
1566    
1567                            throw new NoSuchSubscriptionException(msg.toString());
1568                    }
1569    
1570                    return subscription;
1571            }
1572    
1573            /**
1574             * 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.
1575             *
1576             * @param companyId the company id to search with
1577             * @param userId the user id to search with
1578             * @param classNameId the class name id to search with
1579             * @param classPK the class p k to search with
1580             * @return the matching subscription, or <code>null</code> if a matching subscription could not be found
1581             * @throws SystemException if a system exception occurred
1582             */
1583            public Subscription fetchByC_U_C_C(long companyId, long userId,
1584                    long classNameId, long classPK) throws SystemException {
1585                    return fetchByC_U_C_C(companyId, userId, classNameId, classPK, true);
1586            }
1587    
1588            /**
1589             * 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.
1590             *
1591             * @param companyId the company id to search with
1592             * @param userId the user id to search with
1593             * @param classNameId the class name id to search with
1594             * @param classPK the class p k to search with
1595             * @return the matching subscription, or <code>null</code> if a matching subscription could not be found
1596             * @throws SystemException if a system exception occurred
1597             */
1598            public Subscription fetchByC_U_C_C(long companyId, long userId,
1599                    long classNameId, long classPK, boolean retrieveFromCache)
1600                    throws SystemException {
1601                    Object[] finderArgs = new Object[] {
1602                                    companyId, userId, classNameId, classPK
1603                            };
1604    
1605                    Object result = null;
1606    
1607                    if (retrieveFromCache) {
1608                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1609                                            finderArgs, this);
1610                    }
1611    
1612                    if (result == null) {
1613                            Session session = null;
1614    
1615                            try {
1616                                    session = openSession();
1617    
1618                                    StringBundler query = new StringBundler(5);
1619    
1620                                    query.append(_SQL_SELECT_SUBSCRIPTION_WHERE);
1621    
1622                                    query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
1623    
1624                                    query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
1625    
1626                                    query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
1627    
1628                                    query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
1629    
1630                                    String sql = query.toString();
1631    
1632                                    Query q = session.createQuery(sql);
1633    
1634                                    QueryPos qPos = QueryPos.getInstance(q);
1635    
1636                                    qPos.add(companyId);
1637    
1638                                    qPos.add(userId);
1639    
1640                                    qPos.add(classNameId);
1641    
1642                                    qPos.add(classPK);
1643    
1644                                    List<Subscription> list = q.list();
1645    
1646                                    result = list;
1647    
1648                                    Subscription subscription = null;
1649    
1650                                    if (list.isEmpty()) {
1651                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1652                                                    finderArgs, list);
1653                                    }
1654                                    else {
1655                                            subscription = list.get(0);
1656    
1657                                            cacheResult(subscription);
1658    
1659                                            if ((subscription.getCompanyId() != companyId) ||
1660                                                            (subscription.getUserId() != userId) ||
1661                                                            (subscription.getClassNameId() != classNameId) ||
1662                                                            (subscription.getClassPK() != classPK)) {
1663                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1664                                                            finderArgs, subscription);
1665                                            }
1666                                    }
1667    
1668                                    return subscription;
1669                            }
1670                            catch (Exception e) {
1671                                    throw processException(e);
1672                            }
1673                            finally {
1674                                    if (result == null) {
1675                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_C_C,
1676                                                    finderArgs, new ArrayList<Subscription>());
1677                                    }
1678    
1679                                    closeSession(session);
1680                            }
1681                    }
1682                    else {
1683                            if (result instanceof List<?>) {
1684                                    return null;
1685                            }
1686                            else {
1687                                    return (Subscription)result;
1688                            }
1689                    }
1690            }
1691    
1692            /**
1693             * Finds all the subscriptions.
1694             *
1695             * @return the subscriptions
1696             * @throws SystemException if a system exception occurred
1697             */
1698            public List<Subscription> findAll() throws SystemException {
1699                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1700            }
1701    
1702            /**
1703             * Finds a range of all the subscriptions.
1704             *
1705             * <p>
1706             * 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.
1707             * </p>
1708             *
1709             * @param start the lower bound of the range of subscriptions to return
1710             * @param end the upper bound of the range of subscriptions to return (not inclusive)
1711             * @return the range of subscriptions
1712             * @throws SystemException if a system exception occurred
1713             */
1714            public List<Subscription> findAll(int start, int end)
1715                    throws SystemException {
1716                    return findAll(start, end, null);
1717            }
1718    
1719            /**
1720             * Finds an ordered range of all the subscriptions.
1721             *
1722             * <p>
1723             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1724             * </p>
1725             *
1726             * @param start the lower bound of the range of subscriptions to return
1727             * @param end the upper bound of the range of subscriptions to return (not inclusive)
1728             * @param orderByComparator the comparator to order the results by
1729             * @return the ordered range of subscriptions
1730             * @throws SystemException if a system exception occurred
1731             */
1732            public List<Subscription> findAll(int start, int end,
1733                    OrderByComparator orderByComparator) throws SystemException {
1734                    Object[] finderArgs = new Object[] {
1735                                    String.valueOf(start), String.valueOf(end),
1736                                    String.valueOf(orderByComparator)
1737                            };
1738    
1739                    List<Subscription> list = (List<Subscription>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1740                                    finderArgs, this);
1741    
1742                    if (list == null) {
1743                            Session session = null;
1744    
1745                            try {
1746                                    session = openSession();
1747    
1748                                    StringBundler query = null;
1749                                    String sql = null;
1750    
1751                                    if (orderByComparator != null) {
1752                                            query = new StringBundler(2 +
1753                                                            (orderByComparator.getOrderByFields().length * 3));
1754    
1755                                            query.append(_SQL_SELECT_SUBSCRIPTION);
1756    
1757                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1758                                                    orderByComparator);
1759    
1760                                            sql = query.toString();
1761                                    }
1762                                    else {
1763                                            sql = _SQL_SELECT_SUBSCRIPTION;
1764                                    }
1765    
1766                                    Query q = session.createQuery(sql);
1767    
1768                                    if (orderByComparator == null) {
1769                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1770                                                            start, end, false);
1771    
1772                                            Collections.sort(list);
1773                                    }
1774                                    else {
1775                                            list = (List<Subscription>)QueryUtil.list(q, getDialect(),
1776                                                            start, end);
1777                                    }
1778                            }
1779                            catch (Exception e) {
1780                                    throw processException(e);
1781                            }
1782                            finally {
1783                                    if (list == null) {
1784                                            list = new ArrayList<Subscription>();
1785                                    }
1786    
1787                                    cacheResult(list);
1788    
1789                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1790    
1791                                    closeSession(session);
1792                            }
1793                    }
1794    
1795                    return list;
1796            }
1797    
1798            /**
1799             * Removes all the subscriptions where userId = &#63; from the database.
1800             *
1801             * @param userId the user id to search with
1802             * @throws SystemException if a system exception occurred
1803             */
1804            public void removeByUserId(long userId) throws SystemException {
1805                    for (Subscription subscription : findByUserId(userId)) {
1806                            remove(subscription);
1807                    }
1808            }
1809    
1810            /**
1811             * Removes all the subscriptions where userId = &#63; and classNameId = &#63; from the database.
1812             *
1813             * @param userId the user id to search with
1814             * @param classNameId the class name id to search with
1815             * @throws SystemException if a system exception occurred
1816             */
1817            public void removeByU_C(long userId, long classNameId)
1818                    throws SystemException {
1819                    for (Subscription subscription : findByU_C(userId, classNameId)) {
1820                            remove(subscription);
1821                    }
1822            }
1823    
1824            /**
1825             * Removes all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
1826             *
1827             * @param companyId the company id to search with
1828             * @param classNameId the class name id to search with
1829             * @param classPK the class p k to search with
1830             * @throws SystemException if a system exception occurred
1831             */
1832            public void removeByC_C_C(long companyId, long classNameId, long classPK)
1833                    throws SystemException {
1834                    for (Subscription subscription : findByC_C_C(companyId, classNameId,
1835                                    classPK)) {
1836                            remove(subscription);
1837                    }
1838            }
1839    
1840            /**
1841             * Removes the subscription where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
1842             *
1843             * @param companyId the company id to search with
1844             * @param userId the user id to search with
1845             * @param classNameId the class name id to search with
1846             * @param classPK the class p k to search with
1847             * @throws SystemException if a system exception occurred
1848             */
1849            public void removeByC_U_C_C(long companyId, long userId, long classNameId,
1850                    long classPK) throws NoSuchSubscriptionException, SystemException {
1851                    Subscription subscription = findByC_U_C_C(companyId, userId,
1852                                    classNameId, classPK);
1853    
1854                    remove(subscription);
1855            }
1856    
1857            /**
1858             * Removes all the subscriptions from the database.
1859             *
1860             * @throws SystemException if a system exception occurred
1861             */
1862            public void removeAll() throws SystemException {
1863                    for (Subscription subscription : findAll()) {
1864                            remove(subscription);
1865                    }
1866            }
1867    
1868            /**
1869             * Counts all the subscriptions where userId = &#63;.
1870             *
1871             * @param userId the user id to search with
1872             * @return the number of matching subscriptions
1873             * @throws SystemException if a system exception occurred
1874             */
1875            public int countByUserId(long userId) throws SystemException {
1876                    Object[] finderArgs = new Object[] { userId };
1877    
1878                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1879                                    finderArgs, this);
1880    
1881                    if (count == null) {
1882                            Session session = null;
1883    
1884                            try {
1885                                    session = openSession();
1886    
1887                                    StringBundler query = new StringBundler(2);
1888    
1889                                    query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1890    
1891                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1892    
1893                                    String sql = query.toString();
1894    
1895                                    Query q = session.createQuery(sql);
1896    
1897                                    QueryPos qPos = QueryPos.getInstance(q);
1898    
1899                                    qPos.add(userId);
1900    
1901                                    count = (Long)q.uniqueResult();
1902                            }
1903                            catch (Exception e) {
1904                                    throw processException(e);
1905                            }
1906                            finally {
1907                                    if (count == null) {
1908                                            count = Long.valueOf(0);
1909                                    }
1910    
1911                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1912                                            finderArgs, count);
1913    
1914                                    closeSession(session);
1915                            }
1916                    }
1917    
1918                    return count.intValue();
1919            }
1920    
1921            /**
1922             * Counts all the subscriptions where userId = &#63; and classNameId = &#63;.
1923             *
1924             * @param userId the user id to search with
1925             * @param classNameId the class name id to search with
1926             * @return the number of matching subscriptions
1927             * @throws SystemException if a system exception occurred
1928             */
1929            public int countByU_C(long userId, long classNameId)
1930                    throws SystemException {
1931                    Object[] finderArgs = new Object[] { userId, classNameId };
1932    
1933                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C,
1934                                    finderArgs, this);
1935    
1936                    if (count == null) {
1937                            Session session = null;
1938    
1939                            try {
1940                                    session = openSession();
1941    
1942                                    StringBundler query = new StringBundler(3);
1943    
1944                                    query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
1945    
1946                                    query.append(_FINDER_COLUMN_U_C_USERID_2);
1947    
1948                                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
1949    
1950                                    String sql = query.toString();
1951    
1952                                    Query q = session.createQuery(sql);
1953    
1954                                    QueryPos qPos = QueryPos.getInstance(q);
1955    
1956                                    qPos.add(userId);
1957    
1958                                    qPos.add(classNameId);
1959    
1960                                    count = (Long)q.uniqueResult();
1961                            }
1962                            catch (Exception e) {
1963                                    throw processException(e);
1964                            }
1965                            finally {
1966                                    if (count == null) {
1967                                            count = Long.valueOf(0);
1968                                    }
1969    
1970                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C, finderArgs,
1971                                            count);
1972    
1973                                    closeSession(session);
1974                            }
1975                    }
1976    
1977                    return count.intValue();
1978            }
1979    
1980            /**
1981             * Counts all the subscriptions where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
1982             *
1983             * @param companyId the company id to search with
1984             * @param classNameId the class name id to search with
1985             * @param classPK the class p k to search with
1986             * @return the number of matching subscriptions
1987             * @throws SystemException if a system exception occurred
1988             */
1989            public int countByC_C_C(long companyId, long classNameId, long classPK)
1990                    throws SystemException {
1991                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
1992    
1993                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
1994                                    finderArgs, this);
1995    
1996                    if (count == null) {
1997                            Session session = null;
1998    
1999                            try {
2000                                    session = openSession();
2001    
2002                                    StringBundler query = new StringBundler(4);
2003    
2004                                    query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2005    
2006                                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2007    
2008                                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2009    
2010                                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2011    
2012                                    String sql = query.toString();
2013    
2014                                    Query q = session.createQuery(sql);
2015    
2016                                    QueryPos qPos = QueryPos.getInstance(q);
2017    
2018                                    qPos.add(companyId);
2019    
2020                                    qPos.add(classNameId);
2021    
2022                                    qPos.add(classPK);
2023    
2024                                    count = (Long)q.uniqueResult();
2025                            }
2026                            catch (Exception e) {
2027                                    throw processException(e);
2028                            }
2029                            finally {
2030                                    if (count == null) {
2031                                            count = Long.valueOf(0);
2032                                    }
2033    
2034                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
2035                                            finderArgs, count);
2036    
2037                                    closeSession(session);
2038                            }
2039                    }
2040    
2041                    return count.intValue();
2042            }
2043    
2044            /**
2045             * Counts all the subscriptions where companyId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63;.
2046             *
2047             * @param companyId the company id to search with
2048             * @param userId the user id to search with
2049             * @param classNameId the class name id to search with
2050             * @param classPK the class p k to search with
2051             * @return the number of matching subscriptions
2052             * @throws SystemException if a system exception occurred
2053             */
2054            public int countByC_U_C_C(long companyId, long userId, long classNameId,
2055                    long classPK) throws SystemException {
2056                    Object[] finderArgs = new Object[] {
2057                                    companyId, userId, classNameId, classPK
2058                            };
2059    
2060                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_U_C_C,
2061                                    finderArgs, this);
2062    
2063                    if (count == null) {
2064                            Session session = null;
2065    
2066                            try {
2067                                    session = openSession();
2068    
2069                                    StringBundler query = new StringBundler(5);
2070    
2071                                    query.append(_SQL_COUNT_SUBSCRIPTION_WHERE);
2072    
2073                                    query.append(_FINDER_COLUMN_C_U_C_C_COMPANYID_2);
2074    
2075                                    query.append(_FINDER_COLUMN_C_U_C_C_USERID_2);
2076    
2077                                    query.append(_FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2);
2078    
2079                                    query.append(_FINDER_COLUMN_C_U_C_C_CLASSPK_2);
2080    
2081                                    String sql = query.toString();
2082    
2083                                    Query q = session.createQuery(sql);
2084    
2085                                    QueryPos qPos = QueryPos.getInstance(q);
2086    
2087                                    qPos.add(companyId);
2088    
2089                                    qPos.add(userId);
2090    
2091                                    qPos.add(classNameId);
2092    
2093                                    qPos.add(classPK);
2094    
2095                                    count = (Long)q.uniqueResult();
2096                            }
2097                            catch (Exception e) {
2098                                    throw processException(e);
2099                            }
2100                            finally {
2101                                    if (count == null) {
2102                                            count = Long.valueOf(0);
2103                                    }
2104    
2105                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_C_C,
2106                                            finderArgs, count);
2107    
2108                                    closeSession(session);
2109                            }
2110                    }
2111    
2112                    return count.intValue();
2113            }
2114    
2115            /**
2116             * Counts all the subscriptions.
2117             *
2118             * @return the number of subscriptions
2119             * @throws SystemException if a system exception occurred
2120             */
2121            public int countAll() throws SystemException {
2122                    Object[] finderArgs = new Object[0];
2123    
2124                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2125                                    finderArgs, this);
2126    
2127                    if (count == null) {
2128                            Session session = null;
2129    
2130                            try {
2131                                    session = openSession();
2132    
2133                                    Query q = session.createQuery(_SQL_COUNT_SUBSCRIPTION);
2134    
2135                                    count = (Long)q.uniqueResult();
2136                            }
2137                            catch (Exception e) {
2138                                    throw processException(e);
2139                            }
2140                            finally {
2141                                    if (count == null) {
2142                                            count = Long.valueOf(0);
2143                                    }
2144    
2145                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2146                                            count);
2147    
2148                                    closeSession(session);
2149                            }
2150                    }
2151    
2152                    return count.intValue();
2153            }
2154    
2155            /**
2156             * Initializes the subscription persistence.
2157             */
2158            public void afterPropertiesSet() {
2159                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2160                                            com.liferay.portal.util.PropsUtil.get(
2161                                                    "value.object.listener.com.liferay.portal.model.Subscription")));
2162    
2163                    if (listenerClassNames.length > 0) {
2164                            try {
2165                                    List<ModelListener<Subscription>> listenersList = new ArrayList<ModelListener<Subscription>>();
2166    
2167                                    for (String listenerClassName : listenerClassNames) {
2168                                            listenersList.add((ModelListener<Subscription>)InstanceFactory.newInstance(
2169                                                            listenerClassName));
2170                                    }
2171    
2172                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2173                            }
2174                            catch (Exception e) {
2175                                    _log.error(e);
2176                            }
2177                    }
2178            }
2179    
2180            public void destroy() {
2181                    EntityCacheUtil.removeCache(SubscriptionImpl.class.getName());
2182                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2183                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2184            }
2185    
2186            @BeanReference(type = AccountPersistence.class)
2187            protected AccountPersistence accountPersistence;
2188            @BeanReference(type = AddressPersistence.class)
2189            protected AddressPersistence addressPersistence;
2190            @BeanReference(type = BrowserTrackerPersistence.class)
2191            protected BrowserTrackerPersistence browserTrackerPersistence;
2192            @BeanReference(type = ClassNamePersistence.class)
2193            protected ClassNamePersistence classNamePersistence;
2194            @BeanReference(type = ClusterGroupPersistence.class)
2195            protected ClusterGroupPersistence clusterGroupPersistence;
2196            @BeanReference(type = CompanyPersistence.class)
2197            protected CompanyPersistence companyPersistence;
2198            @BeanReference(type = ContactPersistence.class)
2199            protected ContactPersistence contactPersistence;
2200            @BeanReference(type = CountryPersistence.class)
2201            protected CountryPersistence countryPersistence;
2202            @BeanReference(type = EmailAddressPersistence.class)
2203            protected EmailAddressPersistence emailAddressPersistence;
2204            @BeanReference(type = GroupPersistence.class)
2205            protected GroupPersistence groupPersistence;
2206            @BeanReference(type = ImagePersistence.class)
2207            protected ImagePersistence imagePersistence;
2208            @BeanReference(type = LayoutPersistence.class)
2209            protected LayoutPersistence layoutPersistence;
2210            @BeanReference(type = LayoutPrototypePersistence.class)
2211            protected LayoutPrototypePersistence layoutPrototypePersistence;
2212            @BeanReference(type = LayoutSetPersistence.class)
2213            protected LayoutSetPersistence layoutSetPersistence;
2214            @BeanReference(type = LayoutSetPrototypePersistence.class)
2215            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2216            @BeanReference(type = ListTypePersistence.class)
2217            protected ListTypePersistence listTypePersistence;
2218            @BeanReference(type = LockPersistence.class)
2219            protected LockPersistence lockPersistence;
2220            @BeanReference(type = MembershipRequestPersistence.class)
2221            protected MembershipRequestPersistence membershipRequestPersistence;
2222            @BeanReference(type = OrganizationPersistence.class)
2223            protected OrganizationPersistence organizationPersistence;
2224            @BeanReference(type = OrgGroupPermissionPersistence.class)
2225            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2226            @BeanReference(type = OrgGroupRolePersistence.class)
2227            protected OrgGroupRolePersistence orgGroupRolePersistence;
2228            @BeanReference(type = OrgLaborPersistence.class)
2229            protected OrgLaborPersistence orgLaborPersistence;
2230            @BeanReference(type = PasswordPolicyPersistence.class)
2231            protected PasswordPolicyPersistence passwordPolicyPersistence;
2232            @BeanReference(type = PasswordPolicyRelPersistence.class)
2233            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2234            @BeanReference(type = PasswordTrackerPersistence.class)
2235            protected PasswordTrackerPersistence passwordTrackerPersistence;
2236            @BeanReference(type = PermissionPersistence.class)
2237            protected PermissionPersistence permissionPersistence;
2238            @BeanReference(type = PhonePersistence.class)
2239            protected PhonePersistence phonePersistence;
2240            @BeanReference(type = PluginSettingPersistence.class)
2241            protected PluginSettingPersistence pluginSettingPersistence;
2242            @BeanReference(type = PortletPersistence.class)
2243            protected PortletPersistence portletPersistence;
2244            @BeanReference(type = PortletItemPersistence.class)
2245            protected PortletItemPersistence portletItemPersistence;
2246            @BeanReference(type = PortletPreferencesPersistence.class)
2247            protected PortletPreferencesPersistence portletPreferencesPersistence;
2248            @BeanReference(type = RegionPersistence.class)
2249            protected RegionPersistence regionPersistence;
2250            @BeanReference(type = ReleasePersistence.class)
2251            protected ReleasePersistence releasePersistence;
2252            @BeanReference(type = ResourcePersistence.class)
2253            protected ResourcePersistence resourcePersistence;
2254            @BeanReference(type = ResourceActionPersistence.class)
2255            protected ResourceActionPersistence resourceActionPersistence;
2256            @BeanReference(type = ResourceCodePersistence.class)
2257            protected ResourceCodePersistence resourceCodePersistence;
2258            @BeanReference(type = ResourcePermissionPersistence.class)
2259            protected ResourcePermissionPersistence resourcePermissionPersistence;
2260            @BeanReference(type = RolePersistence.class)
2261            protected RolePersistence rolePersistence;
2262            @BeanReference(type = ServiceComponentPersistence.class)
2263            protected ServiceComponentPersistence serviceComponentPersistence;
2264            @BeanReference(type = ShardPersistence.class)
2265            protected ShardPersistence shardPersistence;
2266            @BeanReference(type = SubscriptionPersistence.class)
2267            protected SubscriptionPersistence subscriptionPersistence;
2268            @BeanReference(type = TicketPersistence.class)
2269            protected TicketPersistence ticketPersistence;
2270            @BeanReference(type = TeamPersistence.class)
2271            protected TeamPersistence teamPersistence;
2272            @BeanReference(type = UserPersistence.class)
2273            protected UserPersistence userPersistence;
2274            @BeanReference(type = UserGroupPersistence.class)
2275            protected UserGroupPersistence userGroupPersistence;
2276            @BeanReference(type = UserGroupGroupRolePersistence.class)
2277            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2278            @BeanReference(type = UserGroupRolePersistence.class)
2279            protected UserGroupRolePersistence userGroupRolePersistence;
2280            @BeanReference(type = UserIdMapperPersistence.class)
2281            protected UserIdMapperPersistence userIdMapperPersistence;
2282            @BeanReference(type = UserTrackerPersistence.class)
2283            protected UserTrackerPersistence userTrackerPersistence;
2284            @BeanReference(type = UserTrackerPathPersistence.class)
2285            protected UserTrackerPathPersistence userTrackerPathPersistence;
2286            @BeanReference(type = WebDAVPropsPersistence.class)
2287            protected WebDAVPropsPersistence webDAVPropsPersistence;
2288            @BeanReference(type = WebsitePersistence.class)
2289            protected WebsitePersistence websitePersistence;
2290            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2291            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2292            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2293            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2294            private static final String _SQL_SELECT_SUBSCRIPTION = "SELECT subscription FROM Subscription subscription";
2295            private static final String _SQL_SELECT_SUBSCRIPTION_WHERE = "SELECT subscription FROM Subscription subscription WHERE ";
2296            private static final String _SQL_COUNT_SUBSCRIPTION = "SELECT COUNT(subscription) FROM Subscription subscription";
2297            private static final String _SQL_COUNT_SUBSCRIPTION_WHERE = "SELECT COUNT(subscription) FROM Subscription subscription WHERE ";
2298            private static final String _FINDER_COLUMN_USERID_USERID_2 = "subscription.userId = ?";
2299            private static final String _FINDER_COLUMN_U_C_USERID_2 = "subscription.userId = ? AND ";
2300            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "subscription.classNameId = ?";
2301            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2302            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2303            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "subscription.classPK = ?";
2304            private static final String _FINDER_COLUMN_C_U_C_C_COMPANYID_2 = "subscription.companyId = ? AND ";
2305            private static final String _FINDER_COLUMN_C_U_C_C_USERID_2 = "subscription.userId = ? AND ";
2306            private static final String _FINDER_COLUMN_C_U_C_C_CLASSNAMEID_2 = "subscription.classNameId = ? AND ";
2307            private static final String _FINDER_COLUMN_C_U_C_C_CLASSPK_2 = "subscription.classPK = ?";
2308            private static final String _ORDER_BY_ENTITY_ALIAS = "subscription.";
2309            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Subscription exists with the primary key ";
2310            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Subscription exists with the key {";
2311            private static Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class);
2312    }