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