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