001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.social.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
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.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.BatchSessionUtil;
039    import com.liferay.portal.service.persistence.GroupPersistence;
040    import com.liferay.portal.service.persistence.LayoutPersistence;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
046    import com.liferay.portlet.social.NoSuchActivityException;
047    import com.liferay.portlet.social.model.SocialActivity;
048    import com.liferay.portlet.social.model.impl.SocialActivityImpl;
049    import com.liferay.portlet.social.model.impl.SocialActivityModelImpl;
050    
051    import java.io.Serializable;
052    
053    import java.util.ArrayList;
054    import java.util.Collections;
055    import java.util.List;
056    
057    /**
058     * The persistence implementation for the social activity service.
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see SocialActivityPersistence
066     * @see SocialActivityUtil
067     * @generated
068     */
069    public class SocialActivityPersistenceImpl extends BasePersistenceImpl<SocialActivity>
070            implements SocialActivityPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * Never modify or reference this class directly. Always use {@link SocialActivityUtil} to access the social activity persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivityImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
082                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
083                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
084                            "findByGroupId",
085                            new String[] {
086                                    Long.class.getName(),
087                                    
088                            "java.lang.Integer", "java.lang.Integer",
089                                    "com.liferay.portal.kernel.util.OrderByComparator"
090                            });
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
092                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
093                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
094                            SocialActivityImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
096                            new String[] { Long.class.getName() },
097                            SocialActivityModelImpl.GROUPID_COLUMN_BITMASK);
098            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
099                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
101                            new String[] { Long.class.getName() });
102            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
103                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
104                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
105                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
106                            "findByCompanyId",
107                            new String[] {
108                                    Long.class.getName(),
109                                    
110                            "java.lang.Integer", "java.lang.Integer",
111                                    "com.liferay.portal.kernel.util.OrderByComparator"
112                            });
113            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
114                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
115                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
116                            SocialActivityImpl.class,
117                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
118                            new String[] { Long.class.getName() },
119                            SocialActivityModelImpl.COMPANYID_COLUMN_BITMASK);
120            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
121                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
122                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
123                            new String[] { Long.class.getName() });
124            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
125                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
126                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
127                            "findByUserId",
128                            new String[] {
129                                    Long.class.getName(),
130                                    
131                            "java.lang.Integer", "java.lang.Integer",
132                                    "com.liferay.portal.kernel.util.OrderByComparator"
133                            });
134            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
135                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
136                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
137                            SocialActivityImpl.class,
138                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
139                            new String[] { Long.class.getName() },
140                            SocialActivityModelImpl.USERID_COLUMN_BITMASK);
141            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
142                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
143                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
144                            new String[] { Long.class.getName() });
145            public static final FinderPath FINDER_PATH_FETCH_BY_MIRRORACTIVITYID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
146                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
147                            SocialActivityImpl.class, FINDER_CLASS_NAME_ENTITY,
148                            "fetchByMirrorActivityId", new String[] { Long.class.getName() },
149                            SocialActivityModelImpl.MIRRORACTIVITYID_COLUMN_BITMASK);
150            public static final FinderPath FINDER_PATH_COUNT_BY_MIRRORACTIVITYID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
151                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
152                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
153                            "countByMirrorActivityId", new String[] { Long.class.getName() });
154            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
155                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
156                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
157                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
158                            "findByClassNameId",
159                            new String[] {
160                                    Long.class.getName(),
161                                    
162                            "java.lang.Integer", "java.lang.Integer",
163                                    "com.liferay.portal.kernel.util.OrderByComparator"
164                            });
165            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
166                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
167                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
168                            SocialActivityImpl.class,
169                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassNameId",
170                            new String[] { Long.class.getName() },
171                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK);
172            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
173                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
174                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
175                            new String[] { Long.class.getName() });
176            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RECEIVERUSERID =
177                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
178                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
179                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
180                            "findByReceiverUserId",
181                            new String[] {
182                                    Long.class.getName(),
183                                    
184                            "java.lang.Integer", "java.lang.Integer",
185                                    "com.liferay.portal.kernel.util.OrderByComparator"
186                            });
187            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID =
188                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
189                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
190                            SocialActivityImpl.class,
191                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByReceiverUserId",
192                            new String[] { Long.class.getName() },
193                            SocialActivityModelImpl.RECEIVERUSERID_COLUMN_BITMASK);
194            public static final FinderPath FINDER_PATH_COUNT_BY_RECEIVERUSERID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
195                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
196                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByReceiverUserId",
197                            new String[] { Long.class.getName() });
198            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
199                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
200                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
201                            "findByC_C",
202                            new String[] {
203                                    Long.class.getName(), Long.class.getName(),
204                                    
205                            "java.lang.Integer", "java.lang.Integer",
206                                    "com.liferay.portal.kernel.util.OrderByComparator"
207                            });
208            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
209                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
210                            SocialActivityImpl.class,
211                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
212                            new String[] { Long.class.getName(), Long.class.getName() },
213                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK |
214                            SocialActivityModelImpl.CLASSPK_COLUMN_BITMASK);
215            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
216                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
217                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
218                            new String[] { Long.class.getName(), Long.class.getName() });
219            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_M_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
220                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
221                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
222                            "findByM_C_C",
223                            new String[] {
224                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
225                                    
226                            "java.lang.Integer", "java.lang.Integer",
227                                    "com.liferay.portal.kernel.util.OrderByComparator"
228                            });
229            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_M_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
230                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
231                            SocialActivityImpl.class,
232                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByM_C_C",
233                            new String[] {
234                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
235                            },
236                            SocialActivityModelImpl.MIRRORACTIVITYID_COLUMN_BITMASK |
237                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK |
238                            SocialActivityModelImpl.CLASSPK_COLUMN_BITMASK);
239            public static final FinderPath FINDER_PATH_COUNT_BY_M_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
240                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
241                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByM_C_C",
242                            new String[] {
243                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
244                            });
245            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_C_T_R =
246                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
247                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
248                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
249                            "findByG_U_C_C_T_R",
250                            new String[] {
251                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
252                                    Long.class.getName(), Integer.class.getName(),
253                                    Long.class.getName(),
254                                    
255                            "java.lang.Integer", "java.lang.Integer",
256                                    "com.liferay.portal.kernel.util.OrderByComparator"
257                            });
258            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_C_T_R =
259                    new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
260                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
261                            SocialActivityImpl.class,
262                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_C_C_T_R",
263                            new String[] {
264                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
265                                    Long.class.getName(), Integer.class.getName(),
266                                    Long.class.getName()
267                            },
268                            SocialActivityModelImpl.GROUPID_COLUMN_BITMASK |
269                            SocialActivityModelImpl.USERID_COLUMN_BITMASK |
270                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK |
271                            SocialActivityModelImpl.CLASSPK_COLUMN_BITMASK |
272                            SocialActivityModelImpl.TYPE_COLUMN_BITMASK |
273                            SocialActivityModelImpl.RECEIVERUSERID_COLUMN_BITMASK);
274            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_C_C_T_R = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
275                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
276                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_C_C_T_R",
277                            new String[] {
278                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
279                                    Long.class.getName(), Integer.class.getName(),
280                                    Long.class.getName()
281                            });
282            public static final FinderPath FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
283                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
284                            SocialActivityImpl.class, FINDER_CLASS_NAME_ENTITY,
285                            "fetchByG_U_CD_C_C_T_R",
286                            new String[] {
287                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
288                                    Long.class.getName(), Long.class.getName(),
289                                    Integer.class.getName(), Long.class.getName()
290                            },
291                            SocialActivityModelImpl.GROUPID_COLUMN_BITMASK |
292                            SocialActivityModelImpl.USERID_COLUMN_BITMASK |
293                            SocialActivityModelImpl.CREATEDATE_COLUMN_BITMASK |
294                            SocialActivityModelImpl.CLASSNAMEID_COLUMN_BITMASK |
295                            SocialActivityModelImpl.CLASSPK_COLUMN_BITMASK |
296                            SocialActivityModelImpl.TYPE_COLUMN_BITMASK |
297                            SocialActivityModelImpl.RECEIVERUSERID_COLUMN_BITMASK);
298            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
299                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
300                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_CD_C_C_T_R",
301                            new String[] {
302                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
303                                    Long.class.getName(), Long.class.getName(),
304                                    Integer.class.getName(), Long.class.getName()
305                            });
306            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
307                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
308                            SocialActivityImpl.class,
309                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
310            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
311                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
312                            SocialActivityImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
313                            "findAll", new String[0]);
314            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
315                            SocialActivityModelImpl.FINDER_CACHE_ENABLED, Long.class,
316                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
317    
318            /**
319             * Caches the social activity in the entity cache if it is enabled.
320             *
321             * @param socialActivity the social activity
322             */
323            public void cacheResult(SocialActivity socialActivity) {
324                    EntityCacheUtil.putResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
325                            SocialActivityImpl.class, socialActivity.getPrimaryKey(),
326                            socialActivity);
327    
328                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
329                            new Object[] { Long.valueOf(socialActivity.getMirrorActivityId()) },
330                            socialActivity);
331    
332                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
333                            new Object[] {
334                                    Long.valueOf(socialActivity.getGroupId()),
335                                    Long.valueOf(socialActivity.getUserId()),
336                                    Long.valueOf(socialActivity.getCreateDate()),
337                                    Long.valueOf(socialActivity.getClassNameId()),
338                                    Long.valueOf(socialActivity.getClassPK()),
339                                    Integer.valueOf(socialActivity.getType()),
340                                    Long.valueOf(socialActivity.getReceiverUserId())
341                            }, socialActivity);
342    
343                    socialActivity.resetOriginalValues();
344            }
345    
346            /**
347             * Caches the social activities in the entity cache if it is enabled.
348             *
349             * @param socialActivities the social activities
350             */
351            public void cacheResult(List<SocialActivity> socialActivities) {
352                    for (SocialActivity socialActivity : socialActivities) {
353                            if (EntityCacheUtil.getResult(
354                                                    SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
355                                                    SocialActivityImpl.class, socialActivity.getPrimaryKey()) == null) {
356                                    cacheResult(socialActivity);
357                            }
358                            else {
359                                    socialActivity.resetOriginalValues();
360                            }
361                    }
362            }
363    
364            /**
365             * Clears the cache for all social activities.
366             *
367             * <p>
368             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
369             * </p>
370             */
371            @Override
372            public void clearCache() {
373                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
374                            CacheRegistryUtil.clear(SocialActivityImpl.class.getName());
375                    }
376    
377                    EntityCacheUtil.clearCache(SocialActivityImpl.class.getName());
378    
379                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
380                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
381                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
382            }
383    
384            /**
385             * Clears the cache for the social activity.
386             *
387             * <p>
388             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
389             * </p>
390             */
391            @Override
392            public void clearCache(SocialActivity socialActivity) {
393                    EntityCacheUtil.removeResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
394                            SocialActivityImpl.class, socialActivity.getPrimaryKey());
395    
396                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
397                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
398    
399                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
400                            new Object[] { Long.valueOf(socialActivity.getMirrorActivityId()) });
401    
402                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
403                            new Object[] {
404                                    Long.valueOf(socialActivity.getGroupId()),
405                                    Long.valueOf(socialActivity.getUserId()),
406                                    Long.valueOf(socialActivity.getCreateDate()),
407                                    Long.valueOf(socialActivity.getClassNameId()),
408                                    Long.valueOf(socialActivity.getClassPK()),
409                                    Integer.valueOf(socialActivity.getType()),
410                                    Long.valueOf(socialActivity.getReceiverUserId())
411                            });
412            }
413    
414            /**
415             * Creates a new social activity with the primary key. Does not add the social activity to the database.
416             *
417             * @param activityId the primary key for the new social activity
418             * @return the new social activity
419             */
420            public SocialActivity create(long activityId) {
421                    SocialActivity socialActivity = new SocialActivityImpl();
422    
423                    socialActivity.setNew(true);
424                    socialActivity.setPrimaryKey(activityId);
425    
426                    return socialActivity;
427            }
428    
429            /**
430             * Removes the social activity with the primary key from the database. Also notifies the appropriate model listeners.
431             *
432             * @param primaryKey the primary key of the social activity
433             * @return the social activity that was removed
434             * @throws com.liferay.portal.NoSuchModelException if a social activity with the primary key could not be found
435             * @throws SystemException if a system exception occurred
436             */
437            @Override
438            public SocialActivity remove(Serializable primaryKey)
439                    throws NoSuchModelException, SystemException {
440                    return remove(((Long)primaryKey).longValue());
441            }
442    
443            /**
444             * Removes the social activity with the primary key from the database. Also notifies the appropriate model listeners.
445             *
446             * @param activityId the primary key of the social activity
447             * @return the social activity that was removed
448             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
449             * @throws SystemException if a system exception occurred
450             */
451            public SocialActivity remove(long activityId)
452                    throws NoSuchActivityException, SystemException {
453                    Session session = null;
454    
455                    try {
456                            session = openSession();
457    
458                            SocialActivity socialActivity = (SocialActivity)session.get(SocialActivityImpl.class,
459                                            Long.valueOf(activityId));
460    
461                            if (socialActivity == null) {
462                                    if (_log.isWarnEnabled()) {
463                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + activityId);
464                                    }
465    
466                                    throw new NoSuchActivityException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
467                                            activityId);
468                            }
469    
470                            return socialActivityPersistence.remove(socialActivity);
471                    }
472                    catch (NoSuchActivityException nsee) {
473                            throw nsee;
474                    }
475                    catch (Exception e) {
476                            throw processException(e);
477                    }
478                    finally {
479                            closeSession(session);
480                    }
481            }
482    
483            /**
484             * Removes the social activity from the database. Also notifies the appropriate model listeners.
485             *
486             * @param socialActivity the social activity
487             * @return the social activity that was removed
488             * @throws SystemException if a system exception occurred
489             */
490            @Override
491            public SocialActivity remove(SocialActivity socialActivity)
492                    throws SystemException {
493                    return super.remove(socialActivity);
494            }
495    
496            @Override
497            protected SocialActivity removeImpl(SocialActivity socialActivity)
498                    throws SystemException {
499                    socialActivity = toUnwrappedModel(socialActivity);
500    
501                    Session session = null;
502    
503                    try {
504                            session = openSession();
505    
506                            BatchSessionUtil.delete(session, socialActivity);
507                    }
508                    catch (Exception e) {
509                            throw processException(e);
510                    }
511                    finally {
512                            closeSession(session);
513                    }
514    
515                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
516                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
517    
518                    SocialActivityModelImpl socialActivityModelImpl = (SocialActivityModelImpl)socialActivity;
519    
520                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
521                            new Object[] {
522                                    Long.valueOf(socialActivityModelImpl.getMirrorActivityId())
523                            });
524    
525                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
526                            new Object[] {
527                                    Long.valueOf(socialActivityModelImpl.getGroupId()),
528                                    Long.valueOf(socialActivityModelImpl.getUserId()),
529                                    Long.valueOf(socialActivityModelImpl.getCreateDate()),
530                                    Long.valueOf(socialActivityModelImpl.getClassNameId()),
531                                    Long.valueOf(socialActivityModelImpl.getClassPK()),
532                                    Integer.valueOf(socialActivityModelImpl.getType()),
533                                    Long.valueOf(socialActivityModelImpl.getReceiverUserId())
534                            });
535    
536                    EntityCacheUtil.removeResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
537                            SocialActivityImpl.class, socialActivity.getPrimaryKey());
538    
539                    return socialActivity;
540            }
541    
542            @Override
543            public SocialActivity updateImpl(
544                    com.liferay.portlet.social.model.SocialActivity socialActivity,
545                    boolean merge) throws SystemException {
546                    socialActivity = toUnwrappedModel(socialActivity);
547    
548                    boolean isNew = socialActivity.isNew();
549    
550                    SocialActivityModelImpl socialActivityModelImpl = (SocialActivityModelImpl)socialActivity;
551    
552                    Session session = null;
553    
554                    try {
555                            session = openSession();
556    
557                            BatchSessionUtil.update(session, socialActivity, merge);
558    
559                            socialActivity.setNew(false);
560                    }
561                    catch (Exception e) {
562                            throw processException(e);
563                    }
564                    finally {
565                            closeSession(session);
566                    }
567    
568                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
569    
570                    if (isNew || !SocialActivityModelImpl.COLUMN_BITMASK_ENABLED) {
571                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
572                    }
573    
574                    else {
575                            if ((socialActivityModelImpl.getColumnBitmask() &
576                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
577                                    Object[] args = new Object[] {
578                                                    Long.valueOf(socialActivityModelImpl.getOriginalGroupId())
579                                            };
580    
581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
582                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
583                                            args);
584    
585                                    args = new Object[] {
586                                                    Long.valueOf(socialActivityModelImpl.getGroupId())
587                                            };
588    
589                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
590                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
591                                            args);
592                            }
593    
594                            if ((socialActivityModelImpl.getColumnBitmask() &
595                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
596                                    Object[] args = new Object[] {
597                                                    Long.valueOf(socialActivityModelImpl.getOriginalCompanyId())
598                                            };
599    
600                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
601                                            args);
602                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
603                                            args);
604    
605                                    args = new Object[] {
606                                                    Long.valueOf(socialActivityModelImpl.getCompanyId())
607                                            };
608    
609                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
610                                            args);
611                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
612                                            args);
613                            }
614    
615                            if ((socialActivityModelImpl.getColumnBitmask() &
616                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
617                                    Object[] args = new Object[] {
618                                                    Long.valueOf(socialActivityModelImpl.getOriginalUserId())
619                                            };
620    
621                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
622                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
623                                            args);
624    
625                                    args = new Object[] {
626                                                    Long.valueOf(socialActivityModelImpl.getUserId())
627                                            };
628    
629                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
630                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
631                                            args);
632                            }
633    
634                            if ((socialActivityModelImpl.getColumnBitmask() &
635                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
636                                    Object[] args = new Object[] {
637                                                    Long.valueOf(socialActivityModelImpl.getOriginalClassNameId())
638                                            };
639    
640                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
641                                            args);
642                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
643                                            args);
644    
645                                    args = new Object[] {
646                                                    Long.valueOf(socialActivityModelImpl.getClassNameId())
647                                            };
648    
649                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
650                                            args);
651                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
652                                            args);
653                            }
654    
655                            if ((socialActivityModelImpl.getColumnBitmask() &
656                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID.getColumnBitmask()) != 0) {
657                                    Object[] args = new Object[] {
658                                                    Long.valueOf(socialActivityModelImpl.getOriginalReceiverUserId())
659                                            };
660    
661                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
662                                            args);
663                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID,
664                                            args);
665    
666                                    args = new Object[] {
667                                                    Long.valueOf(socialActivityModelImpl.getReceiverUserId())
668                                            };
669    
670                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
671                                            args);
672                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID,
673                                            args);
674                            }
675    
676                            if ((socialActivityModelImpl.getColumnBitmask() &
677                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
678                                    Object[] args = new Object[] {
679                                                    Long.valueOf(socialActivityModelImpl.getOriginalClassNameId()),
680                                                    Long.valueOf(socialActivityModelImpl.getOriginalClassPK())
681                                            };
682    
683                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
684                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
685                                            args);
686    
687                                    args = new Object[] {
688                                                    Long.valueOf(socialActivityModelImpl.getClassNameId()),
689                                                    Long.valueOf(socialActivityModelImpl.getClassPK())
690                                            };
691    
692                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
693                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
694                                            args);
695                            }
696    
697                            if ((socialActivityModelImpl.getColumnBitmask() &
698                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_M_C_C.getColumnBitmask()) != 0) {
699                                    Object[] args = new Object[] {
700                                                    Long.valueOf(socialActivityModelImpl.getOriginalMirrorActivityId()),
701                                                    Long.valueOf(socialActivityModelImpl.getOriginalClassNameId()),
702                                                    Long.valueOf(socialActivityModelImpl.getOriginalClassPK())
703                                            };
704    
705                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_M_C_C, args);
706                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_M_C_C,
707                                            args);
708    
709                                    args = new Object[] {
710                                                    Long.valueOf(socialActivityModelImpl.getMirrorActivityId()),
711                                                    Long.valueOf(socialActivityModelImpl.getClassNameId()),
712                                                    Long.valueOf(socialActivityModelImpl.getClassPK())
713                                            };
714    
715                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_M_C_C, args);
716                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_M_C_C,
717                                            args);
718                            }
719    
720                            if ((socialActivityModelImpl.getColumnBitmask() &
721                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_C_T_R.getColumnBitmask()) != 0) {
722                                    Object[] args = new Object[] {
723                                                    Long.valueOf(socialActivityModelImpl.getOriginalGroupId()),
724                                                    Long.valueOf(socialActivityModelImpl.getOriginalUserId()),
725                                                    Long.valueOf(socialActivityModelImpl.getOriginalClassNameId()),
726                                                    Long.valueOf(socialActivityModelImpl.getOriginalClassPK()),
727                                                    Integer.valueOf(socialActivityModelImpl.getOriginalType()),
728                                                    Long.valueOf(socialActivityModelImpl.getOriginalReceiverUserId())
729                                            };
730    
731                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_T_R,
732                                            args);
733                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_C_T_R,
734                                            args);
735    
736                                    args = new Object[] {
737                                                    Long.valueOf(socialActivityModelImpl.getGroupId()),
738                                                    Long.valueOf(socialActivityModelImpl.getUserId()),
739                                                    Long.valueOf(socialActivityModelImpl.getClassNameId()),
740                                                    Long.valueOf(socialActivityModelImpl.getClassPK()),
741                                                    Integer.valueOf(socialActivityModelImpl.getType()),
742                                                    Long.valueOf(socialActivityModelImpl.getReceiverUserId())
743                                            };
744    
745                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_C_T_R,
746                                            args);
747                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_C_T_R,
748                                            args);
749                            }
750                    }
751    
752                    EntityCacheUtil.putResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
753                            SocialActivityImpl.class, socialActivity.getPrimaryKey(),
754                            socialActivity);
755    
756                    if (isNew) {
757                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
758                                    new Object[] { Long.valueOf(
759                                                    socialActivity.getMirrorActivityId()) }, socialActivity);
760    
761                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
762                                    new Object[] {
763                                            Long.valueOf(socialActivity.getGroupId()),
764                                            Long.valueOf(socialActivity.getUserId()),
765                                            Long.valueOf(socialActivity.getCreateDate()),
766                                            Long.valueOf(socialActivity.getClassNameId()),
767                                            Long.valueOf(socialActivity.getClassPK()),
768                                            Integer.valueOf(socialActivity.getType()),
769                                            Long.valueOf(socialActivity.getReceiverUserId())
770                                    }, socialActivity);
771                    }
772                    else {
773                            if ((socialActivityModelImpl.getColumnBitmask() &
774                                            FINDER_PATH_FETCH_BY_MIRRORACTIVITYID.getColumnBitmask()) != 0) {
775                                    Object[] args = new Object[] {
776                                                    Long.valueOf(socialActivityModelImpl.getOriginalMirrorActivityId())
777                                            };
778    
779                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MIRRORACTIVITYID,
780                                            args);
781                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
782                                            args);
783    
784                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
785                                            new Object[] {
786                                                    Long.valueOf(socialActivity.getMirrorActivityId())
787                                            }, socialActivity);
788                            }
789    
790                            if ((socialActivityModelImpl.getColumnBitmask() &
791                                            FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R.getColumnBitmask()) != 0) {
792                                    Object[] args = new Object[] {
793                                                    Long.valueOf(socialActivityModelImpl.getOriginalGroupId()),
794                                                    Long.valueOf(socialActivityModelImpl.getOriginalUserId()),
795                                                    Long.valueOf(socialActivityModelImpl.getOriginalCreateDate()),
796                                                    Long.valueOf(socialActivityModelImpl.getOriginalClassNameId()),
797                                                    Long.valueOf(socialActivityModelImpl.getOriginalClassPK()),
798                                                    Integer.valueOf(socialActivityModelImpl.getOriginalType()),
799                                                    Long.valueOf(socialActivityModelImpl.getOriginalReceiverUserId())
800                                            };
801    
802                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R,
803                                            args);
804                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
805                                            args);
806    
807                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
808                                            new Object[] {
809                                                    Long.valueOf(socialActivity.getGroupId()),
810                                                    Long.valueOf(socialActivity.getUserId()),
811                                                    Long.valueOf(socialActivity.getCreateDate()),
812                                                    Long.valueOf(socialActivity.getClassNameId()),
813                                                    Long.valueOf(socialActivity.getClassPK()),
814                                                    Integer.valueOf(socialActivity.getType()),
815                                                    Long.valueOf(socialActivity.getReceiverUserId())
816                                            }, socialActivity);
817                            }
818                    }
819    
820                    return socialActivity;
821            }
822    
823            protected SocialActivity toUnwrappedModel(SocialActivity socialActivity) {
824                    if (socialActivity instanceof SocialActivityImpl) {
825                            return socialActivity;
826                    }
827    
828                    SocialActivityImpl socialActivityImpl = new SocialActivityImpl();
829    
830                    socialActivityImpl.setNew(socialActivity.isNew());
831                    socialActivityImpl.setPrimaryKey(socialActivity.getPrimaryKey());
832    
833                    socialActivityImpl.setActivityId(socialActivity.getActivityId());
834                    socialActivityImpl.setGroupId(socialActivity.getGroupId());
835                    socialActivityImpl.setCompanyId(socialActivity.getCompanyId());
836                    socialActivityImpl.setUserId(socialActivity.getUserId());
837                    socialActivityImpl.setCreateDate(socialActivity.getCreateDate());
838                    socialActivityImpl.setMirrorActivityId(socialActivity.getMirrorActivityId());
839                    socialActivityImpl.setClassNameId(socialActivity.getClassNameId());
840                    socialActivityImpl.setClassPK(socialActivity.getClassPK());
841                    socialActivityImpl.setType(socialActivity.getType());
842                    socialActivityImpl.setExtraData(socialActivity.getExtraData());
843                    socialActivityImpl.setReceiverUserId(socialActivity.getReceiverUserId());
844    
845                    return socialActivityImpl;
846            }
847    
848            /**
849             * Returns the social activity with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
850             *
851             * @param primaryKey the primary key of the social activity
852             * @return the social activity
853             * @throws com.liferay.portal.NoSuchModelException if a social activity with the primary key could not be found
854             * @throws SystemException if a system exception occurred
855             */
856            @Override
857            public SocialActivity findByPrimaryKey(Serializable primaryKey)
858                    throws NoSuchModelException, SystemException {
859                    return findByPrimaryKey(((Long)primaryKey).longValue());
860            }
861    
862            /**
863             * Returns the social activity with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivityException} if it could not be found.
864             *
865             * @param activityId the primary key of the social activity
866             * @return the social activity
867             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
868             * @throws SystemException if a system exception occurred
869             */
870            public SocialActivity findByPrimaryKey(long activityId)
871                    throws NoSuchActivityException, SystemException {
872                    SocialActivity socialActivity = fetchByPrimaryKey(activityId);
873    
874                    if (socialActivity == null) {
875                            if (_log.isWarnEnabled()) {
876                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + activityId);
877                            }
878    
879                            throw new NoSuchActivityException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
880                                    activityId);
881                    }
882    
883                    return socialActivity;
884            }
885    
886            /**
887             * Returns the social activity with the primary key or returns <code>null</code> if it could not be found.
888             *
889             * @param primaryKey the primary key of the social activity
890             * @return the social activity, or <code>null</code> if a social activity with the primary key could not be found
891             * @throws SystemException if a system exception occurred
892             */
893            @Override
894            public SocialActivity fetchByPrimaryKey(Serializable primaryKey)
895                    throws SystemException {
896                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
897            }
898    
899            /**
900             * Returns the social activity with the primary key or returns <code>null</code> if it could not be found.
901             *
902             * @param activityId the primary key of the social activity
903             * @return the social activity, or <code>null</code> if a social activity with the primary key could not be found
904             * @throws SystemException if a system exception occurred
905             */
906            public SocialActivity fetchByPrimaryKey(long activityId)
907                    throws SystemException {
908                    SocialActivity socialActivity = (SocialActivity)EntityCacheUtil.getResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
909                                    SocialActivityImpl.class, activityId);
910    
911                    if (socialActivity == _nullSocialActivity) {
912                            return null;
913                    }
914    
915                    if (socialActivity == null) {
916                            Session session = null;
917    
918                            boolean hasException = false;
919    
920                            try {
921                                    session = openSession();
922    
923                                    socialActivity = (SocialActivity)session.get(SocialActivityImpl.class,
924                                                    Long.valueOf(activityId));
925                            }
926                            catch (Exception e) {
927                                    hasException = true;
928    
929                                    throw processException(e);
930                            }
931                            finally {
932                                    if (socialActivity != null) {
933                                            cacheResult(socialActivity);
934                                    }
935                                    else if (!hasException) {
936                                            EntityCacheUtil.putResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
937                                                    SocialActivityImpl.class, activityId,
938                                                    _nullSocialActivity);
939                                    }
940    
941                                    closeSession(session);
942                            }
943                    }
944    
945                    return socialActivity;
946            }
947    
948            /**
949             * Returns all the social activities where groupId = &#63;.
950             *
951             * @param groupId the group ID
952             * @return the matching social activities
953             * @throws SystemException if a system exception occurred
954             */
955            public List<SocialActivity> findByGroupId(long groupId)
956                    throws SystemException {
957                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
958            }
959    
960            /**
961             * Returns a range of all the social activities where groupId = &#63;.
962             *
963             * <p>
964             * 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.
965             * </p>
966             *
967             * @param groupId the group ID
968             * @param start the lower bound of the range of social activities
969             * @param end the upper bound of the range of social activities (not inclusive)
970             * @return the range of matching social activities
971             * @throws SystemException if a system exception occurred
972             */
973            public List<SocialActivity> findByGroupId(long groupId, int start, int end)
974                    throws SystemException {
975                    return findByGroupId(groupId, start, end, null);
976            }
977    
978            /**
979             * Returns an ordered range of all the social activities where groupId = &#63;.
980             *
981             * <p>
982             * 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.
983             * </p>
984             *
985             * @param groupId the group ID
986             * @param start the lower bound of the range of social activities
987             * @param end the upper bound of the range of social activities (not inclusive)
988             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
989             * @return the ordered range of matching social activities
990             * @throws SystemException if a system exception occurred
991             */
992            public List<SocialActivity> findByGroupId(long groupId, int start, int end,
993                    OrderByComparator orderByComparator) throws SystemException {
994                    FinderPath finderPath = null;
995                    Object[] finderArgs = null;
996    
997                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
998                                    (orderByComparator == null)) {
999                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1000                            finderArgs = new Object[] { groupId };
1001                    }
1002                    else {
1003                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1004                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1005                    }
1006    
1007                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
1008                                    finderArgs, this);
1009    
1010                    if (list == null) {
1011                            StringBundler query = null;
1012    
1013                            if (orderByComparator != null) {
1014                                    query = new StringBundler(3 +
1015                                                    (orderByComparator.getOrderByFields().length * 3));
1016                            }
1017                            else {
1018                                    query = new StringBundler(3);
1019                            }
1020    
1021                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1022    
1023                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1024    
1025                            if (orderByComparator != null) {
1026                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1027                                            orderByComparator);
1028                            }
1029    
1030                            else {
1031                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1032                            }
1033    
1034                            String sql = query.toString();
1035    
1036                            Session session = null;
1037    
1038                            try {
1039                                    session = openSession();
1040    
1041                                    Query q = session.createQuery(sql);
1042    
1043                                    QueryPos qPos = QueryPos.getInstance(q);
1044    
1045                                    qPos.add(groupId);
1046    
1047                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
1048                                                    start, end);
1049                            }
1050                            catch (Exception e) {
1051                                    throw processException(e);
1052                            }
1053                            finally {
1054                                    if (list == null) {
1055                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1056                                    }
1057                                    else {
1058                                            cacheResult(list);
1059    
1060                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1061                                    }
1062    
1063                                    closeSession(session);
1064                            }
1065                    }
1066    
1067                    return list;
1068            }
1069    
1070            /**
1071             * Returns the first social activity in the ordered set where groupId = &#63;.
1072             *
1073             * <p>
1074             * 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.
1075             * </p>
1076             *
1077             * @param groupId the group ID
1078             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1079             * @return the first matching social activity
1080             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1081             * @throws SystemException if a system exception occurred
1082             */
1083            public SocialActivity findByGroupId_First(long groupId,
1084                    OrderByComparator orderByComparator)
1085                    throws NoSuchActivityException, SystemException {
1086                    List<SocialActivity> list = findByGroupId(groupId, 0, 1,
1087                                    orderByComparator);
1088    
1089                    if (list.isEmpty()) {
1090                            StringBundler msg = new StringBundler(4);
1091    
1092                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1093    
1094                            msg.append("groupId=");
1095                            msg.append(groupId);
1096    
1097                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1098    
1099                            throw new NoSuchActivityException(msg.toString());
1100                    }
1101                    else {
1102                            return list.get(0);
1103                    }
1104            }
1105    
1106            /**
1107             * Returns the last social activity in the ordered set where groupId = &#63;.
1108             *
1109             * <p>
1110             * 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.
1111             * </p>
1112             *
1113             * @param groupId the group ID
1114             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1115             * @return the last matching social activity
1116             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1117             * @throws SystemException if a system exception occurred
1118             */
1119            public SocialActivity findByGroupId_Last(long groupId,
1120                    OrderByComparator orderByComparator)
1121                    throws NoSuchActivityException, SystemException {
1122                    int count = countByGroupId(groupId);
1123    
1124                    List<SocialActivity> list = findByGroupId(groupId, count - 1, count,
1125                                    orderByComparator);
1126    
1127                    if (list.isEmpty()) {
1128                            StringBundler msg = new StringBundler(4);
1129    
1130                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1131    
1132                            msg.append("groupId=");
1133                            msg.append(groupId);
1134    
1135                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1136    
1137                            throw new NoSuchActivityException(msg.toString());
1138                    }
1139                    else {
1140                            return list.get(0);
1141                    }
1142            }
1143    
1144            /**
1145             * Returns the social activities before and after the current social activity in the ordered set where groupId = &#63;.
1146             *
1147             * <p>
1148             * 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.
1149             * </p>
1150             *
1151             * @param activityId the primary key of the current social activity
1152             * @param groupId the group ID
1153             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1154             * @return the previous, current, and next social activity
1155             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
1156             * @throws SystemException if a system exception occurred
1157             */
1158            public SocialActivity[] findByGroupId_PrevAndNext(long activityId,
1159                    long groupId, OrderByComparator orderByComparator)
1160                    throws NoSuchActivityException, SystemException {
1161                    SocialActivity socialActivity = findByPrimaryKey(activityId);
1162    
1163                    Session session = null;
1164    
1165                    try {
1166                            session = openSession();
1167    
1168                            SocialActivity[] array = new SocialActivityImpl[3];
1169    
1170                            array[0] = getByGroupId_PrevAndNext(session, socialActivity,
1171                                            groupId, orderByComparator, true);
1172    
1173                            array[1] = socialActivity;
1174    
1175                            array[2] = getByGroupId_PrevAndNext(session, socialActivity,
1176                                            groupId, orderByComparator, false);
1177    
1178                            return array;
1179                    }
1180                    catch (Exception e) {
1181                            throw processException(e);
1182                    }
1183                    finally {
1184                            closeSession(session);
1185                    }
1186            }
1187    
1188            protected SocialActivity getByGroupId_PrevAndNext(Session session,
1189                    SocialActivity socialActivity, long groupId,
1190                    OrderByComparator orderByComparator, boolean previous) {
1191                    StringBundler query = null;
1192    
1193                    if (orderByComparator != null) {
1194                            query = new StringBundler(6 +
1195                                            (orderByComparator.getOrderByFields().length * 6));
1196                    }
1197                    else {
1198                            query = new StringBundler(3);
1199                    }
1200    
1201                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1202    
1203                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1204    
1205                    if (orderByComparator != null) {
1206                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1207    
1208                            if (orderByConditionFields.length > 0) {
1209                                    query.append(WHERE_AND);
1210                            }
1211    
1212                            for (int i = 0; i < orderByConditionFields.length; i++) {
1213                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1214                                    query.append(orderByConditionFields[i]);
1215    
1216                                    if ((i + 1) < orderByConditionFields.length) {
1217                                            if (orderByComparator.isAscending() ^ previous) {
1218                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1219                                            }
1220                                            else {
1221                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1222                                            }
1223                                    }
1224                                    else {
1225                                            if (orderByComparator.isAscending() ^ previous) {
1226                                                    query.append(WHERE_GREATER_THAN);
1227                                            }
1228                                            else {
1229                                                    query.append(WHERE_LESSER_THAN);
1230                                            }
1231                                    }
1232                            }
1233    
1234                            query.append(ORDER_BY_CLAUSE);
1235    
1236                            String[] orderByFields = orderByComparator.getOrderByFields();
1237    
1238                            for (int i = 0; i < orderByFields.length; i++) {
1239                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1240                                    query.append(orderByFields[i]);
1241    
1242                                    if ((i + 1) < orderByFields.length) {
1243                                            if (orderByComparator.isAscending() ^ previous) {
1244                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1245                                            }
1246                                            else {
1247                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1248                                            }
1249                                    }
1250                                    else {
1251                                            if (orderByComparator.isAscending() ^ previous) {
1252                                                    query.append(ORDER_BY_ASC);
1253                                            }
1254                                            else {
1255                                                    query.append(ORDER_BY_DESC);
1256                                            }
1257                                    }
1258                            }
1259                    }
1260    
1261                    else {
1262                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1263                    }
1264    
1265                    String sql = query.toString();
1266    
1267                    Query q = session.createQuery(sql);
1268    
1269                    q.setFirstResult(0);
1270                    q.setMaxResults(2);
1271    
1272                    QueryPos qPos = QueryPos.getInstance(q);
1273    
1274                    qPos.add(groupId);
1275    
1276                    if (orderByComparator != null) {
1277                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
1278    
1279                            for (Object value : values) {
1280                                    qPos.add(value);
1281                            }
1282                    }
1283    
1284                    List<SocialActivity> list = q.list();
1285    
1286                    if (list.size() == 2) {
1287                            return list.get(1);
1288                    }
1289                    else {
1290                            return null;
1291                    }
1292            }
1293    
1294            /**
1295             * Returns all the social activities where companyId = &#63;.
1296             *
1297             * @param companyId the company ID
1298             * @return the matching social activities
1299             * @throws SystemException if a system exception occurred
1300             */
1301            public List<SocialActivity> findByCompanyId(long companyId)
1302                    throws SystemException {
1303                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1304                            null);
1305            }
1306    
1307            /**
1308             * Returns a range of all the social activities where companyId = &#63;.
1309             *
1310             * <p>
1311             * 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.
1312             * </p>
1313             *
1314             * @param companyId the company ID
1315             * @param start the lower bound of the range of social activities
1316             * @param end the upper bound of the range of social activities (not inclusive)
1317             * @return the range of matching social activities
1318             * @throws SystemException if a system exception occurred
1319             */
1320            public List<SocialActivity> findByCompanyId(long companyId, int start,
1321                    int end) throws SystemException {
1322                    return findByCompanyId(companyId, start, end, null);
1323            }
1324    
1325            /**
1326             * Returns an ordered range of all the social activities where companyId = &#63;.
1327             *
1328             * <p>
1329             * 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.
1330             * </p>
1331             *
1332             * @param companyId the company ID
1333             * @param start the lower bound of the range of social activities
1334             * @param end the upper bound of the range of social activities (not inclusive)
1335             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1336             * @return the ordered range of matching social activities
1337             * @throws SystemException if a system exception occurred
1338             */
1339            public List<SocialActivity> findByCompanyId(long companyId, int start,
1340                    int end, OrderByComparator orderByComparator) throws SystemException {
1341                    FinderPath finderPath = null;
1342                    Object[] finderArgs = null;
1343    
1344                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1345                                    (orderByComparator == null)) {
1346                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1347                            finderArgs = new Object[] { companyId };
1348                    }
1349                    else {
1350                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1351                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1352                    }
1353    
1354                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
1355                                    finderArgs, this);
1356    
1357                    if (list == null) {
1358                            StringBundler query = null;
1359    
1360                            if (orderByComparator != null) {
1361                                    query = new StringBundler(3 +
1362                                                    (orderByComparator.getOrderByFields().length * 3));
1363                            }
1364                            else {
1365                                    query = new StringBundler(3);
1366                            }
1367    
1368                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1369    
1370                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1371    
1372                            if (orderByComparator != null) {
1373                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1374                                            orderByComparator);
1375                            }
1376    
1377                            else {
1378                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1379                            }
1380    
1381                            String sql = query.toString();
1382    
1383                            Session session = null;
1384    
1385                            try {
1386                                    session = openSession();
1387    
1388                                    Query q = session.createQuery(sql);
1389    
1390                                    QueryPos qPos = QueryPos.getInstance(q);
1391    
1392                                    qPos.add(companyId);
1393    
1394                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
1395                                                    start, end);
1396                            }
1397                            catch (Exception e) {
1398                                    throw processException(e);
1399                            }
1400                            finally {
1401                                    if (list == null) {
1402                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1403                                    }
1404                                    else {
1405                                            cacheResult(list);
1406    
1407                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1408                                    }
1409    
1410                                    closeSession(session);
1411                            }
1412                    }
1413    
1414                    return list;
1415            }
1416    
1417            /**
1418             * Returns the first social activity in the ordered set where companyId = &#63;.
1419             *
1420             * <p>
1421             * 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.
1422             * </p>
1423             *
1424             * @param companyId the company ID
1425             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1426             * @return the first matching social activity
1427             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1428             * @throws SystemException if a system exception occurred
1429             */
1430            public SocialActivity findByCompanyId_First(long companyId,
1431                    OrderByComparator orderByComparator)
1432                    throws NoSuchActivityException, SystemException {
1433                    List<SocialActivity> list = findByCompanyId(companyId, 0, 1,
1434                                    orderByComparator);
1435    
1436                    if (list.isEmpty()) {
1437                            StringBundler msg = new StringBundler(4);
1438    
1439                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1440    
1441                            msg.append("companyId=");
1442                            msg.append(companyId);
1443    
1444                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1445    
1446                            throw new NoSuchActivityException(msg.toString());
1447                    }
1448                    else {
1449                            return list.get(0);
1450                    }
1451            }
1452    
1453            /**
1454             * Returns the last social activity in the ordered set where companyId = &#63;.
1455             *
1456             * <p>
1457             * 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.
1458             * </p>
1459             *
1460             * @param companyId the company ID
1461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1462             * @return the last matching social activity
1463             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1464             * @throws SystemException if a system exception occurred
1465             */
1466            public SocialActivity findByCompanyId_Last(long companyId,
1467                    OrderByComparator orderByComparator)
1468                    throws NoSuchActivityException, SystemException {
1469                    int count = countByCompanyId(companyId);
1470    
1471                    List<SocialActivity> list = findByCompanyId(companyId, count - 1,
1472                                    count, orderByComparator);
1473    
1474                    if (list.isEmpty()) {
1475                            StringBundler msg = new StringBundler(4);
1476    
1477                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1478    
1479                            msg.append("companyId=");
1480                            msg.append(companyId);
1481    
1482                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1483    
1484                            throw new NoSuchActivityException(msg.toString());
1485                    }
1486                    else {
1487                            return list.get(0);
1488                    }
1489            }
1490    
1491            /**
1492             * Returns the social activities before and after the current social activity in the ordered set where companyId = &#63;.
1493             *
1494             * <p>
1495             * 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.
1496             * </p>
1497             *
1498             * @param activityId the primary key of the current social activity
1499             * @param companyId the company ID
1500             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1501             * @return the previous, current, and next social activity
1502             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
1503             * @throws SystemException if a system exception occurred
1504             */
1505            public SocialActivity[] findByCompanyId_PrevAndNext(long activityId,
1506                    long companyId, OrderByComparator orderByComparator)
1507                    throws NoSuchActivityException, SystemException {
1508                    SocialActivity socialActivity = findByPrimaryKey(activityId);
1509    
1510                    Session session = null;
1511    
1512                    try {
1513                            session = openSession();
1514    
1515                            SocialActivity[] array = new SocialActivityImpl[3];
1516    
1517                            array[0] = getByCompanyId_PrevAndNext(session, socialActivity,
1518                                            companyId, orderByComparator, true);
1519    
1520                            array[1] = socialActivity;
1521    
1522                            array[2] = getByCompanyId_PrevAndNext(session, socialActivity,
1523                                            companyId, orderByComparator, false);
1524    
1525                            return array;
1526                    }
1527                    catch (Exception e) {
1528                            throw processException(e);
1529                    }
1530                    finally {
1531                            closeSession(session);
1532                    }
1533            }
1534    
1535            protected SocialActivity getByCompanyId_PrevAndNext(Session session,
1536                    SocialActivity socialActivity, long companyId,
1537                    OrderByComparator orderByComparator, boolean previous) {
1538                    StringBundler query = null;
1539    
1540                    if (orderByComparator != null) {
1541                            query = new StringBundler(6 +
1542                                            (orderByComparator.getOrderByFields().length * 6));
1543                    }
1544                    else {
1545                            query = new StringBundler(3);
1546                    }
1547    
1548                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1549    
1550                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1551    
1552                    if (orderByComparator != null) {
1553                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1554    
1555                            if (orderByConditionFields.length > 0) {
1556                                    query.append(WHERE_AND);
1557                            }
1558    
1559                            for (int i = 0; i < orderByConditionFields.length; i++) {
1560                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1561                                    query.append(orderByConditionFields[i]);
1562    
1563                                    if ((i + 1) < orderByConditionFields.length) {
1564                                            if (orderByComparator.isAscending() ^ previous) {
1565                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1566                                            }
1567                                            else {
1568                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1569                                            }
1570                                    }
1571                                    else {
1572                                            if (orderByComparator.isAscending() ^ previous) {
1573                                                    query.append(WHERE_GREATER_THAN);
1574                                            }
1575                                            else {
1576                                                    query.append(WHERE_LESSER_THAN);
1577                                            }
1578                                    }
1579                            }
1580    
1581                            query.append(ORDER_BY_CLAUSE);
1582    
1583                            String[] orderByFields = orderByComparator.getOrderByFields();
1584    
1585                            for (int i = 0; i < orderByFields.length; i++) {
1586                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1587                                    query.append(orderByFields[i]);
1588    
1589                                    if ((i + 1) < orderByFields.length) {
1590                                            if (orderByComparator.isAscending() ^ previous) {
1591                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1592                                            }
1593                                            else {
1594                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1595                                            }
1596                                    }
1597                                    else {
1598                                            if (orderByComparator.isAscending() ^ previous) {
1599                                                    query.append(ORDER_BY_ASC);
1600                                            }
1601                                            else {
1602                                                    query.append(ORDER_BY_DESC);
1603                                            }
1604                                    }
1605                            }
1606                    }
1607    
1608                    else {
1609                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1610                    }
1611    
1612                    String sql = query.toString();
1613    
1614                    Query q = session.createQuery(sql);
1615    
1616                    q.setFirstResult(0);
1617                    q.setMaxResults(2);
1618    
1619                    QueryPos qPos = QueryPos.getInstance(q);
1620    
1621                    qPos.add(companyId);
1622    
1623                    if (orderByComparator != null) {
1624                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
1625    
1626                            for (Object value : values) {
1627                                    qPos.add(value);
1628                            }
1629                    }
1630    
1631                    List<SocialActivity> list = q.list();
1632    
1633                    if (list.size() == 2) {
1634                            return list.get(1);
1635                    }
1636                    else {
1637                            return null;
1638                    }
1639            }
1640    
1641            /**
1642             * Returns all the social activities where userId = &#63;.
1643             *
1644             * @param userId the user ID
1645             * @return the matching social activities
1646             * @throws SystemException if a system exception occurred
1647             */
1648            public List<SocialActivity> findByUserId(long userId)
1649                    throws SystemException {
1650                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1651            }
1652    
1653            /**
1654             * Returns a range of all the social activities where userId = &#63;.
1655             *
1656             * <p>
1657             * 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.
1658             * </p>
1659             *
1660             * @param userId the user ID
1661             * @param start the lower bound of the range of social activities
1662             * @param end the upper bound of the range of social activities (not inclusive)
1663             * @return the range of matching social activities
1664             * @throws SystemException if a system exception occurred
1665             */
1666            public List<SocialActivity> findByUserId(long userId, int start, int end)
1667                    throws SystemException {
1668                    return findByUserId(userId, start, end, null);
1669            }
1670    
1671            /**
1672             * Returns an ordered range of all the social activities where userId = &#63;.
1673             *
1674             * <p>
1675             * 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.
1676             * </p>
1677             *
1678             * @param userId the user ID
1679             * @param start the lower bound of the range of social activities
1680             * @param end the upper bound of the range of social activities (not inclusive)
1681             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1682             * @return the ordered range of matching social activities
1683             * @throws SystemException if a system exception occurred
1684             */
1685            public List<SocialActivity> findByUserId(long userId, int start, int end,
1686                    OrderByComparator orderByComparator) throws SystemException {
1687                    FinderPath finderPath = null;
1688                    Object[] finderArgs = null;
1689    
1690                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1691                                    (orderByComparator == null)) {
1692                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1693                            finderArgs = new Object[] { userId };
1694                    }
1695                    else {
1696                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1697                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1698                    }
1699    
1700                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
1701                                    finderArgs, this);
1702    
1703                    if (list == null) {
1704                            StringBundler query = null;
1705    
1706                            if (orderByComparator != null) {
1707                                    query = new StringBundler(3 +
1708                                                    (orderByComparator.getOrderByFields().length * 3));
1709                            }
1710                            else {
1711                                    query = new StringBundler(3);
1712                            }
1713    
1714                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1715    
1716                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1717    
1718                            if (orderByComparator != null) {
1719                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1720                                            orderByComparator);
1721                            }
1722    
1723                            else {
1724                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1725                            }
1726    
1727                            String sql = query.toString();
1728    
1729                            Session session = null;
1730    
1731                            try {
1732                                    session = openSession();
1733    
1734                                    Query q = session.createQuery(sql);
1735    
1736                                    QueryPos qPos = QueryPos.getInstance(q);
1737    
1738                                    qPos.add(userId);
1739    
1740                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
1741                                                    start, end);
1742                            }
1743                            catch (Exception e) {
1744                                    throw processException(e);
1745                            }
1746                            finally {
1747                                    if (list == null) {
1748                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1749                                    }
1750                                    else {
1751                                            cacheResult(list);
1752    
1753                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1754                                    }
1755    
1756                                    closeSession(session);
1757                            }
1758                    }
1759    
1760                    return list;
1761            }
1762    
1763            /**
1764             * Returns the first social activity in the ordered set where userId = &#63;.
1765             *
1766             * <p>
1767             * 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.
1768             * </p>
1769             *
1770             * @param userId the user ID
1771             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1772             * @return the first matching social activity
1773             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1774             * @throws SystemException if a system exception occurred
1775             */
1776            public SocialActivity findByUserId_First(long userId,
1777                    OrderByComparator orderByComparator)
1778                    throws NoSuchActivityException, SystemException {
1779                    List<SocialActivity> list = findByUserId(userId, 0, 1, orderByComparator);
1780    
1781                    if (list.isEmpty()) {
1782                            StringBundler msg = new StringBundler(4);
1783    
1784                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1785    
1786                            msg.append("userId=");
1787                            msg.append(userId);
1788    
1789                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1790    
1791                            throw new NoSuchActivityException(msg.toString());
1792                    }
1793                    else {
1794                            return list.get(0);
1795                    }
1796            }
1797    
1798            /**
1799             * Returns the last social activity in the ordered set where userId = &#63;.
1800             *
1801             * <p>
1802             * 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.
1803             * </p>
1804             *
1805             * @param userId the user ID
1806             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1807             * @return the last matching social activity
1808             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1809             * @throws SystemException if a system exception occurred
1810             */
1811            public SocialActivity findByUserId_Last(long userId,
1812                    OrderByComparator orderByComparator)
1813                    throws NoSuchActivityException, SystemException {
1814                    int count = countByUserId(userId);
1815    
1816                    List<SocialActivity> list = findByUserId(userId, count - 1, count,
1817                                    orderByComparator);
1818    
1819                    if (list.isEmpty()) {
1820                            StringBundler msg = new StringBundler(4);
1821    
1822                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1823    
1824                            msg.append("userId=");
1825                            msg.append(userId);
1826    
1827                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1828    
1829                            throw new NoSuchActivityException(msg.toString());
1830                    }
1831                    else {
1832                            return list.get(0);
1833                    }
1834            }
1835    
1836            /**
1837             * Returns the social activities before and after the current social activity in the ordered set where userId = &#63;.
1838             *
1839             * <p>
1840             * 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.
1841             * </p>
1842             *
1843             * @param activityId the primary key of the current social activity
1844             * @param userId the user ID
1845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1846             * @return the previous, current, and next social activity
1847             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
1848             * @throws SystemException if a system exception occurred
1849             */
1850            public SocialActivity[] findByUserId_PrevAndNext(long activityId,
1851                    long userId, OrderByComparator orderByComparator)
1852                    throws NoSuchActivityException, SystemException {
1853                    SocialActivity socialActivity = findByPrimaryKey(activityId);
1854    
1855                    Session session = null;
1856    
1857                    try {
1858                            session = openSession();
1859    
1860                            SocialActivity[] array = new SocialActivityImpl[3];
1861    
1862                            array[0] = getByUserId_PrevAndNext(session, socialActivity, userId,
1863                                            orderByComparator, true);
1864    
1865                            array[1] = socialActivity;
1866    
1867                            array[2] = getByUserId_PrevAndNext(session, socialActivity, userId,
1868                                            orderByComparator, false);
1869    
1870                            return array;
1871                    }
1872                    catch (Exception e) {
1873                            throw processException(e);
1874                    }
1875                    finally {
1876                            closeSession(session);
1877                    }
1878            }
1879    
1880            protected SocialActivity getByUserId_PrevAndNext(Session session,
1881                    SocialActivity socialActivity, long userId,
1882                    OrderByComparator orderByComparator, boolean previous) {
1883                    StringBundler query = null;
1884    
1885                    if (orderByComparator != null) {
1886                            query = new StringBundler(6 +
1887                                            (orderByComparator.getOrderByFields().length * 6));
1888                    }
1889                    else {
1890                            query = new StringBundler(3);
1891                    }
1892    
1893                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1894    
1895                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1896    
1897                    if (orderByComparator != null) {
1898                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1899    
1900                            if (orderByConditionFields.length > 0) {
1901                                    query.append(WHERE_AND);
1902                            }
1903    
1904                            for (int i = 0; i < orderByConditionFields.length; i++) {
1905                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1906                                    query.append(orderByConditionFields[i]);
1907    
1908                                    if ((i + 1) < orderByConditionFields.length) {
1909                                            if (orderByComparator.isAscending() ^ previous) {
1910                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1911                                            }
1912                                            else {
1913                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1914                                            }
1915                                    }
1916                                    else {
1917                                            if (orderByComparator.isAscending() ^ previous) {
1918                                                    query.append(WHERE_GREATER_THAN);
1919                                            }
1920                                            else {
1921                                                    query.append(WHERE_LESSER_THAN);
1922                                            }
1923                                    }
1924                            }
1925    
1926                            query.append(ORDER_BY_CLAUSE);
1927    
1928                            String[] orderByFields = orderByComparator.getOrderByFields();
1929    
1930                            for (int i = 0; i < orderByFields.length; i++) {
1931                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1932                                    query.append(orderByFields[i]);
1933    
1934                                    if ((i + 1) < orderByFields.length) {
1935                                            if (orderByComparator.isAscending() ^ previous) {
1936                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1937                                            }
1938                                            else {
1939                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1940                                            }
1941                                    }
1942                                    else {
1943                                            if (orderByComparator.isAscending() ^ previous) {
1944                                                    query.append(ORDER_BY_ASC);
1945                                            }
1946                                            else {
1947                                                    query.append(ORDER_BY_DESC);
1948                                            }
1949                                    }
1950                            }
1951                    }
1952    
1953                    else {
1954                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1955                    }
1956    
1957                    String sql = query.toString();
1958    
1959                    Query q = session.createQuery(sql);
1960    
1961                    q.setFirstResult(0);
1962                    q.setMaxResults(2);
1963    
1964                    QueryPos qPos = QueryPos.getInstance(q);
1965    
1966                    qPos.add(userId);
1967    
1968                    if (orderByComparator != null) {
1969                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
1970    
1971                            for (Object value : values) {
1972                                    qPos.add(value);
1973                            }
1974                    }
1975    
1976                    List<SocialActivity> list = q.list();
1977    
1978                    if (list.size() == 2) {
1979                            return list.get(1);
1980                    }
1981                    else {
1982                            return null;
1983                    }
1984            }
1985    
1986            /**
1987             * Returns the social activity where mirrorActivityId = &#63; or throws a {@link com.liferay.portlet.social.NoSuchActivityException} if it could not be found.
1988             *
1989             * @param mirrorActivityId the mirror activity ID
1990             * @return the matching social activity
1991             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1992             * @throws SystemException if a system exception occurred
1993             */
1994            public SocialActivity findByMirrorActivityId(long mirrorActivityId)
1995                    throws NoSuchActivityException, SystemException {
1996                    SocialActivity socialActivity = fetchByMirrorActivityId(mirrorActivityId);
1997    
1998                    if (socialActivity == null) {
1999                            StringBundler msg = new StringBundler(4);
2000    
2001                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2002    
2003                            msg.append("mirrorActivityId=");
2004                            msg.append(mirrorActivityId);
2005    
2006                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2007    
2008                            if (_log.isWarnEnabled()) {
2009                                    _log.warn(msg.toString());
2010                            }
2011    
2012                            throw new NoSuchActivityException(msg.toString());
2013                    }
2014    
2015                    return socialActivity;
2016            }
2017    
2018            /**
2019             * Returns the social activity where mirrorActivityId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2020             *
2021             * @param mirrorActivityId the mirror activity ID
2022             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
2023             * @throws SystemException if a system exception occurred
2024             */
2025            public SocialActivity fetchByMirrorActivityId(long mirrorActivityId)
2026                    throws SystemException {
2027                    return fetchByMirrorActivityId(mirrorActivityId, true);
2028            }
2029    
2030            /**
2031             * Returns the social activity where mirrorActivityId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2032             *
2033             * @param mirrorActivityId the mirror activity ID
2034             * @param retrieveFromCache whether to use the finder cache
2035             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
2036             * @throws SystemException if a system exception occurred
2037             */
2038            public SocialActivity fetchByMirrorActivityId(long mirrorActivityId,
2039                    boolean retrieveFromCache) throws SystemException {
2040                    Object[] finderArgs = new Object[] { mirrorActivityId };
2041    
2042                    Object result = null;
2043    
2044                    if (retrieveFromCache) {
2045                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
2046                                            finderArgs, this);
2047                    }
2048    
2049                    if (result == null) {
2050                            StringBundler query = new StringBundler(3);
2051    
2052                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2053    
2054                            query.append(_FINDER_COLUMN_MIRRORACTIVITYID_MIRRORACTIVITYID_2);
2055    
2056                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2057    
2058                            String sql = query.toString();
2059    
2060                            Session session = null;
2061    
2062                            try {
2063                                    session = openSession();
2064    
2065                                    Query q = session.createQuery(sql);
2066    
2067                                    QueryPos qPos = QueryPos.getInstance(q);
2068    
2069                                    qPos.add(mirrorActivityId);
2070    
2071                                    List<SocialActivity> list = q.list();
2072    
2073                                    result = list;
2074    
2075                                    SocialActivity socialActivity = null;
2076    
2077                                    if (list.isEmpty()) {
2078                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
2079                                                    finderArgs, list);
2080                                    }
2081                                    else {
2082                                            socialActivity = list.get(0);
2083    
2084                                            cacheResult(socialActivity);
2085    
2086                                            if ((socialActivity.getMirrorActivityId() != mirrorActivityId)) {
2087                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
2088                                                            finderArgs, socialActivity);
2089                                            }
2090                                    }
2091    
2092                                    return socialActivity;
2093                            }
2094                            catch (Exception e) {
2095                                    throw processException(e);
2096                            }
2097                            finally {
2098                                    if (result == null) {
2099                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
2100                                                    finderArgs);
2101                                    }
2102    
2103                                    closeSession(session);
2104                            }
2105                    }
2106                    else {
2107                            if (result instanceof List<?>) {
2108                                    return null;
2109                            }
2110                            else {
2111                                    return (SocialActivity)result;
2112                            }
2113                    }
2114            }
2115    
2116            /**
2117             * Returns all the social activities where classNameId = &#63;.
2118             *
2119             * @param classNameId the class name ID
2120             * @return the matching social activities
2121             * @throws SystemException if a system exception occurred
2122             */
2123            public List<SocialActivity> findByClassNameId(long classNameId)
2124                    throws SystemException {
2125                    return findByClassNameId(classNameId, QueryUtil.ALL_POS,
2126                            QueryUtil.ALL_POS, null);
2127            }
2128    
2129            /**
2130             * Returns a range of all the social activities where classNameId = &#63;.
2131             *
2132             * <p>
2133             * 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.
2134             * </p>
2135             *
2136             * @param classNameId the class name ID
2137             * @param start the lower bound of the range of social activities
2138             * @param end the upper bound of the range of social activities (not inclusive)
2139             * @return the range of matching social activities
2140             * @throws SystemException if a system exception occurred
2141             */
2142            public List<SocialActivity> findByClassNameId(long classNameId, int start,
2143                    int end) throws SystemException {
2144                    return findByClassNameId(classNameId, start, end, null);
2145            }
2146    
2147            /**
2148             * Returns an ordered range of all the social activities where classNameId = &#63;.
2149             *
2150             * <p>
2151             * 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.
2152             * </p>
2153             *
2154             * @param classNameId the class name ID
2155             * @param start the lower bound of the range of social activities
2156             * @param end the upper bound of the range of social activities (not inclusive)
2157             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2158             * @return the ordered range of matching social activities
2159             * @throws SystemException if a system exception occurred
2160             */
2161            public List<SocialActivity> findByClassNameId(long classNameId, int start,
2162                    int end, OrderByComparator orderByComparator) throws SystemException {
2163                    FinderPath finderPath = null;
2164                    Object[] finderArgs = null;
2165    
2166                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2167                                    (orderByComparator == null)) {
2168                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
2169                            finderArgs = new Object[] { classNameId };
2170                    }
2171                    else {
2172                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
2173                            finderArgs = new Object[] { classNameId, start, end, orderByComparator };
2174                    }
2175    
2176                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
2177                                    finderArgs, this);
2178    
2179                    if (list == null) {
2180                            StringBundler query = null;
2181    
2182                            if (orderByComparator != null) {
2183                                    query = new StringBundler(3 +
2184                                                    (orderByComparator.getOrderByFields().length * 3));
2185                            }
2186                            else {
2187                                    query = new StringBundler(3);
2188                            }
2189    
2190                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2191    
2192                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
2193    
2194                            if (orderByComparator != null) {
2195                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2196                                            orderByComparator);
2197                            }
2198    
2199                            else {
2200                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2201                            }
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(classNameId);
2215    
2216                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
2217                                                    start, end);
2218                            }
2219                            catch (Exception e) {
2220                                    throw processException(e);
2221                            }
2222                            finally {
2223                                    if (list == null) {
2224                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2225                                    }
2226                                    else {
2227                                            cacheResult(list);
2228    
2229                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2230                                    }
2231    
2232                                    closeSession(session);
2233                            }
2234                    }
2235    
2236                    return list;
2237            }
2238    
2239            /**
2240             * Returns the first social activity in the ordered set where classNameId = &#63;.
2241             *
2242             * <p>
2243             * 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.
2244             * </p>
2245             *
2246             * @param classNameId the class name ID
2247             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2248             * @return the first matching social activity
2249             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2250             * @throws SystemException if a system exception occurred
2251             */
2252            public SocialActivity findByClassNameId_First(long classNameId,
2253                    OrderByComparator orderByComparator)
2254                    throws NoSuchActivityException, SystemException {
2255                    List<SocialActivity> list = findByClassNameId(classNameId, 0, 1,
2256                                    orderByComparator);
2257    
2258                    if (list.isEmpty()) {
2259                            StringBundler msg = new StringBundler(4);
2260    
2261                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2262    
2263                            msg.append("classNameId=");
2264                            msg.append(classNameId);
2265    
2266                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2267    
2268                            throw new NoSuchActivityException(msg.toString());
2269                    }
2270                    else {
2271                            return list.get(0);
2272                    }
2273            }
2274    
2275            /**
2276             * Returns the last social activity in the ordered set where classNameId = &#63;.
2277             *
2278             * <p>
2279             * 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.
2280             * </p>
2281             *
2282             * @param classNameId the class name ID
2283             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2284             * @return the last matching social activity
2285             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2286             * @throws SystemException if a system exception occurred
2287             */
2288            public SocialActivity findByClassNameId_Last(long classNameId,
2289                    OrderByComparator orderByComparator)
2290                    throws NoSuchActivityException, SystemException {
2291                    int count = countByClassNameId(classNameId);
2292    
2293                    List<SocialActivity> list = findByClassNameId(classNameId, count - 1,
2294                                    count, orderByComparator);
2295    
2296                    if (list.isEmpty()) {
2297                            StringBundler msg = new StringBundler(4);
2298    
2299                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2300    
2301                            msg.append("classNameId=");
2302                            msg.append(classNameId);
2303    
2304                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2305    
2306                            throw new NoSuchActivityException(msg.toString());
2307                    }
2308                    else {
2309                            return list.get(0);
2310                    }
2311            }
2312    
2313            /**
2314             * Returns the social activities before and after the current social activity in the ordered set where classNameId = &#63;.
2315             *
2316             * <p>
2317             * 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.
2318             * </p>
2319             *
2320             * @param activityId the primary key of the current social activity
2321             * @param classNameId the class name ID
2322             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2323             * @return the previous, current, and next social activity
2324             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
2325             * @throws SystemException if a system exception occurred
2326             */
2327            public SocialActivity[] findByClassNameId_PrevAndNext(long activityId,
2328                    long classNameId, OrderByComparator orderByComparator)
2329                    throws NoSuchActivityException, SystemException {
2330                    SocialActivity socialActivity = findByPrimaryKey(activityId);
2331    
2332                    Session session = null;
2333    
2334                    try {
2335                            session = openSession();
2336    
2337                            SocialActivity[] array = new SocialActivityImpl[3];
2338    
2339                            array[0] = getByClassNameId_PrevAndNext(session, socialActivity,
2340                                            classNameId, orderByComparator, true);
2341    
2342                            array[1] = socialActivity;
2343    
2344                            array[2] = getByClassNameId_PrevAndNext(session, socialActivity,
2345                                            classNameId, orderByComparator, false);
2346    
2347                            return array;
2348                    }
2349                    catch (Exception e) {
2350                            throw processException(e);
2351                    }
2352                    finally {
2353                            closeSession(session);
2354                    }
2355            }
2356    
2357            protected SocialActivity getByClassNameId_PrevAndNext(Session session,
2358                    SocialActivity socialActivity, long classNameId,
2359                    OrderByComparator orderByComparator, boolean previous) {
2360                    StringBundler query = null;
2361    
2362                    if (orderByComparator != null) {
2363                            query = new StringBundler(6 +
2364                                            (orderByComparator.getOrderByFields().length * 6));
2365                    }
2366                    else {
2367                            query = new StringBundler(3);
2368                    }
2369    
2370                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2371    
2372                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
2373    
2374                    if (orderByComparator != null) {
2375                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2376    
2377                            if (orderByConditionFields.length > 0) {
2378                                    query.append(WHERE_AND);
2379                            }
2380    
2381                            for (int i = 0; i < orderByConditionFields.length; i++) {
2382                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2383                                    query.append(orderByConditionFields[i]);
2384    
2385                                    if ((i + 1) < orderByConditionFields.length) {
2386                                            if (orderByComparator.isAscending() ^ previous) {
2387                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2388                                            }
2389                                            else {
2390                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2391                                            }
2392                                    }
2393                                    else {
2394                                            if (orderByComparator.isAscending() ^ previous) {
2395                                                    query.append(WHERE_GREATER_THAN);
2396                                            }
2397                                            else {
2398                                                    query.append(WHERE_LESSER_THAN);
2399                                            }
2400                                    }
2401                            }
2402    
2403                            query.append(ORDER_BY_CLAUSE);
2404    
2405                            String[] orderByFields = orderByComparator.getOrderByFields();
2406    
2407                            for (int i = 0; i < orderByFields.length; i++) {
2408                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2409                                    query.append(orderByFields[i]);
2410    
2411                                    if ((i + 1) < orderByFields.length) {
2412                                            if (orderByComparator.isAscending() ^ previous) {
2413                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2414                                            }
2415                                            else {
2416                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2417                                            }
2418                                    }
2419                                    else {
2420                                            if (orderByComparator.isAscending() ^ previous) {
2421                                                    query.append(ORDER_BY_ASC);
2422                                            }
2423                                            else {
2424                                                    query.append(ORDER_BY_DESC);
2425                                            }
2426                                    }
2427                            }
2428                    }
2429    
2430                    else {
2431                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2432                    }
2433    
2434                    String sql = query.toString();
2435    
2436                    Query q = session.createQuery(sql);
2437    
2438                    q.setFirstResult(0);
2439                    q.setMaxResults(2);
2440    
2441                    QueryPos qPos = QueryPos.getInstance(q);
2442    
2443                    qPos.add(classNameId);
2444    
2445                    if (orderByComparator != null) {
2446                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
2447    
2448                            for (Object value : values) {
2449                                    qPos.add(value);
2450                            }
2451                    }
2452    
2453                    List<SocialActivity> list = q.list();
2454    
2455                    if (list.size() == 2) {
2456                            return list.get(1);
2457                    }
2458                    else {
2459                            return null;
2460                    }
2461            }
2462    
2463            /**
2464             * Returns all the social activities where receiverUserId = &#63;.
2465             *
2466             * @param receiverUserId the receiver user ID
2467             * @return the matching social activities
2468             * @throws SystemException if a system exception occurred
2469             */
2470            public List<SocialActivity> findByReceiverUserId(long receiverUserId)
2471                    throws SystemException {
2472                    return findByReceiverUserId(receiverUserId, QueryUtil.ALL_POS,
2473                            QueryUtil.ALL_POS, null);
2474            }
2475    
2476            /**
2477             * Returns a range of all the social activities where receiverUserId = &#63;.
2478             *
2479             * <p>
2480             * 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.
2481             * </p>
2482             *
2483             * @param receiverUserId the receiver user ID
2484             * @param start the lower bound of the range of social activities
2485             * @param end the upper bound of the range of social activities (not inclusive)
2486             * @return the range of matching social activities
2487             * @throws SystemException if a system exception occurred
2488             */
2489            public List<SocialActivity> findByReceiverUserId(long receiverUserId,
2490                    int start, int end) throws SystemException {
2491                    return findByReceiverUserId(receiverUserId, start, end, null);
2492            }
2493    
2494            /**
2495             * Returns an ordered range of all the social activities where receiverUserId = &#63;.
2496             *
2497             * <p>
2498             * 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.
2499             * </p>
2500             *
2501             * @param receiverUserId the receiver user ID
2502             * @param start the lower bound of the range of social activities
2503             * @param end the upper bound of the range of social activities (not inclusive)
2504             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2505             * @return the ordered range of matching social activities
2506             * @throws SystemException if a system exception occurred
2507             */
2508            public List<SocialActivity> findByReceiverUserId(long receiverUserId,
2509                    int start, int end, OrderByComparator orderByComparator)
2510                    throws SystemException {
2511                    FinderPath finderPath = null;
2512                    Object[] finderArgs = null;
2513    
2514                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2515                                    (orderByComparator == null)) {
2516                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID;
2517                            finderArgs = new Object[] { receiverUserId };
2518                    }
2519                    else {
2520                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RECEIVERUSERID;
2521                            finderArgs = new Object[] {
2522                                            receiverUserId,
2523                                            
2524                                            start, end, orderByComparator
2525                                    };
2526                    }
2527    
2528                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
2529                                    finderArgs, this);
2530    
2531                    if (list == null) {
2532                            StringBundler query = null;
2533    
2534                            if (orderByComparator != null) {
2535                                    query = new StringBundler(3 +
2536                                                    (orderByComparator.getOrderByFields().length * 3));
2537                            }
2538                            else {
2539                                    query = new StringBundler(3);
2540                            }
2541    
2542                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2543    
2544                            query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2545    
2546                            if (orderByComparator != null) {
2547                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2548                                            orderByComparator);
2549                            }
2550    
2551                            else {
2552                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2553                            }
2554    
2555                            String sql = query.toString();
2556    
2557                            Session session = null;
2558    
2559                            try {
2560                                    session = openSession();
2561    
2562                                    Query q = session.createQuery(sql);
2563    
2564                                    QueryPos qPos = QueryPos.getInstance(q);
2565    
2566                                    qPos.add(receiverUserId);
2567    
2568                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
2569                                                    start, end);
2570                            }
2571                            catch (Exception e) {
2572                                    throw processException(e);
2573                            }
2574                            finally {
2575                                    if (list == null) {
2576                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2577                                    }
2578                                    else {
2579                                            cacheResult(list);
2580    
2581                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2582                                    }
2583    
2584                                    closeSession(session);
2585                            }
2586                    }
2587    
2588                    return list;
2589            }
2590    
2591            /**
2592             * Returns the first social activity in the ordered set where receiverUserId = &#63;.
2593             *
2594             * <p>
2595             * 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.
2596             * </p>
2597             *
2598             * @param receiverUserId the receiver user ID
2599             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2600             * @return the first matching social activity
2601             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2602             * @throws SystemException if a system exception occurred
2603             */
2604            public SocialActivity findByReceiverUserId_First(long receiverUserId,
2605                    OrderByComparator orderByComparator)
2606                    throws NoSuchActivityException, SystemException {
2607                    List<SocialActivity> list = findByReceiverUserId(receiverUserId, 0, 1,
2608                                    orderByComparator);
2609    
2610                    if (list.isEmpty()) {
2611                            StringBundler msg = new StringBundler(4);
2612    
2613                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2614    
2615                            msg.append("receiverUserId=");
2616                            msg.append(receiverUserId);
2617    
2618                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2619    
2620                            throw new NoSuchActivityException(msg.toString());
2621                    }
2622                    else {
2623                            return list.get(0);
2624                    }
2625            }
2626    
2627            /**
2628             * Returns the last social activity in the ordered set where receiverUserId = &#63;.
2629             *
2630             * <p>
2631             * 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.
2632             * </p>
2633             *
2634             * @param receiverUserId the receiver user ID
2635             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2636             * @return the last matching social activity
2637             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2638             * @throws SystemException if a system exception occurred
2639             */
2640            public SocialActivity findByReceiverUserId_Last(long receiverUserId,
2641                    OrderByComparator orderByComparator)
2642                    throws NoSuchActivityException, SystemException {
2643                    int count = countByReceiverUserId(receiverUserId);
2644    
2645                    List<SocialActivity> list = findByReceiverUserId(receiverUserId,
2646                                    count - 1, count, orderByComparator);
2647    
2648                    if (list.isEmpty()) {
2649                            StringBundler msg = new StringBundler(4);
2650    
2651                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2652    
2653                            msg.append("receiverUserId=");
2654                            msg.append(receiverUserId);
2655    
2656                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2657    
2658                            throw new NoSuchActivityException(msg.toString());
2659                    }
2660                    else {
2661                            return list.get(0);
2662                    }
2663            }
2664    
2665            /**
2666             * Returns the social activities before and after the current social activity in the ordered set where receiverUserId = &#63;.
2667             *
2668             * <p>
2669             * 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.
2670             * </p>
2671             *
2672             * @param activityId the primary key of the current social activity
2673             * @param receiverUserId the receiver user ID
2674             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2675             * @return the previous, current, and next social activity
2676             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
2677             * @throws SystemException if a system exception occurred
2678             */
2679            public SocialActivity[] findByReceiverUserId_PrevAndNext(long activityId,
2680                    long receiverUserId, OrderByComparator orderByComparator)
2681                    throws NoSuchActivityException, SystemException {
2682                    SocialActivity socialActivity = findByPrimaryKey(activityId);
2683    
2684                    Session session = null;
2685    
2686                    try {
2687                            session = openSession();
2688    
2689                            SocialActivity[] array = new SocialActivityImpl[3];
2690    
2691                            array[0] = getByReceiverUserId_PrevAndNext(session, socialActivity,
2692                                            receiverUserId, orderByComparator, true);
2693    
2694                            array[1] = socialActivity;
2695    
2696                            array[2] = getByReceiverUserId_PrevAndNext(session, socialActivity,
2697                                            receiverUserId, orderByComparator, false);
2698    
2699                            return array;
2700                    }
2701                    catch (Exception e) {
2702                            throw processException(e);
2703                    }
2704                    finally {
2705                            closeSession(session);
2706                    }
2707            }
2708    
2709            protected SocialActivity getByReceiverUserId_PrevAndNext(Session session,
2710                    SocialActivity socialActivity, long receiverUserId,
2711                    OrderByComparator orderByComparator, boolean previous) {
2712                    StringBundler query = null;
2713    
2714                    if (orderByComparator != null) {
2715                            query = new StringBundler(6 +
2716                                            (orderByComparator.getOrderByFields().length * 6));
2717                    }
2718                    else {
2719                            query = new StringBundler(3);
2720                    }
2721    
2722                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2723    
2724                    query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2725    
2726                    if (orderByComparator != null) {
2727                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2728    
2729                            if (orderByConditionFields.length > 0) {
2730                                    query.append(WHERE_AND);
2731                            }
2732    
2733                            for (int i = 0; i < orderByConditionFields.length; i++) {
2734                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2735                                    query.append(orderByConditionFields[i]);
2736    
2737                                    if ((i + 1) < orderByConditionFields.length) {
2738                                            if (orderByComparator.isAscending() ^ previous) {
2739                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2740                                            }
2741                                            else {
2742                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2743                                            }
2744                                    }
2745                                    else {
2746                                            if (orderByComparator.isAscending() ^ previous) {
2747                                                    query.append(WHERE_GREATER_THAN);
2748                                            }
2749                                            else {
2750                                                    query.append(WHERE_LESSER_THAN);
2751                                            }
2752                                    }
2753                            }
2754    
2755                            query.append(ORDER_BY_CLAUSE);
2756    
2757                            String[] orderByFields = orderByComparator.getOrderByFields();
2758    
2759                            for (int i = 0; i < orderByFields.length; i++) {
2760                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2761                                    query.append(orderByFields[i]);
2762    
2763                                    if ((i + 1) < orderByFields.length) {
2764                                            if (orderByComparator.isAscending() ^ previous) {
2765                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2766                                            }
2767                                            else {
2768                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2769                                            }
2770                                    }
2771                                    else {
2772                                            if (orderByComparator.isAscending() ^ previous) {
2773                                                    query.append(ORDER_BY_ASC);
2774                                            }
2775                                            else {
2776                                                    query.append(ORDER_BY_DESC);
2777                                            }
2778                                    }
2779                            }
2780                    }
2781    
2782                    else {
2783                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2784                    }
2785    
2786                    String sql = query.toString();
2787    
2788                    Query q = session.createQuery(sql);
2789    
2790                    q.setFirstResult(0);
2791                    q.setMaxResults(2);
2792    
2793                    QueryPos qPos = QueryPos.getInstance(q);
2794    
2795                    qPos.add(receiverUserId);
2796    
2797                    if (orderByComparator != null) {
2798                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
2799    
2800                            for (Object value : values) {
2801                                    qPos.add(value);
2802                            }
2803                    }
2804    
2805                    List<SocialActivity> list = q.list();
2806    
2807                    if (list.size() == 2) {
2808                            return list.get(1);
2809                    }
2810                    else {
2811                            return null;
2812                    }
2813            }
2814    
2815            /**
2816             * Returns all the social activities where classNameId = &#63; and classPK = &#63;.
2817             *
2818             * @param classNameId the class name ID
2819             * @param classPK the class p k
2820             * @return the matching social activities
2821             * @throws SystemException if a system exception occurred
2822             */
2823            public List<SocialActivity> findByC_C(long classNameId, long classPK)
2824                    throws SystemException {
2825                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
2826                            QueryUtil.ALL_POS, null);
2827            }
2828    
2829            /**
2830             * Returns a range of all the social activities where classNameId = &#63; and classPK = &#63;.
2831             *
2832             * <p>
2833             * 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.
2834             * </p>
2835             *
2836             * @param classNameId the class name ID
2837             * @param classPK the class p k
2838             * @param start the lower bound of the range of social activities
2839             * @param end the upper bound of the range of social activities (not inclusive)
2840             * @return the range of matching social activities
2841             * @throws SystemException if a system exception occurred
2842             */
2843            public List<SocialActivity> findByC_C(long classNameId, long classPK,
2844                    int start, int end) throws SystemException {
2845                    return findByC_C(classNameId, classPK, start, end, null);
2846            }
2847    
2848            /**
2849             * Returns an ordered range of all the social activities where classNameId = &#63; and classPK = &#63;.
2850             *
2851             * <p>
2852             * 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.
2853             * </p>
2854             *
2855             * @param classNameId the class name ID
2856             * @param classPK the class p k
2857             * @param start the lower bound of the range of social activities
2858             * @param end the upper bound of the range of social activities (not inclusive)
2859             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2860             * @return the ordered range of matching social activities
2861             * @throws SystemException if a system exception occurred
2862             */
2863            public List<SocialActivity> findByC_C(long classNameId, long classPK,
2864                    int start, int end, OrderByComparator orderByComparator)
2865                    throws SystemException {
2866                    FinderPath finderPath = null;
2867                    Object[] finderArgs = null;
2868    
2869                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2870                                    (orderByComparator == null)) {
2871                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
2872                            finderArgs = new Object[] { classNameId, classPK };
2873                    }
2874                    else {
2875                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
2876                            finderArgs = new Object[] {
2877                                            classNameId, classPK,
2878                                            
2879                                            start, end, orderByComparator
2880                                    };
2881                    }
2882    
2883                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
2884                                    finderArgs, this);
2885    
2886                    if (list == null) {
2887                            StringBundler query = null;
2888    
2889                            if (orderByComparator != null) {
2890                                    query = new StringBundler(4 +
2891                                                    (orderByComparator.getOrderByFields().length * 3));
2892                            }
2893                            else {
2894                                    query = new StringBundler(4);
2895                            }
2896    
2897                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2898    
2899                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2900    
2901                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2902    
2903                            if (orderByComparator != null) {
2904                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2905                                            orderByComparator);
2906                            }
2907    
2908                            else {
2909                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2910                            }
2911    
2912                            String sql = query.toString();
2913    
2914                            Session session = null;
2915    
2916                            try {
2917                                    session = openSession();
2918    
2919                                    Query q = session.createQuery(sql);
2920    
2921                                    QueryPos qPos = QueryPos.getInstance(q);
2922    
2923                                    qPos.add(classNameId);
2924    
2925                                    qPos.add(classPK);
2926    
2927                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
2928                                                    start, end);
2929                            }
2930                            catch (Exception e) {
2931                                    throw processException(e);
2932                            }
2933                            finally {
2934                                    if (list == null) {
2935                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2936                                    }
2937                                    else {
2938                                            cacheResult(list);
2939    
2940                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2941                                    }
2942    
2943                                    closeSession(session);
2944                            }
2945                    }
2946    
2947                    return list;
2948            }
2949    
2950            /**
2951             * Returns the first social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
2952             *
2953             * <p>
2954             * 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.
2955             * </p>
2956             *
2957             * @param classNameId the class name ID
2958             * @param classPK the class p k
2959             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2960             * @return the first matching social activity
2961             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2962             * @throws SystemException if a system exception occurred
2963             */
2964            public SocialActivity findByC_C_First(long classNameId, long classPK,
2965                    OrderByComparator orderByComparator)
2966                    throws NoSuchActivityException, SystemException {
2967                    List<SocialActivity> list = findByC_C(classNameId, classPK, 0, 1,
2968                                    orderByComparator);
2969    
2970                    if (list.isEmpty()) {
2971                            StringBundler msg = new StringBundler(6);
2972    
2973                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2974    
2975                            msg.append("classNameId=");
2976                            msg.append(classNameId);
2977    
2978                            msg.append(", classPK=");
2979                            msg.append(classPK);
2980    
2981                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2982    
2983                            throw new NoSuchActivityException(msg.toString());
2984                    }
2985                    else {
2986                            return list.get(0);
2987                    }
2988            }
2989    
2990            /**
2991             * Returns the last social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
2992             *
2993             * <p>
2994             * 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.
2995             * </p>
2996             *
2997             * @param classNameId the class name ID
2998             * @param classPK the class p k
2999             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3000             * @return the last matching social activity
3001             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
3002             * @throws SystemException if a system exception occurred
3003             */
3004            public SocialActivity findByC_C_Last(long classNameId, long classPK,
3005                    OrderByComparator orderByComparator)
3006                    throws NoSuchActivityException, SystemException {
3007                    int count = countByC_C(classNameId, classPK);
3008    
3009                    List<SocialActivity> list = findByC_C(classNameId, classPK, count - 1,
3010                                    count, orderByComparator);
3011    
3012                    if (list.isEmpty()) {
3013                            StringBundler msg = new StringBundler(6);
3014    
3015                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3016    
3017                            msg.append("classNameId=");
3018                            msg.append(classNameId);
3019    
3020                            msg.append(", classPK=");
3021                            msg.append(classPK);
3022    
3023                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3024    
3025                            throw new NoSuchActivityException(msg.toString());
3026                    }
3027                    else {
3028                            return list.get(0);
3029                    }
3030            }
3031    
3032            /**
3033             * Returns the social activities before and after the current social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
3034             *
3035             * <p>
3036             * 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.
3037             * </p>
3038             *
3039             * @param activityId the primary key of the current social activity
3040             * @param classNameId the class name ID
3041             * @param classPK the class p k
3042             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3043             * @return the previous, current, and next social activity
3044             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
3045             * @throws SystemException if a system exception occurred
3046             */
3047            public SocialActivity[] findByC_C_PrevAndNext(long activityId,
3048                    long classNameId, long classPK, OrderByComparator orderByComparator)
3049                    throws NoSuchActivityException, SystemException {
3050                    SocialActivity socialActivity = findByPrimaryKey(activityId);
3051    
3052                    Session session = null;
3053    
3054                    try {
3055                            session = openSession();
3056    
3057                            SocialActivity[] array = new SocialActivityImpl[3];
3058    
3059                            array[0] = getByC_C_PrevAndNext(session, socialActivity,
3060                                            classNameId, classPK, orderByComparator, true);
3061    
3062                            array[1] = socialActivity;
3063    
3064                            array[2] = getByC_C_PrevAndNext(session, socialActivity,
3065                                            classNameId, classPK, orderByComparator, false);
3066    
3067                            return array;
3068                    }
3069                    catch (Exception e) {
3070                            throw processException(e);
3071                    }
3072                    finally {
3073                            closeSession(session);
3074                    }
3075            }
3076    
3077            protected SocialActivity getByC_C_PrevAndNext(Session session,
3078                    SocialActivity socialActivity, long classNameId, long classPK,
3079                    OrderByComparator orderByComparator, boolean previous) {
3080                    StringBundler query = null;
3081    
3082                    if (orderByComparator != null) {
3083                            query = new StringBundler(6 +
3084                                            (orderByComparator.getOrderByFields().length * 6));
3085                    }
3086                    else {
3087                            query = new StringBundler(3);
3088                    }
3089    
3090                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3091    
3092                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3093    
3094                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3095    
3096                    if (orderByComparator != null) {
3097                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3098    
3099                            if (orderByConditionFields.length > 0) {
3100                                    query.append(WHERE_AND);
3101                            }
3102    
3103                            for (int i = 0; i < orderByConditionFields.length; i++) {
3104                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3105                                    query.append(orderByConditionFields[i]);
3106    
3107                                    if ((i + 1) < orderByConditionFields.length) {
3108                                            if (orderByComparator.isAscending() ^ previous) {
3109                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3110                                            }
3111                                            else {
3112                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3113                                            }
3114                                    }
3115                                    else {
3116                                            if (orderByComparator.isAscending() ^ previous) {
3117                                                    query.append(WHERE_GREATER_THAN);
3118                                            }
3119                                            else {
3120                                                    query.append(WHERE_LESSER_THAN);
3121                                            }
3122                                    }
3123                            }
3124    
3125                            query.append(ORDER_BY_CLAUSE);
3126    
3127                            String[] orderByFields = orderByComparator.getOrderByFields();
3128    
3129                            for (int i = 0; i < orderByFields.length; i++) {
3130                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3131                                    query.append(orderByFields[i]);
3132    
3133                                    if ((i + 1) < orderByFields.length) {
3134                                            if (orderByComparator.isAscending() ^ previous) {
3135                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3136                                            }
3137                                            else {
3138                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3139                                            }
3140                                    }
3141                                    else {
3142                                            if (orderByComparator.isAscending() ^ previous) {
3143                                                    query.append(ORDER_BY_ASC);
3144                                            }
3145                                            else {
3146                                                    query.append(ORDER_BY_DESC);
3147                                            }
3148                                    }
3149                            }
3150                    }
3151    
3152                    else {
3153                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
3154                    }
3155    
3156                    String sql = query.toString();
3157    
3158                    Query q = session.createQuery(sql);
3159    
3160                    q.setFirstResult(0);
3161                    q.setMaxResults(2);
3162    
3163                    QueryPos qPos = QueryPos.getInstance(q);
3164    
3165                    qPos.add(classNameId);
3166    
3167                    qPos.add(classPK);
3168    
3169                    if (orderByComparator != null) {
3170                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
3171    
3172                            for (Object value : values) {
3173                                    qPos.add(value);
3174                            }
3175                    }
3176    
3177                    List<SocialActivity> list = q.list();
3178    
3179                    if (list.size() == 2) {
3180                            return list.get(1);
3181                    }
3182                    else {
3183                            return null;
3184                    }
3185            }
3186    
3187            /**
3188             * Returns all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3189             *
3190             * @param mirrorActivityId the mirror activity ID
3191             * @param classNameId the class name ID
3192             * @param classPK the class p k
3193             * @return the matching social activities
3194             * @throws SystemException if a system exception occurred
3195             */
3196            public List<SocialActivity> findByM_C_C(long mirrorActivityId,
3197                    long classNameId, long classPK) throws SystemException {
3198                    return findByM_C_C(mirrorActivityId, classNameId, classPK,
3199                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3200            }
3201    
3202            /**
3203             * Returns a range of all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3204             *
3205             * <p>
3206             * 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.
3207             * </p>
3208             *
3209             * @param mirrorActivityId the mirror activity ID
3210             * @param classNameId the class name ID
3211             * @param classPK the class p k
3212             * @param start the lower bound of the range of social activities
3213             * @param end the upper bound of the range of social activities (not inclusive)
3214             * @return the range of matching social activities
3215             * @throws SystemException if a system exception occurred
3216             */
3217            public List<SocialActivity> findByM_C_C(long mirrorActivityId,
3218                    long classNameId, long classPK, int start, int end)
3219                    throws SystemException {
3220                    return findByM_C_C(mirrorActivityId, classNameId, classPK, start, end,
3221                            null);
3222            }
3223    
3224            /**
3225             * Returns an ordered range of all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3226             *
3227             * <p>
3228             * 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.
3229             * </p>
3230             *
3231             * @param mirrorActivityId the mirror activity ID
3232             * @param classNameId the class name ID
3233             * @param classPK the class p k
3234             * @param start the lower bound of the range of social activities
3235             * @param end the upper bound of the range of social activities (not inclusive)
3236             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3237             * @return the ordered range of matching social activities
3238             * @throws SystemException if a system exception occurred
3239             */
3240            public List<SocialActivity> findByM_C_C(long mirrorActivityId,
3241                    long classNameId, long classPK, int start, int end,
3242                    OrderByComparator orderByComparator) throws SystemException {
3243                    FinderPath finderPath = null;
3244                    Object[] finderArgs = null;
3245    
3246                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3247                                    (orderByComparator == null)) {
3248                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_M_C_C;
3249                            finderArgs = new Object[] { mirrorActivityId, classNameId, classPK };
3250                    }
3251                    else {
3252                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_M_C_C;
3253                            finderArgs = new Object[] {
3254                                            mirrorActivityId, classNameId, classPK,
3255                                            
3256                                            start, end, orderByComparator
3257                                    };
3258                    }
3259    
3260                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
3261                                    finderArgs, this);
3262    
3263                    if (list == null) {
3264                            StringBundler query = null;
3265    
3266                            if (orderByComparator != null) {
3267                                    query = new StringBundler(5 +
3268                                                    (orderByComparator.getOrderByFields().length * 3));
3269                            }
3270                            else {
3271                                    query = new StringBundler(5);
3272                            }
3273    
3274                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3275    
3276                            query.append(_FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2);
3277    
3278                            query.append(_FINDER_COLUMN_M_C_C_CLASSNAMEID_2);
3279    
3280                            query.append(_FINDER_COLUMN_M_C_C_CLASSPK_2);
3281    
3282                            if (orderByComparator != null) {
3283                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3284                                            orderByComparator);
3285                            }
3286    
3287                            else {
3288                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
3289                            }
3290    
3291                            String sql = query.toString();
3292    
3293                            Session session = null;
3294    
3295                            try {
3296                                    session = openSession();
3297    
3298                                    Query q = session.createQuery(sql);
3299    
3300                                    QueryPos qPos = QueryPos.getInstance(q);
3301    
3302                                    qPos.add(mirrorActivityId);
3303    
3304                                    qPos.add(classNameId);
3305    
3306                                    qPos.add(classPK);
3307    
3308                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
3309                                                    start, end);
3310                            }
3311                            catch (Exception e) {
3312                                    throw processException(e);
3313                            }
3314                            finally {
3315                                    if (list == null) {
3316                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3317                                    }
3318                                    else {
3319                                            cacheResult(list);
3320    
3321                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3322                                    }
3323    
3324                                    closeSession(session);
3325                            }
3326                    }
3327    
3328                    return list;
3329            }
3330    
3331            /**
3332             * Returns the first social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3333             *
3334             * <p>
3335             * 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.
3336             * </p>
3337             *
3338             * @param mirrorActivityId the mirror activity ID
3339             * @param classNameId the class name ID
3340             * @param classPK the class p k
3341             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3342             * @return the first matching social activity
3343             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
3344             * @throws SystemException if a system exception occurred
3345             */
3346            public SocialActivity findByM_C_C_First(long mirrorActivityId,
3347                    long classNameId, long classPK, OrderByComparator orderByComparator)
3348                    throws NoSuchActivityException, SystemException {
3349                    List<SocialActivity> list = findByM_C_C(mirrorActivityId, classNameId,
3350                                    classPK, 0, 1, orderByComparator);
3351    
3352                    if (list.isEmpty()) {
3353                            StringBundler msg = new StringBundler(8);
3354    
3355                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3356    
3357                            msg.append("mirrorActivityId=");
3358                            msg.append(mirrorActivityId);
3359    
3360                            msg.append(", classNameId=");
3361                            msg.append(classNameId);
3362    
3363                            msg.append(", classPK=");
3364                            msg.append(classPK);
3365    
3366                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3367    
3368                            throw new NoSuchActivityException(msg.toString());
3369                    }
3370                    else {
3371                            return list.get(0);
3372                    }
3373            }
3374    
3375            /**
3376             * Returns the last social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3377             *
3378             * <p>
3379             * 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.
3380             * </p>
3381             *
3382             * @param mirrorActivityId the mirror activity ID
3383             * @param classNameId the class name ID
3384             * @param classPK the class p k
3385             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3386             * @return the last matching social activity
3387             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
3388             * @throws SystemException if a system exception occurred
3389             */
3390            public SocialActivity findByM_C_C_Last(long mirrorActivityId,
3391                    long classNameId, long classPK, OrderByComparator orderByComparator)
3392                    throws NoSuchActivityException, SystemException {
3393                    int count = countByM_C_C(mirrorActivityId, classNameId, classPK);
3394    
3395                    List<SocialActivity> list = findByM_C_C(mirrorActivityId, classNameId,
3396                                    classPK, count - 1, count, orderByComparator);
3397    
3398                    if (list.isEmpty()) {
3399                            StringBundler msg = new StringBundler(8);
3400    
3401                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3402    
3403                            msg.append("mirrorActivityId=");
3404                            msg.append(mirrorActivityId);
3405    
3406                            msg.append(", classNameId=");
3407                            msg.append(classNameId);
3408    
3409                            msg.append(", classPK=");
3410                            msg.append(classPK);
3411    
3412                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3413    
3414                            throw new NoSuchActivityException(msg.toString());
3415                    }
3416                    else {
3417                            return list.get(0);
3418                    }
3419            }
3420    
3421            /**
3422             * Returns the social activities before and after the current social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3423             *
3424             * <p>
3425             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3426             * </p>
3427             *
3428             * @param activityId the primary key of the current social activity
3429             * @param mirrorActivityId the mirror activity ID
3430             * @param classNameId the class name ID
3431             * @param classPK the class p k
3432             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3433             * @return the previous, current, and next social activity
3434             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
3435             * @throws SystemException if a system exception occurred
3436             */
3437            public SocialActivity[] findByM_C_C_PrevAndNext(long activityId,
3438                    long mirrorActivityId, long classNameId, long classPK,
3439                    OrderByComparator orderByComparator)
3440                    throws NoSuchActivityException, SystemException {
3441                    SocialActivity socialActivity = findByPrimaryKey(activityId);
3442    
3443                    Session session = null;
3444    
3445                    try {
3446                            session = openSession();
3447    
3448                            SocialActivity[] array = new SocialActivityImpl[3];
3449    
3450                            array[0] = getByM_C_C_PrevAndNext(session, socialActivity,
3451                                            mirrorActivityId, classNameId, classPK, orderByComparator,
3452                                            true);
3453    
3454                            array[1] = socialActivity;
3455    
3456                            array[2] = getByM_C_C_PrevAndNext(session, socialActivity,
3457                                            mirrorActivityId, classNameId, classPK, orderByComparator,
3458                                            false);
3459    
3460                            return array;
3461                    }
3462                    catch (Exception e) {
3463                            throw processException(e);
3464                    }
3465                    finally {
3466                            closeSession(session);
3467                    }
3468            }
3469    
3470            protected SocialActivity getByM_C_C_PrevAndNext(Session session,
3471                    SocialActivity socialActivity, long mirrorActivityId, long classNameId,
3472                    long classPK, OrderByComparator orderByComparator, boolean previous) {
3473                    StringBundler query = null;
3474    
3475                    if (orderByComparator != null) {
3476                            query = new StringBundler(6 +
3477                                            (orderByComparator.getOrderByFields().length * 6));
3478                    }
3479                    else {
3480                            query = new StringBundler(3);
3481                    }
3482    
3483                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3484    
3485                    query.append(_FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2);
3486    
3487                    query.append(_FINDER_COLUMN_M_C_C_CLASSNAMEID_2);
3488    
3489                    query.append(_FINDER_COLUMN_M_C_C_CLASSPK_2);
3490    
3491                    if (orderByComparator != null) {
3492                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3493    
3494                            if (orderByConditionFields.length > 0) {
3495                                    query.append(WHERE_AND);
3496                            }
3497    
3498                            for (int i = 0; i < orderByConditionFields.length; i++) {
3499                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3500                                    query.append(orderByConditionFields[i]);
3501    
3502                                    if ((i + 1) < orderByConditionFields.length) {
3503                                            if (orderByComparator.isAscending() ^ previous) {
3504                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3505                                            }
3506                                            else {
3507                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3508                                            }
3509                                    }
3510                                    else {
3511                                            if (orderByComparator.isAscending() ^ previous) {
3512                                                    query.append(WHERE_GREATER_THAN);
3513                                            }
3514                                            else {
3515                                                    query.append(WHERE_LESSER_THAN);
3516                                            }
3517                                    }
3518                            }
3519    
3520                            query.append(ORDER_BY_CLAUSE);
3521    
3522                            String[] orderByFields = orderByComparator.getOrderByFields();
3523    
3524                            for (int i = 0; i < orderByFields.length; i++) {
3525                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3526                                    query.append(orderByFields[i]);
3527    
3528                                    if ((i + 1) < orderByFields.length) {
3529                                            if (orderByComparator.isAscending() ^ previous) {
3530                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3531                                            }
3532                                            else {
3533                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3534                                            }
3535                                    }
3536                                    else {
3537                                            if (orderByComparator.isAscending() ^ previous) {
3538                                                    query.append(ORDER_BY_ASC);
3539                                            }
3540                                            else {
3541                                                    query.append(ORDER_BY_DESC);
3542                                            }
3543                                    }
3544                            }
3545                    }
3546    
3547                    else {
3548                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
3549                    }
3550    
3551                    String sql = query.toString();
3552    
3553                    Query q = session.createQuery(sql);
3554    
3555                    q.setFirstResult(0);
3556                    q.setMaxResults(2);
3557    
3558                    QueryPos qPos = QueryPos.getInstance(q);
3559    
3560                    qPos.add(mirrorActivityId);
3561    
3562                    qPos.add(classNameId);
3563    
3564                    qPos.add(classPK);
3565    
3566                    if (orderByComparator != null) {
3567                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
3568    
3569                            for (Object value : values) {
3570                                    qPos.add(value);
3571                            }
3572                    }
3573    
3574                    List<SocialActivity> list = q.list();
3575    
3576                    if (list.size() == 2) {
3577                            return list.get(1);
3578                    }
3579                    else {
3580                            return null;
3581                    }
3582            }
3583    
3584            /**
3585             * Returns all the social activities where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
3586             *
3587             * @param groupId the group ID
3588             * @param userId the user ID
3589             * @param classNameId the class name ID
3590             * @param classPK the class p k
3591             * @param type the type
3592             * @param receiverUserId the receiver user ID
3593             * @return the matching social activities
3594             * @throws SystemException if a system exception occurred
3595             */
3596            public List<SocialActivity> findByG_U_C_C_T_R(long groupId, long userId,
3597                    long classNameId, long classPK, int type, long receiverUserId)
3598                    throws SystemException {
3599                    return findByG_U_C_C_T_R(groupId, userId, classNameId, classPK, type,
3600                            receiverUserId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3601            }
3602    
3603            /**
3604             * 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;.
3605             *
3606             * <p>
3607             * 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.
3608             * </p>
3609             *
3610             * @param groupId the group ID
3611             * @param userId the user ID
3612             * @param classNameId the class name ID
3613             * @param classPK the class p k
3614             * @param type the type
3615             * @param receiverUserId the receiver user ID
3616             * @param start the lower bound of the range of social activities
3617             * @param end the upper bound of the range of social activities (not inclusive)
3618             * @return the range of matching social activities
3619             * @throws SystemException if a system exception occurred
3620             */
3621            public List<SocialActivity> findByG_U_C_C_T_R(long groupId, long userId,
3622                    long classNameId, long classPK, int type, long receiverUserId,
3623                    int start, int end) throws SystemException {
3624                    return findByG_U_C_C_T_R(groupId, userId, classNameId, classPK, type,
3625                            receiverUserId, start, end, null);
3626            }
3627    
3628            /**
3629             * 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;.
3630             *
3631             * <p>
3632             * 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.
3633             * </p>
3634             *
3635             * @param groupId the group ID
3636             * @param userId the user ID
3637             * @param classNameId the class name ID
3638             * @param classPK the class p k
3639             * @param type the type
3640             * @param receiverUserId the receiver user ID
3641             * @param start the lower bound of the range of social activities
3642             * @param end the upper bound of the range of social activities (not inclusive)
3643             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3644             * @return the ordered range of matching social activities
3645             * @throws SystemException if a system exception occurred
3646             */
3647            public List<SocialActivity> findByG_U_C_C_T_R(long groupId, long userId,
3648                    long classNameId, long classPK, int type, long receiverUserId,
3649                    int start, int end, OrderByComparator orderByComparator)
3650                    throws SystemException {
3651                    FinderPath finderPath = null;
3652                    Object[] finderArgs = null;
3653    
3654                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3655                                    (orderByComparator == null)) {
3656                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_C_T_R;
3657                            finderArgs = new Object[] {
3658                                            groupId, userId, classNameId, classPK, type, receiverUserId
3659                                    };
3660                    }
3661                    else {
3662                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_C_T_R;
3663                            finderArgs = new Object[] {
3664                                            groupId, userId, classNameId, classPK, type, receiverUserId,
3665                                            
3666                                            start, end, orderByComparator
3667                                    };
3668                    }
3669    
3670                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
3671                                    finderArgs, this);
3672    
3673                    if (list == null) {
3674                            StringBundler query = null;
3675    
3676                            if (orderByComparator != null) {
3677                                    query = new StringBundler(8 +
3678                                                    (orderByComparator.getOrderByFields().length * 3));
3679                            }
3680                            else {
3681                                    query = new StringBundler(8);
3682                            }
3683    
3684                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3685    
3686                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_GROUPID_2);
3687    
3688                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_USERID_2);
3689    
3690                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSNAMEID_2);
3691    
3692                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSPK_2);
3693    
3694                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_TYPE_2);
3695    
3696                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_RECEIVERUSERID_2);
3697    
3698                            if (orderByComparator != null) {
3699                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3700                                            orderByComparator);
3701                            }
3702    
3703                            else {
3704                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
3705                            }
3706    
3707                            String sql = query.toString();
3708    
3709                            Session session = null;
3710    
3711                            try {
3712                                    session = openSession();
3713    
3714                                    Query q = session.createQuery(sql);
3715    
3716                                    QueryPos qPos = QueryPos.getInstance(q);
3717    
3718                                    qPos.add(groupId);
3719    
3720                                    qPos.add(userId);
3721    
3722                                    qPos.add(classNameId);
3723    
3724                                    qPos.add(classPK);
3725    
3726                                    qPos.add(type);
3727    
3728                                    qPos.add(receiverUserId);
3729    
3730                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
3731                                                    start, end);
3732                            }
3733                            catch (Exception e) {
3734                                    throw processException(e);
3735                            }
3736                            finally {
3737                                    if (list == null) {
3738                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3739                                    }
3740                                    else {
3741                                            cacheResult(list);
3742    
3743                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3744                                    }
3745    
3746                                    closeSession(session);
3747                            }
3748                    }
3749    
3750                    return list;
3751            }
3752    
3753            /**
3754             * 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;.
3755             *
3756             * <p>
3757             * 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.
3758             * </p>
3759             *
3760             * @param groupId the group ID
3761             * @param userId the user ID
3762             * @param classNameId the class name ID
3763             * @param classPK the class p k
3764             * @param type the type
3765             * @param receiverUserId the receiver user ID
3766             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3767             * @return the first matching social activity
3768             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
3769             * @throws SystemException if a system exception occurred
3770             */
3771            public SocialActivity findByG_U_C_C_T_R_First(long groupId, long userId,
3772                    long classNameId, long classPK, int type, long receiverUserId,
3773                    OrderByComparator orderByComparator)
3774                    throws NoSuchActivityException, SystemException {
3775                    List<SocialActivity> list = findByG_U_C_C_T_R(groupId, userId,
3776                                    classNameId, classPK, type, receiverUserId, 0, 1,
3777                                    orderByComparator);
3778    
3779                    if (list.isEmpty()) {
3780                            StringBundler msg = new StringBundler(14);
3781    
3782                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3783    
3784                            msg.append("groupId=");
3785                            msg.append(groupId);
3786    
3787                            msg.append(", userId=");
3788                            msg.append(userId);
3789    
3790                            msg.append(", classNameId=");
3791                            msg.append(classNameId);
3792    
3793                            msg.append(", classPK=");
3794                            msg.append(classPK);
3795    
3796                            msg.append(", type=");
3797                            msg.append(type);
3798    
3799                            msg.append(", receiverUserId=");
3800                            msg.append(receiverUserId);
3801    
3802                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3803    
3804                            throw new NoSuchActivityException(msg.toString());
3805                    }
3806                    else {
3807                            return list.get(0);
3808                    }
3809            }
3810    
3811            /**
3812             * 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;.
3813             *
3814             * <p>
3815             * 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.
3816             * </p>
3817             *
3818             * @param groupId the group ID
3819             * @param userId the user ID
3820             * @param classNameId the class name ID
3821             * @param classPK the class p k
3822             * @param type the type
3823             * @param receiverUserId the receiver user ID
3824             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3825             * @return the last matching social activity
3826             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
3827             * @throws SystemException if a system exception occurred
3828             */
3829            public SocialActivity findByG_U_C_C_T_R_Last(long groupId, long userId,
3830                    long classNameId, long classPK, int type, long receiverUserId,
3831                    OrderByComparator orderByComparator)
3832                    throws NoSuchActivityException, SystemException {
3833                    int count = countByG_U_C_C_T_R(groupId, userId, classNameId, classPK,
3834                                    type, receiverUserId);
3835    
3836                    List<SocialActivity> list = findByG_U_C_C_T_R(groupId, userId,
3837                                    classNameId, classPK, type, receiverUserId, count - 1, count,
3838                                    orderByComparator);
3839    
3840                    if (list.isEmpty()) {
3841                            StringBundler msg = new StringBundler(14);
3842    
3843                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3844    
3845                            msg.append("groupId=");
3846                            msg.append(groupId);
3847    
3848                            msg.append(", userId=");
3849                            msg.append(userId);
3850    
3851                            msg.append(", classNameId=");
3852                            msg.append(classNameId);
3853    
3854                            msg.append(", classPK=");
3855                            msg.append(classPK);
3856    
3857                            msg.append(", type=");
3858                            msg.append(type);
3859    
3860                            msg.append(", receiverUserId=");
3861                            msg.append(receiverUserId);
3862    
3863                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3864    
3865                            throw new NoSuchActivityException(msg.toString());
3866                    }
3867                    else {
3868                            return list.get(0);
3869                    }
3870            }
3871    
3872            /**
3873             * 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;.
3874             *
3875             * <p>
3876             * 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.
3877             * </p>
3878             *
3879             * @param activityId the primary key of the current social activity
3880             * @param groupId the group ID
3881             * @param userId the user ID
3882             * @param classNameId the class name ID
3883             * @param classPK the class p k
3884             * @param type the type
3885             * @param receiverUserId the receiver user ID
3886             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3887             * @return the previous, current, and next social activity
3888             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
3889             * @throws SystemException if a system exception occurred
3890             */
3891            public SocialActivity[] findByG_U_C_C_T_R_PrevAndNext(long activityId,
3892                    long groupId, long userId, long classNameId, long classPK, int type,
3893                    long receiverUserId, OrderByComparator orderByComparator)
3894                    throws NoSuchActivityException, SystemException {
3895                    SocialActivity socialActivity = findByPrimaryKey(activityId);
3896    
3897                    Session session = null;
3898    
3899                    try {
3900                            session = openSession();
3901    
3902                            SocialActivity[] array = new SocialActivityImpl[3];
3903    
3904                            array[0] = getByG_U_C_C_T_R_PrevAndNext(session, socialActivity,
3905                                            groupId, userId, classNameId, classPK, type,
3906                                            receiverUserId, orderByComparator, true);
3907    
3908                            array[1] = socialActivity;
3909    
3910                            array[2] = getByG_U_C_C_T_R_PrevAndNext(session, socialActivity,
3911                                            groupId, userId, classNameId, classPK, type,
3912                                            receiverUserId, orderByComparator, false);
3913    
3914                            return array;
3915                    }
3916                    catch (Exception e) {
3917                            throw processException(e);
3918                    }
3919                    finally {
3920                            closeSession(session);
3921                    }
3922            }
3923    
3924            protected SocialActivity getByG_U_C_C_T_R_PrevAndNext(Session session,
3925                    SocialActivity socialActivity, long groupId, long userId,
3926                    long classNameId, long classPK, int type, long receiverUserId,
3927                    OrderByComparator orderByComparator, boolean previous) {
3928                    StringBundler query = null;
3929    
3930                    if (orderByComparator != null) {
3931                            query = new StringBundler(6 +
3932                                            (orderByComparator.getOrderByFields().length * 6));
3933                    }
3934                    else {
3935                            query = new StringBundler(3);
3936                    }
3937    
3938                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3939    
3940                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_GROUPID_2);
3941    
3942                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_USERID_2);
3943    
3944                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSNAMEID_2);
3945    
3946                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSPK_2);
3947    
3948                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_TYPE_2);
3949    
3950                    query.append(_FINDER_COLUMN_G_U_C_C_T_R_RECEIVERUSERID_2);
3951    
3952                    if (orderByComparator != null) {
3953                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3954    
3955                            if (orderByConditionFields.length > 0) {
3956                                    query.append(WHERE_AND);
3957                            }
3958    
3959                            for (int i = 0; i < orderByConditionFields.length; i++) {
3960                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3961                                    query.append(orderByConditionFields[i]);
3962    
3963                                    if ((i + 1) < orderByConditionFields.length) {
3964                                            if (orderByComparator.isAscending() ^ previous) {
3965                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3966                                            }
3967                                            else {
3968                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3969                                            }
3970                                    }
3971                                    else {
3972                                            if (orderByComparator.isAscending() ^ previous) {
3973                                                    query.append(WHERE_GREATER_THAN);
3974                                            }
3975                                            else {
3976                                                    query.append(WHERE_LESSER_THAN);
3977                                            }
3978                                    }
3979                            }
3980    
3981                            query.append(ORDER_BY_CLAUSE);
3982    
3983                            String[] orderByFields = orderByComparator.getOrderByFields();
3984    
3985                            for (int i = 0; i < orderByFields.length; i++) {
3986                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3987                                    query.append(orderByFields[i]);
3988    
3989                                    if ((i + 1) < orderByFields.length) {
3990                                            if (orderByComparator.isAscending() ^ previous) {
3991                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3992                                            }
3993                                            else {
3994                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3995                                            }
3996                                    }
3997                                    else {
3998                                            if (orderByComparator.isAscending() ^ previous) {
3999                                                    query.append(ORDER_BY_ASC);
4000                                            }
4001                                            else {
4002                                                    query.append(ORDER_BY_DESC);
4003                                            }
4004                                    }
4005                            }
4006                    }
4007    
4008                    else {
4009                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
4010                    }
4011    
4012                    String sql = query.toString();
4013    
4014                    Query q = session.createQuery(sql);
4015    
4016                    q.setFirstResult(0);
4017                    q.setMaxResults(2);
4018    
4019                    QueryPos qPos = QueryPos.getInstance(q);
4020    
4021                    qPos.add(groupId);
4022    
4023                    qPos.add(userId);
4024    
4025                    qPos.add(classNameId);
4026    
4027                    qPos.add(classPK);
4028    
4029                    qPos.add(type);
4030    
4031                    qPos.add(receiverUserId);
4032    
4033                    if (orderByComparator != null) {
4034                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivity);
4035    
4036                            for (Object value : values) {
4037                                    qPos.add(value);
4038                            }
4039                    }
4040    
4041                    List<SocialActivity> list = q.list();
4042    
4043                    if (list.size() == 2) {
4044                            return list.get(1);
4045                    }
4046                    else {
4047                            return null;
4048                    }
4049            }
4050    
4051            /**
4052             * 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.
4053             *
4054             * @param groupId the group ID
4055             * @param userId the user ID
4056             * @param createDate the create date
4057             * @param classNameId the class name ID
4058             * @param classPK the class p k
4059             * @param type the type
4060             * @param receiverUserId the receiver user ID
4061             * @return the matching social activity
4062             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
4063             * @throws SystemException if a system exception occurred
4064             */
4065            public SocialActivity findByG_U_CD_C_C_T_R(long groupId, long userId,
4066                    long createDate, long classNameId, long classPK, int type,
4067                    long receiverUserId) throws NoSuchActivityException, SystemException {
4068                    SocialActivity socialActivity = fetchByG_U_CD_C_C_T_R(groupId, userId,
4069                                    createDate, classNameId, classPK, type, receiverUserId);
4070    
4071                    if (socialActivity == null) {
4072                            StringBundler msg = new StringBundler(16);
4073    
4074                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4075    
4076                            msg.append("groupId=");
4077                            msg.append(groupId);
4078    
4079                            msg.append(", userId=");
4080                            msg.append(userId);
4081    
4082                            msg.append(", createDate=");
4083                            msg.append(createDate);
4084    
4085                            msg.append(", classNameId=");
4086                            msg.append(classNameId);
4087    
4088                            msg.append(", classPK=");
4089                            msg.append(classPK);
4090    
4091                            msg.append(", type=");
4092                            msg.append(type);
4093    
4094                            msg.append(", receiverUserId=");
4095                            msg.append(receiverUserId);
4096    
4097                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4098    
4099                            if (_log.isWarnEnabled()) {
4100                                    _log.warn(msg.toString());
4101                            }
4102    
4103                            throw new NoSuchActivityException(msg.toString());
4104                    }
4105    
4106                    return socialActivity;
4107            }
4108    
4109            /**
4110             * 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.
4111             *
4112             * @param groupId the group ID
4113             * @param userId the user ID
4114             * @param createDate the create date
4115             * @param classNameId the class name ID
4116             * @param classPK the class p k
4117             * @param type the type
4118             * @param receiverUserId the receiver user ID
4119             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
4120             * @throws SystemException if a system exception occurred
4121             */
4122            public SocialActivity fetchByG_U_CD_C_C_T_R(long groupId, long userId,
4123                    long createDate, long classNameId, long classPK, int type,
4124                    long receiverUserId) throws SystemException {
4125                    return fetchByG_U_CD_C_C_T_R(groupId, userId, createDate, classNameId,
4126                            classPK, type, receiverUserId, true);
4127            }
4128    
4129            /**
4130             * 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.
4131             *
4132             * @param groupId the group ID
4133             * @param userId the user ID
4134             * @param createDate the create date
4135             * @param classNameId the class name ID
4136             * @param classPK the class p k
4137             * @param type the type
4138             * @param receiverUserId the receiver user ID
4139             * @param retrieveFromCache whether to use the finder cache
4140             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
4141             * @throws SystemException if a system exception occurred
4142             */
4143            public SocialActivity fetchByG_U_CD_C_C_T_R(long groupId, long userId,
4144                    long createDate, long classNameId, long classPK, int type,
4145                    long receiverUserId, boolean retrieveFromCache)
4146                    throws SystemException {
4147                    Object[] finderArgs = new Object[] {
4148                                    groupId, userId, createDate, classNameId, classPK, type,
4149                                    receiverUserId
4150                            };
4151    
4152                    Object result = null;
4153    
4154                    if (retrieveFromCache) {
4155                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
4156                                            finderArgs, this);
4157                    }
4158    
4159                    if (result == null) {
4160                            StringBundler query = new StringBundler(9);
4161    
4162                            query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
4163    
4164                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_GROUPID_2);
4165    
4166                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_USERID_2);
4167    
4168                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CREATEDATE_2);
4169    
4170                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSNAMEID_2);
4171    
4172                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSPK_2);
4173    
4174                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_TYPE_2);
4175    
4176                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_RECEIVERUSERID_2);
4177    
4178                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
4179    
4180                            String sql = query.toString();
4181    
4182                            Session session = null;
4183    
4184                            try {
4185                                    session = openSession();
4186    
4187                                    Query q = session.createQuery(sql);
4188    
4189                                    QueryPos qPos = QueryPos.getInstance(q);
4190    
4191                                    qPos.add(groupId);
4192    
4193                                    qPos.add(userId);
4194    
4195                                    qPos.add(createDate);
4196    
4197                                    qPos.add(classNameId);
4198    
4199                                    qPos.add(classPK);
4200    
4201                                    qPos.add(type);
4202    
4203                                    qPos.add(receiverUserId);
4204    
4205                                    List<SocialActivity> list = q.list();
4206    
4207                                    result = list;
4208    
4209                                    SocialActivity socialActivity = null;
4210    
4211                                    if (list.isEmpty()) {
4212                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
4213                                                    finderArgs, list);
4214                                    }
4215                                    else {
4216                                            socialActivity = list.get(0);
4217    
4218                                            cacheResult(socialActivity);
4219    
4220                                            if ((socialActivity.getGroupId() != groupId) ||
4221                                                            (socialActivity.getUserId() != userId) ||
4222                                                            (socialActivity.getCreateDate() != createDate) ||
4223                                                            (socialActivity.getClassNameId() != classNameId) ||
4224                                                            (socialActivity.getClassPK() != classPK) ||
4225                                                            (socialActivity.getType() != type) ||
4226                                                            (socialActivity.getReceiverUserId() != receiverUserId)) {
4227                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
4228                                                            finderArgs, socialActivity);
4229                                            }
4230                                    }
4231    
4232                                    return socialActivity;
4233                            }
4234                            catch (Exception e) {
4235                                    throw processException(e);
4236                            }
4237                            finally {
4238                                    if (result == null) {
4239                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
4240                                                    finderArgs);
4241                                    }
4242    
4243                                    closeSession(session);
4244                            }
4245                    }
4246                    else {
4247                            if (result instanceof List<?>) {
4248                                    return null;
4249                            }
4250                            else {
4251                                    return (SocialActivity)result;
4252                            }
4253                    }
4254            }
4255    
4256            /**
4257             * Returns all the social activities.
4258             *
4259             * @return the social activities
4260             * @throws SystemException if a system exception occurred
4261             */
4262            public List<SocialActivity> findAll() throws SystemException {
4263                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4264            }
4265    
4266            /**
4267             * Returns a range of all the social activities.
4268             *
4269             * <p>
4270             * 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.
4271             * </p>
4272             *
4273             * @param start the lower bound of the range of social activities
4274             * @param end the upper bound of the range of social activities (not inclusive)
4275             * @return the range of social activities
4276             * @throws SystemException if a system exception occurred
4277             */
4278            public List<SocialActivity> findAll(int start, int end)
4279                    throws SystemException {
4280                    return findAll(start, end, null);
4281            }
4282    
4283            /**
4284             * Returns an ordered range of all the social activities.
4285             *
4286             * <p>
4287             * 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.
4288             * </p>
4289             *
4290             * @param start the lower bound of the range of social activities
4291             * @param end the upper bound of the range of social activities (not inclusive)
4292             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4293             * @return the ordered range of social activities
4294             * @throws SystemException if a system exception occurred
4295             */
4296            public List<SocialActivity> findAll(int start, int end,
4297                    OrderByComparator orderByComparator) throws SystemException {
4298                    FinderPath finderPath = null;
4299                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
4300    
4301                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4302                                    (orderByComparator == null)) {
4303                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4304                            finderArgs = FINDER_ARGS_EMPTY;
4305                    }
4306                    else {
4307                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4308                            finderArgs = new Object[] { start, end, orderByComparator };
4309                    }
4310    
4311                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(finderPath,
4312                                    finderArgs, this);
4313    
4314                    if (list == null) {
4315                            StringBundler query = null;
4316                            String sql = null;
4317    
4318                            if (orderByComparator != null) {
4319                                    query = new StringBundler(2 +
4320                                                    (orderByComparator.getOrderByFields().length * 3));
4321    
4322                                    query.append(_SQL_SELECT_SOCIALACTIVITY);
4323    
4324                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4325                                            orderByComparator);
4326    
4327                                    sql = query.toString();
4328                            }
4329                            else {
4330                                    sql = _SQL_SELECT_SOCIALACTIVITY.concat(SocialActivityModelImpl.ORDER_BY_JPQL);
4331                            }
4332    
4333                            Session session = null;
4334    
4335                            try {
4336                                    session = openSession();
4337    
4338                                    Query q = session.createQuery(sql);
4339    
4340                                    if (orderByComparator == null) {
4341                                            list = (List<SocialActivity>)QueryUtil.list(q,
4342                                                            getDialect(), start, end, false);
4343    
4344                                            Collections.sort(list);
4345                                    }
4346                                    else {
4347                                            list = (List<SocialActivity>)QueryUtil.list(q,
4348                                                            getDialect(), start, end);
4349                                    }
4350                            }
4351                            catch (Exception e) {
4352                                    throw processException(e);
4353                            }
4354                            finally {
4355                                    if (list == null) {
4356                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4357                                    }
4358                                    else {
4359                                            cacheResult(list);
4360    
4361                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4362                                    }
4363    
4364                                    closeSession(session);
4365                            }
4366                    }
4367    
4368                    return list;
4369            }
4370    
4371            /**
4372             * Removes all the social activities where groupId = &#63; from the database.
4373             *
4374             * @param groupId the group ID
4375             * @throws SystemException if a system exception occurred
4376             */
4377            public void removeByGroupId(long groupId) throws SystemException {
4378                    for (SocialActivity socialActivity : findByGroupId(groupId)) {
4379                            socialActivityPersistence.remove(socialActivity);
4380                    }
4381            }
4382    
4383            /**
4384             * Removes all the social activities where companyId = &#63; from the database.
4385             *
4386             * @param companyId the company ID
4387             * @throws SystemException if a system exception occurred
4388             */
4389            public void removeByCompanyId(long companyId) throws SystemException {
4390                    for (SocialActivity socialActivity : findByCompanyId(companyId)) {
4391                            socialActivityPersistence.remove(socialActivity);
4392                    }
4393            }
4394    
4395            /**
4396             * Removes all the social activities where userId = &#63; from the database.
4397             *
4398             * @param userId the user ID
4399             * @throws SystemException if a system exception occurred
4400             */
4401            public void removeByUserId(long userId) throws SystemException {
4402                    for (SocialActivity socialActivity : findByUserId(userId)) {
4403                            socialActivityPersistence.remove(socialActivity);
4404                    }
4405            }
4406    
4407            /**
4408             * Removes the social activity where mirrorActivityId = &#63; from the database.
4409             *
4410             * @param mirrorActivityId the mirror activity ID
4411             * @throws SystemException if a system exception occurred
4412             */
4413            public void removeByMirrorActivityId(long mirrorActivityId)
4414                    throws NoSuchActivityException, SystemException {
4415                    SocialActivity socialActivity = findByMirrorActivityId(mirrorActivityId);
4416    
4417                    socialActivityPersistence.remove(socialActivity);
4418            }
4419    
4420            /**
4421             * Removes all the social activities where classNameId = &#63; from the database.
4422             *
4423             * @param classNameId the class name ID
4424             * @throws SystemException if a system exception occurred
4425             */
4426            public void removeByClassNameId(long classNameId) throws SystemException {
4427                    for (SocialActivity socialActivity : findByClassNameId(classNameId)) {
4428                            socialActivityPersistence.remove(socialActivity);
4429                    }
4430            }
4431    
4432            /**
4433             * Removes all the social activities where receiverUserId = &#63; from the database.
4434             *
4435             * @param receiverUserId the receiver user ID
4436             * @throws SystemException if a system exception occurred
4437             */
4438            public void removeByReceiverUserId(long receiverUserId)
4439                    throws SystemException {
4440                    for (SocialActivity socialActivity : findByReceiverUserId(
4441                                    receiverUserId)) {
4442                            socialActivityPersistence.remove(socialActivity);
4443                    }
4444            }
4445    
4446            /**
4447             * Removes all the social activities where classNameId = &#63; and classPK = &#63; from the database.
4448             *
4449             * @param classNameId the class name ID
4450             * @param classPK the class p k
4451             * @throws SystemException if a system exception occurred
4452             */
4453            public void removeByC_C(long classNameId, long classPK)
4454                    throws SystemException {
4455                    for (SocialActivity socialActivity : findByC_C(classNameId, classPK)) {
4456                            socialActivityPersistence.remove(socialActivity);
4457                    }
4458            }
4459    
4460            /**
4461             * Removes all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
4462             *
4463             * @param mirrorActivityId the mirror activity ID
4464             * @param classNameId the class name ID
4465             * @param classPK the class p k
4466             * @throws SystemException if a system exception occurred
4467             */
4468            public void removeByM_C_C(long mirrorActivityId, long classNameId,
4469                    long classPK) throws SystemException {
4470                    for (SocialActivity socialActivity : findByM_C_C(mirrorActivityId,
4471                                    classNameId, classPK)) {
4472                            socialActivityPersistence.remove(socialActivity);
4473                    }
4474            }
4475    
4476            /**
4477             * 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.
4478             *
4479             * @param groupId the group ID
4480             * @param userId the user ID
4481             * @param classNameId the class name ID
4482             * @param classPK the class p k
4483             * @param type the type
4484             * @param receiverUserId the receiver user ID
4485             * @throws SystemException if a system exception occurred
4486             */
4487            public void removeByG_U_C_C_T_R(long groupId, long userId,
4488                    long classNameId, long classPK, int type, long receiverUserId)
4489                    throws SystemException {
4490                    for (SocialActivity socialActivity : findByG_U_C_C_T_R(groupId, userId,
4491                                    classNameId, classPK, type, receiverUserId)) {
4492                            socialActivityPersistence.remove(socialActivity);
4493                    }
4494            }
4495    
4496            /**
4497             * 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.
4498             *
4499             * @param groupId the group ID
4500             * @param userId the user ID
4501             * @param createDate the create date
4502             * @param classNameId the class name ID
4503             * @param classPK the class p k
4504             * @param type the type
4505             * @param receiverUserId the receiver user ID
4506             * @throws SystemException if a system exception occurred
4507             */
4508            public void removeByG_U_CD_C_C_T_R(long groupId, long userId,
4509                    long createDate, long classNameId, long classPK, int type,
4510                    long receiverUserId) throws NoSuchActivityException, SystemException {
4511                    SocialActivity socialActivity = findByG_U_CD_C_C_T_R(groupId, userId,
4512                                    createDate, classNameId, classPK, type, receiverUserId);
4513    
4514                    socialActivityPersistence.remove(socialActivity);
4515            }
4516    
4517            /**
4518             * Removes all the social activities from the database.
4519             *
4520             * @throws SystemException if a system exception occurred
4521             */
4522            public void removeAll() throws SystemException {
4523                    for (SocialActivity socialActivity : findAll()) {
4524                            socialActivityPersistence.remove(socialActivity);
4525                    }
4526            }
4527    
4528            /**
4529             * Returns the number of social activities where groupId = &#63;.
4530             *
4531             * @param groupId the group ID
4532             * @return the number of matching social activities
4533             * @throws SystemException if a system exception occurred
4534             */
4535            public int countByGroupId(long groupId) throws SystemException {
4536                    Object[] finderArgs = new Object[] { groupId };
4537    
4538                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
4539                                    finderArgs, this);
4540    
4541                    if (count == null) {
4542                            StringBundler query = new StringBundler(2);
4543    
4544                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4545    
4546                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4547    
4548                            String sql = query.toString();
4549    
4550                            Session session = null;
4551    
4552                            try {
4553                                    session = openSession();
4554    
4555                                    Query q = session.createQuery(sql);
4556    
4557                                    QueryPos qPos = QueryPos.getInstance(q);
4558    
4559                                    qPos.add(groupId);
4560    
4561                                    count = (Long)q.uniqueResult();
4562                            }
4563                            catch (Exception e) {
4564                                    throw processException(e);
4565                            }
4566                            finally {
4567                                    if (count == null) {
4568                                            count = Long.valueOf(0);
4569                                    }
4570    
4571                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
4572                                            finderArgs, count);
4573    
4574                                    closeSession(session);
4575                            }
4576                    }
4577    
4578                    return count.intValue();
4579            }
4580    
4581            /**
4582             * Returns the number of social activities where companyId = &#63;.
4583             *
4584             * @param companyId the company ID
4585             * @return the number of matching social activities
4586             * @throws SystemException if a system exception occurred
4587             */
4588            public int countByCompanyId(long companyId) throws SystemException {
4589                    Object[] finderArgs = new Object[] { companyId };
4590    
4591                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
4592                                    finderArgs, this);
4593    
4594                    if (count == null) {
4595                            StringBundler query = new StringBundler(2);
4596    
4597                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4598    
4599                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4600    
4601                            String sql = query.toString();
4602    
4603                            Session session = null;
4604    
4605                            try {
4606                                    session = openSession();
4607    
4608                                    Query q = session.createQuery(sql);
4609    
4610                                    QueryPos qPos = QueryPos.getInstance(q);
4611    
4612                                    qPos.add(companyId);
4613    
4614                                    count = (Long)q.uniqueResult();
4615                            }
4616                            catch (Exception e) {
4617                                    throw processException(e);
4618                            }
4619                            finally {
4620                                    if (count == null) {
4621                                            count = Long.valueOf(0);
4622                                    }
4623    
4624                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
4625                                            finderArgs, count);
4626    
4627                                    closeSession(session);
4628                            }
4629                    }
4630    
4631                    return count.intValue();
4632            }
4633    
4634            /**
4635             * Returns the number of social activities where userId = &#63;.
4636             *
4637             * @param userId the user ID
4638             * @return the number of matching social activities
4639             * @throws SystemException if a system exception occurred
4640             */
4641            public int countByUserId(long userId) throws SystemException {
4642                    Object[] finderArgs = new Object[] { userId };
4643    
4644                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
4645                                    finderArgs, this);
4646    
4647                    if (count == null) {
4648                            StringBundler query = new StringBundler(2);
4649    
4650                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4651    
4652                            query.append(_FINDER_COLUMN_USERID_USERID_2);
4653    
4654                            String sql = query.toString();
4655    
4656                            Session session = null;
4657    
4658                            try {
4659                                    session = openSession();
4660    
4661                                    Query q = session.createQuery(sql);
4662    
4663                                    QueryPos qPos = QueryPos.getInstance(q);
4664    
4665                                    qPos.add(userId);
4666    
4667                                    count = (Long)q.uniqueResult();
4668                            }
4669                            catch (Exception e) {
4670                                    throw processException(e);
4671                            }
4672                            finally {
4673                                    if (count == null) {
4674                                            count = Long.valueOf(0);
4675                                    }
4676    
4677                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
4678                                            finderArgs, count);
4679    
4680                                    closeSession(session);
4681                            }
4682                    }
4683    
4684                    return count.intValue();
4685            }
4686    
4687            /**
4688             * Returns the number of social activities where mirrorActivityId = &#63;.
4689             *
4690             * @param mirrorActivityId the mirror activity ID
4691             * @return the number of matching social activities
4692             * @throws SystemException if a system exception occurred
4693             */
4694            public int countByMirrorActivityId(long mirrorActivityId)
4695                    throws SystemException {
4696                    Object[] finderArgs = new Object[] { mirrorActivityId };
4697    
4698                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MIRRORACTIVITYID,
4699                                    finderArgs, this);
4700    
4701                    if (count == null) {
4702                            StringBundler query = new StringBundler(2);
4703    
4704                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4705    
4706                            query.append(_FINDER_COLUMN_MIRRORACTIVITYID_MIRRORACTIVITYID_2);
4707    
4708                            String sql = query.toString();
4709    
4710                            Session session = null;
4711    
4712                            try {
4713                                    session = openSession();
4714    
4715                                    Query q = session.createQuery(sql);
4716    
4717                                    QueryPos qPos = QueryPos.getInstance(q);
4718    
4719                                    qPos.add(mirrorActivityId);
4720    
4721                                    count = (Long)q.uniqueResult();
4722                            }
4723                            catch (Exception e) {
4724                                    throw processException(e);
4725                            }
4726                            finally {
4727                                    if (count == null) {
4728                                            count = Long.valueOf(0);
4729                                    }
4730    
4731                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MIRRORACTIVITYID,
4732                                            finderArgs, count);
4733    
4734                                    closeSession(session);
4735                            }
4736                    }
4737    
4738                    return count.intValue();
4739            }
4740    
4741            /**
4742             * Returns the number of social activities where classNameId = &#63;.
4743             *
4744             * @param classNameId the class name ID
4745             * @return the number of matching social activities
4746             * @throws SystemException if a system exception occurred
4747             */
4748            public int countByClassNameId(long classNameId) throws SystemException {
4749                    Object[] finderArgs = new Object[] { classNameId };
4750    
4751                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
4752                                    finderArgs, this);
4753    
4754                    if (count == null) {
4755                            StringBundler query = new StringBundler(2);
4756    
4757                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4758    
4759                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
4760    
4761                            String sql = query.toString();
4762    
4763                            Session session = null;
4764    
4765                            try {
4766                                    session = openSession();
4767    
4768                                    Query q = session.createQuery(sql);
4769    
4770                                    QueryPos qPos = QueryPos.getInstance(q);
4771    
4772                                    qPos.add(classNameId);
4773    
4774                                    count = (Long)q.uniqueResult();
4775                            }
4776                            catch (Exception e) {
4777                                    throw processException(e);
4778                            }
4779                            finally {
4780                                    if (count == null) {
4781                                            count = Long.valueOf(0);
4782                                    }
4783    
4784                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
4785                                            finderArgs, count);
4786    
4787                                    closeSession(session);
4788                            }
4789                    }
4790    
4791                    return count.intValue();
4792            }
4793    
4794            /**
4795             * Returns the number of social activities where receiverUserId = &#63;.
4796             *
4797             * @param receiverUserId the receiver user ID
4798             * @return the number of matching social activities
4799             * @throws SystemException if a system exception occurred
4800             */
4801            public int countByReceiverUserId(long receiverUserId)
4802                    throws SystemException {
4803                    Object[] finderArgs = new Object[] { receiverUserId };
4804    
4805                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
4806                                    finderArgs, this);
4807    
4808                    if (count == null) {
4809                            StringBundler query = new StringBundler(2);
4810    
4811                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4812    
4813                            query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
4814    
4815                            String sql = query.toString();
4816    
4817                            Session session = null;
4818    
4819                            try {
4820                                    session = openSession();
4821    
4822                                    Query q = session.createQuery(sql);
4823    
4824                                    QueryPos qPos = QueryPos.getInstance(q);
4825    
4826                                    qPos.add(receiverUserId);
4827    
4828                                    count = (Long)q.uniqueResult();
4829                            }
4830                            catch (Exception e) {
4831                                    throw processException(e);
4832                            }
4833                            finally {
4834                                    if (count == null) {
4835                                            count = Long.valueOf(0);
4836                                    }
4837    
4838                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
4839                                            finderArgs, count);
4840    
4841                                    closeSession(session);
4842                            }
4843                    }
4844    
4845                    return count.intValue();
4846            }
4847    
4848            /**
4849             * Returns the number of social activities where classNameId = &#63; and classPK = &#63;.
4850             *
4851             * @param classNameId the class name ID
4852             * @param classPK the class p k
4853             * @return the number of matching social activities
4854             * @throws SystemException if a system exception occurred
4855             */
4856            public int countByC_C(long classNameId, long classPK)
4857                    throws SystemException {
4858                    Object[] finderArgs = new Object[] { classNameId, classPK };
4859    
4860                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
4861                                    finderArgs, this);
4862    
4863                    if (count == null) {
4864                            StringBundler query = new StringBundler(3);
4865    
4866                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4867    
4868                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
4869    
4870                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
4871    
4872                            String sql = query.toString();
4873    
4874                            Session session = null;
4875    
4876                            try {
4877                                    session = openSession();
4878    
4879                                    Query q = session.createQuery(sql);
4880    
4881                                    QueryPos qPos = QueryPos.getInstance(q);
4882    
4883                                    qPos.add(classNameId);
4884    
4885                                    qPos.add(classPK);
4886    
4887                                    count = (Long)q.uniqueResult();
4888                            }
4889                            catch (Exception e) {
4890                                    throw processException(e);
4891                            }
4892                            finally {
4893                                    if (count == null) {
4894                                            count = Long.valueOf(0);
4895                                    }
4896    
4897                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
4898                                            count);
4899    
4900                                    closeSession(session);
4901                            }
4902                    }
4903    
4904                    return count.intValue();
4905            }
4906    
4907            /**
4908             * Returns the number of social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
4909             *
4910             * @param mirrorActivityId the mirror activity ID
4911             * @param classNameId the class name ID
4912             * @param classPK the class p k
4913             * @return the number of matching social activities
4914             * @throws SystemException if a system exception occurred
4915             */
4916            public int countByM_C_C(long mirrorActivityId, long classNameId,
4917                    long classPK) throws SystemException {
4918                    Object[] finderArgs = new Object[] {
4919                                    mirrorActivityId, classNameId, classPK
4920                            };
4921    
4922                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_M_C_C,
4923                                    finderArgs, this);
4924    
4925                    if (count == null) {
4926                            StringBundler query = new StringBundler(4);
4927    
4928                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4929    
4930                            query.append(_FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2);
4931    
4932                            query.append(_FINDER_COLUMN_M_C_C_CLASSNAMEID_2);
4933    
4934                            query.append(_FINDER_COLUMN_M_C_C_CLASSPK_2);
4935    
4936                            String sql = query.toString();
4937    
4938                            Session session = null;
4939    
4940                            try {
4941                                    session = openSession();
4942    
4943                                    Query q = session.createQuery(sql);
4944    
4945                                    QueryPos qPos = QueryPos.getInstance(q);
4946    
4947                                    qPos.add(mirrorActivityId);
4948    
4949                                    qPos.add(classNameId);
4950    
4951                                    qPos.add(classPK);
4952    
4953                                    count = (Long)q.uniqueResult();
4954                            }
4955                            catch (Exception e) {
4956                                    throw processException(e);
4957                            }
4958                            finally {
4959                                    if (count == null) {
4960                                            count = Long.valueOf(0);
4961                                    }
4962    
4963                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_M_C_C,
4964                                            finderArgs, count);
4965    
4966                                    closeSession(session);
4967                            }
4968                    }
4969    
4970                    return count.intValue();
4971            }
4972    
4973            /**
4974             * Returns the number of social activities where groupId = &#63; and userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
4975             *
4976             * @param groupId the group ID
4977             * @param userId the user ID
4978             * @param classNameId the class name ID
4979             * @param classPK the class p k
4980             * @param type the type
4981             * @param receiverUserId the receiver user ID
4982             * @return the number of matching social activities
4983             * @throws SystemException if a system exception occurred
4984             */
4985            public int countByG_U_C_C_T_R(long groupId, long userId, long classNameId,
4986                    long classPK, int type, long receiverUserId) throws SystemException {
4987                    Object[] finderArgs = new Object[] {
4988                                    groupId, userId, classNameId, classPK, type, receiverUserId
4989                            };
4990    
4991                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_C_C_T_R,
4992                                    finderArgs, this);
4993    
4994                    if (count == null) {
4995                            StringBundler query = new StringBundler(7);
4996    
4997                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4998    
4999                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_GROUPID_2);
5000    
5001                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_USERID_2);
5002    
5003                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSNAMEID_2);
5004    
5005                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_CLASSPK_2);
5006    
5007                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_TYPE_2);
5008    
5009                            query.append(_FINDER_COLUMN_G_U_C_C_T_R_RECEIVERUSERID_2);
5010    
5011                            String sql = query.toString();
5012    
5013                            Session session = null;
5014    
5015                            try {
5016                                    session = openSession();
5017    
5018                                    Query q = session.createQuery(sql);
5019    
5020                                    QueryPos qPos = QueryPos.getInstance(q);
5021    
5022                                    qPos.add(groupId);
5023    
5024                                    qPos.add(userId);
5025    
5026                                    qPos.add(classNameId);
5027    
5028                                    qPos.add(classPK);
5029    
5030                                    qPos.add(type);
5031    
5032                                    qPos.add(receiverUserId);
5033    
5034                                    count = (Long)q.uniqueResult();
5035                            }
5036                            catch (Exception e) {
5037                                    throw processException(e);
5038                            }
5039                            finally {
5040                                    if (count == null) {
5041                                            count = Long.valueOf(0);
5042                                    }
5043    
5044                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_C_C_T_R,
5045                                            finderArgs, count);
5046    
5047                                    closeSession(session);
5048                            }
5049                    }
5050    
5051                    return count.intValue();
5052            }
5053    
5054            /**
5055             * 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;.
5056             *
5057             * @param groupId the group ID
5058             * @param userId the user ID
5059             * @param createDate the create date
5060             * @param classNameId the class name ID
5061             * @param classPK the class p k
5062             * @param type the type
5063             * @param receiverUserId the receiver user ID
5064             * @return the number of matching social activities
5065             * @throws SystemException if a system exception occurred
5066             */
5067            public int countByG_U_CD_C_C_T_R(long groupId, long userId,
5068                    long createDate, long classNameId, long classPK, int type,
5069                    long receiverUserId) throws SystemException {
5070                    Object[] finderArgs = new Object[] {
5071                                    groupId, userId, createDate, classNameId, classPK, type,
5072                                    receiverUserId
5073                            };
5074    
5075                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R,
5076                                    finderArgs, this);
5077    
5078                    if (count == null) {
5079                            StringBundler query = new StringBundler(8);
5080    
5081                            query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
5082    
5083                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_GROUPID_2);
5084    
5085                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_USERID_2);
5086    
5087                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CREATEDATE_2);
5088    
5089                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSNAMEID_2);
5090    
5091                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSPK_2);
5092    
5093                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_TYPE_2);
5094    
5095                            query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_RECEIVERUSERID_2);
5096    
5097                            String sql = query.toString();
5098    
5099                            Session session = null;
5100    
5101                            try {
5102                                    session = openSession();
5103    
5104                                    Query q = session.createQuery(sql);
5105    
5106                                    QueryPos qPos = QueryPos.getInstance(q);
5107    
5108                                    qPos.add(groupId);
5109    
5110                                    qPos.add(userId);
5111    
5112                                    qPos.add(createDate);
5113    
5114                                    qPos.add(classNameId);
5115    
5116                                    qPos.add(classPK);
5117    
5118                                    qPos.add(type);
5119    
5120                                    qPos.add(receiverUserId);
5121    
5122                                    count = (Long)q.uniqueResult();
5123                            }
5124                            catch (Exception e) {
5125                                    throw processException(e);
5126                            }
5127                            finally {
5128                                    if (count == null) {
5129                                            count = Long.valueOf(0);
5130                                    }
5131    
5132                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R,
5133                                            finderArgs, count);
5134    
5135                                    closeSession(session);
5136                            }
5137                    }
5138    
5139                    return count.intValue();
5140            }
5141    
5142            /**
5143             * Returns the number of social activities.
5144             *
5145             * @return the number of social activities
5146             * @throws SystemException if a system exception occurred
5147             */
5148            public int countAll() throws SystemException {
5149                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5150                                    FINDER_ARGS_EMPTY, this);
5151    
5152                    if (count == null) {
5153                            Session session = null;
5154    
5155                            try {
5156                                    session = openSession();
5157    
5158                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITY);
5159    
5160                                    count = (Long)q.uniqueResult();
5161                            }
5162                            catch (Exception e) {
5163                                    throw processException(e);
5164                            }
5165                            finally {
5166                                    if (count == null) {
5167                                            count = Long.valueOf(0);
5168                                    }
5169    
5170                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5171                                            FINDER_ARGS_EMPTY, count);
5172    
5173                                    closeSession(session);
5174                            }
5175                    }
5176    
5177                    return count.intValue();
5178            }
5179    
5180            /**
5181             * Initializes the social activity persistence.
5182             */
5183            public void afterPropertiesSet() {
5184                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5185                                            com.liferay.portal.util.PropsUtil.get(
5186                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivity")));
5187    
5188                    if (listenerClassNames.length > 0) {
5189                            try {
5190                                    List<ModelListener<SocialActivity>> listenersList = new ArrayList<ModelListener<SocialActivity>>();
5191    
5192                                    for (String listenerClassName : listenerClassNames) {
5193                                            listenersList.add((ModelListener<SocialActivity>)InstanceFactory.newInstance(
5194                                                            listenerClassName));
5195                                    }
5196    
5197                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5198                            }
5199                            catch (Exception e) {
5200                                    _log.error(e);
5201                            }
5202                    }
5203            }
5204    
5205            public void destroy() {
5206                    EntityCacheUtil.removeCache(SocialActivityImpl.class.getName());
5207                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5208                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5209            }
5210    
5211            @BeanReference(type = SocialActivityPersistence.class)
5212            protected SocialActivityPersistence socialActivityPersistence;
5213            @BeanReference(type = SocialActivityAchievementPersistence.class)
5214            protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
5215            @BeanReference(type = SocialActivityCounterPersistence.class)
5216            protected SocialActivityCounterPersistence socialActivityCounterPersistence;
5217            @BeanReference(type = SocialActivityLimitPersistence.class)
5218            protected SocialActivityLimitPersistence socialActivityLimitPersistence;
5219            @BeanReference(type = SocialActivitySettingPersistence.class)
5220            protected SocialActivitySettingPersistence socialActivitySettingPersistence;
5221            @BeanReference(type = SocialRelationPersistence.class)
5222            protected SocialRelationPersistence socialRelationPersistence;
5223            @BeanReference(type = SocialRequestPersistence.class)
5224            protected SocialRequestPersistence socialRequestPersistence;
5225            @BeanReference(type = GroupPersistence.class)
5226            protected GroupPersistence groupPersistence;
5227            @BeanReference(type = LayoutPersistence.class)
5228            protected LayoutPersistence layoutPersistence;
5229            @BeanReference(type = ResourcePersistence.class)
5230            protected ResourcePersistence resourcePersistence;
5231            @BeanReference(type = UserPersistence.class)
5232            protected UserPersistence userPersistence;
5233            @BeanReference(type = AssetEntryPersistence.class)
5234            protected AssetEntryPersistence assetEntryPersistence;
5235            private static final String _SQL_SELECT_SOCIALACTIVITY = "SELECT socialActivity FROM SocialActivity socialActivity";
5236            private static final String _SQL_SELECT_SOCIALACTIVITY_WHERE = "SELECT socialActivity FROM SocialActivity socialActivity WHERE ";
5237            private static final String _SQL_COUNT_SOCIALACTIVITY = "SELECT COUNT(socialActivity) FROM SocialActivity socialActivity";
5238            private static final String _SQL_COUNT_SOCIALACTIVITY_WHERE = "SELECT COUNT(socialActivity) FROM SocialActivity socialActivity WHERE ";
5239            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "socialActivity.groupId = ?";
5240            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialActivity.companyId = ?";
5241            private static final String _FINDER_COLUMN_USERID_USERID_2 = "socialActivity.userId = ?";
5242            private static final String _FINDER_COLUMN_MIRRORACTIVITYID_MIRRORACTIVITYID_2 =
5243                    "socialActivity.mirrorActivityId = ?";
5244            private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "socialActivity.classNameId = ?";
5245            private static final String _FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2 = "socialActivity.receiverUserId = ?";
5246            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
5247            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "socialActivity.classPK = ?";
5248            private static final String _FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2 = "socialActivity.mirrorActivityId = ? AND ";
5249            private static final String _FINDER_COLUMN_M_C_C_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
5250            private static final String _FINDER_COLUMN_M_C_C_CLASSPK_2 = "socialActivity.classPK = ?";
5251            private static final String _FINDER_COLUMN_G_U_C_C_T_R_GROUPID_2 = "socialActivity.groupId = ? AND ";
5252            private static final String _FINDER_COLUMN_G_U_C_C_T_R_USERID_2 = "socialActivity.userId = ? AND ";
5253            private static final String _FINDER_COLUMN_G_U_C_C_T_R_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
5254            private static final String _FINDER_COLUMN_G_U_C_C_T_R_CLASSPK_2 = "socialActivity.classPK = ? AND ";
5255            private static final String _FINDER_COLUMN_G_U_C_C_T_R_TYPE_2 = "socialActivity.type = ? AND ";
5256            private static final String _FINDER_COLUMN_G_U_C_C_T_R_RECEIVERUSERID_2 = "socialActivity.receiverUserId = ?";
5257            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_GROUPID_2 = "socialActivity.groupId = ? AND ";
5258            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_USERID_2 = "socialActivity.userId = ? AND ";
5259            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_CREATEDATE_2 = "socialActivity.createDate = ? AND ";
5260            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
5261            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSPK_2 = "socialActivity.classPK = ? AND ";
5262            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_TYPE_2 = "socialActivity.type = ? AND ";
5263            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_RECEIVERUSERID_2 = "socialActivity.receiverUserId = ?";
5264            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivity.";
5265            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivity exists with the primary key ";
5266            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivity exists with the key {";
5267            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5268            private static Log _log = LogFactoryUtil.getLog(SocialActivityPersistenceImpl.class);
5269            private static SocialActivity _nullSocialActivity = new SocialActivityImpl() {
5270                            @Override
5271                            public Object clone() {
5272                                    return this;
5273                            }
5274    
5275                            @Override
5276                            public CacheModel<SocialActivity> toCacheModel() {
5277                                    return _nullSocialActivityCacheModel;
5278                            }
5279                    };
5280    
5281            private static CacheModel<SocialActivity> _nullSocialActivityCacheModel = new CacheModel<SocialActivity>() {
5282                            public SocialActivity toEntityModel() {
5283                                    return _nullSocialActivity;
5284                            }
5285                    };
5286    }