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