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