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