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