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