001    /**
002     * Copyright (c) 2000-2013 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.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.GroupPersistence;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.social.NoSuchActivityLimitException;
046    import com.liferay.portlet.social.model.SocialActivityLimit;
047    import com.liferay.portlet.social.model.impl.SocialActivityLimitImpl;
048    import com.liferay.portlet.social.model.impl.SocialActivityLimitModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the social activity limit service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see SocialActivityLimitPersistence
065     * @see SocialActivityLimitUtil
066     * @generated
067     */
068    public class SocialActivityLimitPersistenceImpl extends BasePersistenceImpl<SocialActivityLimit>
069            implements SocialActivityLimitPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * 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.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivityLimitImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
081                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
082                            SocialActivityLimitImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
084                            new String[] {
085                                    Long.class.getName(), Long.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
091                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
092                            SocialActivityLimitImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
094                            new String[] { Long.class.getName(), Long.class.getName() },
095                            SocialActivityLimitModelImpl.CLASSNAMEID_COLUMN_BITMASK |
096                            SocialActivityLimitModelImpl.CLASSPK_COLUMN_BITMASK);
097            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
098                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED, Long.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
100                            new String[] { Long.class.getName(), Long.class.getName() });
101            public static final FinderPath FINDER_PATH_FETCH_BY_G_U_C_C_A_A = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
102                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
103                            SocialActivityLimitImpl.class, FINDER_CLASS_NAME_ENTITY,
104                            "fetchByG_U_C_C_A_A",
105                            new String[] {
106                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
107                                    Long.class.getName(), Integer.class.getName(),
108                                    String.class.getName()
109                            },
110                            SocialActivityLimitModelImpl.GROUPID_COLUMN_BITMASK |
111                            SocialActivityLimitModelImpl.USERID_COLUMN_BITMASK |
112                            SocialActivityLimitModelImpl.CLASSNAMEID_COLUMN_BITMASK |
113                            SocialActivityLimitModelImpl.CLASSPK_COLUMN_BITMASK |
114                            SocialActivityLimitModelImpl.ACTIVITYTYPE_COLUMN_BITMASK |
115                            SocialActivityLimitModelImpl.ACTIVITYCOUNTERNAME_COLUMN_BITMASK);
116            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_C_C_A_A = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
117                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED, Long.class,
118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_C_C_A_A",
119                            new String[] {
120                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
121                                    Long.class.getName(), Integer.class.getName(),
122                                    String.class.getName()
123                            });
124            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
125                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
126                            SocialActivityLimitImpl.class,
127                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
128            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
129                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED,
130                            SocialActivityLimitImpl.class,
131                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
132            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
133                            SocialActivityLimitModelImpl.FINDER_CACHE_ENABLED, Long.class,
134                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
135    
136            /**
137             * Caches the social activity limit in the entity cache if it is enabled.
138             *
139             * @param socialActivityLimit the social activity limit
140             */
141            public void cacheResult(SocialActivityLimit socialActivityLimit) {
142                    EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
143                            SocialActivityLimitImpl.class, socialActivityLimit.getPrimaryKey(),
144                            socialActivityLimit);
145    
146                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
147                            new Object[] {
148                                    Long.valueOf(socialActivityLimit.getGroupId()),
149                                    Long.valueOf(socialActivityLimit.getUserId()),
150                                    Long.valueOf(socialActivityLimit.getClassNameId()),
151                                    Long.valueOf(socialActivityLimit.getClassPK()),
152                                    Integer.valueOf(socialActivityLimit.getActivityType()),
153                                    
154                            socialActivityLimit.getActivityCounterName()
155                            }, socialActivityLimit);
156    
157                    socialActivityLimit.resetOriginalValues();
158            }
159    
160            /**
161             * Caches the social activity limits in the entity cache if it is enabled.
162             *
163             * @param socialActivityLimits the social activity limits
164             */
165            public void cacheResult(List<SocialActivityLimit> socialActivityLimits) {
166                    for (SocialActivityLimit socialActivityLimit : socialActivityLimits) {
167                            if (EntityCacheUtil.getResult(
168                                                    SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
169                                                    SocialActivityLimitImpl.class,
170                                                    socialActivityLimit.getPrimaryKey()) == null) {
171                                    cacheResult(socialActivityLimit);
172                            }
173                            else {
174                                    socialActivityLimit.resetOriginalValues();
175                            }
176                    }
177            }
178    
179            /**
180             * Clears the cache for all social activity limits.
181             *
182             * <p>
183             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
184             * </p>
185             */
186            @Override
187            public void clearCache() {
188                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
189                            CacheRegistryUtil.clear(SocialActivityLimitImpl.class.getName());
190                    }
191    
192                    EntityCacheUtil.clearCache(SocialActivityLimitImpl.class.getName());
193    
194                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
195                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
196                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
197            }
198    
199            /**
200             * Clears the cache for the social activity limit.
201             *
202             * <p>
203             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
204             * </p>
205             */
206            @Override
207            public void clearCache(SocialActivityLimit socialActivityLimit) {
208                    EntityCacheUtil.removeResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
209                            SocialActivityLimitImpl.class, socialActivityLimit.getPrimaryKey());
210    
211                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
212                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
213    
214                    clearUniqueFindersCache(socialActivityLimit);
215            }
216    
217            @Override
218            public void clearCache(List<SocialActivityLimit> socialActivityLimits) {
219                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
220                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
221    
222                    for (SocialActivityLimit socialActivityLimit : socialActivityLimits) {
223                            EntityCacheUtil.removeResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
224                                    SocialActivityLimitImpl.class,
225                                    socialActivityLimit.getPrimaryKey());
226    
227                            clearUniqueFindersCache(socialActivityLimit);
228                    }
229            }
230    
231            protected void cacheUniqueFindersCache(
232                    SocialActivityLimit socialActivityLimit) {
233                    if (socialActivityLimit.isNew()) {
234                            Object[] args = new Object[] {
235                                            Long.valueOf(socialActivityLimit.getGroupId()),
236                                            Long.valueOf(socialActivityLimit.getUserId()),
237                                            Long.valueOf(socialActivityLimit.getClassNameId()),
238                                            Long.valueOf(socialActivityLimit.getClassPK()),
239                                            Integer.valueOf(socialActivityLimit.getActivityType()),
240                                            
241                                            socialActivityLimit.getActivityCounterName()
242                                    };
243    
244                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A, args,
245                                    Long.valueOf(1));
246                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A, args,
247                                    socialActivityLimit);
248                    }
249                    else {
250                            SocialActivityLimitModelImpl socialActivityLimitModelImpl = (SocialActivityLimitModelImpl)socialActivityLimit;
251    
252                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
253                                            FINDER_PATH_FETCH_BY_G_U_C_C_A_A.getColumnBitmask()) != 0) {
254                                    Object[] args = new Object[] {
255                                                    Long.valueOf(socialActivityLimit.getGroupId()),
256                                                    Long.valueOf(socialActivityLimit.getUserId()),
257                                                    Long.valueOf(socialActivityLimit.getClassNameId()),
258                                                    Long.valueOf(socialActivityLimit.getClassPK()),
259                                                    Integer.valueOf(socialActivityLimit.getActivityType()),
260                                                    
261                                                    socialActivityLimit.getActivityCounterName()
262                                            };
263    
264                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A,
265                                            args, Long.valueOf(1));
266                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
267                                            args, socialActivityLimit);
268                            }
269                    }
270            }
271    
272            protected void clearUniqueFindersCache(
273                    SocialActivityLimit socialActivityLimit) {
274                    SocialActivityLimitModelImpl socialActivityLimitModelImpl = (SocialActivityLimitModelImpl)socialActivityLimit;
275    
276                    Object[] args = new Object[] {
277                                    Long.valueOf(socialActivityLimit.getGroupId()),
278                                    Long.valueOf(socialActivityLimit.getUserId()),
279                                    Long.valueOf(socialActivityLimit.getClassNameId()),
280                                    Long.valueOf(socialActivityLimit.getClassPK()),
281                                    Integer.valueOf(socialActivityLimit.getActivityType()),
282                                    
283                                    socialActivityLimit.getActivityCounterName()
284                            };
285    
286                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A, args);
287                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A, args);
288    
289                    if ((socialActivityLimitModelImpl.getColumnBitmask() &
290                                    FINDER_PATH_FETCH_BY_G_U_C_C_A_A.getColumnBitmask()) != 0) {
291                            args = new Object[] {
292                                            Long.valueOf(socialActivityLimitModelImpl.getOriginalGroupId()),
293                                            Long.valueOf(socialActivityLimitModelImpl.getOriginalUserId()),
294                                            Long.valueOf(socialActivityLimitModelImpl.getOriginalClassNameId()),
295                                            Long.valueOf(socialActivityLimitModelImpl.getOriginalClassPK()),
296                                            Integer.valueOf(socialActivityLimitModelImpl.getOriginalActivityType()),
297                                            
298                                            socialActivityLimitModelImpl.getOriginalActivityCounterName()
299                                    };
300    
301                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A, args);
302                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A, args);
303                    }
304            }
305    
306            /**
307             * Creates a new social activity limit with the primary key. Does not add the social activity limit to the database.
308             *
309             * @param activityLimitId the primary key for the new social activity limit
310             * @return the new social activity limit
311             */
312            public SocialActivityLimit create(long activityLimitId) {
313                    SocialActivityLimit socialActivityLimit = new SocialActivityLimitImpl();
314    
315                    socialActivityLimit.setNew(true);
316                    socialActivityLimit.setPrimaryKey(activityLimitId);
317    
318                    return socialActivityLimit;
319            }
320    
321            /**
322             * Removes the social activity limit with the primary key from the database. Also notifies the appropriate model listeners.
323             *
324             * @param activityLimitId the primary key of the social activity limit
325             * @return the social activity limit that was removed
326             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
327             * @throws SystemException if a system exception occurred
328             */
329            public SocialActivityLimit remove(long activityLimitId)
330                    throws NoSuchActivityLimitException, SystemException {
331                    return remove(Long.valueOf(activityLimitId));
332            }
333    
334            /**
335             * Removes the social activity limit with the primary key from the database. Also notifies the appropriate model listeners.
336             *
337             * @param primaryKey the primary key of the social activity limit
338             * @return the social activity limit that was removed
339             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
340             * @throws SystemException if a system exception occurred
341             */
342            @Override
343            public SocialActivityLimit remove(Serializable primaryKey)
344                    throws NoSuchActivityLimitException, SystemException {
345                    Session session = null;
346    
347                    try {
348                            session = openSession();
349    
350                            SocialActivityLimit socialActivityLimit = (SocialActivityLimit)session.get(SocialActivityLimitImpl.class,
351                                            primaryKey);
352    
353                            if (socialActivityLimit == null) {
354                                    if (_log.isWarnEnabled()) {
355                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
356                                    }
357    
358                                    throw new NoSuchActivityLimitException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
359                                            primaryKey);
360                            }
361    
362                            return remove(socialActivityLimit);
363                    }
364                    catch (NoSuchActivityLimitException nsee) {
365                            throw nsee;
366                    }
367                    catch (Exception e) {
368                            throw processException(e);
369                    }
370                    finally {
371                            closeSession(session);
372                    }
373            }
374    
375            @Override
376            protected SocialActivityLimit removeImpl(
377                    SocialActivityLimit socialActivityLimit) throws SystemException {
378                    socialActivityLimit = toUnwrappedModel(socialActivityLimit);
379    
380                    Session session = null;
381    
382                    try {
383                            session = openSession();
384    
385                            BatchSessionUtil.delete(session, socialActivityLimit);
386                    }
387                    catch (Exception e) {
388                            throw processException(e);
389                    }
390                    finally {
391                            closeSession(session);
392                    }
393    
394                    clearCache(socialActivityLimit);
395    
396                    return socialActivityLimit;
397            }
398    
399            @Override
400            public SocialActivityLimit updateImpl(
401                    com.liferay.portlet.social.model.SocialActivityLimit socialActivityLimit,
402                    boolean merge) throws SystemException {
403                    socialActivityLimit = toUnwrappedModel(socialActivityLimit);
404    
405                    boolean isNew = socialActivityLimit.isNew();
406    
407                    SocialActivityLimitModelImpl socialActivityLimitModelImpl = (SocialActivityLimitModelImpl)socialActivityLimit;
408    
409                    Session session = null;
410    
411                    try {
412                            session = openSession();
413    
414                            BatchSessionUtil.update(session, socialActivityLimit, merge);
415    
416                            socialActivityLimit.setNew(false);
417                    }
418                    catch (Exception e) {
419                            throw processException(e);
420                    }
421                    finally {
422                            closeSession(session);
423                    }
424    
425                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
426    
427                    if (isNew || !SocialActivityLimitModelImpl.COLUMN_BITMASK_ENABLED) {
428                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
429                    }
430    
431                    else {
432                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
433                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
434                                    Object[] args = new Object[] {
435                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalClassNameId()),
436                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalClassPK())
437                                            };
438    
439                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
440                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
441                                            args);
442    
443                                    args = new Object[] {
444                                                    Long.valueOf(socialActivityLimitModelImpl.getClassNameId()),
445                                                    Long.valueOf(socialActivityLimitModelImpl.getClassPK())
446                                            };
447    
448                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
449                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
450                                            args);
451                            }
452                    }
453    
454                    EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
455                            SocialActivityLimitImpl.class, socialActivityLimit.getPrimaryKey(),
456                            socialActivityLimit);
457    
458                    clearUniqueFindersCache(socialActivityLimit);
459                    cacheUniqueFindersCache(socialActivityLimit);
460    
461                    return socialActivityLimit;
462            }
463    
464            protected SocialActivityLimit toUnwrappedModel(
465                    SocialActivityLimit socialActivityLimit) {
466                    if (socialActivityLimit instanceof SocialActivityLimitImpl) {
467                            return socialActivityLimit;
468                    }
469    
470                    SocialActivityLimitImpl socialActivityLimitImpl = new SocialActivityLimitImpl();
471    
472                    socialActivityLimitImpl.setNew(socialActivityLimit.isNew());
473                    socialActivityLimitImpl.setPrimaryKey(socialActivityLimit.getPrimaryKey());
474    
475                    socialActivityLimitImpl.setActivityLimitId(socialActivityLimit.getActivityLimitId());
476                    socialActivityLimitImpl.setGroupId(socialActivityLimit.getGroupId());
477                    socialActivityLimitImpl.setCompanyId(socialActivityLimit.getCompanyId());
478                    socialActivityLimitImpl.setUserId(socialActivityLimit.getUserId());
479                    socialActivityLimitImpl.setClassNameId(socialActivityLimit.getClassNameId());
480                    socialActivityLimitImpl.setClassPK(socialActivityLimit.getClassPK());
481                    socialActivityLimitImpl.setActivityType(socialActivityLimit.getActivityType());
482                    socialActivityLimitImpl.setActivityCounterName(socialActivityLimit.getActivityCounterName());
483                    socialActivityLimitImpl.setValue(socialActivityLimit.getValue());
484    
485                    return socialActivityLimitImpl;
486            }
487    
488            /**
489             * Returns the social activity limit with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
490             *
491             * @param primaryKey the primary key of the social activity limit
492             * @return the social activity limit
493             * @throws com.liferay.portal.NoSuchModelException if a social activity limit with the primary key could not be found
494             * @throws SystemException if a system exception occurred
495             */
496            @Override
497            public SocialActivityLimit findByPrimaryKey(Serializable primaryKey)
498                    throws NoSuchModelException, SystemException {
499                    return findByPrimaryKey(((Long)primaryKey).longValue());
500            }
501    
502            /**
503             * Returns the social activity limit with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivityLimitException} if it could not be found.
504             *
505             * @param activityLimitId the primary key of the social activity limit
506             * @return the social activity limit
507             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
508             * @throws SystemException if a system exception occurred
509             */
510            public SocialActivityLimit findByPrimaryKey(long activityLimitId)
511                    throws NoSuchActivityLimitException, SystemException {
512                    SocialActivityLimit socialActivityLimit = fetchByPrimaryKey(activityLimitId);
513    
514                    if (socialActivityLimit == null) {
515                            if (_log.isWarnEnabled()) {
516                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + activityLimitId);
517                            }
518    
519                            throw new NoSuchActivityLimitException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
520                                    activityLimitId);
521                    }
522    
523                    return socialActivityLimit;
524            }
525    
526            /**
527             * Returns the social activity limit with the primary key or returns <code>null</code> if it could not be found.
528             *
529             * @param primaryKey the primary key of the social activity limit
530             * @return the social activity limit, or <code>null</code> if a social activity limit with the primary key could not be found
531             * @throws SystemException if a system exception occurred
532             */
533            @Override
534            public SocialActivityLimit fetchByPrimaryKey(Serializable primaryKey)
535                    throws SystemException {
536                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
537            }
538    
539            /**
540             * Returns the social activity limit with the primary key or returns <code>null</code> if it could not be found.
541             *
542             * @param activityLimitId the primary key of the social activity limit
543             * @return the social activity limit, or <code>null</code> if a social activity limit with the primary key could not be found
544             * @throws SystemException if a system exception occurred
545             */
546            public SocialActivityLimit fetchByPrimaryKey(long activityLimitId)
547                    throws SystemException {
548                    SocialActivityLimit socialActivityLimit = (SocialActivityLimit)EntityCacheUtil.getResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
549                                    SocialActivityLimitImpl.class, activityLimitId);
550    
551                    if (socialActivityLimit == _nullSocialActivityLimit) {
552                            return null;
553                    }
554    
555                    if (socialActivityLimit == null) {
556                            Session session = null;
557    
558                            boolean hasException = false;
559    
560                            try {
561                                    session = openSession();
562    
563                                    socialActivityLimit = (SocialActivityLimit)session.get(SocialActivityLimitImpl.class,
564                                                    Long.valueOf(activityLimitId));
565                            }
566                            catch (Exception e) {
567                                    hasException = true;
568    
569                                    throw processException(e);
570                            }
571                            finally {
572                                    if (socialActivityLimit != null) {
573                                            cacheResult(socialActivityLimit);
574                                    }
575                                    else if (!hasException) {
576                                            EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
577                                                    SocialActivityLimitImpl.class, activityLimitId,
578                                                    _nullSocialActivityLimit);
579                                    }
580    
581                                    closeSession(session);
582                            }
583                    }
584    
585                    return socialActivityLimit;
586            }
587    
588            /**
589             * Returns all the social activity limits where classNameId = &#63; and classPK = &#63;.
590             *
591             * @param classNameId the class name ID
592             * @param classPK the class p k
593             * @return the matching social activity limits
594             * @throws SystemException if a system exception occurred
595             */
596            public List<SocialActivityLimit> findByC_C(long classNameId, long classPK)
597                    throws SystemException {
598                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
599                            QueryUtil.ALL_POS, null);
600            }
601    
602            /**
603             * Returns a range of all the social activity limits where classNameId = &#63; and classPK = &#63;.
604             *
605             * <p>
606             * 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.
607             * </p>
608             *
609             * @param classNameId the class name ID
610             * @param classPK the class p k
611             * @param start the lower bound of the range of social activity limits
612             * @param end the upper bound of the range of social activity limits (not inclusive)
613             * @return the range of matching social activity limits
614             * @throws SystemException if a system exception occurred
615             */
616            public List<SocialActivityLimit> findByC_C(long classNameId, long classPK,
617                    int start, int end) throws SystemException {
618                    return findByC_C(classNameId, classPK, start, end, null);
619            }
620    
621            /**
622             * Returns an ordered range of all the social activity limits where classNameId = &#63; and classPK = &#63;.
623             *
624             * <p>
625             * 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.
626             * </p>
627             *
628             * @param classNameId the class name ID
629             * @param classPK the class p k
630             * @param start the lower bound of the range of social activity limits
631             * @param end the upper bound of the range of social activity limits (not inclusive)
632             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
633             * @return the ordered range of matching social activity limits
634             * @throws SystemException if a system exception occurred
635             */
636            public List<SocialActivityLimit> findByC_C(long classNameId, long classPK,
637                    int start, int end, OrderByComparator orderByComparator)
638                    throws SystemException {
639                    FinderPath finderPath = null;
640                    Object[] finderArgs = null;
641    
642                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
643                                    (orderByComparator == null)) {
644                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
645                            finderArgs = new Object[] { classNameId, classPK };
646                    }
647                    else {
648                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
649                            finderArgs = new Object[] {
650                                            classNameId, classPK,
651                                            
652                                            start, end, orderByComparator
653                                    };
654                    }
655    
656                    List<SocialActivityLimit> list = (List<SocialActivityLimit>)FinderCacheUtil.getResult(finderPath,
657                                    finderArgs, this);
658    
659                    if ((list != null) && !list.isEmpty()) {
660                            for (SocialActivityLimit socialActivityLimit : list) {
661                                    if ((classNameId != socialActivityLimit.getClassNameId()) ||
662                                                    (classPK != socialActivityLimit.getClassPK())) {
663                                            list = null;
664    
665                                            break;
666                                    }
667                            }
668                    }
669    
670                    if (list == null) {
671                            StringBundler query = null;
672    
673                            if (orderByComparator != null) {
674                                    query = new StringBundler(4 +
675                                                    (orderByComparator.getOrderByFields().length * 3));
676                            }
677                            else {
678                                    query = new StringBundler(3);
679                            }
680    
681                            query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
682    
683                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
684    
685                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
686    
687                            if (orderByComparator != null) {
688                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
689                                            orderByComparator);
690                            }
691    
692                            String sql = query.toString();
693    
694                            Session session = null;
695    
696                            try {
697                                    session = openSession();
698    
699                                    Query q = session.createQuery(sql);
700    
701                                    QueryPos qPos = QueryPos.getInstance(q);
702    
703                                    qPos.add(classNameId);
704    
705                                    qPos.add(classPK);
706    
707                                    list = (List<SocialActivityLimit>)QueryUtil.list(q,
708                                                    getDialect(), start, end);
709                            }
710                            catch (Exception e) {
711                                    throw processException(e);
712                            }
713                            finally {
714                                    if (list == null) {
715                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
716                                    }
717                                    else {
718                                            cacheResult(list);
719    
720                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
721                                    }
722    
723                                    closeSession(session);
724                            }
725                    }
726    
727                    return list;
728            }
729    
730            /**
731             * Returns the first social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
732             *
733             * @param classNameId the class name ID
734             * @param classPK the class p k
735             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
736             * @return the first matching social activity limit
737             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
738             * @throws SystemException if a system exception occurred
739             */
740            public SocialActivityLimit findByC_C_First(long classNameId, long classPK,
741                    OrderByComparator orderByComparator)
742                    throws NoSuchActivityLimitException, SystemException {
743                    SocialActivityLimit socialActivityLimit = fetchByC_C_First(classNameId,
744                                    classPK, orderByComparator);
745    
746                    if (socialActivityLimit != null) {
747                            return socialActivityLimit;
748                    }
749    
750                    StringBundler msg = new StringBundler(6);
751    
752                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
753    
754                    msg.append("classNameId=");
755                    msg.append(classNameId);
756    
757                    msg.append(", classPK=");
758                    msg.append(classPK);
759    
760                    msg.append(StringPool.CLOSE_CURLY_BRACE);
761    
762                    throw new NoSuchActivityLimitException(msg.toString());
763            }
764    
765            /**
766             * Returns the first social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
767             *
768             * @param classNameId the class name ID
769             * @param classPK the class p k
770             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
771             * @return the first matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
772             * @throws SystemException if a system exception occurred
773             */
774            public SocialActivityLimit fetchByC_C_First(long classNameId, long classPK,
775                    OrderByComparator orderByComparator) throws SystemException {
776                    List<SocialActivityLimit> list = findByC_C(classNameId, classPK, 0, 1,
777                                    orderByComparator);
778    
779                    if (!list.isEmpty()) {
780                            return list.get(0);
781                    }
782    
783                    return null;
784            }
785    
786            /**
787             * Returns the last social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
788             *
789             * @param classNameId the class name ID
790             * @param classPK the class p k
791             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
792             * @return the last matching social activity limit
793             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
794             * @throws SystemException if a system exception occurred
795             */
796            public SocialActivityLimit findByC_C_Last(long classNameId, long classPK,
797                    OrderByComparator orderByComparator)
798                    throws NoSuchActivityLimitException, SystemException {
799                    SocialActivityLimit socialActivityLimit = fetchByC_C_Last(classNameId,
800                                    classPK, orderByComparator);
801    
802                    if (socialActivityLimit != null) {
803                            return socialActivityLimit;
804                    }
805    
806                    StringBundler msg = new StringBundler(6);
807    
808                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
809    
810                    msg.append("classNameId=");
811                    msg.append(classNameId);
812    
813                    msg.append(", classPK=");
814                    msg.append(classPK);
815    
816                    msg.append(StringPool.CLOSE_CURLY_BRACE);
817    
818                    throw new NoSuchActivityLimitException(msg.toString());
819            }
820    
821            /**
822             * Returns the last social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
823             *
824             * @param classNameId the class name ID
825             * @param classPK the class p k
826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
827             * @return the last matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
828             * @throws SystemException if a system exception occurred
829             */
830            public SocialActivityLimit fetchByC_C_Last(long classNameId, long classPK,
831                    OrderByComparator orderByComparator) throws SystemException {
832                    int count = countByC_C(classNameId, classPK);
833    
834                    List<SocialActivityLimit> list = findByC_C(classNameId, classPK,
835                                    count - 1, count, orderByComparator);
836    
837                    if (!list.isEmpty()) {
838                            return list.get(0);
839                    }
840    
841                    return null;
842            }
843    
844            /**
845             * Returns the social activity limits before and after the current social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
846             *
847             * @param activityLimitId the primary key of the current social activity limit
848             * @param classNameId the class name ID
849             * @param classPK the class p k
850             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
851             * @return the previous, current, and next social activity limit
852             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
853             * @throws SystemException if a system exception occurred
854             */
855            public SocialActivityLimit[] findByC_C_PrevAndNext(long activityLimitId,
856                    long classNameId, long classPK, OrderByComparator orderByComparator)
857                    throws NoSuchActivityLimitException, SystemException {
858                    SocialActivityLimit socialActivityLimit = findByPrimaryKey(activityLimitId);
859    
860                    Session session = null;
861    
862                    try {
863                            session = openSession();
864    
865                            SocialActivityLimit[] array = new SocialActivityLimitImpl[3];
866    
867                            array[0] = getByC_C_PrevAndNext(session, socialActivityLimit,
868                                            classNameId, classPK, orderByComparator, true);
869    
870                            array[1] = socialActivityLimit;
871    
872                            array[2] = getByC_C_PrevAndNext(session, socialActivityLimit,
873                                            classNameId, classPK, orderByComparator, false);
874    
875                            return array;
876                    }
877                    catch (Exception e) {
878                            throw processException(e);
879                    }
880                    finally {
881                            closeSession(session);
882                    }
883            }
884    
885            protected SocialActivityLimit getByC_C_PrevAndNext(Session session,
886                    SocialActivityLimit socialActivityLimit, long classNameId,
887                    long classPK, OrderByComparator orderByComparator, boolean previous) {
888                    StringBundler query = null;
889    
890                    if (orderByComparator != null) {
891                            query = new StringBundler(6 +
892                                            (orderByComparator.getOrderByFields().length * 6));
893                    }
894                    else {
895                            query = new StringBundler(3);
896                    }
897    
898                    query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
899    
900                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
901    
902                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
903    
904                    if (orderByComparator != null) {
905                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
906    
907                            if (orderByConditionFields.length > 0) {
908                                    query.append(WHERE_AND);
909                            }
910    
911                            for (int i = 0; i < orderByConditionFields.length; i++) {
912                                    query.append(_ORDER_BY_ENTITY_ALIAS);
913                                    query.append(orderByConditionFields[i]);
914    
915                                    if ((i + 1) < orderByConditionFields.length) {
916                                            if (orderByComparator.isAscending() ^ previous) {
917                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
918                                            }
919                                            else {
920                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
921                                            }
922                                    }
923                                    else {
924                                            if (orderByComparator.isAscending() ^ previous) {
925                                                    query.append(WHERE_GREATER_THAN);
926                                            }
927                                            else {
928                                                    query.append(WHERE_LESSER_THAN);
929                                            }
930                                    }
931                            }
932    
933                            query.append(ORDER_BY_CLAUSE);
934    
935                            String[] orderByFields = orderByComparator.getOrderByFields();
936    
937                            for (int i = 0; i < orderByFields.length; i++) {
938                                    query.append(_ORDER_BY_ENTITY_ALIAS);
939                                    query.append(orderByFields[i]);
940    
941                                    if ((i + 1) < orderByFields.length) {
942                                            if (orderByComparator.isAscending() ^ previous) {
943                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
944                                            }
945                                            else {
946                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
947                                            }
948                                    }
949                                    else {
950                                            if (orderByComparator.isAscending() ^ previous) {
951                                                    query.append(ORDER_BY_ASC);
952                                            }
953                                            else {
954                                                    query.append(ORDER_BY_DESC);
955                                            }
956                                    }
957                            }
958                    }
959    
960                    String sql = query.toString();
961    
962                    Query q = session.createQuery(sql);
963    
964                    q.setFirstResult(0);
965                    q.setMaxResults(2);
966    
967                    QueryPos qPos = QueryPos.getInstance(q);
968    
969                    qPos.add(classNameId);
970    
971                    qPos.add(classPK);
972    
973                    if (orderByComparator != null) {
974                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityLimit);
975    
976                            for (Object value : values) {
977                                    qPos.add(value);
978                            }
979                    }
980    
981                    List<SocialActivityLimit> list = q.list();
982    
983                    if (list.size() == 2) {
984                            return list.get(1);
985                    }
986                    else {
987                            return null;
988                    }
989            }
990    
991            /**
992             * Returns 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.
993             *
994             * @param groupId the group ID
995             * @param userId the user ID
996             * @param classNameId the class name ID
997             * @param classPK the class p k
998             * @param activityType the activity type
999             * @param activityCounterName the activity counter name
1000             * @return the matching social activity limit
1001             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
1002             * @throws SystemException if a system exception occurred
1003             */
1004            public SocialActivityLimit findByG_U_C_C_A_A(long groupId, long userId,
1005                    long classNameId, long classPK, int activityType,
1006                    String activityCounterName)
1007                    throws NoSuchActivityLimitException, SystemException {
1008                    SocialActivityLimit socialActivityLimit = fetchByG_U_C_C_A_A(groupId,
1009                                    userId, classNameId, classPK, activityType, activityCounterName);
1010    
1011                    if (socialActivityLimit == null) {
1012                            StringBundler msg = new StringBundler(14);
1013    
1014                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1015    
1016                            msg.append("groupId=");
1017                            msg.append(groupId);
1018    
1019                            msg.append(", userId=");
1020                            msg.append(userId);
1021    
1022                            msg.append(", classNameId=");
1023                            msg.append(classNameId);
1024    
1025                            msg.append(", classPK=");
1026                            msg.append(classPK);
1027    
1028                            msg.append(", activityType=");
1029                            msg.append(activityType);
1030    
1031                            msg.append(", activityCounterName=");
1032                            msg.append(activityCounterName);
1033    
1034                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1035    
1036                            if (_log.isWarnEnabled()) {
1037                                    _log.warn(msg.toString());
1038                            }
1039    
1040                            throw new NoSuchActivityLimitException(msg.toString());
1041                    }
1042    
1043                    return socialActivityLimit;
1044            }
1045    
1046            /**
1047             * 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.
1048             *
1049             * @param groupId the group ID
1050             * @param userId the user ID
1051             * @param classNameId the class name ID
1052             * @param classPK the class p k
1053             * @param activityType the activity type
1054             * @param activityCounterName the activity counter name
1055             * @return the matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
1056             * @throws SystemException if a system exception occurred
1057             */
1058            public SocialActivityLimit fetchByG_U_C_C_A_A(long groupId, long userId,
1059                    long classNameId, long classPK, int activityType,
1060                    String activityCounterName) throws SystemException {
1061                    return fetchByG_U_C_C_A_A(groupId, userId, classNameId, classPK,
1062                            activityType, activityCounterName, true);
1063            }
1064    
1065            /**
1066             * 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.
1067             *
1068             * @param groupId the group ID
1069             * @param userId the user ID
1070             * @param classNameId the class name ID
1071             * @param classPK the class p k
1072             * @param activityType the activity type
1073             * @param activityCounterName the activity counter name
1074             * @param retrieveFromCache whether to use the finder cache
1075             * @return the matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
1076             * @throws SystemException if a system exception occurred
1077             */
1078            public SocialActivityLimit fetchByG_U_C_C_A_A(long groupId, long userId,
1079                    long classNameId, long classPK, int activityType,
1080                    String activityCounterName, boolean retrieveFromCache)
1081                    throws SystemException {
1082                    Object[] finderArgs = new Object[] {
1083                                    groupId, userId, classNameId, classPK, activityType,
1084                                    activityCounterName
1085                            };
1086    
1087                    Object result = null;
1088    
1089                    if (retrieveFromCache) {
1090                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1091                                            finderArgs, this);
1092                    }
1093    
1094                    if (result instanceof SocialActivityLimit) {
1095                            SocialActivityLimit socialActivityLimit = (SocialActivityLimit)result;
1096    
1097                            if ((groupId != socialActivityLimit.getGroupId()) ||
1098                                            (userId != socialActivityLimit.getUserId()) ||
1099                                            (classNameId != socialActivityLimit.getClassNameId()) ||
1100                                            (classPK != socialActivityLimit.getClassPK()) ||
1101                                            (activityType != socialActivityLimit.getActivityType()) ||
1102                                            !Validator.equals(activityCounterName,
1103                                                    socialActivityLimit.getActivityCounterName())) {
1104                                    result = null;
1105                            }
1106                    }
1107    
1108                    if (result == null) {
1109                            StringBundler query = new StringBundler(7);
1110    
1111                            query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
1112    
1113                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2);
1114    
1115                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_USERID_2);
1116    
1117                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2);
1118    
1119                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2);
1120    
1121                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2);
1122    
1123                            if (activityCounterName == null) {
1124                                    query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1);
1125                            }
1126                            else {
1127                                    if (activityCounterName.equals(StringPool.BLANK)) {
1128                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3);
1129                                    }
1130                                    else {
1131                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2);
1132                                    }
1133                            }
1134    
1135                            String sql = query.toString();
1136    
1137                            Session session = null;
1138    
1139                            try {
1140                                    session = openSession();
1141    
1142                                    Query q = session.createQuery(sql);
1143    
1144                                    QueryPos qPos = QueryPos.getInstance(q);
1145    
1146                                    qPos.add(groupId);
1147    
1148                                    qPos.add(userId);
1149    
1150                                    qPos.add(classNameId);
1151    
1152                                    qPos.add(classPK);
1153    
1154                                    qPos.add(activityType);
1155    
1156                                    if (activityCounterName != null) {
1157                                            qPos.add(activityCounterName);
1158                                    }
1159    
1160                                    List<SocialActivityLimit> list = q.list();
1161    
1162                                    result = list;
1163    
1164                                    SocialActivityLimit socialActivityLimit = null;
1165    
1166                                    if (list.isEmpty()) {
1167                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1168                                                    finderArgs, list);
1169                                    }
1170                                    else {
1171                                            socialActivityLimit = list.get(0);
1172    
1173                                            cacheResult(socialActivityLimit);
1174    
1175                                            if ((socialActivityLimit.getGroupId() != groupId) ||
1176                                                            (socialActivityLimit.getUserId() != userId) ||
1177                                                            (socialActivityLimit.getClassNameId() != classNameId) ||
1178                                                            (socialActivityLimit.getClassPK() != classPK) ||
1179                                                            (socialActivityLimit.getActivityType() != activityType) ||
1180                                                            (socialActivityLimit.getActivityCounterName() == null) ||
1181                                                            !socialActivityLimit.getActivityCounterName()
1182                                                                                                            .equals(activityCounterName)) {
1183                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1184                                                            finderArgs, socialActivityLimit);
1185                                            }
1186                                    }
1187    
1188                                    return socialActivityLimit;
1189                            }
1190                            catch (Exception e) {
1191                                    throw processException(e);
1192                            }
1193                            finally {
1194                                    if (result == null) {
1195                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1196                                                    finderArgs);
1197                                    }
1198    
1199                                    closeSession(session);
1200                            }
1201                    }
1202                    else {
1203                            if (result instanceof List<?>) {
1204                                    return null;
1205                            }
1206                            else {
1207                                    return (SocialActivityLimit)result;
1208                            }
1209                    }
1210            }
1211    
1212            /**
1213             * Returns all the social activity limits.
1214             *
1215             * @return the social activity limits
1216             * @throws SystemException if a system exception occurred
1217             */
1218            public List<SocialActivityLimit> findAll() throws SystemException {
1219                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1220            }
1221    
1222            /**
1223             * Returns a range of all the social activity limits.
1224             *
1225             * <p>
1226             * 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.
1227             * </p>
1228             *
1229             * @param start the lower bound of the range of social activity limits
1230             * @param end the upper bound of the range of social activity limits (not inclusive)
1231             * @return the range of social activity limits
1232             * @throws SystemException if a system exception occurred
1233             */
1234            public List<SocialActivityLimit> findAll(int start, int end)
1235                    throws SystemException {
1236                    return findAll(start, end, null);
1237            }
1238    
1239            /**
1240             * Returns an ordered range of all the social activity limits.
1241             *
1242             * <p>
1243             * 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.
1244             * </p>
1245             *
1246             * @param start the lower bound of the range of social activity limits
1247             * @param end the upper bound of the range of social activity limits (not inclusive)
1248             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1249             * @return the ordered range of social activity limits
1250             * @throws SystemException if a system exception occurred
1251             */
1252            public List<SocialActivityLimit> findAll(int start, int end,
1253                    OrderByComparator orderByComparator) throws SystemException {
1254                    FinderPath finderPath = null;
1255                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1256    
1257                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1258                                    (orderByComparator == null)) {
1259                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1260                            finderArgs = FINDER_ARGS_EMPTY;
1261                    }
1262                    else {
1263                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1264                            finderArgs = new Object[] { start, end, orderByComparator };
1265                    }
1266    
1267                    List<SocialActivityLimit> list = (List<SocialActivityLimit>)FinderCacheUtil.getResult(finderPath,
1268                                    finderArgs, this);
1269    
1270                    if (list == null) {
1271                            StringBundler query = null;
1272                            String sql = null;
1273    
1274                            if (orderByComparator != null) {
1275                                    query = new StringBundler(2 +
1276                                                    (orderByComparator.getOrderByFields().length * 3));
1277    
1278                                    query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT);
1279    
1280                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1281                                            orderByComparator);
1282    
1283                                    sql = query.toString();
1284                            }
1285                            else {
1286                                    sql = _SQL_SELECT_SOCIALACTIVITYLIMIT;
1287                            }
1288    
1289                            Session session = null;
1290    
1291                            try {
1292                                    session = openSession();
1293    
1294                                    Query q = session.createQuery(sql);
1295    
1296                                    if (orderByComparator == null) {
1297                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
1298                                                            getDialect(), start, end, false);
1299    
1300                                            Collections.sort(list);
1301                                    }
1302                                    else {
1303                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
1304                                                            getDialect(), start, end);
1305                                    }
1306                            }
1307                            catch (Exception e) {
1308                                    throw processException(e);
1309                            }
1310                            finally {
1311                                    if (list == null) {
1312                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1313                                    }
1314                                    else {
1315                                            cacheResult(list);
1316    
1317                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1318                                    }
1319    
1320                                    closeSession(session);
1321                            }
1322                    }
1323    
1324                    return list;
1325            }
1326    
1327            /**
1328             * Removes all the social activity limits where classNameId = &#63; and classPK = &#63; from the database.
1329             *
1330             * @param classNameId the class name ID
1331             * @param classPK the class p k
1332             * @throws SystemException if a system exception occurred
1333             */
1334            public void removeByC_C(long classNameId, long classPK)
1335                    throws SystemException {
1336                    for (SocialActivityLimit socialActivityLimit : findByC_C(classNameId,
1337                                    classPK)) {
1338                            remove(socialActivityLimit);
1339                    }
1340            }
1341    
1342            /**
1343             * 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.
1344             *
1345             * @param groupId the group ID
1346             * @param userId the user ID
1347             * @param classNameId the class name ID
1348             * @param classPK the class p k
1349             * @param activityType the activity type
1350             * @param activityCounterName the activity counter name
1351             * @return the social activity limit that was removed
1352             * @throws SystemException if a system exception occurred
1353             */
1354            public SocialActivityLimit removeByG_U_C_C_A_A(long groupId, long userId,
1355                    long classNameId, long classPK, int activityType,
1356                    String activityCounterName)
1357                    throws NoSuchActivityLimitException, SystemException {
1358                    SocialActivityLimit socialActivityLimit = findByG_U_C_C_A_A(groupId,
1359                                    userId, classNameId, classPK, activityType, activityCounterName);
1360    
1361                    return remove(socialActivityLimit);
1362            }
1363    
1364            /**
1365             * Removes all the social activity limits from the database.
1366             *
1367             * @throws SystemException if a system exception occurred
1368             */
1369            public void removeAll() throws SystemException {
1370                    for (SocialActivityLimit socialActivityLimit : findAll()) {
1371                            remove(socialActivityLimit);
1372                    }
1373            }
1374    
1375            /**
1376             * Returns the number of social activity limits where classNameId = &#63; and classPK = &#63;.
1377             *
1378             * @param classNameId the class name ID
1379             * @param classPK the class p k
1380             * @return the number of matching social activity limits
1381             * @throws SystemException if a system exception occurred
1382             */
1383            public int countByC_C(long classNameId, long classPK)
1384                    throws SystemException {
1385                    Object[] finderArgs = new Object[] { classNameId, classPK };
1386    
1387                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1388                                    finderArgs, this);
1389    
1390                    if (count == null) {
1391                            StringBundler query = new StringBundler(3);
1392    
1393                            query.append(_SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE);
1394    
1395                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1396    
1397                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1398    
1399                            String sql = query.toString();
1400    
1401                            Session session = null;
1402    
1403                            try {
1404                                    session = openSession();
1405    
1406                                    Query q = session.createQuery(sql);
1407    
1408                                    QueryPos qPos = QueryPos.getInstance(q);
1409    
1410                                    qPos.add(classNameId);
1411    
1412                                    qPos.add(classPK);
1413    
1414                                    count = (Long)q.uniqueResult();
1415                            }
1416                            catch (Exception e) {
1417                                    throw processException(e);
1418                            }
1419                            finally {
1420                                    if (count == null) {
1421                                            count = Long.valueOf(0);
1422                                    }
1423    
1424                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1425                                            count);
1426    
1427                                    closeSession(session);
1428                            }
1429                    }
1430    
1431                    return count.intValue();
1432            }
1433    
1434            /**
1435             * 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;.
1436             *
1437             * @param groupId the group ID
1438             * @param userId the user ID
1439             * @param classNameId the class name ID
1440             * @param classPK the class p k
1441             * @param activityType the activity type
1442             * @param activityCounterName the activity counter name
1443             * @return the number of matching social activity limits
1444             * @throws SystemException if a system exception occurred
1445             */
1446            public int countByG_U_C_C_A_A(long groupId, long userId, long classNameId,
1447                    long classPK, int activityType, String activityCounterName)
1448                    throws SystemException {
1449                    Object[] finderArgs = new Object[] {
1450                                    groupId, userId, classNameId, classPK, activityType,
1451                                    activityCounterName
1452                            };
1453    
1454                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A,
1455                                    finderArgs, this);
1456    
1457                    if (count == null) {
1458                            StringBundler query = new StringBundler(7);
1459    
1460                            query.append(_SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE);
1461    
1462                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2);
1463    
1464                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_USERID_2);
1465    
1466                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2);
1467    
1468                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2);
1469    
1470                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2);
1471    
1472                            if (activityCounterName == null) {
1473                                    query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1);
1474                            }
1475                            else {
1476                                    if (activityCounterName.equals(StringPool.BLANK)) {
1477                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3);
1478                                    }
1479                                    else {
1480                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2);
1481                                    }
1482                            }
1483    
1484                            String sql = query.toString();
1485    
1486                            Session session = null;
1487    
1488                            try {
1489                                    session = openSession();
1490    
1491                                    Query q = session.createQuery(sql);
1492    
1493                                    QueryPos qPos = QueryPos.getInstance(q);
1494    
1495                                    qPos.add(groupId);
1496    
1497                                    qPos.add(userId);
1498    
1499                                    qPos.add(classNameId);
1500    
1501                                    qPos.add(classPK);
1502    
1503                                    qPos.add(activityType);
1504    
1505                                    if (activityCounterName != null) {
1506                                            qPos.add(activityCounterName);
1507                                    }
1508    
1509                                    count = (Long)q.uniqueResult();
1510                            }
1511                            catch (Exception e) {
1512                                    throw processException(e);
1513                            }
1514                            finally {
1515                                    if (count == null) {
1516                                            count = Long.valueOf(0);
1517                                    }
1518    
1519                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A,
1520                                            finderArgs, count);
1521    
1522                                    closeSession(session);
1523                            }
1524                    }
1525    
1526                    return count.intValue();
1527            }
1528    
1529            /**
1530             * Returns the number of social activity limits.
1531             *
1532             * @return the number of social activity limits
1533             * @throws SystemException if a system exception occurred
1534             */
1535            public int countAll() throws SystemException {
1536                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1537                                    FINDER_ARGS_EMPTY, this);
1538    
1539                    if (count == null) {
1540                            Session session = null;
1541    
1542                            try {
1543                                    session = openSession();
1544    
1545                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYLIMIT);
1546    
1547                                    count = (Long)q.uniqueResult();
1548                            }
1549                            catch (Exception e) {
1550                                    throw processException(e);
1551                            }
1552                            finally {
1553                                    if (count == null) {
1554                                            count = Long.valueOf(0);
1555                                    }
1556    
1557                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1558                                            FINDER_ARGS_EMPTY, count);
1559    
1560                                    closeSession(session);
1561                            }
1562                    }
1563    
1564                    return count.intValue();
1565            }
1566    
1567            /**
1568             * Initializes the social activity limit persistence.
1569             */
1570            public void afterPropertiesSet() {
1571                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1572                                            com.liferay.portal.util.PropsUtil.get(
1573                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivityLimit")));
1574    
1575                    if (listenerClassNames.length > 0) {
1576                            try {
1577                                    List<ModelListener<SocialActivityLimit>> listenersList = new ArrayList<ModelListener<SocialActivityLimit>>();
1578    
1579                                    for (String listenerClassName : listenerClassNames) {
1580                                            Class<?> clazz = getClass();
1581    
1582                                            listenersList.add((ModelListener<SocialActivityLimit>)InstanceFactory.newInstance(
1583                                                            clazz.getClassLoader(), listenerClassName));
1584                                    }
1585    
1586                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1587                            }
1588                            catch (Exception e) {
1589                                    _log.error(e);
1590                            }
1591                    }
1592            }
1593    
1594            public void destroy() {
1595                    EntityCacheUtil.removeCache(SocialActivityLimitImpl.class.getName());
1596                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1597                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1598            }
1599    
1600            @BeanReference(type = SocialActivityPersistence.class)
1601            protected SocialActivityPersistence socialActivityPersistence;
1602            @BeanReference(type = SocialActivityAchievementPersistence.class)
1603            protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
1604            @BeanReference(type = SocialActivityCounterPersistence.class)
1605            protected SocialActivityCounterPersistence socialActivityCounterPersistence;
1606            @BeanReference(type = SocialActivityLimitPersistence.class)
1607            protected SocialActivityLimitPersistence socialActivityLimitPersistence;
1608            @BeanReference(type = SocialActivitySettingPersistence.class)
1609            protected SocialActivitySettingPersistence socialActivitySettingPersistence;
1610            @BeanReference(type = SocialRelationPersistence.class)
1611            protected SocialRelationPersistence socialRelationPersistence;
1612            @BeanReference(type = SocialRequestPersistence.class)
1613            protected SocialRequestPersistence socialRequestPersistence;
1614            @BeanReference(type = GroupPersistence.class)
1615            protected GroupPersistence groupPersistence;
1616            @BeanReference(type = ResourcePersistence.class)
1617            protected ResourcePersistence resourcePersistence;
1618            @BeanReference(type = UserPersistence.class)
1619            protected UserPersistence userPersistence;
1620            private static final String _SQL_SELECT_SOCIALACTIVITYLIMIT = "SELECT socialActivityLimit FROM SocialActivityLimit socialActivityLimit";
1621            private static final String _SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE = "SELECT socialActivityLimit FROM SocialActivityLimit socialActivityLimit WHERE ";
1622            private static final String _SQL_COUNT_SOCIALACTIVITYLIMIT = "SELECT COUNT(socialActivityLimit) FROM SocialActivityLimit socialActivityLimit";
1623            private static final String _SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE = "SELECT COUNT(socialActivityLimit) FROM SocialActivityLimit socialActivityLimit WHERE ";
1624            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "socialActivityLimit.classNameId = ? AND ";
1625            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "socialActivityLimit.classPK = ?";
1626            private static final String _FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2 = "socialActivityLimit.groupId = ? AND ";
1627            private static final String _FINDER_COLUMN_G_U_C_C_A_A_USERID_2 = "socialActivityLimit.userId = ? AND ";
1628            private static final String _FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2 = "socialActivityLimit.classNameId = ? AND ";
1629            private static final String _FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2 = "socialActivityLimit.classPK = ? AND ";
1630            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2 = "socialActivityLimit.activityType = ? AND ";
1631            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1 =
1632                    "socialActivityLimit.activityCounterName IS NULL";
1633            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2 =
1634                    "socialActivityLimit.activityCounterName = ?";
1635            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3 =
1636                    "(socialActivityLimit.activityCounterName IS NULL OR socialActivityLimit.activityCounterName = ?)";
1637            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivityLimit.";
1638            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivityLimit exists with the primary key ";
1639            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivityLimit exists with the key {";
1640            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1641            private static Log _log = LogFactoryUtil.getLog(SocialActivityLimitPersistenceImpl.class);
1642            private static SocialActivityLimit _nullSocialActivityLimit = new SocialActivityLimitImpl() {
1643                            @Override
1644                            public Object clone() {
1645                                    return this;
1646                            }
1647    
1648                            @Override
1649                            public CacheModel<SocialActivityLimit> toCacheModel() {
1650                                    return _nullSocialActivityLimitCacheModel;
1651                            }
1652                    };
1653    
1654            private static CacheModel<SocialActivityLimit> _nullSocialActivityLimitCacheModel =
1655                    new CacheModel<SocialActivityLimit>() {
1656                            public SocialActivityLimit toEntityModel() {
1657                                    return _nullSocialActivityLimit;
1658                            }
1659                    };
1660    }