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