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