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