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