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