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