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