001    /**
002     * Copyright (c) 2000-2010 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.annotation.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.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.GroupPersistence;
039    import com.liferay.portal.service.persistence.LayoutPersistence;
040    import com.liferay.portal.service.persistence.ResourcePersistence;
041    import com.liferay.portal.service.persistence.UserPersistence;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
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 for the social activity service.
057     *
058     * <p>
059     * Never modify this class directly. Modify <code>service.xml</code> and rerun ServiceBuilder to regnerate this class.
060     * </p>
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see SocialActivityPersistence
068     * @see SocialActivityUtil
069     * @generated
070     */
071    public class SocialActivityPersistenceImpl extends BasePersistenceImpl<SocialActivity>
072            implements SocialActivityPersistence {
073            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivityImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075                    ".List";
076            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
077                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
078                            FINDER_CLASS_NAME_LIST, "findByGroupId",
079                            new String[] {
080                                    Long.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
086                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
087                            FINDER_CLASS_NAME_LIST, "countByGroupId",
088                            new String[] { Long.class.getName() });
089            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
090                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
091                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
092                            new String[] {
093                                    Long.class.getName(),
094                                    
095                            "java.lang.Integer", "java.lang.Integer",
096                                    "com.liferay.portal.kernel.util.OrderByComparator"
097                            });
098            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
099                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
100                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
101                            new String[] { Long.class.getName() });
102            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
103                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
104                            FINDER_CLASS_NAME_LIST, "findByUserId",
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_COUNT_BY_USERID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
112                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
113                            FINDER_CLASS_NAME_LIST, "countByUserId",
114                            new String[] { Long.class.getName() });
115            public static final FinderPath FINDER_PATH_FETCH_BY_MIRRORACTIVITYID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
116                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
117                            FINDER_CLASS_NAME_ENTITY, "fetchByMirrorActivityId",
118                            new String[] { Long.class.getName() });
119            public static final FinderPath FINDER_PATH_COUNT_BY_MIRRORACTIVITYID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
120                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
121                            FINDER_CLASS_NAME_LIST, "countByMirrorActivityId",
122                            new String[] { Long.class.getName() });
123            public static final FinderPath FINDER_PATH_FIND_BY_CLASSNAMEID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
124                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
125                            FINDER_CLASS_NAME_LIST, "findByClassNameId",
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_COUNT_BY_CLASSNAMEID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
133                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
134                            FINDER_CLASS_NAME_LIST, "countByClassNameId",
135                            new String[] { Long.class.getName() });
136            public static final FinderPath FINDER_PATH_FIND_BY_RECEIVERUSERID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
137                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
138                            FINDER_CLASS_NAME_LIST, "findByReceiverUserId",
139                            new String[] {
140                                    Long.class.getName(),
141                                    
142                            "java.lang.Integer", "java.lang.Integer",
143                                    "com.liferay.portal.kernel.util.OrderByComparator"
144                            });
145            public static final FinderPath FINDER_PATH_COUNT_BY_RECEIVERUSERID = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
146                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
147                            FINDER_CLASS_NAME_LIST, "countByReceiverUserId",
148                            new String[] { Long.class.getName() });
149            public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
150                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
151                            FINDER_CLASS_NAME_LIST, "findByC_C",
152                            new String[] {
153                                    Long.class.getName(), Long.class.getName(),
154                                    
155                            "java.lang.Integer", "java.lang.Integer",
156                                    "com.liferay.portal.kernel.util.OrderByComparator"
157                            });
158            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
159                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
160                            FINDER_CLASS_NAME_LIST, "countByC_C",
161                            new String[] { Long.class.getName(), Long.class.getName() });
162            public static final FinderPath FINDER_PATH_FIND_BY_M_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
163                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
164                            FINDER_CLASS_NAME_LIST, "findByM_C_C",
165                            new String[] {
166                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
167                                    
168                            "java.lang.Integer", "java.lang.Integer",
169                                    "com.liferay.portal.kernel.util.OrderByComparator"
170                            });
171            public static final FinderPath FINDER_PATH_COUNT_BY_M_C_C = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
172                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
173                            FINDER_CLASS_NAME_LIST, "countByM_C_C",
174                            new String[] {
175                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
176                            });
177            public static final FinderPath FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
178                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
179                            FINDER_CLASS_NAME_ENTITY, "fetchByG_U_CD_C_C_T_R",
180                            new String[] {
181                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
182                                    Long.class.getName(), Long.class.getName(),
183                                    Integer.class.getName(), Long.class.getName()
184                            });
185            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
186                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
187                            FINDER_CLASS_NAME_LIST, "countByG_U_CD_C_C_T_R",
188                            new String[] {
189                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
190                                    Long.class.getName(), Long.class.getName(),
191                                    Integer.class.getName(), Long.class.getName()
192                            });
193            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
194                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
195                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
196            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
197                            SocialActivityModelImpl.FINDER_CACHE_ENABLED,
198                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
199    
200            /**
201             * Caches the social activity in the entity cache if it is enabled.
202             *
203             * @param socialActivity the social activity to cache
204             */
205            public void cacheResult(SocialActivity socialActivity) {
206                    EntityCacheUtil.putResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
207                            SocialActivityImpl.class, socialActivity.getPrimaryKey(),
208                            socialActivity);
209    
210                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
211                            new Object[] { new Long(socialActivity.getMirrorActivityId()) },
212                            socialActivity);
213    
214                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
215                            new Object[] {
216                                    new Long(socialActivity.getGroupId()),
217                                    new Long(socialActivity.getUserId()),
218                                    new Long(socialActivity.getCreateDate()),
219                                    new Long(socialActivity.getClassNameId()),
220                                    new Long(socialActivity.getClassPK()),
221                                    new Integer(socialActivity.getType()),
222                                    new Long(socialActivity.getReceiverUserId())
223                            }, socialActivity);
224            }
225    
226            /**
227             * Caches the social activities in the entity cache if it is enabled.
228             *
229             * @param socialActivities the social activities to cache
230             */
231            public void cacheResult(List<SocialActivity> socialActivities) {
232                    for (SocialActivity socialActivity : socialActivities) {
233                            if (EntityCacheUtil.getResult(
234                                                    SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
235                                                    SocialActivityImpl.class,
236                                                    socialActivity.getPrimaryKey(), this) == null) {
237                                    cacheResult(socialActivity);
238                            }
239                    }
240            }
241    
242            /**
243             * Clears the cache for all social activities.
244             *
245             * <p>
246             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
247             * </p>
248             */
249            public void clearCache() {
250                    CacheRegistryUtil.clear(SocialActivityImpl.class.getName());
251                    EntityCacheUtil.clearCache(SocialActivityImpl.class.getName());
252                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
253                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
254            }
255    
256            /**
257             * Clears the cache for the social activity.
258             *
259             * <p>
260             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
261             * </p>
262             */
263            public void clearCache(SocialActivity socialActivity) {
264                    EntityCacheUtil.removeResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
265                            SocialActivityImpl.class, socialActivity.getPrimaryKey());
266    
267                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
268                            new Object[] { new Long(socialActivity.getMirrorActivityId()) });
269    
270                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
271                            new Object[] {
272                                    new Long(socialActivity.getGroupId()),
273                                    new Long(socialActivity.getUserId()),
274                                    new Long(socialActivity.getCreateDate()),
275                                    new Long(socialActivity.getClassNameId()),
276                                    new Long(socialActivity.getClassPK()),
277                                    new Integer(socialActivity.getType()),
278                                    new Long(socialActivity.getReceiverUserId())
279                            });
280            }
281    
282            /**
283             * Creates a new social activity with the primary key.
284             *
285             * @param activityId the primary key for the new social activity
286             * @return the new social activity
287             */
288            public SocialActivity create(long activityId) {
289                    SocialActivity socialActivity = new SocialActivityImpl();
290    
291                    socialActivity.setNew(true);
292                    socialActivity.setPrimaryKey(activityId);
293    
294                    return socialActivity;
295            }
296    
297            /**
298             * Removes the social activity with the primary key from the database. Also notifies the appropriate model listeners.
299             *
300             * @param primaryKey the primary key of the social activity to remove
301             * @return the social activity that was removed
302             * @throws com.liferay.portal.NoSuchModelException if a social activity with the primary key could not be found
303             * @throws SystemException if a system exception occurred
304             */
305            public SocialActivity remove(Serializable primaryKey)
306                    throws NoSuchModelException, SystemException {
307                    return remove(((Long)primaryKey).longValue());
308            }
309    
310            /**
311             * Removes the social activity with the primary key from the database. Also notifies the appropriate model listeners.
312             *
313             * @param activityId the primary key of the social activity to remove
314             * @return the social activity that was removed
315             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
316             * @throws SystemException if a system exception occurred
317             */
318            public SocialActivity remove(long activityId)
319                    throws NoSuchActivityException, SystemException {
320                    Session session = null;
321    
322                    try {
323                            session = openSession();
324    
325                            SocialActivity socialActivity = (SocialActivity)session.get(SocialActivityImpl.class,
326                                            new Long(activityId));
327    
328                            if (socialActivity == null) {
329                                    if (_log.isWarnEnabled()) {
330                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + activityId);
331                                    }
332    
333                                    throw new NoSuchActivityException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
334                                            activityId);
335                            }
336    
337                            return remove(socialActivity);
338                    }
339                    catch (NoSuchActivityException nsee) {
340                            throw nsee;
341                    }
342                    catch (Exception e) {
343                            throw processException(e);
344                    }
345                    finally {
346                            closeSession(session);
347                    }
348            }
349    
350            protected SocialActivity removeImpl(SocialActivity socialActivity)
351                    throws SystemException {
352                    socialActivity = toUnwrappedModel(socialActivity);
353    
354                    Session session = null;
355    
356                    try {
357                            session = openSession();
358    
359                            if (socialActivity.isCachedModel() || BatchSessionUtil.isEnabled()) {
360                                    Object staleObject = session.get(SocialActivityImpl.class,
361                                                    socialActivity.getPrimaryKeyObj());
362    
363                                    if (staleObject != null) {
364                                            session.evict(staleObject);
365                                    }
366                            }
367    
368                            session.delete(socialActivity);
369    
370                            session.flush();
371                    }
372                    catch (Exception e) {
373                            throw processException(e);
374                    }
375                    finally {
376                            closeSession(session);
377                    }
378    
379                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
380    
381                    SocialActivityModelImpl socialActivityModelImpl = (SocialActivityModelImpl)socialActivity;
382    
383                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
384                            new Object[] {
385                                    new Long(socialActivityModelImpl.getOriginalMirrorActivityId())
386                            });
387    
388                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
389                            new Object[] {
390                                    new Long(socialActivityModelImpl.getOriginalGroupId()),
391                                    new Long(socialActivityModelImpl.getOriginalUserId()),
392                                    new Long(socialActivityModelImpl.getOriginalCreateDate()),
393                                    new Long(socialActivityModelImpl.getOriginalClassNameId()),
394                                    new Long(socialActivityModelImpl.getOriginalClassPK()),
395                                    new Integer(socialActivityModelImpl.getOriginalType()),
396                                    new Long(socialActivityModelImpl.getOriginalReceiverUserId())
397                            });
398    
399                    EntityCacheUtil.removeResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
400                            SocialActivityImpl.class, socialActivity.getPrimaryKey());
401    
402                    return socialActivity;
403            }
404    
405            public SocialActivity updateImpl(
406                    com.liferay.portlet.social.model.SocialActivity socialActivity,
407                    boolean merge) throws SystemException {
408                    socialActivity = toUnwrappedModel(socialActivity);
409    
410                    boolean isNew = socialActivity.isNew();
411    
412                    SocialActivityModelImpl socialActivityModelImpl = (SocialActivityModelImpl)socialActivity;
413    
414                    Session session = null;
415    
416                    try {
417                            session = openSession();
418    
419                            BatchSessionUtil.update(session, socialActivity, merge);
420    
421                            socialActivity.setNew(false);
422                    }
423                    catch (Exception e) {
424                            throw processException(e);
425                    }
426                    finally {
427                            closeSession(session);
428                    }
429    
430                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
431    
432                    EntityCacheUtil.putResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
433                            SocialActivityImpl.class, socialActivity.getPrimaryKey(),
434                            socialActivity);
435    
436                    if (!isNew &&
437                                    (socialActivity.getMirrorActivityId() != socialActivityModelImpl.getOriginalMirrorActivityId())) {
438                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
439                                    new Object[] {
440                                            new Long(socialActivityModelImpl.getOriginalMirrorActivityId())
441                                    });
442                    }
443    
444                    if (isNew ||
445                                    (socialActivity.getMirrorActivityId() != socialActivityModelImpl.getOriginalMirrorActivityId())) {
446                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
447                                    new Object[] { new Long(socialActivity.getMirrorActivityId()) },
448                                    socialActivity);
449                    }
450    
451                    if (!isNew &&
452                                    ((socialActivity.getGroupId() != socialActivityModelImpl.getOriginalGroupId()) ||
453                                    (socialActivity.getUserId() != socialActivityModelImpl.getOriginalUserId()) ||
454                                    (socialActivity.getCreateDate() != socialActivityModelImpl.getOriginalCreateDate()) ||
455                                    (socialActivity.getClassNameId() != socialActivityModelImpl.getOriginalClassNameId()) ||
456                                    (socialActivity.getClassPK() != socialActivityModelImpl.getOriginalClassPK()) ||
457                                    (socialActivity.getType() != socialActivityModelImpl.getOriginalType()) ||
458                                    (socialActivity.getReceiverUserId() != socialActivityModelImpl.getOriginalReceiverUserId()))) {
459                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
460                                    new Object[] {
461                                            new Long(socialActivityModelImpl.getOriginalGroupId()),
462                                            new Long(socialActivityModelImpl.getOriginalUserId()),
463                                            new Long(socialActivityModelImpl.getOriginalCreateDate()),
464                                            new Long(socialActivityModelImpl.getOriginalClassNameId()),
465                                            new Long(socialActivityModelImpl.getOriginalClassPK()),
466                                            new Integer(socialActivityModelImpl.getOriginalType()),
467                                            new Long(socialActivityModelImpl.getOriginalReceiverUserId())
468                                    });
469                    }
470    
471                    if (isNew ||
472                                    ((socialActivity.getGroupId() != socialActivityModelImpl.getOriginalGroupId()) ||
473                                    (socialActivity.getUserId() != socialActivityModelImpl.getOriginalUserId()) ||
474                                    (socialActivity.getCreateDate() != socialActivityModelImpl.getOriginalCreateDate()) ||
475                                    (socialActivity.getClassNameId() != socialActivityModelImpl.getOriginalClassNameId()) ||
476                                    (socialActivity.getClassPK() != socialActivityModelImpl.getOriginalClassPK()) ||
477                                    (socialActivity.getType() != socialActivityModelImpl.getOriginalType()) ||
478                                    (socialActivity.getReceiverUserId() != socialActivityModelImpl.getOriginalReceiverUserId()))) {
479                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
480                                    new Object[] {
481                                            new Long(socialActivity.getGroupId()),
482                                            new Long(socialActivity.getUserId()),
483                                            new Long(socialActivity.getCreateDate()),
484                                            new Long(socialActivity.getClassNameId()),
485                                            new Long(socialActivity.getClassPK()),
486                                            new Integer(socialActivity.getType()),
487                                            new Long(socialActivity.getReceiverUserId())
488                                    }, socialActivity);
489                    }
490    
491                    return socialActivity;
492            }
493    
494            protected SocialActivity toUnwrappedModel(SocialActivity socialActivity) {
495                    if (socialActivity instanceof SocialActivityImpl) {
496                            return socialActivity;
497                    }
498    
499                    SocialActivityImpl socialActivityImpl = new SocialActivityImpl();
500    
501                    socialActivityImpl.setNew(socialActivity.isNew());
502                    socialActivityImpl.setPrimaryKey(socialActivity.getPrimaryKey());
503    
504                    socialActivityImpl.setActivityId(socialActivity.getActivityId());
505                    socialActivityImpl.setGroupId(socialActivity.getGroupId());
506                    socialActivityImpl.setCompanyId(socialActivity.getCompanyId());
507                    socialActivityImpl.setUserId(socialActivity.getUserId());
508                    socialActivityImpl.setCreateDate(socialActivity.getCreateDate());
509                    socialActivityImpl.setMirrorActivityId(socialActivity.getMirrorActivityId());
510                    socialActivityImpl.setClassNameId(socialActivity.getClassNameId());
511                    socialActivityImpl.setClassPK(socialActivity.getClassPK());
512                    socialActivityImpl.setType(socialActivity.getType());
513                    socialActivityImpl.setExtraData(socialActivity.getExtraData());
514                    socialActivityImpl.setReceiverUserId(socialActivity.getReceiverUserId());
515    
516                    return socialActivityImpl;
517            }
518    
519            /**
520             * Finds the social activity with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
521             *
522             * @param primaryKey the primary key of the social activity to find
523             * @return the social activity
524             * @throws com.liferay.portal.NoSuchModelException if a social activity with the primary key could not be found
525             * @throws SystemException if a system exception occurred
526             */
527            public SocialActivity findByPrimaryKey(Serializable primaryKey)
528                    throws NoSuchModelException, SystemException {
529                    return findByPrimaryKey(((Long)primaryKey).longValue());
530            }
531    
532            /**
533             * Finds the social activity with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivityException} if it could not be found.
534             *
535             * @param activityId the primary key of the social activity to find
536             * @return the social activity
537             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
538             * @throws SystemException if a system exception occurred
539             */
540            public SocialActivity findByPrimaryKey(long activityId)
541                    throws NoSuchActivityException, SystemException {
542                    SocialActivity socialActivity = fetchByPrimaryKey(activityId);
543    
544                    if (socialActivity == null) {
545                            if (_log.isWarnEnabled()) {
546                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + activityId);
547                            }
548    
549                            throw new NoSuchActivityException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
550                                    activityId);
551                    }
552    
553                    return socialActivity;
554            }
555    
556            /**
557             * Finds the social activity with the primary key or returns <code>null</code> if it could not be found.
558             *
559             * @param primaryKey the primary key of the social activity to find
560             * @return the social activity, or <code>null</code> if a social activity with the primary key could not be found
561             * @throws SystemException if a system exception occurred
562             */
563            public SocialActivity fetchByPrimaryKey(Serializable primaryKey)
564                    throws SystemException {
565                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
566            }
567    
568            /**
569             * Finds the social activity with the primary key or returns <code>null</code> if it could not be found.
570             *
571             * @param activityId the primary key of the social activity to find
572             * @return the social activity, or <code>null</code> if a social activity with the primary key could not be found
573             * @throws SystemException if a system exception occurred
574             */
575            public SocialActivity fetchByPrimaryKey(long activityId)
576                    throws SystemException {
577                    SocialActivity socialActivity = (SocialActivity)EntityCacheUtil.getResult(SocialActivityModelImpl.ENTITY_CACHE_ENABLED,
578                                    SocialActivityImpl.class, activityId, this);
579    
580                    if (socialActivity == null) {
581                            Session session = null;
582    
583                            try {
584                                    session = openSession();
585    
586                                    socialActivity = (SocialActivity)session.get(SocialActivityImpl.class,
587                                                    new Long(activityId));
588                            }
589                            catch (Exception e) {
590                                    throw processException(e);
591                            }
592                            finally {
593                                    if (socialActivity != null) {
594                                            cacheResult(socialActivity);
595                                    }
596    
597                                    closeSession(session);
598                            }
599                    }
600    
601                    return socialActivity;
602            }
603    
604            /**
605             * Finds all the social activities where groupId = &#63;.
606             *
607             * @param groupId the group id to search with
608             * @return the matching social activities
609             * @throws SystemException if a system exception occurred
610             */
611            public List<SocialActivity> findByGroupId(long groupId)
612                    throws SystemException {
613                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
614            }
615    
616            /**
617             * Finds a range of all the social activities where groupId = &#63;.
618             *
619             * <p>
620             * 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.
621             * </p>
622             *
623             * @param groupId the group id to search with
624             * @param start the lower bound of the range of social activities to return
625             * @param end the upper bound of the range of social activities to return (not inclusive)
626             * @return the range of matching social activities
627             * @throws SystemException if a system exception occurred
628             */
629            public List<SocialActivity> findByGroupId(long groupId, int start, int end)
630                    throws SystemException {
631                    return findByGroupId(groupId, start, end, null);
632            }
633    
634            /**
635             * Finds an ordered range of all the social activities where groupId = &#63;.
636             *
637             * <p>
638             * 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.
639             * </p>
640             *
641             * @param groupId the group id to search with
642             * @param start the lower bound of the range of social activities to return
643             * @param end the upper bound of the range of social activities to return (not inclusive)
644             * @param orderByComparator the comparator to order the results by
645             * @return the ordered range of matching social activities
646             * @throws SystemException if a system exception occurred
647             */
648            public List<SocialActivity> findByGroupId(long groupId, int start, int end,
649                    OrderByComparator orderByComparator) throws SystemException {
650                    Object[] finderArgs = new Object[] {
651                                    groupId,
652                                    
653                                    String.valueOf(start), String.valueOf(end),
654                                    String.valueOf(orderByComparator)
655                            };
656    
657                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
658                                    finderArgs, this);
659    
660                    if (list == null) {
661                            Session session = null;
662    
663                            try {
664                                    session = openSession();
665    
666                                    StringBundler query = null;
667    
668                                    if (orderByComparator != null) {
669                                            query = new StringBundler(3 +
670                                                            (orderByComparator.getOrderByFields().length * 3));
671                                    }
672                                    else {
673                                            query = new StringBundler(3);
674                                    }
675    
676                                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
677    
678                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
679    
680                                    if (orderByComparator != null) {
681                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
682                                                    orderByComparator);
683                                    }
684    
685                                    else {
686                                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
687                                    }
688    
689                                    String sql = query.toString();
690    
691                                    Query q = session.createQuery(sql);
692    
693                                    QueryPos qPos = QueryPos.getInstance(q);
694    
695                                    qPos.add(groupId);
696    
697                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
698                                                    start, end);
699                            }
700                            catch (Exception e) {
701                                    throw processException(e);
702                            }
703                            finally {
704                                    if (list == null) {
705                                            list = new ArrayList<SocialActivity>();
706                                    }
707    
708                                    cacheResult(list);
709    
710                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
711                                            finderArgs, list);
712    
713                                    closeSession(session);
714                            }
715                    }
716    
717                    return list;
718            }
719    
720            /**
721             * Finds the first social activity in the ordered set where groupId = &#63;.
722             *
723             * <p>
724             * 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.
725             * </p>
726             *
727             * @param groupId the group id to search with
728             * @param orderByComparator the comparator to order the set by
729             * @return the first matching social activity
730             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
731             * @throws SystemException if a system exception occurred
732             */
733            public SocialActivity findByGroupId_First(long groupId,
734                    OrderByComparator orderByComparator)
735                    throws NoSuchActivityException, SystemException {
736                    List<SocialActivity> list = findByGroupId(groupId, 0, 1,
737                                    orderByComparator);
738    
739                    if (list.isEmpty()) {
740                            StringBundler msg = new StringBundler(4);
741    
742                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
743    
744                            msg.append("groupId=");
745                            msg.append(groupId);
746    
747                            msg.append(StringPool.CLOSE_CURLY_BRACE);
748    
749                            throw new NoSuchActivityException(msg.toString());
750                    }
751                    else {
752                            return list.get(0);
753                    }
754            }
755    
756            /**
757             * Finds the last social activity in the ordered set where groupId = &#63;.
758             *
759             * <p>
760             * 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.
761             * </p>
762             *
763             * @param groupId the group id to search with
764             * @param orderByComparator the comparator to order the set by
765             * @return the last matching social activity
766             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
767             * @throws SystemException if a system exception occurred
768             */
769            public SocialActivity findByGroupId_Last(long groupId,
770                    OrderByComparator orderByComparator)
771                    throws NoSuchActivityException, SystemException {
772                    int count = countByGroupId(groupId);
773    
774                    List<SocialActivity> list = findByGroupId(groupId, count - 1, count,
775                                    orderByComparator);
776    
777                    if (list.isEmpty()) {
778                            StringBundler msg = new StringBundler(4);
779    
780                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
781    
782                            msg.append("groupId=");
783                            msg.append(groupId);
784    
785                            msg.append(StringPool.CLOSE_CURLY_BRACE);
786    
787                            throw new NoSuchActivityException(msg.toString());
788                    }
789                    else {
790                            return list.get(0);
791                    }
792            }
793    
794            /**
795             * Finds the social activities before and after the current social activity in the ordered set where groupId = &#63;.
796             *
797             * <p>
798             * 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.
799             * </p>
800             *
801             * @param activityId the primary key of the current social activity
802             * @param groupId the group id to search with
803             * @param orderByComparator the comparator to order the set by
804             * @return the previous, current, and next social activity
805             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
806             * @throws SystemException if a system exception occurred
807             */
808            public SocialActivity[] findByGroupId_PrevAndNext(long activityId,
809                    long groupId, OrderByComparator orderByComparator)
810                    throws NoSuchActivityException, SystemException {
811                    SocialActivity socialActivity = findByPrimaryKey(activityId);
812    
813                    Session session = null;
814    
815                    try {
816                            session = openSession();
817    
818                            SocialActivity[] array = new SocialActivityImpl[3];
819    
820                            array[0] = getByGroupId_PrevAndNext(session, socialActivity,
821                                            groupId, orderByComparator, true);
822    
823                            array[1] = socialActivity;
824    
825                            array[2] = getByGroupId_PrevAndNext(session, socialActivity,
826                                            groupId, orderByComparator, false);
827    
828                            return array;
829                    }
830                    catch (Exception e) {
831                            throw processException(e);
832                    }
833                    finally {
834                            closeSession(session);
835                    }
836            }
837    
838            protected SocialActivity getByGroupId_PrevAndNext(Session session,
839                    SocialActivity socialActivity, long groupId,
840                    OrderByComparator orderByComparator, boolean previous) {
841                    StringBundler query = null;
842    
843                    if (orderByComparator != null) {
844                            query = new StringBundler(6 +
845                                            (orderByComparator.getOrderByFields().length * 6));
846                    }
847                    else {
848                            query = new StringBundler(3);
849                    }
850    
851                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
852    
853                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
854    
855                    if (orderByComparator != null) {
856                            String[] orderByFields = orderByComparator.getOrderByFields();
857    
858                            if (orderByFields.length > 0) {
859                                    query.append(WHERE_AND);
860                            }
861    
862                            for (int i = 0; i < orderByFields.length; i++) {
863                                    query.append(_ORDER_BY_ENTITY_ALIAS);
864                                    query.append(orderByFields[i]);
865    
866                                    if ((i + 1) < orderByFields.length) {
867                                            if (orderByComparator.isAscending() ^ previous) {
868                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
869                                            }
870                                            else {
871                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
872                                            }
873                                    }
874                                    else {
875                                            if (orderByComparator.isAscending() ^ previous) {
876                                                    query.append(WHERE_GREATER_THAN);
877                                            }
878                                            else {
879                                                    query.append(WHERE_LESSER_THAN);
880                                            }
881                                    }
882                            }
883    
884                            query.append(ORDER_BY_CLAUSE);
885    
886                            for (int i = 0; i < orderByFields.length; i++) {
887                                    query.append(_ORDER_BY_ENTITY_ALIAS);
888                                    query.append(orderByFields[i]);
889    
890                                    if ((i + 1) < orderByFields.length) {
891                                            if (orderByComparator.isAscending() ^ previous) {
892                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
893                                            }
894                                            else {
895                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
896                                            }
897                                    }
898                                    else {
899                                            if (orderByComparator.isAscending() ^ previous) {
900                                                    query.append(ORDER_BY_ASC);
901                                            }
902                                            else {
903                                                    query.append(ORDER_BY_DESC);
904                                            }
905                                    }
906                            }
907                    }
908    
909                    else {
910                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
911                    }
912    
913                    String sql = query.toString();
914    
915                    Query q = session.createQuery(sql);
916    
917                    q.setFirstResult(0);
918                    q.setMaxResults(2);
919    
920                    QueryPos qPos = QueryPos.getInstance(q);
921    
922                    qPos.add(groupId);
923    
924                    if (orderByComparator != null) {
925                            Object[] values = orderByComparator.getOrderByValues(socialActivity);
926    
927                            for (Object value : values) {
928                                    qPos.add(value);
929                            }
930                    }
931    
932                    List<SocialActivity> list = q.list();
933    
934                    if (list.size() == 2) {
935                            return list.get(1);
936                    }
937                    else {
938                            return null;
939                    }
940            }
941    
942            /**
943             * Finds all the social activities where companyId = &#63;.
944             *
945             * @param companyId the company id to search with
946             * @return the matching social activities
947             * @throws SystemException if a system exception occurred
948             */
949            public List<SocialActivity> findByCompanyId(long companyId)
950                    throws SystemException {
951                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
952                            null);
953            }
954    
955            /**
956             * Finds a range of all the social activities where companyId = &#63;.
957             *
958             * <p>
959             * 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.
960             * </p>
961             *
962             * @param companyId the company id to search with
963             * @param start the lower bound of the range of social activities to return
964             * @param end the upper bound of the range of social activities to return (not inclusive)
965             * @return the range of matching social activities
966             * @throws SystemException if a system exception occurred
967             */
968            public List<SocialActivity> findByCompanyId(long companyId, int start,
969                    int end) throws SystemException {
970                    return findByCompanyId(companyId, start, end, null);
971            }
972    
973            /**
974             * Finds an ordered range of all the social activities where companyId = &#63;.
975             *
976             * <p>
977             * 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.
978             * </p>
979             *
980             * @param companyId the company id to search with
981             * @param start the lower bound of the range of social activities to return
982             * @param end the upper bound of the range of social activities to return (not inclusive)
983             * @param orderByComparator the comparator to order the results by
984             * @return the ordered range of matching social activities
985             * @throws SystemException if a system exception occurred
986             */
987            public List<SocialActivity> findByCompanyId(long companyId, int start,
988                    int end, OrderByComparator orderByComparator) throws SystemException {
989                    Object[] finderArgs = new Object[] {
990                                    companyId,
991                                    
992                                    String.valueOf(start), String.valueOf(end),
993                                    String.valueOf(orderByComparator)
994                            };
995    
996                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
997                                    finderArgs, this);
998    
999                    if (list == null) {
1000                            Session session = null;
1001    
1002                            try {
1003                                    session = openSession();
1004    
1005                                    StringBundler query = null;
1006    
1007                                    if (orderByComparator != null) {
1008                                            query = new StringBundler(3 +
1009                                                            (orderByComparator.getOrderByFields().length * 3));
1010                                    }
1011                                    else {
1012                                            query = new StringBundler(3);
1013                                    }
1014    
1015                                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1016    
1017                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1018    
1019                                    if (orderByComparator != null) {
1020                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1021                                                    orderByComparator);
1022                                    }
1023    
1024                                    else {
1025                                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1026                                    }
1027    
1028                                    String sql = query.toString();
1029    
1030                                    Query q = session.createQuery(sql);
1031    
1032                                    QueryPos qPos = QueryPos.getInstance(q);
1033    
1034                                    qPos.add(companyId);
1035    
1036                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
1037                                                    start, end);
1038                            }
1039                            catch (Exception e) {
1040                                    throw processException(e);
1041                            }
1042                            finally {
1043                                    if (list == null) {
1044                                            list = new ArrayList<SocialActivity>();
1045                                    }
1046    
1047                                    cacheResult(list);
1048    
1049                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1050                                            finderArgs, list);
1051    
1052                                    closeSession(session);
1053                            }
1054                    }
1055    
1056                    return list;
1057            }
1058    
1059            /**
1060             * Finds the first social activity in the ordered set where companyId = &#63;.
1061             *
1062             * <p>
1063             * 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.
1064             * </p>
1065             *
1066             * @param companyId the company id to search with
1067             * @param orderByComparator the comparator to order the set by
1068             * @return the first matching social activity
1069             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1070             * @throws SystemException if a system exception occurred
1071             */
1072            public SocialActivity findByCompanyId_First(long companyId,
1073                    OrderByComparator orderByComparator)
1074                    throws NoSuchActivityException, SystemException {
1075                    List<SocialActivity> list = findByCompanyId(companyId, 0, 1,
1076                                    orderByComparator);
1077    
1078                    if (list.isEmpty()) {
1079                            StringBundler msg = new StringBundler(4);
1080    
1081                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1082    
1083                            msg.append("companyId=");
1084                            msg.append(companyId);
1085    
1086                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1087    
1088                            throw new NoSuchActivityException(msg.toString());
1089                    }
1090                    else {
1091                            return list.get(0);
1092                    }
1093            }
1094    
1095            /**
1096             * Finds the last social activity in the ordered set where companyId = &#63;.
1097             *
1098             * <p>
1099             * 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.
1100             * </p>
1101             *
1102             * @param companyId the company id to search with
1103             * @param orderByComparator the comparator to order the set by
1104             * @return the last matching social activity
1105             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1106             * @throws SystemException if a system exception occurred
1107             */
1108            public SocialActivity findByCompanyId_Last(long companyId,
1109                    OrderByComparator orderByComparator)
1110                    throws NoSuchActivityException, SystemException {
1111                    int count = countByCompanyId(companyId);
1112    
1113                    List<SocialActivity> list = findByCompanyId(companyId, count - 1,
1114                                    count, orderByComparator);
1115    
1116                    if (list.isEmpty()) {
1117                            StringBundler msg = new StringBundler(4);
1118    
1119                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1120    
1121                            msg.append("companyId=");
1122                            msg.append(companyId);
1123    
1124                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1125    
1126                            throw new NoSuchActivityException(msg.toString());
1127                    }
1128                    else {
1129                            return list.get(0);
1130                    }
1131            }
1132    
1133            /**
1134             * Finds the social activities before and after the current social activity in the ordered set where companyId = &#63;.
1135             *
1136             * <p>
1137             * 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.
1138             * </p>
1139             *
1140             * @param activityId the primary key of the current social activity
1141             * @param companyId the company id to search with
1142             * @param orderByComparator the comparator to order the set by
1143             * @return the previous, current, and next social activity
1144             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
1145             * @throws SystemException if a system exception occurred
1146             */
1147            public SocialActivity[] findByCompanyId_PrevAndNext(long activityId,
1148                    long companyId, OrderByComparator orderByComparator)
1149                    throws NoSuchActivityException, SystemException {
1150                    SocialActivity socialActivity = findByPrimaryKey(activityId);
1151    
1152                    Session session = null;
1153    
1154                    try {
1155                            session = openSession();
1156    
1157                            SocialActivity[] array = new SocialActivityImpl[3];
1158    
1159                            array[0] = getByCompanyId_PrevAndNext(session, socialActivity,
1160                                            companyId, orderByComparator, true);
1161    
1162                            array[1] = socialActivity;
1163    
1164                            array[2] = getByCompanyId_PrevAndNext(session, socialActivity,
1165                                            companyId, orderByComparator, false);
1166    
1167                            return array;
1168                    }
1169                    catch (Exception e) {
1170                            throw processException(e);
1171                    }
1172                    finally {
1173                            closeSession(session);
1174                    }
1175            }
1176    
1177            protected SocialActivity getByCompanyId_PrevAndNext(Session session,
1178                    SocialActivity socialActivity, long companyId,
1179                    OrderByComparator orderByComparator, boolean previous) {
1180                    StringBundler query = null;
1181    
1182                    if (orderByComparator != null) {
1183                            query = new StringBundler(6 +
1184                                            (orderByComparator.getOrderByFields().length * 6));
1185                    }
1186                    else {
1187                            query = new StringBundler(3);
1188                    }
1189    
1190                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1191    
1192                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1193    
1194                    if (orderByComparator != null) {
1195                            String[] orderByFields = orderByComparator.getOrderByFields();
1196    
1197                            if (orderByFields.length > 0) {
1198                                    query.append(WHERE_AND);
1199                            }
1200    
1201                            for (int i = 0; i < orderByFields.length; i++) {
1202                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1203                                    query.append(orderByFields[i]);
1204    
1205                                    if ((i + 1) < orderByFields.length) {
1206                                            if (orderByComparator.isAscending() ^ previous) {
1207                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1208                                            }
1209                                            else {
1210                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1211                                            }
1212                                    }
1213                                    else {
1214                                            if (orderByComparator.isAscending() ^ previous) {
1215                                                    query.append(WHERE_GREATER_THAN);
1216                                            }
1217                                            else {
1218                                                    query.append(WHERE_LESSER_THAN);
1219                                            }
1220                                    }
1221                            }
1222    
1223                            query.append(ORDER_BY_CLAUSE);
1224    
1225                            for (int i = 0; i < orderByFields.length; i++) {
1226                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1227                                    query.append(orderByFields[i]);
1228    
1229                                    if ((i + 1) < orderByFields.length) {
1230                                            if (orderByComparator.isAscending() ^ previous) {
1231                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1232                                            }
1233                                            else {
1234                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1235                                            }
1236                                    }
1237                                    else {
1238                                            if (orderByComparator.isAscending() ^ previous) {
1239                                                    query.append(ORDER_BY_ASC);
1240                                            }
1241                                            else {
1242                                                    query.append(ORDER_BY_DESC);
1243                                            }
1244                                    }
1245                            }
1246                    }
1247    
1248                    else {
1249                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1250                    }
1251    
1252                    String sql = query.toString();
1253    
1254                    Query q = session.createQuery(sql);
1255    
1256                    q.setFirstResult(0);
1257                    q.setMaxResults(2);
1258    
1259                    QueryPos qPos = QueryPos.getInstance(q);
1260    
1261                    qPos.add(companyId);
1262    
1263                    if (orderByComparator != null) {
1264                            Object[] values = orderByComparator.getOrderByValues(socialActivity);
1265    
1266                            for (Object value : values) {
1267                                    qPos.add(value);
1268                            }
1269                    }
1270    
1271                    List<SocialActivity> list = q.list();
1272    
1273                    if (list.size() == 2) {
1274                            return list.get(1);
1275                    }
1276                    else {
1277                            return null;
1278                    }
1279            }
1280    
1281            /**
1282             * Finds all the social activities where userId = &#63;.
1283             *
1284             * @param userId the user id to search with
1285             * @return the matching social activities
1286             * @throws SystemException if a system exception occurred
1287             */
1288            public List<SocialActivity> findByUserId(long userId)
1289                    throws SystemException {
1290                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1291            }
1292    
1293            /**
1294             * Finds a range of all the social activities where userId = &#63;.
1295             *
1296             * <p>
1297             * 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.
1298             * </p>
1299             *
1300             * @param userId the user id to search with
1301             * @param start the lower bound of the range of social activities to return
1302             * @param end the upper bound of the range of social activities to return (not inclusive)
1303             * @return the range of matching social activities
1304             * @throws SystemException if a system exception occurred
1305             */
1306            public List<SocialActivity> findByUserId(long userId, int start, int end)
1307                    throws SystemException {
1308                    return findByUserId(userId, start, end, null);
1309            }
1310    
1311            /**
1312             * Finds an ordered range of all the social activities where userId = &#63;.
1313             *
1314             * <p>
1315             * 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.
1316             * </p>
1317             *
1318             * @param userId the user id to search with
1319             * @param start the lower bound of the range of social activities to return
1320             * @param end the upper bound of the range of social activities to return (not inclusive)
1321             * @param orderByComparator the comparator to order the results by
1322             * @return the ordered range of matching social activities
1323             * @throws SystemException if a system exception occurred
1324             */
1325            public List<SocialActivity> findByUserId(long userId, int start, int end,
1326                    OrderByComparator orderByComparator) throws SystemException {
1327                    Object[] finderArgs = new Object[] {
1328                                    userId,
1329                                    
1330                                    String.valueOf(start), String.valueOf(end),
1331                                    String.valueOf(orderByComparator)
1332                            };
1333    
1334                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
1335                                    finderArgs, this);
1336    
1337                    if (list == null) {
1338                            Session session = null;
1339    
1340                            try {
1341                                    session = openSession();
1342    
1343                                    StringBundler query = null;
1344    
1345                                    if (orderByComparator != null) {
1346                                            query = new StringBundler(3 +
1347                                                            (orderByComparator.getOrderByFields().length * 3));
1348                                    }
1349                                    else {
1350                                            query = new StringBundler(3);
1351                                    }
1352    
1353                                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1354    
1355                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1356    
1357                                    if (orderByComparator != null) {
1358                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1359                                                    orderByComparator);
1360                                    }
1361    
1362                                    else {
1363                                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1364                                    }
1365    
1366                                    String sql = query.toString();
1367    
1368                                    Query q = session.createQuery(sql);
1369    
1370                                    QueryPos qPos = QueryPos.getInstance(q);
1371    
1372                                    qPos.add(userId);
1373    
1374                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
1375                                                    start, end);
1376                            }
1377                            catch (Exception e) {
1378                                    throw processException(e);
1379                            }
1380                            finally {
1381                                    if (list == null) {
1382                                            list = new ArrayList<SocialActivity>();
1383                                    }
1384    
1385                                    cacheResult(list);
1386    
1387                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
1388                                            finderArgs, list);
1389    
1390                                    closeSession(session);
1391                            }
1392                    }
1393    
1394                    return list;
1395            }
1396    
1397            /**
1398             * Finds the first social activity in the ordered set where userId = &#63;.
1399             *
1400             * <p>
1401             * 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.
1402             * </p>
1403             *
1404             * @param userId the user id to search with
1405             * @param orderByComparator the comparator to order the set by
1406             * @return the first matching social activity
1407             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1408             * @throws SystemException if a system exception occurred
1409             */
1410            public SocialActivity findByUserId_First(long userId,
1411                    OrderByComparator orderByComparator)
1412                    throws NoSuchActivityException, SystemException {
1413                    List<SocialActivity> list = findByUserId(userId, 0, 1, orderByComparator);
1414    
1415                    if (list.isEmpty()) {
1416                            StringBundler msg = new StringBundler(4);
1417    
1418                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1419    
1420                            msg.append("userId=");
1421                            msg.append(userId);
1422    
1423                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1424    
1425                            throw new NoSuchActivityException(msg.toString());
1426                    }
1427                    else {
1428                            return list.get(0);
1429                    }
1430            }
1431    
1432            /**
1433             * Finds the last social activity in the ordered set where userId = &#63;.
1434             *
1435             * <p>
1436             * 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.
1437             * </p>
1438             *
1439             * @param userId the user id to search with
1440             * @param orderByComparator the comparator to order the set by
1441             * @return the last matching social activity
1442             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1443             * @throws SystemException if a system exception occurred
1444             */
1445            public SocialActivity findByUserId_Last(long userId,
1446                    OrderByComparator orderByComparator)
1447                    throws NoSuchActivityException, SystemException {
1448                    int count = countByUserId(userId);
1449    
1450                    List<SocialActivity> list = findByUserId(userId, count - 1, count,
1451                                    orderByComparator);
1452    
1453                    if (list.isEmpty()) {
1454                            StringBundler msg = new StringBundler(4);
1455    
1456                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1457    
1458                            msg.append("userId=");
1459                            msg.append(userId);
1460    
1461                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1462    
1463                            throw new NoSuchActivityException(msg.toString());
1464                    }
1465                    else {
1466                            return list.get(0);
1467                    }
1468            }
1469    
1470            /**
1471             * Finds the social activities before and after the current social activity in the ordered set where userId = &#63;.
1472             *
1473             * <p>
1474             * 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.
1475             * </p>
1476             *
1477             * @param activityId the primary key of the current social activity
1478             * @param userId the user id to search with
1479             * @param orderByComparator the comparator to order the set by
1480             * @return the previous, current, and next social activity
1481             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
1482             * @throws SystemException if a system exception occurred
1483             */
1484            public SocialActivity[] findByUserId_PrevAndNext(long activityId,
1485                    long userId, OrderByComparator orderByComparator)
1486                    throws NoSuchActivityException, SystemException {
1487                    SocialActivity socialActivity = findByPrimaryKey(activityId);
1488    
1489                    Session session = null;
1490    
1491                    try {
1492                            session = openSession();
1493    
1494                            SocialActivity[] array = new SocialActivityImpl[3];
1495    
1496                            array[0] = getByUserId_PrevAndNext(session, socialActivity, userId,
1497                                            orderByComparator, true);
1498    
1499                            array[1] = socialActivity;
1500    
1501                            array[2] = getByUserId_PrevAndNext(session, socialActivity, userId,
1502                                            orderByComparator, false);
1503    
1504                            return array;
1505                    }
1506                    catch (Exception e) {
1507                            throw processException(e);
1508                    }
1509                    finally {
1510                            closeSession(session);
1511                    }
1512            }
1513    
1514            protected SocialActivity getByUserId_PrevAndNext(Session session,
1515                    SocialActivity socialActivity, long userId,
1516                    OrderByComparator orderByComparator, boolean previous) {
1517                    StringBundler query = null;
1518    
1519                    if (orderByComparator != null) {
1520                            query = new StringBundler(6 +
1521                                            (orderByComparator.getOrderByFields().length * 6));
1522                    }
1523                    else {
1524                            query = new StringBundler(3);
1525                    }
1526    
1527                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1528    
1529                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1530    
1531                    if (orderByComparator != null) {
1532                            String[] orderByFields = orderByComparator.getOrderByFields();
1533    
1534                            if (orderByFields.length > 0) {
1535                                    query.append(WHERE_AND);
1536                            }
1537    
1538                            for (int i = 0; i < orderByFields.length; i++) {
1539                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1540                                    query.append(orderByFields[i]);
1541    
1542                                    if ((i + 1) < orderByFields.length) {
1543                                            if (orderByComparator.isAscending() ^ previous) {
1544                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1545                                            }
1546                                            else {
1547                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1548                                            }
1549                                    }
1550                                    else {
1551                                            if (orderByComparator.isAscending() ^ previous) {
1552                                                    query.append(WHERE_GREATER_THAN);
1553                                            }
1554                                            else {
1555                                                    query.append(WHERE_LESSER_THAN);
1556                                            }
1557                                    }
1558                            }
1559    
1560                            query.append(ORDER_BY_CLAUSE);
1561    
1562                            for (int i = 0; i < orderByFields.length; i++) {
1563                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1564                                    query.append(orderByFields[i]);
1565    
1566                                    if ((i + 1) < orderByFields.length) {
1567                                            if (orderByComparator.isAscending() ^ previous) {
1568                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1569                                            }
1570                                            else {
1571                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1572                                            }
1573                                    }
1574                                    else {
1575                                            if (orderByComparator.isAscending() ^ previous) {
1576                                                    query.append(ORDER_BY_ASC);
1577                                            }
1578                                            else {
1579                                                    query.append(ORDER_BY_DESC);
1580                                            }
1581                                    }
1582                            }
1583                    }
1584    
1585                    else {
1586                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1587                    }
1588    
1589                    String sql = query.toString();
1590    
1591                    Query q = session.createQuery(sql);
1592    
1593                    q.setFirstResult(0);
1594                    q.setMaxResults(2);
1595    
1596                    QueryPos qPos = QueryPos.getInstance(q);
1597    
1598                    qPos.add(userId);
1599    
1600                    if (orderByComparator != null) {
1601                            Object[] values = orderByComparator.getOrderByValues(socialActivity);
1602    
1603                            for (Object value : values) {
1604                                    qPos.add(value);
1605                            }
1606                    }
1607    
1608                    List<SocialActivity> list = q.list();
1609    
1610                    if (list.size() == 2) {
1611                            return list.get(1);
1612                    }
1613                    else {
1614                            return null;
1615                    }
1616            }
1617    
1618            /**
1619             * Finds the social activity where mirrorActivityId = &#63; or throws a {@link com.liferay.portlet.social.NoSuchActivityException} if it could not be found.
1620             *
1621             * @param mirrorActivityId the mirror activity id to search with
1622             * @return the matching social activity
1623             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1624             * @throws SystemException if a system exception occurred
1625             */
1626            public SocialActivity findByMirrorActivityId(long mirrorActivityId)
1627                    throws NoSuchActivityException, SystemException {
1628                    SocialActivity socialActivity = fetchByMirrorActivityId(mirrorActivityId);
1629    
1630                    if (socialActivity == null) {
1631                            StringBundler msg = new StringBundler(4);
1632    
1633                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1634    
1635                            msg.append("mirrorActivityId=");
1636                            msg.append(mirrorActivityId);
1637    
1638                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1639    
1640                            if (_log.isWarnEnabled()) {
1641                                    _log.warn(msg.toString());
1642                            }
1643    
1644                            throw new NoSuchActivityException(msg.toString());
1645                    }
1646    
1647                    return socialActivity;
1648            }
1649    
1650            /**
1651             * Finds the social activity where mirrorActivityId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1652             *
1653             * @param mirrorActivityId the mirror activity id to search with
1654             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
1655             * @throws SystemException if a system exception occurred
1656             */
1657            public SocialActivity fetchByMirrorActivityId(long mirrorActivityId)
1658                    throws SystemException {
1659                    return fetchByMirrorActivityId(mirrorActivityId, true);
1660            }
1661    
1662            /**
1663             * Finds the social activity where mirrorActivityId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1664             *
1665             * @param mirrorActivityId the mirror activity id to search with
1666             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
1667             * @throws SystemException if a system exception occurred
1668             */
1669            public SocialActivity fetchByMirrorActivityId(long mirrorActivityId,
1670                    boolean retrieveFromCache) throws SystemException {
1671                    Object[] finderArgs = new Object[] { mirrorActivityId };
1672    
1673                    Object result = null;
1674    
1675                    if (retrieveFromCache) {
1676                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
1677                                            finderArgs, this);
1678                    }
1679    
1680                    if (result == null) {
1681                            Session session = null;
1682    
1683                            try {
1684                                    session = openSession();
1685    
1686                                    StringBundler query = new StringBundler(3);
1687    
1688                                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1689    
1690                                    query.append(_FINDER_COLUMN_MIRRORACTIVITYID_MIRRORACTIVITYID_2);
1691    
1692                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1693    
1694                                    String sql = query.toString();
1695    
1696                                    Query q = session.createQuery(sql);
1697    
1698                                    QueryPos qPos = QueryPos.getInstance(q);
1699    
1700                                    qPos.add(mirrorActivityId);
1701    
1702                                    List<SocialActivity> list = q.list();
1703    
1704                                    result = list;
1705    
1706                                    SocialActivity socialActivity = null;
1707    
1708                                    if (list.isEmpty()) {
1709                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
1710                                                    finderArgs, list);
1711                                    }
1712                                    else {
1713                                            socialActivity = list.get(0);
1714    
1715                                            cacheResult(socialActivity);
1716    
1717                                            if ((socialActivity.getMirrorActivityId() != mirrorActivityId)) {
1718                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
1719                                                            finderArgs, socialActivity);
1720                                            }
1721                                    }
1722    
1723                                    return socialActivity;
1724                            }
1725                            catch (Exception e) {
1726                                    throw processException(e);
1727                            }
1728                            finally {
1729                                    if (result == null) {
1730                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MIRRORACTIVITYID,
1731                                                    finderArgs, new ArrayList<SocialActivity>());
1732                                    }
1733    
1734                                    closeSession(session);
1735                            }
1736                    }
1737                    else {
1738                            if (result instanceof List<?>) {
1739                                    return null;
1740                            }
1741                            else {
1742                                    return (SocialActivity)result;
1743                            }
1744                    }
1745            }
1746    
1747            /**
1748             * Finds all the social activities where classNameId = &#63;.
1749             *
1750             * @param classNameId the class name id to search with
1751             * @return the matching social activities
1752             * @throws SystemException if a system exception occurred
1753             */
1754            public List<SocialActivity> findByClassNameId(long classNameId)
1755                    throws SystemException {
1756                    return findByClassNameId(classNameId, QueryUtil.ALL_POS,
1757                            QueryUtil.ALL_POS, null);
1758            }
1759    
1760            /**
1761             * Finds a range of all the social activities where classNameId = &#63;.
1762             *
1763             * <p>
1764             * 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.
1765             * </p>
1766             *
1767             * @param classNameId the class name id to search with
1768             * @param start the lower bound of the range of social activities to return
1769             * @param end the upper bound of the range of social activities to return (not inclusive)
1770             * @return the range of matching social activities
1771             * @throws SystemException if a system exception occurred
1772             */
1773            public List<SocialActivity> findByClassNameId(long classNameId, int start,
1774                    int end) throws SystemException {
1775                    return findByClassNameId(classNameId, start, end, null);
1776            }
1777    
1778            /**
1779             * Finds an ordered range of all the social activities where classNameId = &#63;.
1780             *
1781             * <p>
1782             * 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.
1783             * </p>
1784             *
1785             * @param classNameId the class name id to search with
1786             * @param start the lower bound of the range of social activities to return
1787             * @param end the upper bound of the range of social activities to return (not inclusive)
1788             * @param orderByComparator the comparator to order the results by
1789             * @return the ordered range of matching social activities
1790             * @throws SystemException if a system exception occurred
1791             */
1792            public List<SocialActivity> findByClassNameId(long classNameId, int start,
1793                    int end, OrderByComparator orderByComparator) throws SystemException {
1794                    Object[] finderArgs = new Object[] {
1795                                    classNameId,
1796                                    
1797                                    String.valueOf(start), String.valueOf(end),
1798                                    String.valueOf(orderByComparator)
1799                            };
1800    
1801                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
1802                                    finderArgs, this);
1803    
1804                    if (list == null) {
1805                            Session session = null;
1806    
1807                            try {
1808                                    session = openSession();
1809    
1810                                    StringBundler query = null;
1811    
1812                                    if (orderByComparator != null) {
1813                                            query = new StringBundler(3 +
1814                                                            (orderByComparator.getOrderByFields().length * 3));
1815                                    }
1816                                    else {
1817                                            query = new StringBundler(3);
1818                                    }
1819    
1820                                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1821    
1822                                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1823    
1824                                    if (orderByComparator != null) {
1825                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1826                                                    orderByComparator);
1827                                    }
1828    
1829                                    else {
1830                                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
1831                                    }
1832    
1833                                    String sql = query.toString();
1834    
1835                                    Query q = session.createQuery(sql);
1836    
1837                                    QueryPos qPos = QueryPos.getInstance(q);
1838    
1839                                    qPos.add(classNameId);
1840    
1841                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
1842                                                    start, end);
1843                            }
1844                            catch (Exception e) {
1845                                    throw processException(e);
1846                            }
1847                            finally {
1848                                    if (list == null) {
1849                                            list = new ArrayList<SocialActivity>();
1850                                    }
1851    
1852                                    cacheResult(list);
1853    
1854                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
1855                                            finderArgs, list);
1856    
1857                                    closeSession(session);
1858                            }
1859                    }
1860    
1861                    return list;
1862            }
1863    
1864            /**
1865             * Finds the first social activity in the ordered set where classNameId = &#63;.
1866             *
1867             * <p>
1868             * 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.
1869             * </p>
1870             *
1871             * @param classNameId the class name id to search with
1872             * @param orderByComparator the comparator to order the set by
1873             * @return the first matching social activity
1874             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1875             * @throws SystemException if a system exception occurred
1876             */
1877            public SocialActivity findByClassNameId_First(long classNameId,
1878                    OrderByComparator orderByComparator)
1879                    throws NoSuchActivityException, SystemException {
1880                    List<SocialActivity> list = findByClassNameId(classNameId, 0, 1,
1881                                    orderByComparator);
1882    
1883                    if (list.isEmpty()) {
1884                            StringBundler msg = new StringBundler(4);
1885    
1886                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1887    
1888                            msg.append("classNameId=");
1889                            msg.append(classNameId);
1890    
1891                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1892    
1893                            throw new NoSuchActivityException(msg.toString());
1894                    }
1895                    else {
1896                            return list.get(0);
1897                    }
1898            }
1899    
1900            /**
1901             * Finds the last social activity in the ordered set where classNameId = &#63;.
1902             *
1903             * <p>
1904             * 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.
1905             * </p>
1906             *
1907             * @param classNameId the class name id to search with
1908             * @param orderByComparator the comparator to order the set by
1909             * @return the last matching social activity
1910             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
1911             * @throws SystemException if a system exception occurred
1912             */
1913            public SocialActivity findByClassNameId_Last(long classNameId,
1914                    OrderByComparator orderByComparator)
1915                    throws NoSuchActivityException, SystemException {
1916                    int count = countByClassNameId(classNameId);
1917    
1918                    List<SocialActivity> list = findByClassNameId(classNameId, count - 1,
1919                                    count, orderByComparator);
1920    
1921                    if (list.isEmpty()) {
1922                            StringBundler msg = new StringBundler(4);
1923    
1924                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1925    
1926                            msg.append("classNameId=");
1927                            msg.append(classNameId);
1928    
1929                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1930    
1931                            throw new NoSuchActivityException(msg.toString());
1932                    }
1933                    else {
1934                            return list.get(0);
1935                    }
1936            }
1937    
1938            /**
1939             * Finds the social activities before and after the current social activity in the ordered set where classNameId = &#63;.
1940             *
1941             * <p>
1942             * 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.
1943             * </p>
1944             *
1945             * @param activityId the primary key of the current social activity
1946             * @param classNameId the class name id to search with
1947             * @param orderByComparator the comparator to order the set by
1948             * @return the previous, current, and next social activity
1949             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
1950             * @throws SystemException if a system exception occurred
1951             */
1952            public SocialActivity[] findByClassNameId_PrevAndNext(long activityId,
1953                    long classNameId, OrderByComparator orderByComparator)
1954                    throws NoSuchActivityException, SystemException {
1955                    SocialActivity socialActivity = findByPrimaryKey(activityId);
1956    
1957                    Session session = null;
1958    
1959                    try {
1960                            session = openSession();
1961    
1962                            SocialActivity[] array = new SocialActivityImpl[3];
1963    
1964                            array[0] = getByClassNameId_PrevAndNext(session, socialActivity,
1965                                            classNameId, orderByComparator, true);
1966    
1967                            array[1] = socialActivity;
1968    
1969                            array[2] = getByClassNameId_PrevAndNext(session, socialActivity,
1970                                            classNameId, orderByComparator, false);
1971    
1972                            return array;
1973                    }
1974                    catch (Exception e) {
1975                            throw processException(e);
1976                    }
1977                    finally {
1978                            closeSession(session);
1979                    }
1980            }
1981    
1982            protected SocialActivity getByClassNameId_PrevAndNext(Session session,
1983                    SocialActivity socialActivity, long classNameId,
1984                    OrderByComparator orderByComparator, boolean previous) {
1985                    StringBundler query = null;
1986    
1987                    if (orderByComparator != null) {
1988                            query = new StringBundler(6 +
1989                                            (orderByComparator.getOrderByFields().length * 6));
1990                    }
1991                    else {
1992                            query = new StringBundler(3);
1993                    }
1994    
1995                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
1996    
1997                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1998    
1999                    if (orderByComparator != null) {
2000                            String[] orderByFields = orderByComparator.getOrderByFields();
2001    
2002                            if (orderByFields.length > 0) {
2003                                    query.append(WHERE_AND);
2004                            }
2005    
2006                            for (int i = 0; i < orderByFields.length; i++) {
2007                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2008                                    query.append(orderByFields[i]);
2009    
2010                                    if ((i + 1) < orderByFields.length) {
2011                                            if (orderByComparator.isAscending() ^ previous) {
2012                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2013                                            }
2014                                            else {
2015                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2016                                            }
2017                                    }
2018                                    else {
2019                                            if (orderByComparator.isAscending() ^ previous) {
2020                                                    query.append(WHERE_GREATER_THAN);
2021                                            }
2022                                            else {
2023                                                    query.append(WHERE_LESSER_THAN);
2024                                            }
2025                                    }
2026                            }
2027    
2028                            query.append(ORDER_BY_CLAUSE);
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(classNameId);
2067    
2068                    if (orderByComparator != null) {
2069                            Object[] values = orderByComparator.getOrderByValues(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             * Finds all the social activities where receiverUserId = &#63;.
2088             *
2089             * @param receiverUserId the receiver user id to search with
2090             * @return the matching social activities
2091             * @throws SystemException if a system exception occurred
2092             */
2093            public List<SocialActivity> findByReceiverUserId(long receiverUserId)
2094                    throws SystemException {
2095                    return findByReceiverUserId(receiverUserId, QueryUtil.ALL_POS,
2096                            QueryUtil.ALL_POS, null);
2097            }
2098    
2099            /**
2100             * Finds a range of all the social activities where receiverUserId = &#63;.
2101             *
2102             * <p>
2103             * 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.
2104             * </p>
2105             *
2106             * @param receiverUserId the receiver user id to search with
2107             * @param start the lower bound of the range of social activities to return
2108             * @param end the upper bound of the range of social activities to return (not inclusive)
2109             * @return the range of matching social activities
2110             * @throws SystemException if a system exception occurred
2111             */
2112            public List<SocialActivity> findByReceiverUserId(long receiverUserId,
2113                    int start, int end) throws SystemException {
2114                    return findByReceiverUserId(receiverUserId, start, end, null);
2115            }
2116    
2117            /**
2118             * Finds an ordered range of all the social activities where receiverUserId = &#63;.
2119             *
2120             * <p>
2121             * 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.
2122             * </p>
2123             *
2124             * @param receiverUserId the receiver user id to search with
2125             * @param start the lower bound of the range of social activities to return
2126             * @param end the upper bound of the range of social activities to return (not inclusive)
2127             * @param orderByComparator the comparator to order the results by
2128             * @return the ordered range of matching social activities
2129             * @throws SystemException if a system exception occurred
2130             */
2131            public List<SocialActivity> findByReceiverUserId(long receiverUserId,
2132                    int start, int end, OrderByComparator orderByComparator)
2133                    throws SystemException {
2134                    Object[] finderArgs = new Object[] {
2135                                    receiverUserId,
2136                                    
2137                                    String.valueOf(start), String.valueOf(end),
2138                                    String.valueOf(orderByComparator)
2139                            };
2140    
2141                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_RECEIVERUSERID,
2142                                    finderArgs, this);
2143    
2144                    if (list == null) {
2145                            Session session = null;
2146    
2147                            try {
2148                                    session = openSession();
2149    
2150                                    StringBundler query = null;
2151    
2152                                    if (orderByComparator != null) {
2153                                            query = new StringBundler(3 +
2154                                                            (orderByComparator.getOrderByFields().length * 3));
2155                                    }
2156                                    else {
2157                                            query = new StringBundler(3);
2158                                    }
2159    
2160                                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2161    
2162                                    query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2163    
2164                                    if (orderByComparator != null) {
2165                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2166                                                    orderByComparator);
2167                                    }
2168    
2169                                    else {
2170                                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2171                                    }
2172    
2173                                    String sql = query.toString();
2174    
2175                                    Query q = session.createQuery(sql);
2176    
2177                                    QueryPos qPos = QueryPos.getInstance(q);
2178    
2179                                    qPos.add(receiverUserId);
2180    
2181                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
2182                                                    start, end);
2183                            }
2184                            catch (Exception e) {
2185                                    throw processException(e);
2186                            }
2187                            finally {
2188                                    if (list == null) {
2189                                            list = new ArrayList<SocialActivity>();
2190                                    }
2191    
2192                                    cacheResult(list);
2193    
2194                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_RECEIVERUSERID,
2195                                            finderArgs, list);
2196    
2197                                    closeSession(session);
2198                            }
2199                    }
2200    
2201                    return list;
2202            }
2203    
2204            /**
2205             * Finds the first social activity in the ordered set where receiverUserId = &#63;.
2206             *
2207             * <p>
2208             * 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.
2209             * </p>
2210             *
2211             * @param receiverUserId the receiver user id to search with
2212             * @param orderByComparator the comparator to order the set by
2213             * @return the first matching social activity
2214             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2215             * @throws SystemException if a system exception occurred
2216             */
2217            public SocialActivity findByReceiverUserId_First(long receiverUserId,
2218                    OrderByComparator orderByComparator)
2219                    throws NoSuchActivityException, SystemException {
2220                    List<SocialActivity> list = findByReceiverUserId(receiverUserId, 0, 1,
2221                                    orderByComparator);
2222    
2223                    if (list.isEmpty()) {
2224                            StringBundler msg = new StringBundler(4);
2225    
2226                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2227    
2228                            msg.append("receiverUserId=");
2229                            msg.append(receiverUserId);
2230    
2231                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2232    
2233                            throw new NoSuchActivityException(msg.toString());
2234                    }
2235                    else {
2236                            return list.get(0);
2237                    }
2238            }
2239    
2240            /**
2241             * Finds the last social activity in the ordered set where receiverUserId = &#63;.
2242             *
2243             * <p>
2244             * 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.
2245             * </p>
2246             *
2247             * @param receiverUserId the receiver user id to search with
2248             * @param orderByComparator the comparator to order the set by
2249             * @return the last matching social activity
2250             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2251             * @throws SystemException if a system exception occurred
2252             */
2253            public SocialActivity findByReceiverUserId_Last(long receiverUserId,
2254                    OrderByComparator orderByComparator)
2255                    throws NoSuchActivityException, SystemException {
2256                    int count = countByReceiverUserId(receiverUserId);
2257    
2258                    List<SocialActivity> list = findByReceiverUserId(receiverUserId,
2259                                    count - 1, count, orderByComparator);
2260    
2261                    if (list.isEmpty()) {
2262                            StringBundler msg = new StringBundler(4);
2263    
2264                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2265    
2266                            msg.append("receiverUserId=");
2267                            msg.append(receiverUserId);
2268    
2269                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2270    
2271                            throw new NoSuchActivityException(msg.toString());
2272                    }
2273                    else {
2274                            return list.get(0);
2275                    }
2276            }
2277    
2278            /**
2279             * Finds the social activities before and after the current social activity in the ordered set where receiverUserId = &#63;.
2280             *
2281             * <p>
2282             * 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.
2283             * </p>
2284             *
2285             * @param activityId the primary key of the current social activity
2286             * @param receiverUserId the receiver user id to search with
2287             * @param orderByComparator the comparator to order the set by
2288             * @return the previous, current, and next social activity
2289             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
2290             * @throws SystemException if a system exception occurred
2291             */
2292            public SocialActivity[] findByReceiverUserId_PrevAndNext(long activityId,
2293                    long receiverUserId, OrderByComparator orderByComparator)
2294                    throws NoSuchActivityException, SystemException {
2295                    SocialActivity socialActivity = findByPrimaryKey(activityId);
2296    
2297                    Session session = null;
2298    
2299                    try {
2300                            session = openSession();
2301    
2302                            SocialActivity[] array = new SocialActivityImpl[3];
2303    
2304                            array[0] = getByReceiverUserId_PrevAndNext(session, socialActivity,
2305                                            receiverUserId, orderByComparator, true);
2306    
2307                            array[1] = socialActivity;
2308    
2309                            array[2] = getByReceiverUserId_PrevAndNext(session, socialActivity,
2310                                            receiverUserId, orderByComparator, false);
2311    
2312                            return array;
2313                    }
2314                    catch (Exception e) {
2315                            throw processException(e);
2316                    }
2317                    finally {
2318                            closeSession(session);
2319                    }
2320            }
2321    
2322            protected SocialActivity getByReceiverUserId_PrevAndNext(Session session,
2323                    SocialActivity socialActivity, long receiverUserId,
2324                    OrderByComparator orderByComparator, boolean previous) {
2325                    StringBundler query = null;
2326    
2327                    if (orderByComparator != null) {
2328                            query = new StringBundler(6 +
2329                                            (orderByComparator.getOrderByFields().length * 6));
2330                    }
2331                    else {
2332                            query = new StringBundler(3);
2333                    }
2334    
2335                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2336    
2337                    query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2338    
2339                    if (orderByComparator != null) {
2340                            String[] orderByFields = orderByComparator.getOrderByFields();
2341    
2342                            if (orderByFields.length > 0) {
2343                                    query.append(WHERE_AND);
2344                            }
2345    
2346                            for (int i = 0; i < orderByFields.length; i++) {
2347                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2348                                    query.append(orderByFields[i]);
2349    
2350                                    if ((i + 1) < orderByFields.length) {
2351                                            if (orderByComparator.isAscending() ^ previous) {
2352                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2353                                            }
2354                                            else {
2355                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2356                                            }
2357                                    }
2358                                    else {
2359                                            if (orderByComparator.isAscending() ^ previous) {
2360                                                    query.append(WHERE_GREATER_THAN);
2361                                            }
2362                                            else {
2363                                                    query.append(WHERE_LESSER_THAN);
2364                                            }
2365                                    }
2366                            }
2367    
2368                            query.append(ORDER_BY_CLAUSE);
2369    
2370                            for (int i = 0; i < orderByFields.length; i++) {
2371                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2372                                    query.append(orderByFields[i]);
2373    
2374                                    if ((i + 1) < orderByFields.length) {
2375                                            if (orderByComparator.isAscending() ^ previous) {
2376                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2377                                            }
2378                                            else {
2379                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2380                                            }
2381                                    }
2382                                    else {
2383                                            if (orderByComparator.isAscending() ^ previous) {
2384                                                    query.append(ORDER_BY_ASC);
2385                                            }
2386                                            else {
2387                                                    query.append(ORDER_BY_DESC);
2388                                            }
2389                                    }
2390                            }
2391                    }
2392    
2393                    else {
2394                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2395                    }
2396    
2397                    String sql = query.toString();
2398    
2399                    Query q = session.createQuery(sql);
2400    
2401                    q.setFirstResult(0);
2402                    q.setMaxResults(2);
2403    
2404                    QueryPos qPos = QueryPos.getInstance(q);
2405    
2406                    qPos.add(receiverUserId);
2407    
2408                    if (orderByComparator != null) {
2409                            Object[] values = orderByComparator.getOrderByValues(socialActivity);
2410    
2411                            for (Object value : values) {
2412                                    qPos.add(value);
2413                            }
2414                    }
2415    
2416                    List<SocialActivity> list = q.list();
2417    
2418                    if (list.size() == 2) {
2419                            return list.get(1);
2420                    }
2421                    else {
2422                            return null;
2423                    }
2424            }
2425    
2426            /**
2427             * Finds all the social activities where classNameId = &#63; and classPK = &#63;.
2428             *
2429             * @param classNameId the class name id to search with
2430             * @param classPK the class p k to search with
2431             * @return the matching social activities
2432             * @throws SystemException if a system exception occurred
2433             */
2434            public List<SocialActivity> findByC_C(long classNameId, long classPK)
2435                    throws SystemException {
2436                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
2437                            QueryUtil.ALL_POS, null);
2438            }
2439    
2440            /**
2441             * Finds a range of all the social activities where classNameId = &#63; and classPK = &#63;.
2442             *
2443             * <p>
2444             * 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.
2445             * </p>
2446             *
2447             * @param classNameId the class name id to search with
2448             * @param classPK the class p k to search with
2449             * @param start the lower bound of the range of social activities to return
2450             * @param end the upper bound of the range of social activities to return (not inclusive)
2451             * @return the range of matching social activities
2452             * @throws SystemException if a system exception occurred
2453             */
2454            public List<SocialActivity> findByC_C(long classNameId, long classPK,
2455                    int start, int end) throws SystemException {
2456                    return findByC_C(classNameId, classPK, start, end, null);
2457            }
2458    
2459            /**
2460             * Finds an ordered range of all the social activities where classNameId = &#63; and classPK = &#63;.
2461             *
2462             * <p>
2463             * 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.
2464             * </p>
2465             *
2466             * @param classNameId the class name id to search with
2467             * @param classPK the class p k to search with
2468             * @param start the lower bound of the range of social activities to return
2469             * @param end the upper bound of the range of social activities to return (not inclusive)
2470             * @param orderByComparator the comparator to order the results by
2471             * @return the ordered range of matching social activities
2472             * @throws SystemException if a system exception occurred
2473             */
2474            public List<SocialActivity> findByC_C(long classNameId, long classPK,
2475                    int start, int end, OrderByComparator orderByComparator)
2476                    throws SystemException {
2477                    Object[] finderArgs = new Object[] {
2478                                    classNameId, classPK,
2479                                    
2480                                    String.valueOf(start), String.valueOf(end),
2481                                    String.valueOf(orderByComparator)
2482                            };
2483    
2484                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
2485                                    finderArgs, this);
2486    
2487                    if (list == null) {
2488                            Session session = null;
2489    
2490                            try {
2491                                    session = openSession();
2492    
2493                                    StringBundler query = null;
2494    
2495                                    if (orderByComparator != null) {
2496                                            query = new StringBundler(4 +
2497                                                            (orderByComparator.getOrderByFields().length * 3));
2498                                    }
2499                                    else {
2500                                            query = new StringBundler(4);
2501                                    }
2502    
2503                                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2504    
2505                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2506    
2507                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2508    
2509                                    if (orderByComparator != null) {
2510                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2511                                                    orderByComparator);
2512                                    }
2513    
2514                                    else {
2515                                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2516                                    }
2517    
2518                                    String sql = query.toString();
2519    
2520                                    Query q = session.createQuery(sql);
2521    
2522                                    QueryPos qPos = QueryPos.getInstance(q);
2523    
2524                                    qPos.add(classNameId);
2525    
2526                                    qPos.add(classPK);
2527    
2528                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
2529                                                    start, end);
2530                            }
2531                            catch (Exception e) {
2532                                    throw processException(e);
2533                            }
2534                            finally {
2535                                    if (list == null) {
2536                                            list = new ArrayList<SocialActivity>();
2537                                    }
2538    
2539                                    cacheResult(list);
2540    
2541                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
2542                                            list);
2543    
2544                                    closeSession(session);
2545                            }
2546                    }
2547    
2548                    return list;
2549            }
2550    
2551            /**
2552             * Finds the first social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
2553             *
2554             * <p>
2555             * 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.
2556             * </p>
2557             *
2558             * @param classNameId the class name id to search with
2559             * @param classPK the class p k to search with
2560             * @param orderByComparator the comparator to order the set by
2561             * @return the first matching social activity
2562             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2563             * @throws SystemException if a system exception occurred
2564             */
2565            public SocialActivity findByC_C_First(long classNameId, long classPK,
2566                    OrderByComparator orderByComparator)
2567                    throws NoSuchActivityException, SystemException {
2568                    List<SocialActivity> list = findByC_C(classNameId, classPK, 0, 1,
2569                                    orderByComparator);
2570    
2571                    if (list.isEmpty()) {
2572                            StringBundler msg = new StringBundler(6);
2573    
2574                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2575    
2576                            msg.append("classNameId=");
2577                            msg.append(classNameId);
2578    
2579                            msg.append(", classPK=");
2580                            msg.append(classPK);
2581    
2582                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2583    
2584                            throw new NoSuchActivityException(msg.toString());
2585                    }
2586                    else {
2587                            return list.get(0);
2588                    }
2589            }
2590    
2591            /**
2592             * Finds the last social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
2593             *
2594             * <p>
2595             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2596             * </p>
2597             *
2598             * @param classNameId the class name id to search with
2599             * @param classPK the class p k to search with
2600             * @param orderByComparator the comparator to order the set by
2601             * @return the last matching social activity
2602             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2603             * @throws SystemException if a system exception occurred
2604             */
2605            public SocialActivity findByC_C_Last(long classNameId, long classPK,
2606                    OrderByComparator orderByComparator)
2607                    throws NoSuchActivityException, SystemException {
2608                    int count = countByC_C(classNameId, classPK);
2609    
2610                    List<SocialActivity> list = findByC_C(classNameId, classPK, count - 1,
2611                                    count, orderByComparator);
2612    
2613                    if (list.isEmpty()) {
2614                            StringBundler msg = new StringBundler(6);
2615    
2616                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2617    
2618                            msg.append("classNameId=");
2619                            msg.append(classNameId);
2620    
2621                            msg.append(", classPK=");
2622                            msg.append(classPK);
2623    
2624                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2625    
2626                            throw new NoSuchActivityException(msg.toString());
2627                    }
2628                    else {
2629                            return list.get(0);
2630                    }
2631            }
2632    
2633            /**
2634             * Finds the social activities before and after the current social activity in the ordered set where classNameId = &#63; and classPK = &#63;.
2635             *
2636             * <p>
2637             * 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.
2638             * </p>
2639             *
2640             * @param activityId the primary key of the current social activity
2641             * @param classNameId the class name id to search with
2642             * @param classPK the class p k to search with
2643             * @param orderByComparator the comparator to order the set by
2644             * @return the previous, current, and next social activity
2645             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
2646             * @throws SystemException if a system exception occurred
2647             */
2648            public SocialActivity[] findByC_C_PrevAndNext(long activityId,
2649                    long classNameId, long classPK, OrderByComparator orderByComparator)
2650                    throws NoSuchActivityException, SystemException {
2651                    SocialActivity socialActivity = findByPrimaryKey(activityId);
2652    
2653                    Session session = null;
2654    
2655                    try {
2656                            session = openSession();
2657    
2658                            SocialActivity[] array = new SocialActivityImpl[3];
2659    
2660                            array[0] = getByC_C_PrevAndNext(session, socialActivity,
2661                                            classNameId, classPK, orderByComparator, true);
2662    
2663                            array[1] = socialActivity;
2664    
2665                            array[2] = getByC_C_PrevAndNext(session, socialActivity,
2666                                            classNameId, classPK, orderByComparator, false);
2667    
2668                            return array;
2669                    }
2670                    catch (Exception e) {
2671                            throw processException(e);
2672                    }
2673                    finally {
2674                            closeSession(session);
2675                    }
2676            }
2677    
2678            protected SocialActivity getByC_C_PrevAndNext(Session session,
2679                    SocialActivity socialActivity, long classNameId, long classPK,
2680                    OrderByComparator orderByComparator, boolean previous) {
2681                    StringBundler query = null;
2682    
2683                    if (orderByComparator != null) {
2684                            query = new StringBundler(6 +
2685                                            (orderByComparator.getOrderByFields().length * 6));
2686                    }
2687                    else {
2688                            query = new StringBundler(3);
2689                    }
2690    
2691                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2692    
2693                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2694    
2695                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2696    
2697                    if (orderByComparator != null) {
2698                            String[] orderByFields = orderByComparator.getOrderByFields();
2699    
2700                            if (orderByFields.length > 0) {
2701                                    query.append(WHERE_AND);
2702                            }
2703    
2704                            for (int i = 0; i < orderByFields.length; i++) {
2705                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2706                                    query.append(orderByFields[i]);
2707    
2708                                    if ((i + 1) < orderByFields.length) {
2709                                            if (orderByComparator.isAscending() ^ previous) {
2710                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2711                                            }
2712                                            else {
2713                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2714                                            }
2715                                    }
2716                                    else {
2717                                            if (orderByComparator.isAscending() ^ previous) {
2718                                                    query.append(WHERE_GREATER_THAN);
2719                                            }
2720                                            else {
2721                                                    query.append(WHERE_LESSER_THAN);
2722                                            }
2723                                    }
2724                            }
2725    
2726                            query.append(ORDER_BY_CLAUSE);
2727    
2728                            for (int i = 0; i < orderByFields.length; i++) {
2729                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2730                                    query.append(orderByFields[i]);
2731    
2732                                    if ((i + 1) < orderByFields.length) {
2733                                            if (orderByComparator.isAscending() ^ previous) {
2734                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2735                                            }
2736                                            else {
2737                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2738                                            }
2739                                    }
2740                                    else {
2741                                            if (orderByComparator.isAscending() ^ previous) {
2742                                                    query.append(ORDER_BY_ASC);
2743                                            }
2744                                            else {
2745                                                    query.append(ORDER_BY_DESC);
2746                                            }
2747                                    }
2748                            }
2749                    }
2750    
2751                    else {
2752                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2753                    }
2754    
2755                    String sql = query.toString();
2756    
2757                    Query q = session.createQuery(sql);
2758    
2759                    q.setFirstResult(0);
2760                    q.setMaxResults(2);
2761    
2762                    QueryPos qPos = QueryPos.getInstance(q);
2763    
2764                    qPos.add(classNameId);
2765    
2766                    qPos.add(classPK);
2767    
2768                    if (orderByComparator != null) {
2769                            Object[] values = orderByComparator.getOrderByValues(socialActivity);
2770    
2771                            for (Object value : values) {
2772                                    qPos.add(value);
2773                            }
2774                    }
2775    
2776                    List<SocialActivity> list = q.list();
2777    
2778                    if (list.size() == 2) {
2779                            return list.get(1);
2780                    }
2781                    else {
2782                            return null;
2783                    }
2784            }
2785    
2786            /**
2787             * Finds all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
2788             *
2789             * @param mirrorActivityId the mirror activity id to search with
2790             * @param classNameId the class name id to search with
2791             * @param classPK the class p k to search with
2792             * @return the matching social activities
2793             * @throws SystemException if a system exception occurred
2794             */
2795            public List<SocialActivity> findByM_C_C(long mirrorActivityId,
2796                    long classNameId, long classPK) throws SystemException {
2797                    return findByM_C_C(mirrorActivityId, classNameId, classPK,
2798                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2799            }
2800    
2801            /**
2802             * Finds a range of all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
2803             *
2804             * <p>
2805             * 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.
2806             * </p>
2807             *
2808             * @param mirrorActivityId the mirror activity id to search with
2809             * @param classNameId the class name id to search with
2810             * @param classPK the class p k to search with
2811             * @param start the lower bound of the range of social activities to return
2812             * @param end the upper bound of the range of social activities to return (not inclusive)
2813             * @return the range of matching social activities
2814             * @throws SystemException if a system exception occurred
2815             */
2816            public List<SocialActivity> findByM_C_C(long mirrorActivityId,
2817                    long classNameId, long classPK, int start, int end)
2818                    throws SystemException {
2819                    return findByM_C_C(mirrorActivityId, classNameId, classPK, start, end,
2820                            null);
2821            }
2822    
2823            /**
2824             * Finds an ordered range of all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
2825             *
2826             * <p>
2827             * 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.
2828             * </p>
2829             *
2830             * @param mirrorActivityId the mirror activity id to search with
2831             * @param classNameId the class name id to search with
2832             * @param classPK the class p k to search with
2833             * @param start the lower bound of the range of social activities to return
2834             * @param end the upper bound of the range of social activities to return (not inclusive)
2835             * @param orderByComparator the comparator to order the results by
2836             * @return the ordered range of matching social activities
2837             * @throws SystemException if a system exception occurred
2838             */
2839            public List<SocialActivity> findByM_C_C(long mirrorActivityId,
2840                    long classNameId, long classPK, int start, int end,
2841                    OrderByComparator orderByComparator) throws SystemException {
2842                    Object[] finderArgs = new Object[] {
2843                                    mirrorActivityId, classNameId, classPK,
2844                                    
2845                                    String.valueOf(start), String.valueOf(end),
2846                                    String.valueOf(orderByComparator)
2847                            };
2848    
2849                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_M_C_C,
2850                                    finderArgs, this);
2851    
2852                    if (list == null) {
2853                            Session session = null;
2854    
2855                            try {
2856                                    session = openSession();
2857    
2858                                    StringBundler query = null;
2859    
2860                                    if (orderByComparator != null) {
2861                                            query = new StringBundler(5 +
2862                                                            (orderByComparator.getOrderByFields().length * 3));
2863                                    }
2864                                    else {
2865                                            query = new StringBundler(5);
2866                                    }
2867    
2868                                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
2869    
2870                                    query.append(_FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2);
2871    
2872                                    query.append(_FINDER_COLUMN_M_C_C_CLASSNAMEID_2);
2873    
2874                                    query.append(_FINDER_COLUMN_M_C_C_CLASSPK_2);
2875    
2876                                    if (orderByComparator != null) {
2877                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2878                                                    orderByComparator);
2879                                    }
2880    
2881                                    else {
2882                                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
2883                                    }
2884    
2885                                    String sql = query.toString();
2886    
2887                                    Query q = session.createQuery(sql);
2888    
2889                                    QueryPos qPos = QueryPos.getInstance(q);
2890    
2891                                    qPos.add(mirrorActivityId);
2892    
2893                                    qPos.add(classNameId);
2894    
2895                                    qPos.add(classPK);
2896    
2897                                    list = (List<SocialActivity>)QueryUtil.list(q, getDialect(),
2898                                                    start, end);
2899                            }
2900                            catch (Exception e) {
2901                                    throw processException(e);
2902                            }
2903                            finally {
2904                                    if (list == null) {
2905                                            list = new ArrayList<SocialActivity>();
2906                                    }
2907    
2908                                    cacheResult(list);
2909    
2910                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_M_C_C,
2911                                            finderArgs, list);
2912    
2913                                    closeSession(session);
2914                            }
2915                    }
2916    
2917                    return list;
2918            }
2919    
2920            /**
2921             * Finds the first social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
2922             *
2923             * <p>
2924             * 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.
2925             * </p>
2926             *
2927             * @param mirrorActivityId the mirror activity id to search with
2928             * @param classNameId the class name id to search with
2929             * @param classPK the class p k to search with
2930             * @param orderByComparator the comparator to order the set by
2931             * @return the first matching social activity
2932             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2933             * @throws SystemException if a system exception occurred
2934             */
2935            public SocialActivity findByM_C_C_First(long mirrorActivityId,
2936                    long classNameId, long classPK, OrderByComparator orderByComparator)
2937                    throws NoSuchActivityException, SystemException {
2938                    List<SocialActivity> list = findByM_C_C(mirrorActivityId, classNameId,
2939                                    classPK, 0, 1, orderByComparator);
2940    
2941                    if (list.isEmpty()) {
2942                            StringBundler msg = new StringBundler(8);
2943    
2944                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2945    
2946                            msg.append("mirrorActivityId=");
2947                            msg.append(mirrorActivityId);
2948    
2949                            msg.append(", classNameId=");
2950                            msg.append(classNameId);
2951    
2952                            msg.append(", classPK=");
2953                            msg.append(classPK);
2954    
2955                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2956    
2957                            throw new NoSuchActivityException(msg.toString());
2958                    }
2959                    else {
2960                            return list.get(0);
2961                    }
2962            }
2963    
2964            /**
2965             * Finds the last social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
2966             *
2967             * <p>
2968             * 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.
2969             * </p>
2970             *
2971             * @param mirrorActivityId the mirror activity id to search with
2972             * @param classNameId the class name id to search with
2973             * @param classPK the class p k to search with
2974             * @param orderByComparator the comparator to order the set by
2975             * @return the last matching social activity
2976             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
2977             * @throws SystemException if a system exception occurred
2978             */
2979            public SocialActivity findByM_C_C_Last(long mirrorActivityId,
2980                    long classNameId, long classPK, OrderByComparator orderByComparator)
2981                    throws NoSuchActivityException, SystemException {
2982                    int count = countByM_C_C(mirrorActivityId, classNameId, classPK);
2983    
2984                    List<SocialActivity> list = findByM_C_C(mirrorActivityId, classNameId,
2985                                    classPK, count - 1, count, orderByComparator);
2986    
2987                    if (list.isEmpty()) {
2988                            StringBundler msg = new StringBundler(8);
2989    
2990                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2991    
2992                            msg.append("mirrorActivityId=");
2993                            msg.append(mirrorActivityId);
2994    
2995                            msg.append(", classNameId=");
2996                            msg.append(classNameId);
2997    
2998                            msg.append(", classPK=");
2999                            msg.append(classPK);
3000    
3001                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3002    
3003                            throw new NoSuchActivityException(msg.toString());
3004                    }
3005                    else {
3006                            return list.get(0);
3007                    }
3008            }
3009    
3010            /**
3011             * Finds the social activities before and after the current social activity in the ordered set where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3012             *
3013             * <p>
3014             * 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.
3015             * </p>
3016             *
3017             * @param activityId the primary key of the current social activity
3018             * @param mirrorActivityId the mirror activity id to search with
3019             * @param classNameId the class name id to search with
3020             * @param classPK the class p k to search with
3021             * @param orderByComparator the comparator to order the set by
3022             * @return the previous, current, and next social activity
3023             * @throws com.liferay.portlet.social.NoSuchActivityException if a social activity with the primary key could not be found
3024             * @throws SystemException if a system exception occurred
3025             */
3026            public SocialActivity[] findByM_C_C_PrevAndNext(long activityId,
3027                    long mirrorActivityId, long classNameId, long classPK,
3028                    OrderByComparator orderByComparator)
3029                    throws NoSuchActivityException, SystemException {
3030                    SocialActivity socialActivity = findByPrimaryKey(activityId);
3031    
3032                    Session session = null;
3033    
3034                    try {
3035                            session = openSession();
3036    
3037                            SocialActivity[] array = new SocialActivityImpl[3];
3038    
3039                            array[0] = getByM_C_C_PrevAndNext(session, socialActivity,
3040                                            mirrorActivityId, classNameId, classPK, orderByComparator,
3041                                            true);
3042    
3043                            array[1] = socialActivity;
3044    
3045                            array[2] = getByM_C_C_PrevAndNext(session, socialActivity,
3046                                            mirrorActivityId, classNameId, classPK, orderByComparator,
3047                                            false);
3048    
3049                            return array;
3050                    }
3051                    catch (Exception e) {
3052                            throw processException(e);
3053                    }
3054                    finally {
3055                            closeSession(session);
3056                    }
3057            }
3058    
3059            protected SocialActivity getByM_C_C_PrevAndNext(Session session,
3060                    SocialActivity socialActivity, long mirrorActivityId, long classNameId,
3061                    long classPK, OrderByComparator orderByComparator, boolean previous) {
3062                    StringBundler query = null;
3063    
3064                    if (orderByComparator != null) {
3065                            query = new StringBundler(6 +
3066                                            (orderByComparator.getOrderByFields().length * 6));
3067                    }
3068                    else {
3069                            query = new StringBundler(3);
3070                    }
3071    
3072                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3073    
3074                    query.append(_FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2);
3075    
3076                    query.append(_FINDER_COLUMN_M_C_C_CLASSNAMEID_2);
3077    
3078                    query.append(_FINDER_COLUMN_M_C_C_CLASSPK_2);
3079    
3080                    if (orderByComparator != null) {
3081                            String[] orderByFields = orderByComparator.getOrderByFields();
3082    
3083                            if (orderByFields.length > 0) {
3084                                    query.append(WHERE_AND);
3085                            }
3086    
3087                            for (int i = 0; i < orderByFields.length; i++) {
3088                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3089                                    query.append(orderByFields[i]);
3090    
3091                                    if ((i + 1) < orderByFields.length) {
3092                                            if (orderByComparator.isAscending() ^ previous) {
3093                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3094                                            }
3095                                            else {
3096                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3097                                            }
3098                                    }
3099                                    else {
3100                                            if (orderByComparator.isAscending() ^ previous) {
3101                                                    query.append(WHERE_GREATER_THAN);
3102                                            }
3103                                            else {
3104                                                    query.append(WHERE_LESSER_THAN);
3105                                            }
3106                                    }
3107                            }
3108    
3109                            query.append(ORDER_BY_CLAUSE);
3110    
3111                            for (int i = 0; i < orderByFields.length; i++) {
3112                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3113                                    query.append(orderByFields[i]);
3114    
3115                                    if ((i + 1) < orderByFields.length) {
3116                                            if (orderByComparator.isAscending() ^ previous) {
3117                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3118                                            }
3119                                            else {
3120                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3121                                            }
3122                                    }
3123                                    else {
3124                                            if (orderByComparator.isAscending() ^ previous) {
3125                                                    query.append(ORDER_BY_ASC);
3126                                            }
3127                                            else {
3128                                                    query.append(ORDER_BY_DESC);
3129                                            }
3130                                    }
3131                            }
3132                    }
3133    
3134                    else {
3135                            query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
3136                    }
3137    
3138                    String sql = query.toString();
3139    
3140                    Query q = session.createQuery(sql);
3141    
3142                    q.setFirstResult(0);
3143                    q.setMaxResults(2);
3144    
3145                    QueryPos qPos = QueryPos.getInstance(q);
3146    
3147                    qPos.add(mirrorActivityId);
3148    
3149                    qPos.add(classNameId);
3150    
3151                    qPos.add(classPK);
3152    
3153                    if (orderByComparator != null) {
3154                            Object[] values = orderByComparator.getOrderByValues(socialActivity);
3155    
3156                            for (Object value : values) {
3157                                    qPos.add(value);
3158                            }
3159                    }
3160    
3161                    List<SocialActivity> list = q.list();
3162    
3163                    if (list.size() == 2) {
3164                            return list.get(1);
3165                    }
3166                    else {
3167                            return null;
3168                    }
3169            }
3170    
3171            /**
3172             * Finds 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.
3173             *
3174             * @param groupId the group id to search with
3175             * @param userId the user id to search with
3176             * @param createDate the create date to search with
3177             * @param classNameId the class name id to search with
3178             * @param classPK the class p k to search with
3179             * @param type the type to search with
3180             * @param receiverUserId the receiver user id to search with
3181             * @return the matching social activity
3182             * @throws com.liferay.portlet.social.NoSuchActivityException if a matching social activity could not be found
3183             * @throws SystemException if a system exception occurred
3184             */
3185            public SocialActivity findByG_U_CD_C_C_T_R(long groupId, long userId,
3186                    long createDate, long classNameId, long classPK, int type,
3187                    long receiverUserId) throws NoSuchActivityException, SystemException {
3188                    SocialActivity socialActivity = fetchByG_U_CD_C_C_T_R(groupId, userId,
3189                                    createDate, classNameId, classPK, type, receiverUserId);
3190    
3191                    if (socialActivity == null) {
3192                            StringBundler msg = new StringBundler(16);
3193    
3194                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3195    
3196                            msg.append("groupId=");
3197                            msg.append(groupId);
3198    
3199                            msg.append(", userId=");
3200                            msg.append(userId);
3201    
3202                            msg.append(", createDate=");
3203                            msg.append(createDate);
3204    
3205                            msg.append(", classNameId=");
3206                            msg.append(classNameId);
3207    
3208                            msg.append(", classPK=");
3209                            msg.append(classPK);
3210    
3211                            msg.append(", type=");
3212                            msg.append(type);
3213    
3214                            msg.append(", receiverUserId=");
3215                            msg.append(receiverUserId);
3216    
3217                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3218    
3219                            if (_log.isWarnEnabled()) {
3220                                    _log.warn(msg.toString());
3221                            }
3222    
3223                            throw new NoSuchActivityException(msg.toString());
3224                    }
3225    
3226                    return socialActivity;
3227            }
3228    
3229            /**
3230             * Finds 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.
3231             *
3232             * @param groupId the group id to search with
3233             * @param userId the user id to search with
3234             * @param createDate the create date to search with
3235             * @param classNameId the class name id to search with
3236             * @param classPK the class p k to search with
3237             * @param type the type to search with
3238             * @param receiverUserId the receiver user id to search with
3239             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
3240             * @throws SystemException if a system exception occurred
3241             */
3242            public SocialActivity fetchByG_U_CD_C_C_T_R(long groupId, long userId,
3243                    long createDate, long classNameId, long classPK, int type,
3244                    long receiverUserId) throws SystemException {
3245                    return fetchByG_U_CD_C_C_T_R(groupId, userId, createDate, classNameId,
3246                            classPK, type, receiverUserId, true);
3247            }
3248    
3249            /**
3250             * Finds 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.
3251             *
3252             * @param groupId the group id to search with
3253             * @param userId the user id to search with
3254             * @param createDate the create date to search with
3255             * @param classNameId the class name id to search with
3256             * @param classPK the class p k to search with
3257             * @param type the type to search with
3258             * @param receiverUserId the receiver user id to search with
3259             * @return the matching social activity, or <code>null</code> if a matching social activity could not be found
3260             * @throws SystemException if a system exception occurred
3261             */
3262            public SocialActivity fetchByG_U_CD_C_C_T_R(long groupId, long userId,
3263                    long createDate, long classNameId, long classPK, int type,
3264                    long receiverUserId, boolean retrieveFromCache)
3265                    throws SystemException {
3266                    Object[] finderArgs = new Object[] {
3267                                    groupId, userId, createDate, classNameId, classPK, type,
3268                                    receiverUserId
3269                            };
3270    
3271                    Object result = null;
3272    
3273                    if (retrieveFromCache) {
3274                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
3275                                            finderArgs, this);
3276                    }
3277    
3278                    if (result == null) {
3279                            Session session = null;
3280    
3281                            try {
3282                                    session = openSession();
3283    
3284                                    StringBundler query = new StringBundler(9);
3285    
3286                                    query.append(_SQL_SELECT_SOCIALACTIVITY_WHERE);
3287    
3288                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_GROUPID_2);
3289    
3290                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_USERID_2);
3291    
3292                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CREATEDATE_2);
3293    
3294                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSNAMEID_2);
3295    
3296                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSPK_2);
3297    
3298                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_TYPE_2);
3299    
3300                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_RECEIVERUSERID_2);
3301    
3302                                    query.append(SocialActivityModelImpl.ORDER_BY_JPQL);
3303    
3304                                    String sql = query.toString();
3305    
3306                                    Query q = session.createQuery(sql);
3307    
3308                                    QueryPos qPos = QueryPos.getInstance(q);
3309    
3310                                    qPos.add(groupId);
3311    
3312                                    qPos.add(userId);
3313    
3314                                    qPos.add(createDate);
3315    
3316                                    qPos.add(classNameId);
3317    
3318                                    qPos.add(classPK);
3319    
3320                                    qPos.add(type);
3321    
3322                                    qPos.add(receiverUserId);
3323    
3324                                    List<SocialActivity> list = q.list();
3325    
3326                                    result = list;
3327    
3328                                    SocialActivity socialActivity = null;
3329    
3330                                    if (list.isEmpty()) {
3331                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
3332                                                    finderArgs, list);
3333                                    }
3334                                    else {
3335                                            socialActivity = list.get(0);
3336    
3337                                            cacheResult(socialActivity);
3338    
3339                                            if ((socialActivity.getGroupId() != groupId) ||
3340                                                            (socialActivity.getUserId() != userId) ||
3341                                                            (socialActivity.getCreateDate() != createDate) ||
3342                                                            (socialActivity.getClassNameId() != classNameId) ||
3343                                                            (socialActivity.getClassPK() != classPK) ||
3344                                                            (socialActivity.getType() != type) ||
3345                                                            (socialActivity.getReceiverUserId() != receiverUserId)) {
3346                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
3347                                                            finderArgs, socialActivity);
3348                                            }
3349                                    }
3350    
3351                                    return socialActivity;
3352                            }
3353                            catch (Exception e) {
3354                                    throw processException(e);
3355                            }
3356                            finally {
3357                                    if (result == null) {
3358                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_CD_C_C_T_R,
3359                                                    finderArgs, new ArrayList<SocialActivity>());
3360                                    }
3361    
3362                                    closeSession(session);
3363                            }
3364                    }
3365                    else {
3366                            if (result instanceof List<?>) {
3367                                    return null;
3368                            }
3369                            else {
3370                                    return (SocialActivity)result;
3371                            }
3372                    }
3373            }
3374    
3375            /**
3376             * Finds all the social activities.
3377             *
3378             * @return the social activities
3379             * @throws SystemException if a system exception occurred
3380             */
3381            public List<SocialActivity> findAll() throws SystemException {
3382                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3383            }
3384    
3385            /**
3386             * Finds a range of all the social activities.
3387             *
3388             * <p>
3389             * 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.
3390             * </p>
3391             *
3392             * @param start the lower bound of the range of social activities to return
3393             * @param end the upper bound of the range of social activities to return (not inclusive)
3394             * @return the range of social activities
3395             * @throws SystemException if a system exception occurred
3396             */
3397            public List<SocialActivity> findAll(int start, int end)
3398                    throws SystemException {
3399                    return findAll(start, end, null);
3400            }
3401    
3402            /**
3403             * Finds an ordered range of all the social activities.
3404             *
3405             * <p>
3406             * 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.
3407             * </p>
3408             *
3409             * @param start the lower bound of the range of social activities to return
3410             * @param end the upper bound of the range of social activities to return (not inclusive)
3411             * @param orderByComparator the comparator to order the results by
3412             * @return the ordered range of social activities
3413             * @throws SystemException if a system exception occurred
3414             */
3415            public List<SocialActivity> findAll(int start, int end,
3416                    OrderByComparator orderByComparator) throws SystemException {
3417                    Object[] finderArgs = new Object[] {
3418                                    String.valueOf(start), String.valueOf(end),
3419                                    String.valueOf(orderByComparator)
3420                            };
3421    
3422                    List<SocialActivity> list = (List<SocialActivity>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3423                                    finderArgs, this);
3424    
3425                    if (list == null) {
3426                            Session session = null;
3427    
3428                            try {
3429                                    session = openSession();
3430    
3431                                    StringBundler query = null;
3432                                    String sql = null;
3433    
3434                                    if (orderByComparator != null) {
3435                                            query = new StringBundler(2 +
3436                                                            (orderByComparator.getOrderByFields().length * 3));
3437    
3438                                            query.append(_SQL_SELECT_SOCIALACTIVITY);
3439    
3440                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3441                                                    orderByComparator);
3442    
3443                                            sql = query.toString();
3444                                    }
3445                                    else {
3446                                            sql = _SQL_SELECT_SOCIALACTIVITY.concat(SocialActivityModelImpl.ORDER_BY_JPQL);
3447                                    }
3448    
3449                                    Query q = session.createQuery(sql);
3450    
3451                                    if (orderByComparator == null) {
3452                                            list = (List<SocialActivity>)QueryUtil.list(q,
3453                                                            getDialect(), start, end, false);
3454    
3455                                            Collections.sort(list);
3456                                    }
3457                                    else {
3458                                            list = (List<SocialActivity>)QueryUtil.list(q,
3459                                                            getDialect(), start, end);
3460                                    }
3461                            }
3462                            catch (Exception e) {
3463                                    throw processException(e);
3464                            }
3465                            finally {
3466                                    if (list == null) {
3467                                            list = new ArrayList<SocialActivity>();
3468                                    }
3469    
3470                                    cacheResult(list);
3471    
3472                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3473    
3474                                    closeSession(session);
3475                            }
3476                    }
3477    
3478                    return list;
3479            }
3480    
3481            /**
3482             * Removes all the social activities where groupId = &#63; from the database.
3483             *
3484             * @param groupId the group id to search with
3485             * @throws SystemException if a system exception occurred
3486             */
3487            public void removeByGroupId(long groupId) throws SystemException {
3488                    for (SocialActivity socialActivity : findByGroupId(groupId)) {
3489                            remove(socialActivity);
3490                    }
3491            }
3492    
3493            /**
3494             * Removes all the social activities where companyId = &#63; from the database.
3495             *
3496             * @param companyId the company id to search with
3497             * @throws SystemException if a system exception occurred
3498             */
3499            public void removeByCompanyId(long companyId) throws SystemException {
3500                    for (SocialActivity socialActivity : findByCompanyId(companyId)) {
3501                            remove(socialActivity);
3502                    }
3503            }
3504    
3505            /**
3506             * Removes all the social activities where userId = &#63; from the database.
3507             *
3508             * @param userId the user id to search with
3509             * @throws SystemException if a system exception occurred
3510             */
3511            public void removeByUserId(long userId) throws SystemException {
3512                    for (SocialActivity socialActivity : findByUserId(userId)) {
3513                            remove(socialActivity);
3514                    }
3515            }
3516    
3517            /**
3518             * Removes the social activity where mirrorActivityId = &#63; from the database.
3519             *
3520             * @param mirrorActivityId the mirror activity id to search with
3521             * @throws SystemException if a system exception occurred
3522             */
3523            public void removeByMirrorActivityId(long mirrorActivityId)
3524                    throws NoSuchActivityException, SystemException {
3525                    SocialActivity socialActivity = findByMirrorActivityId(mirrorActivityId);
3526    
3527                    remove(socialActivity);
3528            }
3529    
3530            /**
3531             * Removes all the social activities where classNameId = &#63; from the database.
3532             *
3533             * @param classNameId the class name id to search with
3534             * @throws SystemException if a system exception occurred
3535             */
3536            public void removeByClassNameId(long classNameId) throws SystemException {
3537                    for (SocialActivity socialActivity : findByClassNameId(classNameId)) {
3538                            remove(socialActivity);
3539                    }
3540            }
3541    
3542            /**
3543             * Removes all the social activities where receiverUserId = &#63; from the database.
3544             *
3545             * @param receiverUserId the receiver user id to search with
3546             * @throws SystemException if a system exception occurred
3547             */
3548            public void removeByReceiverUserId(long receiverUserId)
3549                    throws SystemException {
3550                    for (SocialActivity socialActivity : findByReceiverUserId(
3551                                    receiverUserId)) {
3552                            remove(socialActivity);
3553                    }
3554            }
3555    
3556            /**
3557             * Removes all the social activities where classNameId = &#63; and classPK = &#63; from the database.
3558             *
3559             * @param classNameId the class name id to search with
3560             * @param classPK the class p k to search with
3561             * @throws SystemException if a system exception occurred
3562             */
3563            public void removeByC_C(long classNameId, long classPK)
3564                    throws SystemException {
3565                    for (SocialActivity socialActivity : findByC_C(classNameId, classPK)) {
3566                            remove(socialActivity);
3567                    }
3568            }
3569    
3570            /**
3571             * Removes all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
3572             *
3573             * @param mirrorActivityId the mirror activity id to search with
3574             * @param classNameId the class name id to search with
3575             * @param classPK the class p k to search with
3576             * @throws SystemException if a system exception occurred
3577             */
3578            public void removeByM_C_C(long mirrorActivityId, long classNameId,
3579                    long classPK) throws SystemException {
3580                    for (SocialActivity socialActivity : findByM_C_C(mirrorActivityId,
3581                                    classNameId, classPK)) {
3582                            remove(socialActivity);
3583                    }
3584            }
3585    
3586            /**
3587             * 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.
3588             *
3589             * @param groupId the group id to search with
3590             * @param userId the user id to search with
3591             * @param createDate the create date to search with
3592             * @param classNameId the class name id to search with
3593             * @param classPK the class p k to search with
3594             * @param type the type to search with
3595             * @param receiverUserId the receiver user id to search with
3596             * @throws SystemException if a system exception occurred
3597             */
3598            public void removeByG_U_CD_C_C_T_R(long groupId, long userId,
3599                    long createDate, long classNameId, long classPK, int type,
3600                    long receiverUserId) throws NoSuchActivityException, SystemException {
3601                    SocialActivity socialActivity = findByG_U_CD_C_C_T_R(groupId, userId,
3602                                    createDate, classNameId, classPK, type, receiverUserId);
3603    
3604                    remove(socialActivity);
3605            }
3606    
3607            /**
3608             * Removes all the social activities from the database.
3609             *
3610             * @throws SystemException if a system exception occurred
3611             */
3612            public void removeAll() throws SystemException {
3613                    for (SocialActivity socialActivity : findAll()) {
3614                            remove(socialActivity);
3615                    }
3616            }
3617    
3618            /**
3619             * Counts all the social activities where groupId = &#63;.
3620             *
3621             * @param groupId the group id to search with
3622             * @return the number of matching social activities
3623             * @throws SystemException if a system exception occurred
3624             */
3625            public int countByGroupId(long groupId) throws SystemException {
3626                    Object[] finderArgs = new Object[] { groupId };
3627    
3628                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3629                                    finderArgs, this);
3630    
3631                    if (count == null) {
3632                            Session session = null;
3633    
3634                            try {
3635                                    session = openSession();
3636    
3637                                    StringBundler query = new StringBundler(2);
3638    
3639                                    query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
3640    
3641                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3642    
3643                                    String sql = query.toString();
3644    
3645                                    Query q = session.createQuery(sql);
3646    
3647                                    QueryPos qPos = QueryPos.getInstance(q);
3648    
3649                                    qPos.add(groupId);
3650    
3651                                    count = (Long)q.uniqueResult();
3652                            }
3653                            catch (Exception e) {
3654                                    throw processException(e);
3655                            }
3656                            finally {
3657                                    if (count == null) {
3658                                            count = Long.valueOf(0);
3659                                    }
3660    
3661                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3662                                            finderArgs, count);
3663    
3664                                    closeSession(session);
3665                            }
3666                    }
3667    
3668                    return count.intValue();
3669            }
3670    
3671            /**
3672             * Counts all the social activities where companyId = &#63;.
3673             *
3674             * @param companyId the company id to search with
3675             * @return the number of matching social activities
3676             * @throws SystemException if a system exception occurred
3677             */
3678            public int countByCompanyId(long companyId) throws SystemException {
3679                    Object[] finderArgs = new Object[] { companyId };
3680    
3681                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3682                                    finderArgs, this);
3683    
3684                    if (count == null) {
3685                            Session session = null;
3686    
3687                            try {
3688                                    session = openSession();
3689    
3690                                    StringBundler query = new StringBundler(2);
3691    
3692                                    query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
3693    
3694                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3695    
3696                                    String sql = query.toString();
3697    
3698                                    Query q = session.createQuery(sql);
3699    
3700                                    QueryPos qPos = QueryPos.getInstance(q);
3701    
3702                                    qPos.add(companyId);
3703    
3704                                    count = (Long)q.uniqueResult();
3705                            }
3706                            catch (Exception e) {
3707                                    throw processException(e);
3708                            }
3709                            finally {
3710                                    if (count == null) {
3711                                            count = Long.valueOf(0);
3712                                    }
3713    
3714                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3715                                            finderArgs, count);
3716    
3717                                    closeSession(session);
3718                            }
3719                    }
3720    
3721                    return count.intValue();
3722            }
3723    
3724            /**
3725             * Counts all the social activities where userId = &#63;.
3726             *
3727             * @param userId the user id to search with
3728             * @return the number of matching social activities
3729             * @throws SystemException if a system exception occurred
3730             */
3731            public int countByUserId(long userId) throws SystemException {
3732                    Object[] finderArgs = new Object[] { userId };
3733    
3734                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
3735                                    finderArgs, this);
3736    
3737                    if (count == null) {
3738                            Session session = null;
3739    
3740                            try {
3741                                    session = openSession();
3742    
3743                                    StringBundler query = new StringBundler(2);
3744    
3745                                    query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
3746    
3747                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
3748    
3749                                    String sql = query.toString();
3750    
3751                                    Query q = session.createQuery(sql);
3752    
3753                                    QueryPos qPos = QueryPos.getInstance(q);
3754    
3755                                    qPos.add(userId);
3756    
3757                                    count = (Long)q.uniqueResult();
3758                            }
3759                            catch (Exception e) {
3760                                    throw processException(e);
3761                            }
3762                            finally {
3763                                    if (count == null) {
3764                                            count = Long.valueOf(0);
3765                                    }
3766    
3767                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
3768                                            finderArgs, count);
3769    
3770                                    closeSession(session);
3771                            }
3772                    }
3773    
3774                    return count.intValue();
3775            }
3776    
3777            /**
3778             * Counts all the social activities where mirrorActivityId = &#63;.
3779             *
3780             * @param mirrorActivityId the mirror activity id to search with
3781             * @return the number of matching social activities
3782             * @throws SystemException if a system exception occurred
3783             */
3784            public int countByMirrorActivityId(long mirrorActivityId)
3785                    throws SystemException {
3786                    Object[] finderArgs = new Object[] { mirrorActivityId };
3787    
3788                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MIRRORACTIVITYID,
3789                                    finderArgs, this);
3790    
3791                    if (count == null) {
3792                            Session session = null;
3793    
3794                            try {
3795                                    session = openSession();
3796    
3797                                    StringBundler query = new StringBundler(2);
3798    
3799                                    query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
3800    
3801                                    query.append(_FINDER_COLUMN_MIRRORACTIVITYID_MIRRORACTIVITYID_2);
3802    
3803                                    String sql = query.toString();
3804    
3805                                    Query q = session.createQuery(sql);
3806    
3807                                    QueryPos qPos = QueryPos.getInstance(q);
3808    
3809                                    qPos.add(mirrorActivityId);
3810    
3811                                    count = (Long)q.uniqueResult();
3812                            }
3813                            catch (Exception e) {
3814                                    throw processException(e);
3815                            }
3816                            finally {
3817                                    if (count == null) {
3818                                            count = Long.valueOf(0);
3819                                    }
3820    
3821                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MIRRORACTIVITYID,
3822                                            finderArgs, count);
3823    
3824                                    closeSession(session);
3825                            }
3826                    }
3827    
3828                    return count.intValue();
3829            }
3830    
3831            /**
3832             * Counts all the social activities where classNameId = &#63;.
3833             *
3834             * @param classNameId the class name id to search with
3835             * @return the number of matching social activities
3836             * @throws SystemException if a system exception occurred
3837             */
3838            public int countByClassNameId(long classNameId) throws SystemException {
3839                    Object[] finderArgs = new Object[] { classNameId };
3840    
3841                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
3842                                    finderArgs, this);
3843    
3844                    if (count == null) {
3845                            Session session = null;
3846    
3847                            try {
3848                                    session = openSession();
3849    
3850                                    StringBundler query = new StringBundler(2);
3851    
3852                                    query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
3853    
3854                                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
3855    
3856                                    String sql = query.toString();
3857    
3858                                    Query q = session.createQuery(sql);
3859    
3860                                    QueryPos qPos = QueryPos.getInstance(q);
3861    
3862                                    qPos.add(classNameId);
3863    
3864                                    count = (Long)q.uniqueResult();
3865                            }
3866                            catch (Exception e) {
3867                                    throw processException(e);
3868                            }
3869                            finally {
3870                                    if (count == null) {
3871                                            count = Long.valueOf(0);
3872                                    }
3873    
3874                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
3875                                            finderArgs, count);
3876    
3877                                    closeSession(session);
3878                            }
3879                    }
3880    
3881                    return count.intValue();
3882            }
3883    
3884            /**
3885             * Counts all the social activities where receiverUserId = &#63;.
3886             *
3887             * @param receiverUserId the receiver user id to search with
3888             * @return the number of matching social activities
3889             * @throws SystemException if a system exception occurred
3890             */
3891            public int countByReceiverUserId(long receiverUserId)
3892                    throws SystemException {
3893                    Object[] finderArgs = new Object[] { receiverUserId };
3894    
3895                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
3896                                    finderArgs, this);
3897    
3898                    if (count == null) {
3899                            Session session = null;
3900    
3901                            try {
3902                                    session = openSession();
3903    
3904                                    StringBundler query = new StringBundler(2);
3905    
3906                                    query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
3907    
3908                                    query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
3909    
3910                                    String sql = query.toString();
3911    
3912                                    Query q = session.createQuery(sql);
3913    
3914                                    QueryPos qPos = QueryPos.getInstance(q);
3915    
3916                                    qPos.add(receiverUserId);
3917    
3918                                    count = (Long)q.uniqueResult();
3919                            }
3920                            catch (Exception e) {
3921                                    throw processException(e);
3922                            }
3923                            finally {
3924                                    if (count == null) {
3925                                            count = Long.valueOf(0);
3926                                    }
3927    
3928                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
3929                                            finderArgs, count);
3930    
3931                                    closeSession(session);
3932                            }
3933                    }
3934    
3935                    return count.intValue();
3936            }
3937    
3938            /**
3939             * Counts all the social activities where classNameId = &#63; and classPK = &#63;.
3940             *
3941             * @param classNameId the class name id to search with
3942             * @param classPK the class p k to search with
3943             * @return the number of matching social activities
3944             * @throws SystemException if a system exception occurred
3945             */
3946            public int countByC_C(long classNameId, long classPK)
3947                    throws SystemException {
3948                    Object[] finderArgs = new Object[] { classNameId, classPK };
3949    
3950                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
3951                                    finderArgs, this);
3952    
3953                    if (count == null) {
3954                            Session session = null;
3955    
3956                            try {
3957                                    session = openSession();
3958    
3959                                    StringBundler query = new StringBundler(3);
3960    
3961                                    query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
3962    
3963                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3964    
3965                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3966    
3967                                    String sql = query.toString();
3968    
3969                                    Query q = session.createQuery(sql);
3970    
3971                                    QueryPos qPos = QueryPos.getInstance(q);
3972    
3973                                    qPos.add(classNameId);
3974    
3975                                    qPos.add(classPK);
3976    
3977                                    count = (Long)q.uniqueResult();
3978                            }
3979                            catch (Exception e) {
3980                                    throw processException(e);
3981                            }
3982                            finally {
3983                                    if (count == null) {
3984                                            count = Long.valueOf(0);
3985                                    }
3986    
3987                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
3988                                            count);
3989    
3990                                    closeSession(session);
3991                            }
3992                    }
3993    
3994                    return count.intValue();
3995            }
3996    
3997            /**
3998             * Counts all the social activities where mirrorActivityId = &#63; and classNameId = &#63; and classPK = &#63;.
3999             *
4000             * @param mirrorActivityId the mirror activity id to search with
4001             * @param classNameId the class name id to search with
4002             * @param classPK the class p k to search with
4003             * @return the number of matching social activities
4004             * @throws SystemException if a system exception occurred
4005             */
4006            public int countByM_C_C(long mirrorActivityId, long classNameId,
4007                    long classPK) throws SystemException {
4008                    Object[] finderArgs = new Object[] {
4009                                    mirrorActivityId, classNameId, classPK
4010                            };
4011    
4012                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_M_C_C,
4013                                    finderArgs, this);
4014    
4015                    if (count == null) {
4016                            Session session = null;
4017    
4018                            try {
4019                                    session = openSession();
4020    
4021                                    StringBundler query = new StringBundler(4);
4022    
4023                                    query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4024    
4025                                    query.append(_FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2);
4026    
4027                                    query.append(_FINDER_COLUMN_M_C_C_CLASSNAMEID_2);
4028    
4029                                    query.append(_FINDER_COLUMN_M_C_C_CLASSPK_2);
4030    
4031                                    String sql = query.toString();
4032    
4033                                    Query q = session.createQuery(sql);
4034    
4035                                    QueryPos qPos = QueryPos.getInstance(q);
4036    
4037                                    qPos.add(mirrorActivityId);
4038    
4039                                    qPos.add(classNameId);
4040    
4041                                    qPos.add(classPK);
4042    
4043                                    count = (Long)q.uniqueResult();
4044                            }
4045                            catch (Exception e) {
4046                                    throw processException(e);
4047                            }
4048                            finally {
4049                                    if (count == null) {
4050                                            count = Long.valueOf(0);
4051                                    }
4052    
4053                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_M_C_C,
4054                                            finderArgs, count);
4055    
4056                                    closeSession(session);
4057                            }
4058                    }
4059    
4060                    return count.intValue();
4061            }
4062    
4063            /**
4064             * Counts all the social activities where groupId = &#63; and userId = &#63; and createDate = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
4065             *
4066             * @param groupId the group id to search with
4067             * @param userId the user id to search with
4068             * @param createDate the create date to search with
4069             * @param classNameId the class name id to search with
4070             * @param classPK the class p k to search with
4071             * @param type the type to search with
4072             * @param receiverUserId the receiver user id to search with
4073             * @return the number of matching social activities
4074             * @throws SystemException if a system exception occurred
4075             */
4076            public int countByG_U_CD_C_C_T_R(long groupId, long userId,
4077                    long createDate, long classNameId, long classPK, int type,
4078                    long receiverUserId) throws SystemException {
4079                    Object[] finderArgs = new Object[] {
4080                                    groupId, userId, createDate, classNameId, classPK, type,
4081                                    receiverUserId
4082                            };
4083    
4084                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R,
4085                                    finderArgs, this);
4086    
4087                    if (count == null) {
4088                            Session session = null;
4089    
4090                            try {
4091                                    session = openSession();
4092    
4093                                    StringBundler query = new StringBundler(8);
4094    
4095                                    query.append(_SQL_COUNT_SOCIALACTIVITY_WHERE);
4096    
4097                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_GROUPID_2);
4098    
4099                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_USERID_2);
4100    
4101                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CREATEDATE_2);
4102    
4103                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSNAMEID_2);
4104    
4105                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSPK_2);
4106    
4107                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_TYPE_2);
4108    
4109                                    query.append(_FINDER_COLUMN_G_U_CD_C_C_T_R_RECEIVERUSERID_2);
4110    
4111                                    String sql = query.toString();
4112    
4113                                    Query q = session.createQuery(sql);
4114    
4115                                    QueryPos qPos = QueryPos.getInstance(q);
4116    
4117                                    qPos.add(groupId);
4118    
4119                                    qPos.add(userId);
4120    
4121                                    qPos.add(createDate);
4122    
4123                                    qPos.add(classNameId);
4124    
4125                                    qPos.add(classPK);
4126    
4127                                    qPos.add(type);
4128    
4129                                    qPos.add(receiverUserId);
4130    
4131                                    count = (Long)q.uniqueResult();
4132                            }
4133                            catch (Exception e) {
4134                                    throw processException(e);
4135                            }
4136                            finally {
4137                                    if (count == null) {
4138                                            count = Long.valueOf(0);
4139                                    }
4140    
4141                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_CD_C_C_T_R,
4142                                            finderArgs, count);
4143    
4144                                    closeSession(session);
4145                            }
4146                    }
4147    
4148                    return count.intValue();
4149            }
4150    
4151            /**
4152             * Counts all the social activities.
4153             *
4154             * @return the number of social activities
4155             * @throws SystemException if a system exception occurred
4156             */
4157            public int countAll() throws SystemException {
4158                    Object[] finderArgs = new Object[0];
4159    
4160                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4161                                    finderArgs, this);
4162    
4163                    if (count == null) {
4164                            Session session = null;
4165    
4166                            try {
4167                                    session = openSession();
4168    
4169                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITY);
4170    
4171                                    count = (Long)q.uniqueResult();
4172                            }
4173                            catch (Exception e) {
4174                                    throw processException(e);
4175                            }
4176                            finally {
4177                                    if (count == null) {
4178                                            count = Long.valueOf(0);
4179                                    }
4180    
4181                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
4182                                            count);
4183    
4184                                    closeSession(session);
4185                            }
4186                    }
4187    
4188                    return count.intValue();
4189            }
4190    
4191            /**
4192             * Initializes the social activity persistence.
4193             */
4194            public void afterPropertiesSet() {
4195                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4196                                            com.liferay.portal.util.PropsUtil.get(
4197                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivity")));
4198    
4199                    if (listenerClassNames.length > 0) {
4200                            try {
4201                                    List<ModelListener<SocialActivity>> listenersList = new ArrayList<ModelListener<SocialActivity>>();
4202    
4203                                    for (String listenerClassName : listenerClassNames) {
4204                                            listenersList.add((ModelListener<SocialActivity>)InstanceFactory.newInstance(
4205                                                            listenerClassName));
4206                                    }
4207    
4208                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4209                            }
4210                            catch (Exception e) {
4211                                    _log.error(e);
4212                            }
4213                    }
4214            }
4215    
4216            @BeanReference(type = SocialActivityPersistence.class)
4217            protected SocialActivityPersistence socialActivityPersistence;
4218            @BeanReference(type = SocialEquityAssetEntryPersistence.class)
4219            protected SocialEquityAssetEntryPersistence socialEquityAssetEntryPersistence;
4220            @BeanReference(type = SocialEquityHistoryPersistence.class)
4221            protected SocialEquityHistoryPersistence socialEquityHistoryPersistence;
4222            @BeanReference(type = SocialEquityLogPersistence.class)
4223            protected SocialEquityLogPersistence socialEquityLogPersistence;
4224            @BeanReference(type = SocialEquitySettingPersistence.class)
4225            protected SocialEquitySettingPersistence socialEquitySettingPersistence;
4226            @BeanReference(type = SocialEquityUserPersistence.class)
4227            protected SocialEquityUserPersistence socialEquityUserPersistence;
4228            @BeanReference(type = SocialRelationPersistence.class)
4229            protected SocialRelationPersistence socialRelationPersistence;
4230            @BeanReference(type = SocialRequestPersistence.class)
4231            protected SocialRequestPersistence socialRequestPersistence;
4232            @BeanReference(type = GroupPersistence.class)
4233            protected GroupPersistence groupPersistence;
4234            @BeanReference(type = LayoutPersistence.class)
4235            protected LayoutPersistence layoutPersistence;
4236            @BeanReference(type = ResourcePersistence.class)
4237            protected ResourcePersistence resourcePersistence;
4238            @BeanReference(type = UserPersistence.class)
4239            protected UserPersistence userPersistence;
4240            private static final String _SQL_SELECT_SOCIALACTIVITY = "SELECT socialActivity FROM SocialActivity socialActivity";
4241            private static final String _SQL_SELECT_SOCIALACTIVITY_WHERE = "SELECT socialActivity FROM SocialActivity socialActivity WHERE ";
4242            private static final String _SQL_COUNT_SOCIALACTIVITY = "SELECT COUNT(socialActivity) FROM SocialActivity socialActivity";
4243            private static final String _SQL_COUNT_SOCIALACTIVITY_WHERE = "SELECT COUNT(socialActivity) FROM SocialActivity socialActivity WHERE ";
4244            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "socialActivity.groupId = ?";
4245            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialActivity.companyId = ?";
4246            private static final String _FINDER_COLUMN_USERID_USERID_2 = "socialActivity.userId = ?";
4247            private static final String _FINDER_COLUMN_MIRRORACTIVITYID_MIRRORACTIVITYID_2 =
4248                    "socialActivity.mirrorActivityId = ?";
4249            private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "socialActivity.classNameId = ?";
4250            private static final String _FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2 = "socialActivity.receiverUserId = ?";
4251            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
4252            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "socialActivity.classPK = ?";
4253            private static final String _FINDER_COLUMN_M_C_C_MIRRORACTIVITYID_2 = "socialActivity.mirrorActivityId = ? AND ";
4254            private static final String _FINDER_COLUMN_M_C_C_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
4255            private static final String _FINDER_COLUMN_M_C_C_CLASSPK_2 = "socialActivity.classPK = ?";
4256            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_GROUPID_2 = "socialActivity.groupId = ? AND ";
4257            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_USERID_2 = "socialActivity.userId = ? AND ";
4258            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_CREATEDATE_2 = "socialActivity.createDate = ? AND ";
4259            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSNAMEID_2 = "socialActivity.classNameId = ? AND ";
4260            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_CLASSPK_2 = "socialActivity.classPK = ? AND ";
4261            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_TYPE_2 = "socialActivity.type = ? AND ";
4262            private static final String _FINDER_COLUMN_G_U_CD_C_C_T_R_RECEIVERUSERID_2 = "socialActivity.receiverUserId = ?";
4263            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivity.";
4264            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivity exists with the primary key ";
4265            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivity exists with the key {";
4266            private static Log _log = LogFactoryUtil.getLog(SocialActivityPersistenceImpl.class);
4267    }