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