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