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