001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstanceFactory;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.SetUtil;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039    
040    import com.liferay.portlet.social.NoSuchActivityException;
041    import com.liferay.portlet.social.model.SocialActivity;
042    import com.liferay.portlet.social.model.impl.SocialActivityImpl;
043    import com.liferay.portlet.social.model.impl.SocialActivityModelImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.List;
050    import java.util.Set;
051    
052    /**
053     * The persistence implementation for the social activity 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 SocialActivityPersistence
061     * @see SocialActivityUtil
062     * @generated
063     */
064    public class SocialActivityPersistenceImpl extends BasePersistenceImpl<SocialActivity>
065            implements SocialActivityPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link SocialActivityUtil} to access the social activity persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivityImpl.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(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
077                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
078                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
079                            "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
081                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
082                            SocialActivityImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
085                            SocialActivityModelImpl.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_GROUPID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
088                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
089                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090                            "findByGroupId",
091                            new String[] {
092                                    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_GROUPID =
098                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
099                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
100                            SocialActivityImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
102                            new String[] { Long.class.getName() },
103                            SocialActivityModelImpl.GROUPID_COLUMN_BITMASK |
104                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
106                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
108                            new String[] { Long.class.getName() });
109    
110            /**
111             * Returns all the social activities where groupId = &#63;.
112             *
113             * @param groupId the group ID
114             * @return the matching social activities
115             * @throws SystemException if a system exception occurred
116             */
117            public List<SocialActivity> findByGroupId(long groupId)
118                    throws SystemException {
119                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
120            }
121    
122            /**
123             * Returns a range of all the social activities where groupId = &#63;.
124             *
125             * <p>
126             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.SocialActivityModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
127             * </p>
128             *
129             * @param groupId the group ID
130             * @param start the lower bound of the range of social activities
131             * @param end the upper bound of the range of social activities (not inclusive)
132             * @return the range of matching social activities
133             * @throws SystemException if a system exception occurred
134             */
135            public List<SocialActivity> findByGroupId(long groupId, int start, int end)
136                    throws SystemException {
137                    return findByGroupId(groupId, start, end, null);
138            }
139    
140            /**
141             * Returns an ordered range of all the social activities where groupId = &#63;.
142             *
143             * <p>
144             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.SocialActivityModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
145             * </p>
146             *
147             * @param groupId the group ID
148             * @param start the lower bound of the range of social activities
149             * @param end the upper bound of the range of social activities (not inclusive)
150             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
151             * @return the ordered range of matching social activities
152             * @throws SystemException if a system exception occurred
153             */
154            public List<SocialActivity> findByGroupId(long groupId, int start, int end,
155                    OrderByComparator orderByComparator) throws SystemException {
156                    boolean pagination = true;
157                    FinderPath finderPath = null;
158                    Object[] finderArgs = null;
159    
160                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161                                    (orderByComparator == null)) {
162                            pagination = false;
163                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
164                            finderArgs = new Object[] { groupId };
165                    }
166                    else {
167                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
168                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
169                    }
170    
171                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
172                                    finderArgs, this);
173    
174                    if ((list != null) && !list.isEmpty()) {
175                            for (SocialActivity socialActivity : list) {
176                                    if ((groupId != socialActivity.getGroupId())) {
177                                            list = null;
178    
179                                            break;
180                                    }
181                            }
182                    }
183    
184                    if (list == null) {
185                            StringBundler query = null;
186    
187                            if (orderByComparator != null) {
188                                    query = new StringBundler(3 +
189                                                    (orderByComparator.getOrderByFields().length * 3));
190                            }
191                            else {
192                                    query = new StringBundler(3);
193                            }
194    
195                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
196    
197                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
198    
199                            if (orderByComparator != null) {
200                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
201                                            orderByComparator);
202                            }
203                            else
204                             if (pagination) {
205                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
206                            }
207    
208                            String sql = query.toString();
209    
210                            Session session = null;
211    
212                            try {
213                                    session = openSession();
214    
215                                    Query q = session.createQuery(sql);
216    
217                                    QueryPos qPos = QueryPos.getInstance(q);
218    
219                                    qPos.add(groupId);
220    
221                                    if (!pagination) {
222                                            list = (List<SocialActivity>)QueryUtil.list(q,
223                                                            getDialect(), start, end, false);
224    
225                                            Collections.sort(list);
226    
227                                            list = new UnmodifiableList<SocialActivity>(list);
228                                    }
229                                    else {
230                                            list = (List<SocialActivity>)QueryUtil.list(q,
231                                                            getDialect(), start, end);
232                                    }
233    
234                                    cacheResult(list);
235    
236                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
237                            }
238                            catch (Exception e) {
239                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
240    
241                                    throw processException(e);
242                            }
243                            finally {
244                                    closeSession(session);
245                            }
246                    }
247    
248                    return list;
249            }
250    
251            /**
252             * Returns the first social activity in the ordered set where groupId = &#63;.
253             *
254             * @param groupId the group ID
255             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
256             * @return the first matching social activity
257             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
258             * @throws SystemException if a system exception occurred
259             */
260            public SocialActivity findByGroupId_First(long groupId,
261                    OrderByComparator orderByComparator)
262                    throws NoSuchActivityException, SystemException {
263                    SocialActivity socialActivity = fetchByGroupId_First(groupId,
264                                    orderByComparator);
265    
266                    if (socialActivity != null) {
267                            return socialActivity;
268                    }
269    
270                    StringBundler msg = new StringBundler(4);
271    
272                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
273    
274                    msg.append("groupId=");
275                    msg.append(groupId);
276    
277                    msg.append(StringPool.CLOSE_CURLY_BRACE);
278    
279                    throw new NoSuchActivityException(msg.toString());
280            }
281    
282            /**
283             * Returns the first social activity in the ordered set where groupId = &#63;.
284             *
285             * @param groupId the group ID
286             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
287             * @return the first matching social activity, or <code>null</code> if a matching social activity could not be found
288             * @throws SystemException if a system exception occurred
289             */
290            public SocialActivity fetchByGroupId_First(long groupId,
291                    OrderByComparator orderByComparator) throws SystemException {
292                    List<SocialActivity> list = findByGroupId(groupId, 0, 1,
293                                    orderByComparator);
294    
295                    if (!list.isEmpty()) {
296                            return list.get(0);
297                    }
298    
299                    return null;
300            }
301    
302            /**
303             * Returns the last social activity in the ordered set where groupId = &#63;.
304             *
305             * @param groupId the group ID
306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
307             * @return the last matching social activity
308             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
309             * @throws SystemException if a system exception occurred
310             */
311            public SocialActivity findByGroupId_Last(long groupId,
312                    OrderByComparator orderByComparator)
313                    throws NoSuchActivityException, SystemException {
314                    SocialActivity socialActivity = fetchByGroupId_Last(groupId,
315                                    orderByComparator);
316    
317                    if (socialActivity != null) {
318                            return socialActivity;
319                    }
320    
321                    StringBundler msg = new StringBundler(4);
322    
323                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
324    
325                    msg.append("groupId=");
326                    msg.append(groupId);
327    
328                    msg.append(StringPool.CLOSE_CURLY_BRACE);
329    
330                    throw new NoSuchActivityException(msg.toString());
331            }
332    
333            /**
334             * Returns the last social activity in the ordered set where groupId = &#63;.
335             *
336             * @param groupId the group ID
337             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
338             * @return the last matching social activity, or <code>null</code> if a matching social activity could not be found
339             * @throws SystemException if a system exception occurred
340             */
341            public SocialActivity fetchByGroupId_Last(long groupId,
342                    OrderByComparator orderByComparator) throws SystemException {
343                    int count = countByGroupId(groupId);
344    
345                    List<SocialActivity> list = findByGroupId(groupId, count - 1, count,
346                                    orderByComparator);
347    
348                    if (!list.isEmpty()) {
349                            return list.get(0);
350                    }
351    
352                    return null;
353            }
354    
355            /**
356             * Returns the social activities before and after the current social activity in the ordered set where groupId = &#63;.
357             *
358             * @param activityId the primary key of the current social activity
359             * @param groupId the group ID
360             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
361             * @return the previous, current, and next social activity
362             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
363             * @throws SystemException if a system exception occurred
364             */
365            public SocialActivity[] findByGroupId_PrevAndNext(long activityId,
366                    long groupId, OrderByComparator orderByComparator)
367                    throws NoSuchActivityException, SystemException {
368                    SocialActivity socialActivity = findByPrimaryKey(activityId);
369    
370                    Session session = null;
371    
372                    try {
373                            session = openSession();
374    
375                            SocialActivity[] array = new SocialActivityImpl[3];
376    
377                            array[0] = getByGroupId_PrevAndNext(session, socialActivity,
378                                            groupId, orderByComparator, true);
379    
380                            array[1] = socialActivity;
381    
382                            array[2] = getByGroupId_PrevAndNext(session, socialActivity,
383                                            groupId, orderByComparator, false);
384    
385                            return array;
386                    }
387                    catch (Exception e) {
388                            throw processException(e);
389                    }
390                    finally {
391                            closeSession(session);
392                    }
393            }
394    
395            protected SocialActivity getByGroupId_PrevAndNext(Session session,
396                    SocialActivity socialActivity, long groupId,
397                    OrderByComparator orderByComparator, boolean previous) {
398                    StringBundler query = null;
399    
400                    if (orderByComparator != null) {
401                            query = new StringBundler(6 +
402                                            (orderByComparator.getOrderByFields().length * 6));
403                    }
404                    else {
405                            query = new StringBundler(3);
406                    }
407    
408                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
409    
410                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
411    
412                    if (orderByComparator != null) {
413                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
414    
415                            if (orderByConditionFields.length > 0) {
416                                    query.append(WHERE_AND);
417                            }
418    
419                            for (int i = 0; i < orderByConditionFields.length; i++) {
420                                    query.append(_ORDER_BY_ENTITY_ALIAS);
421                                    query.append(orderByConditionFields[i]);
422    
423                                    if ((i + 1) < orderByConditionFields.length) {
424                                            if (orderByComparator.isAscending() ^ previous) {
425                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
426                                            }
427                                            else {
428                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
429                                            }
430                                    }
431                                    else {
432                                            if (orderByComparator.isAscending() ^ previous) {
433                                                    query.append(WHERE_GREATER_THAN);
434                                            }
435                                            else {
436                                                    query.append(WHERE_LESSER_THAN);
437                                            }
438                                    }
439                            }
440    
441                            query.append(ORDER_BY_CLAUSE);
442    
443                            String[] orderByFields = orderByComparator.getOrderByFields();
444    
445                            for (int i = 0; i < orderByFields.length; i++) {
446                                    query.append(_ORDER_BY_ENTITY_ALIAS);
447                                    query.append(orderByFields[i]);
448    
449                                    if ((i + 1) < orderByFields.length) {
450                                            if (orderByComparator.isAscending() ^ previous) {
451                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
452                                            }
453                                            else {
454                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
455                                            }
456                                    }
457                                    else {
458                                            if (orderByComparator.isAscending() ^ previous) {
459                                                    query.append(ORDER_BY_ASC);
460                                            }
461                                            else {
462                                                    query.append(ORDER_BY_DESC);
463                                            }
464                                    }
465                            }
466                    }
467                    else {
468                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
469                    }
470    
471                    String sql = query.toString();
472    
473                    Query q = session.createQuery(sql);
474    
475                    q.setFirstResult(0);
476                    q.setMaxResults(2);
477    
478                    QueryPos qPos = QueryPos.getInstance(q);
479    
480                    qPos.add(groupId);
481    
482                    if (orderByComparator != null) {
483                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
484    
485                            for (Object value : values) {
486                                    qPos.add(value);
487                            }
488                    }
489    
490                    List<SocialActivity> list = q.list();
491    
492                    if (list.size() == 2) {
493                            return list.get(1);
494                    }
495                    else {
496                            return null;
497                    }
498            }
499    
500            /**
501             * Removes all the social activities where groupId = &#63; from the database.
502             *
503             * @param groupId the group ID
504             * @throws SystemException if a system exception occurred
505             */
506            public void removeByGroupId(long groupId) throws SystemException {
507                    for (SocialActivity socialActivity : findByGroupId(groupId,
508                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
509                            remove(socialActivity);
510                    }
511            }
512    
513            /**
514             * Returns the number of social activities where groupId = &#63;.
515             *
516             * @param groupId the group ID
517             * @return the number of matching social activities
518             * @throws SystemException if a system exception occurred
519             */
520            public int countByGroupId(long groupId) throws SystemException {
521                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
522    
523                    Object[] finderArgs = new Object[] { groupId };
524    
525                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
526                                    this);
527    
528                    if (count == null) {
529                            StringBundler query = new StringBundler(2);
530    
531                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
532    
533                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
534    
535                            String sql = query.toString();
536    
537                            Session session = null;
538    
539                            try {
540                                    session = openSession();
541    
542                                    Query q = session.createQuery(sql);
543    
544                                    QueryPos qPos = QueryPos.getInstance(q);
545    
546                                    qPos.add(groupId);
547    
548                                    count = (Long)q.uniqueResult();
549    
550                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
551                            }
552                            catch (Exception e) {
553                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
554    
555                                    throw processException(e);
556                            }
557                            finally {
558                                    closeSession(session);
559                            }
560                    }
561    
562                    return count.intValue();
563            }
564    
565            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "socialActivity.groupId = ?";
566            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
567                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
568                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
569                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
570                            "findByCompanyId",
571                            new String[] {
572                                    Long.class.getName(),
573                                    
574                            Integer.class.getName(), Integer.class.getName(),
575                                    OrderByComparator.class.getName()
576                            });
577            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
578                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
579                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
580                            SocialActivityImpl.class,
581                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
582                            new String[] { Long.class.getName() },
583                            SocialActivityModelImpl.COMPANYID_COLUMN_BITMASK |
584                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK);
585            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
586                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
587                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
588                            new String[] { Long.class.getName() });
589    
590            /**
591             * Returns all the social activities where companyId = &#63;.
592             *
593             * @param companyId the company ID
594             * @return the matching social activities
595             * @throws SystemException if a system exception occurred
596             */
597            public List<SocialActivity> findByCompanyId(long companyId)
598                    throws SystemException {
599                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
600                            null);
601            }
602    
603            /**
604             * Returns a range of all the social activities where companyId = &#63;.
605             *
606             * <p>
607             * 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.SocialActivityModelImpl}. 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.
608             * </p>
609             *
610             * @param companyId the company ID
611             * @param start the lower bound of the range of social activities
612             * @param end the upper bound of the range of social activities (not inclusive)
613             * @return the range of matching social activities
614             * @throws SystemException if a system exception occurred
615             */
616            public List<SocialActivity> findByCompanyId(long companyId, int start,
617                    int end) throws SystemException {
618                    return findByCompanyId(companyId, start, end, null);
619            }
620    
621            /**
622             * Returns an ordered range of all the social activities where companyId = &#63;.
623             *
624             * <p>
625             * 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.SocialActivityModelImpl}. 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.
626             * </p>
627             *
628             * @param companyId the company ID
629             * @param start the lower bound of the range of social activities
630             * @param end the upper bound of the range of social activities (not inclusive)
631             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
632             * @return the ordered range of matching social activities
633             * @throws SystemException if a system exception occurred
634             */
635            public List<SocialActivity> findByCompanyId(long companyId, int start,
636                    int end, OrderByComparator orderByComparator) throws SystemException {
637                    boolean pagination = true;
638                    FinderPath finderPath = null;
639                    Object[] finderArgs = null;
640    
641                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
642                                    (orderByComparator == null)) {
643                            pagination = false;
644                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
645                            finderArgs = new Object[] { companyId };
646                    }
647                    else {
648                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
649                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
650                    }
651    
652                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
653                                    finderArgs, this);
654    
655                    if ((list != null) && !list.isEmpty()) {
656                            for (SocialActivity socialActivity : list) {
657                                    if ((companyId != socialActivity.getCompanyId())) {
658                                            list = null;
659    
660                                            break;
661                                    }
662                            }
663                    }
664    
665                    if (list == null) {
666                            StringBundler query = null;
667    
668                            if (orderByComparator != null) {
669                                    query = new StringBundler(3 +
670                                                    (orderByComparator.getOrderByFields().length * 3));
671                            }
672                            else {
673                                    query = new StringBundler(3);
674                            }
675    
676                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
677    
678                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
679    
680                            if (orderByComparator != null) {
681                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
682                                            orderByComparator);
683                            }
684                            else
685                             if (pagination) {
686                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
687                            }
688    
689                            String sql = query.toString();
690    
691                            Session session = null;
692    
693                            try {
694                                    session = openSession();
695    
696                                    Query q = session.createQuery(sql);
697    
698                                    QueryPos qPos = QueryPos.getInstance(q);
699    
700                                    qPos.add(companyId);
701    
702                                    if (!pagination) {
703                                            list = (List<SocialActivity>)QueryUtil.list(q,
704                                                            getDialect(), start, end, false);
705    
706                                            Collections.sort(list);
707    
708                                            list = new UnmodifiableList<SocialActivity>(list);
709                                    }
710                                    else {
711                                            list = (List<SocialActivity>)QueryUtil.list(q,
712                                                            getDialect(), start, end);
713                                    }
714    
715                                    cacheResult(list);
716    
717                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
718                            }
719                            catch (Exception e) {
720                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
721    
722                                    throw processException(e);
723                            }
724                            finally {
725                                    closeSession(session);
726                            }
727                    }
728    
729                    return list;
730            }
731    
732            /**
733             * Returns the first social activity in the ordered set where companyId = &#63;.
734             *
735             * @param companyId the company ID
736             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
737             * @return the first matching social activity
738             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
739             * @throws SystemException if a system exception occurred
740             */
741            public SocialActivity findByCompanyId_First(long companyId,
742                    OrderByComparator orderByComparator)
743                    throws NoSuchActivityException, SystemException {
744                    SocialActivity socialActivity = fetchByCompanyId_First(companyId,
745                                    orderByComparator);
746    
747                    if (socialActivity != null) {
748                            return socialActivity;
749                    }
750    
751                    StringBundler msg = new StringBundler(4);
752    
753                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
754    
755                    msg.append("companyId=");
756                    msg.append(companyId);
757    
758                    msg.append(StringPool.CLOSE_CURLY_BRACE);
759    
760                    throw new NoSuchActivityException(msg.toString());
761            }
762    
763            /**
764             * Returns the first social activity in the ordered set where companyId = &#63;.
765             *
766             * @param companyId the company ID
767             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
768             * @return the first matching social activity, or <code>null</code> if a matching social activity could not be found
769             * @throws SystemException if a system exception occurred
770             */
771            public SocialActivity fetchByCompanyId_First(long companyId,
772                    OrderByComparator orderByComparator) throws SystemException {
773                    List<SocialActivity> list = findByCompanyId(companyId, 0, 1,
774                                    orderByComparator);
775    
776                    if (!list.isEmpty()) {
777                            return list.get(0);
778                    }
779    
780                    return null;
781            }
782    
783            /**
784             * Returns the last social activity in the ordered set where companyId = &#63;.
785             *
786             * @param companyId the company ID
787             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
788             * @return the last matching social activity
789             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
790             * @throws SystemException if a system exception occurred
791             */
792            public SocialActivity findByCompanyId_Last(long companyId,
793                    OrderByComparator orderByComparator)
794                    throws NoSuchActivityException, SystemException {
795                    SocialActivity socialActivity = fetchByCompanyId_Last(companyId,
796                                    orderByComparator);
797    
798                    if (socialActivity != null) {
799                            return socialActivity;
800                    }
801    
802                    StringBundler msg = new StringBundler(4);
803    
804                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
805    
806                    msg.append("companyId=");
807                    msg.append(companyId);
808    
809                    msg.append(StringPool.CLOSE_CURLY_BRACE);
810    
811                    throw new NoSuchActivityException(msg.toString());
812            }
813    
814            /**
815             * Returns the last social activity in the ordered set where companyId = &#63;.
816             *
817             * @param companyId the company ID
818             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
819             * @return the last matching social activity, or <code>null</code> if a matching social activity could not be found
820             * @throws SystemException if a system exception occurred
821             */
822            public SocialActivity fetchByCompanyId_Last(long companyId,
823                    OrderByComparator orderByComparator) throws SystemException {
824                    int count = countByCompanyId(companyId);
825    
826                    List<SocialActivity> list = findByCompanyId(companyId, count - 1,
827                                    count, orderByComparator);
828    
829                    if (!list.isEmpty()) {
830                            return list.get(0);
831                    }
832    
833                    return null;
834            }
835    
836            /**
837             * Returns the social activities before and after the current social activity in the ordered set where companyId = &#63;.
838             *
839             * @param activityId the primary key of the current social activity
840             * @param companyId the company ID
841             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
842             * @return the previous, current, and next social activity
843             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
844             * @throws SystemException if a system exception occurred
845             */
846            public SocialActivity[] findByCompanyId_PrevAndNext(long activityId,
847                    long companyId, OrderByComparator orderByComparator)
848                    throws NoSuchActivityException, SystemException {
849                    SocialActivity socialActivity = findByPrimaryKey(activityId);
850    
851                    Session session = null;
852    
853                    try {
854                            session = openSession();
855    
856                            SocialActivity[] array = new SocialActivityImpl[3];
857    
858                            array[0] = getByCompanyId_PrevAndNext(session, socialActivity,
859                                            companyId, orderByComparator, true);
860    
861                            array[1] = socialActivity;
862    
863                            array[2] = getByCompanyId_PrevAndNext(session, socialActivity,
864                                            companyId, orderByComparator, false);
865    
866                            return array;
867                    }
868                    catch (Exception e) {
869                            throw processException(e);
870                    }
871                    finally {
872                            closeSession(session);
873                    }
874            }
875    
876            protected SocialActivity getByCompanyId_PrevAndNext(Session session,
877                    SocialActivity socialActivity, long companyId,
878                    OrderByComparator orderByComparator, boolean previous) {
879                    StringBundler query = null;
880    
881                    if (orderByComparator != null) {
882                            query = new StringBundler(6 +
883                                            (orderByComparator.getOrderByFields().length * 6));
884                    }
885                    else {
886                            query = new StringBundler(3);
887                    }
888    
889                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
890    
891                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
892    
893                    if (orderByComparator != null) {
894                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
895    
896                            if (orderByConditionFields.length > 0) {
897                                    query.append(WHERE_AND);
898                            }
899    
900                            for (int i = 0; i < orderByConditionFields.length; i++) {
901                                    query.append(_ORDER_BY_ENTITY_ALIAS);
902                                    query.append(orderByConditionFields[i]);
903    
904                                    if ((i + 1) < orderByConditionFields.length) {
905                                            if (orderByComparator.isAscending() ^ previous) {
906                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
907                                            }
908                                            else {
909                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
910                                            }
911                                    }
912                                    else {
913                                            if (orderByComparator.isAscending() ^ previous) {
914                                                    query.append(WHERE_GREATER_THAN);
915                                            }
916                                            else {
917                                                    query.append(WHERE_LESSER_THAN);
918                                            }
919                                    }
920                            }
921    
922                            query.append(ORDER_BY_CLAUSE);
923    
924                            String[] orderByFields = orderByComparator.getOrderByFields();
925    
926                            for (int i = 0; i < orderByFields.length; i++) {
927                                    query.append(_ORDER_BY_ENTITY_ALIAS);
928                                    query.append(orderByFields[i]);
929    
930                                    if ((i + 1) < orderByFields.length) {
931                                            if (orderByComparator.isAscending() ^ previous) {
932                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
933                                            }
934                                            else {
935                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
936                                            }
937                                    }
938                                    else {
939                                            if (orderByComparator.isAscending() ^ previous) {
940                                                    query.append(ORDER_BY_ASC);
941                                            }
942                                            else {
943                                                    query.append(ORDER_BY_DESC);
944                                            }
945                                    }
946                            }
947                    }
948                    else {
949                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
950                    }
951    
952                    String sql = query.toString();
953    
954                    Query q = session.createQuery(sql);
955    
956                    q.setFirstResult(0);
957                    q.setMaxResults(2);
958    
959                    QueryPos qPos = QueryPos.getInstance(q);
960    
961                    qPos.add(companyId);
962    
963                    if (orderByComparator != null) {
964                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
965    
966                            for (Object value : values) {
967                                    qPos.add(value);
968                            }
969                    }
970    
971                    List<SocialActivity> list = q.list();
972    
973                    if (list.size() == 2) {
974                            return list.get(1);
975                    }
976                    else {
977                            return null;
978                    }
979            }
980    
981            /**
982             * Removes all the social activities where companyId = &#63; from the database.
983             *
984             * @param companyId the company ID
985             * @throws SystemException if a system exception occurred
986             */
987            public void removeByCompanyId(long companyId) throws SystemException {
988                    for (SocialActivity socialActivity : findByCompanyId(companyId,
989                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
990                            remove(socialActivity);
991                    }
992            }
993    
994            /**
995             * Returns the number of social activities where companyId = &#63;.
996             *
997             * @param companyId the company ID
998             * @return the number of matching social activities
999             * @throws SystemException if a system exception occurred
1000             */
1001            public int countByCompanyId(long companyId) throws SystemException {
1002                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1003    
1004                    Object[] finderArgs = new Object[] { companyId };
1005    
1006                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1007                                    this);
1008    
1009                    if (count == null) {
1010                            StringBundler query = new StringBundler(2);
1011    
1012                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
1013    
1014                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1015    
1016                            String sql = query.toString();
1017    
1018                            Session session = null;
1019    
1020                            try {
1021                                    session = openSession();
1022    
1023                                    Query q = session.createQuery(sql);
1024    
1025                                    QueryPos qPos = QueryPos.getInstance(q);
1026    
1027                                    qPos.add(companyId);
1028    
1029                                    count = (Long)q.uniqueResult();
1030    
1031                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1032                            }
1033                            catch (Exception e) {
1034                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1035    
1036                                    throw processException(e);
1037                            }
1038                            finally {
1039                                    closeSession(session);
1040                            }
1041                    }
1042    
1043                    return count.intValue();
1044            }
1045    
1046            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialActivity.companyId = ?";
1047            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
1048                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
1049                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1050                            "findByUserId",
1051                            new String[] {
1052                                    Long.class.getName(),
1053                                    
1054                            Integer.class.getName(), Integer.class.getName(),
1055                                    OrderByComparator.class.getName()
1056                            });
1057            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1058                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
1059                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
1060                            SocialActivityImpl.class,
1061                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1062                            new String[] { Long.class.getName() },
1063                            SocialActivityModelImpl.USERID_COLUMN_BITMASK |
1064                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK);
1065            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
1066                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
1067                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1068                            new String[] { Long.class.getName() });
1069    
1070            /**
1071             * Returns all the social activities where userId = &#63;.
1072             *
1073             * @param userId the user ID
1074             * @return the matching social activities
1075             * @throws SystemException if a system exception occurred
1076             */
1077            public List<SocialActivity> findByUserId(long userId)
1078                    throws SystemException {
1079                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1080            }
1081    
1082            /**
1083             * Returns a range of all the social activities where userId = &#63;.
1084             *
1085             * <p>
1086             * 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.SocialActivityModelImpl}. 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.
1087             * </p>
1088             *
1089             * @param userId the user ID
1090             * @param start the lower bound of the range of social activities
1091             * @param end the upper bound of the range of social activities (not inclusive)
1092             * @return the range of matching social activities
1093             * @throws SystemException if a system exception occurred
1094             */
1095            public List<SocialActivity> findByUserId(long userId, int start, int end)
1096                    throws SystemException {
1097                    return findByUserId(userId, start, end, null);
1098            }
1099    
1100            /**
1101             * Returns an ordered range of all the social activities where userId = &#63;.
1102             *
1103             * <p>
1104             * 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.SocialActivityModelImpl}. 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.
1105             * </p>
1106             *
1107             * @param userId the user ID
1108             * @param start the lower bound of the range of social activities
1109             * @param end the upper bound of the range of social activities (not inclusive)
1110             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1111             * @return the ordered range of matching social activities
1112             * @throws SystemException if a system exception occurred
1113             */
1114            public List<SocialActivity> findByUserId(long userId, int start, int end,
1115                    OrderByComparator orderByComparator) throws SystemException {
1116                    boolean pagination = true;
1117                    FinderPath finderPath = null;
1118                    Object[] finderArgs = null;
1119    
1120                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1121                                    (orderByComparator == null)) {
1122                            pagination = false;
1123                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1124                            finderArgs = new Object[] { userId };
1125                    }
1126                    else {
1127                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1128                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1129                    }
1130    
1131                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
1132                                    finderArgs, this);
1133    
1134                    if ((list != null) && !list.isEmpty()) {
1135                            for (SocialActivity socialActivity : list) {
1136                                    if ((userId != socialActivity.getUserId())) {
1137                                            list = null;
1138    
1139                                            break;
1140                                    }
1141                            }
1142                    }
1143    
1144                    if (list == null) {
1145                            StringBundler query = null;
1146    
1147                            if (orderByComparator != null) {
1148                                    query = new StringBundler(3 +
1149                                                    (orderByComparator.getOrderByFields().length * 3));
1150                            }
1151                            else {
1152                                    query = new StringBundler(3);
1153                            }
1154    
1155                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1156    
1157                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1158    
1159                            if (orderByComparator != null) {
1160                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1161                                            orderByComparator);
1162                            }
1163                            else
1164                             if (pagination) {
1165                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1166                            }
1167    
1168                            String sql = query.toString();
1169    
1170                            Session session = null;
1171    
1172                            try {
1173                                    session = openSession();
1174    
1175                                    Query q = session.createQuery(sql);
1176    
1177                                    QueryPos qPos = QueryPos.getInstance(q);
1178    
1179                                    qPos.add(userId);
1180    
1181                                    if (!pagination) {
1182                                            list = (List<SocialActivity>)QueryUtil.list(q,
1183                                                            getDialect(), start, end, false);
1184    
1185                                            Collections.sort(list);
1186    
1187                                            list = new UnmodifiableList<SocialActivity>(list);
1188                                    }
1189                                    else {
1190                                            list = (List<SocialActivity>)QueryUtil.list(q,
1191                                                            getDialect(), start, end);
1192                                    }
1193    
1194                                    cacheResult(list);
1195    
1196                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1197                            }
1198                            catch (Exception e) {
1199                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1200    
1201                                    throw processException(e);
1202                            }
1203                            finally {
1204                                    closeSession(session);
1205                            }
1206                    }
1207    
1208                    return list;
1209            }
1210    
1211            /**
1212             * Returns the first social activity in the ordered set where userId = &#63;.
1213             *
1214             * @param userId the user ID
1215             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1216             * @return the first matching social activity
1217             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1218             * @throws SystemException if a system exception occurred
1219             */
1220            public SocialActivity findByUserId_First(long userId,
1221                    OrderByComparator orderByComparator)
1222                    throws NoSuchActivityException, SystemException {
1223                    SocialActivity socialActivity = fetchByUserId_First(userId,
1224                                    orderByComparator);
1225    
1226                    if (socialActivity != null) {
1227                            return socialActivity;
1228                    }
1229    
1230                    StringBundler msg = new StringBundler(4);
1231    
1232                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1233    
1234                    msg.append("userId=");
1235                    msg.append(userId);
1236    
1237                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1238    
1239                    throw new NoSuchActivityException(msg.toString());
1240            }
1241    
1242            /**
1243             * Returns the first social activity in the ordered set where userId = &#63;.
1244             *
1245             * @param userId the user ID
1246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1247             * @return the first matching social activity, or <code>null</code> if a matching social activity could not be found
1248             * @throws SystemException if a system exception occurred
1249             */
1250            public SocialActivity fetchByUserId_First(long userId,
1251                    OrderByComparator orderByComparator) throws SystemException {
1252                    List<SocialActivity> list = findByUserId(userId, 0, 1, orderByComparator);
1253    
1254                    if (!list.isEmpty()) {
1255                            return list.get(0);
1256                    }
1257    
1258                    return null;
1259            }
1260    
1261            /**
1262             * Returns the last social activity in the ordered set where userId = &#63;.
1263             *
1264             * @param userId the user ID
1265             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1266             * @return the last matching social activity
1267             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1268             * @throws SystemException if a system exception occurred
1269             */
1270            public SocialActivity findByUserId_Last(long userId,
1271                    OrderByComparator orderByComparator)
1272                    throws NoSuchActivityException, SystemException {
1273                    SocialActivity socialActivity = fetchByUserId_Last(userId,
1274                                    orderByComparator);
1275    
1276                    if (socialActivity != null) {
1277                            return socialActivity;
1278                    }
1279    
1280                    StringBundler msg = new StringBundler(4);
1281    
1282                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1283    
1284                    msg.append("userId=");
1285                    msg.append(userId);
1286    
1287                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1288    
1289                    throw new NoSuchActivityException(msg.toString());
1290            }
1291    
1292            /**
1293             * Returns the last social activity in the ordered set where userId = &#63;.
1294             *
1295             * @param userId the user ID
1296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1297             * @return the last matching social activity, or <code>null</code> if a matching social activity could not be found
1298             * @throws SystemException if a system exception occurred
1299             */
1300            public SocialActivity fetchByUserId_Last(long userId,
1301                    OrderByComparator orderByComparator) throws SystemException {
1302                    int count = countByUserId(userId);
1303    
1304                    List<SocialActivity> list = findByUserId(userId, count - 1, count,
1305                                    orderByComparator);
1306    
1307                    if (!list.isEmpty()) {
1308                            return list.get(0);
1309                    }
1310    
1311                    return null;
1312            }
1313    
1314            /**
1315             * Returns the social activities before and after the current social activity in the ordered set where userId = &#63;.
1316             *
1317             * @param activityId the primary key of the current social activity
1318             * @param userId the user ID
1319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1320             * @return the previous, current, and next social activity
1321             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
1322             * @throws SystemException if a system exception occurred
1323             */
1324            public SocialActivity[] findByUserId_PrevAndNext(long activityId,
1325                    long userId, OrderByComparator orderByComparator)
1326                    throws NoSuchActivityException, SystemException {
1327                    SocialActivity socialActivity = findByPrimaryKey(activityId);
1328    
1329                    Session session = null;
1330    
1331                    try {
1332                            session = openSession();
1333    
1334                            SocialActivity[] array = new SocialActivityImpl[3];
1335    
1336                            array[0] = getByUserId_PrevAndNext(session, socialActivity, userId,
1337                                            orderByComparator, true);
1338    
1339                            array[1] = socialActivity;
1340    
1341                            array[2] = getByUserId_PrevAndNext(session, socialActivity, userId,
1342                                            orderByComparator, false);
1343    
1344                            return array;
1345                    }
1346                    catch (Exception e) {
1347                            throw processException(e);
1348                    }
1349                    finally {
1350                            closeSession(session);
1351                    }
1352            }
1353    
1354            protected SocialActivity getByUserId_PrevAndNext(Session session,
1355                    SocialActivity socialActivity, long userId,
1356                    OrderByComparator orderByComparator, boolean previous) {
1357                    StringBundler query = null;
1358    
1359                    if (orderByComparator != null) {
1360                            query = new StringBundler(6 +
1361                                            (orderByComparator.getOrderByFields().length * 6));
1362                    }
1363                    else {
1364                            query = new StringBundler(3);
1365                    }
1366    
1367                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1368    
1369                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1370    
1371                    if (orderByComparator != null) {
1372                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1373    
1374                            if (orderByConditionFields.length > 0) {
1375                                    query.append(WHERE_AND);
1376                            }
1377    
1378                            for (int i = 0; i < orderByConditionFields.length; i++) {
1379                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1380                                    query.append(orderByConditionFields[i]);
1381    
1382                                    if ((i + 1) < orderByConditionFields.length) {
1383                                            if (orderByComparator.isAscending() ^ previous) {
1384                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1385                                            }
1386                                            else {
1387                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1388                                            }
1389                                    }
1390                                    else {
1391                                            if (orderByComparator.isAscending() ^ previous) {
1392                                                    query.append(WHERE_GREATER_THAN);
1393                                            }
1394                                            else {
1395                                                    query.append(WHERE_LESSER_THAN);
1396                                            }
1397                                    }
1398                            }
1399    
1400                            query.append(ORDER_BY_CLAUSE);
1401    
1402                            String[] orderByFields = orderByComparator.getOrderByFields();
1403    
1404                            for (int i = 0; i < orderByFields.length; i++) {
1405                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1406                                    query.append(orderByFields[i]);
1407    
1408                                    if ((i + 1) < orderByFields.length) {
1409                                            if (orderByComparator.isAscending() ^ previous) {
1410                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1411                                            }
1412                                            else {
1413                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1414                                            }
1415                                    }
1416                                    else {
1417                                            if (orderByComparator.isAscending() ^ previous) {
1418                                                    query.append(ORDER_BY_ASC);
1419                                            }
1420                                            else {
1421                                                    query.append(ORDER_BY_DESC);
1422                                            }
1423                                    }
1424                            }
1425                    }
1426                    else {
1427                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1428                    }
1429    
1430                    String sql = query.toString();
1431    
1432                    Query q = session.createQuery(sql);
1433    
1434                    q.setFirstResult(0);
1435                    q.setMaxResults(2);
1436    
1437                    QueryPos qPos = QueryPos.getInstance(q);
1438    
1439                    qPos.add(userId);
1440    
1441                    if (orderByComparator != null) {
1442                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
1443    
1444                            for (Object value : values) {
1445                                    qPos.add(value);
1446                            }
1447                    }
1448    
1449                    List<SocialActivity> list = q.list();
1450    
1451                    if (list.size() == 2) {
1452                            return list.get(1);
1453                    }
1454                    else {
1455                            return null;
1456                    }
1457            }
1458    
1459            /**
1460             * Removes all the social activities where userId = &#63; from the database.
1461             *
1462             * @param userId the user ID
1463             * @throws SystemException if a system exception occurred
1464             */
1465            public void removeByUserId(long userId) throws SystemException {
1466                    for (SocialActivity socialActivity : findByUserId(userId,
1467                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1468                            remove(socialActivity);
1469                    }
1470            }
1471    
1472            /**
1473             * Returns the number of social activities where userId = &#63;.
1474             *
1475             * @param userId the user ID
1476             * @return the number of matching social activities
1477             * @throws SystemException if a system exception occurred
1478             */
1479            public int countByUserId(long userId) throws SystemException {
1480                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1481    
1482                    Object[] finderArgs = new Object[] { userId };
1483    
1484                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1485                                    this);
1486    
1487                    if (count == null) {
1488                            StringBundler query = new StringBundler(2);
1489    
1490                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
1491    
1492                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1493    
1494                            String sql = query.toString();
1495    
1496                            Session session = null;
1497    
1498                            try {
1499                                    session = openSession();
1500    
1501                                    Query q = session.createQuery(sql);
1502    
1503                                    QueryPos qPos = QueryPos.getInstance(q);
1504    
1505                                    qPos.add(userId);
1506    
1507                                    count = (Long)q.uniqueResult();
1508    
1509                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1510                            }
1511                            catch (Exception e) {
1512                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1513    
1514                                    throw processException(e);
1515                            }
1516                            finally {
1517                                    closeSession(session);
1518                            }
1519                    }
1520    
1521                    return count.intValue();
1522            }
1523    
1524            private static final String _FINDER_COLUMN_USERID_USERID_2 = "socialActivity.userId = ?";
1525            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVITYSETID =
1526                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
1527                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
1528                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1529                            "findByActivitySetId",
1530                            new String[] {
1531                                    Long.class.getName(),
1532                                    
1533                            Integer.class.getName(), Integer.class.getName(),
1534                                    OrderByComparator.class.getName()
1535                            });
1536            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVITYSETID =
1537                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
1538                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
1539                            SocialActivityImpl.class,
1540                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByActivitySetId",
1541                            new String[] { Long.class.getName() },
1542                            SocialActivityModelImpl.ACTIVITYSETID_COLUMN_BITMASK |
1543                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK);
1544            public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVITYSETID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
1545                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
1546                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActivitySetId",
1547                            new String[] { Long.class.getName() });
1548    
1549            /**
1550             * Returns all the social activities where activitySetId = &#63;.
1551             *
1552             * @param activitySetId the activity set ID
1553             * @return the matching social activities
1554             * @throws SystemException if a system exception occurred
1555             */
1556            public List<SocialActivity> findByActivitySetId(long activitySetId)
1557                    throws SystemException {
1558                    return findByActivitySetId(activitySetId, QueryUtil.ALL_POS,
1559                            QueryUtil.ALL_POS, null);
1560            }
1561    
1562            /**
1563             * Returns a range of all the social activities where activitySetId = &#63;.
1564             *
1565             * <p>
1566             * 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.SocialActivityModelImpl}. 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.
1567             * </p>
1568             *
1569             * @param activitySetId the activity set ID
1570             * @param start the lower bound of the range of social activities
1571             * @param end the upper bound of the range of social activities (not inclusive)
1572             * @return the range of matching social activities
1573             * @throws SystemException if a system exception occurred
1574             */
1575            public List<SocialActivity> findByActivitySetId(long activitySetId,
1576                    int start, int end) throws SystemException {
1577                    return findByActivitySetId(activitySetId, start, end, null);
1578            }
1579    
1580            /**
1581             * Returns an ordered range of all the social activities where activitySetId = &#63;.
1582             *
1583             * <p>
1584             * 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.SocialActivityModelImpl}. 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.
1585             * </p>
1586             *
1587             * @param activitySetId the activity set ID
1588             * @param start the lower bound of the range of social activities
1589             * @param end the upper bound of the range of social activities (not inclusive)
1590             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1591             * @return the ordered range of matching social activities
1592             * @throws SystemException if a system exception occurred
1593             */
1594            public List<SocialActivity> findByActivitySetId(long activitySetId,
1595                    int start, int end, OrderByComparator orderByComparator)
1596                    throws SystemException {
1597                    boolean pagination = true;
1598                    FinderPath finderPath = null;
1599                    Object[] finderArgs = null;
1600    
1601                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1602                                    (orderByComparator == null)) {
1603                            pagination = false;
1604                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVITYSETID;
1605                            finderArgs = new Object[] { activitySetId };
1606                    }
1607                    else {
1608                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVITYSETID;
1609                            finderArgs = new Object[] {
1610                                            activitySetId,
1611                                            
1612                                            start, end, orderByComparator
1613                                    };
1614                    }
1615    
1616                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
1617                                    finderArgs, this);
1618    
1619                    if ((list != null) && !list.isEmpty()) {
1620                            for (SocialActivity socialActivity : list) {
1621                                    if ((activitySetId != socialActivity.getActivitySetId())) {
1622                                            list = null;
1623    
1624                                            break;
1625                                    }
1626                            }
1627                    }
1628    
1629                    if (list == null) {
1630                            StringBundler query = null;
1631    
1632                            if (orderByComparator != null) {
1633                                    query = new StringBundler(3 +
1634                                                    (orderByComparator.getOrderByFields().length * 3));
1635                            }
1636                            else {
1637                                    query = new StringBundler(3);
1638                            }
1639    
1640                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1641    
1642                            query.append(_FINDER_COLUMN_ACTIVITYSETID_ACTIVITYSETID_2);
1643    
1644                            if (orderByComparator != null) {
1645                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1646                                            orderByComparator);
1647                            }
1648                            else
1649                             if (pagination) {
1650                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1651                            }
1652    
1653                            String sql = query.toString();
1654    
1655                            Session session = null;
1656    
1657                            try {
1658                                    session = openSession();
1659    
1660                                    Query q = session.createQuery(sql);
1661    
1662                                    QueryPos qPos = QueryPos.getInstance(q);
1663    
1664                                    qPos.add(activitySetId);
1665    
1666                                    if (!pagination) {
1667                                            list = (List<SocialActivity>)QueryUtil.list(q,
1668                                                            getDialect(), start, end, false);
1669    
1670                                            Collections.sort(list);
1671    
1672                                            list = new UnmodifiableList<SocialActivity>(list);
1673                                    }
1674                                    else {
1675                                            list = (List<SocialActivity>)QueryUtil.list(q,
1676                                                            getDialect(), start, end);
1677                                    }
1678    
1679                                    cacheResult(list);
1680    
1681                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1682                            }
1683                            catch (Exception e) {
1684                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1685    
1686                                    throw processException(e);
1687                            }
1688                            finally {
1689                                    closeSession(session);
1690                            }
1691                    }
1692    
1693                    return list;
1694            }
1695    
1696            /**
1697             * Returns the first social activity in the ordered set where activitySetId = &#63;.
1698             *
1699             * @param activitySetId the activity set ID
1700             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1701             * @return the first matching social activity
1702             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1703             * @throws SystemException if a system exception occurred
1704             */
1705            public SocialActivity findByActivitySetId_First(long activitySetId,
1706                    OrderByComparator orderByComparator)
1707                    throws NoSuchActivityException, SystemException {
1708                    SocialActivity socialActivity = fetchByActivitySetId_First(activitySetId,
1709                                    orderByComparator);
1710    
1711                    if (socialActivity != null) {
1712                            return socialActivity;
1713                    }
1714    
1715                    StringBundler msg = new StringBundler(4);
1716    
1717                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1718    
1719                    msg.append("activitySetId=");
1720                    msg.append(activitySetId);
1721    
1722                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1723    
1724                    throw new NoSuchActivityException(msg.toString());
1725            }
1726    
1727            /**
1728             * Returns the first social activity in the ordered set where activitySetId = &#63;.
1729             *
1730             * @param activitySetId the activity set ID
1731             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1732             * @return the first matching social activity, or <code>null</code> if a matching social activity could not be found
1733             * @throws SystemException if a system exception occurred
1734             */
1735            public SocialActivity fetchByActivitySetId_First(long activitySetId,
1736                    OrderByComparator orderByComparator) throws SystemException {
1737                    List<SocialActivity> list = findByActivitySetId(activitySetId, 0, 1,
1738                                    orderByComparator);
1739    
1740                    if (!list.isEmpty()) {
1741                            return list.get(0);
1742                    }
1743    
1744                    return null;
1745            }
1746    
1747            /**
1748             * Returns the last social activity in the ordered set where activitySetId = &#63;.
1749             *
1750             * @param activitySetId the activity set ID
1751             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1752             * @return the last matching social activity
1753             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1754             * @throws SystemException if a system exception occurred
1755             */
1756            public SocialActivity findByActivitySetId_Last(long activitySetId,
1757                    OrderByComparator orderByComparator)
1758                    throws NoSuchActivityException, SystemException {
1759                    SocialActivity socialActivity = fetchByActivitySetId_Last(activitySetId,
1760                                    orderByComparator);
1761    
1762                    if (socialActivity != null) {
1763                            return socialActivity;
1764                    }
1765    
1766                    StringBundler msg = new StringBundler(4);
1767    
1768                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1769    
1770                    msg.append("activitySetId=");
1771                    msg.append(activitySetId);
1772    
1773                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1774    
1775                    throw new NoSuchActivityException(msg.toString());
1776            }
1777    
1778            /**
1779             * Returns the last social activity in the ordered set where activitySetId = &#63;.
1780             *
1781             * @param activitySetId the activity set ID
1782             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1783             * @return the last matching social activity, or <code>null</code> if a matching social activity could not be found
1784             * @throws SystemException if a system exception occurred
1785             */
1786            public SocialActivity fetchByActivitySetId_Last(long activitySetId,
1787                    OrderByComparator orderByComparator) throws SystemException {
1788                    int count = countByActivitySetId(activitySetId);
1789    
1790                    List<SocialActivity> list = findByActivitySetId(activitySetId,
1791                                    count - 1, count, orderByComparator);
1792    
1793                    if (!list.isEmpty()) {
1794                            return list.get(0);
1795                    }
1796    
1797                    return null;
1798            }
1799    
1800            /**
1801             * Returns the social activities before and after the current social activity in the ordered set where activitySetId = &#63;.
1802             *
1803             * @param activityId the primary key of the current social activity
1804             * @param activitySetId the activity set ID
1805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1806             * @return the previous, current, and next social activity
1807             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
1808             * @throws SystemException if a system exception occurred
1809             */
1810            public SocialActivity[] findByActivitySetId_PrevAndNext(long activityId,
1811                    long activitySetId, OrderByComparator orderByComparator)
1812                    throws NoSuchActivityException, SystemException {
1813                    SocialActivity socialActivity = findByPrimaryKey(activityId);
1814    
1815                    Session session = null;
1816    
1817                    try {
1818                            session = openSession();
1819    
1820                            SocialActivity[] array = new SocialActivityImpl[3];
1821    
1822                            array[0] = getByActivitySetId_PrevAndNext(session, socialActivity,
1823                                            activitySetId, orderByComparator, true);
1824    
1825                            array[1] = socialActivity;
1826    
1827                            array[2] = getByActivitySetId_PrevAndNext(session, socialActivity,
1828                                            activitySetId, orderByComparator, false);
1829    
1830                            return array;
1831                    }
1832                    catch (Exception e) {
1833                            throw processException(e);
1834                    }
1835                    finally {
1836                            closeSession(session);
1837                    }
1838            }
1839    
1840            protected SocialActivity getByActivitySetId_PrevAndNext(Session session,
1841                    SocialActivity socialActivity, long activitySetId,
1842                    OrderByComparator orderByComparator, boolean previous) {
1843                    StringBundler query = null;
1844    
1845                    if (orderByComparator != null) {
1846                            query = new StringBundler(6 +
1847                                            (orderByComparator.getOrderByFields().length * 6));
1848                    }
1849                    else {
1850                            query = new StringBundler(3);
1851                    }
1852    
1853                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1854    
1855                    query.append(_FINDER_COLUMN_ACTIVITYSETID_ACTIVITYSETID_2);
1856    
1857                    if (orderByComparator != null) {
1858                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1859    
1860                            if (orderByConditionFields.length > 0) {
1861                                    query.append(WHERE_AND);
1862                            }
1863    
1864                            for (int i = 0; i < orderByConditionFields.length; i++) {
1865                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1866                                    query.append(orderByConditionFields[i]);
1867    
1868                                    if ((i + 1) < orderByConditionFields.length) {
1869                                            if (orderByComparator.isAscending() ^ previous) {
1870                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1871                                            }
1872                                            else {
1873                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1874                                            }
1875                                    }
1876                                    else {
1877                                            if (orderByComparator.isAscending() ^ previous) {
1878                                                    query.append(WHERE_GREATER_THAN);
1879                                            }
1880                                            else {
1881                                                    query.append(WHERE_LESSER_THAN);
1882                                            }
1883                                    }
1884                            }
1885    
1886                            query.append(ORDER_BY_CLAUSE);
1887    
1888                            String[] orderByFields = orderByComparator.getOrderByFields();
1889    
1890                            for (int i = 0; i < orderByFields.length; i++) {
1891                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1892                                    query.append(orderByFields[i]);
1893    
1894                                    if ((i + 1) < orderByFields.length) {
1895                                            if (orderByComparator.isAscending() ^ previous) {
1896                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1897                                            }
1898                                            else {
1899                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1900                                            }
1901                                    }
1902                                    else {
1903                                            if (orderByComparator.isAscending() ^ previous) {
1904                                                    query.append(ORDER_BY_ASC);
1905                                            }
1906                                            else {
1907                                                    query.append(ORDER_BY_DESC);
1908                                            }
1909                                    }
1910                            }
1911                    }
1912                    else {
1913                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1914                    }
1915    
1916                    String sql = query.toString();
1917    
1918                    Query q = session.createQuery(sql);
1919    
1920                    q.setFirstResult(0);
1921                    q.setMaxResults(2);
1922    
1923                    QueryPos qPos = QueryPos.getInstance(q);
1924    
1925                    qPos.add(activitySetId);
1926    
1927                    if (orderByComparator != null) {
1928                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
1929    
1930                            for (Object value : values) {
1931                                    qPos.add(value);
1932                            }
1933                    }
1934    
1935                    List<SocialActivity> list = q.list();
1936    
1937                    if (list.size() == 2) {
1938                            return list.get(1);
1939                    }
1940                    else {
1941                            return null;
1942                    }
1943            }
1944    
1945            /**
1946             * Removes all the social activities where activitySetId = &#63; from the database.
1947             *
1948             * @param activitySetId the activity set ID
1949             * @throws SystemException if a system exception occurred
1950             */
1951            public void removeByActivitySetId(long activitySetId)
1952                    throws SystemException {
1953                    for (SocialActivity socialActivity : findByActivitySetId(
1954                                    activitySetId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1955                            remove(socialActivity);
1956                    }
1957            }
1958    
1959            /**
1960             * Returns the number of social activities where activitySetId = &#63;.
1961             *
1962             * @param activitySetId the activity set ID
1963             * @return the number of matching social activities
1964             * @throws SystemException if a system exception occurred
1965             */
1966            public int countByActivitySetId(long activitySetId)
1967                    throws SystemException {
1968                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVITYSETID;
1969    
1970                    Object[] finderArgs = new Object[] { activitySetId };
1971    
1972                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1973                                    this);
1974    
1975                    if (count == null) {
1976                            StringBundler query = new StringBundler(2);
1977    
1978                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
1979    
1980                            query.append(_FINDER_COLUMN_ACTIVITYSETID_ACTIVITYSETID_2);
1981    
1982                            String sql = query.toString();
1983    
1984                            Session session = null;
1985    
1986                            try {
1987                                    session = openSession();
1988    
1989                                    Query q = session.createQuery(sql);
1990    
1991                                    QueryPos qPos = QueryPos.getInstance(q);
1992    
1993                                    qPos.add(activitySetId);
1994    
1995                                    count = (Long)q.uniqueResult();
1996    
1997                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1998                            }
1999                            catch (Exception e) {
2000                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2001    
2002                                    throw processException(e);
2003                            }
2004                            finally {
2005                                    closeSession(session);
2006                            }
2007                    }
2008    
2009                    return count.intValue();
2010            }
2011    
2012            private static final String _FINDER_COLUMN_ACTIVITYSETID_ACTIVITYSETID_2 = "socialActivity.activitySetId = ?";
2013            public static final FinderPath FINDER_PATH_FETCH_BY_MIRRORACTIVITYID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
2014                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
2015                            SocialActivityImpl.class, FINDER_CLASS_NAME_ENTITY,
2016                            "fetchByMirrorActivityId", new String[] { Long.class.getName() },
2017                            SocialActivityModelImpl.MIRRORACTIVITYID_COLUMN_BITMASK);
2018            public static final FinderPath FINDER_PATH_COUNT_BY_MIRRORACTIVITYID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
2019                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
2020                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2021                            "countByMirrorActivityId", new String[] { Long.class.getName() });
2022    
2023            /**
2024             * Returns the social activity where mirrorActivityId = &#63; or throws a {@link com.liferay.portlet.social.NoSuchActivityException} if it could not be found.
2025             *
2026             * @param mirrorActivityId the mirror activity ID
2027             * @return the matching social activity
2028             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2029             * @throws SystemException if a system exception occurred
2030             */
2031            public SocialActivity findByMirrorActivityId(long mirrorActivityId)
2032                    throws NoSuchActivityException, SystemException {
2033                    SocialActivity socialActivity = fetchByMirrorActivityId(mirrorActivityId);
2034    
2035                    if (socialActivity == null) {
2036                            StringBundler msg = new StringBundler(4);
2037    
2038                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2039    
2040                            msg.append("mirrorActivityId=");
2041                            msg.append(mirrorActivityId);
2042    
2043                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2044    
2045                            if (_log.isWarnEnabled()) {
2046                                    _log.warn(msg.toString());
2047                            }
2048    
2049                            throw new NoSuchActivityException(msg.toString());
2050                    }
2051    
2052                    return socialActivity;
2053            }
2054    
2055            /**
2056             * Returns the social activity where mirrorActivityId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2057             *
2058             * @param mirrorActivityId the mirror activity ID
2059             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
2060             * @throws SystemException if a system exception occurred
2061             */
2062            public SocialActivity fetchByMirrorActivityId(long mirrorActivityId)
2063                    throws SystemException {
2064                    return fetchByMirrorActivityId(mirrorActivityId, true);
2065            }
2066    
2067            /**
2068             * Returns the social activity where mirrorActivityId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2069             *
2070             * @param mirrorActivityId the mirror activity ID
2071             * @param retrieveFromCache whether to use the finder cache
2072             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
2073             * @throws SystemException if a system exception occurred
2074             */
2075            public SocialActivity fetchByMirrorActivityId(long mirrorActivityId,
2076                    boolean retrieveFromCache) throws SystemException {
2077                    Object[] finderArgs = new Object[] { mirrorActivityId };
2078    
2079                    Object result = null;
2080    
2081                    if (retrieveFromCache) {
2082                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
2083                                            finderArgs, this);
2084                    }
2085    
2086                    if (result instanceof SocialActivity) {
2087                            SocialActivity socialActivity = (SocialActivity)result;
2088    
2089                            if ((mirrorActivityId != socialActivity.getMirrorActivityId())) {
2090                                    result = null;
2091                            }
2092                    }
2093    
2094                    if (result == null) {
2095                            StringBundler query = new StringBundler(3);
2096    
2097                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2098    
2099                            query.append(_FINDER_COLUMN_MIRRORACTIVITYID_MIRRORACTIVITYID_2);
2100    
2101                            String sql = query.toString();
2102    
2103                            Session session = null;
2104    
2105                            try {
2106                                    session = openSession();
2107    
2108                                    Query q = session.createQuery(sql);
2109    
2110                                    QueryPos qPos = QueryPos.getInstance(q);
2111    
2112                                    qPos.add(mirrorActivityId);
2113    
2114                                    List<SocialActivity> list = q.list();
2115    
2116                                    if (list.isEmpty()) {
2117                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
2118                                                    finderArgs, list);
2119                                    }
2120                                    else {
2121                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2122                                                    _log.warn(
2123                                                            "SocialActivityPersistenceImpl.fetchByMirrorActivityId(long, boolean) with parameters (" +
2124                                                            StringUtil.merge(finderArgs) +
2125                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
2126                                            }
2127    
2128                                            SocialActivity socialActivity = list.get(0);
2129    
2130                                            result = socialActivity;
2131    
2132                                            cacheResult(socialActivity);
2133    
2134                                            if ((socialActivity.getMirrorActivityId() != mirrorActivityId)) {
2135                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
2136                                                            finderArgs, socialActivity);
2137                                            }
2138                                    }
2139                            }
2140                            catch (Exception e) {
2141                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
2142                                            finderArgs);
2143    
2144                                    throw processException(e);
2145                            }
2146                            finally {
2147                                    closeSession(session);
2148                            }
2149                    }
2150    
2151                    if (result instanceof List<?>) {
2152                            return null;
2153                    }
2154                    else {
2155                            return (SocialActivity)result;
2156                    }
2157            }
2158    
2159            /**
2160             * Removes the social activity where mirrorActivityId = &#63; from the database.
2161             *
2162             * @param mirrorActivityId the mirror activity ID
2163             * @return the social activity that was removed
2164             * @throws SystemException if a system exception occurred
2165             */
2166            public SocialActivity removeByMirrorActivityId(long mirrorActivityId)
2167                    throws NoSuchActivityException, SystemException {
2168                    SocialActivity socialActivity = findByMirrorActivityId(mirrorActivityId);
2169    
2170                    return remove(socialActivity);
2171            }
2172    
2173            /**
2174             * Returns the number of social activities where mirrorActivityId = &#63;.
2175             *
2176             * @param mirrorActivityId the mirror activity ID
2177             * @return the number of matching social activities
2178             * @throws SystemException if a system exception occurred
2179             */
2180            public int countByMirrorActivityId(long mirrorActivityId)
2181                    throws SystemException {
2182                    FinderPath finderPath = FINDER_PATH_COUNT_BY_MIRRORACTIVITYID;
2183    
2184                    Object[] finderArgs = new Object[] { mirrorActivityId };
2185    
2186                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2187                                    this);
2188    
2189                    if (count == null) {
2190                            StringBundler query = new StringBundler(2);
2191    
2192                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
2193    
2194                            query.append(_FINDER_COLUMN_MIRRORACTIVITYID_MIRRORACTIVITYID_2);
2195    
2196                            String sql = query.toString();
2197    
2198                            Session session = null;
2199    
2200                            try {
2201                                    session = openSession();
2202    
2203                                    Query q = session.createQuery(sql);
2204    
2205                                    QueryPos qPos = QueryPos.getInstance(q);
2206    
2207                                    qPos.add(mirrorActivityId);
2208    
2209                                    count = (Long)q.uniqueResult();
2210    
2211                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2212                            }
2213                            catch (Exception e) {
2214                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2215    
2216                                    throw processException(e);
2217                            }
2218                            finally {
2219                                    closeSession(session);
2220                            }
2221                    }
2222    
2223                    return count.intValue();
2224            }
2225    
2226            private static final String _FINDER_COLUMN_MIRRORACTIVITYID_MIRRORACTIVITYID_2 =
2227                    "socialActivity.mirrorActivityId = ?";
2228            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
2229                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
2230                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
2231                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2232                            "findByClassNameId",
2233                            new String[] {
2234                                    Long.class.getName(),
2235                                    
2236                            Integer.class.getName(), Integer.class.getName(),
2237                                    OrderByComparator.class.getName()
2238                            });
2239            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
2240                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
2241                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
2242                            SocialActivityImpl.class,
2243                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassNameId",
2244                            new String[] { Long.class.getName() },
2245                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2246                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK);
2247            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
2248                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
2249                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
2250                            new String[] { Long.class.getName() });
2251    
2252            /**
2253             * Returns all the social activities where classNameId = &#63;.
2254             *
2255             * @param classNameId the class name ID
2256             * @return the matching social activities
2257             * @throws SystemException if a system exception occurred
2258             */
2259            public List<SocialActivity> findByClassNameId(long classNameId)
2260                    throws SystemException {
2261                    return findByClassNameId(classNameId, QueryUtil.ALL_POS,
2262                            QueryUtil.ALL_POS, null);
2263            }
2264    
2265            /**
2266             * Returns a range of all the social activities where classNameId = &#63;.
2267             *
2268             * <p>
2269             * 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.SocialActivityModelImpl}. 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.
2270             * </p>
2271             *
2272             * @param classNameId the class name ID
2273             * @param start the lower bound of the range of social activities
2274             * @param end the upper bound of the range of social activities (not inclusive)
2275             * @return the range of matching social activities
2276             * @throws SystemException if a system exception occurred
2277             */
2278            public List<SocialActivity> findByClassNameId(long classNameId, int start,
2279                    int end) throws SystemException {
2280                    return findByClassNameId(classNameId, start, end, null);
2281            }
2282    
2283            /**
2284             * Returns an ordered range of all the social activities where classNameId = &#63;.
2285             *
2286             * <p>
2287             * 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.SocialActivityModelImpl}. 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.
2288             * </p>
2289             *
2290             * @param classNameId the class name ID
2291             * @param start the lower bound of the range of social activities
2292             * @param end the upper bound of the range of social activities (not inclusive)
2293             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2294             * @return the ordered range of matching social activities
2295             * @throws SystemException if a system exception occurred
2296             */
2297            public List<SocialActivity> findByClassNameId(long classNameId, int start,
2298                    int end, OrderByComparator orderByComparator) throws SystemException {
2299                    boolean pagination = true;
2300                    FinderPath finderPath = null;
2301                    Object[] finderArgs = null;
2302    
2303                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2304                                    (orderByComparator == null)) {
2305                            pagination = false;
2306                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
2307                            finderArgs = new Object[] { classNameId };
2308                    }
2309                    else {
2310                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
2311                            finderArgs = new Object[] { classNameId, start, end, orderByComparator };
2312                    }
2313    
2314                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
2315                                    finderArgs, this);
2316    
2317                    if ((list != null) && !list.isEmpty()) {
2318                            for (SocialActivity socialActivity : list) {
2319                                    if ((classNameId != socialActivity.getClassNameId())) {
2320                                            list = null;
2321    
2322                                            break;
2323                                    }
2324                            }
2325                    }
2326    
2327                    if (list == null) {
2328                            StringBundler query = null;
2329    
2330                            if (orderByComparator != null) {
2331                                    query = new StringBundler(3 +
2332                                                    (orderByComparator.getOrderByFields().length * 3));
2333                            }
2334                            else {
2335                                    query = new StringBundler(3);
2336                            }
2337    
2338                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2339    
2340                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
2341    
2342                            if (orderByComparator != null) {
2343                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2344                                            orderByComparator);
2345                            }
2346                            else
2347                             if (pagination) {
2348                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2349                            }
2350    
2351                            String sql = query.toString();
2352    
2353                            Session session = null;
2354    
2355                            try {
2356                                    session = openSession();
2357    
2358                                    Query q = session.createQuery(sql);
2359    
2360                                    QueryPos qPos = QueryPos.getInstance(q);
2361    
2362                                    qPos.add(classNameId);
2363    
2364                                    if (!pagination) {
2365                                            list = (List<SocialActivity>)QueryUtil.list(q,
2366                                                            getDialect(), start, end, false);
2367    
2368                                            Collections.sort(list);
2369    
2370                                            list = new UnmodifiableList<SocialActivity>(list);
2371                                    }
2372                                    else {
2373                                            list = (List<SocialActivity>)QueryUtil.list(q,
2374                                                            getDialect(), start, end);
2375                                    }
2376    
2377                                    cacheResult(list);
2378    
2379                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2380                            }
2381                            catch (Exception e) {
2382                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2383    
2384                                    throw processException(e);
2385                            }
2386                            finally {
2387                                    closeSession(session);
2388                            }
2389                    }
2390    
2391                    return list;
2392            }
2393    
2394            /**
2395             * Returns the first social activity in the ordered set where classNameId = &#63;.
2396             *
2397             * @param classNameId the class name ID
2398             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2399             * @return the first matching social activity
2400             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2401             * @throws SystemException if a system exception occurred
2402             */
2403            public SocialActivity findByClassNameId_First(long classNameId,
2404                    OrderByComparator orderByComparator)
2405                    throws NoSuchActivityException, SystemException {
2406                    SocialActivity socialActivity = fetchByClassNameId_First(classNameId,
2407                                    orderByComparator);
2408    
2409                    if (socialActivity != null) {
2410                            return socialActivity;
2411                    }
2412    
2413                    StringBundler msg = new StringBundler(4);
2414    
2415                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2416    
2417                    msg.append("classNameId=");
2418                    msg.append(classNameId);
2419    
2420                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2421    
2422                    throw new NoSuchActivityException(msg.toString());
2423            }
2424    
2425            /**
2426             * Returns the first social activity in the ordered set where classNameId = &#63;.
2427             *
2428             * @param classNameId the class name ID
2429             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2430             * @return the first matching social activity, or <code>null</code> if a matching social activity could not be found
2431             * @throws SystemException if a system exception occurred
2432             */
2433            public SocialActivity fetchByClassNameId_First(long classNameId,
2434                    OrderByComparator orderByComparator) throws SystemException {
2435                    List<SocialActivity> list = findByClassNameId(classNameId, 0, 1,
2436                                    orderByComparator);
2437    
2438                    if (!list.isEmpty()) {
2439                            return list.get(0);
2440                    }
2441    
2442                    return null;
2443            }
2444    
2445            /**
2446             * Returns the last social activity in the ordered set where classNameId = &#63;.
2447             *
2448             * @param classNameId the class name ID
2449             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2450             * @return the last matching social activity
2451             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2452             * @throws SystemException if a system exception occurred
2453             */
2454            public SocialActivity findByClassNameId_Last(long classNameId,
2455                    OrderByComparator orderByComparator)
2456                    throws NoSuchActivityException, SystemException {
2457                    SocialActivity socialActivity = fetchByClassNameId_Last(classNameId,
2458                                    orderByComparator);
2459    
2460                    if (socialActivity != null) {
2461                            return socialActivity;
2462                    }
2463    
2464                    StringBundler msg = new StringBundler(4);
2465    
2466                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2467    
2468                    msg.append("classNameId=");
2469                    msg.append(classNameId);
2470    
2471                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2472    
2473                    throw new NoSuchActivityException(msg.toString());
2474            }
2475    
2476            /**
2477             * Returns the last social activity in the ordered set where classNameId = &#63;.
2478             *
2479             * @param classNameId the class name ID
2480             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2481             * @return the last matching social activity, or <code>null</code> if a matching social activity could not be found
2482             * @throws SystemException if a system exception occurred
2483             */
2484            public SocialActivity fetchByClassNameId_Last(long classNameId,
2485                    OrderByComparator orderByComparator) throws SystemException {
2486                    int count = countByClassNameId(classNameId);
2487    
2488                    List<SocialActivity> list = findByClassNameId(classNameId, count - 1,
2489                                    count, orderByComparator);
2490    
2491                    if (!list.isEmpty()) {
2492                            return list.get(0);
2493                    }
2494    
2495                    return null;
2496            }
2497    
2498            /**
2499             * Returns the social activities before and after the current social activity in the ordered set where classNameId = &#63;.
2500             *
2501             * @param activityId the primary key of the current social activity
2502             * @param classNameId the class name ID
2503             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2504             * @return the previous, current, and next social activity
2505             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
2506             * @throws SystemException if a system exception occurred
2507             */
2508            public SocialActivity[] findByClassNameId_PrevAndNext(long activityId,
2509                    long classNameId, OrderByComparator orderByComparator)
2510                    throws NoSuchActivityException, SystemException {
2511                    SocialActivity socialActivity = findByPrimaryKey(activityId);
2512    
2513                    Session session = null;
2514    
2515                    try {
2516                            session = openSession();
2517    
2518                            SocialActivity[] array = new SocialActivityImpl[3];
2519    
2520                            array[0] = getByClassNameId_PrevAndNext(session, socialActivity,
2521                                            classNameId, orderByComparator, true);
2522    
2523                            array[1] = socialActivity;
2524    
2525                            array[2] = getByClassNameId_PrevAndNext(session, socialActivity,
2526                                            classNameId, orderByComparator, false);
2527    
2528                            return array;
2529                    }
2530                    catch (Exception e) {
2531                            throw processException(e);
2532                    }
2533                    finally {
2534                            closeSession(session);
2535                    }
2536            }
2537    
2538            protected SocialActivity getByClassNameId_PrevAndNext(Session session,
2539                    SocialActivity socialActivity, long classNameId,
2540                    OrderByComparator orderByComparator, boolean previous) {
2541                    StringBundler query = null;
2542    
2543                    if (orderByComparator != null) {
2544                            query = new StringBundler(6 +
2545                                            (orderByComparator.getOrderByFields().length * 6));
2546                    }
2547                    else {
2548                            query = new StringBundler(3);
2549                    }
2550    
2551                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2552    
2553                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
2554    
2555                    if (orderByComparator != null) {
2556                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2557    
2558                            if (orderByConditionFields.length > 0) {
2559                                    query.append(WHERE_AND);
2560                            }
2561    
2562                            for (int i = 0; i < orderByConditionFields.length; i++) {
2563                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2564                                    query.append(orderByConditionFields[i]);
2565    
2566                                    if ((i + 1) < orderByConditionFields.length) {
2567                                            if (orderByComparator.isAscending() ^ previous) {
2568                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2569                                            }
2570                                            else {
2571                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2572                                            }
2573                                    }
2574                                    else {
2575                                            if (orderByComparator.isAscending() ^ previous) {
2576                                                    query.append(WHERE_GREATER_THAN);
2577                                            }
2578                                            else {
2579                                                    query.append(WHERE_LESSER_THAN);
2580                                            }
2581                                    }
2582                            }
2583    
2584                            query.append(ORDER_BY_CLAUSE);
2585    
2586                            String[] orderByFields = orderByComparator.getOrderByFields();
2587    
2588                            for (int i = 0; i < orderByFields.length; i++) {
2589                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2590                                    query.append(orderByFields[i]);
2591    
2592                                    if ((i + 1) < orderByFields.length) {
2593                                            if (orderByComparator.isAscending() ^ previous) {
2594                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2595                                            }
2596                                            else {
2597                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2598                                            }
2599                                    }
2600                                    else {
2601                                            if (orderByComparator.isAscending() ^ previous) {
2602                                                    query.append(ORDER_BY_ASC);
2603                                            }
2604                                            else {
2605                                                    query.append(ORDER_BY_DESC);
2606                                            }
2607                                    }
2608                            }
2609                    }
2610                    else {
2611                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2612                    }
2613    
2614                    String sql = query.toString();
2615    
2616                    Query q = session.createQuery(sql);
2617    
2618                    q.setFirstResult(0);
2619                    q.setMaxResults(2);
2620    
2621                    QueryPos qPos = QueryPos.getInstance(q);
2622    
2623                    qPos.add(classNameId);
2624    
2625                    if (orderByComparator != null) {
2626                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
2627    
2628                            for (Object value : values) {
2629                                    qPos.add(value);
2630                            }
2631                    }
2632    
2633                    List<SocialActivity> list = q.list();
2634    
2635                    if (list.size() == 2) {
2636                            return list.get(1);
2637                    }
2638                    else {
2639                            return null;
2640                    }
2641            }
2642    
2643            /**
2644             * Removes all the social activities where classNameId = &#63; from the database.
2645             *
2646             * @param classNameId the class name ID
2647             * @throws SystemException if a system exception occurred
2648             */
2649            public void removeByClassNameId(long classNameId) throws SystemException {
2650                    for (SocialActivity socialActivity : findByClassNameId(classNameId,
2651                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2652                            remove(socialActivity);
2653                    }
2654            }
2655    
2656            /**
2657             * Returns the number of social activities where classNameId = &#63;.
2658             *
2659             * @param classNameId the class name ID
2660             * @return the number of matching social activities
2661             * @throws SystemException if a system exception occurred
2662             */
2663            public int countByClassNameId(long classNameId) throws SystemException {
2664                    FinderPath finderPath = FINDER_PATH_COUNT_BY_CLASSNAMEID;
2665    
2666                    Object[] finderArgs = new Object[] { classNameId };
2667    
2668                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2669                                    this);
2670    
2671                    if (count == null) {
2672                            StringBundler query = new StringBundler(2);
2673    
2674                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
2675    
2676                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
2677    
2678                            String sql = query.toString();
2679    
2680                            Session session = null;
2681    
2682                            try {
2683                                    session = openSession();
2684    
2685                                    Query q = session.createQuery(sql);
2686    
2687                                    QueryPos qPos = QueryPos.getInstance(q);
2688    
2689                                    qPos.add(classNameId);
2690    
2691                                    count = (Long)q.uniqueResult();
2692    
2693                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2694                            }
2695                            catch (Exception e) {
2696                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2697    
2698                                    throw processException(e);
2699                            }
2700                            finally {
2701                                    closeSession(session);
2702                            }
2703                    }
2704    
2705                    return count.intValue();
2706            }
2707    
2708            private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "socialActivity.classNameId = ?";
2709            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RECEIVERUSERID =
2710                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
2711                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
2712                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2713                            "findByReceiverUserId",
2714                            new String[] {
2715                                    Long.class.getName(),
2716                                    
2717                            Integer.class.getName(), Integer.class.getName(),
2718                                    OrderByComparator.class.getName()
2719                            });
2720            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID =
2721                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
2722                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
2723                            SocialActivityImpl.class,
2724                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByReceiverUserId",
2725                            new String[] { Long.class.getName() },
2726                            SocialActivityModelImpl.RECEIVERUSERID_COLUMN_BITMASK |
2727                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK);
2728            public static final FinderPath FINDER_PATH_COUNT_BY_RECEIVERUSERID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
2729                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
2730                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByReceiverUserId",
2731                            new String[] { Long.class.getName() });
2732    
2733            /**
2734             * Returns all the social activities where receiverUserId = &#63;.
2735             *
2736             * @param receiverUserId the receiver user ID
2737             * @return the matching social activities
2738             * @throws SystemException if a system exception occurred
2739             */
2740            public List<SocialActivity> findByReceiverUserId(long receiverUserId)
2741                    throws SystemException {
2742                    return findByReceiverUserId(receiverUserId, QueryUtil.ALL_POS,
2743                            QueryUtil.ALL_POS, null);
2744            }
2745    
2746            /**
2747             * Returns a range of all the social activities where receiverUserId = &#63;.
2748             *
2749             * <p>
2750             * 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.SocialActivityModelImpl}. 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.
2751             * </p>
2752             *
2753             * @param receiverUserId the receiver user ID
2754             * @param start the lower bound of the range of social activities
2755             * @param end the upper bound of the range of social activities (not inclusive)
2756             * @return the range of matching social activities
2757             * @throws SystemException if a system exception occurred
2758             */
2759            public List<SocialActivity> findByReceiverUserId(long receiverUserId,
2760                    int start, int end) throws SystemException {
2761                    return findByReceiverUserId(receiverUserId, start, end, null);
2762            }
2763    
2764            /**
2765             * Returns an ordered range of all the social activities where receiverUserId = &#63;.
2766             *
2767             * <p>
2768             * 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.SocialActivityModelImpl}. 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.
2769             * </p>
2770             *
2771             * @param receiverUserId the receiver user ID
2772             * @param start the lower bound of the range of social activities
2773             * @param end the upper bound of the range of social activities (not inclusive)
2774             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2775             * @return the ordered range of matching social activities
2776             * @throws SystemException if a system exception occurred
2777             */
2778            public List<SocialActivity> findByReceiverUserId(long receiverUserId,
2779                    int start, int end, OrderByComparator orderByComparator)
2780                    throws SystemException {
2781                    boolean pagination = true;
2782                    FinderPath finderPath = null;
2783                    Object[] finderArgs = null;
2784    
2785                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2786                                    (orderByComparator == null)) {
2787                            pagination = false;
2788                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID;
2789                            finderArgs = new Object[] { receiverUserId };
2790                    }
2791                    else {
2792                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RECEIVERUSERID;
2793                            finderArgs = new Object[] {
2794                                            receiverUserId,
2795                                            
2796                                            start, end, orderByComparator
2797                                    };
2798                    }
2799    
2800                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
2801                                    finderArgs, this);
2802    
2803                    if ((list != null) && !list.isEmpty()) {
2804                            for (SocialActivity socialActivity : list) {
2805                                    if ((receiverUserId != socialActivity.getReceiverUserId())) {
2806                                            list = null;
2807    
2808                                            break;
2809                                    }
2810                            }
2811                    }
2812    
2813                    if (list == null) {
2814                            StringBundler query = null;
2815    
2816                            if (orderByComparator != null) {
2817                                    query = new StringBundler(3 +
2818                                                    (orderByComparator.getOrderByFields().length * 3));
2819                            }
2820                            else {
2821                                    query = new StringBundler(3);
2822                            }
2823    
2824                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2825    
2826                            query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2827    
2828                            if (orderByComparator != null) {
2829                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2830                                            orderByComparator);
2831                            }
2832                            else
2833                             if (pagination) {
2834                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2835                            }
2836    
2837                            String sql = query.toString();
2838    
2839                            Session session = null;
2840    
2841                            try {
2842                                    session = openSession();
2843    
2844                                    Query q = session.createQuery(sql);
2845    
2846                                    QueryPos qPos = QueryPos.getInstance(q);
2847    
2848                                    qPos.add(receiverUserId);
2849    
2850                                    if (!pagination) {
2851                                            list = (List<SocialActivity>)QueryUtil.list(q,
2852                                                            getDialect(), start, end, false);
2853    
2854                                            Collections.sort(list);
2855    
2856                                            list = new UnmodifiableList<SocialActivity>(list);
2857                                    }
2858                                    else {
2859                                            list = (List<SocialActivity>)QueryUtil.list(q,
2860                                                            getDialect(), start, end);
2861                                    }
2862    
2863                                    cacheResult(list);
2864    
2865                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2866                            }
2867                            catch (Exception e) {
2868                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2869    
2870                                    throw processException(e);
2871                            }
2872                            finally {
2873                                    closeSession(session);
2874                            }
2875                    }
2876    
2877                    return list;
2878            }
2879    
2880            /**
2881             * Returns the first social activity in the ordered set where receiverUserId = &#63;.
2882             *
2883             * @param receiverUserId the receiver user ID
2884             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2885             * @return the first matching social activity
2886             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2887             * @throws SystemException if a system exception occurred
2888             */
2889            public SocialActivity findByReceiverUserId_First(long receiverUserId,
2890                    OrderByComparator orderByComparator)
2891                    throws NoSuchActivityException, SystemException {
2892                    SocialActivity socialActivity = fetchByReceiverUserId_First(receiverUserId,
2893                                    orderByComparator);
2894    
2895                    if (socialActivity != null) {
2896                            return socialActivity;
2897                    }
2898    
2899                    StringBundler msg = new StringBundler(4);
2900    
2901                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2902    
2903                    msg.append("receiverUserId=");
2904                    msg.append(receiverUserId);
2905    
2906                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2907    
2908                    throw new NoSuchActivityException(msg.toString());
2909            }
2910    
2911            /**
2912             * Returns the first social activity in the ordered set where receiverUserId = &#63;.
2913             *
2914             * @param receiverUserId the receiver user ID
2915             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2916             * @return the first matching social activity, or <code>null</code> if a matching social activity could not be found
2917             * @throws SystemException if a system exception occurred
2918             */
2919            public SocialActivity fetchByReceiverUserId_First(long receiverUserId,
2920                    OrderByComparator orderByComparator) throws SystemException {
2921                    List<SocialActivity> list = findByReceiverUserId(receiverUserId, 0, 1,
2922                                    orderByComparator);
2923    
2924                    if (!list.isEmpty()) {
2925                            return list.get(0);
2926                    }
2927    
2928                    return null;
2929            }
2930    
2931            /**
2932             * Returns the last social activity in the ordered set where receiverUserId = &#63;.
2933             *
2934             * @param receiverUserId the receiver user ID
2935             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2936             * @return the last matching social activity
2937             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2938             * @throws SystemException if a system exception occurred
2939             */
2940            public SocialActivity findByReceiverUserId_Last(long receiverUserId,
2941                    OrderByComparator orderByComparator)
2942                    throws NoSuchActivityException, SystemException {
2943                    SocialActivity socialActivity = fetchByReceiverUserId_Last(receiverUserId,
2944                                    orderByComparator);
2945    
2946                    if (socialActivity != null) {
2947                            return socialActivity;
2948                    }
2949    
2950                    StringBundler msg = new StringBundler(4);
2951    
2952                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2953    
2954                    msg.append("receiverUserId=");
2955                    msg.append(receiverUserId);
2956    
2957                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2958    
2959                    throw new NoSuchActivityException(msg.toString());
2960            }
2961    
2962            /**
2963             * Returns the last social activity in the ordered set where receiverUserId = &#63;.
2964             *
2965             * @param receiverUserId the receiver user ID
2966             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2967             * @return the last matching social activity, or <code>null</code> if a matching social activity could not be found
2968             * @throws SystemException if a system exception occurred
2969             */
2970            public SocialActivity fetchByReceiverUserId_Last(long receiverUserId,
2971                    OrderByComparator orderByComparator) throws SystemException {
2972                    int count = countByReceiverUserId(receiverUserId);
2973    
2974                    List<SocialActivity> list = findByReceiverUserId(receiverUserId,
2975                                    count - 1, count, orderByComparator);
2976    
2977                    if (!list.isEmpty()) {
2978                            return list.get(0);
2979                    }
2980    
2981                    return null;
2982            }
2983    
2984            /**
2985             * Returns the social activities before and after the current social activity in the ordered set where receiverUserId = &#63;.
2986             *
2987             * @param activityId the primary key of the current social activity
2988             * @param receiverUserId the receiver user ID
2989             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2990             * @return the previous, current, and next social activity
2991             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
2992             * @throws SystemException if a system exception occurred
2993             */
2994            public SocialActivity[] findByReceiverUserId_PrevAndNext(long activityId,
2995                    long receiverUserId, OrderByComparator orderByComparator)
2996                    throws NoSuchActivityException, SystemException {
2997                    SocialActivity socialActivity = findByPrimaryKey(activityId);
2998    
2999                    Session session = null;
3000    
3001                    try {
3002                            session = openSession();
3003    
3004                            SocialActivity[] array = new SocialActivityImpl[3];
3005    
3006                            array[0] = getByReceiverUserId_PrevAndNext(session, socialActivity,
3007                                            receiverUserId, orderByComparator, true);
3008    
3009                            array[1] = socialActivity;
3010    
3011                            array[2] = getByReceiverUserId_PrevAndNext(session, socialActivity,
3012                                            receiverUserId, orderByComparator, false);
3013    
3014                            return array;
3015                    }
3016                    catch (Exception e) {
3017                            throw processException(e);
3018                    }
3019                    finally {
3020                            closeSession(session);
3021                    }
3022            }
3023    
3024            protected SocialActivity getByReceiverUserId_PrevAndNext(Session session,
3025                    SocialActivity socialActivity, long receiverUserId,
3026                    OrderByComparator orderByComparator, boolean previous) {
3027                    StringBundler query = null;
3028    
3029                    if (orderByComparator != null) {
3030                            query = new StringBundler(6 +
3031                                            (orderByComparator.getOrderByFields().length * 6));
3032                    }
3033                    else {
3034                            query = new StringBundler(3);
3035                    }
3036    
3037                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3038    
3039                    query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
3040    
3041                    if (orderByComparator != null) {
3042                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3043    
3044                            if (orderByConditionFields.length > 0) {
3045                                    query.append(WHERE_AND);
3046                            }
3047    
3048                            for (int i = 0; i < orderByConditionFields.length; i++) {
3049                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3050                                    query.append(orderByConditionFields[i]);
3051    
3052                                    if ((i + 1) < orderByConditionFields.length) {
3053                                            if (orderByComparator.isAscending() ^ previous) {
3054                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3055                                            }
3056                                            else {
3057                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3058                                            }
3059                                    }
3060                                    else {
3061                                            if (orderByComparator.isAscending() ^ previous) {
3062                                                    query.append(WHERE_GREATER_THAN);
3063                                            }
3064                                            else {
3065                                                    query.append(WHERE_LESSER_THAN);
3066                                            }
3067                                    }
3068                            }
3069    
3070                            query.append(ORDER_BY_CLAUSE);
3071    
3072                            String[] orderByFields = orderByComparator.getOrderByFields();
3073    
3074                            for (int i = 0; i < orderByFields.length; i++) {
3075                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3076                                    query.append(orderByFields[i]);
3077    
3078                                    if ((i + 1) < orderByFields.length) {
3079                                            if (orderByComparator.isAscending() ^ previous) {
3080                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3081                                            }
3082                                            else {
3083                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3084                                            }
3085                                    }
3086                                    else {
3087                                            if (orderByComparator.isAscending() ^ previous) {
3088                                                    query.append(ORDER_BY_ASC);
3089                                            }
3090                                            else {
3091                                                    query.append(ORDER_BY_DESC);
3092                                            }
3093                                    }
3094                            }
3095                    }
3096                    else {
3097                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
3098                    }
3099    
3100                    String sql = query.toString();
3101    
3102                    Query q = session.createQuery(sql);
3103    
3104                    q.setFirstResult(0);
3105                    q.setMaxResults(2);
3106    
3107                    QueryPos qPos = QueryPos.getInstance(q);
3108    
3109                    qPos.add(receiverUserId);
3110    
3111                    if (orderByComparator != null) {
3112                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
3113    
3114                            for (Object value : values) {
3115                                    qPos.add(value);
3116                            }
3117                    }
3118    
3119                    List<SocialActivity> list = q.list();
3120    
3121                    if (list.size() == 2) {
3122                            return list.get(1);
3123                    }
3124                    else {
3125                            return null;
3126                    }
3127            }
3128    
3129            /**
3130             * Removes all the social activities where receiverUserId = &#63; from the database.
3131             *
3132             * @param receiverUserId the receiver user ID
3133             * @throws SystemException if a system exception occurred
3134             */
3135            public void removeByReceiverUserId(long receiverUserId)
3136                    throws SystemException {
3137                    for (SocialActivity socialActivity : findByReceiverUserId(
3138                                    receiverUserId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3139                            remove(socialActivity);
3140                    }
3141            }
3142    
3143            /**
3144             * Returns the number of social activities where receiverUserId = &#63;.
3145             *
3146             * @param receiverUserId the receiver user ID
3147             * @return the number of matching social activities
3148             * @throws SystemException if a system exception occurred
3149             */
3150            public int countByReceiverUserId(long receiverUserId)
3151                    throws SystemException {
3152                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RECEIVERUSERID;
3153    
3154                    Object[] finderArgs = new Object[] { receiverUserId };
3155    
3156                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3157                                    this);
3158    
3159                    if (count == null) {
3160                            StringBundler query = new StringBundler(2);
3161    
3162                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
3163    
3164                            query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
3165    
3166                            String sql = query.toString();
3167    
3168                            Session session = null;
3169    
3170                            try {
3171                                    session = openSession();
3172    
3173                                    Query q = session.createQuery(sql);
3174    
3175                                    QueryPos qPos = QueryPos.getInstance(q);
3176    
3177                                    qPos.add(receiverUserId);
3178    
3179                                    count = (Long)q.uniqueResult();
3180    
3181                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3182                            }
3183                            catch (Exception e) {
3184                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3185    
3186                                    throw processException(e);
3187                            }
3188                            finally {
3189                                    closeSession(session);
3190                            }
3191                    }
3192    
3193                    return count.intValue();
3194            }
3195    
3196            private static final String _FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2 = "socialActivity.receiverUserId = ?";
3197            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
3198                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
3199                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3200                            "findByC_C",
3201                            new String[] {
3202                                    Long.class.getName(), Long.class.getName(),
3203                                    
3204                            Integer.class.getName(), Integer.class.getName(),
3205                                    OrderByComparator.class.getName()
3206                            });
3207            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
3208                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
3209                            SocialActivityImpl.class,
3210                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
3211                            new String[] { Long.class.getName(), Long.class.getName() },
3212                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3213                            SocialActivityModelImpl.CLASSPK_COLUMN_BITMASK |
3214                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK);
3215            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
3216                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
3217                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
3218                            new String[] { Long.class.getName(), Long.class.getName() });
3219    
3220            /**
3221             * Returns all the social activities where classNameId = &#63; and classPK = &#63;.
3222             *
3223             * @param classNameId the class name ID
3224             * @param classPK the class p k
3225             * @return the matching social activities
3226             * @throws SystemException if a system exception occurred
3227             */
3228            public List<SocialActivity> findByC_C(long classNameId, long classPK)
3229                    throws SystemException {
3230                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
3231                            QueryUtil.ALL_POS, null);
3232            }
3233    
3234            /**
3235             * Returns a range of all the social activities where classNameId = &#63; and classPK = &#63;.
3236             *
3237             * <p>
3238             * 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.SocialActivityModelImpl}. 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.
3239             * </p>
3240             *
3241             * @param classNameId the class name ID
3242             * @param classPK the class p k
3243             * @param start the lower bound of the range of social activities
3244             * @param end the upper bound of the range of social activities (not inclusive)
3245             * @return the range of matching social activities
3246             * @throws SystemException if a system exception occurred
3247             */
3248            public List<SocialActivity> findByC_C(long classNameId, long classPK,
3249                    int start, int end) throws SystemException {
3250                    return findByC_C(classNameId, classPK, start, end, null);
3251            }
3252    
3253            /**
3254             * Returns an ordered range of all the social activities where classNameId = &#63; and classPK = &#63;.
3255             *
3256             * <p>
3257             * 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.SocialActivityModelImpl}. 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.
3258             * </p>
3259             *
3260             * @param classNameId the class name ID
3261             * @param classPK the class p k
3262             * @param start the lower bound of the range of social activities
3263             * @param end the upper bound of the range of social activities (not inclusive)
3264             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3265             * @return the ordered range of matching social activities
3266             * @throws SystemException if a system exception occurred
3267             */
3268            public List<SocialActivity> findByC_C(long classNameId, long classPK,
3269                    int start, int end, OrderByComparator orderByComparator)
3270                    throws SystemException {
3271                    boolean pagination = true;
3272                    FinderPath finderPath = null;
3273                    Object[] finderArgs = null;
3274    
3275                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3276                                    (orderByComparator == null)) {
3277                            pagination = false;
3278                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
3279                            finderArgs = new Object[] { classNameId, classPK };
3280                    }
3281                    else {
3282                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
3283                            finderArgs = new Object[] {
3284                                            classNameId, classPK,
3285                                            
3286                                            start, end, orderByComparator
3287                                    };
3288                    }
3289    
3290                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
3291                                    finderArgs, this);
3292    
3293                    if ((list != null) && !list.isEmpty()) {
3294                            for (SocialActivity socialActivity : list) {
3295                                    if ((classNameId != socialActivity.getClassNameId()) ||
3296                                                    (classPK != socialActivity.getClassPK())) {
3297                                            list = null;
3298    
3299                                            break;
3300                                    }
3301                            }
3302                    }
3303    
3304                    if (list == null) {
3305                            StringBundler query = null;
3306    
3307                            if (orderByComparator != null) {
3308                                    query = new StringBundler(4 +
3309                                                    (orderByComparator.getOrderByFields().length * 3));
3310                            }
3311                            else {
3312                                    query = new StringBundler(4);
3313                            }
3314    
3315                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3316    
3317                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3318    
3319                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3320    
3321                            if (orderByComparator != null) {
3322                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3323                                            orderByComparator);
3324                            }
3325                            else
3326                             if (pagination) {
3327                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
3328                            }
3329    
3330                            String sql = query.toString();
3331    
3332                            Session session = null;
3333    
3334                            try {
3335                                    session = openSession();
3336    
3337                                    Query q = session.createQuery(sql);
3338    
3339                                    QueryPos qPos = QueryPos.getInstance(q);
3340    
3341                                    qPos.add(classNameId);
3342    
3343                                    qPos.add(classPK);
3344    
3345                                    if (!pagination) {
3346                                            list = (List<SocialActivity>)QueryUtil.list(q,
3347                                                            getDialect(), start, end, false);
3348    
3349                                            Collections.sort(list);
3350    
3351                                            list = new UnmodifiableList<SocialActivity>(list);
3352                                    }
3353                                    else {
3354                                            list = (List<SocialActivity>)QueryUtil.list(q,
3355                                                            getDialect(), start, end);
3356                                    }
3357    
3358                                    cacheResult(list);
3359    
3360                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3361                            }
3362                            catch (Exception e) {
3363                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3364    
3365                                    throw processException(e);
3366                            }
3367                            finally {
3368                                    closeSession(session);
3369                            }
3370                    }
3371    
3372                    return list;
3373            }
3374    
3375            /**
3376             * Returns the first social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
3377             *
3378             * @param classNameId the class name ID
3379             * @param classPK the class p k
3380             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3381             * @return the first matching social activity
3382             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
3383             * @throws SystemException if a system exception occurred
3384             */
3385            public SocialActivity findByC_C_First(long classNameId, long classPK,
3386                    OrderByComparator orderByComparator)
3387                    throws NoSuchActivityException, SystemException {
3388                    SocialActivity socialActivity = fetchByC_C_First(classNameId, classPK,
3389                                    orderByComparator);
3390    
3391                    if (socialActivity != null) {
3392                            return socialActivity;
3393                    }
3394    
3395                    StringBundler msg = new StringBundler(6);
3396    
3397                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3398    
3399                    msg.append("classNameId=");
3400                    msg.append(classNameId);
3401    
3402                    msg.append(", classPK=");
3403                    msg.append(classPK);
3404    
3405                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3406    
3407                    throw new NoSuchActivityException(msg.toString());
3408            }
3409    
3410            /**
3411             * Returns the first social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
3412             *
3413             * @param classNameId the class name ID
3414             * @param classPK the class p k
3415             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3416             * @return the first matching social activity, or <code>null</code> if a matching social activity could not be found
3417             * @throws SystemException if a system exception occurred
3418             */
3419            public SocialActivity fetchByC_C_First(long classNameId, long classPK,
3420                    OrderByComparator orderByComparator) throws SystemException {
3421                    List<SocialActivity> list = findByC_C(classNameId, classPK, 0, 1,
3422                                    orderByComparator);
3423    
3424                    if (!list.isEmpty()) {
3425                            return list.get(0);
3426                    }
3427    
3428                    return null;
3429            }
3430    
3431            /**
3432             * Returns the last social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
3433             *
3434             * @param classNameId the class name ID
3435             * @param classPK the class p k
3436             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3437             * @return the last matching social activity
3438             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
3439             * @throws SystemException if a system exception occurred
3440             */
3441            public SocialActivity findByC_C_Last(long classNameId, long classPK,
3442                    OrderByComparator orderByComparator)
3443                    throws NoSuchActivityException, SystemException {
3444                    SocialActivity socialActivity = fetchByC_C_Last(classNameId, classPK,
3445                                    orderByComparator);
3446    
3447                    if (socialActivity != null) {
3448                            return socialActivity;
3449                    }
3450    
3451                    StringBundler msg = new StringBundler(6);
3452    
3453                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3454    
3455                    msg.append("classNameId=");
3456                    msg.append(classNameId);
3457    
3458                    msg.append(", classPK=");
3459                    msg.append(classPK);
3460    
3461                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3462    
3463                    throw new NoSuchActivityException(msg.toString());
3464            }
3465    
3466            /**
3467             * Returns the last social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
3468             *
3469             * @param classNameId the class name ID
3470             * @param classPK the class p k
3471             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3472             * @return the last matching social activity, or <code>null</code> if a matching social activity could not be found
3473             * @throws SystemException if a system exception occurred
3474             */
3475            public SocialActivity fetchByC_C_Last(long classNameId, long classPK,
3476                    OrderByComparator orderByComparator) throws SystemException {
3477                    int count = countByC_C(classNameId, classPK);
3478    
3479                    List<SocialActivity> list = findByC_C(classNameId, classPK, count - 1,
3480                                    count, orderByComparator);
3481    
3482                    if (!list.isEmpty()) {
3483                            return list.get(0);
3484                    }
3485    
3486                    return null;
3487            }
3488    
3489            /**
3490             * Returns the social activities before and after the current social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
3491             *
3492             * @param activityId the primary key of the current social activity
3493             * @param classNameId the class name ID
3494             * @param classPK the class p k
3495             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3496             * @return the previous, current, and next social activity
3497             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
3498             * @throws SystemException if a system exception occurred
3499             */
3500            public SocialActivity[] findByC_C_PrevAndNext(long activityId,
3501                    long classNameId, long classPK, OrderByComparator orderByComparator)
3502                    throws NoSuchActivityException, SystemException {
3503                    SocialActivity socialActivity = findByPrimaryKey(activityId);
3504    
3505                    Session session = null;
3506    
3507                    try {
3508                            session = openSession();
3509    
3510                            SocialActivity[] array = new SocialActivityImpl[3];
3511    
3512                            array[0] = getByC_C_PrevAndNext(session, socialActivity,
3513                                            classNameId, classPK, orderByComparator, true);
3514    
3515                            array[1] = socialActivity;
3516    
3517                            array[2] = getByC_C_PrevAndNext(session, socialActivity,
3518                                            classNameId, classPK, orderByComparator, false);
3519    
3520                            return array;
3521                    }
3522                    catch (Exception e) {
3523                            throw processException(e);
3524                    }
3525                    finally {
3526                            closeSession(session);
3527                    }
3528            }
3529    
3530            protected SocialActivity getByC_C_PrevAndNext(Session session,
3531                    SocialActivity socialActivity, long classNameId, long classPK,
3532                    OrderByComparator orderByComparator, boolean previous) {
3533                    StringBundler query = null;
3534    
3535                    if (orderByComparator != null) {
3536                            query = new StringBundler(6 +
3537                                            (orderByComparator.getOrderByFields().length * 6));
3538                    }
3539                    else {
3540                            query = new StringBundler(3);
3541                    }
3542    
3543                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3544    
3545                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3546    
3547                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3548    
3549                    if (orderByComparator != null) {
3550                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3551    
3552                            if (orderByConditionFields.length > 0) {
3553                                    query.append(WHERE_AND);
3554                            }
3555    
3556                            for (int i = 0; i < orderByConditionFields.length; i++) {
3557                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3558                                    query.append(orderByConditionFields[i]);
3559    
3560                                    if ((i + 1) < orderByConditionFields.length) {
3561                                            if (orderByComparator.isAscending() ^ previous) {
3562                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3563                                            }
3564                                            else {
3565                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3566                                            }
3567                                    }
3568                                    else {
3569                                            if (orderByComparator.isAscending() ^ previous) {
3570                                                    query.append(WHERE_GREATER_THAN);
3571                                            }
3572                                            else {
3573                                                    query.append(WHERE_LESSER_THAN);
3574                                            }
3575                                    }
3576                            }
3577    
3578                            query.append(ORDER_BY_CLAUSE);
3579    
3580                            String[] orderByFields = orderByComparator.getOrderByFields();
3581    
3582                            for (int i = 0; i < orderByFields.length; i++) {
3583                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3584                                    query.append(orderByFields[i]);
3585    
3586                                    if ((i + 1) < orderByFields.length) {
3587                                            if (orderByComparator.isAscending() ^ previous) {
3588                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3589                                            }
3590                                            else {
3591                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3592                                            }
3593                                    }
3594                                    else {
3595                                            if (orderByComparator.isAscending() ^ previous) {
3596                                                    query.append(ORDER_BY_ASC);
3597                                            }
3598                                            else {
3599                                                    query.append(ORDER_BY_DESC);
3600                                            }
3601                                    }
3602                            }
3603                    }
3604                    else {
3605                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
3606                    }
3607    
3608                    String sql = query.toString();
3609    
3610                    Query q = session.createQuery(sql);
3611    
3612                    q.setFirstResult(0);
3613                    q.setMaxResults(2);
3614    
3615                    QueryPos qPos = QueryPos.getInstance(q);
3616    
3617                    qPos.add(classNameId);
3618    
3619                    qPos.add(classPK);
3620    
3621                    if (orderByComparator != null) {
3622                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
3623    
3624                            for (Object value : values) {
3625                                    qPos.add(value);
3626                            }
3627                    }
3628    
3629                    List<SocialActivity> list = q.list();
3630    
3631                    if (list.size() == 2) {
3632                            return list.get(1);
3633                    }
3634                    else {
3635                            return null;
3636                    }
3637            }
3638    
3639            /**
3640             * Removes all the social activities where classNameId = &#63; and classPK = &#63; from the database.
3641             *
3642             * @param classNameId the class name ID
3643             * @param classPK the class p k
3644             * @throws SystemException if a system exception occurred
3645             */
3646            public void removeByC_C(long classNameId, long classPK)
3647                    throws SystemException {
3648                    for (SocialActivity socialActivity : findByC_C(classNameId, classPK,
3649                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3650                            remove(socialActivity);
3651                    }
3652            }
3653    
3654            /**
3655             * Returns the number of social activities where classNameId = &#63; and classPK = &#63;.
3656             *
3657             * @param classNameId the class name ID
3658             * @param classPK the class p k
3659             * @return the number of matching social activities
3660             * @throws SystemException if a system exception occurred
3661             */
3662            public int countByC_C(long classNameId, long classPK)
3663                    throws SystemException {
3664                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
3665    
3666                    Object[] finderArgs = new Object[] { classNameId, classPK };
3667    
3668                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3669                                    this);
3670    
3671                    if (count == null) {
3672                            StringBundler query = new StringBundler(3);
3673    
3674                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
3675    
3676                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3677    
3678                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3679    
3680                            String sql = query.toString();
3681    
3682                            Session session = null;
3683    
3684                            try {
3685                                    session = openSession();
3686    
3687                                    Query q = session.createQuery(sql);
3688    
3689                                    QueryPos qPos = QueryPos.getInstance(q);
3690    
3691                                    qPos.add(classNameId);
3692    
3693                                    qPos.add(classPK);
3694    
3695                                    count = (Long)q.uniqueResult();
3696    
3697                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3698                            }
3699                            catch (Exception e) {
3700                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3701    
3702                                    throw processException(e);
3703                            }
3704                            finally {
3705                                    closeSession(session);
3706                            }
3707                    }
3708    
3709                    return count.intValue();
3710            }
3711    
3712            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
3713            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "socialActivity.classPK = ?";
3714            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_M_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
3715                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
3716                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3717                            "findByM_C_C",
3718                            new String[] {
3719                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3720                                    
3721                            Integer.class.getName(), Integer.class.getName(),
3722                                    OrderByComparator.class.getName()
3723                            });
3724            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_M_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
3725                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
3726                            SocialActivityImpl.class,
3727                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByM_C_C",
3728                            new String[] {
3729                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
3730                            },
3731                            SocialActivityModelImpl.MIRRORACTIVITYID_COLUMN_BITMASK |
3732                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3733                            SocialActivityModelImpl.CLASSPK_COLUMN_BITMASK |
3734                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK);
3735            public static final FinderPath FINDER_PATH_COUNT_BY_M_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
3736                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
3737                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByM_C_C",
3738                            new String[] {
3739                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
3740                            });
3741    
3742            /**
3743             * Returns all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3744             *
3745             * @param mirrorActivityId the mirror activity ID
3746             * @param classNameId the class name ID
3747             * @param classPK the class p k
3748             * @return the matching social activities
3749             * @throws SystemException if a system exception occurred
3750             */
3751            public List<SocialActivity> findByM_C_C(long mirrorActivityId,
3752                    long classNameId, long classPK) throws SystemException {
3753                    return findByM_C_C(mirrorActivityId, classNameId, classPK,
3754                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3755            }
3756    
3757            /**
3758             * Returns a range of all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3759             *
3760             * <p>
3761             * 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.SocialActivityModelImpl}. 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.
3762             * </p>
3763             *
3764             * @param mirrorActivityId the mirror activity ID
3765             * @param classNameId the class name ID
3766             * @param classPK the class p k
3767             * @param start the lower bound of the range of social activities
3768             * @param end the upper bound of the range of social activities (not inclusive)
3769             * @return the range of matching social activities
3770             * @throws SystemException if a system exception occurred
3771             */
3772            public List<SocialActivity> findByM_C_C(long mirrorActivityId,
3773                    long classNameId, long classPK, int start, int end)
3774                    throws SystemException {
3775                    return findByM_C_C(mirrorActivityId, classNameId, classPK, start, end,
3776                            null);
3777            }
3778    
3779            /**
3780             * Returns an ordered range of all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3781             *
3782             * <p>
3783             * 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.SocialActivityModelImpl}. 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.
3784             * </p>
3785             *
3786             * @param mirrorActivityId the mirror activity ID
3787             * @param classNameId the class name ID
3788             * @param classPK the class p k
3789             * @param start the lower bound of the range of social activities
3790             * @param end the upper bound of the range of social activities (not inclusive)
3791             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3792             * @return the ordered range of matching social activities
3793             * @throws SystemException if a system exception occurred
3794             */
3795            public List<SocialActivity> findByM_C_C(long mirrorActivityId,
3796                    long classNameId, long classPK, int start, int end,
3797                    OrderByComparator orderByComparator) throws SystemException {
3798                    boolean pagination = true;
3799                    FinderPath finderPath = null;
3800                    Object[] finderArgs = null;
3801    
3802                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3803                                    (orderByComparator == null)) {
3804                            pagination = false;
3805                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_M_C_C;
3806                            finderArgs = new Object[] { mirrorActivityId, classNameId, classPK };
3807                    }
3808                    else {
3809                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_M_C_C;
3810                            finderArgs = new Object[] {
3811                                            mirrorActivityId, classNameId, classPK,
3812                                            
3813                                            start, end, orderByComparator
3814                                    };
3815                    }
3816    
3817                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
3818                                    finderArgs, this);
3819    
3820                    if ((list != null) && !list.isEmpty()) {
3821                            for (SocialActivity socialActivity : list) {
3822                                    if ((mirrorActivityId != socialActivity.getMirrorActivityId()) ||
3823                                                    (classNameId != socialActivity.getClassNameId()) ||
3824                                                    (classPK != socialActivity.getClassPK())) {
3825                                            list = null;
3826    
3827                                            break;
3828                                    }
3829                            }
3830                    }
3831    
3832                    if (list == null) {
3833                            StringBundler query = null;
3834    
3835                            if (orderByComparator != null) {
3836                                    query = new StringBundler(5 +
3837                                                    (orderByComparator.getOrderByFields().length * 3));
3838                            }
3839                            else {
3840                                    query = new StringBundler(5);
3841                            }
3842    
3843                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3844    
3845                            query.append(_FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2);
3846    
3847                            query.append(_FINDER_COLUMN_M_C_C_CLASSNAMEID_2);
3848    
3849                            query.append(_FINDER_COLUMN_M_C_C_CLASSPK_2);
3850    
3851                            if (orderByComparator != null) {
3852                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3853                                            orderByComparator);
3854                            }
3855                            else
3856                             if (pagination) {
3857                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
3858                            }
3859    
3860                            String sql = query.toString();
3861    
3862                            Session session = null;
3863    
3864                            try {
3865                                    session = openSession();
3866    
3867                                    Query q = session.createQuery(sql);
3868    
3869                                    QueryPos qPos = QueryPos.getInstance(q);
3870    
3871                                    qPos.add(mirrorActivityId);
3872    
3873                                    qPos.add(classNameId);
3874    
3875                                    qPos.add(classPK);
3876    
3877                                    if (!pagination) {
3878                                            list = (List<SocialActivity>)QueryUtil.list(q,
3879                                                            getDialect(), start, end, false);
3880    
3881                                            Collections.sort(list);
3882    
3883                                            list = new UnmodifiableList<SocialActivity>(list);
3884                                    }
3885                                    else {
3886                                            list = (List<SocialActivity>)QueryUtil.list(q,
3887                                                            getDialect(), start, end);
3888                                    }
3889    
3890                                    cacheResult(list);
3891    
3892                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3893                            }
3894                            catch (Exception e) {
3895                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3896    
3897                                    throw processException(e);
3898                            }
3899                            finally {
3900                                    closeSession(session);
3901                            }
3902                    }
3903    
3904                    return list;
3905            }
3906    
3907            /**
3908             * Returns the first social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3909             *
3910             * @param mirrorActivityId the mirror activity ID
3911             * @param classNameId the class name ID
3912             * @param classPK the class p k
3913             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3914             * @return the first matching social activity
3915             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
3916             * @throws SystemException if a system exception occurred
3917             */
3918            public SocialActivity findByM_C_C_First(long mirrorActivityId,
3919                    long classNameId, long classPK, OrderByComparator orderByComparator)
3920                    throws NoSuchActivityException, SystemException {
3921                    SocialActivity socialActivity = fetchByM_C_C_First(mirrorActivityId,
3922                                    classNameId, classPK, orderByComparator);
3923    
3924                    if (socialActivity != null) {
3925                            return socialActivity;
3926                    }
3927    
3928                    StringBundler msg = new StringBundler(8);
3929    
3930                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3931    
3932                    msg.append("mirrorActivityId=");
3933                    msg.append(mirrorActivityId);
3934    
3935                    msg.append(", classNameId=");
3936                    msg.append(classNameId);
3937    
3938                    msg.append(", classPK=");
3939                    msg.append(classPK);
3940    
3941                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3942    
3943                    throw new NoSuchActivityException(msg.toString());
3944            }
3945    
3946            /**
3947             * Returns the first social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3948             *
3949             * @param mirrorActivityId the mirror activity ID
3950             * @param classNameId the class name ID
3951             * @param classPK the class p k
3952             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3953             * @return the first matching social activity, or <code>null</code> if a matching social activity could not be found
3954             * @throws SystemException if a system exception occurred
3955             */
3956            public SocialActivity fetchByM_C_C_First(long mirrorActivityId,
3957                    long classNameId, long classPK, OrderByComparator orderByComparator)
3958                    throws SystemException {
3959                    List<SocialActivity> list = findByM_C_C(mirrorActivityId, classNameId,
3960                                    classPK, 0, 1, orderByComparator);
3961    
3962                    if (!list.isEmpty()) {
3963                            return list.get(0);
3964                    }
3965    
3966                    return null;
3967            }
3968    
3969            /**
3970             * Returns the last social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3971             *
3972             * @param mirrorActivityId the mirror activity ID
3973             * @param classNameId the class name ID
3974             * @param classPK the class p k
3975             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3976             * @return the last matching social activity
3977             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
3978             * @throws SystemException if a system exception occurred
3979             */
3980            public SocialActivity findByM_C_C_Last(long mirrorActivityId,
3981                    long classNameId, long classPK, OrderByComparator orderByComparator)
3982                    throws NoSuchActivityException, SystemException {
3983                    SocialActivity socialActivity = fetchByM_C_C_Last(mirrorActivityId,
3984                                    classNameId, classPK, orderByComparator);
3985    
3986                    if (socialActivity != null) {
3987                            return socialActivity;
3988                    }
3989    
3990                    StringBundler msg = new StringBundler(8);
3991    
3992                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3993    
3994                    msg.append("mirrorActivityId=");
3995                    msg.append(mirrorActivityId);
3996    
3997                    msg.append(", classNameId=");
3998                    msg.append(classNameId);
3999    
4000                    msg.append(", classPK=");
4001                    msg.append(classPK);
4002    
4003                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4004    
4005                    throw new NoSuchActivityException(msg.toString());
4006            }
4007    
4008            /**
4009             * Returns the last social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
4010             *
4011             * @param mirrorActivityId the mirror activity ID
4012             * @param classNameId the class name ID
4013             * @param classPK the class p k
4014             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4015             * @return the last matching social activity, or <code>null</code> if a matching social activity could not be found
4016             * @throws SystemException if a system exception occurred
4017             */
4018            public SocialActivity fetchByM_C_C_Last(long mirrorActivityId,
4019                    long classNameId, long classPK, OrderByComparator orderByComparator)
4020                    throws SystemException {
4021                    int count = countByM_C_C(mirrorActivityId, classNameId, classPK);
4022    
4023                    List<SocialActivity> list = findByM_C_C(mirrorActivityId, classNameId,
4024                                    classPK, count - 1, count, orderByComparator);
4025    
4026                    if (!list.isEmpty()) {
4027                            return list.get(0);
4028                    }
4029    
4030                    return null;
4031            }
4032    
4033            /**
4034             * Returns the social activities before and after the current social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
4035             *
4036             * @param activityId the primary key of the current social activity
4037             * @param mirrorActivityId the mirror activity ID
4038             * @param classNameId the class name ID
4039             * @param classPK the class p k
4040             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4041             * @return the previous, current, and next social activity
4042             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
4043             * @throws SystemException if a system exception occurred
4044             */
4045            public SocialActivity[] findByM_C_C_PrevAndNext(long activityId,
4046                    long mirrorActivityId, long classNameId, long classPK,
4047                    OrderByComparator orderByComparator)
4048                    throws NoSuchActivityException, SystemException {
4049                    SocialActivity socialActivity = findByPrimaryKey(activityId);
4050    
4051                    Session session = null;
4052    
4053                    try {
4054                            session = openSession();
4055    
4056                            SocialActivity[] array = new SocialActivityImpl[3];
4057    
4058                            array[0] = getByM_C_C_PrevAndNext(session, socialActivity,
4059                                            mirrorActivityId, classNameId, classPK, orderByComparator,
4060                                            true);
4061    
4062                            array[1] = socialActivity;
4063    
4064                            array[2] = getByM_C_C_PrevAndNext(session, socialActivity,
4065                                            mirrorActivityId, classNameId, classPK, orderByComparator,
4066                                            false);
4067    
4068                            return array;
4069                    }
4070                    catch (Exception e) {
4071                            throw processException(e);
4072                    }
4073                    finally {
4074                            closeSession(session);
4075                    }
4076            }
4077    
4078            protected SocialActivity getByM_C_C_PrevAndNext(Session session,
4079                    SocialActivity socialActivity, long mirrorActivityId, long classNameId,
4080                    long classPK, OrderByComparator orderByComparator, boolean previous) {
4081                    StringBundler query = null;
4082    
4083                    if (orderByComparator != null) {
4084                            query = new StringBundler(6 +
4085                                            (orderByComparator.getOrderByFields().length * 6));
4086                    }
4087                    else {
4088                            query = new StringBundler(3);
4089                    }
4090    
4091                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
4092    
4093                    query.append(_FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2);
4094    
4095                    query.append(_FINDER_COLUMN_M_C_C_CLASSNAMEID_2);
4096    
4097                    query.append(_FINDER_COLUMN_M_C_C_CLASSPK_2);
4098    
4099                    if (orderByComparator != null) {
4100                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4101    
4102                            if (orderByConditionFields.length > 0) {
4103                                    query.append(WHERE_AND);
4104                            }
4105    
4106                            for (int i = 0; i < orderByConditionFields.length; i++) {
4107                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4108                                    query.append(orderByConditionFields[i]);
4109    
4110                                    if ((i + 1) < orderByConditionFields.length) {
4111                                            if (orderByComparator.isAscending() ^ previous) {
4112                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4113                                            }
4114                                            else {
4115                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4116                                            }
4117                                    }
4118                                    else {
4119                                            if (orderByComparator.isAscending() ^ previous) {
4120                                                    query.append(WHERE_GREATER_THAN);
4121                                            }
4122                                            else {
4123                                                    query.append(WHERE_LESSER_THAN);
4124                                            }
4125                                    }
4126                            }
4127    
4128                            query.append(ORDER_BY_CLAUSE);
4129    
4130                            String[] orderByFields = orderByComparator.getOrderByFields();
4131    
4132                            for (int i = 0; i < orderByFields.length; i++) {
4133                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4134                                    query.append(orderByFields[i]);
4135    
4136                                    if ((i + 1) < orderByFields.length) {
4137                                            if (orderByComparator.isAscending() ^ previous) {
4138                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4139                                            }
4140                                            else {
4141                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4142                                            }
4143                                    }
4144                                    else {
4145                                            if (orderByComparator.isAscending() ^ previous) {
4146                                                    query.append(ORDER_BY_ASC);
4147                                            }
4148                                            else {
4149                                                    query.append(ORDER_BY_DESC);
4150                                            }
4151                                    }
4152                            }
4153                    }
4154                    else {
4155                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
4156                    }
4157    
4158                    String sql = query.toString();
4159    
4160                    Query q = session.createQuery(sql);
4161    
4162                    q.setFirstResult(0);
4163                    q.setMaxResults(2);
4164    
4165                    QueryPos qPos = QueryPos.getInstance(q);
4166    
4167                    qPos.add(mirrorActivityId);
4168    
4169                    qPos.add(classNameId);
4170    
4171                    qPos.add(classPK);
4172    
4173                    if (orderByComparator != null) {
4174                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
4175    
4176                            for (Object value : values) {
4177                                    qPos.add(value);
4178                            }
4179                    }
4180    
4181                    List<SocialActivity> list = q.list();
4182    
4183                    if (list.size() == 2) {
4184                            return list.get(1);
4185                    }
4186                    else {
4187                            return null;
4188                    }
4189            }
4190    
4191            /**
4192             * Removes all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
4193             *
4194             * @param mirrorActivityId the mirror activity ID
4195             * @param classNameId the class name ID
4196             * @param classPK the class p k
4197             * @throws SystemException if a system exception occurred
4198             */
4199            public void removeByM_C_C(long mirrorActivityId, long classNameId,
4200                    long classPK) throws SystemException {
4201                    for (SocialActivity socialActivity : findByM_C_C(mirrorActivityId,
4202                                    classNameId, classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4203                            remove(socialActivity);
4204                    }
4205            }
4206    
4207            /**
4208             * Returns the number of social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
4209             *
4210             * @param mirrorActivityId the mirror activity ID
4211             * @param classNameId the class name ID
4212             * @param classPK the class p k
4213             * @return the number of matching social activities
4214             * @throws SystemException if a system exception occurred
4215             */
4216            public int countByM_C_C(long mirrorActivityId, long classNameId,
4217                    long classPK) throws SystemException {
4218                    FinderPath finderPath = FINDER_PATH_COUNT_BY_M_C_C;
4219    
4220                    Object[] finderArgs = new Object[] {
4221                                    mirrorActivityId, classNameId, classPK
4222                            };
4223    
4224                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4225                                    this);
4226    
4227                    if (count == null) {
4228                            StringBundler query = new StringBundler(4);
4229    
4230                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4231    
4232                            query.append(_FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2);
4233    
4234                            query.append(_FINDER_COLUMN_M_C_C_CLASSNAMEID_2);
4235    
4236                            query.append(_FINDER_COLUMN_M_C_C_CLASSPK_2);
4237    
4238                            String sql = query.toString();
4239    
4240                            Session session = null;
4241    
4242                            try {
4243                                    session = openSession();
4244    
4245                                    Query q = session.createQuery(sql);
4246    
4247                                    QueryPos qPos = QueryPos.getInstance(q);
4248    
4249                                    qPos.add(mirrorActivityId);
4250    
4251                                    qPos.add(classNameId);
4252    
4253                                    qPos.add(classPK);
4254    
4255                                    count = (Long)q.uniqueResult();
4256    
4257                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4258                            }
4259                            catch (Exception e) {
4260                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4261    
4262                                    throw processException(e);
4263                            }
4264                            finally {
4265                                    closeSession(session);
4266                            }
4267                    }
4268    
4269                    return count.intValue();
4270            }
4271    
4272            private static final String _FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2 = "socialActivity.mirrorActivityId = ? AND ";
4273            private static final String _FINDER_COLUMN_M_C_C_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
4274            private static final String _FINDER_COLUMN_M_C_C_CLASSPK_2 = "socialActivity.classPK = ?";
4275            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
4276                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
4277                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4278                            "findByC_C_T",
4279                            new String[] {
4280                                    Long.class.getName(), Long.class.getName(),
4281                                    Integer.class.getName(),
4282                                    
4283                            Integer.class.getName(), Integer.class.getName(),
4284                                    OrderByComparator.class.getName()
4285                            });
4286            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
4287                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
4288                            SocialActivityImpl.class,
4289                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_T",
4290                            new String[] {
4291                                    Long.class.getName(), Long.class.getName(),
4292                                    Integer.class.getName()
4293                            },
4294                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK |
4295                            SocialActivityModelImpl.CLASSPK_COLUMN_BITMASK |
4296                            SocialActivityModelImpl.TYPE_COLUMN_BITMASK |
4297                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK);
4298            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
4299                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
4300                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_T",
4301                            new String[] {
4302                                    Long.class.getName(), Long.class.getName(),
4303                                    Integer.class.getName()
4304                            });
4305    
4306            /**
4307             * Returns all the social activities where classNameId = &#63; and classPK = &#63; and type = &#63;.
4308             *
4309             * @param classNameId the class name ID
4310             * @param classPK the class p k
4311             * @param type the type
4312             * @return the matching social activities
4313             * @throws SystemException if a system exception occurred
4314             */
4315            public List<SocialActivity> findByC_C_T(long classNameId, long classPK,
4316                    int type) throws SystemException {
4317                    return findByC_C_T(classNameId, classPK, type, QueryUtil.ALL_POS,
4318                            QueryUtil.ALL_POS, null);
4319            }
4320    
4321            /**
4322             * Returns a range of all the social activities where classNameId = &#63; and classPK = &#63; and type = &#63;.
4323             *
4324             * <p>
4325             * 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.SocialActivityModelImpl}. 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.
4326             * </p>
4327             *
4328             * @param classNameId the class name ID
4329             * @param classPK the class p k
4330             * @param type the type
4331             * @param start the lower bound of the range of social activities
4332             * @param end the upper bound of the range of social activities (not inclusive)
4333             * @return the range of matching social activities
4334             * @throws SystemException if a system exception occurred
4335             */
4336            public List<SocialActivity> findByC_C_T(long classNameId, long classPK,
4337                    int type, int start, int end) throws SystemException {
4338                    return findByC_C_T(classNameId, classPK, type, start, end, null);
4339            }
4340    
4341            /**
4342             * Returns an ordered range of all the social activities where classNameId = &#63; and classPK = &#63; and type = &#63;.
4343             *
4344             * <p>
4345             * 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.SocialActivityModelImpl}. 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.
4346             * </p>
4347             *
4348             * @param classNameId the class name ID
4349             * @param classPK the class p k
4350             * @param type the type
4351             * @param start the lower bound of the range of social activities
4352             * @param end the upper bound of the range of social activities (not inclusive)
4353             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4354             * @return the ordered range of matching social activities
4355             * @throws SystemException if a system exception occurred
4356             */
4357            public List<SocialActivity> findByC_C_T(long classNameId, long classPK,
4358                    int type, int start, int end, OrderByComparator orderByComparator)
4359                    throws SystemException {
4360                    boolean pagination = true;
4361                    FinderPath finderPath = null;
4362                    Object[] finderArgs = null;
4363    
4364                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4365                                    (orderByComparator == null)) {
4366                            pagination = false;
4367                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T;
4368                            finderArgs = new Object[] { classNameId, classPK, type };
4369                    }
4370                    else {
4371                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T;
4372                            finderArgs = new Object[] {
4373                                            classNameId, classPK, type,
4374                                            
4375                                            start, end, orderByComparator
4376                                    };
4377                    }
4378    
4379                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
4380                                    finderArgs, this);
4381    
4382                    if ((list != null) && !list.isEmpty()) {
4383                            for (SocialActivity socialActivity : list) {
4384                                    if ((classNameId != socialActivity.getClassNameId()) ||
4385                                                    (classPK != socialActivity.getClassPK()) ||
4386                                                    (type != socialActivity.getType())) {
4387                                            list = null;
4388    
4389                                            break;
4390                                    }
4391                            }
4392                    }
4393    
4394                    if (list == null) {
4395                            StringBundler query = null;
4396    
4397                            if (orderByComparator != null) {
4398                                    query = new StringBundler(5 +
4399                                                    (orderByComparator.getOrderByFields().length * 3));
4400                            }
4401                            else {
4402                                    query = new StringBundler(5);
4403                            }
4404    
4405                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
4406    
4407                            query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
4408    
4409                            query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
4410    
4411                            query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
4412    
4413                            if (orderByComparator != null) {
4414                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4415                                            orderByComparator);
4416                            }
4417                            else
4418                             if (pagination) {
4419                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
4420                            }
4421    
4422                            String sql = query.toString();
4423    
4424                            Session session = null;
4425    
4426                            try {
4427                                    session = openSession();
4428    
4429                                    Query q = session.createQuery(sql);
4430    
4431                                    QueryPos qPos = QueryPos.getInstance(q);
4432    
4433                                    qPos.add(classNameId);
4434    
4435                                    qPos.add(classPK);
4436    
4437                                    qPos.add(type);
4438    
4439                                    if (!pagination) {
4440                                            list = (List<SocialActivity>)QueryUtil.list(q,
4441                                                            getDialect(), start, end, false);
4442    
4443                                            Collections.sort(list);
4444    
4445                                            list = new UnmodifiableList<SocialActivity>(list);
4446                                    }
4447                                    else {
4448                                            list = (List<SocialActivity>)QueryUtil.list(q,
4449                                                            getDialect(), start, end);
4450                                    }
4451    
4452                                    cacheResult(list);
4453    
4454                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4455                            }
4456                            catch (Exception e) {
4457                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4458    
4459                                    throw processException(e);
4460                            }
4461                            finally {
4462                                    closeSession(session);
4463                            }
4464                    }
4465    
4466                    return list;
4467            }
4468    
4469            /**
4470             * Returns the first social activity in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
4471             *
4472             * @param classNameId the class name ID
4473             * @param classPK the class p k
4474             * @param type the type
4475             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4476             * @return the first matching social activity
4477             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
4478             * @throws SystemException if a system exception occurred
4479             */
4480            public SocialActivity findByC_C_T_First(long classNameId, long classPK,
4481                    int type, OrderByComparator orderByComparator)
4482                    throws NoSuchActivityException, SystemException {
4483                    SocialActivity socialActivity = fetchByC_C_T_First(classNameId,
4484                                    classPK, type, orderByComparator);
4485    
4486                    if (socialActivity != null) {
4487                            return socialActivity;
4488                    }
4489    
4490                    StringBundler msg = new StringBundler(8);
4491    
4492                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4493    
4494                    msg.append("classNameId=");
4495                    msg.append(classNameId);
4496    
4497                    msg.append(", classPK=");
4498                    msg.append(classPK);
4499    
4500                    msg.append(", type=");
4501                    msg.append(type);
4502    
4503                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4504    
4505                    throw new NoSuchActivityException(msg.toString());
4506            }
4507    
4508            /**
4509             * Returns the first social activity in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
4510             *
4511             * @param classNameId the class name ID
4512             * @param classPK the class p k
4513             * @param type the type
4514             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4515             * @return the first matching social activity, or <code>null</code> if a matching social activity could not be found
4516             * @throws SystemException if a system exception occurred
4517             */
4518            public SocialActivity fetchByC_C_T_First(long classNameId, long classPK,
4519                    int type, OrderByComparator orderByComparator)
4520                    throws SystemException {
4521                    List<SocialActivity> list = findByC_C_T(classNameId, classPK, type, 0,
4522                                    1, orderByComparator);
4523    
4524                    if (!list.isEmpty()) {
4525                            return list.get(0);
4526                    }
4527    
4528                    return null;
4529            }
4530    
4531            /**
4532             * Returns the last social activity in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
4533             *
4534             * @param classNameId the class name ID
4535             * @param classPK the class p k
4536             * @param type the type
4537             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4538             * @return the last matching social activity
4539             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
4540             * @throws SystemException if a system exception occurred
4541             */
4542            public SocialActivity findByC_C_T_Last(long classNameId, long classPK,
4543                    int type, OrderByComparator orderByComparator)
4544                    throws NoSuchActivityException, SystemException {
4545                    SocialActivity socialActivity = fetchByC_C_T_Last(classNameId, classPK,
4546                                    type, orderByComparator);
4547    
4548                    if (socialActivity != null) {
4549                            return socialActivity;
4550                    }
4551    
4552                    StringBundler msg = new StringBundler(8);
4553    
4554                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4555    
4556                    msg.append("classNameId=");
4557                    msg.append(classNameId);
4558    
4559                    msg.append(", classPK=");
4560                    msg.append(classPK);
4561    
4562                    msg.append(", type=");
4563                    msg.append(type);
4564    
4565                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4566    
4567                    throw new NoSuchActivityException(msg.toString());
4568            }
4569    
4570            /**
4571             * Returns the last social activity in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
4572             *
4573             * @param classNameId the class name ID
4574             * @param classPK the class p k
4575             * @param type the type
4576             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4577             * @return the last matching social activity, or <code>null</code> if a matching social activity could not be found
4578             * @throws SystemException if a system exception occurred
4579             */
4580            public SocialActivity fetchByC_C_T_Last(long classNameId, long classPK,
4581                    int type, OrderByComparator orderByComparator)
4582                    throws SystemException {
4583                    int count = countByC_C_T(classNameId, classPK, type);
4584    
4585                    List<SocialActivity> list = findByC_C_T(classNameId, classPK, type,
4586                                    count - 1, count, orderByComparator);
4587    
4588                    if (!list.isEmpty()) {
4589                            return list.get(0);
4590                    }
4591    
4592                    return null;
4593            }
4594    
4595            /**
4596             * Returns the social activities before and after the current social activity in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
4597             *
4598             * @param activityId the primary key of the current social activity
4599             * @param classNameId the class name ID
4600             * @param classPK the class p k
4601             * @param type the type
4602             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4603             * @return the previous, current, and next social activity
4604             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
4605             * @throws SystemException if a system exception occurred
4606             */
4607            public SocialActivity[] findByC_C_T_PrevAndNext(long activityId,
4608                    long classNameId, long classPK, int type,
4609                    OrderByComparator orderByComparator)
4610                    throws NoSuchActivityException, SystemException {
4611                    SocialActivity socialActivity = findByPrimaryKey(activityId);
4612    
4613                    Session session = null;
4614    
4615                    try {
4616                            session = openSession();
4617    
4618                            SocialActivity[] array = new SocialActivityImpl[3];
4619    
4620                            array[0] = getByC_C_T_PrevAndNext(session, socialActivity,
4621                                            classNameId, classPK, type, orderByComparator, true);
4622    
4623                            array[1] = socialActivity;
4624    
4625                            array[2] = getByC_C_T_PrevAndNext(session, socialActivity,
4626                                            classNameId, classPK, type, orderByComparator, false);
4627    
4628                            return array;
4629                    }
4630                    catch (Exception e) {
4631                            throw processException(e);
4632                    }
4633                    finally {
4634                            closeSession(session);
4635                    }
4636            }
4637    
4638            protected SocialActivity getByC_C_T_PrevAndNext(Session session,
4639                    SocialActivity socialActivity, long classNameId, long classPK,
4640                    int type, OrderByComparator orderByComparator, boolean previous) {
4641                    StringBundler query = null;
4642    
4643                    if (orderByComparator != null) {
4644                            query = new StringBundler(6 +
4645                                            (orderByComparator.getOrderByFields().length * 6));
4646                    }
4647                    else {
4648                            query = new StringBundler(3);
4649                    }
4650    
4651                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
4652    
4653                    query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
4654    
4655                    query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
4656    
4657                    query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
4658    
4659                    if (orderByComparator != null) {
4660                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4661    
4662                            if (orderByConditionFields.length > 0) {
4663                                    query.append(WHERE_AND);
4664                            }
4665    
4666                            for (int i = 0; i < orderByConditionFields.length; i++) {
4667                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4668                                    query.append(orderByConditionFields[i]);
4669    
4670                                    if ((i + 1) < orderByConditionFields.length) {
4671                                            if (orderByComparator.isAscending() ^ previous) {
4672                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4673                                            }
4674                                            else {
4675                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4676                                            }
4677                                    }
4678                                    else {
4679                                            if (orderByComparator.isAscending() ^ previous) {
4680                                                    query.append(WHERE_GREATER_THAN);
4681                                            }
4682                                            else {
4683                                                    query.append(WHERE_LESSER_THAN);
4684                                            }
4685                                    }
4686                            }
4687    
4688                            query.append(ORDER_BY_CLAUSE);
4689    
4690                            String[] orderByFields = orderByComparator.getOrderByFields();
4691    
4692                            for (int i = 0; i < orderByFields.length; i++) {
4693                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4694                                    query.append(orderByFields[i]);
4695    
4696                                    if ((i + 1) < orderByFields.length) {
4697                                            if (orderByComparator.isAscending() ^ previous) {
4698                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4699                                            }
4700                                            else {
4701                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4702                                            }
4703                                    }
4704                                    else {
4705                                            if (orderByComparator.isAscending() ^ previous) {
4706                                                    query.append(ORDER_BY_ASC);
4707                                            }
4708                                            else {
4709                                                    query.append(ORDER_BY_DESC);
4710                                            }
4711                                    }
4712                            }
4713                    }
4714                    else {
4715                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
4716                    }
4717    
4718                    String sql = query.toString();
4719    
4720                    Query q = session.createQuery(sql);
4721    
4722                    q.setFirstResult(0);
4723                    q.setMaxResults(2);
4724    
4725                    QueryPos qPos = QueryPos.getInstance(q);
4726    
4727                    qPos.add(classNameId);
4728    
4729                    qPos.add(classPK);
4730    
4731                    qPos.add(type);
4732    
4733                    if (orderByComparator != null) {
4734                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
4735    
4736                            for (Object value : values) {
4737                                    qPos.add(value);
4738                            }
4739                    }
4740    
4741                    List<SocialActivity> list = q.list();
4742    
4743                    if (list.size() == 2) {
4744                            return list.get(1);
4745                    }
4746                    else {
4747                            return null;
4748                    }
4749            }
4750    
4751            /**
4752             * Removes all the social activities where classNameId = &#63; and classPK = &#63; and type = &#63; from the database.
4753             *
4754             * @param classNameId the class name ID
4755             * @param classPK the class p k
4756             * @param type the type
4757             * @throws SystemException if a system exception occurred
4758             */
4759            public void removeByC_C_T(long classNameId, long classPK, int type)
4760                    throws SystemException {
4761                    for (SocialActivity socialActivity : findByC_C_T(classNameId, classPK,
4762                                    type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4763                            remove(socialActivity);
4764                    }
4765            }
4766    
4767            /**
4768             * Returns the number of social activities where classNameId = &#63; and classPK = &#63; and type = &#63;.
4769             *
4770             * @param classNameId the class name ID
4771             * @param classPK the class p k
4772             * @param type the type
4773             * @return the number of matching social activities
4774             * @throws SystemException if a system exception occurred
4775             */
4776            public int countByC_C_T(long classNameId, long classPK, int type)
4777                    throws SystemException {
4778                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_T;
4779    
4780                    Object[] finderArgs = new Object[] { classNameId, classPK, type };
4781    
4782                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4783                                    this);
4784    
4785                    if (count == null) {
4786                            StringBundler query = new StringBundler(4);
4787    
4788                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4789    
4790                            query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
4791    
4792                            query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
4793    
4794                            query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
4795    
4796                            String sql = query.toString();
4797    
4798                            Session session = null;
4799    
4800                            try {
4801                                    session = openSession();
4802    
4803                                    Query q = session.createQuery(sql);
4804    
4805                                    QueryPos qPos = QueryPos.getInstance(q);
4806    
4807                                    qPos.add(classNameId);
4808    
4809                                    qPos.add(classPK);
4810    
4811                                    qPos.add(type);
4812    
4813                                    count = (Long)q.uniqueResult();
4814    
4815                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4816                            }
4817                            catch (Exception e) {
4818                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4819    
4820                                    throw processException(e);
4821                            }
4822                            finally {
4823                                    closeSession(session);
4824                            }
4825                    }
4826    
4827                    return count.intValue();
4828            }
4829    
4830            private static final String _FINDER_COLUMN_C_C_T_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
4831            private static final String _FINDER_COLUMN_C_C_T_CLASSPK_2 = "socialActivity.classPK = ? AND ";
4832            private static final String _FINDER_COLUMN_C_C_T_TYPE_2 = "socialActivity.type = ?";
4833            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_C_T_R =
4834                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
4835                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
4836                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4837                            "findByG_U_C_C_T_R",
4838                            new String[] {
4839                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4840                                    Long.class.getName(), Integer.class.getName(),
4841                                    Long.class.getName(),
4842                                    
4843                            Integer.class.getName(), Integer.class.getName(),
4844                                    OrderByComparator.class.getName()
4845                            });
4846            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_C_T_R =
4847                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
4848                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
4849                            SocialActivityImpl.class,
4850                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_C_C_T_R",
4851                            new String[] {
4852                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4853                                    Long.class.getName(), Integer.class.getName(),
4854                                    Long.class.getName()
4855                            },
4856                            SocialActivityModelImpl.GROUPID_COLUMN_BITMASK |
4857                            SocialActivityModelImpl.USERID_COLUMN_BITMASK |
4858                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK |
4859                            SocialActivityModelImpl.CLASSPK_COLUMN_BITMASK |
4860                            SocialActivityModelImpl.TYPE_COLUMN_BITMASK |
4861                            SocialActivityModelImpl.RECEIVERUSERID_COLUMN_BITMASK |
4862                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK);
4863            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_C_C_T_R = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
4864                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
4865                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_C_C_T_R",
4866                            new String[] {
4867                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4868                                    Long.class.getName(), Integer.class.getName(),
4869                                    Long.class.getName()
4870                            });
4871    
4872            /**
4873             * Returns all the social activities where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
4874             *
4875             * @param groupId the group ID
4876             * @param userId the user ID
4877             * @param classNameId the class name ID
4878             * @param classPK the class p k
4879             * @param type the type
4880             * @param receiverUserId the receiver user ID
4881             * @return the matching social activities
4882             * @throws SystemException if a system exception occurred
4883             */
4884            public List<SocialActivity> findByG_U_C_C_T_R(long groupId, long userId,
4885                    long classNameId, long classPK, int type, long receiverUserId)
4886                    throws SystemException {
4887                    return findByG_U_C_C_T_R(groupId, userId, classNameId, classPK, type,
4888                            receiverUserId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4889            }
4890    
4891            /**
4892             * Returns a range of all the social activities where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
4893             *
4894             * <p>
4895             * 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.SocialActivityModelImpl}. 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.
4896             * </p>
4897             *
4898             * @param groupId the group ID
4899             * @param userId the user ID
4900             * @param classNameId the class name ID
4901             * @param classPK the class p k
4902             * @param type the type
4903             * @param receiverUserId the receiver user ID
4904             * @param start the lower bound of the range of social activities
4905             * @param end the upper bound of the range of social activities (not inclusive)
4906             * @return the range of matching social activities
4907             * @throws SystemException if a system exception occurred
4908             */
4909            public List<SocialActivity> findByG_U_C_C_T_R(long groupId, long userId,
4910                    long classNameId, long classPK, int type, long receiverUserId,
4911                    int start, int end) throws SystemException {
4912                    return findByG_U_C_C_T_R(groupId, userId, classNameId, classPK, type,
4913                            receiverUserId, start, end, null);
4914            }
4915    
4916            /**
4917             * Returns an ordered range of all the social activities where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
4918             *
4919             * <p>
4920             * 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.SocialActivityModelImpl}. 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.
4921             * </p>
4922             *
4923             * @param groupId the group ID
4924             * @param userId the user ID
4925             * @param classNameId the class name ID
4926             * @param classPK the class p k
4927             * @param type the type
4928             * @param receiverUserId the receiver user ID
4929             * @param start the lower bound of the range of social activities
4930             * @param end the upper bound of the range of social activities (not inclusive)
4931             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4932             * @return the ordered range of matching social activities
4933             * @throws SystemException if a system exception occurred
4934             */
4935            public List<SocialActivity> findByG_U_C_C_T_R(long groupId, long userId,
4936                    long classNameId, long classPK, int type, long receiverUserId,
4937                    int start, int end, OrderByComparator orderByComparator)
4938                    throws SystemException {
4939                    boolean pagination = true;
4940                    FinderPath finderPath = null;
4941                    Object[] finderArgs = null;
4942    
4943                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4944                                    (orderByComparator == null)) {
4945                            pagination = false;
4946                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_C_T_R;
4947                            finderArgs = new Object[] {
4948                                            groupId, userId, classNameId, classPK, type, receiverUserId
4949                                    };
4950                    }
4951                    else {
4952                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_C_T_R;
4953                            finderArgs = new Object[] {
4954                                            groupId, userId, classNameId, classPK, type, receiverUserId,
4955                                            
4956                                            start, end, orderByComparator
4957                                    };
4958                    }
4959    
4960                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
4961                                    finderArgs, this);
4962    
4963                    if ((list != null) && !list.isEmpty()) {
4964                            for (SocialActivity socialActivity : list) {
4965                                    if ((groupId != socialActivity.getGroupId()) ||
4966                                                    (userId != socialActivity.getUserId()) ||
4967                                                    (classNameId != socialActivity.getClassNameId()) ||
4968                                                    (classPK != socialActivity.getClassPK()) ||
4969                                                    (type != socialActivity.getType()) ||
4970                                                    (receiverUserId != socialActivity.getReceiverUserId())) {
4971                                            list = null;
4972    
4973                                            break;
4974                                    }
4975                            }
4976                    }
4977    
4978                    if (list == null) {
4979                            StringBundler query = null;
4980    
4981                            if (orderByComparator != null) {
4982                                    query = new StringBundler(8 +
4983                                                    (orderByComparator.getOrderByFields().length * 3));
4984                            }
4985                            else {
4986                                    query = new StringBundler(8);
4987                            }
4988    
4989                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
4990    
4991                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_GROUPID_2);
4992    
4993                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_USERID_2);
4994    
4995                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSNAMEID_2);
4996    
4997                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSPK_2);
4998    
4999                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_TYPE_2);
5000    
5001                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_RECEIVERUSERID_2);
5002    
5003                            if (orderByComparator != null) {
5004                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5005                                            orderByComparator);
5006                            }
5007                            else
5008                             if (pagination) {
5009                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
5010                            }
5011    
5012                            String sql = query.toString();
5013    
5014                            Session session = null;
5015    
5016                            try {
5017                                    session = openSession();
5018    
5019                                    Query q = session.createQuery(sql);
5020    
5021                                    QueryPos qPos = QueryPos.getInstance(q);
5022    
5023                                    qPos.add(groupId);
5024    
5025                                    qPos.add(userId);
5026    
5027                                    qPos.add(classNameId);
5028    
5029                                    qPos.add(classPK);
5030    
5031                                    qPos.add(type);
5032    
5033                                    qPos.add(receiverUserId);
5034    
5035                                    if (!pagination) {
5036                                            list = (List<SocialActivity>)QueryUtil.list(q,
5037                                                            getDialect(), start, end, false);
5038    
5039                                            Collections.sort(list);
5040    
5041                                            list = new UnmodifiableList<SocialActivity>(list);
5042                                    }
5043                                    else {
5044                                            list = (List<SocialActivity>)QueryUtil.list(q,
5045                                                            getDialect(), start, end);
5046                                    }
5047    
5048                                    cacheResult(list);
5049    
5050                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5051                            }
5052                            catch (Exception e) {
5053                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5054    
5055                                    throw processException(e);
5056                            }
5057                            finally {
5058                                    closeSession(session);
5059                            }
5060                    }
5061    
5062                    return list;
5063            }
5064    
5065            /**
5066             * Returns the first social activity in the ordered set where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
5067             *
5068             * @param groupId the group ID
5069             * @param userId the user ID
5070             * @param classNameId the class name ID
5071             * @param classPK the class p k
5072             * @param type the type
5073             * @param receiverUserId the receiver user ID
5074             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5075             * @return the first matching social activity
5076             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
5077             * @throws SystemException if a system exception occurred
5078             */
5079            public SocialActivity findByG_U_C_C_T_R_First(long groupId, long userId,
5080                    long classNameId, long classPK, int type, long receiverUserId,
5081                    OrderByComparator orderByComparator)
5082                    throws NoSuchActivityException, SystemException {
5083                    SocialActivity socialActivity = fetchByG_U_C_C_T_R_First(groupId,
5084                                    userId, classNameId, classPK, type, receiverUserId,
5085                                    orderByComparator);
5086    
5087                    if (socialActivity != null) {
5088                            return socialActivity;
5089                    }
5090    
5091                    StringBundler msg = new StringBundler(14);
5092    
5093                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5094    
5095                    msg.append("groupId=");
5096                    msg.append(groupId);
5097    
5098                    msg.append(", userId=");
5099                    msg.append(userId);
5100    
5101                    msg.append(", classNameId=");
5102                    msg.append(classNameId);
5103    
5104                    msg.append(", classPK=");
5105                    msg.append(classPK);
5106    
5107                    msg.append(", type=");
5108                    msg.append(type);
5109    
5110                    msg.append(", receiverUserId=");
5111                    msg.append(receiverUserId);
5112    
5113                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5114    
5115                    throw new NoSuchActivityException(msg.toString());
5116            }
5117    
5118            /**
5119             * Returns the first social activity in the ordered set where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
5120             *
5121             * @param groupId the group ID
5122             * @param userId the user ID
5123             * @param classNameId the class name ID
5124             * @param classPK the class p k
5125             * @param type the type
5126             * @param receiverUserId the receiver user ID
5127             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5128             * @return the first matching social activity, or <code>null</code> if a matching social activity could not be found
5129             * @throws SystemException if a system exception occurred
5130             */
5131            public SocialActivity fetchByG_U_C_C_T_R_First(long groupId, long userId,
5132                    long classNameId, long classPK, int type, long receiverUserId,
5133                    OrderByComparator orderByComparator) throws SystemException {
5134                    List<SocialActivity> list = findByG_U_C_C_T_R(groupId, userId,
5135                                    classNameId, classPK, type, receiverUserId, 0, 1,
5136                                    orderByComparator);
5137    
5138                    if (!list.isEmpty()) {
5139                            return list.get(0);
5140                    }
5141    
5142                    return null;
5143            }
5144    
5145            /**
5146             * Returns the last social activity in the ordered set where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
5147             *
5148             * @param groupId the group ID
5149             * @param userId the user ID
5150             * @param classNameId the class name ID
5151             * @param classPK the class p k
5152             * @param type the type
5153             * @param receiverUserId the receiver user ID
5154             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5155             * @return the last matching social activity
5156             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
5157             * @throws SystemException if a system exception occurred
5158             */
5159            public SocialActivity findByG_U_C_C_T_R_Last(long groupId, long userId,
5160                    long classNameId, long classPK, int type, long receiverUserId,
5161                    OrderByComparator orderByComparator)
5162                    throws NoSuchActivityException, SystemException {
5163                    SocialActivity socialActivity = fetchByG_U_C_C_T_R_Last(groupId,
5164                                    userId, classNameId, classPK, type, receiverUserId,
5165                                    orderByComparator);
5166    
5167                    if (socialActivity != null) {
5168                            return socialActivity;
5169                    }
5170    
5171                    StringBundler msg = new StringBundler(14);
5172    
5173                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5174    
5175                    msg.append("groupId=");
5176                    msg.append(groupId);
5177    
5178                    msg.append(", userId=");
5179                    msg.append(userId);
5180    
5181                    msg.append(", classNameId=");
5182                    msg.append(classNameId);
5183    
5184                    msg.append(", classPK=");
5185                    msg.append(classPK);
5186    
5187                    msg.append(", type=");
5188                    msg.append(type);
5189    
5190                    msg.append(", receiverUserId=");
5191                    msg.append(receiverUserId);
5192    
5193                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5194    
5195                    throw new NoSuchActivityException(msg.toString());
5196            }
5197    
5198            /**
5199             * Returns the last social activity in the ordered set where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
5200             *
5201             * @param groupId the group ID
5202             * @param userId the user ID
5203             * @param classNameId the class name ID
5204             * @param classPK the class p k
5205             * @param type the type
5206             * @param receiverUserId the receiver user ID
5207             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5208             * @return the last matching social activity, or <code>null</code> if a matching social activity could not be found
5209             * @throws SystemException if a system exception occurred
5210             */
5211            public SocialActivity fetchByG_U_C_C_T_R_Last(long groupId, long userId,
5212                    long classNameId, long classPK, int type, long receiverUserId,
5213                    OrderByComparator orderByComparator) throws SystemException {
5214                    int count = countByG_U_C_C_T_R(groupId, userId, classNameId, classPK,
5215                                    type, receiverUserId);
5216    
5217                    List<SocialActivity> list = findByG_U_C_C_T_R(groupId, userId,
5218                                    classNameId, classPK, type, receiverUserId, count - 1, count,
5219                                    orderByComparator);
5220    
5221                    if (!list.isEmpty()) {
5222                            return list.get(0);
5223                    }
5224    
5225                    return null;
5226            }
5227    
5228            /**
5229             * Returns the social activities before and after the current social activity in the ordered set where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
5230             *
5231             * @param activityId the primary key of the current social activity
5232             * @param groupId the group ID
5233             * @param userId the user ID
5234             * @param classNameId the class name ID
5235             * @param classPK the class p k
5236             * @param type the type
5237             * @param receiverUserId the receiver user ID
5238             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5239             * @return the previous, current, and next social activity
5240             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
5241             * @throws SystemException if a system exception occurred
5242             */
5243            public SocialActivity[] findByG_U_C_C_T_R_PrevAndNext(long activityId,
5244                    long groupId, long userId, long classNameId, long classPK, int type,
5245                    long receiverUserId, OrderByComparator orderByComparator)
5246                    throws NoSuchActivityException, SystemException {
5247                    SocialActivity socialActivity = findByPrimaryKey(activityId);
5248    
5249                    Session session = null;
5250    
5251                    try {
5252                            session = openSession();
5253    
5254                            SocialActivity[] array = new SocialActivityImpl[3];
5255    
5256                            array[0] = getByG_U_C_C_T_R_PrevAndNext(session, socialActivity,
5257                                            groupId, userId, classNameId, classPK, type,
5258                                            receiverUserId, orderByComparator, true);
5259    
5260                            array[1] = socialActivity;
5261    
5262                            array[2] = getByG_U_C_C_T_R_PrevAndNext(session, socialActivity,
5263                                            groupId, userId, classNameId, classPK, type,
5264                                            receiverUserId, orderByComparator, false);
5265    
5266                            return array;
5267                    }
5268                    catch (Exception e) {
5269                            throw processException(e);
5270                    }
5271                    finally {
5272                            closeSession(session);
5273                    }
5274            }
5275    
5276            protected SocialActivity getByG_U_C_C_T_R_PrevAndNext(Session session,
5277                    SocialActivity socialActivity, long groupId, long userId,
5278                    long classNameId, long classPK, int type, long receiverUserId,
5279                    OrderByComparator orderByComparator, boolean previous) {
5280                    StringBundler query = null;
5281    
5282                    if (orderByComparator != null) {
5283                            query = new StringBundler(6 +
5284                                            (orderByComparator.getOrderByFields().length * 6));
5285                    }
5286                    else {
5287                            query = new StringBundler(3);
5288                    }
5289    
5290                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
5291    
5292                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_GROUPID_2);
5293    
5294                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_USERID_2);
5295    
5296                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSNAMEID_2);
5297    
5298                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSPK_2);
5299    
5300                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_TYPE_2);
5301    
5302                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_RECEIVERUSERID_2);
5303    
5304                    if (orderByComparator != null) {
5305                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5306    
5307                            if (orderByConditionFields.length > 0) {
5308                                    query.append(WHERE_AND);
5309                            }
5310    
5311                            for (int i = 0; i < orderByConditionFields.length; i++) {
5312                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5313                                    query.append(orderByConditionFields[i]);
5314    
5315                                    if ((i + 1) < orderByConditionFields.length) {
5316                                            if (orderByComparator.isAscending() ^ previous) {
5317                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5318                                            }
5319                                            else {
5320                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5321                                            }
5322                                    }
5323                                    else {
5324                                            if (orderByComparator.isAscending() ^ previous) {
5325                                                    query.append(WHERE_GREATER_THAN);
5326                                            }
5327                                            else {
5328                                                    query.append(WHERE_LESSER_THAN);
5329                                            }
5330                                    }
5331                            }
5332    
5333                            query.append(ORDER_BY_CLAUSE);
5334    
5335                            String[] orderByFields = orderByComparator.getOrderByFields();
5336    
5337                            for (int i = 0; i < orderByFields.length; i++) {
5338                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5339                                    query.append(orderByFields[i]);
5340    
5341                                    if ((i + 1) < orderByFields.length) {
5342                                            if (orderByComparator.isAscending() ^ previous) {
5343                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5344                                            }
5345                                            else {
5346                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5347                                            }
5348                                    }
5349                                    else {
5350                                            if (orderByComparator.isAscending() ^ previous) {
5351                                                    query.append(ORDER_BY_ASC);
5352                                            }
5353                                            else {
5354                                                    query.append(ORDER_BY_DESC);
5355                                            }
5356                                    }
5357                            }
5358                    }
5359                    else {
5360                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
5361                    }
5362    
5363                    String sql = query.toString();
5364    
5365                    Query q = session.createQuery(sql);
5366    
5367                    q.setFirstResult(0);
5368                    q.setMaxResults(2);
5369    
5370                    QueryPos qPos = QueryPos.getInstance(q);
5371    
5372                    qPos.add(groupId);
5373    
5374                    qPos.add(userId);
5375    
5376                    qPos.add(classNameId);
5377    
5378                    qPos.add(classPK);
5379    
5380                    qPos.add(type);
5381    
5382                    qPos.add(receiverUserId);
5383    
5384                    if (orderByComparator != null) {
5385                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
5386    
5387                            for (Object value : values) {
5388                                    qPos.add(value);
5389                            }
5390                    }
5391    
5392                    List<SocialActivity> list = q.list();
5393    
5394                    if (list.size() == 2) {
5395                            return list.get(1);
5396                    }
5397                    else {
5398                            return null;
5399                    }
5400            }
5401    
5402            /**
5403             * Removes all the social activities where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; from the database.
5404             *
5405             * @param groupId the group ID
5406             * @param userId the user ID
5407             * @param classNameId the class name ID
5408             * @param classPK the class p k
5409             * @param type the type
5410             * @param receiverUserId the receiver user ID
5411             * @throws SystemException if a system exception occurred
5412             */
5413            public void removeByG_U_C_C_T_R(long groupId, long userId,
5414                    long classNameId, long classPK, int type, long receiverUserId)
5415                    throws SystemException {
5416                    for (SocialActivity socialActivity : findByG_U_C_C_T_R(groupId, userId,
5417                                    classNameId, classPK, type, receiverUserId, QueryUtil.ALL_POS,
5418                                    QueryUtil.ALL_POS, null)) {
5419                            remove(socialActivity);
5420                    }
5421            }
5422    
5423            /**
5424             * Returns the number of social activities where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
5425             *
5426             * @param groupId the group ID
5427             * @param userId the user ID
5428             * @param classNameId the class name ID
5429             * @param classPK the class p k
5430             * @param type the type
5431             * @param receiverUserId the receiver user ID
5432             * @return the number of matching social activities
5433             * @throws SystemException if a system exception occurred
5434             */
5435            public int countByG_U_C_C_T_R(long groupId, long userId, long classNameId,
5436                    long classPK, int type, long receiverUserId) throws SystemException {
5437                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_C_C_T_R;
5438    
5439                    Object[] finderArgs = new Object[] {
5440                                    groupId, userId, classNameId, classPK, type, receiverUserId
5441                            };
5442    
5443                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5444                                    this);
5445    
5446                    if (count == null) {
5447                            StringBundler query = new StringBundler(7);
5448    
5449                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
5450    
5451                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_GROUPID_2);
5452    
5453                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_USERID_2);
5454    
5455                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSNAMEID_2);
5456    
5457                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSPK_2);
5458    
5459                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_TYPE_2);
5460    
5461                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_RECEIVERUSERID_2);
5462    
5463                            String sql = query.toString();
5464    
5465                            Session session = null;
5466    
5467                            try {
5468                                    session = openSession();
5469    
5470                                    Query q = session.createQuery(sql);
5471    
5472                                    QueryPos qPos = QueryPos.getInstance(q);
5473    
5474                                    qPos.add(groupId);
5475    
5476                                    qPos.add(userId);
5477    
5478                                    qPos.add(classNameId);
5479    
5480                                    qPos.add(classPK);
5481    
5482                                    qPos.add(type);
5483    
5484                                    qPos.add(receiverUserId);
5485    
5486                                    count = (Long)q.uniqueResult();
5487    
5488                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5489                            }
5490                            catch (Exception e) {
5491                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5492    
5493                                    throw processException(e);
5494                            }
5495                            finally {
5496                                    closeSession(session);
5497                            }
5498                    }
5499    
5500                    return count.intValue();
5501            }
5502    
5503            private static final String _FINDER_COLUMN_G_U_C_C_T_R_GROUPID_2 = "socialActivity.groupId = ? AND ";
5504            private static final String _FINDER_COLUMN_G_U_C_C_T_R_USERID_2 = "socialActivity.userId = ? AND ";
5505            private static final String _FINDER_COLUMN_G_U_C_C_T_R_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
5506            private static final String _FINDER_COLUMN_G_U_C_C_T_R_CLASSPK_2 = "socialActivity.classPK = ? AND ";
5507            private static final String _FINDER_COLUMN_G_U_C_C_T_R_TYPE_2 = "socialActivity.type = ? AND ";
5508            private static final String _FINDER_COLUMN_G_U_C_C_T_R_RECEIVERUSERID_2 = "socialActivity.receiverUserId = ?";
5509            public static final FinderPath FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
5510                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
5511                            SocialActivityImpl.class, FINDER_CLASS_NAME_ENTITY,
5512                            "fetchByG_U_CD_C_C_T_R",
5513                            new String[] {
5514                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
5515                                    Long.class.getName(), Long.class.getName(),
5516                                    Integer.class.getName(), Long.class.getName()
5517                            },
5518                            SocialActivityModelImpl.GROUPID_COLUMN_BITMASK |
5519                            SocialActivityModelImpl.USERID_COLUMN_BITMASK |
5520                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK |
5521                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK |
5522                            SocialActivityModelImpl.CLASSPK_COLUMN_BITMASK |
5523                            SocialActivityModelImpl.TYPE_COLUMN_BITMASK |
5524                            SocialActivityModelImpl.RECEIVERUSERID_COLUMN_BITMASK);
5525            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
5526                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
5527                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_CD_C_C_T_R",
5528                            new String[] {
5529                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
5530                                    Long.class.getName(), Long.class.getName(),
5531                                    Integer.class.getName(), Long.class.getName()
5532                            });
5533    
5534            /**
5535             * Returns the social activity where groupId = &#63; and userId = &#63; and createDate = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; or throws a {@link com.liferay.portlet.social.NoSuchActivityException} if it could not be found.
5536             *
5537             * @param groupId the group ID
5538             * @param userId the user ID
5539             * @param createDate the create date
5540             * @param classNameId the class name ID
5541             * @param classPK the class p k
5542             * @param type the type
5543             * @param receiverUserId the receiver user ID
5544             * @return the matching social activity
5545             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
5546             * @throws SystemException if a system exception occurred
5547             */
5548            public SocialActivity findByG_U_CD_C_C_T_R(long groupId, long userId,
5549                    long createDate, long classNameId, long classPK, int type,
5550                    long receiverUserId) throws NoSuchActivityException, SystemException {
5551                    SocialActivity socialActivity = fetchByG_U_CD_C_C_T_R(groupId, userId,
5552                                    createDate, classNameId, classPK, type, receiverUserId);
5553    
5554                    if (socialActivity == null) {
5555                            StringBundler msg = new StringBundler(16);
5556    
5557                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5558    
5559                            msg.append("groupId=");
5560                            msg.append(groupId);
5561    
5562                            msg.append(", userId=");
5563                            msg.append(userId);
5564    
5565                            msg.append(", createDate=");
5566                            msg.append(createDate);
5567    
5568                            msg.append(", classNameId=");
5569                            msg.append(classNameId);
5570    
5571                            msg.append(", classPK=");
5572                            msg.append(classPK);
5573    
5574                            msg.append(", type=");
5575                            msg.append(type);
5576    
5577                            msg.append(", receiverUserId=");
5578                            msg.append(receiverUserId);
5579    
5580                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5581    
5582                            if (_log.isWarnEnabled()) {
5583                                    _log.warn(msg.toString());
5584                            }
5585    
5586                            throw new NoSuchActivityException(msg.toString());
5587                    }
5588    
5589                    return socialActivity;
5590            }
5591    
5592            /**
5593             * Returns the social activity where groupId = &#63; and userId = &#63; and createDate = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
5594             *
5595             * @param groupId the group ID
5596             * @param userId the user ID
5597             * @param createDate the create date
5598             * @param classNameId the class name ID
5599             * @param classPK the class p k
5600             * @param type the type
5601             * @param receiverUserId the receiver user ID
5602             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
5603             * @throws SystemException if a system exception occurred
5604             */
5605            public SocialActivity fetchByG_U_CD_C_C_T_R(long groupId, long userId,
5606                    long createDate, long classNameId, long classPK, int type,
5607                    long receiverUserId) throws SystemException {
5608                    return fetchByG_U_CD_C_C_T_R(groupId, userId, createDate, classNameId,
5609                            classPK, type, receiverUserId, true);
5610            }
5611    
5612            /**
5613             * Returns the social activity where groupId = &#63; and userId = &#63; and createDate = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
5614             *
5615             * @param groupId the group ID
5616             * @param userId the user ID
5617             * @param createDate the create date
5618             * @param classNameId the class name ID
5619             * @param classPK the class p k
5620             * @param type the type
5621             * @param receiverUserId the receiver user ID
5622             * @param retrieveFromCache whether to use the finder cache
5623             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
5624             * @throws SystemException if a system exception occurred
5625             */
5626            public SocialActivity fetchByG_U_CD_C_C_T_R(long groupId, long userId,
5627                    long createDate, long classNameId, long classPK, int type,
5628                    long receiverUserId, boolean retrieveFromCache)
5629                    throws SystemException {
5630                    Object[] finderArgs = new Object[] {
5631                                    groupId, userId, createDate, classNameId, classPK, type,
5632                                    receiverUserId
5633                            };
5634    
5635                    Object result = null;
5636    
5637                    if (retrieveFromCache) {
5638                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
5639                                            finderArgs, this);
5640                    }
5641    
5642                    if (result instanceof SocialActivity) {
5643                            SocialActivity socialActivity = (SocialActivity)result;
5644    
5645                            if ((groupId != socialActivity.getGroupId()) ||
5646                                            (userId != socialActivity.getUserId()) ||
5647                                            (createDate != socialActivity.getCreateDate()) ||
5648                                            (classNameId != socialActivity.getClassNameId()) ||
5649                                            (classPK != socialActivity.getClassPK()) ||
5650                                            (type != socialActivity.getType()) ||
5651                                            (receiverUserId != socialActivity.getReceiverUserId())) {
5652                                    result = null;
5653                            }
5654                    }
5655    
5656                    if (result == null) {
5657                            StringBundler query = new StringBundler(9);
5658    
5659                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
5660    
5661                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_GROUPID_2);
5662    
5663                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_USERID_2);
5664    
5665                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CREATEDATE_2);
5666    
5667                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSNAMEID_2);
5668    
5669                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSPK_2);
5670    
5671                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_TYPE_2);
5672    
5673                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_RECEIVERUSERID_2);
5674    
5675                            String sql = query.toString();
5676    
5677                            Session session = null;
5678    
5679                            try {
5680                                    session = openSession();
5681    
5682                                    Query q = session.createQuery(sql);
5683    
5684                                    QueryPos qPos = QueryPos.getInstance(q);
5685    
5686                                    qPos.add(groupId);
5687    
5688                                    qPos.add(userId);
5689    
5690                                    qPos.add(createDate);
5691    
5692                                    qPos.add(classNameId);
5693    
5694                                    qPos.add(classPK);
5695    
5696                                    qPos.add(type);
5697    
5698                                    qPos.add(receiverUserId);
5699    
5700                                    List<SocialActivity> list = q.list();
5701    
5702                                    if (list.isEmpty()) {
5703                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
5704                                                    finderArgs, list);
5705                                    }
5706                                    else {
5707                                            SocialActivity socialActivity = list.get(0);
5708    
5709                                            result = socialActivity;
5710    
5711                                            cacheResult(socialActivity);
5712    
5713                                            if ((socialActivity.getGroupId() != groupId) ||
5714                                                            (socialActivity.getUserId() != userId) ||
5715                                                            (socialActivity.getCreateDate() != createDate) ||
5716                                                            (socialActivity.getClassNameId() != classNameId) ||
5717                                                            (socialActivity.getClassPK() != classPK) ||
5718                                                            (socialActivity.getType() != type) ||
5719                                                            (socialActivity.getReceiverUserId() != receiverUserId)) {
5720                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
5721                                                            finderArgs, socialActivity);
5722                                            }
5723                                    }
5724                            }
5725                            catch (Exception e) {
5726                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
5727                                            finderArgs);
5728    
5729                                    throw processException(e);
5730                            }
5731                            finally {
5732                                    closeSession(session);
5733                            }
5734                    }
5735    
5736                    if (result instanceof List<?>) {
5737                            return null;
5738                    }
5739                    else {
5740                            return (SocialActivity)result;
5741                    }
5742            }
5743    
5744            /**
5745             * Removes the social activity where groupId = &#63; and userId = &#63; and createDate = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; from the database.
5746             *
5747             * @param groupId the group ID
5748             * @param userId the user ID
5749             * @param createDate the create date
5750             * @param classNameId the class name ID
5751             * @param classPK the class p k
5752             * @param type the type
5753             * @param receiverUserId the receiver user ID
5754             * @return the social activity that was removed
5755             * @throws SystemException if a system exception occurred
5756             */
5757            public SocialActivity removeByG_U_CD_C_C_T_R(long groupId, long userId,
5758                    long createDate, long classNameId, long classPK, int type,
5759                    long receiverUserId) throws NoSuchActivityException, SystemException {
5760                    SocialActivity socialActivity = findByG_U_CD_C_C_T_R(groupId, userId,
5761                                    createDate, classNameId, classPK, type, receiverUserId);
5762    
5763                    return remove(socialActivity);
5764            }
5765    
5766            /**
5767             * Returns the number of social activities where groupId = &#63; and userId = &#63; and createDate = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
5768             *
5769             * @param groupId the group ID
5770             * @param userId the user ID
5771             * @param createDate the create date
5772             * @param classNameId the class name ID
5773             * @param classPK the class p k
5774             * @param type the type
5775             * @param receiverUserId the receiver user ID
5776             * @return the number of matching social activities
5777             * @throws SystemException if a system exception occurred
5778             */
5779            public int countByG_U_CD_C_C_T_R(long groupId, long userId,
5780                    long createDate, long classNameId, long classPK, int type,
5781                    long receiverUserId) throws SystemException {
5782                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R;
5783    
5784                    Object[] finderArgs = new Object[] {
5785                                    groupId, userId, createDate, classNameId, classPK, type,
5786                                    receiverUserId
5787                            };
5788    
5789                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5790                                    this);
5791    
5792                    if (count == null) {
5793                            StringBundler query = new StringBundler(8);
5794    
5795                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
5796    
5797                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_GROUPID_2);
5798    
5799                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_USERID_2);
5800    
5801                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CREATEDATE_2);
5802    
5803                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSNAMEID_2);
5804    
5805                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSPK_2);
5806    
5807                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_TYPE_2);
5808    
5809                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_RECEIVERUSERID_2);
5810    
5811                            String sql = query.toString();
5812    
5813                            Session session = null;
5814    
5815                            try {
5816                                    session = openSession();
5817    
5818                                    Query q = session.createQuery(sql);
5819    
5820                                    QueryPos qPos = QueryPos.getInstance(q);
5821    
5822                                    qPos.add(groupId);
5823    
5824                                    qPos.add(userId);
5825    
5826                                    qPos.add(createDate);
5827    
5828                                    qPos.add(classNameId);
5829    
5830                                    qPos.add(classPK);
5831    
5832                                    qPos.add(type);
5833    
5834                                    qPos.add(receiverUserId);
5835    
5836                                    count = (Long)q.uniqueResult();
5837    
5838                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5839                            }
5840                            catch (Exception e) {
5841                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5842    
5843                                    throw processException(e);
5844                            }
5845                            finally {
5846                                    closeSession(session);
5847                            }
5848                    }
5849    
5850                    return count.intValue();
5851            }
5852    
5853            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_GROUPID_2 = "socialActivity.groupId = ? AND ";
5854            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_USERID_2 = "socialActivity.userId = ? AND ";
5855            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_CREATEDATE_2 = "socialActivity.createDate = ? AND ";
5856            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
5857            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSPK_2 = "socialActivity.classPK = ? AND ";
5858            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_TYPE_2 = "socialActivity.type = ? AND ";
5859            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_RECEIVERUSERID_2 = "socialActivity.receiverUserId = ?";
5860    
5861            /**
5862             * Caches the social activity in the entity cache if it is enabled.
5863             *
5864             * @param socialActivity the social activity
5865             */
5866            public void cacheResult(SocialActivity socialActivity) {
5867                    EntityCacheUtil.putResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
5868                            SocialActivityImpl.class, socialActivity.getPrimaryKey(),
5869                            socialActivity);
5870    
5871                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
5872                            new Object[] { socialActivity.getMirrorActivityId() },
5873                            socialActivity);
5874    
5875                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
5876                            new Object[] {
5877                                    socialActivity.getGroupId(), socialActivity.getUserId(),
5878                                    socialActivity.getCreateDate(), socialActivity.getClassNameId(),
5879                                    socialActivity.getClassPK(), socialActivity.getType(),
5880                                    socialActivity.getReceiverUserId()
5881                            }, socialActivity);
5882    
5883                    socialActivity.resetOriginalValues();
5884            }
5885    
5886            /**
5887             * Caches the social activities in the entity cache if it is enabled.
5888             *
5889             * @param socialActivities the social activities
5890             */
5891            public void cacheResult(List<SocialActivity> socialActivities) {
5892                    for (SocialActivity socialActivity : socialActivities) {
5893                            if (EntityCacheUtil.getResult(
5894                                                    SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
5895                                                    SocialActivityImpl.class, socialActivity.getPrimaryKey()) == null) {
5896                                    cacheResult(socialActivity);
5897                            }
5898                            else {
5899                                    socialActivity.resetOriginalValues();
5900                            }
5901                    }
5902            }
5903    
5904            /**
5905             * Clears the cache for all social activities.
5906             *
5907             * <p>
5908             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
5909             * </p>
5910             */
5911            @Override
5912            public void clearCache() {
5913                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
5914                            CacheRegistryUtil.clear(SocialActivityImpl.class.getName());
5915                    }
5916    
5917                    EntityCacheUtil.clearCache(SocialActivityImpl.class.getName());
5918    
5919                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
5920                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5921                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5922            }
5923    
5924            /**
5925             * Clears the cache for the social activity.
5926             *
5927             * <p>
5928             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
5929             * </p>
5930             */
5931            @Override
5932            public void clearCache(SocialActivity socialActivity) {
5933                    EntityCacheUtil.removeResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
5934                            SocialActivityImpl.class, socialActivity.getPrimaryKey());
5935    
5936                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5937                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5938    
5939                    clearUniqueFindersCache(socialActivity);
5940            }
5941    
5942            @Override
5943            public void clearCache(List<SocialActivity> socialActivities) {
5944                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5945                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5946    
5947                    for (SocialActivity socialActivity : socialActivities) {
5948                            EntityCacheUtil.removeResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
5949                                    SocialActivityImpl.class, socialActivity.getPrimaryKey());
5950    
5951                            clearUniqueFindersCache(socialActivity);
5952                    }
5953            }
5954    
5955            protected void cacheUniqueFindersCache(SocialActivity socialActivity) {
5956                    if (socialActivity.isNew()) {
5957                            Object[] args = new Object[] { socialActivity.getMirrorActivityId() };
5958    
5959                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MIRRORACTIVITYID,
5960                                    args, Long.valueOf(1));
5961                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
5962                                    args, socialActivity);
5963    
5964                            args = new Object[] {
5965                                            socialActivity.getGroupId(), socialActivity.getUserId(),
5966                                            socialActivity.getCreateDate(),
5967                                            socialActivity.getClassNameId(), socialActivity.getClassPK(),
5968                                            socialActivity.getType(), socialActivity.getReceiverUserId()
5969                                    };
5970    
5971                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R,
5972                                    args, Long.valueOf(1));
5973                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
5974                                    args, socialActivity);
5975                    }
5976                    else {
5977                            SocialActivityModelImpl socialActivityModelImpl = (SocialActivityModelImpl)socialActivity;
5978    
5979                            if ((socialActivityModelImpl.getColumnBitmask() &
5980                                            FINDER_PATH_FETCH_BY_MIRRORACTIVITYID.getColumnBitmask()) != 0) {
5981                                    Object[] args = new Object[] {
5982                                                    socialActivity.getMirrorActivityId()
5983                                            };
5984    
5985                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MIRRORACTIVITYID,
5986                                            args, Long.valueOf(1));
5987                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
5988                                            args, socialActivity);
5989                            }
5990    
5991                            if ((socialActivityModelImpl.getColumnBitmask() &
5992                                            FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R.getColumnBitmask()) != 0) {
5993                                    Object[] args = new Object[] {
5994                                                    socialActivity.getGroupId(), socialActivity.getUserId(),
5995                                                    socialActivity.getCreateDate(),
5996                                                    socialActivity.getClassNameId(),
5997                                                    socialActivity.getClassPK(), socialActivity.getType(),
5998                                                    socialActivity.getReceiverUserId()
5999                                            };
6000    
6001                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R,
6002                                            args, Long.valueOf(1));
6003                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
6004                                            args, socialActivity);
6005                            }
6006                    }
6007            }
6008    
6009            protected void clearUniqueFindersCache(SocialActivity socialActivity) {
6010                    SocialActivityModelImpl socialActivityModelImpl = (SocialActivityModelImpl)socialActivity;
6011    
6012                    Object[] args = new Object[] { socialActivity.getMirrorActivityId() };
6013    
6014                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MIRRORACTIVITYID, args);
6015                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID, args);
6016    
6017                    if ((socialActivityModelImpl.getColumnBitmask() &
6018                                    FINDER_PATH_FETCH_BY_MIRRORACTIVITYID.getColumnBitmask()) != 0) {
6019                            args = new Object[] {
6020                                            socialActivityModelImpl.getOriginalMirrorActivityId()
6021                                    };
6022    
6023                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MIRRORACTIVITYID,
6024                                    args);
6025                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
6026                                    args);
6027                    }
6028    
6029                    args = new Object[] {
6030                                    socialActivity.getGroupId(), socialActivity.getUserId(),
6031                                    socialActivity.getCreateDate(), socialActivity.getClassNameId(),
6032                                    socialActivity.getClassPK(), socialActivity.getType(),
6033                                    socialActivity.getReceiverUserId()
6034                            };
6035    
6036                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R, args);
6037                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R, args);
6038    
6039                    if ((socialActivityModelImpl.getColumnBitmask() &
6040                                    FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R.getColumnBitmask()) != 0) {
6041                            args = new Object[] {
6042                                            socialActivityModelImpl.getOriginalGroupId(),
6043                                            socialActivityModelImpl.getOriginalUserId(),
6044                                            socialActivityModelImpl.getOriginalCreateDate(),
6045                                            socialActivityModelImpl.getOriginalClassNameId(),
6046                                            socialActivityModelImpl.getOriginalClassPK(),
6047                                            socialActivityModelImpl.getOriginalType(),
6048                                            socialActivityModelImpl.getOriginalReceiverUserId()
6049                                    };
6050    
6051                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R,
6052                                    args);
6053                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
6054                                    args);
6055                    }
6056            }
6057    
6058            /**
6059             * Creates a new social activity with the primary key. Does not add the social activity to the database.
6060             *
6061             * @param activityId the primary key for the new social activity
6062             * @return the new social activity
6063             */
6064            public SocialActivity create(long activityId) {
6065                    SocialActivity socialActivity = new SocialActivityImpl();
6066    
6067                    socialActivity.setNew(true);
6068                    socialActivity.setPrimaryKey(activityId);
6069    
6070                    return socialActivity;
6071            }
6072    
6073            /**
6074             * Removes the social activity with the primary key from the database. Also notifies the appropriate model listeners.
6075             *
6076             * @param activityId the primary key of the social activity
6077             * @return the social activity that was removed
6078             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
6079             * @throws SystemException if a system exception occurred
6080             */
6081            public SocialActivity remove(long activityId)
6082                    throws NoSuchActivityException, SystemException {
6083                    return remove((Serializable)activityId);
6084            }
6085    
6086            /**
6087             * Removes the social activity with the primary key from the database. Also notifies the appropriate model listeners.
6088             *
6089             * @param primaryKey the primary key of the social activity
6090             * @return the social activity that was removed
6091             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
6092             * @throws SystemException if a system exception occurred
6093             */
6094            @Override
6095            public SocialActivity remove(Serializable primaryKey)
6096                    throws NoSuchActivityException, SystemException {
6097                    Session session = null;
6098    
6099                    try {
6100                            session = openSession();
6101    
6102                            SocialActivity socialActivity = (SocialActivity)session.get(SocialActivityImpl.class,
6103                                            primaryKey);
6104    
6105                            if (socialActivity == null) {
6106                                    if (_log.isWarnEnabled()) {
6107                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6108                                    }
6109    
6110                                    throw new NoSuchActivityException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6111                                            primaryKey);
6112                            }
6113    
6114                            return remove(socialActivity);
6115                    }
6116                    catch (NoSuchActivityException nsee) {
6117                            throw nsee;
6118                    }
6119                    catch (Exception e) {
6120                            throw processException(e);
6121                    }
6122                    finally {
6123                            closeSession(session);
6124                    }
6125            }
6126    
6127            @Override
6128            protected SocialActivity removeImpl(SocialActivity socialActivity)
6129                    throws SystemException {
6130                    socialActivity = toUnwrappedModel(socialActivity);
6131    
6132                    Session session = null;
6133    
6134                    try {
6135                            session = openSession();
6136    
6137                            if (!session.contains(socialActivity)) {
6138                                    socialActivity = (SocialActivity)session.get(SocialActivityImpl.class,
6139                                                    socialActivity.getPrimaryKeyObj());
6140                            }
6141    
6142                            if (socialActivity != null) {
6143                                    session.delete(socialActivity);
6144                            }
6145                    }
6146                    catch (Exception e) {
6147                            throw processException(e);
6148                    }
6149                    finally {
6150                            closeSession(session);
6151                    }
6152    
6153                    if (socialActivity != null) {
6154                            clearCache(socialActivity);
6155                    }
6156    
6157                    return socialActivity;
6158            }
6159    
6160            @Override
6161            public SocialActivity updateImpl(
6162                    com.liferay.portlet.social.model.SocialActivity socialActivity)
6163                    throws SystemException {
6164                    socialActivity = toUnwrappedModel(socialActivity);
6165    
6166                    boolean isNew = socialActivity.isNew();
6167    
6168                    SocialActivityModelImpl socialActivityModelImpl = (SocialActivityModelImpl)socialActivity;
6169    
6170                    Session session = null;
6171    
6172                    try {
6173                            session = openSession();
6174    
6175                            if (socialActivity.isNew()) {
6176                                    session.save(socialActivity);
6177    
6178                                    socialActivity.setNew(false);
6179                            }
6180                            else {
6181                                    session.merge(socialActivity);
6182                            }
6183                    }
6184                    catch (Exception e) {
6185                            throw processException(e);
6186                    }
6187                    finally {
6188                            closeSession(session);
6189                    }
6190    
6191                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6192    
6193                    if (isNew || !SocialActivityModelImpl.COLUMN_BITMASK_ENABLED) {
6194                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6195                    }
6196    
6197                    else {
6198                            if ((socialActivityModelImpl.getColumnBitmask() &
6199                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
6200                                    Object[] args = new Object[] {
6201                                                    socialActivityModelImpl.getOriginalGroupId()
6202                                            };
6203    
6204                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
6205                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
6206                                            args);
6207    
6208                                    args = new Object[] { socialActivityModelImpl.getGroupId() };
6209    
6210                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
6211                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
6212                                            args);
6213                            }
6214    
6215                            if ((socialActivityModelImpl.getColumnBitmask() &
6216                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
6217                                    Object[] args = new Object[] {
6218                                                    socialActivityModelImpl.getOriginalCompanyId()
6219                                            };
6220    
6221                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6222                                            args);
6223                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6224                                            args);
6225    
6226                                    args = new Object[] { socialActivityModelImpl.getCompanyId() };
6227    
6228                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6229                                            args);
6230                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6231                                            args);
6232                            }
6233    
6234                            if ((socialActivityModelImpl.getColumnBitmask() &
6235                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
6236                                    Object[] args = new Object[] {
6237                                                    socialActivityModelImpl.getOriginalUserId()
6238                                            };
6239    
6240                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
6241                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
6242                                            args);
6243    
6244                                    args = new Object[] { socialActivityModelImpl.getUserId() };
6245    
6246                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
6247                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
6248                                            args);
6249                            }
6250    
6251                            if ((socialActivityModelImpl.getColumnBitmask() &
6252                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVITYSETID.getColumnBitmask()) != 0) {
6253                                    Object[] args = new Object[] {
6254                                                    socialActivityModelImpl.getOriginalActivitySetId()
6255                                            };
6256    
6257                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVITYSETID,
6258                                            args);
6259                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVITYSETID,
6260                                            args);
6261    
6262                                    args = new Object[] { socialActivityModelImpl.getActivitySetId() };
6263    
6264                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ACTIVITYSETID,
6265                                            args);
6266                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVITYSETID,
6267                                            args);
6268                            }
6269    
6270                            if ((socialActivityModelImpl.getColumnBitmask() &
6271                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
6272                                    Object[] args = new Object[] {
6273                                                    socialActivityModelImpl.getOriginalClassNameId()
6274                                            };
6275    
6276                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
6277                                            args);
6278                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
6279                                            args);
6280    
6281                                    args = new Object[] { socialActivityModelImpl.getClassNameId() };
6282    
6283                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
6284                                            args);
6285                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
6286                                            args);
6287                            }
6288    
6289                            if ((socialActivityModelImpl.getColumnBitmask() &
6290                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID.getColumnBitmask()) != 0) {
6291                                    Object[] args = new Object[] {
6292                                                    socialActivityModelImpl.getOriginalReceiverUserId()
6293                                            };
6294    
6295                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
6296                                            args);
6297                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID,
6298                                            args);
6299    
6300                                    args = new Object[] { socialActivityModelImpl.getReceiverUserId() };
6301    
6302                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
6303                                            args);
6304                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID,
6305                                            args);
6306                            }
6307    
6308                            if ((socialActivityModelImpl.getColumnBitmask() &
6309                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
6310                                    Object[] args = new Object[] {
6311                                                    socialActivityModelImpl.getOriginalClassNameId(),
6312                                                    socialActivityModelImpl.getOriginalClassPK()
6313                                            };
6314    
6315                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
6316                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
6317                                            args);
6318    
6319                                    args = new Object[] {
6320                                                    socialActivityModelImpl.getClassNameId(),
6321                                                    socialActivityModelImpl.getClassPK()
6322                                            };
6323    
6324                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
6325                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
6326                                            args);
6327                            }
6328    
6329                            if ((socialActivityModelImpl.getColumnBitmask() &
6330                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_M_C_C.getColumnBitmask()) != 0) {
6331                                    Object[] args = new Object[] {
6332                                                    socialActivityModelImpl.getOriginalMirrorActivityId(),
6333                                                    socialActivityModelImpl.getOriginalClassNameId(),
6334                                                    socialActivityModelImpl.getOriginalClassPK()
6335                                            };
6336    
6337                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_M_C_C, args);
6338                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_M_C_C,
6339                                            args);
6340    
6341                                    args = new Object[] {
6342                                                    socialActivityModelImpl.getMirrorActivityId(),
6343                                                    socialActivityModelImpl.getClassNameId(),
6344                                                    socialActivityModelImpl.getClassPK()
6345                                            };
6346    
6347                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_M_C_C, args);
6348                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_M_C_C,
6349                                            args);
6350                            }
6351    
6352                            if ((socialActivityModelImpl.getColumnBitmask() &
6353                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T.getColumnBitmask()) != 0) {
6354                                    Object[] args = new Object[] {
6355                                                    socialActivityModelImpl.getOriginalClassNameId(),
6356                                                    socialActivityModelImpl.getOriginalClassPK(),
6357                                                    socialActivityModelImpl.getOriginalType()
6358                                            };
6359    
6360                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T, args);
6361                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T,
6362                                            args);
6363    
6364                                    args = new Object[] {
6365                                                    socialActivityModelImpl.getClassNameId(),
6366                                                    socialActivityModelImpl.getClassPK(),
6367                                                    socialActivityModelImpl.getType()
6368                                            };
6369    
6370                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T, args);
6371                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T,
6372                                            args);
6373                            }
6374    
6375                            if ((socialActivityModelImpl.getColumnBitmask() &
6376                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_C_T_R.getColumnBitmask()) != 0) {
6377                                    Object[] args = new Object[] {
6378                                                    socialActivityModelImpl.getOriginalGroupId(),
6379                                                    socialActivityModelImpl.getOriginalUserId(),
6380                                                    socialActivityModelImpl.getOriginalClassNameId(),
6381                                                    socialActivityModelImpl.getOriginalClassPK(),
6382                                                    socialActivityModelImpl.getOriginalType(),
6383                                                    socialActivityModelImpl.getOriginalReceiverUserId()
6384                                            };
6385    
6386                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_T_R,
6387                                            args);
6388                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_C_T_R,
6389                                            args);
6390    
6391                                    args = new Object[] {
6392                                                    socialActivityModelImpl.getGroupId(),
6393                                                    socialActivityModelImpl.getUserId(),
6394                                                    socialActivityModelImpl.getClassNameId(),
6395                                                    socialActivityModelImpl.getClassPK(),
6396                                                    socialActivityModelImpl.getType(),
6397                                                    socialActivityModelImpl.getReceiverUserId()
6398                                            };
6399    
6400                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_T_R,
6401                                            args);
6402                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_C_T_R,
6403                                            args);
6404                            }
6405                    }
6406    
6407                    EntityCacheUtil.putResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
6408                            SocialActivityImpl.class, socialActivity.getPrimaryKey(),
6409                            socialActivity);
6410    
6411                    clearUniqueFindersCache(socialActivity);
6412                    cacheUniqueFindersCache(socialActivity);
6413    
6414                    return socialActivity;
6415            }
6416    
6417            protected SocialActivity toUnwrappedModel(SocialActivity socialActivity) {
6418                    if (socialActivity instanceof SocialActivityImpl) {
6419                            return socialActivity;
6420                    }
6421    
6422                    SocialActivityImpl socialActivityImpl = new SocialActivityImpl();
6423    
6424                    socialActivityImpl.setNew(socialActivity.isNew());
6425                    socialActivityImpl.setPrimaryKey(socialActivity.getPrimaryKey());
6426    
6427                    socialActivityImpl.setActivityId(socialActivity.getActivityId());
6428                    socialActivityImpl.setGroupId(socialActivity.getGroupId());
6429                    socialActivityImpl.setCompanyId(socialActivity.getCompanyId());
6430                    socialActivityImpl.setUserId(socialActivity.getUserId());
6431                    socialActivityImpl.setCreateDate(socialActivity.getCreateDate());
6432                    socialActivityImpl.setActivitySetId(socialActivity.getActivitySetId());
6433                    socialActivityImpl.setMirrorActivityId(socialActivity.getMirrorActivityId());
6434                    socialActivityImpl.setClassNameId(socialActivity.getClassNameId());
6435                    socialActivityImpl.setClassPK(socialActivity.getClassPK());
6436                    socialActivityImpl.setType(socialActivity.getType());
6437                    socialActivityImpl.setExtraData(socialActivity.getExtraData());
6438                    socialActivityImpl.setReceiverUserId(socialActivity.getReceiverUserId());
6439    
6440                    return socialActivityImpl;
6441            }
6442    
6443            /**
6444             * Returns the social activity with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
6445             *
6446             * @param primaryKey the primary key of the social activity
6447             * @return the social activity
6448             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
6449             * @throws SystemException if a system exception occurred
6450             */
6451            @Override
6452            public SocialActivity findByPrimaryKey(Serializable primaryKey)
6453                    throws NoSuchActivityException, SystemException {
6454                    SocialActivity socialActivity = fetchByPrimaryKey(primaryKey);
6455    
6456                    if (socialActivity == null) {
6457                            if (_log.isWarnEnabled()) {
6458                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6459                            }
6460    
6461                            throw new NoSuchActivityException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6462                                    primaryKey);
6463                    }
6464    
6465                    return socialActivity;
6466            }
6467    
6468            /**
6469             * Returns the social activity with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivityException} if it could not be found.
6470             *
6471             * @param activityId the primary key of the social activity
6472             * @return the social activity
6473             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
6474             * @throws SystemException if a system exception occurred
6475             */
6476            public SocialActivity findByPrimaryKey(long activityId)
6477                    throws NoSuchActivityException, SystemException {
6478                    return findByPrimaryKey((Serializable)activityId);
6479            }
6480    
6481            /**
6482             * Returns the social activity with the primary key or returns <code>null</code> if it could not be found.
6483             *
6484             * @param primaryKey the primary key of the social activity
6485             * @return the social activity, or <code>null</code> if a social activity with the primary key could not be found
6486             * @throws SystemException if a system exception occurred
6487             */
6488            @Override
6489            public SocialActivity fetchByPrimaryKey(Serializable primaryKey)
6490                    throws SystemException {
6491                    SocialActivity socialActivity = (SocialActivity)EntityCacheUtil.getResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
6492                                    SocialActivityImpl.class, primaryKey);
6493    
6494                    if (socialActivity == _nullSocialActivity) {
6495                            return null;
6496                    }
6497    
6498                    if (socialActivity == null) {
6499                            Session session = null;
6500    
6501                            try {
6502                                    session = openSession();
6503    
6504                                    socialActivity = (SocialActivity)session.get(SocialActivityImpl.class,
6505                                                    primaryKey);
6506    
6507                                    if (socialActivity != null) {
6508                                            cacheResult(socialActivity);
6509                                    }
6510                                    else {
6511                                            EntityCacheUtil.putResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
6512                                                    SocialActivityImpl.class, primaryKey,
6513                                                    _nullSocialActivity);
6514                                    }
6515                            }
6516                            catch (Exception e) {
6517                                    EntityCacheUtil.removeResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
6518                                            SocialActivityImpl.class, primaryKey);
6519    
6520                                    throw processException(e);
6521                            }
6522                            finally {
6523                                    closeSession(session);
6524                            }
6525                    }
6526    
6527                    return socialActivity;
6528            }
6529    
6530            /**
6531             * Returns the social activity with the primary key or returns <code>null</code> if it could not be found.
6532             *
6533             * @param activityId the primary key of the social activity
6534             * @return the social activity, or <code>null</code> if a social activity with the primary key could not be found
6535             * @throws SystemException if a system exception occurred
6536             */
6537            public SocialActivity fetchByPrimaryKey(long activityId)
6538                    throws SystemException {
6539                    return fetchByPrimaryKey((Serializable)activityId);
6540            }
6541    
6542            /**
6543             * Returns all the social activities.
6544             *
6545             * @return the social activities
6546             * @throws SystemException if a system exception occurred
6547             */
6548            public List<SocialActivity> findAll() throws SystemException {
6549                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6550            }
6551    
6552            /**
6553             * Returns a range of all the social activities.
6554             *
6555             * <p>
6556             * 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.SocialActivityModelImpl}. 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.
6557             * </p>
6558             *
6559             * @param start the lower bound of the range of social activities
6560             * @param end the upper bound of the range of social activities (not inclusive)
6561             * @return the range of social activities
6562             * @throws SystemException if a system exception occurred
6563             */
6564            public List<SocialActivity> findAll(int start, int end)
6565                    throws SystemException {
6566                    return findAll(start, end, null);
6567            }
6568    
6569            /**
6570             * Returns an ordered range of all the social activities.
6571             *
6572             * <p>
6573             * 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.SocialActivityModelImpl}. 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.
6574             * </p>
6575             *
6576             * @param start the lower bound of the range of social activities
6577             * @param end the upper bound of the range of social activities (not inclusive)
6578             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6579             * @return the ordered range of social activities
6580             * @throws SystemException if a system exception occurred
6581             */
6582            public List<SocialActivity> findAll(int start, int end,
6583                    OrderByComparator orderByComparator) throws SystemException {
6584                    boolean pagination = true;
6585                    FinderPath finderPath = null;
6586                    Object[] finderArgs = null;
6587    
6588                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6589                                    (orderByComparator == null)) {
6590                            pagination = false;
6591                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
6592                            finderArgs = FINDER_ARGS_EMPTY;
6593                    }
6594                    else {
6595                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
6596                            finderArgs = new Object[] { start, end, orderByComparator };
6597                    }
6598    
6599                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
6600                                    finderArgs, this);
6601    
6602                    if (list == null) {
6603                            StringBundler query = null;
6604                            String sql = null;
6605    
6606                            if (orderByComparator != null) {
6607                                    query = new StringBundler(2 +
6608                                                    (orderByComparator.getOrderByFields().length * 3));
6609    
6610                                    query.append(_SQL_SELECT_SOCIALACTIVITY);
6611    
6612                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6613                                            orderByComparator);
6614    
6615                                    sql = query.toString();
6616                            }
6617                            else {
6618                                    sql = _SQL_SELECT_SOCIALACTIVITY;
6619    
6620                                    if (pagination) {
6621                                            sql = sql.concat(SocialActivityModelImpl.ORDER_BY_JPQL);
6622                                    }
6623                            }
6624    
6625                            Session session = null;
6626    
6627                            try {
6628                                    session = openSession();
6629    
6630                                    Query q = session.createQuery(sql);
6631    
6632                                    if (!pagination) {
6633                                            list = (List<SocialActivity>)QueryUtil.list(q,
6634                                                            getDialect(), start, end, false);
6635    
6636                                            Collections.sort(list);
6637    
6638                                            list = new UnmodifiableList<SocialActivity>(list);
6639                                    }
6640                                    else {
6641                                            list = (List<SocialActivity>)QueryUtil.list(q,
6642                                                            getDialect(), start, end);
6643                                    }
6644    
6645                                    cacheResult(list);
6646    
6647                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6648                            }
6649                            catch (Exception e) {
6650                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6651    
6652                                    throw processException(e);
6653                            }
6654                            finally {
6655                                    closeSession(session);
6656                            }
6657                    }
6658    
6659                    return list;
6660            }
6661    
6662            /**
6663             * Removes all the social activities from the database.
6664             *
6665             * @throws SystemException if a system exception occurred
6666             */
6667            public void removeAll() throws SystemException {
6668                    for (SocialActivity socialActivity : findAll()) {
6669                            remove(socialActivity);
6670                    }
6671            }
6672    
6673            /**
6674             * Returns the number of social activities.
6675             *
6676             * @return the number of social activities
6677             * @throws SystemException if a system exception occurred
6678             */
6679            public int countAll() throws SystemException {
6680                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
6681                                    FINDER_ARGS_EMPTY, this);
6682    
6683                    if (count == null) {
6684                            Session session = null;
6685    
6686                            try {
6687                                    session = openSession();
6688    
6689                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITY);
6690    
6691                                    count = (Long)q.uniqueResult();
6692    
6693                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
6694                                            FINDER_ARGS_EMPTY, count);
6695                            }
6696                            catch (Exception e) {
6697                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
6698                                            FINDER_ARGS_EMPTY);
6699    
6700                                    throw processException(e);
6701                            }
6702                            finally {
6703                                    closeSession(session);
6704                            }
6705                    }
6706    
6707                    return count.intValue();
6708            }
6709    
6710            @Override
6711            protected Set<String> getBadColumnNames() {
6712                    return _badColumnNames;
6713            }
6714    
6715            /**
6716             * Initializes the social activity persistence.
6717             */
6718            public void afterPropertiesSet() {
6719                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
6720                                            com.liferay.portal.util.PropsUtil.get(
6721                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivity")));
6722    
6723                    if (listenerClassNames.length > 0) {
6724                            try {
6725                                    List<ModelListener<SocialActivity>> listenersList = new ArrayList<ModelListener<SocialActivity>>();
6726    
6727                                    for (String listenerClassName : listenerClassNames) {
6728                                            listenersList.add((ModelListener<SocialActivity>)InstanceFactory.newInstance(
6729                                                            getClassLoader(), listenerClassName));
6730                                    }
6731    
6732                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
6733                            }
6734                            catch (Exception e) {
6735                                    _log.error(e);
6736                            }
6737                    }
6738            }
6739    
6740            public void destroy() {
6741                    EntityCacheUtil.removeCache(SocialActivityImpl.class.getName());
6742                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
6743                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6744                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6745            }
6746    
6747            private static final String _SQL_SELECT_SOCIALACTIVITY = "SELECT socialActivity FROM SocialActivity socialActivity";
6748            private static final String _SQL_SELECT_SOCIALACTIVITY_WHERE = "SELECT socialActivity FROM SocialActivity socialActivity WHERE ";
6749            private static final String _SQL_COUNT_SOCIALACTIVITY = "SELECT COUNT(socialActivity) FROM SocialActivity socialActivity";
6750            private static final String _SQL_COUNT_SOCIALACTIVITY_WHERE = "SELECT COUNT(socialActivity) FROM SocialActivity socialActivity WHERE ";
6751            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivity.";
6752            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivity exists with the primary key ";
6753            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivity exists with the key {";
6754            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
6755            private static Log _log = LogFactoryUtil.getLog(SocialActivityPersistenceImpl.class);
6756            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
6757                                    "type"
6758                            });
6759            private static SocialActivity _nullSocialActivity = new SocialActivityImpl() {
6760                            @Override
6761                            public Object clone() {
6762                                    return this;
6763                            }
6764    
6765                            @Override
6766                            public CacheModel<SocialActivity> toCacheModel() {
6767                                    return _nullSocialActivityCacheModel;
6768                            }
6769                    };
6770    
6771            private static CacheModel<SocialActivity> _nullSocialActivityCacheModel = new CacheModel<SocialActivity>() {
6772                            public SocialActivity toEntityModel() {
6773                                    return _nullSocialActivity;
6774                            }
6775                    };
6776    }