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