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