001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.GroupPersistence;
041    import com.liferay.portal.service.persistence.LockPersistence;
042    import com.liferay.portal.service.persistence.ResourcePersistence;
043    import com.liferay.portal.service.persistence.UserPersistence;
044    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045    
046    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
047    import com.liferay.portlet.social.NoSuchActivityCounterException;
048    import com.liferay.portlet.social.model.SocialActivityCounter;
049    import com.liferay.portlet.social.model.impl.SocialActivityCounterImpl;
050    import com.liferay.portlet.social.model.impl.SocialActivityCounterModelImpl;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    
058    /**
059     * The persistence implementation for the social activity counter service.
060     *
061     * <p>
062     * Caching information and settings can be found in <code>portal.properties</code>
063     * </p>
064     *
065     * @author Brian Wing Shun Chan
066     * @see SocialActivityCounterPersistence
067     * @see SocialActivityCounterUtil
068     * @generated
069     */
070    public class SocialActivityCounterPersistenceImpl extends BasePersistenceImpl<SocialActivityCounter>
071            implements SocialActivityCounterPersistence {
072            /*
073             * NOTE FOR DEVELOPERS:
074             *
075             * Never modify or reference this class directly. Always use {@link SocialActivityCounterUtil} to access the social activity counter persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
076             */
077            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivityCounterImpl.class.getName();
078            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List1";
080            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List2";
082            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
083                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED,
084                            SocialActivityCounterImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
086                            new String[] {
087                                    Long.class.getName(), Long.class.getName(),
088                                    
089                            "java.lang.Integer", "java.lang.Integer",
090                                    "com.liferay.portal.kernel.util.OrderByComparator"
091                            });
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
093                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED,
094                            SocialActivityCounterImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
096                            new String[] { Long.class.getName(), Long.class.getName() },
097                            SocialActivityCounterModelImpl.CLASSNAMEID_COLUMN_BITMASK |
098                            SocialActivityCounterModelImpl.CLASSPK_COLUMN_BITMASK);
099            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
100                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED, Long.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
102                            new String[] { Long.class.getName(), Long.class.getName() });
103            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_O = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
104                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED,
105                            SocialActivityCounterImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C_O",
107                            new String[] {
108                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
109                                    Integer.class.getName(),
110                                    
111                            "java.lang.Integer", "java.lang.Integer",
112                                    "com.liferay.portal.kernel.util.OrderByComparator"
113                            });
114            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_O =
115                    new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
116                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED,
117                            SocialActivityCounterImpl.class,
118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C_O",
119                            new String[] {
120                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
121                                    Integer.class.getName()
122                            },
123                            SocialActivityCounterModelImpl.GROUPID_COLUMN_BITMASK |
124                            SocialActivityCounterModelImpl.CLASSNAMEID_COLUMN_BITMASK |
125                            SocialActivityCounterModelImpl.CLASSPK_COLUMN_BITMASK |
126                            SocialActivityCounterModelImpl.OWNERTYPE_COLUMN_BITMASK);
127            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_O = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
128                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED, Long.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C_O",
130                            new String[] {
131                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
132                                    Integer.class.getName()
133                            });
134            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_C_N_O_S = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
135                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED,
136                            SocialActivityCounterImpl.class, FINDER_CLASS_NAME_ENTITY,
137                            "fetchByG_C_C_N_O_S",
138                            new String[] {
139                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
140                                    String.class.getName(), Integer.class.getName(),
141                                    Integer.class.getName()
142                            },
143                            SocialActivityCounterModelImpl.GROUPID_COLUMN_BITMASK |
144                            SocialActivityCounterModelImpl.CLASSNAMEID_COLUMN_BITMASK |
145                            SocialActivityCounterModelImpl.CLASSPK_COLUMN_BITMASK |
146                            SocialActivityCounterModelImpl.NAME_COLUMN_BITMASK |
147                            SocialActivityCounterModelImpl.OWNERTYPE_COLUMN_BITMASK |
148                            SocialActivityCounterModelImpl.STARTPERIOD_COLUMN_BITMASK);
149            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_N_O_S = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
150                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED, Long.class,
151                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C_N_O_S",
152                            new String[] {
153                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
154                                    String.class.getName(), Integer.class.getName(),
155                                    Integer.class.getName()
156                            });
157            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_C_N_O_E = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
158                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED,
159                            SocialActivityCounterImpl.class, FINDER_CLASS_NAME_ENTITY,
160                            "fetchByG_C_C_N_O_E",
161                            new String[] {
162                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
163                                    String.class.getName(), Integer.class.getName(),
164                                    Integer.class.getName()
165                            },
166                            SocialActivityCounterModelImpl.GROUPID_COLUMN_BITMASK |
167                            SocialActivityCounterModelImpl.CLASSNAMEID_COLUMN_BITMASK |
168                            SocialActivityCounterModelImpl.CLASSPK_COLUMN_BITMASK |
169                            SocialActivityCounterModelImpl.NAME_COLUMN_BITMASK |
170                            SocialActivityCounterModelImpl.OWNERTYPE_COLUMN_BITMASK |
171                            SocialActivityCounterModelImpl.ENDPERIOD_COLUMN_BITMASK);
172            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C_N_O_E = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
173                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED, Long.class,
174                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C_N_O_E",
175                            new String[] {
176                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
177                                    String.class.getName(), Integer.class.getName(),
178                                    Integer.class.getName()
179                            });
180            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
181                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED,
182                            SocialActivityCounterImpl.class,
183                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
184            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
185                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED,
186                            SocialActivityCounterImpl.class,
187                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
188            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
189                            SocialActivityCounterModelImpl.FINDER_CACHE_ENABLED, Long.class,
190                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
191    
192            /**
193             * Caches the social activity counter in the entity cache if it is enabled.
194             *
195             * @param socialActivityCounter the social activity counter
196             */
197            public void cacheResult(SocialActivityCounter socialActivityCounter) {
198                    EntityCacheUtil.putResult(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
199                            SocialActivityCounterImpl.class,
200                            socialActivityCounter.getPrimaryKey(), socialActivityCounter);
201    
202                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_S,
203                            new Object[] {
204                                    Long.valueOf(socialActivityCounter.getGroupId()),
205                                    Long.valueOf(socialActivityCounter.getClassNameId()),
206                                    Long.valueOf(socialActivityCounter.getClassPK()),
207                                    
208                            socialActivityCounter.getName(),
209                                    Integer.valueOf(socialActivityCounter.getOwnerType()),
210                                    Integer.valueOf(socialActivityCounter.getStartPeriod())
211                            }, socialActivityCounter);
212    
213                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_E,
214                            new Object[] {
215                                    Long.valueOf(socialActivityCounter.getGroupId()),
216                                    Long.valueOf(socialActivityCounter.getClassNameId()),
217                                    Long.valueOf(socialActivityCounter.getClassPK()),
218                                    
219                            socialActivityCounter.getName(),
220                                    Integer.valueOf(socialActivityCounter.getOwnerType()),
221                                    Integer.valueOf(socialActivityCounter.getEndPeriod())
222                            }, socialActivityCounter);
223    
224                    socialActivityCounter.resetOriginalValues();
225            }
226    
227            /**
228             * Caches the social activity counters in the entity cache if it is enabled.
229             *
230             * @param socialActivityCounters the social activity counters
231             */
232            public void cacheResult(List<SocialActivityCounter> socialActivityCounters) {
233                    for (SocialActivityCounter socialActivityCounter : socialActivityCounters) {
234                            if (EntityCacheUtil.getResult(
235                                                    SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
236                                                    SocialActivityCounterImpl.class,
237                                                    socialActivityCounter.getPrimaryKey()) == null) {
238                                    cacheResult(socialActivityCounter);
239                            }
240                            else {
241                                    socialActivityCounter.resetOriginalValues();
242                            }
243                    }
244            }
245    
246            /**
247             * Clears the cache for all social activity counters.
248             *
249             * <p>
250             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
251             * </p>
252             */
253            @Override
254            public void clearCache() {
255                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
256                            CacheRegistryUtil.clear(SocialActivityCounterImpl.class.getName());
257                    }
258    
259                    EntityCacheUtil.clearCache(SocialActivityCounterImpl.class.getName());
260    
261                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
262                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
263                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
264            }
265    
266            /**
267             * Clears the cache for the social activity counter.
268             *
269             * <p>
270             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
271             * </p>
272             */
273            @Override
274            public void clearCache(SocialActivityCounter socialActivityCounter) {
275                    EntityCacheUtil.removeResult(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
276                            SocialActivityCounterImpl.class,
277                            socialActivityCounter.getPrimaryKey());
278    
279                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
280                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
281    
282                    clearUniqueFindersCache(socialActivityCounter);
283            }
284    
285            @Override
286            public void clearCache(List<SocialActivityCounter> socialActivityCounters) {
287                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
288                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
289    
290                    for (SocialActivityCounter socialActivityCounter : socialActivityCounters) {
291                            EntityCacheUtil.removeResult(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
292                                    SocialActivityCounterImpl.class,
293                                    socialActivityCounter.getPrimaryKey());
294    
295                            clearUniqueFindersCache(socialActivityCounter);
296                    }
297            }
298    
299            protected void cacheUniqueFindersCache(
300                    SocialActivityCounter socialActivityCounter) {
301                    if (socialActivityCounter.isNew()) {
302                            Object[] args = new Object[] {
303                                            Long.valueOf(socialActivityCounter.getGroupId()),
304                                            Long.valueOf(socialActivityCounter.getClassNameId()),
305                                            Long.valueOf(socialActivityCounter.getClassPK()),
306                                            
307                                            socialActivityCounter.getName(),
308                                            Integer.valueOf(socialActivityCounter.getOwnerType()),
309                                            Integer.valueOf(socialActivityCounter.getStartPeriod())
310                                    };
311    
312                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_S, args,
313                                    Long.valueOf(1));
314                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_S, args,
315                                    socialActivityCounter);
316    
317                            args = new Object[] {
318                                            Long.valueOf(socialActivityCounter.getGroupId()),
319                                            Long.valueOf(socialActivityCounter.getClassNameId()),
320                                            Long.valueOf(socialActivityCounter.getClassPK()),
321                                            
322                                            socialActivityCounter.getName(),
323                                            Integer.valueOf(socialActivityCounter.getOwnerType()),
324                                            Integer.valueOf(socialActivityCounter.getEndPeriod())
325                                    };
326    
327                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_E, args,
328                                    Long.valueOf(1));
329                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_E, args,
330                                    socialActivityCounter);
331                    }
332                    else {
333                            SocialActivityCounterModelImpl socialActivityCounterModelImpl = (SocialActivityCounterModelImpl)socialActivityCounter;
334    
335                            if ((socialActivityCounterModelImpl.getColumnBitmask() &
336                                            FINDER_PATH_FETCH_BY_G_C_C_N_O_S.getColumnBitmask()) != 0) {
337                                    Object[] args = new Object[] {
338                                                    Long.valueOf(socialActivityCounter.getGroupId()),
339                                                    Long.valueOf(socialActivityCounter.getClassNameId()),
340                                                    Long.valueOf(socialActivityCounter.getClassPK()),
341                                                    
342                                                    socialActivityCounter.getName(),
343                                                    Integer.valueOf(socialActivityCounter.getOwnerType()),
344                                                    Integer.valueOf(socialActivityCounter.getStartPeriod())
345                                            };
346    
347                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_S,
348                                            args, Long.valueOf(1));
349                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_S,
350                                            args, socialActivityCounter);
351                            }
352    
353                            if ((socialActivityCounterModelImpl.getColumnBitmask() &
354                                            FINDER_PATH_FETCH_BY_G_C_C_N_O_E.getColumnBitmask()) != 0) {
355                                    Object[] args = new Object[] {
356                                                    Long.valueOf(socialActivityCounter.getGroupId()),
357                                                    Long.valueOf(socialActivityCounter.getClassNameId()),
358                                                    Long.valueOf(socialActivityCounter.getClassPK()),
359                                                    
360                                                    socialActivityCounter.getName(),
361                                                    Integer.valueOf(socialActivityCounter.getOwnerType()),
362                                                    Integer.valueOf(socialActivityCounter.getEndPeriod())
363                                            };
364    
365                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_E,
366                                            args, Long.valueOf(1));
367                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_E,
368                                            args, socialActivityCounter);
369                            }
370                    }
371            }
372    
373            protected void clearUniqueFindersCache(
374                    SocialActivityCounter socialActivityCounter) {
375                    SocialActivityCounterModelImpl socialActivityCounterModelImpl = (SocialActivityCounterModelImpl)socialActivityCounter;
376    
377                    Object[] args = new Object[] {
378                                    Long.valueOf(socialActivityCounter.getGroupId()),
379                                    Long.valueOf(socialActivityCounter.getClassNameId()),
380                                    Long.valueOf(socialActivityCounter.getClassPK()),
381                                    
382                                    socialActivityCounter.getName(),
383                                    Integer.valueOf(socialActivityCounter.getOwnerType()),
384                                    Integer.valueOf(socialActivityCounter.getStartPeriod())
385                            };
386    
387                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_S, args);
388                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_S, args);
389    
390                    if ((socialActivityCounterModelImpl.getColumnBitmask() &
391                                    FINDER_PATH_FETCH_BY_G_C_C_N_O_S.getColumnBitmask()) != 0) {
392                            args = new Object[] {
393                                            Long.valueOf(socialActivityCounterModelImpl.getOriginalGroupId()),
394                                            Long.valueOf(socialActivityCounterModelImpl.getOriginalClassNameId()),
395                                            Long.valueOf(socialActivityCounterModelImpl.getOriginalClassPK()),
396                                            
397                                            socialActivityCounterModelImpl.getOriginalName(),
398                                            Integer.valueOf(socialActivityCounterModelImpl.getOriginalOwnerType()),
399                                            Integer.valueOf(socialActivityCounterModelImpl.getOriginalStartPeriod())
400                                    };
401    
402                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_S, args);
403                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_S, args);
404                    }
405    
406                    args = new Object[] {
407                                    Long.valueOf(socialActivityCounter.getGroupId()),
408                                    Long.valueOf(socialActivityCounter.getClassNameId()),
409                                    Long.valueOf(socialActivityCounter.getClassPK()),
410                                    
411                                    socialActivityCounter.getName(),
412                                    Integer.valueOf(socialActivityCounter.getOwnerType()),
413                                    Integer.valueOf(socialActivityCounter.getEndPeriod())
414                            };
415    
416                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_E, args);
417                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_E, args);
418    
419                    if ((socialActivityCounterModelImpl.getColumnBitmask() &
420                                    FINDER_PATH_FETCH_BY_G_C_C_N_O_E.getColumnBitmask()) != 0) {
421                            args = new Object[] {
422                                            Long.valueOf(socialActivityCounterModelImpl.getOriginalGroupId()),
423                                            Long.valueOf(socialActivityCounterModelImpl.getOriginalClassNameId()),
424                                            Long.valueOf(socialActivityCounterModelImpl.getOriginalClassPK()),
425                                            
426                                            socialActivityCounterModelImpl.getOriginalName(),
427                                            Integer.valueOf(socialActivityCounterModelImpl.getOriginalOwnerType()),
428                                            Integer.valueOf(socialActivityCounterModelImpl.getOriginalEndPeriod())
429                                    };
430    
431                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_E, args);
432                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_E, args);
433                    }
434            }
435    
436            /**
437             * Creates a new social activity counter with the primary key. Does not add the social activity counter to the database.
438             *
439             * @param activityCounterId the primary key for the new social activity counter
440             * @return the new social activity counter
441             */
442            public SocialActivityCounter create(long activityCounterId) {
443                    SocialActivityCounter socialActivityCounter = new SocialActivityCounterImpl();
444    
445                    socialActivityCounter.setNew(true);
446                    socialActivityCounter.setPrimaryKey(activityCounterId);
447    
448                    return socialActivityCounter;
449            }
450    
451            /**
452             * Removes the social activity counter with the primary key from the database. Also notifies the appropriate model listeners.
453             *
454             * @param activityCounterId the primary key of the social activity counter
455             * @return the social activity counter that was removed
456             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a social activity counter with the primary key could not be found
457             * @throws SystemException if a system exception occurred
458             */
459            public SocialActivityCounter remove(long activityCounterId)
460                    throws NoSuchActivityCounterException, SystemException {
461                    return remove(Long.valueOf(activityCounterId));
462            }
463    
464            /**
465             * Removes the social activity counter with the primary key from the database. Also notifies the appropriate model listeners.
466             *
467             * @param primaryKey the primary key of the social activity counter
468             * @return the social activity counter that was removed
469             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a social activity counter with the primary key could not be found
470             * @throws SystemException if a system exception occurred
471             */
472            @Override
473            public SocialActivityCounter remove(Serializable primaryKey)
474                    throws NoSuchActivityCounterException, SystemException {
475                    Session session = null;
476    
477                    try {
478                            session = openSession();
479    
480                            SocialActivityCounter socialActivityCounter = (SocialActivityCounter)session.get(SocialActivityCounterImpl.class,
481                                            primaryKey);
482    
483                            if (socialActivityCounter == null) {
484                                    if (_log.isWarnEnabled()) {
485                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
486                                    }
487    
488                                    throw new NoSuchActivityCounterException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
489                                            primaryKey);
490                            }
491    
492                            return remove(socialActivityCounter);
493                    }
494                    catch (NoSuchActivityCounterException nsee) {
495                            throw nsee;
496                    }
497                    catch (Exception e) {
498                            throw processException(e);
499                    }
500                    finally {
501                            closeSession(session);
502                    }
503            }
504    
505            @Override
506            protected SocialActivityCounter removeImpl(
507                    SocialActivityCounter socialActivityCounter) throws SystemException {
508                    socialActivityCounter = toUnwrappedModel(socialActivityCounter);
509    
510                    Session session = null;
511    
512                    try {
513                            session = openSession();
514    
515                            BatchSessionUtil.delete(session, socialActivityCounter);
516                    }
517                    catch (Exception e) {
518                            throw processException(e);
519                    }
520                    finally {
521                            closeSession(session);
522                    }
523    
524                    clearCache(socialActivityCounter);
525    
526                    return socialActivityCounter;
527            }
528    
529            @Override
530            public SocialActivityCounter updateImpl(
531                    com.liferay.portlet.social.model.SocialActivityCounter socialActivityCounter,
532                    boolean merge) throws SystemException {
533                    socialActivityCounter = toUnwrappedModel(socialActivityCounter);
534    
535                    boolean isNew = socialActivityCounter.isNew();
536    
537                    SocialActivityCounterModelImpl socialActivityCounterModelImpl = (SocialActivityCounterModelImpl)socialActivityCounter;
538    
539                    Session session = null;
540    
541                    try {
542                            session = openSession();
543    
544                            BatchSessionUtil.update(session, socialActivityCounter, merge);
545    
546                            socialActivityCounter.setNew(false);
547                    }
548                    catch (Exception e) {
549                            throw processException(e);
550                    }
551                    finally {
552                            closeSession(session);
553                    }
554    
555                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
556    
557                    if (isNew || !SocialActivityCounterModelImpl.COLUMN_BITMASK_ENABLED) {
558                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
559                    }
560    
561                    else {
562                            if ((socialActivityCounterModelImpl.getColumnBitmask() &
563                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
564                                    Object[] args = new Object[] {
565                                                    Long.valueOf(socialActivityCounterModelImpl.getOriginalClassNameId()),
566                                                    Long.valueOf(socialActivityCounterModelImpl.getOriginalClassPK())
567                                            };
568    
569                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
570                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
571                                            args);
572    
573                                    args = new Object[] {
574                                                    Long.valueOf(socialActivityCounterModelImpl.getClassNameId()),
575                                                    Long.valueOf(socialActivityCounterModelImpl.getClassPK())
576                                            };
577    
578                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
579                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
580                                            args);
581                            }
582    
583                            if ((socialActivityCounterModelImpl.getColumnBitmask() &
584                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_O.getColumnBitmask()) != 0) {
585                                    Object[] args = new Object[] {
586                                                    Long.valueOf(socialActivityCounterModelImpl.getOriginalGroupId()),
587                                                    Long.valueOf(socialActivityCounterModelImpl.getOriginalClassNameId()),
588                                                    Long.valueOf(socialActivityCounterModelImpl.getOriginalClassPK()),
589                                                    Integer.valueOf(socialActivityCounterModelImpl.getOriginalOwnerType())
590                                            };
591    
592                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_O, args);
593                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_O,
594                                            args);
595    
596                                    args = new Object[] {
597                                                    Long.valueOf(socialActivityCounterModelImpl.getGroupId()),
598                                                    Long.valueOf(socialActivityCounterModelImpl.getClassNameId()),
599                                                    Long.valueOf(socialActivityCounterModelImpl.getClassPK()),
600                                                    Integer.valueOf(socialActivityCounterModelImpl.getOwnerType())
601                                            };
602    
603                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C_O, args);
604                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_O,
605                                            args);
606                            }
607                    }
608    
609                    EntityCacheUtil.putResult(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
610                            SocialActivityCounterImpl.class,
611                            socialActivityCounter.getPrimaryKey(), socialActivityCounter);
612    
613                    clearUniqueFindersCache(socialActivityCounter);
614                    cacheUniqueFindersCache(socialActivityCounter);
615    
616                    return socialActivityCounter;
617            }
618    
619            protected SocialActivityCounter toUnwrappedModel(
620                    SocialActivityCounter socialActivityCounter) {
621                    if (socialActivityCounter instanceof SocialActivityCounterImpl) {
622                            return socialActivityCounter;
623                    }
624    
625                    SocialActivityCounterImpl socialActivityCounterImpl = new SocialActivityCounterImpl();
626    
627                    socialActivityCounterImpl.setNew(socialActivityCounter.isNew());
628                    socialActivityCounterImpl.setPrimaryKey(socialActivityCounter.getPrimaryKey());
629    
630                    socialActivityCounterImpl.setActivityCounterId(socialActivityCounter.getActivityCounterId());
631                    socialActivityCounterImpl.setGroupId(socialActivityCounter.getGroupId());
632                    socialActivityCounterImpl.setCompanyId(socialActivityCounter.getCompanyId());
633                    socialActivityCounterImpl.setClassNameId(socialActivityCounter.getClassNameId());
634                    socialActivityCounterImpl.setClassPK(socialActivityCounter.getClassPK());
635                    socialActivityCounterImpl.setName(socialActivityCounter.getName());
636                    socialActivityCounterImpl.setOwnerType(socialActivityCounter.getOwnerType());
637                    socialActivityCounterImpl.setCurrentValue(socialActivityCounter.getCurrentValue());
638                    socialActivityCounterImpl.setTotalValue(socialActivityCounter.getTotalValue());
639                    socialActivityCounterImpl.setGraceValue(socialActivityCounter.getGraceValue());
640                    socialActivityCounterImpl.setStartPeriod(socialActivityCounter.getStartPeriod());
641                    socialActivityCounterImpl.setEndPeriod(socialActivityCounter.getEndPeriod());
642    
643                    return socialActivityCounterImpl;
644            }
645    
646            /**
647             * Returns the social activity counter with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
648             *
649             * @param primaryKey the primary key of the social activity counter
650             * @return the social activity counter
651             * @throws com.liferay.portal.NoSuchModelException if a social activity counter with the primary key could not be found
652             * @throws SystemException if a system exception occurred
653             */
654            @Override
655            public SocialActivityCounter findByPrimaryKey(Serializable primaryKey)
656                    throws NoSuchModelException, SystemException {
657                    return findByPrimaryKey(((Long)primaryKey).longValue());
658            }
659    
660            /**
661             * Returns the social activity counter with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivityCounterException} if it could not be found.
662             *
663             * @param activityCounterId the primary key of the social activity counter
664             * @return the social activity counter
665             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a social activity counter with the primary key could not be found
666             * @throws SystemException if a system exception occurred
667             */
668            public SocialActivityCounter findByPrimaryKey(long activityCounterId)
669                    throws NoSuchActivityCounterException, SystemException {
670                    SocialActivityCounter socialActivityCounter = fetchByPrimaryKey(activityCounterId);
671    
672                    if (socialActivityCounter == null) {
673                            if (_log.isWarnEnabled()) {
674                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + activityCounterId);
675                            }
676    
677                            throw new NoSuchActivityCounterException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
678                                    activityCounterId);
679                    }
680    
681                    return socialActivityCounter;
682            }
683    
684            /**
685             * Returns the social activity counter with the primary key or returns <code>null</code> if it could not be found.
686             *
687             * @param primaryKey the primary key of the social activity counter
688             * @return the social activity counter, or <code>null</code> if a social activity counter with the primary key could not be found
689             * @throws SystemException if a system exception occurred
690             */
691            @Override
692            public SocialActivityCounter fetchByPrimaryKey(Serializable primaryKey)
693                    throws SystemException {
694                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
695            }
696    
697            /**
698             * Returns the social activity counter with the primary key or returns <code>null</code> if it could not be found.
699             *
700             * @param activityCounterId the primary key of the social activity counter
701             * @return the social activity counter, or <code>null</code> if a social activity counter with the primary key could not be found
702             * @throws SystemException if a system exception occurred
703             */
704            public SocialActivityCounter fetchByPrimaryKey(long activityCounterId)
705                    throws SystemException {
706                    SocialActivityCounter socialActivityCounter = (SocialActivityCounter)EntityCacheUtil.getResult(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
707                                    SocialActivityCounterImpl.class, activityCounterId);
708    
709                    if (socialActivityCounter == _nullSocialActivityCounter) {
710                            return null;
711                    }
712    
713                    if (socialActivityCounter == null) {
714                            Session session = null;
715    
716                            boolean hasException = false;
717    
718                            try {
719                                    session = openSession();
720    
721                                    socialActivityCounter = (SocialActivityCounter)session.get(SocialActivityCounterImpl.class,
722                                                    Long.valueOf(activityCounterId));
723                            }
724                            catch (Exception e) {
725                                    hasException = true;
726    
727                                    throw processException(e);
728                            }
729                            finally {
730                                    if (socialActivityCounter != null) {
731                                            cacheResult(socialActivityCounter);
732                                    }
733                                    else if (!hasException) {
734                                            EntityCacheUtil.putResult(SocialActivityCounterModelImpl.ENTITY_CACHE_ENABLED,
735                                                    SocialActivityCounterImpl.class, activityCounterId,
736                                                    _nullSocialActivityCounter);
737                                    }
738    
739                                    closeSession(session);
740                            }
741                    }
742    
743                    return socialActivityCounter;
744            }
745    
746            /**
747             * Returns all the social activity counters where classNameId = &#63; and classPK = &#63;.
748             *
749             * @param classNameId the class name ID
750             * @param classPK the class p k
751             * @return the matching social activity counters
752             * @throws SystemException if a system exception occurred
753             */
754            public List<SocialActivityCounter> findByC_C(long classNameId, long classPK)
755                    throws SystemException {
756                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
757                            QueryUtil.ALL_POS, null);
758            }
759    
760            /**
761             * Returns a range of all the social activity counters where classNameId = &#63; and classPK = &#63;.
762             *
763             * <p>
764             * 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.
765             * </p>
766             *
767             * @param classNameId the class name ID
768             * @param classPK the class p k
769             * @param start the lower bound of the range of social activity counters
770             * @param end the upper bound of the range of social activity counters (not inclusive)
771             * @return the range of matching social activity counters
772             * @throws SystemException if a system exception occurred
773             */
774            public List<SocialActivityCounter> findByC_C(long classNameId,
775                    long classPK, int start, int end) throws SystemException {
776                    return findByC_C(classNameId, classPK, start, end, null);
777            }
778    
779            /**
780             * Returns an ordered range of all the social activity counters where classNameId = &#63; and classPK = &#63;.
781             *
782             * <p>
783             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
784             * </p>
785             *
786             * @param classNameId the class name ID
787             * @param classPK the class p k
788             * @param start the lower bound of the range of social activity counters
789             * @param end the upper bound of the range of social activity counters (not inclusive)
790             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
791             * @return the ordered range of matching social activity counters
792             * @throws SystemException if a system exception occurred
793             */
794            public List<SocialActivityCounter> findByC_C(long classNameId,
795                    long classPK, int start, int end, OrderByComparator orderByComparator)
796                    throws SystemException {
797                    FinderPath finderPath = null;
798                    Object[] finderArgs = null;
799    
800                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
801                                    (orderByComparator == null)) {
802                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
803                            finderArgs = new Object[] { classNameId, classPK };
804                    }
805                    else {
806                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
807                            finderArgs = new Object[] {
808                                            classNameId, classPK,
809                                            
810                                            start, end, orderByComparator
811                                    };
812                    }
813    
814                    List<SocialActivityCounter> list = (List<SocialActivityCounter>)FinderCacheUtil.getResult(finderPath,
815                                    finderArgs, this);
816    
817                    if ((list != null) && !list.isEmpty()) {
818                            for (SocialActivityCounter socialActivityCounter : list) {
819                                    if ((classNameId != socialActivityCounter.getClassNameId()) ||
820                                                    (classPK != socialActivityCounter.getClassPK())) {
821                                            list = null;
822    
823                                            break;
824                                    }
825                            }
826                    }
827    
828                    if (list == null) {
829                            StringBundler query = null;
830    
831                            if (orderByComparator != null) {
832                                    query = new StringBundler(4 +
833                                                    (orderByComparator.getOrderByFields().length * 3));
834                            }
835                            else {
836                                    query = new StringBundler(3);
837                            }
838    
839                            query.append(_SQL_SELECT_SOCIALACTIVITYCOUNTER_WHERE);
840    
841                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
842    
843                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
844    
845                            if (orderByComparator != null) {
846                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
847                                            orderByComparator);
848                            }
849    
850                            String sql = query.toString();
851    
852                            Session session = null;
853    
854                            try {
855                                    session = openSession();
856    
857                                    Query q = session.createQuery(sql);
858    
859                                    QueryPos qPos = QueryPos.getInstance(q);
860    
861                                    qPos.add(classNameId);
862    
863                                    qPos.add(classPK);
864    
865                                    list = (List<SocialActivityCounter>)QueryUtil.list(q,
866                                                    getDialect(), start, end);
867                            }
868                            catch (Exception e) {
869                                    throw processException(e);
870                            }
871                            finally {
872                                    if (list == null) {
873                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
874                                    }
875                                    else {
876                                            cacheResult(list);
877    
878                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
879                                    }
880    
881                                    closeSession(session);
882                            }
883                    }
884    
885                    return list;
886            }
887    
888            /**
889             * Returns the first social activity counter in the ordered set where classNameId = &#63; and classPK = &#63;.
890             *
891             * @param classNameId the class name ID
892             * @param classPK the class p k
893             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
894             * @return the first matching social activity counter
895             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a matching social activity counter could not be found
896             * @throws SystemException if a system exception occurred
897             */
898            public SocialActivityCounter findByC_C_First(long classNameId,
899                    long classPK, OrderByComparator orderByComparator)
900                    throws NoSuchActivityCounterException, SystemException {
901                    SocialActivityCounter socialActivityCounter = fetchByC_C_First(classNameId,
902                                    classPK, orderByComparator);
903    
904                    if (socialActivityCounter != null) {
905                            return socialActivityCounter;
906                    }
907    
908                    StringBundler msg = new StringBundler(6);
909    
910                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
911    
912                    msg.append("classNameId=");
913                    msg.append(classNameId);
914    
915                    msg.append(", classPK=");
916                    msg.append(classPK);
917    
918                    msg.append(StringPool.CLOSE_CURLY_BRACE);
919    
920                    throw new NoSuchActivityCounterException(msg.toString());
921            }
922    
923            /**
924             * Returns the first social activity counter in the ordered set where classNameId = &#63; and classPK = &#63;.
925             *
926             * @param classNameId the class name ID
927             * @param classPK the class p k
928             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
929             * @return the first matching social activity counter, or <code>null</code> if a matching social activity counter could not be found
930             * @throws SystemException if a system exception occurred
931             */
932            public SocialActivityCounter fetchByC_C_First(long classNameId,
933                    long classPK, OrderByComparator orderByComparator)
934                    throws SystemException {
935                    List<SocialActivityCounter> list = findByC_C(classNameId, classPK, 0,
936                                    1, orderByComparator);
937    
938                    if (!list.isEmpty()) {
939                            return list.get(0);
940                    }
941    
942                    return null;
943            }
944    
945            /**
946             * Returns the last social activity counter in the ordered set where classNameId = &#63; and classPK = &#63;.
947             *
948             * @param classNameId the class name ID
949             * @param classPK the class p k
950             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
951             * @return the last matching social activity counter
952             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a matching social activity counter could not be found
953             * @throws SystemException if a system exception occurred
954             */
955            public SocialActivityCounter findByC_C_Last(long classNameId, long classPK,
956                    OrderByComparator orderByComparator)
957                    throws NoSuchActivityCounterException, SystemException {
958                    SocialActivityCounter socialActivityCounter = fetchByC_C_Last(classNameId,
959                                    classPK, orderByComparator);
960    
961                    if (socialActivityCounter != null) {
962                            return socialActivityCounter;
963                    }
964    
965                    StringBundler msg = new StringBundler(6);
966    
967                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
968    
969                    msg.append("classNameId=");
970                    msg.append(classNameId);
971    
972                    msg.append(", classPK=");
973                    msg.append(classPK);
974    
975                    msg.append(StringPool.CLOSE_CURLY_BRACE);
976    
977                    throw new NoSuchActivityCounterException(msg.toString());
978            }
979    
980            /**
981             * Returns the last social activity counter in the ordered set where classNameId = &#63; and classPK = &#63;.
982             *
983             * @param classNameId the class name ID
984             * @param classPK the class p k
985             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
986             * @return the last matching social activity counter, or <code>null</code> if a matching social activity counter could not be found
987             * @throws SystemException if a system exception occurred
988             */
989            public SocialActivityCounter fetchByC_C_Last(long classNameId,
990                    long classPK, OrderByComparator orderByComparator)
991                    throws SystemException {
992                    int count = countByC_C(classNameId, classPK);
993    
994                    List<SocialActivityCounter> list = findByC_C(classNameId, classPK,
995                                    count - 1, count, orderByComparator);
996    
997                    if (!list.isEmpty()) {
998                            return list.get(0);
999                    }
1000    
1001                    return null;
1002            }
1003    
1004            /**
1005             * Returns the social activity counters before and after the current social activity counter in the ordered set where classNameId = &#63; and classPK = &#63;.
1006             *
1007             * @param activityCounterId the primary key of the current social activity counter
1008             * @param classNameId the class name ID
1009             * @param classPK the class p k
1010             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1011             * @return the previous, current, and next social activity counter
1012             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a social activity counter with the primary key could not be found
1013             * @throws SystemException if a system exception occurred
1014             */
1015            public SocialActivityCounter[] findByC_C_PrevAndNext(
1016                    long activityCounterId, long classNameId, long classPK,
1017                    OrderByComparator orderByComparator)
1018                    throws NoSuchActivityCounterException, SystemException {
1019                    SocialActivityCounter socialActivityCounter = findByPrimaryKey(activityCounterId);
1020    
1021                    Session session = null;
1022    
1023                    try {
1024                            session = openSession();
1025    
1026                            SocialActivityCounter[] array = new SocialActivityCounterImpl[3];
1027    
1028                            array[0] = getByC_C_PrevAndNext(session, socialActivityCounter,
1029                                            classNameId, classPK, orderByComparator, true);
1030    
1031                            array[1] = socialActivityCounter;
1032    
1033                            array[2] = getByC_C_PrevAndNext(session, socialActivityCounter,
1034                                            classNameId, classPK, orderByComparator, false);
1035    
1036                            return array;
1037                    }
1038                    catch (Exception e) {
1039                            throw processException(e);
1040                    }
1041                    finally {
1042                            closeSession(session);
1043                    }
1044            }
1045    
1046            protected SocialActivityCounter getByC_C_PrevAndNext(Session session,
1047                    SocialActivityCounter socialActivityCounter, long classNameId,
1048                    long classPK, OrderByComparator orderByComparator, boolean previous) {
1049                    StringBundler query = null;
1050    
1051                    if (orderByComparator != null) {
1052                            query = new StringBundler(6 +
1053                                            (orderByComparator.getOrderByFields().length * 6));
1054                    }
1055                    else {
1056                            query = new StringBundler(3);
1057                    }
1058    
1059                    query.append(_SQL_SELECT_SOCIALACTIVITYCOUNTER_WHERE);
1060    
1061                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1062    
1063                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1064    
1065                    if (orderByComparator != null) {
1066                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1067    
1068                            if (orderByConditionFields.length > 0) {
1069                                    query.append(WHERE_AND);
1070                            }
1071    
1072                            for (int i = 0; i < orderByConditionFields.length; i++) {
1073                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1074                                    query.append(orderByConditionFields[i]);
1075    
1076                                    if ((i + 1) < orderByConditionFields.length) {
1077                                            if (orderByComparator.isAscending() ^ previous) {
1078                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1079                                            }
1080                                            else {
1081                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1082                                            }
1083                                    }
1084                                    else {
1085                                            if (orderByComparator.isAscending() ^ previous) {
1086                                                    query.append(WHERE_GREATER_THAN);
1087                                            }
1088                                            else {
1089                                                    query.append(WHERE_LESSER_THAN);
1090                                            }
1091                                    }
1092                            }
1093    
1094                            query.append(ORDER_BY_CLAUSE);
1095    
1096                            String[] orderByFields = orderByComparator.getOrderByFields();
1097    
1098                            for (int i = 0; i < orderByFields.length; i++) {
1099                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1100                                    query.append(orderByFields[i]);
1101    
1102                                    if ((i + 1) < orderByFields.length) {
1103                                            if (orderByComparator.isAscending() ^ previous) {
1104                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1105                                            }
1106                                            else {
1107                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1108                                            }
1109                                    }
1110                                    else {
1111                                            if (orderByComparator.isAscending() ^ previous) {
1112                                                    query.append(ORDER_BY_ASC);
1113                                            }
1114                                            else {
1115                                                    query.append(ORDER_BY_DESC);
1116                                            }
1117                                    }
1118                            }
1119                    }
1120    
1121                    String sql = query.toString();
1122    
1123                    Query q = session.createQuery(sql);
1124    
1125                    q.setFirstResult(0);
1126                    q.setMaxResults(2);
1127    
1128                    QueryPos qPos = QueryPos.getInstance(q);
1129    
1130                    qPos.add(classNameId);
1131    
1132                    qPos.add(classPK);
1133    
1134                    if (orderByComparator != null) {
1135                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityCounter);
1136    
1137                            for (Object value : values) {
1138                                    qPos.add(value);
1139                            }
1140                    }
1141    
1142                    List<SocialActivityCounter> list = q.list();
1143    
1144                    if (list.size() == 2) {
1145                            return list.get(1);
1146                    }
1147                    else {
1148                            return null;
1149                    }
1150            }
1151    
1152            /**
1153             * Returns all the social activity counters where groupId = &#63; and classNameId = &#63; and classPK = &#63; and ownerType = &#63;.
1154             *
1155             * @param groupId the group ID
1156             * @param classNameId the class name ID
1157             * @param classPK the class p k
1158             * @param ownerType the owner type
1159             * @return the matching social activity counters
1160             * @throws SystemException if a system exception occurred
1161             */
1162            public List<SocialActivityCounter> findByG_C_C_O(long groupId,
1163                    long classNameId, long classPK, int ownerType)
1164                    throws SystemException {
1165                    return findByG_C_C_O(groupId, classNameId, classPK, ownerType,
1166                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1167            }
1168    
1169            /**
1170             * Returns a range of all the social activity counters where groupId = &#63; and classNameId = &#63; and classPK = &#63; and ownerType = &#63;.
1171             *
1172             * <p>
1173             * 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.
1174             * </p>
1175             *
1176             * @param groupId the group ID
1177             * @param classNameId the class name ID
1178             * @param classPK the class p k
1179             * @param ownerType the owner type
1180             * @param start the lower bound of the range of social activity counters
1181             * @param end the upper bound of the range of social activity counters (not inclusive)
1182             * @return the range of matching social activity counters
1183             * @throws SystemException if a system exception occurred
1184             */
1185            public List<SocialActivityCounter> findByG_C_C_O(long groupId,
1186                    long classNameId, long classPK, int ownerType, int start, int end)
1187                    throws SystemException {
1188                    return findByG_C_C_O(groupId, classNameId, classPK, ownerType, start,
1189                            end, null);
1190            }
1191    
1192            /**
1193             * Returns an ordered range of all the social activity counters where groupId = &#63; and classNameId = &#63; and classPK = &#63; and ownerType = &#63;.
1194             *
1195             * <p>
1196             * 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.
1197             * </p>
1198             *
1199             * @param groupId the group ID
1200             * @param classNameId the class name ID
1201             * @param classPK the class p k
1202             * @param ownerType the owner type
1203             * @param start the lower bound of the range of social activity counters
1204             * @param end the upper bound of the range of social activity counters (not inclusive)
1205             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1206             * @return the ordered range of matching social activity counters
1207             * @throws SystemException if a system exception occurred
1208             */
1209            public List<SocialActivityCounter> findByG_C_C_O(long groupId,
1210                    long classNameId, long classPK, int ownerType, int start, int end,
1211                    OrderByComparator orderByComparator) throws SystemException {
1212                    FinderPath finderPath = null;
1213                    Object[] finderArgs = null;
1214    
1215                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1216                                    (orderByComparator == null)) {
1217                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C_O;
1218                            finderArgs = new Object[] { groupId, classNameId, classPK, ownerType };
1219                    }
1220                    else {
1221                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C_O;
1222                            finderArgs = new Object[] {
1223                                            groupId, classNameId, classPK, ownerType,
1224                                            
1225                                            start, end, orderByComparator
1226                                    };
1227                    }
1228    
1229                    List<SocialActivityCounter> list = (List<SocialActivityCounter>)FinderCacheUtil.getResult(finderPath,
1230                                    finderArgs, this);
1231    
1232                    if ((list != null) && !list.isEmpty()) {
1233                            for (SocialActivityCounter socialActivityCounter : list) {
1234                                    if ((groupId != socialActivityCounter.getGroupId()) ||
1235                                                    (classNameId != socialActivityCounter.getClassNameId()) ||
1236                                                    (classPK != socialActivityCounter.getClassPK()) ||
1237                                                    (ownerType != socialActivityCounter.getOwnerType())) {
1238                                            list = null;
1239    
1240                                            break;
1241                                    }
1242                            }
1243                    }
1244    
1245                    if (list == null) {
1246                            StringBundler query = null;
1247    
1248                            if (orderByComparator != null) {
1249                                    query = new StringBundler(6 +
1250                                                    (orderByComparator.getOrderByFields().length * 3));
1251                            }
1252                            else {
1253                                    query = new StringBundler(5);
1254                            }
1255    
1256                            query.append(_SQL_SELECT_SOCIALACTIVITYCOUNTER_WHERE);
1257    
1258                            query.append(_FINDER_COLUMN_G_C_C_O_GROUPID_2);
1259    
1260                            query.append(_FINDER_COLUMN_G_C_C_O_CLASSNAMEID_2);
1261    
1262                            query.append(_FINDER_COLUMN_G_C_C_O_CLASSPK_2);
1263    
1264                            query.append(_FINDER_COLUMN_G_C_C_O_OWNERTYPE_2);
1265    
1266                            if (orderByComparator != null) {
1267                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1268                                            orderByComparator);
1269                            }
1270    
1271                            String sql = query.toString();
1272    
1273                            Session session = null;
1274    
1275                            try {
1276                                    session = openSession();
1277    
1278                                    Query q = session.createQuery(sql);
1279    
1280                                    QueryPos qPos = QueryPos.getInstance(q);
1281    
1282                                    qPos.add(groupId);
1283    
1284                                    qPos.add(classNameId);
1285    
1286                                    qPos.add(classPK);
1287    
1288                                    qPos.add(ownerType);
1289    
1290                                    list = (List<SocialActivityCounter>)QueryUtil.list(q,
1291                                                    getDialect(), start, end);
1292                            }
1293                            catch (Exception e) {
1294                                    throw processException(e);
1295                            }
1296                            finally {
1297                                    if (list == null) {
1298                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1299                                    }
1300                                    else {
1301                                            cacheResult(list);
1302    
1303                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1304                                    }
1305    
1306                                    closeSession(session);
1307                            }
1308                    }
1309    
1310                    return list;
1311            }
1312    
1313            /**
1314             * Returns the first social activity counter in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and ownerType = &#63;.
1315             *
1316             * @param groupId the group ID
1317             * @param classNameId the class name ID
1318             * @param classPK the class p k
1319             * @param ownerType the owner type
1320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1321             * @return the first matching social activity counter
1322             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a matching social activity counter could not be found
1323             * @throws SystemException if a system exception occurred
1324             */
1325            public SocialActivityCounter findByG_C_C_O_First(long groupId,
1326                    long classNameId, long classPK, int ownerType,
1327                    OrderByComparator orderByComparator)
1328                    throws NoSuchActivityCounterException, SystemException {
1329                    SocialActivityCounter socialActivityCounter = fetchByG_C_C_O_First(groupId,
1330                                    classNameId, classPK, ownerType, orderByComparator);
1331    
1332                    if (socialActivityCounter != null) {
1333                            return socialActivityCounter;
1334                    }
1335    
1336                    StringBundler msg = new StringBundler(10);
1337    
1338                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1339    
1340                    msg.append("groupId=");
1341                    msg.append(groupId);
1342    
1343                    msg.append(", classNameId=");
1344                    msg.append(classNameId);
1345    
1346                    msg.append(", classPK=");
1347                    msg.append(classPK);
1348    
1349                    msg.append(", ownerType=");
1350                    msg.append(ownerType);
1351    
1352                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1353    
1354                    throw new NoSuchActivityCounterException(msg.toString());
1355            }
1356    
1357            /**
1358             * Returns the first social activity counter in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and ownerType = &#63;.
1359             *
1360             * @param groupId the group ID
1361             * @param classNameId the class name ID
1362             * @param classPK the class p k
1363             * @param ownerType the owner type
1364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1365             * @return the first matching social activity counter, or <code>null</code> if a matching social activity counter could not be found
1366             * @throws SystemException if a system exception occurred
1367             */
1368            public SocialActivityCounter fetchByG_C_C_O_First(long groupId,
1369                    long classNameId, long classPK, int ownerType,
1370                    OrderByComparator orderByComparator) throws SystemException {
1371                    List<SocialActivityCounter> list = findByG_C_C_O(groupId, classNameId,
1372                                    classPK, ownerType, 0, 1, orderByComparator);
1373    
1374                    if (!list.isEmpty()) {
1375                            return list.get(0);
1376                    }
1377    
1378                    return null;
1379            }
1380    
1381            /**
1382             * Returns the last social activity counter in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and ownerType = &#63;.
1383             *
1384             * @param groupId the group ID
1385             * @param classNameId the class name ID
1386             * @param classPK the class p k
1387             * @param ownerType the owner type
1388             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1389             * @return the last matching social activity counter
1390             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a matching social activity counter could not be found
1391             * @throws SystemException if a system exception occurred
1392             */
1393            public SocialActivityCounter findByG_C_C_O_Last(long groupId,
1394                    long classNameId, long classPK, int ownerType,
1395                    OrderByComparator orderByComparator)
1396                    throws NoSuchActivityCounterException, SystemException {
1397                    SocialActivityCounter socialActivityCounter = fetchByG_C_C_O_Last(groupId,
1398                                    classNameId, classPK, ownerType, orderByComparator);
1399    
1400                    if (socialActivityCounter != null) {
1401                            return socialActivityCounter;
1402                    }
1403    
1404                    StringBundler msg = new StringBundler(10);
1405    
1406                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1407    
1408                    msg.append("groupId=");
1409                    msg.append(groupId);
1410    
1411                    msg.append(", classNameId=");
1412                    msg.append(classNameId);
1413    
1414                    msg.append(", classPK=");
1415                    msg.append(classPK);
1416    
1417                    msg.append(", ownerType=");
1418                    msg.append(ownerType);
1419    
1420                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1421    
1422                    throw new NoSuchActivityCounterException(msg.toString());
1423            }
1424    
1425            /**
1426             * Returns the last social activity counter in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and ownerType = &#63;.
1427             *
1428             * @param groupId the group ID
1429             * @param classNameId the class name ID
1430             * @param classPK the class p k
1431             * @param ownerType the owner type
1432             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1433             * @return the last matching social activity counter, or <code>null</code> if a matching social activity counter could not be found
1434             * @throws SystemException if a system exception occurred
1435             */
1436            public SocialActivityCounter fetchByG_C_C_O_Last(long groupId,
1437                    long classNameId, long classPK, int ownerType,
1438                    OrderByComparator orderByComparator) throws SystemException {
1439                    int count = countByG_C_C_O(groupId, classNameId, classPK, ownerType);
1440    
1441                    List<SocialActivityCounter> list = findByG_C_C_O(groupId, classNameId,
1442                                    classPK, ownerType, count - 1, count, orderByComparator);
1443    
1444                    if (!list.isEmpty()) {
1445                            return list.get(0);
1446                    }
1447    
1448                    return null;
1449            }
1450    
1451            /**
1452             * Returns the social activity counters before and after the current social activity counter in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63; and ownerType = &#63;.
1453             *
1454             * @param activityCounterId the primary key of the current social activity counter
1455             * @param groupId the group ID
1456             * @param classNameId the class name ID
1457             * @param classPK the class p k
1458             * @param ownerType the owner type
1459             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1460             * @return the previous, current, and next social activity counter
1461             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a social activity counter with the primary key could not be found
1462             * @throws SystemException if a system exception occurred
1463             */
1464            public SocialActivityCounter[] findByG_C_C_O_PrevAndNext(
1465                    long activityCounterId, long groupId, long classNameId, long classPK,
1466                    int ownerType, OrderByComparator orderByComparator)
1467                    throws NoSuchActivityCounterException, SystemException {
1468                    SocialActivityCounter socialActivityCounter = findByPrimaryKey(activityCounterId);
1469    
1470                    Session session = null;
1471    
1472                    try {
1473                            session = openSession();
1474    
1475                            SocialActivityCounter[] array = new SocialActivityCounterImpl[3];
1476    
1477                            array[0] = getByG_C_C_O_PrevAndNext(session, socialActivityCounter,
1478                                            groupId, classNameId, classPK, ownerType,
1479                                            orderByComparator, true);
1480    
1481                            array[1] = socialActivityCounter;
1482    
1483                            array[2] = getByG_C_C_O_PrevAndNext(session, socialActivityCounter,
1484                                            groupId, classNameId, classPK, ownerType,
1485                                            orderByComparator, false);
1486    
1487                            return array;
1488                    }
1489                    catch (Exception e) {
1490                            throw processException(e);
1491                    }
1492                    finally {
1493                            closeSession(session);
1494                    }
1495            }
1496    
1497            protected SocialActivityCounter getByG_C_C_O_PrevAndNext(Session session,
1498                    SocialActivityCounter socialActivityCounter, long groupId,
1499                    long classNameId, long classPK, int ownerType,
1500                    OrderByComparator orderByComparator, boolean previous) {
1501                    StringBundler query = null;
1502    
1503                    if (orderByComparator != null) {
1504                            query = new StringBundler(6 +
1505                                            (orderByComparator.getOrderByFields().length * 6));
1506                    }
1507                    else {
1508                            query = new StringBundler(3);
1509                    }
1510    
1511                    query.append(_SQL_SELECT_SOCIALACTIVITYCOUNTER_WHERE);
1512    
1513                    query.append(_FINDER_COLUMN_G_C_C_O_GROUPID_2);
1514    
1515                    query.append(_FINDER_COLUMN_G_C_C_O_CLASSNAMEID_2);
1516    
1517                    query.append(_FINDER_COLUMN_G_C_C_O_CLASSPK_2);
1518    
1519                    query.append(_FINDER_COLUMN_G_C_C_O_OWNERTYPE_2);
1520    
1521                    if (orderByComparator != null) {
1522                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1523    
1524                            if (orderByConditionFields.length > 0) {
1525                                    query.append(WHERE_AND);
1526                            }
1527    
1528                            for (int i = 0; i < orderByConditionFields.length; i++) {
1529                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1530                                    query.append(orderByConditionFields[i]);
1531    
1532                                    if ((i + 1) < orderByConditionFields.length) {
1533                                            if (orderByComparator.isAscending() ^ previous) {
1534                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1535                                            }
1536                                            else {
1537                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1538                                            }
1539                                    }
1540                                    else {
1541                                            if (orderByComparator.isAscending() ^ previous) {
1542                                                    query.append(WHERE_GREATER_THAN);
1543                                            }
1544                                            else {
1545                                                    query.append(WHERE_LESSER_THAN);
1546                                            }
1547                                    }
1548                            }
1549    
1550                            query.append(ORDER_BY_CLAUSE);
1551    
1552                            String[] orderByFields = orderByComparator.getOrderByFields();
1553    
1554                            for (int i = 0; i < orderByFields.length; i++) {
1555                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1556                                    query.append(orderByFields[i]);
1557    
1558                                    if ((i + 1) < orderByFields.length) {
1559                                            if (orderByComparator.isAscending() ^ previous) {
1560                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1561                                            }
1562                                            else {
1563                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1564                                            }
1565                                    }
1566                                    else {
1567                                            if (orderByComparator.isAscending() ^ previous) {
1568                                                    query.append(ORDER_BY_ASC);
1569                                            }
1570                                            else {
1571                                                    query.append(ORDER_BY_DESC);
1572                                            }
1573                                    }
1574                            }
1575                    }
1576    
1577                    String sql = query.toString();
1578    
1579                    Query q = session.createQuery(sql);
1580    
1581                    q.setFirstResult(0);
1582                    q.setMaxResults(2);
1583    
1584                    QueryPos qPos = QueryPos.getInstance(q);
1585    
1586                    qPos.add(groupId);
1587    
1588                    qPos.add(classNameId);
1589    
1590                    qPos.add(classPK);
1591    
1592                    qPos.add(ownerType);
1593    
1594                    if (orderByComparator != null) {
1595                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityCounter);
1596    
1597                            for (Object value : values) {
1598                                    qPos.add(value);
1599                            }
1600                    }
1601    
1602                    List<SocialActivityCounter> list = q.list();
1603    
1604                    if (list.size() == 2) {
1605                            return list.get(1);
1606                    }
1607                    else {
1608                            return null;
1609                    }
1610            }
1611    
1612            /**
1613             * Returns the social activity counter where groupId = &#63; and classNameId = &#63; and classPK = &#63; and name = &#63; and ownerType = &#63; and startPeriod = &#63; or throws a {@link com.liferay.portlet.social.NoSuchActivityCounterException} if it could not be found.
1614             *
1615             * @param groupId the group ID
1616             * @param classNameId the class name ID
1617             * @param classPK the class p k
1618             * @param name the name
1619             * @param ownerType the owner type
1620             * @param startPeriod the start period
1621             * @return the matching social activity counter
1622             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a matching social activity counter could not be found
1623             * @throws SystemException if a system exception occurred
1624             */
1625            public SocialActivityCounter findByG_C_C_N_O_S(long groupId,
1626                    long classNameId, long classPK, String name, int ownerType,
1627                    int startPeriod) throws NoSuchActivityCounterException, SystemException {
1628                    SocialActivityCounter socialActivityCounter = fetchByG_C_C_N_O_S(groupId,
1629                                    classNameId, classPK, name, ownerType, startPeriod);
1630    
1631                    if (socialActivityCounter == null) {
1632                            StringBundler msg = new StringBundler(14);
1633    
1634                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1635    
1636                            msg.append("groupId=");
1637                            msg.append(groupId);
1638    
1639                            msg.append(", classNameId=");
1640                            msg.append(classNameId);
1641    
1642                            msg.append(", classPK=");
1643                            msg.append(classPK);
1644    
1645                            msg.append(", name=");
1646                            msg.append(name);
1647    
1648                            msg.append(", ownerType=");
1649                            msg.append(ownerType);
1650    
1651                            msg.append(", startPeriod=");
1652                            msg.append(startPeriod);
1653    
1654                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1655    
1656                            if (_log.isWarnEnabled()) {
1657                                    _log.warn(msg.toString());
1658                            }
1659    
1660                            throw new NoSuchActivityCounterException(msg.toString());
1661                    }
1662    
1663                    return socialActivityCounter;
1664            }
1665    
1666            /**
1667             * Returns the social activity counter where groupId = &#63; and classNameId = &#63; and classPK = &#63; and name = &#63; and ownerType = &#63; and startPeriod = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1668             *
1669             * @param groupId the group ID
1670             * @param classNameId the class name ID
1671             * @param classPK the class p k
1672             * @param name the name
1673             * @param ownerType the owner type
1674             * @param startPeriod the start period
1675             * @return the matching social activity counter, or <code>null</code> if a matching social activity counter could not be found
1676             * @throws SystemException if a system exception occurred
1677             */
1678            public SocialActivityCounter fetchByG_C_C_N_O_S(long groupId,
1679                    long classNameId, long classPK, String name, int ownerType,
1680                    int startPeriod) throws SystemException {
1681                    return fetchByG_C_C_N_O_S(groupId, classNameId, classPK, name,
1682                            ownerType, startPeriod, true);
1683            }
1684    
1685            /**
1686             * Returns the social activity counter where groupId = &#63; and classNameId = &#63; and classPK = &#63; and name = &#63; and ownerType = &#63; and startPeriod = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1687             *
1688             * @param groupId the group ID
1689             * @param classNameId the class name ID
1690             * @param classPK the class p k
1691             * @param name the name
1692             * @param ownerType the owner type
1693             * @param startPeriod the start period
1694             * @param retrieveFromCache whether to use the finder cache
1695             * @return the matching social activity counter, or <code>null</code> if a matching social activity counter could not be found
1696             * @throws SystemException if a system exception occurred
1697             */
1698            public SocialActivityCounter fetchByG_C_C_N_O_S(long groupId,
1699                    long classNameId, long classPK, String name, int ownerType,
1700                    int startPeriod, boolean retrieveFromCache) throws SystemException {
1701                    Object[] finderArgs = new Object[] {
1702                                    groupId, classNameId, classPK, name, ownerType, startPeriod
1703                            };
1704    
1705                    Object result = null;
1706    
1707                    if (retrieveFromCache) {
1708                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_S,
1709                                            finderArgs, this);
1710                    }
1711    
1712                    if (result instanceof SocialActivityCounter) {
1713                            SocialActivityCounter socialActivityCounter = (SocialActivityCounter)result;
1714    
1715                            if ((groupId != socialActivityCounter.getGroupId()) ||
1716                                            (classNameId != socialActivityCounter.getClassNameId()) ||
1717                                            (classPK != socialActivityCounter.getClassPK()) ||
1718                                            !Validator.equals(name, socialActivityCounter.getName()) ||
1719                                            (ownerType != socialActivityCounter.getOwnerType()) ||
1720                                            (startPeriod != socialActivityCounter.getStartPeriod())) {
1721                                    result = null;
1722                            }
1723                    }
1724    
1725                    if (result == null) {
1726                            StringBundler query = new StringBundler(7);
1727    
1728                            query.append(_SQL_SELECT_SOCIALACTIVITYCOUNTER_WHERE);
1729    
1730                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_GROUPID_2);
1731    
1732                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_CLASSNAMEID_2);
1733    
1734                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_CLASSPK_2);
1735    
1736                            if (name == null) {
1737                                    query.append(_FINDER_COLUMN_G_C_C_N_O_S_NAME_1);
1738                            }
1739                            else {
1740                                    if (name.equals(StringPool.BLANK)) {
1741                                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_NAME_3);
1742                                    }
1743                                    else {
1744                                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_NAME_2);
1745                                    }
1746                            }
1747    
1748                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_OWNERTYPE_2);
1749    
1750                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_STARTPERIOD_2);
1751    
1752                            String sql = query.toString();
1753    
1754                            Session session = null;
1755    
1756                            try {
1757                                    session = openSession();
1758    
1759                                    Query q = session.createQuery(sql);
1760    
1761                                    QueryPos qPos = QueryPos.getInstance(q);
1762    
1763                                    qPos.add(groupId);
1764    
1765                                    qPos.add(classNameId);
1766    
1767                                    qPos.add(classPK);
1768    
1769                                    if (name != null) {
1770                                            qPos.add(name);
1771                                    }
1772    
1773                                    qPos.add(ownerType);
1774    
1775                                    qPos.add(startPeriod);
1776    
1777                                    List<SocialActivityCounter> list = q.list();
1778    
1779                                    result = list;
1780    
1781                                    SocialActivityCounter socialActivityCounter = null;
1782    
1783                                    if (list.isEmpty()) {
1784                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_S,
1785                                                    finderArgs, list);
1786                                    }
1787                                    else {
1788                                            socialActivityCounter = list.get(0);
1789    
1790                                            cacheResult(socialActivityCounter);
1791    
1792                                            if ((socialActivityCounter.getGroupId() != groupId) ||
1793                                                            (socialActivityCounter.getClassNameId() != classNameId) ||
1794                                                            (socialActivityCounter.getClassPK() != classPK) ||
1795                                                            (socialActivityCounter.getName() == null) ||
1796                                                            !socialActivityCounter.getName().equals(name) ||
1797                                                            (socialActivityCounter.getOwnerType() != ownerType) ||
1798                                                            (socialActivityCounter.getStartPeriod() != startPeriod)) {
1799                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_S,
1800                                                            finderArgs, socialActivityCounter);
1801                                            }
1802                                    }
1803    
1804                                    return socialActivityCounter;
1805                            }
1806                            catch (Exception e) {
1807                                    throw processException(e);
1808                            }
1809                            finally {
1810                                    if (result == null) {
1811                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_S,
1812                                                    finderArgs);
1813                                    }
1814    
1815                                    closeSession(session);
1816                            }
1817                    }
1818                    else {
1819                            if (result instanceof List<?>) {
1820                                    return null;
1821                            }
1822                            else {
1823                                    return (SocialActivityCounter)result;
1824                            }
1825                    }
1826            }
1827    
1828            /**
1829             * Returns the social activity counter where groupId = &#63; and classNameId = &#63; and classPK = &#63; and name = &#63; and ownerType = &#63; and endPeriod = &#63; or throws a {@link com.liferay.portlet.social.NoSuchActivityCounterException} if it could not be found.
1830             *
1831             * @param groupId the group ID
1832             * @param classNameId the class name ID
1833             * @param classPK the class p k
1834             * @param name the name
1835             * @param ownerType the owner type
1836             * @param endPeriod the end period
1837             * @return the matching social activity counter
1838             * @throws com.liferay.portlet.social.NoSuchActivityCounterException if a matching social activity counter could not be found
1839             * @throws SystemException if a system exception occurred
1840             */
1841            public SocialActivityCounter findByG_C_C_N_O_E(long groupId,
1842                    long classNameId, long classPK, String name, int ownerType,
1843                    int endPeriod) throws NoSuchActivityCounterException, SystemException {
1844                    SocialActivityCounter socialActivityCounter = fetchByG_C_C_N_O_E(groupId,
1845                                    classNameId, classPK, name, ownerType, endPeriod);
1846    
1847                    if (socialActivityCounter == null) {
1848                            StringBundler msg = new StringBundler(14);
1849    
1850                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1851    
1852                            msg.append("groupId=");
1853                            msg.append(groupId);
1854    
1855                            msg.append(", classNameId=");
1856                            msg.append(classNameId);
1857    
1858                            msg.append(", classPK=");
1859                            msg.append(classPK);
1860    
1861                            msg.append(", name=");
1862                            msg.append(name);
1863    
1864                            msg.append(", ownerType=");
1865                            msg.append(ownerType);
1866    
1867                            msg.append(", endPeriod=");
1868                            msg.append(endPeriod);
1869    
1870                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1871    
1872                            if (_log.isWarnEnabled()) {
1873                                    _log.warn(msg.toString());
1874                            }
1875    
1876                            throw new NoSuchActivityCounterException(msg.toString());
1877                    }
1878    
1879                    return socialActivityCounter;
1880            }
1881    
1882            /**
1883             * Returns the social activity counter where groupId = &#63; and classNameId = &#63; and classPK = &#63; and name = &#63; and ownerType = &#63; and endPeriod = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1884             *
1885             * @param groupId the group ID
1886             * @param classNameId the class name ID
1887             * @param classPK the class p k
1888             * @param name the name
1889             * @param ownerType the owner type
1890             * @param endPeriod the end period
1891             * @return the matching social activity counter, or <code>null</code> if a matching social activity counter could not be found
1892             * @throws SystemException if a system exception occurred
1893             */
1894            public SocialActivityCounter fetchByG_C_C_N_O_E(long groupId,
1895                    long classNameId, long classPK, String name, int ownerType,
1896                    int endPeriod) throws SystemException {
1897                    return fetchByG_C_C_N_O_E(groupId, classNameId, classPK, name,
1898                            ownerType, endPeriod, true);
1899            }
1900    
1901            /**
1902             * Returns the social activity counter where groupId = &#63; and classNameId = &#63; and classPK = &#63; and name = &#63; and ownerType = &#63; and endPeriod = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1903             *
1904             * @param groupId the group ID
1905             * @param classNameId the class name ID
1906             * @param classPK the class p k
1907             * @param name the name
1908             * @param ownerType the owner type
1909             * @param endPeriod the end period
1910             * @param retrieveFromCache whether to use the finder cache
1911             * @return the matching social activity counter, or <code>null</code> if a matching social activity counter could not be found
1912             * @throws SystemException if a system exception occurred
1913             */
1914            public SocialActivityCounter fetchByG_C_C_N_O_E(long groupId,
1915                    long classNameId, long classPK, String name, int ownerType,
1916                    int endPeriod, boolean retrieveFromCache) throws SystemException {
1917                    Object[] finderArgs = new Object[] {
1918                                    groupId, classNameId, classPK, name, ownerType, endPeriod
1919                            };
1920    
1921                    Object result = null;
1922    
1923                    if (retrieveFromCache) {
1924                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_E,
1925                                            finderArgs, this);
1926                    }
1927    
1928                    if (result instanceof SocialActivityCounter) {
1929                            SocialActivityCounter socialActivityCounter = (SocialActivityCounter)result;
1930    
1931                            if ((groupId != socialActivityCounter.getGroupId()) ||
1932                                            (classNameId != socialActivityCounter.getClassNameId()) ||
1933                                            (classPK != socialActivityCounter.getClassPK()) ||
1934                                            !Validator.equals(name, socialActivityCounter.getName()) ||
1935                                            (ownerType != socialActivityCounter.getOwnerType()) ||
1936                                            (endPeriod != socialActivityCounter.getEndPeriod())) {
1937                                    result = null;
1938                            }
1939                    }
1940    
1941                    if (result == null) {
1942                            StringBundler query = new StringBundler(7);
1943    
1944                            query.append(_SQL_SELECT_SOCIALACTIVITYCOUNTER_WHERE);
1945    
1946                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_GROUPID_2);
1947    
1948                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_CLASSNAMEID_2);
1949    
1950                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_CLASSPK_2);
1951    
1952                            if (name == null) {
1953                                    query.append(_FINDER_COLUMN_G_C_C_N_O_E_NAME_1);
1954                            }
1955                            else {
1956                                    if (name.equals(StringPool.BLANK)) {
1957                                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_NAME_3);
1958                                    }
1959                                    else {
1960                                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_NAME_2);
1961                                    }
1962                            }
1963    
1964                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_OWNERTYPE_2);
1965    
1966                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_ENDPERIOD_2);
1967    
1968                            String sql = query.toString();
1969    
1970                            Session session = null;
1971    
1972                            try {
1973                                    session = openSession();
1974    
1975                                    Query q = session.createQuery(sql);
1976    
1977                                    QueryPos qPos = QueryPos.getInstance(q);
1978    
1979                                    qPos.add(groupId);
1980    
1981                                    qPos.add(classNameId);
1982    
1983                                    qPos.add(classPK);
1984    
1985                                    if (name != null) {
1986                                            qPos.add(name);
1987                                    }
1988    
1989                                    qPos.add(ownerType);
1990    
1991                                    qPos.add(endPeriod);
1992    
1993                                    List<SocialActivityCounter> list = q.list();
1994    
1995                                    result = list;
1996    
1997                                    SocialActivityCounter socialActivityCounter = null;
1998    
1999                                    if (list.isEmpty()) {
2000                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_E,
2001                                                    finderArgs, list);
2002                                    }
2003                                    else {
2004                                            socialActivityCounter = list.get(0);
2005    
2006                                            cacheResult(socialActivityCounter);
2007    
2008                                            if ((socialActivityCounter.getGroupId() != groupId) ||
2009                                                            (socialActivityCounter.getClassNameId() != classNameId) ||
2010                                                            (socialActivityCounter.getClassPK() != classPK) ||
2011                                                            (socialActivityCounter.getName() == null) ||
2012                                                            !socialActivityCounter.getName().equals(name) ||
2013                                                            (socialActivityCounter.getOwnerType() != ownerType) ||
2014                                                            (socialActivityCounter.getEndPeriod() != endPeriod)) {
2015                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_E,
2016                                                            finderArgs, socialActivityCounter);
2017                                            }
2018                                    }
2019    
2020                                    return socialActivityCounter;
2021                            }
2022                            catch (Exception e) {
2023                                    throw processException(e);
2024                            }
2025                            finally {
2026                                    if (result == null) {
2027                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_C_N_O_E,
2028                                                    finderArgs);
2029                                    }
2030    
2031                                    closeSession(session);
2032                            }
2033                    }
2034                    else {
2035                            if (result instanceof List<?>) {
2036                                    return null;
2037                            }
2038                            else {
2039                                    return (SocialActivityCounter)result;
2040                            }
2041                    }
2042            }
2043    
2044            /**
2045             * Returns all the social activity counters.
2046             *
2047             * @return the social activity counters
2048             * @throws SystemException if a system exception occurred
2049             */
2050            public List<SocialActivityCounter> findAll() throws SystemException {
2051                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2052            }
2053    
2054            /**
2055             * Returns a range of all the social activity counters.
2056             *
2057             * <p>
2058             * 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.
2059             * </p>
2060             *
2061             * @param start the lower bound of the range of social activity counters
2062             * @param end the upper bound of the range of social activity counters (not inclusive)
2063             * @return the range of social activity counters
2064             * @throws SystemException if a system exception occurred
2065             */
2066            public List<SocialActivityCounter> findAll(int start, int end)
2067                    throws SystemException {
2068                    return findAll(start, end, null);
2069            }
2070    
2071            /**
2072             * Returns an ordered range of all the social activity counters.
2073             *
2074             * <p>
2075             * 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.
2076             * </p>
2077             *
2078             * @param start the lower bound of the range of social activity counters
2079             * @param end the upper bound of the range of social activity counters (not inclusive)
2080             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2081             * @return the ordered range of social activity counters
2082             * @throws SystemException if a system exception occurred
2083             */
2084            public List<SocialActivityCounter> findAll(int start, int end,
2085                    OrderByComparator orderByComparator) throws SystemException {
2086                    FinderPath finderPath = null;
2087                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2088    
2089                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2090                                    (orderByComparator == null)) {
2091                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2092                            finderArgs = FINDER_ARGS_EMPTY;
2093                    }
2094                    else {
2095                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2096                            finderArgs = new Object[] { start, end, orderByComparator };
2097                    }
2098    
2099                    List<SocialActivityCounter> list = (List<SocialActivityCounter>)FinderCacheUtil.getResult(finderPath,
2100                                    finderArgs, this);
2101    
2102                    if (list == null) {
2103                            StringBundler query = null;
2104                            String sql = null;
2105    
2106                            if (orderByComparator != null) {
2107                                    query = new StringBundler(2 +
2108                                                    (orderByComparator.getOrderByFields().length * 3));
2109    
2110                                    query.append(_SQL_SELECT_SOCIALACTIVITYCOUNTER);
2111    
2112                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2113                                            orderByComparator);
2114    
2115                                    sql = query.toString();
2116                            }
2117                            else {
2118                                    sql = _SQL_SELECT_SOCIALACTIVITYCOUNTER;
2119                            }
2120    
2121                            Session session = null;
2122    
2123                            try {
2124                                    session = openSession();
2125    
2126                                    Query q = session.createQuery(sql);
2127    
2128                                    if (orderByComparator == null) {
2129                                            list = (List<SocialActivityCounter>)QueryUtil.list(q,
2130                                                            getDialect(), start, end, false);
2131    
2132                                            Collections.sort(list);
2133                                    }
2134                                    else {
2135                                            list = (List<SocialActivityCounter>)QueryUtil.list(q,
2136                                                            getDialect(), start, end);
2137                                    }
2138                            }
2139                            catch (Exception e) {
2140                                    throw processException(e);
2141                            }
2142                            finally {
2143                                    if (list == null) {
2144                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2145                                    }
2146                                    else {
2147                                            cacheResult(list);
2148    
2149                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2150                                    }
2151    
2152                                    closeSession(session);
2153                            }
2154                    }
2155    
2156                    return list;
2157            }
2158    
2159            /**
2160             * Removes all the social activity counters where classNameId = &#63; and classPK = &#63; from the database.
2161             *
2162             * @param classNameId the class name ID
2163             * @param classPK the class p k
2164             * @throws SystemException if a system exception occurred
2165             */
2166            public void removeByC_C(long classNameId, long classPK)
2167                    throws SystemException {
2168                    for (SocialActivityCounter socialActivityCounter : findByC_C(
2169                                    classNameId, classPK)) {
2170                            remove(socialActivityCounter);
2171                    }
2172            }
2173    
2174            /**
2175             * Removes all the social activity counters where groupId = &#63; and classNameId = &#63; and classPK = &#63; and ownerType = &#63; from the database.
2176             *
2177             * @param groupId the group ID
2178             * @param classNameId the class name ID
2179             * @param classPK the class p k
2180             * @param ownerType the owner type
2181             * @throws SystemException if a system exception occurred
2182             */
2183            public void removeByG_C_C_O(long groupId, long classNameId, long classPK,
2184                    int ownerType) throws SystemException {
2185                    for (SocialActivityCounter socialActivityCounter : findByG_C_C_O(
2186                                    groupId, classNameId, classPK, ownerType)) {
2187                            remove(socialActivityCounter);
2188                    }
2189            }
2190    
2191            /**
2192             * Removes the social activity counter where groupId = &#63; and classNameId = &#63; and classPK = &#63; and name = &#63; and ownerType = &#63; and startPeriod = &#63; from the database.
2193             *
2194             * @param groupId the group ID
2195             * @param classNameId the class name ID
2196             * @param classPK the class p k
2197             * @param name the name
2198             * @param ownerType the owner type
2199             * @param startPeriod the start period
2200             * @return the social activity counter that was removed
2201             * @throws SystemException if a system exception occurred
2202             */
2203            public SocialActivityCounter removeByG_C_C_N_O_S(long groupId,
2204                    long classNameId, long classPK, String name, int ownerType,
2205                    int startPeriod) throws NoSuchActivityCounterException, SystemException {
2206                    SocialActivityCounter socialActivityCounter = findByG_C_C_N_O_S(groupId,
2207                                    classNameId, classPK, name, ownerType, startPeriod);
2208    
2209                    return remove(socialActivityCounter);
2210            }
2211    
2212            /**
2213             * Removes the social activity counter where groupId = &#63; and classNameId = &#63; and classPK = &#63; and name = &#63; and ownerType = &#63; and endPeriod = &#63; from the database.
2214             *
2215             * @param groupId the group ID
2216             * @param classNameId the class name ID
2217             * @param classPK the class p k
2218             * @param name the name
2219             * @param ownerType the owner type
2220             * @param endPeriod the end period
2221             * @return the social activity counter that was removed
2222             * @throws SystemException if a system exception occurred
2223             */
2224            public SocialActivityCounter removeByG_C_C_N_O_E(long groupId,
2225                    long classNameId, long classPK, String name, int ownerType,
2226                    int endPeriod) throws NoSuchActivityCounterException, SystemException {
2227                    SocialActivityCounter socialActivityCounter = findByG_C_C_N_O_E(groupId,
2228                                    classNameId, classPK, name, ownerType, endPeriod);
2229    
2230                    return remove(socialActivityCounter);
2231            }
2232    
2233            /**
2234             * Removes all the social activity counters from the database.
2235             *
2236             * @throws SystemException if a system exception occurred
2237             */
2238            public void removeAll() throws SystemException {
2239                    for (SocialActivityCounter socialActivityCounter : findAll()) {
2240                            remove(socialActivityCounter);
2241                    }
2242            }
2243    
2244            /**
2245             * Returns the number of social activity counters where classNameId = &#63; and classPK = &#63;.
2246             *
2247             * @param classNameId the class name ID
2248             * @param classPK the class p k
2249             * @return the number of matching social activity counters
2250             * @throws SystemException if a system exception occurred
2251             */
2252            public int countByC_C(long classNameId, long classPK)
2253                    throws SystemException {
2254                    Object[] finderArgs = new Object[] { classNameId, classPK };
2255    
2256                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
2257                                    finderArgs, this);
2258    
2259                    if (count == null) {
2260                            StringBundler query = new StringBundler(3);
2261    
2262                            query.append(_SQL_COUNT_SOCIALACTIVITYCOUNTER_WHERE);
2263    
2264                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2265    
2266                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2267    
2268                            String sql = query.toString();
2269    
2270                            Session session = null;
2271    
2272                            try {
2273                                    session = openSession();
2274    
2275                                    Query q = session.createQuery(sql);
2276    
2277                                    QueryPos qPos = QueryPos.getInstance(q);
2278    
2279                                    qPos.add(classNameId);
2280    
2281                                    qPos.add(classPK);
2282    
2283                                    count = (Long)q.uniqueResult();
2284                            }
2285                            catch (Exception e) {
2286                                    throw processException(e);
2287                            }
2288                            finally {
2289                                    if (count == null) {
2290                                            count = Long.valueOf(0);
2291                                    }
2292    
2293                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
2294                                            count);
2295    
2296                                    closeSession(session);
2297                            }
2298                    }
2299    
2300                    return count.intValue();
2301            }
2302    
2303            /**
2304             * Returns the number of social activity counters where groupId = &#63; and classNameId = &#63; and classPK = &#63; and ownerType = &#63;.
2305             *
2306             * @param groupId the group ID
2307             * @param classNameId the class name ID
2308             * @param classPK the class p k
2309             * @param ownerType the owner type
2310             * @return the number of matching social activity counters
2311             * @throws SystemException if a system exception occurred
2312             */
2313            public int countByG_C_C_O(long groupId, long classNameId, long classPK,
2314                    int ownerType) throws SystemException {
2315                    Object[] finderArgs = new Object[] {
2316                                    groupId, classNameId, classPK, ownerType
2317                            };
2318    
2319                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_C_O,
2320                                    finderArgs, this);
2321    
2322                    if (count == null) {
2323                            StringBundler query = new StringBundler(5);
2324    
2325                            query.append(_SQL_COUNT_SOCIALACTIVITYCOUNTER_WHERE);
2326    
2327                            query.append(_FINDER_COLUMN_G_C_C_O_GROUPID_2);
2328    
2329                            query.append(_FINDER_COLUMN_G_C_C_O_CLASSNAMEID_2);
2330    
2331                            query.append(_FINDER_COLUMN_G_C_C_O_CLASSPK_2);
2332    
2333                            query.append(_FINDER_COLUMN_G_C_C_O_OWNERTYPE_2);
2334    
2335                            String sql = query.toString();
2336    
2337                            Session session = null;
2338    
2339                            try {
2340                                    session = openSession();
2341    
2342                                    Query q = session.createQuery(sql);
2343    
2344                                    QueryPos qPos = QueryPos.getInstance(q);
2345    
2346                                    qPos.add(groupId);
2347    
2348                                    qPos.add(classNameId);
2349    
2350                                    qPos.add(classPK);
2351    
2352                                    qPos.add(ownerType);
2353    
2354                                    count = (Long)q.uniqueResult();
2355                            }
2356                            catch (Exception e) {
2357                                    throw processException(e);
2358                            }
2359                            finally {
2360                                    if (count == null) {
2361                                            count = Long.valueOf(0);
2362                                    }
2363    
2364                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_O,
2365                                            finderArgs, count);
2366    
2367                                    closeSession(session);
2368                            }
2369                    }
2370    
2371                    return count.intValue();
2372            }
2373    
2374            /**
2375             * Returns the number of social activity counters where groupId = &#63; and classNameId = &#63; and classPK = &#63; and name = &#63; and ownerType = &#63; and startPeriod = &#63;.
2376             *
2377             * @param groupId the group ID
2378             * @param classNameId the class name ID
2379             * @param classPK the class p k
2380             * @param name the name
2381             * @param ownerType the owner type
2382             * @param startPeriod the start period
2383             * @return the number of matching social activity counters
2384             * @throws SystemException if a system exception occurred
2385             */
2386            public int countByG_C_C_N_O_S(long groupId, long classNameId, long classPK,
2387                    String name, int ownerType, int startPeriod) throws SystemException {
2388                    Object[] finderArgs = new Object[] {
2389                                    groupId, classNameId, classPK, name, ownerType, startPeriod
2390                            };
2391    
2392                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_S,
2393                                    finderArgs, this);
2394    
2395                    if (count == null) {
2396                            StringBundler query = new StringBundler(7);
2397    
2398                            query.append(_SQL_COUNT_SOCIALACTIVITYCOUNTER_WHERE);
2399    
2400                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_GROUPID_2);
2401    
2402                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_CLASSNAMEID_2);
2403    
2404                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_CLASSPK_2);
2405    
2406                            if (name == null) {
2407                                    query.append(_FINDER_COLUMN_G_C_C_N_O_S_NAME_1);
2408                            }
2409                            else {
2410                                    if (name.equals(StringPool.BLANK)) {
2411                                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_NAME_3);
2412                                    }
2413                                    else {
2414                                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_NAME_2);
2415                                    }
2416                            }
2417    
2418                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_OWNERTYPE_2);
2419    
2420                            query.append(_FINDER_COLUMN_G_C_C_N_O_S_STARTPERIOD_2);
2421    
2422                            String sql = query.toString();
2423    
2424                            Session session = null;
2425    
2426                            try {
2427                                    session = openSession();
2428    
2429                                    Query q = session.createQuery(sql);
2430    
2431                                    QueryPos qPos = QueryPos.getInstance(q);
2432    
2433                                    qPos.add(groupId);
2434    
2435                                    qPos.add(classNameId);
2436    
2437                                    qPos.add(classPK);
2438    
2439                                    if (name != null) {
2440                                            qPos.add(name);
2441                                    }
2442    
2443                                    qPos.add(ownerType);
2444    
2445                                    qPos.add(startPeriod);
2446    
2447                                    count = (Long)q.uniqueResult();
2448                            }
2449                            catch (Exception e) {
2450                                    throw processException(e);
2451                            }
2452                            finally {
2453                                    if (count == null) {
2454                                            count = Long.valueOf(0);
2455                                    }
2456    
2457                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_S,
2458                                            finderArgs, count);
2459    
2460                                    closeSession(session);
2461                            }
2462                    }
2463    
2464                    return count.intValue();
2465            }
2466    
2467            /**
2468             * Returns the number of social activity counters where groupId = &#63; and classNameId = &#63; and classPK = &#63; and name = &#63; and ownerType = &#63; and endPeriod = &#63;.
2469             *
2470             * @param groupId the group ID
2471             * @param classNameId the class name ID
2472             * @param classPK the class p k
2473             * @param name the name
2474             * @param ownerType the owner type
2475             * @param endPeriod the end period
2476             * @return the number of matching social activity counters
2477             * @throws SystemException if a system exception occurred
2478             */
2479            public int countByG_C_C_N_O_E(long groupId, long classNameId, long classPK,
2480                    String name, int ownerType, int endPeriod) throws SystemException {
2481                    Object[] finderArgs = new Object[] {
2482                                    groupId, classNameId, classPK, name, ownerType, endPeriod
2483                            };
2484    
2485                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_E,
2486                                    finderArgs, this);
2487    
2488                    if (count == null) {
2489                            StringBundler query = new StringBundler(7);
2490    
2491                            query.append(_SQL_COUNT_SOCIALACTIVITYCOUNTER_WHERE);
2492    
2493                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_GROUPID_2);
2494    
2495                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_CLASSNAMEID_2);
2496    
2497                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_CLASSPK_2);
2498    
2499                            if (name == null) {
2500                                    query.append(_FINDER_COLUMN_G_C_C_N_O_E_NAME_1);
2501                            }
2502                            else {
2503                                    if (name.equals(StringPool.BLANK)) {
2504                                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_NAME_3);
2505                                    }
2506                                    else {
2507                                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_NAME_2);
2508                                    }
2509                            }
2510    
2511                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_OWNERTYPE_2);
2512    
2513                            query.append(_FINDER_COLUMN_G_C_C_N_O_E_ENDPERIOD_2);
2514    
2515                            String sql = query.toString();
2516    
2517                            Session session = null;
2518    
2519                            try {
2520                                    session = openSession();
2521    
2522                                    Query q = session.createQuery(sql);
2523    
2524                                    QueryPos qPos = QueryPos.getInstance(q);
2525    
2526                                    qPos.add(groupId);
2527    
2528                                    qPos.add(classNameId);
2529    
2530                                    qPos.add(classPK);
2531    
2532                                    if (name != null) {
2533                                            qPos.add(name);
2534                                    }
2535    
2536                                    qPos.add(ownerType);
2537    
2538                                    qPos.add(endPeriod);
2539    
2540                                    count = (Long)q.uniqueResult();
2541                            }
2542                            catch (Exception e) {
2543                                    throw processException(e);
2544                            }
2545                            finally {
2546                                    if (count == null) {
2547                                            count = Long.valueOf(0);
2548                                    }
2549    
2550                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C_N_O_E,
2551                                            finderArgs, count);
2552    
2553                                    closeSession(session);
2554                            }
2555                    }
2556    
2557                    return count.intValue();
2558            }
2559    
2560            /**
2561             * Returns the number of social activity counters.
2562             *
2563             * @return the number of social activity counters
2564             * @throws SystemException if a system exception occurred
2565             */
2566            public int countAll() throws SystemException {
2567                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2568                                    FINDER_ARGS_EMPTY, this);
2569    
2570                    if (count == null) {
2571                            Session session = null;
2572    
2573                            try {
2574                                    session = openSession();
2575    
2576                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYCOUNTER);
2577    
2578                                    count = (Long)q.uniqueResult();
2579                            }
2580                            catch (Exception e) {
2581                                    throw processException(e);
2582                            }
2583                            finally {
2584                                    if (count == null) {
2585                                            count = Long.valueOf(0);
2586                                    }
2587    
2588                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2589                                            FINDER_ARGS_EMPTY, count);
2590    
2591                                    closeSession(session);
2592                            }
2593                    }
2594    
2595                    return count.intValue();
2596            }
2597    
2598            /**
2599             * Initializes the social activity counter persistence.
2600             */
2601            public void afterPropertiesSet() {
2602                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2603                                            com.liferay.portal.util.PropsUtil.get(
2604                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivityCounter")));
2605    
2606                    if (listenerClassNames.length > 0) {
2607                            try {
2608                                    List<ModelListener<SocialActivityCounter>> listenersList = new ArrayList<ModelListener<SocialActivityCounter>>();
2609    
2610                                    for (String listenerClassName : listenerClassNames) {
2611                                            Class<?> clazz = getClass();
2612    
2613                                            listenersList.add((ModelListener<SocialActivityCounter>)InstanceFactory.newInstance(
2614                                                            clazz.getClassLoader(), listenerClassName));
2615                                    }
2616    
2617                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2618                            }
2619                            catch (Exception e) {
2620                                    _log.error(e);
2621                            }
2622                    }
2623            }
2624    
2625            public void destroy() {
2626                    EntityCacheUtil.removeCache(SocialActivityCounterImpl.class.getName());
2627                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2628                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2629            }
2630    
2631            @BeanReference(type = SocialActivityPersistence.class)
2632            protected SocialActivityPersistence socialActivityPersistence;
2633            @BeanReference(type = SocialActivityAchievementPersistence.class)
2634            protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
2635            @BeanReference(type = SocialActivityCounterPersistence.class)
2636            protected SocialActivityCounterPersistence socialActivityCounterPersistence;
2637            @BeanReference(type = SocialActivityLimitPersistence.class)
2638            protected SocialActivityLimitPersistence socialActivityLimitPersistence;
2639            @BeanReference(type = SocialActivitySettingPersistence.class)
2640            protected SocialActivitySettingPersistence socialActivitySettingPersistence;
2641            @BeanReference(type = SocialRelationPersistence.class)
2642            protected SocialRelationPersistence socialRelationPersistence;
2643            @BeanReference(type = SocialRequestPersistence.class)
2644            protected SocialRequestPersistence socialRequestPersistence;
2645            @BeanReference(type = GroupPersistence.class)
2646            protected GroupPersistence groupPersistence;
2647            @BeanReference(type = LockPersistence.class)
2648            protected LockPersistence lockPersistence;
2649            @BeanReference(type = ResourcePersistence.class)
2650            protected ResourcePersistence resourcePersistence;
2651            @BeanReference(type = UserPersistence.class)
2652            protected UserPersistence userPersistence;
2653            @BeanReference(type = AssetEntryPersistence.class)
2654            protected AssetEntryPersistence assetEntryPersistence;
2655            private static final String _SQL_SELECT_SOCIALACTIVITYCOUNTER = "SELECT socialActivityCounter FROM SocialActivityCounter socialActivityCounter";
2656            private static final String _SQL_SELECT_SOCIALACTIVITYCOUNTER_WHERE = "SELECT socialActivityCounter FROM SocialActivityCounter socialActivityCounter WHERE ";
2657            private static final String _SQL_COUNT_SOCIALACTIVITYCOUNTER = "SELECT COUNT(socialActivityCounter) FROM SocialActivityCounter socialActivityCounter";
2658            private static final String _SQL_COUNT_SOCIALACTIVITYCOUNTER_WHERE = "SELECT COUNT(socialActivityCounter) FROM SocialActivityCounter socialActivityCounter WHERE ";
2659            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "socialActivityCounter.classNameId = ? AND ";
2660            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "socialActivityCounter.classPK = ?";
2661            private static final String _FINDER_COLUMN_G_C_C_O_GROUPID_2 = "socialActivityCounter.groupId = ? AND ";
2662            private static final String _FINDER_COLUMN_G_C_C_O_CLASSNAMEID_2 = "socialActivityCounter.classNameId = ? AND ";
2663            private static final String _FINDER_COLUMN_G_C_C_O_CLASSPK_2 = "socialActivityCounter.classPK = ? AND ";
2664            private static final String _FINDER_COLUMN_G_C_C_O_OWNERTYPE_2 = "socialActivityCounter.ownerType = ? AND socialActivityCounter.endPeriod = -1";
2665            private static final String _FINDER_COLUMN_G_C_C_N_O_S_GROUPID_2 = "socialActivityCounter.groupId = ? AND ";
2666            private static final String _FINDER_COLUMN_G_C_C_N_O_S_CLASSNAMEID_2 = "socialActivityCounter.classNameId = ? AND ";
2667            private static final String _FINDER_COLUMN_G_C_C_N_O_S_CLASSPK_2 = "socialActivityCounter.classPK = ? AND ";
2668            private static final String _FINDER_COLUMN_G_C_C_N_O_S_NAME_1 = "socialActivityCounter.name IS NULL AND ";
2669            private static final String _FINDER_COLUMN_G_C_C_N_O_S_NAME_2 = "socialActivityCounter.name = ? AND ";
2670            private static final String _FINDER_COLUMN_G_C_C_N_O_S_NAME_3 = "(socialActivityCounter.name IS NULL OR socialActivityCounter.name = ?) AND ";
2671            private static final String _FINDER_COLUMN_G_C_C_N_O_S_OWNERTYPE_2 = "socialActivityCounter.ownerType = ? AND ";
2672            private static final String _FINDER_COLUMN_G_C_C_N_O_S_STARTPERIOD_2 = "socialActivityCounter.startPeriod = ?";
2673            private static final String _FINDER_COLUMN_G_C_C_N_O_E_GROUPID_2 = "socialActivityCounter.groupId = ? AND ";
2674            private static final String _FINDER_COLUMN_G_C_C_N_O_E_CLASSNAMEID_2 = "socialActivityCounter.classNameId = ? AND ";
2675            private static final String _FINDER_COLUMN_G_C_C_N_O_E_CLASSPK_2 = "socialActivityCounter.classPK = ? AND ";
2676            private static final String _FINDER_COLUMN_G_C_C_N_O_E_NAME_1 = "socialActivityCounter.name IS NULL AND ";
2677            private static final String _FINDER_COLUMN_G_C_C_N_O_E_NAME_2 = "socialActivityCounter.name = ? AND ";
2678            private static final String _FINDER_COLUMN_G_C_C_N_O_E_NAME_3 = "(socialActivityCounter.name IS NULL OR socialActivityCounter.name = ?) AND ";
2679            private static final String _FINDER_COLUMN_G_C_C_N_O_E_OWNERTYPE_2 = "socialActivityCounter.ownerType = ? AND ";
2680            private static final String _FINDER_COLUMN_G_C_C_N_O_E_ENDPERIOD_2 = "socialActivityCounter.endPeriod = ?";
2681            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivityCounter.";
2682            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivityCounter exists with the primary key ";
2683            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivityCounter exists with the key {";
2684            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2685            private static Log _log = LogFactoryUtil.getLog(SocialActivityCounterPersistenceImpl.class);
2686            private static SocialActivityCounter _nullSocialActivityCounter = new SocialActivityCounterImpl() {
2687                            @Override
2688                            public Object clone() {
2689                                    return this;
2690                            }
2691    
2692                            @Override
2693                            public CacheModel<SocialActivityCounter> toCacheModel() {
2694                                    return _nullSocialActivityCounterCacheModel;
2695                            }
2696                    };
2697    
2698            private static CacheModel<SocialActivityCounter> _nullSocialActivityCounterCacheModel =
2699                    new CacheModel<SocialActivityCounter>() {
2700                            public SocialActivityCounter toEntityModel() {
2701                                    return _nullSocialActivityCounter;
2702                            }
2703                    };
2704    }