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