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