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