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