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