001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.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    
370                    else {
371                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
372                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
373                                    Object[] args = new Object[] {
374                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalClassNameId()),
375                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalClassPK())
376                                            };
377    
378                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
379                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
380                                            args);
381    
382                                    args = new Object[] {
383                                                    Long.valueOf(socialActivityLimitModelImpl.getClassNameId()),
384                                                    Long.valueOf(socialActivityLimitModelImpl.getClassPK())
385                                            };
386    
387                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
388                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
389                                            args);
390                            }
391                    }
392    
393                    EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
394                            SocialActivityLimitImpl.class, socialActivityLimit.getPrimaryKey(),
395                            socialActivityLimit);
396    
397                    if (isNew) {
398                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
399                                    new Object[] {
400                                            Long.valueOf(socialActivityLimit.getGroupId()),
401                                            Long.valueOf(socialActivityLimit.getUserId()),
402                                            Long.valueOf(socialActivityLimit.getClassNameId()),
403                                            Long.valueOf(socialActivityLimit.getClassPK()),
404                                            Integer.valueOf(socialActivityLimit.getActivityType()),
405                                            
406                                    socialActivityLimit.getActivityCounterName()
407                                    }, socialActivityLimit);
408                    }
409                    else {
410                            if ((socialActivityLimitModelImpl.getColumnBitmask() &
411                                            FINDER_PATH_FETCH_BY_G_U_C_C_A_A.getColumnBitmask()) != 0) {
412                                    Object[] args = new Object[] {
413                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalGroupId()),
414                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalUserId()),
415                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalClassNameId()),
416                                                    Long.valueOf(socialActivityLimitModelImpl.getOriginalClassPK()),
417                                                    Integer.valueOf(socialActivityLimitModelImpl.getOriginalActivityType()),
418                                                    
419                                                    socialActivityLimitModelImpl.getOriginalActivityCounterName()
420                                            };
421    
422                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A,
423                                            args);
424    
425                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
426                                            args);
427    
428                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
429                                            new Object[] {
430                                                    Long.valueOf(socialActivityLimit.getGroupId()),
431                                                    Long.valueOf(socialActivityLimit.getUserId()),
432                                                    Long.valueOf(socialActivityLimit.getClassNameId()),
433                                                    Long.valueOf(socialActivityLimit.getClassPK()),
434                                                    Integer.valueOf(socialActivityLimit.getActivityType()),
435                                                    
436                                            socialActivityLimit.getActivityCounterName()
437                                            }, socialActivityLimit);
438                            }
439                    }
440    
441                    return socialActivityLimit;
442            }
443    
444            protected SocialActivityLimit toUnwrappedModel(
445                    SocialActivityLimit socialActivityLimit) {
446                    if (socialActivityLimit instanceof SocialActivityLimitImpl) {
447                            return socialActivityLimit;
448                    }
449    
450                    SocialActivityLimitImpl socialActivityLimitImpl = new SocialActivityLimitImpl();
451    
452                    socialActivityLimitImpl.setNew(socialActivityLimit.isNew());
453                    socialActivityLimitImpl.setPrimaryKey(socialActivityLimit.getPrimaryKey());
454    
455                    socialActivityLimitImpl.setActivityLimitId(socialActivityLimit.getActivityLimitId());
456                    socialActivityLimitImpl.setGroupId(socialActivityLimit.getGroupId());
457                    socialActivityLimitImpl.setCompanyId(socialActivityLimit.getCompanyId());
458                    socialActivityLimitImpl.setUserId(socialActivityLimit.getUserId());
459                    socialActivityLimitImpl.setClassNameId(socialActivityLimit.getClassNameId());
460                    socialActivityLimitImpl.setClassPK(socialActivityLimit.getClassPK());
461                    socialActivityLimitImpl.setActivityType(socialActivityLimit.getActivityType());
462                    socialActivityLimitImpl.setActivityCounterName(socialActivityLimit.getActivityCounterName());
463                    socialActivityLimitImpl.setValue(socialActivityLimit.getValue());
464    
465                    return socialActivityLimitImpl;
466            }
467    
468            /**
469             * Returns the social activity limit with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
470             *
471             * @param primaryKey the primary key of the social activity limit
472             * @return the social activity limit
473             * @throws com.liferay.portal.NoSuchModelException if a social activity limit with the primary key could not be found
474             * @throws SystemException if a system exception occurred
475             */
476            @Override
477            public SocialActivityLimit findByPrimaryKey(Serializable primaryKey)
478                    throws NoSuchModelException, SystemException {
479                    return findByPrimaryKey(((Long)primaryKey).longValue());
480            }
481    
482            /**
483             * Returns the social activity limit with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivityLimitException} if it could not be found.
484             *
485             * @param activityLimitId the primary key of the social activity limit
486             * @return the social activity limit
487             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
488             * @throws SystemException if a system exception occurred
489             */
490            public SocialActivityLimit findByPrimaryKey(long activityLimitId)
491                    throws NoSuchActivityLimitException, SystemException {
492                    SocialActivityLimit socialActivityLimit = fetchByPrimaryKey(activityLimitId);
493    
494                    if (socialActivityLimit == null) {
495                            if (_log.isWarnEnabled()) {
496                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + activityLimitId);
497                            }
498    
499                            throw new NoSuchActivityLimitException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
500                                    activityLimitId);
501                    }
502    
503                    return socialActivityLimit;
504            }
505    
506            /**
507             * Returns the social activity limit with the primary key or returns <code>null</code> if it could not be found.
508             *
509             * @param primaryKey the primary key of the social activity limit
510             * @return the social activity limit, or <code>null</code> if a social activity limit with the primary key could not be found
511             * @throws SystemException if a system exception occurred
512             */
513            @Override
514            public SocialActivityLimit fetchByPrimaryKey(Serializable primaryKey)
515                    throws SystemException {
516                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
517            }
518    
519            /**
520             * Returns the social activity limit with the primary key or returns <code>null</code> if it could not be found.
521             *
522             * @param activityLimitId the primary key of the social activity limit
523             * @return the social activity limit, or <code>null</code> if a social activity limit with the primary key could not be found
524             * @throws SystemException if a system exception occurred
525             */
526            public SocialActivityLimit fetchByPrimaryKey(long activityLimitId)
527                    throws SystemException {
528                    SocialActivityLimit socialActivityLimit = (SocialActivityLimit)EntityCacheUtil.getResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
529                                    SocialActivityLimitImpl.class, activityLimitId);
530    
531                    if (socialActivityLimit == _nullSocialActivityLimit) {
532                            return null;
533                    }
534    
535                    if (socialActivityLimit == null) {
536                            Session session = null;
537    
538                            boolean hasException = false;
539    
540                            try {
541                                    session = openSession();
542    
543                                    socialActivityLimit = (SocialActivityLimit)session.get(SocialActivityLimitImpl.class,
544                                                    Long.valueOf(activityLimitId));
545                            }
546                            catch (Exception e) {
547                                    hasException = true;
548    
549                                    throw processException(e);
550                            }
551                            finally {
552                                    if (socialActivityLimit != null) {
553                                            cacheResult(socialActivityLimit);
554                                    }
555                                    else if (!hasException) {
556                                            EntityCacheUtil.putResult(SocialActivityLimitModelImpl.ENTITY_CACHE_ENABLED,
557                                                    SocialActivityLimitImpl.class, activityLimitId,
558                                                    _nullSocialActivityLimit);
559                                    }
560    
561                                    closeSession(session);
562                            }
563                    }
564    
565                    return socialActivityLimit;
566            }
567    
568            /**
569             * Returns all the social activity limits where classNameId = &#63; and classPK = &#63;.
570             *
571             * @param classNameId the class name ID
572             * @param classPK the class p k
573             * @return the matching social activity limits
574             * @throws SystemException if a system exception occurred
575             */
576            public List<SocialActivityLimit> findByC_C(long classNameId, long classPK)
577                    throws SystemException {
578                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
579                            QueryUtil.ALL_POS, null);
580            }
581    
582            /**
583             * Returns a range of all the social activity limits where classNameId = &#63; and classPK = &#63;.
584             *
585             * <p>
586             * 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.
587             * </p>
588             *
589             * @param classNameId the class name ID
590             * @param classPK the class p k
591             * @param start the lower bound of the range of social activity limits
592             * @param end the upper bound of the range of social activity limits (not inclusive)
593             * @return the range of matching social activity limits
594             * @throws SystemException if a system exception occurred
595             */
596            public List<SocialActivityLimit> findByC_C(long classNameId, long classPK,
597                    int start, int end) throws SystemException {
598                    return findByC_C(classNameId, classPK, start, end, null);
599            }
600    
601            /**
602             * Returns an ordered range of all the social activity limits where classNameId = &#63; and classPK = &#63;.
603             *
604             * <p>
605             * 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.
606             * </p>
607             *
608             * @param classNameId the class name ID
609             * @param classPK the class p k
610             * @param start the lower bound of the range of social activity limits
611             * @param end the upper bound of the range of social activity limits (not inclusive)
612             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
613             * @return the ordered range of matching social activity limits
614             * @throws SystemException if a system exception occurred
615             */
616            public List<SocialActivityLimit> findByC_C(long classNameId, long classPK,
617                    int start, int end, OrderByComparator orderByComparator)
618                    throws SystemException {
619                    FinderPath finderPath = null;
620                    Object[] finderArgs = null;
621    
622                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
623                                    (orderByComparator == null)) {
624                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
625                            finderArgs = new Object[] { classNameId, classPK };
626                    }
627                    else {
628                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
629                            finderArgs = new Object[] {
630                                            classNameId, classPK,
631                                            
632                                            start, end, orderByComparator
633                                    };
634                    }
635    
636                    List<SocialActivityLimit> list = (List<SocialActivityLimit>)FinderCacheUtil.getResult(finderPath,
637                                    finderArgs, this);
638    
639                    if ((list != null) && !list.isEmpty()) {
640                            for (SocialActivityLimit socialActivityLimit : list) {
641                                    if ((classNameId != socialActivityLimit.getClassNameId()) ||
642                                                    (classPK != socialActivityLimit.getClassPK())) {
643                                            list = null;
644    
645                                            break;
646                                    }
647                            }
648                    }
649    
650                    if (list == null) {
651                            StringBundler query = null;
652    
653                            if (orderByComparator != null) {
654                                    query = new StringBundler(4 +
655                                                    (orderByComparator.getOrderByFields().length * 3));
656                            }
657                            else {
658                                    query = new StringBundler(3);
659                            }
660    
661                            query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
662    
663                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
664    
665                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
666    
667                            if (orderByComparator != null) {
668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
669                                            orderByComparator);
670                            }
671    
672                            String sql = query.toString();
673    
674                            Session session = null;
675    
676                            try {
677                                    session = openSession();
678    
679                                    Query q = session.createQuery(sql);
680    
681                                    QueryPos qPos = QueryPos.getInstance(q);
682    
683                                    qPos.add(classNameId);
684    
685                                    qPos.add(classPK);
686    
687                                    list = (List<SocialActivityLimit>)QueryUtil.list(q,
688                                                    getDialect(), start, end);
689                            }
690                            catch (Exception e) {
691                                    throw processException(e);
692                            }
693                            finally {
694                                    if (list == null) {
695                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
696                                    }
697                                    else {
698                                            cacheResult(list);
699    
700                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
701                                    }
702    
703                                    closeSession(session);
704                            }
705                    }
706    
707                    return list;
708            }
709    
710            /**
711             * Returns the first social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
712             *
713             * @param classNameId the class name ID
714             * @param classPK the class p k
715             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
716             * @return the first matching social activity limit
717             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
718             * @throws SystemException if a system exception occurred
719             */
720            public SocialActivityLimit findByC_C_First(long classNameId, long classPK,
721                    OrderByComparator orderByComparator)
722                    throws NoSuchActivityLimitException, SystemException {
723                    SocialActivityLimit socialActivityLimit = fetchByC_C_First(classNameId,
724                                    classPK, orderByComparator);
725    
726                    if (socialActivityLimit != null) {
727                            return socialActivityLimit;
728                    }
729    
730                    StringBundler msg = new StringBundler(6);
731    
732                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
733    
734                    msg.append("classNameId=");
735                    msg.append(classNameId);
736    
737                    msg.append(", classPK=");
738                    msg.append(classPK);
739    
740                    msg.append(StringPool.CLOSE_CURLY_BRACE);
741    
742                    throw new NoSuchActivityLimitException(msg.toString());
743            }
744    
745            /**
746             * Returns the first social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
747             *
748             * @param classNameId the class name ID
749             * @param classPK the class p k
750             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
751             * @return the first matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
752             * @throws SystemException if a system exception occurred
753             */
754            public SocialActivityLimit fetchByC_C_First(long classNameId, long classPK,
755                    OrderByComparator orderByComparator) throws SystemException {
756                    List<SocialActivityLimit> list = findByC_C(classNameId, classPK, 0, 1,
757                                    orderByComparator);
758    
759                    if (!list.isEmpty()) {
760                            return list.get(0);
761                    }
762    
763                    return null;
764            }
765    
766            /**
767             * Returns the last social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
768             *
769             * @param classNameId the class name ID
770             * @param classPK the class p k
771             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
772             * @return the last matching social activity limit
773             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
774             * @throws SystemException if a system exception occurred
775             */
776            public SocialActivityLimit findByC_C_Last(long classNameId, long classPK,
777                    OrderByComparator orderByComparator)
778                    throws NoSuchActivityLimitException, SystemException {
779                    SocialActivityLimit socialActivityLimit = fetchByC_C_Last(classNameId,
780                                    classPK, orderByComparator);
781    
782                    if (socialActivityLimit != null) {
783                            return socialActivityLimit;
784                    }
785    
786                    StringBundler msg = new StringBundler(6);
787    
788                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
789    
790                    msg.append("classNameId=");
791                    msg.append(classNameId);
792    
793                    msg.append(", classPK=");
794                    msg.append(classPK);
795    
796                    msg.append(StringPool.CLOSE_CURLY_BRACE);
797    
798                    throw new NoSuchActivityLimitException(msg.toString());
799            }
800    
801            /**
802             * Returns the last social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
803             *
804             * @param classNameId the class name ID
805             * @param classPK the class p k
806             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
807             * @return the last matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
808             * @throws SystemException if a system exception occurred
809             */
810            public SocialActivityLimit fetchByC_C_Last(long classNameId, long classPK,
811                    OrderByComparator orderByComparator) throws SystemException {
812                    int count = countByC_C(classNameId, classPK);
813    
814                    List<SocialActivityLimit> list = findByC_C(classNameId, classPK,
815                                    count - 1, count, orderByComparator);
816    
817                    if (!list.isEmpty()) {
818                            return list.get(0);
819                    }
820    
821                    return null;
822            }
823    
824            /**
825             * Returns the social activity limits before and after the current social activity limit in the ordered set where classNameId = &#63; and classPK = &#63;.
826             *
827             * @param activityLimitId the primary key of the current social activity limit
828             * @param classNameId the class name ID
829             * @param classPK the class p k
830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
831             * @return the previous, current, and next social activity limit
832             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a social activity limit with the primary key could not be found
833             * @throws SystemException if a system exception occurred
834             */
835            public SocialActivityLimit[] findByC_C_PrevAndNext(long activityLimitId,
836                    long classNameId, long classPK, OrderByComparator orderByComparator)
837                    throws NoSuchActivityLimitException, SystemException {
838                    SocialActivityLimit socialActivityLimit = findByPrimaryKey(activityLimitId);
839    
840                    Session session = null;
841    
842                    try {
843                            session = openSession();
844    
845                            SocialActivityLimit[] array = new SocialActivityLimitImpl[3];
846    
847                            array[0] = getByC_C_PrevAndNext(session, socialActivityLimit,
848                                            classNameId, classPK, orderByComparator, true);
849    
850                            array[1] = socialActivityLimit;
851    
852                            array[2] = getByC_C_PrevAndNext(session, socialActivityLimit,
853                                            classNameId, classPK, orderByComparator, false);
854    
855                            return array;
856                    }
857                    catch (Exception e) {
858                            throw processException(e);
859                    }
860                    finally {
861                            closeSession(session);
862                    }
863            }
864    
865            protected SocialActivityLimit getByC_C_PrevAndNext(Session session,
866                    SocialActivityLimit socialActivityLimit, long classNameId,
867                    long classPK, OrderByComparator orderByComparator, boolean previous) {
868                    StringBundler query = null;
869    
870                    if (orderByComparator != null) {
871                            query = new StringBundler(6 +
872                                            (orderByComparator.getOrderByFields().length * 6));
873                    }
874                    else {
875                            query = new StringBundler(3);
876                    }
877    
878                    query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
879    
880                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
881    
882                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
883    
884                    if (orderByComparator != null) {
885                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
886    
887                            if (orderByConditionFields.length > 0) {
888                                    query.append(WHERE_AND);
889                            }
890    
891                            for (int i = 0; i < orderByConditionFields.length; i++) {
892                                    query.append(_ORDER_BY_ENTITY_ALIAS);
893                                    query.append(orderByConditionFields[i]);
894    
895                                    if ((i + 1) < orderByConditionFields.length) {
896                                            if (orderByComparator.isAscending() ^ previous) {
897                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
898                                            }
899                                            else {
900                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
901                                            }
902                                    }
903                                    else {
904                                            if (orderByComparator.isAscending() ^ previous) {
905                                                    query.append(WHERE_GREATER_THAN);
906                                            }
907                                            else {
908                                                    query.append(WHERE_LESSER_THAN);
909                                            }
910                                    }
911                            }
912    
913                            query.append(ORDER_BY_CLAUSE);
914    
915                            String[] orderByFields = orderByComparator.getOrderByFields();
916    
917                            for (int i = 0; i < orderByFields.length; i++) {
918                                    query.append(_ORDER_BY_ENTITY_ALIAS);
919                                    query.append(orderByFields[i]);
920    
921                                    if ((i + 1) < orderByFields.length) {
922                                            if (orderByComparator.isAscending() ^ previous) {
923                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
924                                            }
925                                            else {
926                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
927                                            }
928                                    }
929                                    else {
930                                            if (orderByComparator.isAscending() ^ previous) {
931                                                    query.append(ORDER_BY_ASC);
932                                            }
933                                            else {
934                                                    query.append(ORDER_BY_DESC);
935                                            }
936                                    }
937                            }
938                    }
939    
940                    String sql = query.toString();
941    
942                    Query q = session.createQuery(sql);
943    
944                    q.setFirstResult(0);
945                    q.setMaxResults(2);
946    
947                    QueryPos qPos = QueryPos.getInstance(q);
948    
949                    qPos.add(classNameId);
950    
951                    qPos.add(classPK);
952    
953                    if (orderByComparator != null) {
954                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityLimit);
955    
956                            for (Object value : values) {
957                                    qPos.add(value);
958                            }
959                    }
960    
961                    List<SocialActivityLimit> list = q.list();
962    
963                    if (list.size() == 2) {
964                            return list.get(1);
965                    }
966                    else {
967                            return null;
968                    }
969            }
970    
971            /**
972             * 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.
973             *
974             * @param groupId the group ID
975             * @param userId the user ID
976             * @param classNameId the class name ID
977             * @param classPK the class p k
978             * @param activityType the activity type
979             * @param activityCounterName the activity counter name
980             * @return the matching social activity limit
981             * @throws com.liferay.portlet.social.NoSuchActivityLimitException if a matching social activity limit could not be found
982             * @throws SystemException if a system exception occurred
983             */
984            public SocialActivityLimit findByG_U_C_C_A_A(long groupId, long userId,
985                    long classNameId, long classPK, int activityType,
986                    String activityCounterName)
987                    throws NoSuchActivityLimitException, SystemException {
988                    SocialActivityLimit socialActivityLimit = fetchByG_U_C_C_A_A(groupId,
989                                    userId, classNameId, classPK, activityType, activityCounterName);
990    
991                    if (socialActivityLimit == null) {
992                            StringBundler msg = new StringBundler(14);
993    
994                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
995    
996                            msg.append("groupId=");
997                            msg.append(groupId);
998    
999                            msg.append(", userId=");
1000                            msg.append(userId);
1001    
1002                            msg.append(", classNameId=");
1003                            msg.append(classNameId);
1004    
1005                            msg.append(", classPK=");
1006                            msg.append(classPK);
1007    
1008                            msg.append(", activityType=");
1009                            msg.append(activityType);
1010    
1011                            msg.append(", activityCounterName=");
1012                            msg.append(activityCounterName);
1013    
1014                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1015    
1016                            if (_log.isWarnEnabled()) {
1017                                    _log.warn(msg.toString());
1018                            }
1019    
1020                            throw new NoSuchActivityLimitException(msg.toString());
1021                    }
1022    
1023                    return socialActivityLimit;
1024            }
1025    
1026            /**
1027             * 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.
1028             *
1029             * @param groupId the group ID
1030             * @param userId the user ID
1031             * @param classNameId the class name ID
1032             * @param classPK the class p k
1033             * @param activityType the activity type
1034             * @param activityCounterName the activity counter name
1035             * @return the matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
1036             * @throws SystemException if a system exception occurred
1037             */
1038            public SocialActivityLimit fetchByG_U_C_C_A_A(long groupId, long userId,
1039                    long classNameId, long classPK, int activityType,
1040                    String activityCounterName) throws SystemException {
1041                    return fetchByG_U_C_C_A_A(groupId, userId, classNameId, classPK,
1042                            activityType, activityCounterName, true);
1043            }
1044    
1045            /**
1046             * 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.
1047             *
1048             * @param groupId the group ID
1049             * @param userId the user ID
1050             * @param classNameId the class name ID
1051             * @param classPK the class p k
1052             * @param activityType the activity type
1053             * @param activityCounterName the activity counter name
1054             * @param retrieveFromCache whether to use the finder cache
1055             * @return the matching social activity limit, or <code>null</code> if a matching social activity limit could not be found
1056             * @throws SystemException if a system exception occurred
1057             */
1058            public SocialActivityLimit fetchByG_U_C_C_A_A(long groupId, long userId,
1059                    long classNameId, long classPK, int activityType,
1060                    String activityCounterName, boolean retrieveFromCache)
1061                    throws SystemException {
1062                    Object[] finderArgs = new Object[] {
1063                                    groupId, userId, classNameId, classPK, activityType,
1064                                    activityCounterName
1065                            };
1066    
1067                    Object result = null;
1068    
1069                    if (retrieveFromCache) {
1070                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1071                                            finderArgs, this);
1072                    }
1073    
1074                    if (result instanceof SocialActivityLimit) {
1075                            SocialActivityLimit socialActivityLimit = (SocialActivityLimit)result;
1076    
1077                            if ((groupId != socialActivityLimit.getGroupId()) ||
1078                                            (userId != socialActivityLimit.getUserId()) ||
1079                                            (classNameId != socialActivityLimit.getClassNameId()) ||
1080                                            (classPK != socialActivityLimit.getClassPK()) ||
1081                                            (activityType != socialActivityLimit.getActivityType()) ||
1082                                            !Validator.equals(activityCounterName,
1083                                                    socialActivityLimit.getActivityCounterName())) {
1084                                    result = null;
1085                            }
1086                    }
1087    
1088                    if (result == null) {
1089                            StringBundler query = new StringBundler(7);
1090    
1091                            query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE);
1092    
1093                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2);
1094    
1095                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_USERID_2);
1096    
1097                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2);
1098    
1099                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2);
1100    
1101                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2);
1102    
1103                            if (activityCounterName == null) {
1104                                    query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1);
1105                            }
1106                            else {
1107                                    if (activityCounterName.equals(StringPool.BLANK)) {
1108                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3);
1109                                    }
1110                                    else {
1111                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2);
1112                                    }
1113                            }
1114    
1115                            String sql = query.toString();
1116    
1117                            Session session = null;
1118    
1119                            try {
1120                                    session = openSession();
1121    
1122                                    Query q = session.createQuery(sql);
1123    
1124                                    QueryPos qPos = QueryPos.getInstance(q);
1125    
1126                                    qPos.add(groupId);
1127    
1128                                    qPos.add(userId);
1129    
1130                                    qPos.add(classNameId);
1131    
1132                                    qPos.add(classPK);
1133    
1134                                    qPos.add(activityType);
1135    
1136                                    if (activityCounterName != null) {
1137                                            qPos.add(activityCounterName);
1138                                    }
1139    
1140                                    List<SocialActivityLimit> list = q.list();
1141    
1142                                    result = list;
1143    
1144                                    SocialActivityLimit socialActivityLimit = null;
1145    
1146                                    if (list.isEmpty()) {
1147                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1148                                                    finderArgs, list);
1149                                    }
1150                                    else {
1151                                            socialActivityLimit = list.get(0);
1152    
1153                                            cacheResult(socialActivityLimit);
1154    
1155                                            if ((socialActivityLimit.getGroupId() != groupId) ||
1156                                                            (socialActivityLimit.getUserId() != userId) ||
1157                                                            (socialActivityLimit.getClassNameId() != classNameId) ||
1158                                                            (socialActivityLimit.getClassPK() != classPK) ||
1159                                                            (socialActivityLimit.getActivityType() != activityType) ||
1160                                                            (socialActivityLimit.getActivityCounterName() == null) ||
1161                                                            !socialActivityLimit.getActivityCounterName()
1162                                                                                                            .equals(activityCounterName)) {
1163                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1164                                                            finderArgs, socialActivityLimit);
1165                                            }
1166                                    }
1167    
1168                                    return socialActivityLimit;
1169                            }
1170                            catch (Exception e) {
1171                                    throw processException(e);
1172                            }
1173                            finally {
1174                                    if (result == null) {
1175                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_C_C_A_A,
1176                                                    finderArgs);
1177                                    }
1178    
1179                                    closeSession(session);
1180                            }
1181                    }
1182                    else {
1183                            if (result instanceof List<?>) {
1184                                    return null;
1185                            }
1186                            else {
1187                                    return (SocialActivityLimit)result;
1188                            }
1189                    }
1190            }
1191    
1192            /**
1193             * Returns all the social activity limits.
1194             *
1195             * @return the social activity limits
1196             * @throws SystemException if a system exception occurred
1197             */
1198            public List<SocialActivityLimit> findAll() throws SystemException {
1199                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1200            }
1201    
1202            /**
1203             * Returns a range of all the social activity limits.
1204             *
1205             * <p>
1206             * 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.
1207             * </p>
1208             *
1209             * @param start the lower bound of the range of social activity limits
1210             * @param end the upper bound of the range of social activity limits (not inclusive)
1211             * @return the range of social activity limits
1212             * @throws SystemException if a system exception occurred
1213             */
1214            public List<SocialActivityLimit> findAll(int start, int end)
1215                    throws SystemException {
1216                    return findAll(start, end, null);
1217            }
1218    
1219            /**
1220             * Returns an ordered range of all the social activity limits.
1221             *
1222             * <p>
1223             * 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.
1224             * </p>
1225             *
1226             * @param start the lower bound of the range of social activity limits
1227             * @param end the upper bound of the range of social activity limits (not inclusive)
1228             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1229             * @return the ordered range of social activity limits
1230             * @throws SystemException if a system exception occurred
1231             */
1232            public List<SocialActivityLimit> findAll(int start, int end,
1233                    OrderByComparator orderByComparator) throws SystemException {
1234                    FinderPath finderPath = null;
1235                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1236    
1237                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1238                                    (orderByComparator == null)) {
1239                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1240                            finderArgs = FINDER_ARGS_EMPTY;
1241                    }
1242                    else {
1243                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1244                            finderArgs = new Object[] { start, end, orderByComparator };
1245                    }
1246    
1247                    List<SocialActivityLimit> list = (List<SocialActivityLimit>)FinderCacheUtil.getResult(finderPath,
1248                                    finderArgs, this);
1249    
1250                    if (list == null) {
1251                            StringBundler query = null;
1252                            String sql = null;
1253    
1254                            if (orderByComparator != null) {
1255                                    query = new StringBundler(2 +
1256                                                    (orderByComparator.getOrderByFields().length * 3));
1257    
1258                                    query.append(_SQL_SELECT_SOCIALACTIVITYLIMIT);
1259    
1260                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1261                                            orderByComparator);
1262    
1263                                    sql = query.toString();
1264                            }
1265                            else {
1266                                    sql = _SQL_SELECT_SOCIALACTIVITYLIMIT;
1267                            }
1268    
1269                            Session session = null;
1270    
1271                            try {
1272                                    session = openSession();
1273    
1274                                    Query q = session.createQuery(sql);
1275    
1276                                    if (orderByComparator == null) {
1277                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
1278                                                            getDialect(), start, end, false);
1279    
1280                                            Collections.sort(list);
1281                                    }
1282                                    else {
1283                                            list = (List<SocialActivityLimit>)QueryUtil.list(q,
1284                                                            getDialect(), start, end);
1285                                    }
1286                            }
1287                            catch (Exception e) {
1288                                    throw processException(e);
1289                            }
1290                            finally {
1291                                    if (list == null) {
1292                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1293                                    }
1294                                    else {
1295                                            cacheResult(list);
1296    
1297                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1298                                    }
1299    
1300                                    closeSession(session);
1301                            }
1302                    }
1303    
1304                    return list;
1305            }
1306    
1307            /**
1308             * Removes all the social activity limits where classNameId = &#63; and classPK = &#63; from the database.
1309             *
1310             * @param classNameId the class name ID
1311             * @param classPK the class p k
1312             * @throws SystemException if a system exception occurred
1313             */
1314            public void removeByC_C(long classNameId, long classPK)
1315                    throws SystemException {
1316                    for (SocialActivityLimit socialActivityLimit : findByC_C(classNameId,
1317                                    classPK)) {
1318                            remove(socialActivityLimit);
1319                    }
1320            }
1321    
1322            /**
1323             * 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.
1324             *
1325             * @param groupId the group ID
1326             * @param userId the user ID
1327             * @param classNameId the class name ID
1328             * @param classPK the class p k
1329             * @param activityType the activity type
1330             * @param activityCounterName the activity counter name
1331             * @return the social activity limit that was removed
1332             * @throws SystemException if a system exception occurred
1333             */
1334            public SocialActivityLimit removeByG_U_C_C_A_A(long groupId, long userId,
1335                    long classNameId, long classPK, int activityType,
1336                    String activityCounterName)
1337                    throws NoSuchActivityLimitException, SystemException {
1338                    SocialActivityLimit socialActivityLimit = findByG_U_C_C_A_A(groupId,
1339                                    userId, classNameId, classPK, activityType, activityCounterName);
1340    
1341                    return remove(socialActivityLimit);
1342            }
1343    
1344            /**
1345             * Removes all the social activity limits from the database.
1346             *
1347             * @throws SystemException if a system exception occurred
1348             */
1349            public void removeAll() throws SystemException {
1350                    for (SocialActivityLimit socialActivityLimit : findAll()) {
1351                            remove(socialActivityLimit);
1352                    }
1353            }
1354    
1355            /**
1356             * Returns the number of social activity limits where classNameId = &#63; and classPK = &#63;.
1357             *
1358             * @param classNameId the class name ID
1359             * @param classPK the class p k
1360             * @return the number of matching social activity limits
1361             * @throws SystemException if a system exception occurred
1362             */
1363            public int countByC_C(long classNameId, long classPK)
1364                    throws SystemException {
1365                    Object[] finderArgs = new Object[] { classNameId, classPK };
1366    
1367                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1368                                    finderArgs, this);
1369    
1370                    if (count == null) {
1371                            StringBundler query = new StringBundler(3);
1372    
1373                            query.append(_SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE);
1374    
1375                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1376    
1377                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1378    
1379                            String sql = query.toString();
1380    
1381                            Session session = null;
1382    
1383                            try {
1384                                    session = openSession();
1385    
1386                                    Query q = session.createQuery(sql);
1387    
1388                                    QueryPos qPos = QueryPos.getInstance(q);
1389    
1390                                    qPos.add(classNameId);
1391    
1392                                    qPos.add(classPK);
1393    
1394                                    count = (Long)q.uniqueResult();
1395                            }
1396                            catch (Exception e) {
1397                                    throw processException(e);
1398                            }
1399                            finally {
1400                                    if (count == null) {
1401                                            count = Long.valueOf(0);
1402                                    }
1403    
1404                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1405                                            count);
1406    
1407                                    closeSession(session);
1408                            }
1409                    }
1410    
1411                    return count.intValue();
1412            }
1413    
1414            /**
1415             * 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;.
1416             *
1417             * @param groupId the group ID
1418             * @param userId the user ID
1419             * @param classNameId the class name ID
1420             * @param classPK the class p k
1421             * @param activityType the activity type
1422             * @param activityCounterName the activity counter name
1423             * @return the number of matching social activity limits
1424             * @throws SystemException if a system exception occurred
1425             */
1426            public int countByG_U_C_C_A_A(long groupId, long userId, long classNameId,
1427                    long classPK, int activityType, String activityCounterName)
1428                    throws SystemException {
1429                    Object[] finderArgs = new Object[] {
1430                                    groupId, userId, classNameId, classPK, activityType,
1431                                    activityCounterName
1432                            };
1433    
1434                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A,
1435                                    finderArgs, this);
1436    
1437                    if (count == null) {
1438                            StringBundler query = new StringBundler(7);
1439    
1440                            query.append(_SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE);
1441    
1442                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2);
1443    
1444                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_USERID_2);
1445    
1446                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2);
1447    
1448                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2);
1449    
1450                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2);
1451    
1452                            if (activityCounterName == null) {
1453                                    query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1);
1454                            }
1455                            else {
1456                                    if (activityCounterName.equals(StringPool.BLANK)) {
1457                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3);
1458                                    }
1459                                    else {
1460                                            query.append(_FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2);
1461                                    }
1462                            }
1463    
1464                            String sql = query.toString();
1465    
1466                            Session session = null;
1467    
1468                            try {
1469                                    session = openSession();
1470    
1471                                    Query q = session.createQuery(sql);
1472    
1473                                    QueryPos qPos = QueryPos.getInstance(q);
1474    
1475                                    qPos.add(groupId);
1476    
1477                                    qPos.add(userId);
1478    
1479                                    qPos.add(classNameId);
1480    
1481                                    qPos.add(classPK);
1482    
1483                                    qPos.add(activityType);
1484    
1485                                    if (activityCounterName != null) {
1486                                            qPos.add(activityCounterName);
1487                                    }
1488    
1489                                    count = (Long)q.uniqueResult();
1490                            }
1491                            catch (Exception e) {
1492                                    throw processException(e);
1493                            }
1494                            finally {
1495                                    if (count == null) {
1496                                            count = Long.valueOf(0);
1497                                    }
1498    
1499                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_C_C_A_A,
1500                                            finderArgs, count);
1501    
1502                                    closeSession(session);
1503                            }
1504                    }
1505    
1506                    return count.intValue();
1507            }
1508    
1509            /**
1510             * Returns the number of social activity limits.
1511             *
1512             * @return the number of social activity limits
1513             * @throws SystemException if a system exception occurred
1514             */
1515            public int countAll() throws SystemException {
1516                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1517                                    FINDER_ARGS_EMPTY, this);
1518    
1519                    if (count == null) {
1520                            Session session = null;
1521    
1522                            try {
1523                                    session = openSession();
1524    
1525                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYLIMIT);
1526    
1527                                    count = (Long)q.uniqueResult();
1528                            }
1529                            catch (Exception e) {
1530                                    throw processException(e);
1531                            }
1532                            finally {
1533                                    if (count == null) {
1534                                            count = Long.valueOf(0);
1535                                    }
1536    
1537                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1538                                            FINDER_ARGS_EMPTY, count);
1539    
1540                                    closeSession(session);
1541                            }
1542                    }
1543    
1544                    return count.intValue();
1545            }
1546    
1547            /**
1548             * Initializes the social activity limit persistence.
1549             */
1550            public void afterPropertiesSet() {
1551                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1552                                            com.liferay.portal.util.PropsUtil.get(
1553                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivityLimit")));
1554    
1555                    if (listenerClassNames.length > 0) {
1556                            try {
1557                                    List<ModelListener<SocialActivityLimit>> listenersList = new ArrayList<ModelListener<SocialActivityLimit>>();
1558    
1559                                    for (String listenerClassName : listenerClassNames) {
1560                                            listenersList.add((ModelListener<SocialActivityLimit>)InstanceFactory.newInstance(
1561                                                            listenerClassName));
1562                                    }
1563    
1564                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1565                            }
1566                            catch (Exception e) {
1567                                    _log.error(e);
1568                            }
1569                    }
1570            }
1571    
1572            public void destroy() {
1573                    EntityCacheUtil.removeCache(SocialActivityLimitImpl.class.getName());
1574                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1575                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1576            }
1577    
1578            @BeanReference(type = SocialActivityPersistence.class)
1579            protected SocialActivityPersistence socialActivityPersistence;
1580            @BeanReference(type = SocialActivityAchievementPersistence.class)
1581            protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
1582            @BeanReference(type = SocialActivityCounterPersistence.class)
1583            protected SocialActivityCounterPersistence socialActivityCounterPersistence;
1584            @BeanReference(type = SocialActivityLimitPersistence.class)
1585            protected SocialActivityLimitPersistence socialActivityLimitPersistence;
1586            @BeanReference(type = SocialActivitySettingPersistence.class)
1587            protected SocialActivitySettingPersistence socialActivitySettingPersistence;
1588            @BeanReference(type = SocialRelationPersistence.class)
1589            protected SocialRelationPersistence socialRelationPersistence;
1590            @BeanReference(type = SocialRequestPersistence.class)
1591            protected SocialRequestPersistence socialRequestPersistence;
1592            @BeanReference(type = GroupPersistence.class)
1593            protected GroupPersistence groupPersistence;
1594            @BeanReference(type = ResourcePersistence.class)
1595            protected ResourcePersistence resourcePersistence;
1596            @BeanReference(type = UserPersistence.class)
1597            protected UserPersistence userPersistence;
1598            private static final String _SQL_SELECT_SOCIALACTIVITYLIMIT = "SELECT socialActivityLimit FROM SocialActivityLimit socialActivityLimit";
1599            private static final String _SQL_SELECT_SOCIALACTIVITYLIMIT_WHERE = "SELECT socialActivityLimit FROM SocialActivityLimit socialActivityLimit WHERE ";
1600            private static final String _SQL_COUNT_SOCIALACTIVITYLIMIT = "SELECT COUNT(socialActivityLimit) FROM SocialActivityLimit socialActivityLimit";
1601            private static final String _SQL_COUNT_SOCIALACTIVITYLIMIT_WHERE = "SELECT COUNT(socialActivityLimit) FROM SocialActivityLimit socialActivityLimit WHERE ";
1602            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "socialActivityLimit.classNameId = ? AND ";
1603            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "socialActivityLimit.classPK = ?";
1604            private static final String _FINDER_COLUMN_G_U_C_C_A_A_GROUPID_2 = "socialActivityLimit.groupId = ? AND ";
1605            private static final String _FINDER_COLUMN_G_U_C_C_A_A_USERID_2 = "socialActivityLimit.userId = ? AND ";
1606            private static final String _FINDER_COLUMN_G_U_C_C_A_A_CLASSNAMEID_2 = "socialActivityLimit.classNameId = ? AND ";
1607            private static final String _FINDER_COLUMN_G_U_C_C_A_A_CLASSPK_2 = "socialActivityLimit.classPK = ? AND ";
1608            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYTYPE_2 = "socialActivityLimit.activityType = ? AND ";
1609            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_1 =
1610                    "socialActivityLimit.activityCounterName IS NULL";
1611            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_2 =
1612                    "socialActivityLimit.activityCounterName = ?";
1613            private static final String _FINDER_COLUMN_G_U_C_C_A_A_ACTIVITYCOUNTERNAME_3 =
1614                    "(socialActivityLimit.activityCounterName IS NULL OR socialActivityLimit.activityCounterName = ?)";
1615            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivityLimit.";
1616            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivityLimit exists with the primary key ";
1617            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivityLimit exists with the key {";
1618            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1619            private static Log _log = LogFactoryUtil.getLog(SocialActivityLimitPersistenceImpl.class);
1620            private static SocialActivityLimit _nullSocialActivityLimit = new SocialActivityLimitImpl() {
1621                            @Override
1622                            public Object clone() {
1623                                    return this;
1624                            }
1625    
1626                            @Override
1627                            public CacheModel<SocialActivityLimit> toCacheModel() {
1628                                    return _nullSocialActivityLimitCacheModel;
1629                            }
1630                    };
1631    
1632            private static CacheModel<SocialActivityLimit> _nullSocialActivityLimitCacheModel =
1633                    new CacheModel<SocialActivityLimit>() {
1634                            public SocialActivityLimit toEntityModel() {
1635                                    return _nullSocialActivityLimit;
1636                            }
1637                    };
1638    }