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