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