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