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