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