001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.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 clearUniqueFindersCache(
232                    SocialActivityLimit socialActivityLimit) {
233                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
234                            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    
245            /**
246             * Creates a new social activity limit with the primary key. Does not add the social activity limit to the database.
247             *
248             * @param activityLimitId the primary key for the new social activity limit
249             * @return the new social activity limit
250             */
251            public SocialActivityLimit create(long activityLimitId) {
252                    SocialActivityLimit socialActivityLimit = new SocialActivityLimitImpl();
253    
254                    socialActivityLimit.setNew(true);
255                    socialActivityLimit.setPrimaryKey(activityLimitId);
256    
257                    return socialActivityLimit;
258            }
259    
260            /**
261             * Removes the social activity limit with the primary key from the database. Also notifies the appropriate model listeners.
262             *
263             * @param activityLimitId the primary key of the social activity limit
264             * @return the social activity limit that was removed
265             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
266             * @throws SystemException if a system exception occurred
267             */
268            public SocialActivityLimit remove(long activityLimitId)
269                    throws NoSuchActivityLimitException, SystemException {
270                    return remove(Long.valueOf(activityLimitId));
271            }
272    
273            /**
274             * Removes the social activity limit with the primary key from the database. Also notifies the appropriate model listeners.
275             *
276             * @param primaryKey the primary key of the social activity limit
277             * @return the social activity limit that was removed
278             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
279             * @throws SystemException if a system exception occurred
280             */
281            @Override
282            public SocialActivityLimit remove(Serializable primaryKey)
283                    throws NoSuchActivityLimitException, SystemException {
284                    Session session = null;
285    
286                    try {
287                            session = openSession();
288    
289                            SocialActivityLimit socialActivityLimit = (SocialActivityLimit)session.get(SocialActivityLimitImpl.class,
290                                            primaryKey);
291    
292                            if (socialActivityLimit == null) {
293                                    if (_log.isWarnEnabled()) {
294                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
295                                    }
296    
297                                    throw new NoSuchActivityLimitException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
298                                            primaryKey);
299                            }
300    
301                            return remove(socialActivityLimit);
302                    }
303                    catch (NoSuchActivityLimitException nsee) {
304                            throw nsee;
305                    }
306                    catch (Exception e) {
307                            throw processException(e);
308                    }
309                    finally {
310                            closeSession(session);
311                    }
312            }
313    
314            @Override
315            protected SocialActivityLimit removeImpl(
316                    SocialActivityLimit socialActivityLimit) throws SystemException {
317                    socialActivityLimit = toUnwrappedModel(socialActivityLimit);
318    
319                    Session session = null;
320    
321                    try {
322                            session = openSession();
323    
324                            BatchSessionUtil.delete(session, socialActivityLimit);
325                    }
326                    catch (Exception e) {
327                            throw processException(e);
328                    }
329                    finally {
330                            closeSession(session);
331                    }
332    
333                    clearCache(socialActivityLimit);
334    
335                    return socialActivityLimit;
336            }
337    
338            @Override
339            public SocialActivityLimit updateImpl(
340                    com.liferay.portlet.social.model.SocialActivityLimit socialActivityLimit,
341                    boolean merge) throws SystemException {
342                    socialActivityLimit = toUnwrappedModel(socialActivityLimit);
343    
344                    boolean isNew = socialActivityLimit.isNew();
345    
346                    SocialActivityLimitModelImpl socialActivityLimitModelImpl = (SocialActivityLimitModelImpl)socialActivityLimit;
347    
348                    Session session = null;
349    
350                    try {
351                            session = openSession();
352    
353                            BatchSessionUtil.update(session, socialActivityLimit, merge);
354    
355                            socialActivityLimit.setNew(false);
356                    }
357                    catch (Exception e) {
358                            throw processException(e);
359                    }
360                    finally {
361                            closeSession(session);
362                    }
363    
364                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
365    
366                    if (isNew || !SocialActivityLimitModelImpl.COLUMN_BITMASK_ENABLED) {
367                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
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) && !list.isEmpty()) {
638                            for (SocialActivityLimit socialActivityLimit : list) {
639                                    if ((classNameId != socialActivityLimit.getClassNameId()) ||
640                                                    (classPK != socialActivityLimit.getClassPK())) {
641                                            list = null;
642    
643                                            break;
644                                    }
645                            }
646                    }
647    
648                    if (list == null) {
649                            StringBundler query = null;
650    
651                            if (orderByComparator != null) {
652                                    query = new StringBundler(4 +
653                                                    (orderByComparator.getOrderByFields().length * 3));
654                            }
655                            else {
656                                    query = new StringBundler(3);
657                            }
658    
659                            query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
660    
661                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
662    
663                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
664    
665                            if (orderByComparator != null) {
666                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
667                                            orderByComparator);
668                            }
669    
670                            String sql = query.toString();
671    
672                            Session session = null;
673    
674                            try {
675                                    session = openSession();
676    
677                                    Query q = session.createQuery(sql);
678    
679                                    QueryPos qPos = QueryPos.getInstance(q);
680    
681                                    qPos.add(classNameId);
682    
683                                    qPos.add(classPK);
684    
685                                    list = (List<SocialActivityLimit>)QueryUtil.list(q,
686                                                    getDialect(), start, end);
687                            }
688                            catch (Exception e) {
689                                    throw processException(e);
690                            }
691                            finally {
692                                    if (list == null) {
693                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
694                                    }
695                                    else {
696                                            cacheResult(list);
697    
698                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
699                                    }
700    
701                                    closeSession(session);
702                            }
703                    }
704    
705                    return list;
706            }
707    
708            /**
709             * Returns the first social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
710             *
711             * <p>
712             * 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.
713             * </p>
714             *
715             * @param classNameId the class name ID
716             * @param classPK the class p k
717             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
718             * @return the first matching social activity limit
719             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
720             * @throws SystemException if a system exception occurred
721             */
722            public SocialActivityLimit findByC_C_First(long classNameId, long classPK,
723                    OrderByComparator orderByComparator)
724                    throws NoSuchActivityLimitException, SystemException {
725                    List<SocialActivityLimit> list = findByC_C(classNameId, classPK, 0, 1,
726                                    orderByComparator);
727    
728                    if (list.isEmpty()) {
729                            StringBundler msg = new StringBundler(6);
730    
731                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
732    
733                            msg.append("classNameId=");
734                            msg.append(classNameId);
735    
736                            msg.append(", classPK=");
737                            msg.append(classPK);
738    
739                            msg.append(StringPool.CLOSE_CURLY_BRACE);
740    
741                            throw new NoSuchActivityLimitException(msg.toString());
742                    }
743                    else {
744                            return list.get(0);
745                    }
746            }
747    
748            /**
749             * Returns the last social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
750             *
751             * <p>
752             * 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.
753             * </p>
754             *
755             * @param classNameId the class name ID
756             * @param classPK the class p k
757             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
758             * @return the last matching social activity limit
759             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
760             * @throws SystemException if a system exception occurred
761             */
762            public SocialActivityLimit findByC_C_Last(long classNameId, long classPK,
763                    OrderByComparator orderByComparator)
764                    throws NoSuchActivityLimitException, SystemException {
765                    int count = countByC_C(classNameId, classPK);
766    
767                    List<SocialActivityLimit> list = findByC_C(classNameId, classPK,
768                                    count - 1, count, orderByComparator);
769    
770                    if (list.isEmpty()) {
771                            StringBundler msg = new StringBundler(6);
772    
773                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
774    
775                            msg.append("classNameId=");
776                            msg.append(classNameId);
777    
778                            msg.append(", classPK=");
779                            msg.append(classPK);
780    
781                            msg.append(StringPool.CLOSE_CURLY_BRACE);
782    
783                            throw new NoSuchActivityLimitException(msg.toString());
784                    }
785                    else {
786                            return list.get(0);
787                    }
788            }
789    
790            /**
791             * Returns the social activity limits before and after the current social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
792             *
793             * <p>
794             * 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.
795             * </p>
796             *
797             * @param activityLimitId the primary key of the current social activity limit
798             * @param classNameId the class name ID
799             * @param classPK the class p k
800             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
801             * @return the previous, current, and next social activity limit
802             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
803             * @throws SystemException if a system exception occurred
804             */
805            public SocialActivityLimit[] findByC_C_PrevAndNext(long activityLimitId,
806                    long classNameId, long classPK, OrderByComparator orderByComparator)
807                    throws NoSuchActivityLimitException, SystemException {
808                    SocialActivityLimit socialActivityLimit = findByPrimaryKey(activityLimitId);
809    
810                    Session session = null;
811    
812                    try {
813                            session = openSession();
814    
815                            SocialActivityLimit[] array = new SocialActivityLimitImpl[3];
816    
817                            array[0] = getByC_C_PrevAndNext(session, socialActivityLimit,
818                                            classNameId, classPK, orderByComparator, true);
819    
820                            array[1] = socialActivityLimit;
821    
822                            array[2] = getByC_C_PrevAndNext(session, socialActivityLimit,
823                                            classNameId, classPK, orderByComparator, false);
824    
825                            return array;
826                    }
827                    catch (Exception e) {
828                            throw processException(e);
829                    }
830                    finally {
831                            closeSession(session);
832                    }
833            }
834    
835            protected SocialActivityLimit getByC_C_PrevAndNext(Session session,
836                    SocialActivityLimit socialActivityLimit, long classNameId,
837                    long classPK, OrderByComparator orderByComparator, boolean previous) {
838                    StringBundler query = null;
839    
840                    if (orderByComparator != null) {
841                            query = new StringBundler(6 +
842                                            (orderByComparator.getOrderByFields().length * 6));
843                    }
844                    else {
845                            query = new StringBundler(3);
846                    }
847    
848                    query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
849    
850                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
851    
852                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
853    
854                    if (orderByComparator != null) {
855                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
856    
857                            if (orderByConditionFields.length > 0) {
858                                    query.append(WHERE_AND);
859                            }
860    
861                            for (int i = 0; i < orderByConditionFields.length; i++) {
862                                    query.append(_ORDER_BY_ENTITY_ALIAS);
863                                    query.append(orderByConditionFields[i]);
864    
865                                    if ((i + 1) < orderByConditionFields.length) {
866                                            if (orderByComparator.isAscending() ^ previous) {
867                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
868                                            }
869                                            else {
870                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
871                                            }
872                                    }
873                                    else {
874                                            if (orderByComparator.isAscending() ^ previous) {
875                                                    query.append(WHERE_GREATER_THAN);
876                                            }
877                                            else {
878                                                    query.append(WHERE_LESSER_THAN);
879                                            }
880                                    }
881                            }
882    
883                            query.append(ORDER_BY_CLAUSE);
884    
885                            String[] orderByFields = orderByComparator.getOrderByFields();
886    
887                            for (int i = 0; i < orderByFields.length; i++) {
888                                    query.append(_ORDER_BY_ENTITY_ALIAS);
889                                    query.append(orderByFields[i]);
890    
891                                    if ((i + 1) < orderByFields.length) {
892                                            if (orderByComparator.isAscending() ^ previous) {
893                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
894                                            }
895                                            else {
896                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
897                                            }
898                                    }
899                                    else {
900                                            if (orderByComparator.isAscending() ^ previous) {
901                                                    query.append(ORDER_BY_ASC);
902                                            }
903                                            else {
904                                                    query.append(ORDER_BY_DESC);
905                                            }
906                                    }
907                            }
908                    }
909    
910                    String sql = query.toString();
911    
912                    Query q = session.createQuery(sql);
913    
914                    q.setFirstResult(0);
915                    q.setMaxResults(2);
916    
917                    QueryPos qPos = QueryPos.getInstance(q);
918    
919                    qPos.add(classNameId);
920    
921                    qPos.add(classPK);
922    
923                    if (orderByComparator != null) {
924                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityLimit);
925    
926                            for (Object value : values) {
927                                    qPos.add(value);
928                            }
929                    }
930    
931                    List<SocialActivityLimit> list = q.list();
932    
933                    if (list.size() == 2) {
934                            return list.get(1);
935                    }
936                    else {
937                            return null;
938                    }
939            }
940    
941            /**
942             * 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.
943             *
944             * @param groupId the group ID
945             * @param userId the user ID
946             * @param classNameId the class name ID
947             * @param classPK the class p k
948             * @param activityType the activity type
949             * @param activityCounterName the activity counter name
950             * @return the matching social activity limit
951             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
952             * @throws SystemException if a system exception occurred
953             */
954            public SocialActivityLimit findByG_U_C_C_A_A(long groupId, long userId,
955                    long classNameId, long classPK, int activityType,
956                    String activityCounterName)
957                    throws NoSuchActivityLimitException, SystemException {
958                    SocialActivityLimit socialActivityLimit = fetchByG_U_C_C_A_A(groupId,
959                                    userId, classNameId, classPK, activityType, activityCounterName);
960    
961                    if (socialActivityLimit == null) {
962                            StringBundler msg = new StringBundler(14);
963    
964                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
965    
966                            msg.append("groupId=");
967                            msg.append(groupId);
968    
969                            msg.append(", userId=");
970                            msg.append(userId);
971    
972                            msg.append(", classNameId=");
973                            msg.append(classNameId);
974    
975                            msg.append(", classPK=");
976                            msg.append(classPK);
977    
978                            msg.append(", activityType=");
979                            msg.append(activityType);
980    
981                            msg.append(", activityCounterName=");
982                            msg.append(activityCounterName);
983    
984                            msg.append(StringPool.CLOSE_CURLY_BRACE);
985    
986                            if (_log.isWarnEnabled()) {
987                                    _log.warn(msg.toString());
988                            }
989    
990                            throw new NoSuchActivityLimitException(msg.toString());
991                    }
992    
993                    return socialActivityLimit;
994            }
995    
996            /**
997             * 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.
998             *
999             * @param groupId the group ID
1000             * @param userId the user ID
1001             * @param classNameId the class name ID
1002             * @param classPK the class p k
1003             * @param activityType the activity type
1004             * @param activityCounterName the activity counter name
1005             * @return the matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
1006             * @throws SystemException if a system exception occurred
1007             */
1008            public SocialActivityLimit fetchByG_U_C_C_A_A(long groupId, long userId,
1009                    long classNameId, long classPK, int activityType,
1010                    String activityCounterName) throws SystemException {
1011                    return fetchByG_U_C_C_A_A(groupId, userId, classNameId, classPK,
1012                            activityType, activityCounterName, true);
1013            }
1014    
1015            /**
1016             * 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.
1017             *
1018             * @param groupId the group ID
1019             * @param userId the user ID
1020             * @param classNameId the class name ID
1021             * @param classPK the class p k
1022             * @param activityType the activity type
1023             * @param activityCounterName the activity counter name
1024             * @param retrieveFromCache whether to use the finder cache
1025             * @return the matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
1026             * @throws SystemException if a system exception occurred
1027             */
1028            public SocialActivityLimit fetchByG_U_C_C_A_A(long groupId, long userId,
1029                    long classNameId, long classPK, int activityType,
1030                    String activityCounterName, boolean retrieveFromCache)
1031                    throws SystemException {
1032                    Object[] finderArgs = new Object[] {
1033                                    groupId, userId, classNameId, classPK, activityType,
1034                                    activityCounterName
1035                            };
1036    
1037                    Object result = null;
1038    
1039                    if (retrieveFromCache) {
1040                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1041                                            finderArgs, this);
1042                    }
1043    
1044                    if (result instanceof SocialActivityLimit) {
1045                            SocialActivityLimit socialActivityLimit = (SocialActivityLimit)result;
1046    
1047                            if ((groupId != socialActivityLimit.getGroupId()) ||
1048                                            (userId != socialActivityLimit.getUserId()) ||
1049                                            (classNameId != socialActivityLimit.getClassNameId()) ||
1050                                            (classPK != socialActivityLimit.getClassPK()) ||
1051                                            (activityType != socialActivityLimit.getActivityType()) ||
1052                                            !Validator.equals(activityCounterName,
1053                                                    socialActivityLimit.getActivityCounterName())) {
1054                                    result = null;
1055                            }
1056                    }
1057    
1058                    if (result == null) {
1059                            StringBundler query = new StringBundler(7);
1060    
1061                            query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
1062    
1063                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2);
1064    
1065                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_USERID_2);
1066    
1067                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2);
1068    
1069                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2);
1070    
1071                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2);
1072    
1073                            if (activityCounterName == null) {
1074                                    query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1);
1075                            }
1076                            else {
1077                                    if (activityCounterName.equals(StringPool.BLANK)) {
1078                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3);
1079                                    }
1080                                    else {
1081                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2);
1082                                    }
1083                            }
1084    
1085                            String sql = query.toString();
1086    
1087                            Session session = null;
1088    
1089                            try {
1090                                    session = openSession();
1091    
1092                                    Query q = session.createQuery(sql);
1093    
1094                                    QueryPos qPos = QueryPos.getInstance(q);
1095    
1096                                    qPos.add(groupId);
1097    
1098                                    qPos.add(userId);
1099    
1100                                    qPos.add(classNameId);
1101    
1102                                    qPos.add(classPK);
1103    
1104                                    qPos.add(activityType);
1105    
1106                                    if (activityCounterName != null) {
1107                                            qPos.add(activityCounterName);
1108                                    }
1109    
1110                                    List<SocialActivityLimit> list = q.list();
1111    
1112                                    result = list;
1113    
1114                                    SocialActivityLimit socialActivityLimit = null;
1115    
1116                                    if (list.isEmpty()) {
1117                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1118                                                    finderArgs, list);
1119                                    }
1120                                    else {
1121                                            socialActivityLimit = list.get(0);
1122    
1123                                            cacheResult(socialActivityLimit);
1124    
1125                                            if ((socialActivityLimit.getGroupId() != groupId) ||
1126                                                            (socialActivityLimit.getUserId() != userId) ||
1127                                                            (socialActivityLimit.getClassNameId() != classNameId) ||
1128                                                            (socialActivityLimit.getClassPK() != classPK) ||
1129                                                            (socialActivityLimit.getActivityType() != activityType) ||
1130                                                            (socialActivityLimit.getActivityCounterName() == null) ||
1131                                                            !socialActivityLimit.getActivityCounterName()
1132                                                                                                            .equals(activityCounterName)) {
1133                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1134                                                            finderArgs, socialActivityLimit);
1135                                            }
1136                                    }
1137    
1138                                    return socialActivityLimit;
1139                            }
1140                            catch (Exception e) {
1141                                    throw processException(e);
1142                            }
1143                            finally {
1144                                    if (result == null) {
1145                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1146                                                    finderArgs);
1147                                    }
1148    
1149                                    closeSession(session);
1150                            }
1151                    }
1152                    else {
1153                            if (result instanceof List<?>) {
1154                                    return null;
1155                            }
1156                            else {
1157                                    return (SocialActivityLimit)result;
1158                            }
1159                    }
1160            }
1161    
1162            /**
1163             * Returns all the social activity limits.
1164             *
1165             * @return the social activity limits
1166             * @throws SystemException if a system exception occurred
1167             */
1168            public List<SocialActivityLimit> findAll() throws SystemException {
1169                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1170            }
1171    
1172            /**
1173             * Returns a range of all the social activity limits.
1174             *
1175             * <p>
1176             * 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.
1177             * </p>
1178             *
1179             * @param start the lower bound of the range of social activity limits
1180             * @param end the upper bound of the range of social activity limits (not inclusive)
1181             * @return the range of social activity limits
1182             * @throws SystemException if a system exception occurred
1183             */
1184            public List<SocialActivityLimit> findAll(int start, int end)
1185                    throws SystemException {
1186                    return findAll(start, end, null);
1187            }
1188    
1189            /**
1190             * Returns an ordered range of all the social activity limits.
1191             *
1192             * <p>
1193             * 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.
1194             * </p>
1195             *
1196             * @param start the lower bound of the range of social activity limits
1197             * @param end the upper bound of the range of social activity limits (not inclusive)
1198             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1199             * @return the ordered range of social activity limits
1200             * @throws SystemException if a system exception occurred
1201             */
1202            public List<SocialActivityLimit> findAll(int start, int end,
1203                    OrderByComparator orderByComparator) throws SystemException {
1204                    FinderPath finderPath = null;
1205                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1206    
1207                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1208                                    (orderByComparator == null)) {
1209                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1210                            finderArgs = FINDER_ARGS_EMPTY;
1211                    }
1212                    else {
1213                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1214                            finderArgs = new Object[] { start, end, orderByComparator };
1215                    }
1216    
1217                    List<SocialActivityLimit> list = (List<SocialActivityLimit>)FinderCacheUtil.getResult(finderPath,
1218                                    finderArgs, this);
1219    
1220                    if (list == null) {
1221                            StringBundler query = null;
1222                            String sql = null;
1223    
1224                            if (orderByComparator != null) {
1225                                    query = new StringBundler(2 +
1226                                                    (orderByComparator.getOrderByFields().length * 3));
1227    
1228                                    query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT);
1229    
1230                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1231                                            orderByComparator);
1232    
1233                                    sql = query.toString();
1234                            }
1235                            else {
1236                                    sql = _SQL_SELECT_SOCIALACTIVITYLIMIT;
1237                            }
1238    
1239                            Session session = null;
1240    
1241                            try {
1242                                    session = openSession();
1243    
1244                                    Query q = session.createQuery(sql);
1245    
1246                                    if (orderByComparator == null) {
1247                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
1248                                                            getDialect(), start, end, false);
1249    
1250                                            Collections.sort(list);
1251                                    }
1252                                    else {
1253                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
1254                                                            getDialect(), start, end);
1255                                    }
1256                            }
1257                            catch (Exception e) {
1258                                    throw processException(e);
1259                            }
1260                            finally {
1261                                    if (list == null) {
1262                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1263                                    }
1264                                    else {
1265                                            cacheResult(list);
1266    
1267                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1268                                    }
1269    
1270                                    closeSession(session);
1271                            }
1272                    }
1273    
1274                    return list;
1275            }
1276    
1277            /**
1278             * Removes all the social activity limits where classNameId = &#63; and classPK = &#63; from the database.
1279             *
1280             * @param classNameId the class name ID
1281             * @param classPK the class p k
1282             * @throws SystemException if a system exception occurred
1283             */
1284            public void removeByC_C(long classNameId, long classPK)
1285                    throws SystemException {
1286                    for (SocialActivityLimit socialActivityLimit : findByC_C(classNameId,
1287                                    classPK)) {
1288                            remove(socialActivityLimit);
1289                    }
1290            }
1291    
1292            /**
1293             * 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.
1294             *
1295             * @param groupId the group ID
1296             * @param userId the user ID
1297             * @param classNameId the class name ID
1298             * @param classPK the class p k
1299             * @param activityType the activity type
1300             * @param activityCounterName the activity counter name
1301             * @throws SystemException if a system exception occurred
1302             */
1303            public void removeByG_U_C_C_A_A(long groupId, long userId,
1304                    long classNameId, long classPK, int activityType,
1305                    String activityCounterName)
1306                    throws NoSuchActivityLimitException, SystemException {
1307                    SocialActivityLimit socialActivityLimit = findByG_U_C_C_A_A(groupId,
1308                                    userId, classNameId, classPK, activityType, activityCounterName);
1309    
1310                    remove(socialActivityLimit);
1311            }
1312    
1313            /**
1314             * Removes all the social activity limits from the database.
1315             *
1316             * @throws SystemException if a system exception occurred
1317             */
1318            public void removeAll() throws SystemException {
1319                    for (SocialActivityLimit socialActivityLimit : findAll()) {
1320                            remove(socialActivityLimit);
1321                    }
1322            }
1323    
1324            /**
1325             * Returns the number of social activity limits where classNameId = &#63; and classPK = &#63;.
1326             *
1327             * @param classNameId the class name ID
1328             * @param classPK the class p k
1329             * @return the number of matching social activity limits
1330             * @throws SystemException if a system exception occurred
1331             */
1332            public int countByC_C(long classNameId, long classPK)
1333                    throws SystemException {
1334                    Object[] finderArgs = new Object[] { classNameId, classPK };
1335    
1336                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1337                                    finderArgs, this);
1338    
1339                    if (count == null) {
1340                            StringBundler query = new StringBundler(3);
1341    
1342                            query.append(_SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE);
1343    
1344                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1345    
1346                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1347    
1348                            String sql = query.toString();
1349    
1350                            Session session = null;
1351    
1352                            try {
1353                                    session = openSession();
1354    
1355                                    Query q = session.createQuery(sql);
1356    
1357                                    QueryPos qPos = QueryPos.getInstance(q);
1358    
1359                                    qPos.add(classNameId);
1360    
1361                                    qPos.add(classPK);
1362    
1363                                    count = (Long)q.uniqueResult();
1364                            }
1365                            catch (Exception e) {
1366                                    throw processException(e);
1367                            }
1368                            finally {
1369                                    if (count == null) {
1370                                            count = Long.valueOf(0);
1371                                    }
1372    
1373                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1374                                            count);
1375    
1376                                    closeSession(session);
1377                            }
1378                    }
1379    
1380                    return count.intValue();
1381            }
1382    
1383            /**
1384             * 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;.
1385             *
1386             * @param groupId the group ID
1387             * @param userId the user ID
1388             * @param classNameId the class name ID
1389             * @param classPK the class p k
1390             * @param activityType the activity type
1391             * @param activityCounterName the activity counter name
1392             * @return the number of matching social activity limits
1393             * @throws SystemException if a system exception occurred
1394             */
1395            public int countByG_U_C_C_A_A(long groupId, long userId, long classNameId,
1396                    long classPK, int activityType, String activityCounterName)
1397                    throws SystemException {
1398                    Object[] finderArgs = new Object[] {
1399                                    groupId, userId, classNameId, classPK, activityType,
1400                                    activityCounterName
1401                            };
1402    
1403                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A,
1404                                    finderArgs, this);
1405    
1406                    if (count == null) {
1407                            StringBundler query = new StringBundler(7);
1408    
1409                            query.append(_SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE);
1410    
1411                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2);
1412    
1413                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_USERID_2);
1414    
1415                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2);
1416    
1417                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2);
1418    
1419                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2);
1420    
1421                            if (activityCounterName == null) {
1422                                    query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1);
1423                            }
1424                            else {
1425                                    if (activityCounterName.equals(StringPool.BLANK)) {
1426                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3);
1427                                    }
1428                                    else {
1429                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2);
1430                                    }
1431                            }
1432    
1433                            String sql = query.toString();
1434    
1435                            Session session = null;
1436    
1437                            try {
1438                                    session = openSession();
1439    
1440                                    Query q = session.createQuery(sql);
1441    
1442                                    QueryPos qPos = QueryPos.getInstance(q);
1443    
1444                                    qPos.add(groupId);
1445    
1446                                    qPos.add(userId);
1447    
1448                                    qPos.add(classNameId);
1449    
1450                                    qPos.add(classPK);
1451    
1452                                    qPos.add(activityType);
1453    
1454                                    if (activityCounterName != null) {
1455                                            qPos.add(activityCounterName);
1456                                    }
1457    
1458                                    count = (Long)q.uniqueResult();
1459                            }
1460                            catch (Exception e) {
1461                                    throw processException(e);
1462                            }
1463                            finally {
1464                                    if (count == null) {
1465                                            count = Long.valueOf(0);
1466                                    }
1467    
1468                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A,
1469                                            finderArgs, count);
1470    
1471                                    closeSession(session);
1472                            }
1473                    }
1474    
1475                    return count.intValue();
1476            }
1477    
1478            /**
1479             * Returns the number of social activity limits.
1480             *
1481             * @return the number of social activity limits
1482             * @throws SystemException if a system exception occurred
1483             */
1484            public int countAll() throws SystemException {
1485                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1486                                    FINDER_ARGS_EMPTY, this);
1487    
1488                    if (count == null) {
1489                            Session session = null;
1490    
1491                            try {
1492                                    session = openSession();
1493    
1494                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYLIMIT);
1495    
1496                                    count = (Long)q.uniqueResult();
1497                            }
1498                            catch (Exception e) {
1499                                    throw processException(e);
1500                            }
1501                            finally {
1502                                    if (count == null) {
1503                                            count = Long.valueOf(0);
1504                                    }
1505    
1506                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1507                                            FINDER_ARGS_EMPTY, count);
1508    
1509                                    closeSession(session);
1510                            }
1511                    }
1512    
1513                    return count.intValue();
1514            }
1515    
1516            /**
1517             * Initializes the social activity limit persistence.
1518             */
1519            public void afterPropertiesSet() {
1520                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1521                                            com.liferay.portal.util.PropsUtil.get(
1522                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivityLimit")));
1523    
1524                    if (listenerClassNames.length > 0) {
1525                            try {
1526                                    List<ModelListener<SocialActivityLimit>> listenersList = new ArrayList<ModelListener<SocialActivityLimit>>();
1527    
1528                                    for (String listenerClassName : listenerClassNames) {
1529                                            listenersList.add((ModelListener<SocialActivityLimit>)InstanceFactory.newInstance(
1530                                                            listenerClassName));
1531                                    }
1532    
1533                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1534                            }
1535                            catch (Exception e) {
1536                                    _log.error(e);
1537                            }
1538                    }
1539            }
1540    
1541            public void destroy() {
1542                    EntityCacheUtil.removeCache(SocialActivityLimitImpl.class.getName());
1543                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1544                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1545            }
1546    
1547            @BeanReference(type = SocialActivityPersistence.class)
1548            protected SocialActivityPersistence socialActivityPersistence;
1549            @BeanReference(type = SocialActivityAchievementPersistence.class)
1550            protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
1551            @BeanReference(type = SocialActivityCounterPersistence.class)
1552            protected SocialActivityCounterPersistence socialActivityCounterPersistence;
1553            @BeanReference(type = SocialActivityLimitPersistence.class)
1554            protected SocialActivityLimitPersistence socialActivityLimitPersistence;
1555            @BeanReference(type = SocialActivitySettingPersistence.class)
1556            protected SocialActivitySettingPersistence socialActivitySettingPersistence;
1557            @BeanReference(type = SocialRelationPersistence.class)
1558            protected SocialRelationPersistence socialRelationPersistence;
1559            @BeanReference(type = SocialRequestPersistence.class)
1560            protected SocialRequestPersistence socialRequestPersistence;
1561            @BeanReference(type = GroupPersistence.class)
1562            protected GroupPersistence groupPersistence;
1563            @BeanReference(type = ResourcePersistence.class)
1564            protected ResourcePersistence resourcePersistence;
1565            @BeanReference(type = UserPersistence.class)
1566            protected UserPersistence userPersistence;
1567            private static final String _SQL_SELECT_SOCIALACTIVITYLIMIT = "SELECT socialActivityLimit FROM SocialActivityLimit socialActivityLimit";
1568            private static final String _SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE = "SELECT socialActivityLimit FROM SocialActivityLimit socialActivityLimit WHERE ";
1569            private static final String _SQL_COUNT_SOCIALACTIVITYLIMIT = "SELECT COUNT(socialActivityLimit) FROM SocialActivityLimit socialActivityLimit";
1570            private static final String _SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE = "SELECT COUNT(socialActivityLimit) FROM SocialActivityLimit socialActivityLimit WHERE ";
1571            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "socialActivityLimit.classNameId = ? AND ";
1572            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "socialActivityLimit.classPK = ?";
1573            private static final String _FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2 = "socialActivityLimit.groupId = ? AND ";
1574            private static final String _FINDER_COLUMN_G_U_C_C_A_A_USERID_2 = "socialActivityLimit.userId = ? AND ";
1575            private static final String _FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2 = "socialActivityLimit.classNameId = ? AND ";
1576            private static final String _FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2 = "socialActivityLimit.classPK = ? AND ";
1577            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2 = "socialActivityLimit.activityType = ? AND ";
1578            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1 =
1579                    "socialActivityLimit.activityCounterName IS NULL";
1580            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2 =
1581                    "socialActivityLimit.activityCounterName = ?";
1582            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3 =
1583                    "(socialActivityLimit.activityCounterName IS NULL OR socialActivityLimit.activityCounterName = ?)";
1584            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivityLimit.";
1585            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivityLimit exists with the primary key ";
1586            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivityLimit exists with the key {";
1587            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1588            private static Log _log = LogFactoryUtil.getLog(SocialActivityLimitPersistenceImpl.class);
1589            private static SocialActivityLimit _nullSocialActivityLimit = new SocialActivityLimitImpl() {
1590                            @Override
1591                            public Object clone() {
1592                                    return this;
1593                            }
1594    
1595                            @Override
1596                            public CacheModel<SocialActivityLimit> toCacheModel() {
1597                                    return _nullSocialActivityLimitCacheModel;
1598                            }
1599                    };
1600    
1601            private static CacheModel<SocialActivityLimit> _nullSocialActivityLimitCacheModel =
1602                    new CacheModel<SocialActivityLimit>() {
1603                            public SocialActivityLimit toEntityModel() {
1604                                    return _nullSocialActivityLimit;
1605                            }
1606                    };
1607    }