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