001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.GroupPersistence;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.social.NoSuchActivityAchievementException;
046    import com.liferay.portlet.social.model.SocialActivityAchievement;
047    import com.liferay.portlet.social.model.impl.SocialActivityAchievementImpl;
048    import com.liferay.portlet.social.model.impl.SocialActivityAchievementModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the social activity achievement service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see SocialActivityAchievementPersistence
065     * @see SocialActivityAchievementUtil
066     * @generated
067     */
068    public class SocialActivityAchievementPersistenceImpl
069            extends BasePersistenceImpl<SocialActivityAchievement>
070            implements SocialActivityAchievementPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * Never modify or reference this class directly. Always use {@link SocialActivityAchievementUtil} to access the social activity achievement persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivityAchievementImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
082                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
083                            SocialActivityAchievementImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
085                            new String[] {
086                                    Long.class.getName(),
087                                    
088                            "java.lang.Integer", "java.lang.Integer",
089                                    "com.liferay.portal.kernel.util.OrderByComparator"
090                            });
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
092                    new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
093                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
094                            SocialActivityAchievementImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
096                            new String[] { Long.class.getName() },
097                            SocialActivityAchievementModelImpl.GROUPID_COLUMN_BITMASK);
098            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
099                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
100                            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
101                            "countByGroupId", new String[] { Long.class.getName() });
102            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
103                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
104                            SocialActivityAchievementImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
106                            new String[] {
107                                    Long.class.getName(), Long.class.getName(),
108                                    
109                            "java.lang.Integer", "java.lang.Integer",
110                                    "com.liferay.portal.kernel.util.OrderByComparator"
111                            });
112            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
113                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
114                            SocialActivityAchievementImpl.class,
115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
116                            new String[] { Long.class.getName(), Long.class.getName() },
117                            SocialActivityAchievementModelImpl.GROUPID_COLUMN_BITMASK |
118                            SocialActivityAchievementModelImpl.USERID_COLUMN_BITMASK);
119            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
120                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
121                            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
122                            "countByG_U",
123                            new String[] { Long.class.getName(), Long.class.getName() });
124            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
125                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
126                            SocialActivityAchievementImpl.class,
127                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_N",
128                            new String[] {
129                                    Long.class.getName(), String.class.getName(),
130                                    
131                            "java.lang.Integer", "java.lang.Integer",
132                                    "com.liferay.portal.kernel.util.OrderByComparator"
133                            });
134            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
135                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
136                            SocialActivityAchievementImpl.class,
137                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N",
138                            new String[] { Long.class.getName(), String.class.getName() },
139                            SocialActivityAchievementModelImpl.GROUPID_COLUMN_BITMASK |
140                            SocialActivityAchievementModelImpl.NAME_COLUMN_BITMASK);
141            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
142                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
143                            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
144                            "countByG_N",
145                            new String[] { Long.class.getName(), String.class.getName() });
146            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
147                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
148                            SocialActivityAchievementImpl.class,
149                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_F",
150                            new String[] {
151                                    Long.class.getName(), Boolean.class.getName(),
152                                    
153                            "java.lang.Integer", "java.lang.Integer",
154                                    "com.liferay.portal.kernel.util.OrderByComparator"
155                            });
156            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
157                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
158                            SocialActivityAchievementImpl.class,
159                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_F",
160                            new String[] { Long.class.getName(), Boolean.class.getName() },
161                            SocialActivityAchievementModelImpl.GROUPID_COLUMN_BITMASK |
162                            SocialActivityAchievementModelImpl.FIRSTINGROUP_COLUMN_BITMASK);
163            public static final FinderPath FINDER_PATH_COUNT_BY_G_F = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
164                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
165                            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
166                            "countByG_F",
167                            new String[] { Long.class.getName(), Boolean.class.getName() });
168            public static final FinderPath FINDER_PATH_FETCH_BY_G_U_N = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
169                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
170                            SocialActivityAchievementImpl.class, FINDER_CLASS_NAME_ENTITY,
171                            "fetchByG_U_N",
172                            new String[] {
173                                    Long.class.getName(), Long.class.getName(),
174                                    String.class.getName()
175                            },
176                            SocialActivityAchievementModelImpl.GROUPID_COLUMN_BITMASK |
177                            SocialActivityAchievementModelImpl.USERID_COLUMN_BITMASK |
178                            SocialActivityAchievementModelImpl.NAME_COLUMN_BITMASK);
179            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_N = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
180                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
181                            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
182                            "countByG_U_N",
183                            new String[] {
184                                    Long.class.getName(), Long.class.getName(),
185                                    String.class.getName()
186                            });
187            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_F = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
188                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
189                            SocialActivityAchievementImpl.class,
190                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_F",
191                            new String[] {
192                                    Long.class.getName(), Long.class.getName(),
193                                    Boolean.class.getName(),
194                                    
195                            "java.lang.Integer", "java.lang.Integer",
196                                    "com.liferay.portal.kernel.util.OrderByComparator"
197                            });
198            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_F = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
199                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
200                            SocialActivityAchievementImpl.class,
201                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_F",
202                            new String[] {
203                                    Long.class.getName(), Long.class.getName(),
204                                    Boolean.class.getName()
205                            },
206                            SocialActivityAchievementModelImpl.GROUPID_COLUMN_BITMASK |
207                            SocialActivityAchievementModelImpl.USERID_COLUMN_BITMASK |
208                            SocialActivityAchievementModelImpl.FIRSTINGROUP_COLUMN_BITMASK);
209            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_F = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
210                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
211                            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
212                            "countByG_U_F",
213                            new String[] {
214                                    Long.class.getName(), Long.class.getName(),
215                                    Boolean.class.getName()
216                            });
217            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
218                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
219                            SocialActivityAchievementImpl.class,
220                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
221            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
222                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
223                            SocialActivityAchievementImpl.class,
224                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
225            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
226                            SocialActivityAchievementModelImpl.FINDER_CACHE_ENABLED,
227                            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll",
228                            new String[0]);
229    
230            /**
231             * Caches the social activity achievement in the entity cache if it is enabled.
232             *
233             * @param socialActivityAchievement the social activity achievement
234             */
235            public void cacheResult(SocialActivityAchievement socialActivityAchievement) {
236                    EntityCacheUtil.putResult(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
237                            SocialActivityAchievementImpl.class,
238                            socialActivityAchievement.getPrimaryKey(), socialActivityAchievement);
239    
240                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_N,
241                            new Object[] {
242                                    Long.valueOf(socialActivityAchievement.getGroupId()),
243                                    Long.valueOf(socialActivityAchievement.getUserId()),
244                                    
245                            socialActivityAchievement.getName()
246                            }, socialActivityAchievement);
247    
248                    socialActivityAchievement.resetOriginalValues();
249            }
250    
251            /**
252             * Caches the social activity achievements in the entity cache if it is enabled.
253             *
254             * @param socialActivityAchievements the social activity achievements
255             */
256            public void cacheResult(
257                    List<SocialActivityAchievement> socialActivityAchievements) {
258                    for (SocialActivityAchievement socialActivityAchievement : socialActivityAchievements) {
259                            if (EntityCacheUtil.getResult(
260                                                    SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
261                                                    SocialActivityAchievementImpl.class,
262                                                    socialActivityAchievement.getPrimaryKey()) == null) {
263                                    cacheResult(socialActivityAchievement);
264                            }
265                            else {
266                                    socialActivityAchievement.resetOriginalValues();
267                            }
268                    }
269            }
270    
271            /**
272             * Clears the cache for all social activity achievements.
273             *
274             * <p>
275             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
276             * </p>
277             */
278            @Override
279            public void clearCache() {
280                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
281                            CacheRegistryUtil.clear(SocialActivityAchievementImpl.class.getName());
282                    }
283    
284                    EntityCacheUtil.clearCache(SocialActivityAchievementImpl.class.getName());
285    
286                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
287                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
288                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
289            }
290    
291            /**
292             * Clears the cache for the social activity achievement.
293             *
294             * <p>
295             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
296             * </p>
297             */
298            @Override
299            public void clearCache(SocialActivityAchievement socialActivityAchievement) {
300                    EntityCacheUtil.removeResult(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
301                            SocialActivityAchievementImpl.class,
302                            socialActivityAchievement.getPrimaryKey());
303    
304                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
305                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
306    
307                    clearUniqueFindersCache(socialActivityAchievement);
308            }
309    
310            @Override
311            public void clearCache(
312                    List<SocialActivityAchievement> socialActivityAchievements) {
313                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
314                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
315    
316                    for (SocialActivityAchievement socialActivityAchievement : socialActivityAchievements) {
317                            EntityCacheUtil.removeResult(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
318                                    SocialActivityAchievementImpl.class,
319                                    socialActivityAchievement.getPrimaryKey());
320    
321                            clearUniqueFindersCache(socialActivityAchievement);
322                    }
323            }
324    
325            protected void cacheUniqueFindersCache(
326                    SocialActivityAchievement socialActivityAchievement) {
327                    if (socialActivityAchievement.isNew()) {
328                            Object[] args = new Object[] {
329                                            Long.valueOf(socialActivityAchievement.getGroupId()),
330                                            Long.valueOf(socialActivityAchievement.getUserId()),
331                                            
332                                            socialActivityAchievement.getName()
333                                    };
334    
335                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_N, args,
336                                    Long.valueOf(1));
337                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_N, args,
338                                    socialActivityAchievement);
339                    }
340                    else {
341                            SocialActivityAchievementModelImpl socialActivityAchievementModelImpl =
342                                    (SocialActivityAchievementModelImpl)socialActivityAchievement;
343    
344                            if ((socialActivityAchievementModelImpl.getColumnBitmask() &
345                                            FINDER_PATH_FETCH_BY_G_U_N.getColumnBitmask()) != 0) {
346                                    Object[] args = new Object[] {
347                                                    Long.valueOf(socialActivityAchievement.getGroupId()),
348                                                    Long.valueOf(socialActivityAchievement.getUserId()),
349                                                    
350                                                    socialActivityAchievement.getName()
351                                            };
352    
353                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_N, args,
354                                            Long.valueOf(1));
355                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_N, args,
356                                            socialActivityAchievement);
357                            }
358                    }
359            }
360    
361            protected void clearUniqueFindersCache(
362                    SocialActivityAchievement socialActivityAchievement) {
363                    SocialActivityAchievementModelImpl socialActivityAchievementModelImpl = (SocialActivityAchievementModelImpl)socialActivityAchievement;
364    
365                    Object[] args = new Object[] {
366                                    Long.valueOf(socialActivityAchievement.getGroupId()),
367                                    Long.valueOf(socialActivityAchievement.getUserId()),
368                                    
369                                    socialActivityAchievement.getName()
370                            };
371    
372                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N, args);
373                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_N, args);
374    
375                    if ((socialActivityAchievementModelImpl.getColumnBitmask() &
376                                    FINDER_PATH_FETCH_BY_G_U_N.getColumnBitmask()) != 0) {
377                            args = new Object[] {
378                                            Long.valueOf(socialActivityAchievementModelImpl.getOriginalGroupId()),
379                                            Long.valueOf(socialActivityAchievementModelImpl.getOriginalUserId()),
380                                            
381                                            socialActivityAchievementModelImpl.getOriginalName()
382                                    };
383    
384                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_N, args);
385                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_N, args);
386                    }
387            }
388    
389            /**
390             * Creates a new social activity achievement with the primary key. Does not add the social activity achievement to the database.
391             *
392             * @param activityAchievementId the primary key for the new social activity achievement
393             * @return the new social activity achievement
394             */
395            public SocialActivityAchievement create(long activityAchievementId) {
396                    SocialActivityAchievement socialActivityAchievement = new SocialActivityAchievementImpl();
397    
398                    socialActivityAchievement.setNew(true);
399                    socialActivityAchievement.setPrimaryKey(activityAchievementId);
400    
401                    return socialActivityAchievement;
402            }
403    
404            /**
405             * Removes the social activity achievement with the primary key from the database. Also notifies the appropriate model listeners.
406             *
407             * @param activityAchievementId the primary key of the social activity achievement
408             * @return the social activity achievement that was removed
409             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a social activity achievement with the primary key could not be found
410             * @throws SystemException if a system exception occurred
411             */
412            public SocialActivityAchievement remove(long activityAchievementId)
413                    throws NoSuchActivityAchievementException, SystemException {
414                    return remove(Long.valueOf(activityAchievementId));
415            }
416    
417            /**
418             * Removes the social activity achievement with the primary key from the database. Also notifies the appropriate model listeners.
419             *
420             * @param primaryKey the primary key of the social activity achievement
421             * @return the social activity achievement that was removed
422             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a social activity achievement with the primary key could not be found
423             * @throws SystemException if a system exception occurred
424             */
425            @Override
426            public SocialActivityAchievement remove(Serializable primaryKey)
427                    throws NoSuchActivityAchievementException, SystemException {
428                    Session session = null;
429    
430                    try {
431                            session = openSession();
432    
433                            SocialActivityAchievement socialActivityAchievement = (SocialActivityAchievement)session.get(SocialActivityAchievementImpl.class,
434                                            primaryKey);
435    
436                            if (socialActivityAchievement == null) {
437                                    if (_log.isWarnEnabled()) {
438                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
439                                    }
440    
441                                    throw new NoSuchActivityAchievementException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
442                                            primaryKey);
443                            }
444    
445                            return remove(socialActivityAchievement);
446                    }
447                    catch (NoSuchActivityAchievementException nsee) {
448                            throw nsee;
449                    }
450                    catch (Exception e) {
451                            throw processException(e);
452                    }
453                    finally {
454                            closeSession(session);
455                    }
456            }
457    
458            @Override
459            protected SocialActivityAchievement removeImpl(
460                    SocialActivityAchievement socialActivityAchievement)
461                    throws SystemException {
462                    socialActivityAchievement = toUnwrappedModel(socialActivityAchievement);
463    
464                    Session session = null;
465    
466                    try {
467                            session = openSession();
468    
469                            BatchSessionUtil.delete(session, socialActivityAchievement);
470                    }
471                    catch (Exception e) {
472                            throw processException(e);
473                    }
474                    finally {
475                            closeSession(session);
476                    }
477    
478                    clearCache(socialActivityAchievement);
479    
480                    return socialActivityAchievement;
481            }
482    
483            @Override
484            public SocialActivityAchievement updateImpl(
485                    com.liferay.portlet.social.model.SocialActivityAchievement socialActivityAchievement,
486                    boolean merge) throws SystemException {
487                    socialActivityAchievement = toUnwrappedModel(socialActivityAchievement);
488    
489                    boolean isNew = socialActivityAchievement.isNew();
490    
491                    SocialActivityAchievementModelImpl socialActivityAchievementModelImpl = (SocialActivityAchievementModelImpl)socialActivityAchievement;
492    
493                    Session session = null;
494    
495                    try {
496                            session = openSession();
497    
498                            BatchSessionUtil.update(session, socialActivityAchievement, merge);
499    
500                            socialActivityAchievement.setNew(false);
501                    }
502                    catch (Exception e) {
503                            throw processException(e);
504                    }
505                    finally {
506                            closeSession(session);
507                    }
508    
509                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
510    
511                    if (isNew ||
512                                    !SocialActivityAchievementModelImpl.COLUMN_BITMASK_ENABLED) {
513                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
514                    }
515    
516                    else {
517                            if ((socialActivityAchievementModelImpl.getColumnBitmask() &
518                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
519                                    Object[] args = new Object[] {
520                                                    Long.valueOf(socialActivityAchievementModelImpl.getOriginalGroupId())
521                                            };
522    
523                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
524                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
525                                            args);
526    
527                                    args = new Object[] {
528                                                    Long.valueOf(socialActivityAchievementModelImpl.getGroupId())
529                                            };
530    
531                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
532                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
533                                            args);
534                            }
535    
536                            if ((socialActivityAchievementModelImpl.getColumnBitmask() &
537                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
538                                    Object[] args = new Object[] {
539                                                    Long.valueOf(socialActivityAchievementModelImpl.getOriginalGroupId()),
540                                                    Long.valueOf(socialActivityAchievementModelImpl.getOriginalUserId())
541                                            };
542    
543                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
544                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
545                                            args);
546    
547                                    args = new Object[] {
548                                                    Long.valueOf(socialActivityAchievementModelImpl.getGroupId()),
549                                                    Long.valueOf(socialActivityAchievementModelImpl.getUserId())
550                                            };
551    
552                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
553                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
554                                            args);
555                            }
556    
557                            if ((socialActivityAchievementModelImpl.getColumnBitmask() &
558                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N.getColumnBitmask()) != 0) {
559                                    Object[] args = new Object[] {
560                                                    Long.valueOf(socialActivityAchievementModelImpl.getOriginalGroupId()),
561                                                    
562                                                    socialActivityAchievementModelImpl.getOriginalName()
563                                            };
564    
565                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
566                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N,
567                                            args);
568    
569                                    args = new Object[] {
570                                                    Long.valueOf(socialActivityAchievementModelImpl.getGroupId()),
571                                                    
572                                                    socialActivityAchievementModelImpl.getName()
573                                            };
574    
575                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
576                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N,
577                                            args);
578                            }
579    
580                            if ((socialActivityAchievementModelImpl.getColumnBitmask() &
581                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F.getColumnBitmask()) != 0) {
582                                    Object[] args = new Object[] {
583                                                    Long.valueOf(socialActivityAchievementModelImpl.getOriginalGroupId()),
584                                                    Boolean.valueOf(socialActivityAchievementModelImpl.getOriginalFirstInGroup())
585                                            };
586    
587                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F, args);
588                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F,
589                                            args);
590    
591                                    args = new Object[] {
592                                                    Long.valueOf(socialActivityAchievementModelImpl.getGroupId()),
593                                                    Boolean.valueOf(socialActivityAchievementModelImpl.getFirstInGroup())
594                                            };
595    
596                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F, args);
597                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F,
598                                            args);
599                            }
600    
601                            if ((socialActivityAchievementModelImpl.getColumnBitmask() &
602                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_F.getColumnBitmask()) != 0) {
603                                    Object[] args = new Object[] {
604                                                    Long.valueOf(socialActivityAchievementModelImpl.getOriginalGroupId()),
605                                                    Long.valueOf(socialActivityAchievementModelImpl.getOriginalUserId()),
606                                                    Boolean.valueOf(socialActivityAchievementModelImpl.getOriginalFirstInGroup())
607                                            };
608    
609                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_F, args);
610                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_F,
611                                            args);
612    
613                                    args = new Object[] {
614                                                    Long.valueOf(socialActivityAchievementModelImpl.getGroupId()),
615                                                    Long.valueOf(socialActivityAchievementModelImpl.getUserId()),
616                                                    Boolean.valueOf(socialActivityAchievementModelImpl.getFirstInGroup())
617                                            };
618    
619                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_F, args);
620                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_F,
621                                            args);
622                            }
623                    }
624    
625                    EntityCacheUtil.putResult(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
626                            SocialActivityAchievementImpl.class,
627                            socialActivityAchievement.getPrimaryKey(), socialActivityAchievement);
628    
629                    clearUniqueFindersCache(socialActivityAchievement);
630                    cacheUniqueFindersCache(socialActivityAchievement);
631    
632                    return socialActivityAchievement;
633            }
634    
635            protected SocialActivityAchievement toUnwrappedModel(
636                    SocialActivityAchievement socialActivityAchievement) {
637                    if (socialActivityAchievement instanceof SocialActivityAchievementImpl) {
638                            return socialActivityAchievement;
639                    }
640    
641                    SocialActivityAchievementImpl socialActivityAchievementImpl = new SocialActivityAchievementImpl();
642    
643                    socialActivityAchievementImpl.setNew(socialActivityAchievement.isNew());
644                    socialActivityAchievementImpl.setPrimaryKey(socialActivityAchievement.getPrimaryKey());
645    
646                    socialActivityAchievementImpl.setActivityAchievementId(socialActivityAchievement.getActivityAchievementId());
647                    socialActivityAchievementImpl.setGroupId(socialActivityAchievement.getGroupId());
648                    socialActivityAchievementImpl.setCompanyId(socialActivityAchievement.getCompanyId());
649                    socialActivityAchievementImpl.setUserId(socialActivityAchievement.getUserId());
650                    socialActivityAchievementImpl.setCreateDate(socialActivityAchievement.getCreateDate());
651                    socialActivityAchievementImpl.setName(socialActivityAchievement.getName());
652                    socialActivityAchievementImpl.setFirstInGroup(socialActivityAchievement.isFirstInGroup());
653    
654                    return socialActivityAchievementImpl;
655            }
656    
657            /**
658             * Returns the social activity achievement with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
659             *
660             * @param primaryKey the primary key of the social activity achievement
661             * @return the social activity achievement
662             * @throws com.liferay.portal.NoSuchModelException if a social activity achievement with the primary key could not be found
663             * @throws SystemException if a system exception occurred
664             */
665            @Override
666            public SocialActivityAchievement findByPrimaryKey(Serializable primaryKey)
667                    throws NoSuchModelException, SystemException {
668                    return findByPrimaryKey(((Long)primaryKey).longValue());
669            }
670    
671            /**
672             * Returns the social activity achievement with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivityAchievementException} if it could not be found.
673             *
674             * @param activityAchievementId the primary key of the social activity achievement
675             * @return the social activity achievement
676             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a social activity achievement with the primary key could not be found
677             * @throws SystemException if a system exception occurred
678             */
679            public SocialActivityAchievement findByPrimaryKey(
680                    long activityAchievementId)
681                    throws NoSuchActivityAchievementException, SystemException {
682                    SocialActivityAchievement socialActivityAchievement = fetchByPrimaryKey(activityAchievementId);
683    
684                    if (socialActivityAchievement == null) {
685                            if (_log.isWarnEnabled()) {
686                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
687                                            activityAchievementId);
688                            }
689    
690                            throw new NoSuchActivityAchievementException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
691                                    activityAchievementId);
692                    }
693    
694                    return socialActivityAchievement;
695            }
696    
697            /**
698             * Returns the social activity achievement with the primary key or returns <code>null</code> if it could not be found.
699             *
700             * @param primaryKey the primary key of the social activity achievement
701             * @return the social activity achievement, or <code>null</code> if a social activity achievement with the primary key could not be found
702             * @throws SystemException if a system exception occurred
703             */
704            @Override
705            public SocialActivityAchievement fetchByPrimaryKey(Serializable primaryKey)
706                    throws SystemException {
707                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
708            }
709    
710            /**
711             * Returns the social activity achievement with the primary key or returns <code>null</code> if it could not be found.
712             *
713             * @param activityAchievementId the primary key of the social activity achievement
714             * @return the social activity achievement, or <code>null</code> if a social activity achievement with the primary key could not be found
715             * @throws SystemException if a system exception occurred
716             */
717            public SocialActivityAchievement fetchByPrimaryKey(
718                    long activityAchievementId) throws SystemException {
719                    SocialActivityAchievement socialActivityAchievement = (SocialActivityAchievement)EntityCacheUtil.getResult(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
720                                    SocialActivityAchievementImpl.class, activityAchievementId);
721    
722                    if (socialActivityAchievement == _nullSocialActivityAchievement) {
723                            return null;
724                    }
725    
726                    if (socialActivityAchievement == null) {
727                            Session session = null;
728    
729                            boolean hasException = false;
730    
731                            try {
732                                    session = openSession();
733    
734                                    socialActivityAchievement = (SocialActivityAchievement)session.get(SocialActivityAchievementImpl.class,
735                                                    Long.valueOf(activityAchievementId));
736                            }
737                            catch (Exception e) {
738                                    hasException = true;
739    
740                                    throw processException(e);
741                            }
742                            finally {
743                                    if (socialActivityAchievement != null) {
744                                            cacheResult(socialActivityAchievement);
745                                    }
746                                    else if (!hasException) {
747                                            EntityCacheUtil.putResult(SocialActivityAchievementModelImpl.ENTITY_CACHE_ENABLED,
748                                                    SocialActivityAchievementImpl.class,
749                                                    activityAchievementId, _nullSocialActivityAchievement);
750                                    }
751    
752                                    closeSession(session);
753                            }
754                    }
755    
756                    return socialActivityAchievement;
757            }
758    
759            /**
760             * Returns all the social activity achievements where groupId = &#63;.
761             *
762             * @param groupId the group ID
763             * @return the matching social activity achievements
764             * @throws SystemException if a system exception occurred
765             */
766            public List<SocialActivityAchievement> findByGroupId(long groupId)
767                    throws SystemException {
768                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
769            }
770    
771            /**
772             * Returns a range of all the social activity achievements where groupId = &#63;.
773             *
774             * <p>
775             * 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.
776             * </p>
777             *
778             * @param groupId the group ID
779             * @param start the lower bound of the range of social activity achievements
780             * @param end the upper bound of the range of social activity achievements (not inclusive)
781             * @return the range of matching social activity achievements
782             * @throws SystemException if a system exception occurred
783             */
784            public List<SocialActivityAchievement> findByGroupId(long groupId,
785                    int start, int end) throws SystemException {
786                    return findByGroupId(groupId, start, end, null);
787            }
788    
789            /**
790             * Returns an ordered range of all the social activity achievements where groupId = &#63;.
791             *
792             * <p>
793             * 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.
794             * </p>
795             *
796             * @param groupId the group ID
797             * @param start the lower bound of the range of social activity achievements
798             * @param end the upper bound of the range of social activity achievements (not inclusive)
799             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
800             * @return the ordered range of matching social activity achievements
801             * @throws SystemException if a system exception occurred
802             */
803            public List<SocialActivityAchievement> findByGroupId(long groupId,
804                    int start, int end, OrderByComparator orderByComparator)
805                    throws SystemException {
806                    FinderPath finderPath = null;
807                    Object[] finderArgs = null;
808    
809                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
810                                    (orderByComparator == null)) {
811                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
812                            finderArgs = new Object[] { groupId };
813                    }
814                    else {
815                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
816                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
817                    }
818    
819                    List<SocialActivityAchievement> list = (List<SocialActivityAchievement>)FinderCacheUtil.getResult(finderPath,
820                                    finderArgs, this);
821    
822                    if ((list != null) && !list.isEmpty()) {
823                            for (SocialActivityAchievement socialActivityAchievement : list) {
824                                    if ((groupId != socialActivityAchievement.getGroupId())) {
825                                            list = null;
826    
827                                            break;
828                                    }
829                            }
830                    }
831    
832                    if (list == null) {
833                            StringBundler query = null;
834    
835                            if (orderByComparator != null) {
836                                    query = new StringBundler(3 +
837                                                    (orderByComparator.getOrderByFields().length * 3));
838                            }
839                            else {
840                                    query = new StringBundler(2);
841                            }
842    
843                            query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
844    
845                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
846    
847                            if (orderByComparator != null) {
848                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
849                                            orderByComparator);
850                            }
851    
852                            String sql = query.toString();
853    
854                            Session session = null;
855    
856                            try {
857                                    session = openSession();
858    
859                                    Query q = session.createQuery(sql);
860    
861                                    QueryPos qPos = QueryPos.getInstance(q);
862    
863                                    qPos.add(groupId);
864    
865                                    list = (List<SocialActivityAchievement>)QueryUtil.list(q,
866                                                    getDialect(), start, end);
867                            }
868                            catch (Exception e) {
869                                    throw processException(e);
870                            }
871                            finally {
872                                    if (list == null) {
873                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
874                                    }
875                                    else {
876                                            cacheResult(list);
877    
878                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
879                                    }
880    
881                                    closeSession(session);
882                            }
883                    }
884    
885                    return list;
886            }
887    
888            /**
889             * Returns the first social activity achievement in the ordered set where groupId = &#63;.
890             *
891             * @param groupId the group ID
892             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
893             * @return the first matching social activity achievement
894             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
895             * @throws SystemException if a system exception occurred
896             */
897            public SocialActivityAchievement findByGroupId_First(long groupId,
898                    OrderByComparator orderByComparator)
899                    throws NoSuchActivityAchievementException, SystemException {
900                    SocialActivityAchievement socialActivityAchievement = fetchByGroupId_First(groupId,
901                                    orderByComparator);
902    
903                    if (socialActivityAchievement != null) {
904                            return socialActivityAchievement;
905                    }
906    
907                    StringBundler msg = new StringBundler(4);
908    
909                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
910    
911                    msg.append("groupId=");
912                    msg.append(groupId);
913    
914                    msg.append(StringPool.CLOSE_CURLY_BRACE);
915    
916                    throw new NoSuchActivityAchievementException(msg.toString());
917            }
918    
919            /**
920             * Returns the first social activity achievement in the ordered set where groupId = &#63;.
921             *
922             * @param groupId the group ID
923             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
924             * @return the first matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
925             * @throws SystemException if a system exception occurred
926             */
927            public SocialActivityAchievement fetchByGroupId_First(long groupId,
928                    OrderByComparator orderByComparator) throws SystemException {
929                    List<SocialActivityAchievement> list = findByGroupId(groupId, 0, 1,
930                                    orderByComparator);
931    
932                    if (!list.isEmpty()) {
933                            return list.get(0);
934                    }
935    
936                    return null;
937            }
938    
939            /**
940             * Returns the last social activity achievement in the ordered set where groupId = &#63;.
941             *
942             * @param groupId the group ID
943             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
944             * @return the last matching social activity achievement
945             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
946             * @throws SystemException if a system exception occurred
947             */
948            public SocialActivityAchievement findByGroupId_Last(long groupId,
949                    OrderByComparator orderByComparator)
950                    throws NoSuchActivityAchievementException, SystemException {
951                    SocialActivityAchievement socialActivityAchievement = fetchByGroupId_Last(groupId,
952                                    orderByComparator);
953    
954                    if (socialActivityAchievement != null) {
955                            return socialActivityAchievement;
956                    }
957    
958                    StringBundler msg = new StringBundler(4);
959    
960                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
961    
962                    msg.append("groupId=");
963                    msg.append(groupId);
964    
965                    msg.append(StringPool.CLOSE_CURLY_BRACE);
966    
967                    throw new NoSuchActivityAchievementException(msg.toString());
968            }
969    
970            /**
971             * Returns the last social activity achievement in the ordered set where groupId = &#63;.
972             *
973             * @param groupId the group ID
974             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
975             * @return the last matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
976             * @throws SystemException if a system exception occurred
977             */
978            public SocialActivityAchievement fetchByGroupId_Last(long groupId,
979                    OrderByComparator orderByComparator) throws SystemException {
980                    int count = countByGroupId(groupId);
981    
982                    List<SocialActivityAchievement> list = findByGroupId(groupId,
983                                    count - 1, count, orderByComparator);
984    
985                    if (!list.isEmpty()) {
986                            return list.get(0);
987                    }
988    
989                    return null;
990            }
991    
992            /**
993             * Returns the social activity achievements before and after the current social activity achievement in the ordered set where groupId = &#63;.
994             *
995             * @param activityAchievementId the primary key of the current social activity achievement
996             * @param groupId the group ID
997             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
998             * @return the previous, current, and next social activity achievement
999             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a social activity achievement with the primary key could not be found
1000             * @throws SystemException if a system exception occurred
1001             */
1002            public SocialActivityAchievement[] findByGroupId_PrevAndNext(
1003                    long activityAchievementId, long groupId,
1004                    OrderByComparator orderByComparator)
1005                    throws NoSuchActivityAchievementException, SystemException {
1006                    SocialActivityAchievement socialActivityAchievement = findByPrimaryKey(activityAchievementId);
1007    
1008                    Session session = null;
1009    
1010                    try {
1011                            session = openSession();
1012    
1013                            SocialActivityAchievement[] array = new SocialActivityAchievementImpl[3];
1014    
1015                            array[0] = getByGroupId_PrevAndNext(session,
1016                                            socialActivityAchievement, groupId, orderByComparator, true);
1017    
1018                            array[1] = socialActivityAchievement;
1019    
1020                            array[2] = getByGroupId_PrevAndNext(session,
1021                                            socialActivityAchievement, groupId, orderByComparator, false);
1022    
1023                            return array;
1024                    }
1025                    catch (Exception e) {
1026                            throw processException(e);
1027                    }
1028                    finally {
1029                            closeSession(session);
1030                    }
1031            }
1032    
1033            protected SocialActivityAchievement getByGroupId_PrevAndNext(
1034                    Session session, SocialActivityAchievement socialActivityAchievement,
1035                    long groupId, OrderByComparator orderByComparator, boolean previous) {
1036                    StringBundler query = null;
1037    
1038                    if (orderByComparator != null) {
1039                            query = new StringBundler(6 +
1040                                            (orderByComparator.getOrderByFields().length * 6));
1041                    }
1042                    else {
1043                            query = new StringBundler(3);
1044                    }
1045    
1046                    query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
1047    
1048                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1049    
1050                    if (orderByComparator != null) {
1051                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1052    
1053                            if (orderByConditionFields.length > 0) {
1054                                    query.append(WHERE_AND);
1055                            }
1056    
1057                            for (int i = 0; i < orderByConditionFields.length; i++) {
1058                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1059                                    query.append(orderByConditionFields[i]);
1060    
1061                                    if ((i + 1) < orderByConditionFields.length) {
1062                                            if (orderByComparator.isAscending() ^ previous) {
1063                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1064                                            }
1065                                            else {
1066                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1067                                            }
1068                                    }
1069                                    else {
1070                                            if (orderByComparator.isAscending() ^ previous) {
1071                                                    query.append(WHERE_GREATER_THAN);
1072                                            }
1073                                            else {
1074                                                    query.append(WHERE_LESSER_THAN);
1075                                            }
1076                                    }
1077                            }
1078    
1079                            query.append(ORDER_BY_CLAUSE);
1080    
1081                            String[] orderByFields = orderByComparator.getOrderByFields();
1082    
1083                            for (int i = 0; i < orderByFields.length; i++) {
1084                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1085                                    query.append(orderByFields[i]);
1086    
1087                                    if ((i + 1) < orderByFields.length) {
1088                                            if (orderByComparator.isAscending() ^ previous) {
1089                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1090                                            }
1091                                            else {
1092                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1093                                            }
1094                                    }
1095                                    else {
1096                                            if (orderByComparator.isAscending() ^ previous) {
1097                                                    query.append(ORDER_BY_ASC);
1098                                            }
1099                                            else {
1100                                                    query.append(ORDER_BY_DESC);
1101                                            }
1102                                    }
1103                            }
1104                    }
1105    
1106                    String sql = query.toString();
1107    
1108                    Query q = session.createQuery(sql);
1109    
1110                    q.setFirstResult(0);
1111                    q.setMaxResults(2);
1112    
1113                    QueryPos qPos = QueryPos.getInstance(q);
1114    
1115                    qPos.add(groupId);
1116    
1117                    if (orderByComparator != null) {
1118                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityAchievement);
1119    
1120                            for (Object value : values) {
1121                                    qPos.add(value);
1122                            }
1123                    }
1124    
1125                    List<SocialActivityAchievement> list = q.list();
1126    
1127                    if (list.size() == 2) {
1128                            return list.get(1);
1129                    }
1130                    else {
1131                            return null;
1132                    }
1133            }
1134    
1135            /**
1136             * Returns all the social activity achievements where groupId = &#63; and userId = &#63;.
1137             *
1138             * @param groupId the group ID
1139             * @param userId the user ID
1140             * @return the matching social activity achievements
1141             * @throws SystemException if a system exception occurred
1142             */
1143            public List<SocialActivityAchievement> findByG_U(long groupId, long userId)
1144                    throws SystemException {
1145                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1146                            null);
1147            }
1148    
1149            /**
1150             * Returns a range of all the social activity achievements where groupId = &#63; and userId = &#63;.
1151             *
1152             * <p>
1153             * 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.
1154             * </p>
1155             *
1156             * @param groupId the group ID
1157             * @param userId the user ID
1158             * @param start the lower bound of the range of social activity achievements
1159             * @param end the upper bound of the range of social activity achievements (not inclusive)
1160             * @return the range of matching social activity achievements
1161             * @throws SystemException if a system exception occurred
1162             */
1163            public List<SocialActivityAchievement> findByG_U(long groupId, long userId,
1164                    int start, int end) throws SystemException {
1165                    return findByG_U(groupId, userId, start, end, null);
1166            }
1167    
1168            /**
1169             * Returns an ordered range of all the social activity achievements where groupId = &#63; and userId = &#63;.
1170             *
1171             * <p>
1172             * 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.
1173             * </p>
1174             *
1175             * @param groupId the group ID
1176             * @param userId the user ID
1177             * @param start the lower bound of the range of social activity achievements
1178             * @param end the upper bound of the range of social activity achievements (not inclusive)
1179             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1180             * @return the ordered range of matching social activity achievements
1181             * @throws SystemException if a system exception occurred
1182             */
1183            public List<SocialActivityAchievement> findByG_U(long groupId, long userId,
1184                    int start, int end, OrderByComparator orderByComparator)
1185                    throws SystemException {
1186                    FinderPath finderPath = null;
1187                    Object[] finderArgs = null;
1188    
1189                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1190                                    (orderByComparator == null)) {
1191                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
1192                            finderArgs = new Object[] { groupId, userId };
1193                    }
1194                    else {
1195                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
1196                            finderArgs = new Object[] {
1197                                            groupId, userId,
1198                                            
1199                                            start, end, orderByComparator
1200                                    };
1201                    }
1202    
1203                    List<SocialActivityAchievement> list = (List<SocialActivityAchievement>)FinderCacheUtil.getResult(finderPath,
1204                                    finderArgs, this);
1205    
1206                    if ((list != null) && !list.isEmpty()) {
1207                            for (SocialActivityAchievement socialActivityAchievement : list) {
1208                                    if ((groupId != socialActivityAchievement.getGroupId()) ||
1209                                                    (userId != socialActivityAchievement.getUserId())) {
1210                                            list = null;
1211    
1212                                            break;
1213                                    }
1214                            }
1215                    }
1216    
1217                    if (list == null) {
1218                            StringBundler query = null;
1219    
1220                            if (orderByComparator != null) {
1221                                    query = new StringBundler(4 +
1222                                                    (orderByComparator.getOrderByFields().length * 3));
1223                            }
1224                            else {
1225                                    query = new StringBundler(3);
1226                            }
1227    
1228                            query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
1229    
1230                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1231    
1232                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1233    
1234                            if (orderByComparator != null) {
1235                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1236                                            orderByComparator);
1237                            }
1238    
1239                            String sql = query.toString();
1240    
1241                            Session session = null;
1242    
1243                            try {
1244                                    session = openSession();
1245    
1246                                    Query q = session.createQuery(sql);
1247    
1248                                    QueryPos qPos = QueryPos.getInstance(q);
1249    
1250                                    qPos.add(groupId);
1251    
1252                                    qPos.add(userId);
1253    
1254                                    list = (List<SocialActivityAchievement>)QueryUtil.list(q,
1255                                                    getDialect(), start, end);
1256                            }
1257                            catch (Exception e) {
1258                                    throw processException(e);
1259                            }
1260                            finally {
1261                                    if (list == null) {
1262                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1263                                    }
1264                                    else {
1265                                            cacheResult(list);
1266    
1267                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1268                                    }
1269    
1270                                    closeSession(session);
1271                            }
1272                    }
1273    
1274                    return list;
1275            }
1276    
1277            /**
1278             * Returns the first social activity achievement in the ordered set where groupId = &#63; and userId = &#63;.
1279             *
1280             * @param groupId the group ID
1281             * @param userId the user ID
1282             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1283             * @return the first matching social activity achievement
1284             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
1285             * @throws SystemException if a system exception occurred
1286             */
1287            public SocialActivityAchievement findByG_U_First(long groupId, long userId,
1288                    OrderByComparator orderByComparator)
1289                    throws NoSuchActivityAchievementException, SystemException {
1290                    SocialActivityAchievement socialActivityAchievement = fetchByG_U_First(groupId,
1291                                    userId, orderByComparator);
1292    
1293                    if (socialActivityAchievement != null) {
1294                            return socialActivityAchievement;
1295                    }
1296    
1297                    StringBundler msg = new StringBundler(6);
1298    
1299                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1300    
1301                    msg.append("groupId=");
1302                    msg.append(groupId);
1303    
1304                    msg.append(", userId=");
1305                    msg.append(userId);
1306    
1307                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1308    
1309                    throw new NoSuchActivityAchievementException(msg.toString());
1310            }
1311    
1312            /**
1313             * Returns the first social activity achievement in the ordered set where groupId = &#63; and userId = &#63;.
1314             *
1315             * @param groupId the group ID
1316             * @param userId the user ID
1317             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1318             * @return the first matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
1319             * @throws SystemException if a system exception occurred
1320             */
1321            public SocialActivityAchievement fetchByG_U_First(long groupId,
1322                    long userId, OrderByComparator orderByComparator)
1323                    throws SystemException {
1324                    List<SocialActivityAchievement> list = findByG_U(groupId, userId, 0, 1,
1325                                    orderByComparator);
1326    
1327                    if (!list.isEmpty()) {
1328                            return list.get(0);
1329                    }
1330    
1331                    return null;
1332            }
1333    
1334            /**
1335             * Returns the last social activity achievement in the ordered set where groupId = &#63; and userId = &#63;.
1336             *
1337             * @param groupId the group ID
1338             * @param userId the user ID
1339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1340             * @return the last matching social activity achievement
1341             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
1342             * @throws SystemException if a system exception occurred
1343             */
1344            public SocialActivityAchievement findByG_U_Last(long groupId, long userId,
1345                    OrderByComparator orderByComparator)
1346                    throws NoSuchActivityAchievementException, SystemException {
1347                    SocialActivityAchievement socialActivityAchievement = fetchByG_U_Last(groupId,
1348                                    userId, orderByComparator);
1349    
1350                    if (socialActivityAchievement != null) {
1351                            return socialActivityAchievement;
1352                    }
1353    
1354                    StringBundler msg = new StringBundler(6);
1355    
1356                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1357    
1358                    msg.append("groupId=");
1359                    msg.append(groupId);
1360    
1361                    msg.append(", userId=");
1362                    msg.append(userId);
1363    
1364                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1365    
1366                    throw new NoSuchActivityAchievementException(msg.toString());
1367            }
1368    
1369            /**
1370             * Returns the last social activity achievement in the ordered set where groupId = &#63; and userId = &#63;.
1371             *
1372             * @param groupId the group ID
1373             * @param userId the user ID
1374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1375             * @return the last matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
1376             * @throws SystemException if a system exception occurred
1377             */
1378            public SocialActivityAchievement fetchByG_U_Last(long groupId, long userId,
1379                    OrderByComparator orderByComparator) throws SystemException {
1380                    int count = countByG_U(groupId, userId);
1381    
1382                    List<SocialActivityAchievement> list = findByG_U(groupId, userId,
1383                                    count - 1, count, orderByComparator);
1384    
1385                    if (!list.isEmpty()) {
1386                            return list.get(0);
1387                    }
1388    
1389                    return null;
1390            }
1391    
1392            /**
1393             * Returns the social activity achievements before and after the current social activity achievement in the ordered set where groupId = &#63; and userId = &#63;.
1394             *
1395             * @param activityAchievementId the primary key of the current social activity achievement
1396             * @param groupId the group ID
1397             * @param userId the user ID
1398             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1399             * @return the previous, current, and next social activity achievement
1400             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a social activity achievement with the primary key could not be found
1401             * @throws SystemException if a system exception occurred
1402             */
1403            public SocialActivityAchievement[] findByG_U_PrevAndNext(
1404                    long activityAchievementId, long groupId, long userId,
1405                    OrderByComparator orderByComparator)
1406                    throws NoSuchActivityAchievementException, SystemException {
1407                    SocialActivityAchievement socialActivityAchievement = findByPrimaryKey(activityAchievementId);
1408    
1409                    Session session = null;
1410    
1411                    try {
1412                            session = openSession();
1413    
1414                            SocialActivityAchievement[] array = new SocialActivityAchievementImpl[3];
1415    
1416                            array[0] = getByG_U_PrevAndNext(session, socialActivityAchievement,
1417                                            groupId, userId, orderByComparator, true);
1418    
1419                            array[1] = socialActivityAchievement;
1420    
1421                            array[2] = getByG_U_PrevAndNext(session, socialActivityAchievement,
1422                                            groupId, userId, orderByComparator, false);
1423    
1424                            return array;
1425                    }
1426                    catch (Exception e) {
1427                            throw processException(e);
1428                    }
1429                    finally {
1430                            closeSession(session);
1431                    }
1432            }
1433    
1434            protected SocialActivityAchievement getByG_U_PrevAndNext(Session session,
1435                    SocialActivityAchievement socialActivityAchievement, long groupId,
1436                    long userId, OrderByComparator orderByComparator, boolean previous) {
1437                    StringBundler query = null;
1438    
1439                    if (orderByComparator != null) {
1440                            query = new StringBundler(6 +
1441                                            (orderByComparator.getOrderByFields().length * 6));
1442                    }
1443                    else {
1444                            query = new StringBundler(3);
1445                    }
1446    
1447                    query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
1448    
1449                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1450    
1451                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1452    
1453                    if (orderByComparator != null) {
1454                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1455    
1456                            if (orderByConditionFields.length > 0) {
1457                                    query.append(WHERE_AND);
1458                            }
1459    
1460                            for (int i = 0; i < orderByConditionFields.length; i++) {
1461                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1462                                    query.append(orderByConditionFields[i]);
1463    
1464                                    if ((i + 1) < orderByConditionFields.length) {
1465                                            if (orderByComparator.isAscending() ^ previous) {
1466                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1467                                            }
1468                                            else {
1469                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1470                                            }
1471                                    }
1472                                    else {
1473                                            if (orderByComparator.isAscending() ^ previous) {
1474                                                    query.append(WHERE_GREATER_THAN);
1475                                            }
1476                                            else {
1477                                                    query.append(WHERE_LESSER_THAN);
1478                                            }
1479                                    }
1480                            }
1481    
1482                            query.append(ORDER_BY_CLAUSE);
1483    
1484                            String[] orderByFields = orderByComparator.getOrderByFields();
1485    
1486                            for (int i = 0; i < orderByFields.length; i++) {
1487                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1488                                    query.append(orderByFields[i]);
1489    
1490                                    if ((i + 1) < orderByFields.length) {
1491                                            if (orderByComparator.isAscending() ^ previous) {
1492                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1493                                            }
1494                                            else {
1495                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1496                                            }
1497                                    }
1498                                    else {
1499                                            if (orderByComparator.isAscending() ^ previous) {
1500                                                    query.append(ORDER_BY_ASC);
1501                                            }
1502                                            else {
1503                                                    query.append(ORDER_BY_DESC);
1504                                            }
1505                                    }
1506                            }
1507                    }
1508    
1509                    String sql = query.toString();
1510    
1511                    Query q = session.createQuery(sql);
1512    
1513                    q.setFirstResult(0);
1514                    q.setMaxResults(2);
1515    
1516                    QueryPos qPos = QueryPos.getInstance(q);
1517    
1518                    qPos.add(groupId);
1519    
1520                    qPos.add(userId);
1521    
1522                    if (orderByComparator != null) {
1523                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityAchievement);
1524    
1525                            for (Object value : values) {
1526                                    qPos.add(value);
1527                            }
1528                    }
1529    
1530                    List<SocialActivityAchievement> list = q.list();
1531    
1532                    if (list.size() == 2) {
1533                            return list.get(1);
1534                    }
1535                    else {
1536                            return null;
1537                    }
1538            }
1539    
1540            /**
1541             * Returns all the social activity achievements where groupId = &#63; and name = &#63;.
1542             *
1543             * @param groupId the group ID
1544             * @param name the name
1545             * @return the matching social activity achievements
1546             * @throws SystemException if a system exception occurred
1547             */
1548            public List<SocialActivityAchievement> findByG_N(long groupId, String name)
1549                    throws SystemException {
1550                    return findByG_N(groupId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1551                            null);
1552            }
1553    
1554            /**
1555             * Returns a range of all the social activity achievements where groupId = &#63; and name = &#63;.
1556             *
1557             * <p>
1558             * 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.
1559             * </p>
1560             *
1561             * @param groupId the group ID
1562             * @param name the name
1563             * @param start the lower bound of the range of social activity achievements
1564             * @param end the upper bound of the range of social activity achievements (not inclusive)
1565             * @return the range of matching social activity achievements
1566             * @throws SystemException if a system exception occurred
1567             */
1568            public List<SocialActivityAchievement> findByG_N(long groupId, String name,
1569                    int start, int end) throws SystemException {
1570                    return findByG_N(groupId, name, start, end, null);
1571            }
1572    
1573            /**
1574             * Returns an ordered range of all the social activity achievements where groupId = &#63; and name = &#63;.
1575             *
1576             * <p>
1577             * 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.
1578             * </p>
1579             *
1580             * @param groupId the group ID
1581             * @param name the name
1582             * @param start the lower bound of the range of social activity achievements
1583             * @param end the upper bound of the range of social activity achievements (not inclusive)
1584             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1585             * @return the ordered range of matching social activity achievements
1586             * @throws SystemException if a system exception occurred
1587             */
1588            public List<SocialActivityAchievement> findByG_N(long groupId, String name,
1589                    int start, int end, OrderByComparator orderByComparator)
1590                    throws SystemException {
1591                    FinderPath finderPath = null;
1592                    Object[] finderArgs = null;
1593    
1594                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1595                                    (orderByComparator == null)) {
1596                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N;
1597                            finderArgs = new Object[] { groupId, name };
1598                    }
1599                    else {
1600                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N;
1601                            finderArgs = new Object[] {
1602                                            groupId, name,
1603                                            
1604                                            start, end, orderByComparator
1605                                    };
1606                    }
1607    
1608                    List<SocialActivityAchievement> list = (List<SocialActivityAchievement>)FinderCacheUtil.getResult(finderPath,
1609                                    finderArgs, this);
1610    
1611                    if ((list != null) && !list.isEmpty()) {
1612                            for (SocialActivityAchievement socialActivityAchievement : list) {
1613                                    if ((groupId != socialActivityAchievement.getGroupId()) ||
1614                                                    !Validator.equals(name,
1615                                                            socialActivityAchievement.getName())) {
1616                                            list = null;
1617    
1618                                            break;
1619                                    }
1620                            }
1621                    }
1622    
1623                    if (list == null) {
1624                            StringBundler query = null;
1625    
1626                            if (orderByComparator != null) {
1627                                    query = new StringBundler(4 +
1628                                                    (orderByComparator.getOrderByFields().length * 3));
1629                            }
1630                            else {
1631                                    query = new StringBundler(3);
1632                            }
1633    
1634                            query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
1635    
1636                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1637    
1638                            if (name == null) {
1639                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
1640                            }
1641                            else {
1642                                    if (name.equals(StringPool.BLANK)) {
1643                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
1644                                    }
1645                                    else {
1646                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
1647                                    }
1648                            }
1649    
1650                            if (orderByComparator != null) {
1651                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1652                                            orderByComparator);
1653                            }
1654    
1655                            String sql = query.toString();
1656    
1657                            Session session = null;
1658    
1659                            try {
1660                                    session = openSession();
1661    
1662                                    Query q = session.createQuery(sql);
1663    
1664                                    QueryPos qPos = QueryPos.getInstance(q);
1665    
1666                                    qPos.add(groupId);
1667    
1668                                    if (name != null) {
1669                                            qPos.add(name);
1670                                    }
1671    
1672                                    list = (List<SocialActivityAchievement>)QueryUtil.list(q,
1673                                                    getDialect(), start, end);
1674                            }
1675                            catch (Exception e) {
1676                                    throw processException(e);
1677                            }
1678                            finally {
1679                                    if (list == null) {
1680                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1681                                    }
1682                                    else {
1683                                            cacheResult(list);
1684    
1685                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1686                                    }
1687    
1688                                    closeSession(session);
1689                            }
1690                    }
1691    
1692                    return list;
1693            }
1694    
1695            /**
1696             * Returns the first social activity achievement in the ordered set where groupId = &#63; and name = &#63;.
1697             *
1698             * @param groupId the group ID
1699             * @param name the name
1700             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1701             * @return the first matching social activity achievement
1702             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
1703             * @throws SystemException if a system exception occurred
1704             */
1705            public SocialActivityAchievement findByG_N_First(long groupId, String name,
1706                    OrderByComparator orderByComparator)
1707                    throws NoSuchActivityAchievementException, SystemException {
1708                    SocialActivityAchievement socialActivityAchievement = fetchByG_N_First(groupId,
1709                                    name, orderByComparator);
1710    
1711                    if (socialActivityAchievement != null) {
1712                            return socialActivityAchievement;
1713                    }
1714    
1715                    StringBundler msg = new StringBundler(6);
1716    
1717                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1718    
1719                    msg.append("groupId=");
1720                    msg.append(groupId);
1721    
1722                    msg.append(", name=");
1723                    msg.append(name);
1724    
1725                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1726    
1727                    throw new NoSuchActivityAchievementException(msg.toString());
1728            }
1729    
1730            /**
1731             * Returns the first social activity achievement in the ordered set where groupId = &#63; and name = &#63;.
1732             *
1733             * @param groupId the group ID
1734             * @param name the name
1735             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1736             * @return the first matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
1737             * @throws SystemException if a system exception occurred
1738             */
1739            public SocialActivityAchievement fetchByG_N_First(long groupId,
1740                    String name, OrderByComparator orderByComparator)
1741                    throws SystemException {
1742                    List<SocialActivityAchievement> list = findByG_N(groupId, name, 0, 1,
1743                                    orderByComparator);
1744    
1745                    if (!list.isEmpty()) {
1746                            return list.get(0);
1747                    }
1748    
1749                    return null;
1750            }
1751    
1752            /**
1753             * Returns the last social activity achievement in the ordered set where groupId = &#63; and name = &#63;.
1754             *
1755             * @param groupId the group ID
1756             * @param name the name
1757             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1758             * @return the last matching social activity achievement
1759             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
1760             * @throws SystemException if a system exception occurred
1761             */
1762            public SocialActivityAchievement findByG_N_Last(long groupId, String name,
1763                    OrderByComparator orderByComparator)
1764                    throws NoSuchActivityAchievementException, SystemException {
1765                    SocialActivityAchievement socialActivityAchievement = fetchByG_N_Last(groupId,
1766                                    name, orderByComparator);
1767    
1768                    if (socialActivityAchievement != null) {
1769                            return socialActivityAchievement;
1770                    }
1771    
1772                    StringBundler msg = new StringBundler(6);
1773    
1774                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1775    
1776                    msg.append("groupId=");
1777                    msg.append(groupId);
1778    
1779                    msg.append(", name=");
1780                    msg.append(name);
1781    
1782                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1783    
1784                    throw new NoSuchActivityAchievementException(msg.toString());
1785            }
1786    
1787            /**
1788             * Returns the last social activity achievement in the ordered set where groupId = &#63; and name = &#63;.
1789             *
1790             * @param groupId the group ID
1791             * @param name the name
1792             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1793             * @return the last matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
1794             * @throws SystemException if a system exception occurred
1795             */
1796            public SocialActivityAchievement fetchByG_N_Last(long groupId, String name,
1797                    OrderByComparator orderByComparator) throws SystemException {
1798                    int count = countByG_N(groupId, name);
1799    
1800                    List<SocialActivityAchievement> list = findByG_N(groupId, name,
1801                                    count - 1, count, orderByComparator);
1802    
1803                    if (!list.isEmpty()) {
1804                            return list.get(0);
1805                    }
1806    
1807                    return null;
1808            }
1809    
1810            /**
1811             * Returns the social activity achievements before and after the current social activity achievement in the ordered set where groupId = &#63; and name = &#63;.
1812             *
1813             * @param activityAchievementId the primary key of the current social activity achievement
1814             * @param groupId the group ID
1815             * @param name the name
1816             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1817             * @return the previous, current, and next social activity achievement
1818             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a social activity achievement with the primary key could not be found
1819             * @throws SystemException if a system exception occurred
1820             */
1821            public SocialActivityAchievement[] findByG_N_PrevAndNext(
1822                    long activityAchievementId, long groupId, String name,
1823                    OrderByComparator orderByComparator)
1824                    throws NoSuchActivityAchievementException, SystemException {
1825                    SocialActivityAchievement socialActivityAchievement = findByPrimaryKey(activityAchievementId);
1826    
1827                    Session session = null;
1828    
1829                    try {
1830                            session = openSession();
1831    
1832                            SocialActivityAchievement[] array = new SocialActivityAchievementImpl[3];
1833    
1834                            array[0] = getByG_N_PrevAndNext(session, socialActivityAchievement,
1835                                            groupId, name, orderByComparator, true);
1836    
1837                            array[1] = socialActivityAchievement;
1838    
1839                            array[2] = getByG_N_PrevAndNext(session, socialActivityAchievement,
1840                                            groupId, name, orderByComparator, false);
1841    
1842                            return array;
1843                    }
1844                    catch (Exception e) {
1845                            throw processException(e);
1846                    }
1847                    finally {
1848                            closeSession(session);
1849                    }
1850            }
1851    
1852            protected SocialActivityAchievement getByG_N_PrevAndNext(Session session,
1853                    SocialActivityAchievement socialActivityAchievement, long groupId,
1854                    String name, OrderByComparator orderByComparator, boolean previous) {
1855                    StringBundler query = null;
1856    
1857                    if (orderByComparator != null) {
1858                            query = new StringBundler(6 +
1859                                            (orderByComparator.getOrderByFields().length * 6));
1860                    }
1861                    else {
1862                            query = new StringBundler(3);
1863                    }
1864    
1865                    query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
1866    
1867                    query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1868    
1869                    if (name == null) {
1870                            query.append(_FINDER_COLUMN_G_N_NAME_1);
1871                    }
1872                    else {
1873                            if (name.equals(StringPool.BLANK)) {
1874                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
1875                            }
1876                            else {
1877                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
1878                            }
1879                    }
1880    
1881                    if (orderByComparator != null) {
1882                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1883    
1884                            if (orderByConditionFields.length > 0) {
1885                                    query.append(WHERE_AND);
1886                            }
1887    
1888                            for (int i = 0; i < orderByConditionFields.length; i++) {
1889                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1890                                    query.append(orderByConditionFields[i]);
1891    
1892                                    if ((i + 1) < orderByConditionFields.length) {
1893                                            if (orderByComparator.isAscending() ^ previous) {
1894                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1895                                            }
1896                                            else {
1897                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1898                                            }
1899                                    }
1900                                    else {
1901                                            if (orderByComparator.isAscending() ^ previous) {
1902                                                    query.append(WHERE_GREATER_THAN);
1903                                            }
1904                                            else {
1905                                                    query.append(WHERE_LESSER_THAN);
1906                                            }
1907                                    }
1908                            }
1909    
1910                            query.append(ORDER_BY_CLAUSE);
1911    
1912                            String[] orderByFields = orderByComparator.getOrderByFields();
1913    
1914                            for (int i = 0; i < orderByFields.length; i++) {
1915                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1916                                    query.append(orderByFields[i]);
1917    
1918                                    if ((i + 1) < orderByFields.length) {
1919                                            if (orderByComparator.isAscending() ^ previous) {
1920                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1921                                            }
1922                                            else {
1923                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1924                                            }
1925                                    }
1926                                    else {
1927                                            if (orderByComparator.isAscending() ^ previous) {
1928                                                    query.append(ORDER_BY_ASC);
1929                                            }
1930                                            else {
1931                                                    query.append(ORDER_BY_DESC);
1932                                            }
1933                                    }
1934                            }
1935                    }
1936    
1937                    String sql = query.toString();
1938    
1939                    Query q = session.createQuery(sql);
1940    
1941                    q.setFirstResult(0);
1942                    q.setMaxResults(2);
1943    
1944                    QueryPos qPos = QueryPos.getInstance(q);
1945    
1946                    qPos.add(groupId);
1947    
1948                    if (name != null) {
1949                            qPos.add(name);
1950                    }
1951    
1952                    if (orderByComparator != null) {
1953                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityAchievement);
1954    
1955                            for (Object value : values) {
1956                                    qPos.add(value);
1957                            }
1958                    }
1959    
1960                    List<SocialActivityAchievement> list = q.list();
1961    
1962                    if (list.size() == 2) {
1963                            return list.get(1);
1964                    }
1965                    else {
1966                            return null;
1967                    }
1968            }
1969    
1970            /**
1971             * Returns all the social activity achievements where groupId = &#63; and firstInGroup = &#63;.
1972             *
1973             * @param groupId the group ID
1974             * @param firstInGroup the first in group
1975             * @return the matching social activity achievements
1976             * @throws SystemException if a system exception occurred
1977             */
1978            public List<SocialActivityAchievement> findByG_F(long groupId,
1979                    boolean firstInGroup) throws SystemException {
1980                    return findByG_F(groupId, firstInGroup, QueryUtil.ALL_POS,
1981                            QueryUtil.ALL_POS, null);
1982            }
1983    
1984            /**
1985             * Returns a range of all the social activity achievements where groupId = &#63; and firstInGroup = &#63;.
1986             *
1987             * <p>
1988             * 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.
1989             * </p>
1990             *
1991             * @param groupId the group ID
1992             * @param firstInGroup the first in group
1993             * @param start the lower bound of the range of social activity achievements
1994             * @param end the upper bound of the range of social activity achievements (not inclusive)
1995             * @return the range of matching social activity achievements
1996             * @throws SystemException if a system exception occurred
1997             */
1998            public List<SocialActivityAchievement> findByG_F(long groupId,
1999                    boolean firstInGroup, int start, int end) throws SystemException {
2000                    return findByG_F(groupId, firstInGroup, start, end, null);
2001            }
2002    
2003            /**
2004             * Returns an ordered range of all the social activity achievements where groupId = &#63; and firstInGroup = &#63;.
2005             *
2006             * <p>
2007             * 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.
2008             * </p>
2009             *
2010             * @param groupId the group ID
2011             * @param firstInGroup the first in group
2012             * @param start the lower bound of the range of social activity achievements
2013             * @param end the upper bound of the range of social activity achievements (not inclusive)
2014             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2015             * @return the ordered range of matching social activity achievements
2016             * @throws SystemException if a system exception occurred
2017             */
2018            public List<SocialActivityAchievement> findByG_F(long groupId,
2019                    boolean firstInGroup, int start, int end,
2020                    OrderByComparator orderByComparator) throws SystemException {
2021                    FinderPath finderPath = null;
2022                    Object[] finderArgs = null;
2023    
2024                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2025                                    (orderByComparator == null)) {
2026                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F;
2027                            finderArgs = new Object[] { groupId, firstInGroup };
2028                    }
2029                    else {
2030                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F;
2031                            finderArgs = new Object[] {
2032                                            groupId, firstInGroup,
2033                                            
2034                                            start, end, orderByComparator
2035                                    };
2036                    }
2037    
2038                    List<SocialActivityAchievement> list = (List<SocialActivityAchievement>)FinderCacheUtil.getResult(finderPath,
2039                                    finderArgs, this);
2040    
2041                    if ((list != null) && !list.isEmpty()) {
2042                            for (SocialActivityAchievement socialActivityAchievement : list) {
2043                                    if ((groupId != socialActivityAchievement.getGroupId()) ||
2044                                                    (firstInGroup != socialActivityAchievement.getFirstInGroup())) {
2045                                            list = null;
2046    
2047                                            break;
2048                                    }
2049                            }
2050                    }
2051    
2052                    if (list == null) {
2053                            StringBundler query = null;
2054    
2055                            if (orderByComparator != null) {
2056                                    query = new StringBundler(4 +
2057                                                    (orderByComparator.getOrderByFields().length * 3));
2058                            }
2059                            else {
2060                                    query = new StringBundler(3);
2061                            }
2062    
2063                            query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
2064    
2065                            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
2066    
2067                            query.append(_FINDER_COLUMN_G_F_FIRSTINGROUP_2);
2068    
2069                            if (orderByComparator != null) {
2070                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2071                                            orderByComparator);
2072                            }
2073    
2074                            String sql = query.toString();
2075    
2076                            Session session = null;
2077    
2078                            try {
2079                                    session = openSession();
2080    
2081                                    Query q = session.createQuery(sql);
2082    
2083                                    QueryPos qPos = QueryPos.getInstance(q);
2084    
2085                                    qPos.add(groupId);
2086    
2087                                    qPos.add(firstInGroup);
2088    
2089                                    list = (List<SocialActivityAchievement>)QueryUtil.list(q,
2090                                                    getDialect(), start, end);
2091                            }
2092                            catch (Exception e) {
2093                                    throw processException(e);
2094                            }
2095                            finally {
2096                                    if (list == null) {
2097                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2098                                    }
2099                                    else {
2100                                            cacheResult(list);
2101    
2102                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2103                                    }
2104    
2105                                    closeSession(session);
2106                            }
2107                    }
2108    
2109                    return list;
2110            }
2111    
2112            /**
2113             * Returns the first social activity achievement in the ordered set where groupId = &#63; and firstInGroup = &#63;.
2114             *
2115             * @param groupId the group ID
2116             * @param firstInGroup the first in group
2117             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2118             * @return the first matching social activity achievement
2119             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
2120             * @throws SystemException if a system exception occurred
2121             */
2122            public SocialActivityAchievement findByG_F_First(long groupId,
2123                    boolean firstInGroup, OrderByComparator orderByComparator)
2124                    throws NoSuchActivityAchievementException, SystemException {
2125                    SocialActivityAchievement socialActivityAchievement = fetchByG_F_First(groupId,
2126                                    firstInGroup, orderByComparator);
2127    
2128                    if (socialActivityAchievement != null) {
2129                            return socialActivityAchievement;
2130                    }
2131    
2132                    StringBundler msg = new StringBundler(6);
2133    
2134                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2135    
2136                    msg.append("groupId=");
2137                    msg.append(groupId);
2138    
2139                    msg.append(", firstInGroup=");
2140                    msg.append(firstInGroup);
2141    
2142                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2143    
2144                    throw new NoSuchActivityAchievementException(msg.toString());
2145            }
2146    
2147            /**
2148             * Returns the first social activity achievement in the ordered set where groupId = &#63; and firstInGroup = &#63;.
2149             *
2150             * @param groupId the group ID
2151             * @param firstInGroup the first in group
2152             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2153             * @return the first matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
2154             * @throws SystemException if a system exception occurred
2155             */
2156            public SocialActivityAchievement fetchByG_F_First(long groupId,
2157                    boolean firstInGroup, OrderByComparator orderByComparator)
2158                    throws SystemException {
2159                    List<SocialActivityAchievement> list = findByG_F(groupId, firstInGroup,
2160                                    0, 1, orderByComparator);
2161    
2162                    if (!list.isEmpty()) {
2163                            return list.get(0);
2164                    }
2165    
2166                    return null;
2167            }
2168    
2169            /**
2170             * Returns the last social activity achievement in the ordered set where groupId = &#63; and firstInGroup = &#63;.
2171             *
2172             * @param groupId the group ID
2173             * @param firstInGroup the first in group
2174             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2175             * @return the last matching social activity achievement
2176             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
2177             * @throws SystemException if a system exception occurred
2178             */
2179            public SocialActivityAchievement findByG_F_Last(long groupId,
2180                    boolean firstInGroup, OrderByComparator orderByComparator)
2181                    throws NoSuchActivityAchievementException, SystemException {
2182                    SocialActivityAchievement socialActivityAchievement = fetchByG_F_Last(groupId,
2183                                    firstInGroup, orderByComparator);
2184    
2185                    if (socialActivityAchievement != null) {
2186                            return socialActivityAchievement;
2187                    }
2188    
2189                    StringBundler msg = new StringBundler(6);
2190    
2191                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2192    
2193                    msg.append("groupId=");
2194                    msg.append(groupId);
2195    
2196                    msg.append(", firstInGroup=");
2197                    msg.append(firstInGroup);
2198    
2199                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2200    
2201                    throw new NoSuchActivityAchievementException(msg.toString());
2202            }
2203    
2204            /**
2205             * Returns the last social activity achievement in the ordered set where groupId = &#63; and firstInGroup = &#63;.
2206             *
2207             * @param groupId the group ID
2208             * @param firstInGroup the first in group
2209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2210             * @return the last matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
2211             * @throws SystemException if a system exception occurred
2212             */
2213            public SocialActivityAchievement fetchByG_F_Last(long groupId,
2214                    boolean firstInGroup, OrderByComparator orderByComparator)
2215                    throws SystemException {
2216                    int count = countByG_F(groupId, firstInGroup);
2217    
2218                    List<SocialActivityAchievement> list = findByG_F(groupId, firstInGroup,
2219                                    count - 1, count, orderByComparator);
2220    
2221                    if (!list.isEmpty()) {
2222                            return list.get(0);
2223                    }
2224    
2225                    return null;
2226            }
2227    
2228            /**
2229             * Returns the social activity achievements before and after the current social activity achievement in the ordered set where groupId = &#63; and firstInGroup = &#63;.
2230             *
2231             * @param activityAchievementId the primary key of the current social activity achievement
2232             * @param groupId the group ID
2233             * @param firstInGroup the first in group
2234             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2235             * @return the previous, current, and next social activity achievement
2236             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a social activity achievement with the primary key could not be found
2237             * @throws SystemException if a system exception occurred
2238             */
2239            public SocialActivityAchievement[] findByG_F_PrevAndNext(
2240                    long activityAchievementId, long groupId, boolean firstInGroup,
2241                    OrderByComparator orderByComparator)
2242                    throws NoSuchActivityAchievementException, SystemException {
2243                    SocialActivityAchievement socialActivityAchievement = findByPrimaryKey(activityAchievementId);
2244    
2245                    Session session = null;
2246    
2247                    try {
2248                            session = openSession();
2249    
2250                            SocialActivityAchievement[] array = new SocialActivityAchievementImpl[3];
2251    
2252                            array[0] = getByG_F_PrevAndNext(session, socialActivityAchievement,
2253                                            groupId, firstInGroup, orderByComparator, true);
2254    
2255                            array[1] = socialActivityAchievement;
2256    
2257                            array[2] = getByG_F_PrevAndNext(session, socialActivityAchievement,
2258                                            groupId, firstInGroup, orderByComparator, false);
2259    
2260                            return array;
2261                    }
2262                    catch (Exception e) {
2263                            throw processException(e);
2264                    }
2265                    finally {
2266                            closeSession(session);
2267                    }
2268            }
2269    
2270            protected SocialActivityAchievement getByG_F_PrevAndNext(Session session,
2271                    SocialActivityAchievement socialActivityAchievement, long groupId,
2272                    boolean firstInGroup, OrderByComparator orderByComparator,
2273                    boolean previous) {
2274                    StringBundler query = null;
2275    
2276                    if (orderByComparator != null) {
2277                            query = new StringBundler(6 +
2278                                            (orderByComparator.getOrderByFields().length * 6));
2279                    }
2280                    else {
2281                            query = new StringBundler(3);
2282                    }
2283    
2284                    query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
2285    
2286                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
2287    
2288                    query.append(_FINDER_COLUMN_G_F_FIRSTINGROUP_2);
2289    
2290                    if (orderByComparator != null) {
2291                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2292    
2293                            if (orderByConditionFields.length > 0) {
2294                                    query.append(WHERE_AND);
2295                            }
2296    
2297                            for (int i = 0; i < orderByConditionFields.length; i++) {
2298                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2299                                    query.append(orderByConditionFields[i]);
2300    
2301                                    if ((i + 1) < orderByConditionFields.length) {
2302                                            if (orderByComparator.isAscending() ^ previous) {
2303                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2304                                            }
2305                                            else {
2306                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2307                                            }
2308                                    }
2309                                    else {
2310                                            if (orderByComparator.isAscending() ^ previous) {
2311                                                    query.append(WHERE_GREATER_THAN);
2312                                            }
2313                                            else {
2314                                                    query.append(WHERE_LESSER_THAN);
2315                                            }
2316                                    }
2317                            }
2318    
2319                            query.append(ORDER_BY_CLAUSE);
2320    
2321                            String[] orderByFields = orderByComparator.getOrderByFields();
2322    
2323                            for (int i = 0; i < orderByFields.length; i++) {
2324                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2325                                    query.append(orderByFields[i]);
2326    
2327                                    if ((i + 1) < orderByFields.length) {
2328                                            if (orderByComparator.isAscending() ^ previous) {
2329                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2330                                            }
2331                                            else {
2332                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2333                                            }
2334                                    }
2335                                    else {
2336                                            if (orderByComparator.isAscending() ^ previous) {
2337                                                    query.append(ORDER_BY_ASC);
2338                                            }
2339                                            else {
2340                                                    query.append(ORDER_BY_DESC);
2341                                            }
2342                                    }
2343                            }
2344                    }
2345    
2346                    String sql = query.toString();
2347    
2348                    Query q = session.createQuery(sql);
2349    
2350                    q.setFirstResult(0);
2351                    q.setMaxResults(2);
2352    
2353                    QueryPos qPos = QueryPos.getInstance(q);
2354    
2355                    qPos.add(groupId);
2356    
2357                    qPos.add(firstInGroup);
2358    
2359                    if (orderByComparator != null) {
2360                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityAchievement);
2361    
2362                            for (Object value : values) {
2363                                    qPos.add(value);
2364                            }
2365                    }
2366    
2367                    List<SocialActivityAchievement> list = q.list();
2368    
2369                    if (list.size() == 2) {
2370                            return list.get(1);
2371                    }
2372                    else {
2373                            return null;
2374                    }
2375            }
2376    
2377            /**
2378             * Returns the social activity achievement where groupId = &#63; and userId = &#63; and name = &#63; or throws a {@link com.liferay.portlet.social.NoSuchActivityAchievementException} if it could not be found.
2379             *
2380             * @param groupId the group ID
2381             * @param userId the user ID
2382             * @param name the name
2383             * @return the matching social activity achievement
2384             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
2385             * @throws SystemException if a system exception occurred
2386             */
2387            public SocialActivityAchievement findByG_U_N(long groupId, long userId,
2388                    String name) throws NoSuchActivityAchievementException, SystemException {
2389                    SocialActivityAchievement socialActivityAchievement = fetchByG_U_N(groupId,
2390                                    userId, name);
2391    
2392                    if (socialActivityAchievement == null) {
2393                            StringBundler msg = new StringBundler(8);
2394    
2395                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2396    
2397                            msg.append("groupId=");
2398                            msg.append(groupId);
2399    
2400                            msg.append(", userId=");
2401                            msg.append(userId);
2402    
2403                            msg.append(", name=");
2404                            msg.append(name);
2405    
2406                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2407    
2408                            if (_log.isWarnEnabled()) {
2409                                    _log.warn(msg.toString());
2410                            }
2411    
2412                            throw new NoSuchActivityAchievementException(msg.toString());
2413                    }
2414    
2415                    return socialActivityAchievement;
2416            }
2417    
2418            /**
2419             * Returns the social activity achievement where groupId = &#63; and userId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2420             *
2421             * @param groupId the group ID
2422             * @param userId the user ID
2423             * @param name the name
2424             * @return the matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
2425             * @throws SystemException if a system exception occurred
2426             */
2427            public SocialActivityAchievement fetchByG_U_N(long groupId, long userId,
2428                    String name) throws SystemException {
2429                    return fetchByG_U_N(groupId, userId, name, true);
2430            }
2431    
2432            /**
2433             * Returns the social activity achievement where groupId = &#63; and userId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2434             *
2435             * @param groupId the group ID
2436             * @param userId the user ID
2437             * @param name the name
2438             * @param retrieveFromCache whether to use the finder cache
2439             * @return the matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
2440             * @throws SystemException if a system exception occurred
2441             */
2442            public SocialActivityAchievement fetchByG_U_N(long groupId, long userId,
2443                    String name, boolean retrieveFromCache) throws SystemException {
2444                    Object[] finderArgs = new Object[] { groupId, userId, name };
2445    
2446                    Object result = null;
2447    
2448                    if (retrieveFromCache) {
2449                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U_N,
2450                                            finderArgs, this);
2451                    }
2452    
2453                    if (result instanceof SocialActivityAchievement) {
2454                            SocialActivityAchievement socialActivityAchievement = (SocialActivityAchievement)result;
2455    
2456                            if ((groupId != socialActivityAchievement.getGroupId()) ||
2457                                            (userId != socialActivityAchievement.getUserId()) ||
2458                                            !Validator.equals(name, socialActivityAchievement.getName())) {
2459                                    result = null;
2460                            }
2461                    }
2462    
2463                    if (result == null) {
2464                            StringBundler query = new StringBundler(4);
2465    
2466                            query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
2467    
2468                            query.append(_FINDER_COLUMN_G_U_N_GROUPID_2);
2469    
2470                            query.append(_FINDER_COLUMN_G_U_N_USERID_2);
2471    
2472                            if (name == null) {
2473                                    query.append(_FINDER_COLUMN_G_U_N_NAME_1);
2474                            }
2475                            else {
2476                                    if (name.equals(StringPool.BLANK)) {
2477                                            query.append(_FINDER_COLUMN_G_U_N_NAME_3);
2478                                    }
2479                                    else {
2480                                            query.append(_FINDER_COLUMN_G_U_N_NAME_2);
2481                                    }
2482                            }
2483    
2484                            String sql = query.toString();
2485    
2486                            Session session = null;
2487    
2488                            try {
2489                                    session = openSession();
2490    
2491                                    Query q = session.createQuery(sql);
2492    
2493                                    QueryPos qPos = QueryPos.getInstance(q);
2494    
2495                                    qPos.add(groupId);
2496    
2497                                    qPos.add(userId);
2498    
2499                                    if (name != null) {
2500                                            qPos.add(name);
2501                                    }
2502    
2503                                    List<SocialActivityAchievement> list = q.list();
2504    
2505                                    result = list;
2506    
2507                                    SocialActivityAchievement socialActivityAchievement = null;
2508    
2509                                    if (list.isEmpty()) {
2510                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_N,
2511                                                    finderArgs, list);
2512                                    }
2513                                    else {
2514                                            socialActivityAchievement = list.get(0);
2515    
2516                                            cacheResult(socialActivityAchievement);
2517    
2518                                            if ((socialActivityAchievement.getGroupId() != groupId) ||
2519                                                            (socialActivityAchievement.getUserId() != userId) ||
2520                                                            (socialActivityAchievement.getName() == null) ||
2521                                                            !socialActivityAchievement.getName().equals(name)) {
2522                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U_N,
2523                                                            finderArgs, socialActivityAchievement);
2524                                            }
2525                                    }
2526    
2527                                    return socialActivityAchievement;
2528                            }
2529                            catch (Exception e) {
2530                                    throw processException(e);
2531                            }
2532                            finally {
2533                                    if (result == null) {
2534                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U_N,
2535                                                    finderArgs);
2536                                    }
2537    
2538                                    closeSession(session);
2539                            }
2540                    }
2541                    else {
2542                            if (result instanceof List<?>) {
2543                                    return null;
2544                            }
2545                            else {
2546                                    return (SocialActivityAchievement)result;
2547                            }
2548                    }
2549            }
2550    
2551            /**
2552             * Returns all the social activity achievements where groupId = &#63; and userId = &#63; and firstInGroup = &#63;.
2553             *
2554             * @param groupId the group ID
2555             * @param userId the user ID
2556             * @param firstInGroup the first in group
2557             * @return the matching social activity achievements
2558             * @throws SystemException if a system exception occurred
2559             */
2560            public List<SocialActivityAchievement> findByG_U_F(long groupId,
2561                    long userId, boolean firstInGroup) throws SystemException {
2562                    return findByG_U_F(groupId, userId, firstInGroup, QueryUtil.ALL_POS,
2563                            QueryUtil.ALL_POS, null);
2564            }
2565    
2566            /**
2567             * Returns a range of all the social activity achievements where groupId = &#63; and userId = &#63; and firstInGroup = &#63;.
2568             *
2569             * <p>
2570             * 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.
2571             * </p>
2572             *
2573             * @param groupId the group ID
2574             * @param userId the user ID
2575             * @param firstInGroup the first in group
2576             * @param start the lower bound of the range of social activity achievements
2577             * @param end the upper bound of the range of social activity achievements (not inclusive)
2578             * @return the range of matching social activity achievements
2579             * @throws SystemException if a system exception occurred
2580             */
2581            public List<SocialActivityAchievement> findByG_U_F(long groupId,
2582                    long userId, boolean firstInGroup, int start, int end)
2583                    throws SystemException {
2584                    return findByG_U_F(groupId, userId, firstInGroup, start, end, null);
2585            }
2586    
2587            /**
2588             * Returns an ordered range of all the social activity achievements where groupId = &#63; and userId = &#63; and firstInGroup = &#63;.
2589             *
2590             * <p>
2591             * 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.
2592             * </p>
2593             *
2594             * @param groupId the group ID
2595             * @param userId the user ID
2596             * @param firstInGroup the first in group
2597             * @param start the lower bound of the range of social activity achievements
2598             * @param end the upper bound of the range of social activity achievements (not inclusive)
2599             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2600             * @return the ordered range of matching social activity achievements
2601             * @throws SystemException if a system exception occurred
2602             */
2603            public List<SocialActivityAchievement> findByG_U_F(long groupId,
2604                    long userId, boolean firstInGroup, int start, int end,
2605                    OrderByComparator orderByComparator) throws SystemException {
2606                    FinderPath finderPath = null;
2607                    Object[] finderArgs = null;
2608    
2609                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2610                                    (orderByComparator == null)) {
2611                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_F;
2612                            finderArgs = new Object[] { groupId, userId, firstInGroup };
2613                    }
2614                    else {
2615                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_F;
2616                            finderArgs = new Object[] {
2617                                            groupId, userId, firstInGroup,
2618                                            
2619                                            start, end, orderByComparator
2620                                    };
2621                    }
2622    
2623                    List<SocialActivityAchievement> list = (List<SocialActivityAchievement>)FinderCacheUtil.getResult(finderPath,
2624                                    finderArgs, this);
2625    
2626                    if ((list != null) && !list.isEmpty()) {
2627                            for (SocialActivityAchievement socialActivityAchievement : list) {
2628                                    if ((groupId != socialActivityAchievement.getGroupId()) ||
2629                                                    (userId != socialActivityAchievement.getUserId()) ||
2630                                                    (firstInGroup != socialActivityAchievement.getFirstInGroup())) {
2631                                            list = null;
2632    
2633                                            break;
2634                                    }
2635                            }
2636                    }
2637    
2638                    if (list == null) {
2639                            StringBundler query = null;
2640    
2641                            if (orderByComparator != null) {
2642                                    query = new StringBundler(5 +
2643                                                    (orderByComparator.getOrderByFields().length * 3));
2644                            }
2645                            else {
2646                                    query = new StringBundler(4);
2647                            }
2648    
2649                            query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
2650    
2651                            query.append(_FINDER_COLUMN_G_U_F_GROUPID_2);
2652    
2653                            query.append(_FINDER_COLUMN_G_U_F_USERID_2);
2654    
2655                            query.append(_FINDER_COLUMN_G_U_F_FIRSTINGROUP_2);
2656    
2657                            if (orderByComparator != null) {
2658                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2659                                            orderByComparator);
2660                            }
2661    
2662                            String sql = query.toString();
2663    
2664                            Session session = null;
2665    
2666                            try {
2667                                    session = openSession();
2668    
2669                                    Query q = session.createQuery(sql);
2670    
2671                                    QueryPos qPos = QueryPos.getInstance(q);
2672    
2673                                    qPos.add(groupId);
2674    
2675                                    qPos.add(userId);
2676    
2677                                    qPos.add(firstInGroup);
2678    
2679                                    list = (List<SocialActivityAchievement>)QueryUtil.list(q,
2680                                                    getDialect(), start, end);
2681                            }
2682                            catch (Exception e) {
2683                                    throw processException(e);
2684                            }
2685                            finally {
2686                                    if (list == null) {
2687                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2688                                    }
2689                                    else {
2690                                            cacheResult(list);
2691    
2692                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2693                                    }
2694    
2695                                    closeSession(session);
2696                            }
2697                    }
2698    
2699                    return list;
2700            }
2701    
2702            /**
2703             * Returns the first social activity achievement in the ordered set where groupId = &#63; and userId = &#63; and firstInGroup = &#63;.
2704             *
2705             * @param groupId the group ID
2706             * @param userId the user ID
2707             * @param firstInGroup the first in group
2708             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2709             * @return the first matching social activity achievement
2710             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
2711             * @throws SystemException if a system exception occurred
2712             */
2713            public SocialActivityAchievement findByG_U_F_First(long groupId,
2714                    long userId, boolean firstInGroup, OrderByComparator orderByComparator)
2715                    throws NoSuchActivityAchievementException, SystemException {
2716                    SocialActivityAchievement socialActivityAchievement = fetchByG_U_F_First(groupId,
2717                                    userId, firstInGroup, orderByComparator);
2718    
2719                    if (socialActivityAchievement != null) {
2720                            return socialActivityAchievement;
2721                    }
2722    
2723                    StringBundler msg = new StringBundler(8);
2724    
2725                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2726    
2727                    msg.append("groupId=");
2728                    msg.append(groupId);
2729    
2730                    msg.append(", userId=");
2731                    msg.append(userId);
2732    
2733                    msg.append(", firstInGroup=");
2734                    msg.append(firstInGroup);
2735    
2736                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2737    
2738                    throw new NoSuchActivityAchievementException(msg.toString());
2739            }
2740    
2741            /**
2742             * Returns the first social activity achievement in the ordered set where groupId = &#63; and userId = &#63; and firstInGroup = &#63;.
2743             *
2744             * @param groupId the group ID
2745             * @param userId the user ID
2746             * @param firstInGroup the first in group
2747             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2748             * @return the first matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
2749             * @throws SystemException if a system exception occurred
2750             */
2751            public SocialActivityAchievement fetchByG_U_F_First(long groupId,
2752                    long userId, boolean firstInGroup, OrderByComparator orderByComparator)
2753                    throws SystemException {
2754                    List<SocialActivityAchievement> list = findByG_U_F(groupId, userId,
2755                                    firstInGroup, 0, 1, orderByComparator);
2756    
2757                    if (!list.isEmpty()) {
2758                            return list.get(0);
2759                    }
2760    
2761                    return null;
2762            }
2763    
2764            /**
2765             * Returns the last social activity achievement in the ordered set where groupId = &#63; and userId = &#63; and firstInGroup = &#63;.
2766             *
2767             * @param groupId the group ID
2768             * @param userId the user ID
2769             * @param firstInGroup the first in group
2770             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2771             * @return the last matching social activity achievement
2772             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a matching social activity achievement could not be found
2773             * @throws SystemException if a system exception occurred
2774             */
2775            public SocialActivityAchievement findByG_U_F_Last(long groupId,
2776                    long userId, boolean firstInGroup, OrderByComparator orderByComparator)
2777                    throws NoSuchActivityAchievementException, SystemException {
2778                    SocialActivityAchievement socialActivityAchievement = fetchByG_U_F_Last(groupId,
2779                                    userId, firstInGroup, orderByComparator);
2780    
2781                    if (socialActivityAchievement != null) {
2782                            return socialActivityAchievement;
2783                    }
2784    
2785                    StringBundler msg = new StringBundler(8);
2786    
2787                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2788    
2789                    msg.append("groupId=");
2790                    msg.append(groupId);
2791    
2792                    msg.append(", userId=");
2793                    msg.append(userId);
2794    
2795                    msg.append(", firstInGroup=");
2796                    msg.append(firstInGroup);
2797    
2798                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2799    
2800                    throw new NoSuchActivityAchievementException(msg.toString());
2801            }
2802    
2803            /**
2804             * Returns the last social activity achievement in the ordered set where groupId = &#63; and userId = &#63; and firstInGroup = &#63;.
2805             *
2806             * @param groupId the group ID
2807             * @param userId the user ID
2808             * @param firstInGroup the first in group
2809             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2810             * @return the last matching social activity achievement, or <code>null</code> if a matching social activity achievement could not be found
2811             * @throws SystemException if a system exception occurred
2812             */
2813            public SocialActivityAchievement fetchByG_U_F_Last(long groupId,
2814                    long userId, boolean firstInGroup, OrderByComparator orderByComparator)
2815                    throws SystemException {
2816                    int count = countByG_U_F(groupId, userId, firstInGroup);
2817    
2818                    List<SocialActivityAchievement> list = findByG_U_F(groupId, userId,
2819                                    firstInGroup, count - 1, count, orderByComparator);
2820    
2821                    if (!list.isEmpty()) {
2822                            return list.get(0);
2823                    }
2824    
2825                    return null;
2826            }
2827    
2828            /**
2829             * Returns the social activity achievements before and after the current social activity achievement in the ordered set where groupId = &#63; and userId = &#63; and firstInGroup = &#63;.
2830             *
2831             * @param activityAchievementId the primary key of the current social activity achievement
2832             * @param groupId the group ID
2833             * @param userId the user ID
2834             * @param firstInGroup the first in group
2835             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2836             * @return the previous, current, and next social activity achievement
2837             * @throws com.liferay.portlet.social.NoSuchActivityAchievementException if a social activity achievement with the primary key could not be found
2838             * @throws SystemException if a system exception occurred
2839             */
2840            public SocialActivityAchievement[] findByG_U_F_PrevAndNext(
2841                    long activityAchievementId, long groupId, long userId,
2842                    boolean firstInGroup, OrderByComparator orderByComparator)
2843                    throws NoSuchActivityAchievementException, SystemException {
2844                    SocialActivityAchievement socialActivityAchievement = findByPrimaryKey(activityAchievementId);
2845    
2846                    Session session = null;
2847    
2848                    try {
2849                            session = openSession();
2850    
2851                            SocialActivityAchievement[] array = new SocialActivityAchievementImpl[3];
2852    
2853                            array[0] = getByG_U_F_PrevAndNext(session,
2854                                            socialActivityAchievement, groupId, userId, firstInGroup,
2855                                            orderByComparator, true);
2856    
2857                            array[1] = socialActivityAchievement;
2858    
2859                            array[2] = getByG_U_F_PrevAndNext(session,
2860                                            socialActivityAchievement, groupId, userId, firstInGroup,
2861                                            orderByComparator, false);
2862    
2863                            return array;
2864                    }
2865                    catch (Exception e) {
2866                            throw processException(e);
2867                    }
2868                    finally {
2869                            closeSession(session);
2870                    }
2871            }
2872    
2873            protected SocialActivityAchievement getByG_U_F_PrevAndNext(
2874                    Session session, SocialActivityAchievement socialActivityAchievement,
2875                    long groupId, long userId, boolean firstInGroup,
2876                    OrderByComparator orderByComparator, boolean previous) {
2877                    StringBundler query = null;
2878    
2879                    if (orderByComparator != null) {
2880                            query = new StringBundler(6 +
2881                                            (orderByComparator.getOrderByFields().length * 6));
2882                    }
2883                    else {
2884                            query = new StringBundler(3);
2885                    }
2886    
2887                    query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE);
2888    
2889                    query.append(_FINDER_COLUMN_G_U_F_GROUPID_2);
2890    
2891                    query.append(_FINDER_COLUMN_G_U_F_USERID_2);
2892    
2893                    query.append(_FINDER_COLUMN_G_U_F_FIRSTINGROUP_2);
2894    
2895                    if (orderByComparator != null) {
2896                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2897    
2898                            if (orderByConditionFields.length > 0) {
2899                                    query.append(WHERE_AND);
2900                            }
2901    
2902                            for (int i = 0; i < orderByConditionFields.length; i++) {
2903                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2904                                    query.append(orderByConditionFields[i]);
2905    
2906                                    if ((i + 1) < orderByConditionFields.length) {
2907                                            if (orderByComparator.isAscending() ^ previous) {
2908                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2909                                            }
2910                                            else {
2911                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2912                                            }
2913                                    }
2914                                    else {
2915                                            if (orderByComparator.isAscending() ^ previous) {
2916                                                    query.append(WHERE_GREATER_THAN);
2917                                            }
2918                                            else {
2919                                                    query.append(WHERE_LESSER_THAN);
2920                                            }
2921                                    }
2922                            }
2923    
2924                            query.append(ORDER_BY_CLAUSE);
2925    
2926                            String[] orderByFields = orderByComparator.getOrderByFields();
2927    
2928                            for (int i = 0; i < orderByFields.length; i++) {
2929                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2930                                    query.append(orderByFields[i]);
2931    
2932                                    if ((i + 1) < orderByFields.length) {
2933                                            if (orderByComparator.isAscending() ^ previous) {
2934                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2935                                            }
2936                                            else {
2937                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2938                                            }
2939                                    }
2940                                    else {
2941                                            if (orderByComparator.isAscending() ^ previous) {
2942                                                    query.append(ORDER_BY_ASC);
2943                                            }
2944                                            else {
2945                                                    query.append(ORDER_BY_DESC);
2946                                            }
2947                                    }
2948                            }
2949                    }
2950    
2951                    String sql = query.toString();
2952    
2953                    Query q = session.createQuery(sql);
2954    
2955                    q.setFirstResult(0);
2956                    q.setMaxResults(2);
2957    
2958                    QueryPos qPos = QueryPos.getInstance(q);
2959    
2960                    qPos.add(groupId);
2961    
2962                    qPos.add(userId);
2963    
2964                    qPos.add(firstInGroup);
2965    
2966                    if (orderByComparator != null) {
2967                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivityAchievement);
2968    
2969                            for (Object value : values) {
2970                                    qPos.add(value);
2971                            }
2972                    }
2973    
2974                    List<SocialActivityAchievement> list = q.list();
2975    
2976                    if (list.size() == 2) {
2977                            return list.get(1);
2978                    }
2979                    else {
2980                            return null;
2981                    }
2982            }
2983    
2984            /**
2985             * Returns all the social activity achievements.
2986             *
2987             * @return the social activity achievements
2988             * @throws SystemException if a system exception occurred
2989             */
2990            public List<SocialActivityAchievement> findAll() throws SystemException {
2991                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2992            }
2993    
2994            /**
2995             * Returns a range of all the social activity achievements.
2996             *
2997             * <p>
2998             * 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.
2999             * </p>
3000             *
3001             * @param start the lower bound of the range of social activity achievements
3002             * @param end the upper bound of the range of social activity achievements (not inclusive)
3003             * @return the range of social activity achievements
3004             * @throws SystemException if a system exception occurred
3005             */
3006            public List<SocialActivityAchievement> findAll(int start, int end)
3007                    throws SystemException {
3008                    return findAll(start, end, null);
3009            }
3010    
3011            /**
3012             * Returns an ordered range of all the social activity achievements.
3013             *
3014             * <p>
3015             * 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.
3016             * </p>
3017             *
3018             * @param start the lower bound of the range of social activity achievements
3019             * @param end the upper bound of the range of social activity achievements (not inclusive)
3020             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3021             * @return the ordered range of social activity achievements
3022             * @throws SystemException if a system exception occurred
3023             */
3024            public List<SocialActivityAchievement> findAll(int start, int end,
3025                    OrderByComparator orderByComparator) throws SystemException {
3026                    FinderPath finderPath = null;
3027                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
3028    
3029                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3030                                    (orderByComparator == null)) {
3031                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3032                            finderArgs = FINDER_ARGS_EMPTY;
3033                    }
3034                    else {
3035                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3036                            finderArgs = new Object[] { start, end, orderByComparator };
3037                    }
3038    
3039                    List<SocialActivityAchievement> list = (List<SocialActivityAchievement>)FinderCacheUtil.getResult(finderPath,
3040                                    finderArgs, this);
3041    
3042                    if (list == null) {
3043                            StringBundler query = null;
3044                            String sql = null;
3045    
3046                            if (orderByComparator != null) {
3047                                    query = new StringBundler(2 +
3048                                                    (orderByComparator.getOrderByFields().length * 3));
3049    
3050                                    query.append(_SQL_SELECT_SOCIALACTIVITYACHIEVEMENT);
3051    
3052                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3053                                            orderByComparator);
3054    
3055                                    sql = query.toString();
3056                            }
3057                            else {
3058                                    sql = _SQL_SELECT_SOCIALACTIVITYACHIEVEMENT;
3059                            }
3060    
3061                            Session session = null;
3062    
3063                            try {
3064                                    session = openSession();
3065    
3066                                    Query q = session.createQuery(sql);
3067    
3068                                    if (orderByComparator == null) {
3069                                            list = (List<SocialActivityAchievement>)QueryUtil.list(q,
3070                                                            getDialect(), start, end, false);
3071    
3072                                            Collections.sort(list);
3073                                    }
3074                                    else {
3075                                            list = (List<SocialActivityAchievement>)QueryUtil.list(q,
3076                                                            getDialect(), start, end);
3077                                    }
3078                            }
3079                            catch (Exception e) {
3080                                    throw processException(e);
3081                            }
3082                            finally {
3083                                    if (list == null) {
3084                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3085                                    }
3086                                    else {
3087                                            cacheResult(list);
3088    
3089                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3090                                    }
3091    
3092                                    closeSession(session);
3093                            }
3094                    }
3095    
3096                    return list;
3097            }
3098    
3099            /**
3100             * Removes all the social activity achievements where groupId = &#63; from the database.
3101             *
3102             * @param groupId the group ID
3103             * @throws SystemException if a system exception occurred
3104             */
3105            public void removeByGroupId(long groupId) throws SystemException {
3106                    for (SocialActivityAchievement socialActivityAchievement : findByGroupId(
3107                                    groupId)) {
3108                            remove(socialActivityAchievement);
3109                    }
3110            }
3111    
3112            /**
3113             * Removes all the social activity achievements where groupId = &#63; and userId = &#63; from the database.
3114             *
3115             * @param groupId the group ID
3116             * @param userId the user ID
3117             * @throws SystemException if a system exception occurred
3118             */
3119            public void removeByG_U(long groupId, long userId)
3120                    throws SystemException {
3121                    for (SocialActivityAchievement socialActivityAchievement : findByG_U(
3122                                    groupId, userId)) {
3123                            remove(socialActivityAchievement);
3124                    }
3125            }
3126    
3127            /**
3128             * Removes all the social activity achievements where groupId = &#63; and name = &#63; from the database.
3129             *
3130             * @param groupId the group ID
3131             * @param name the name
3132             * @throws SystemException if a system exception occurred
3133             */
3134            public void removeByG_N(long groupId, String name)
3135                    throws SystemException {
3136                    for (SocialActivityAchievement socialActivityAchievement : findByG_N(
3137                                    groupId, name)) {
3138                            remove(socialActivityAchievement);
3139                    }
3140            }
3141    
3142            /**
3143             * Removes all the social activity achievements where groupId = &#63; and firstInGroup = &#63; from the database.
3144             *
3145             * @param groupId the group ID
3146             * @param firstInGroup the first in group
3147             * @throws SystemException if a system exception occurred
3148             */
3149            public void removeByG_F(long groupId, boolean firstInGroup)
3150                    throws SystemException {
3151                    for (SocialActivityAchievement socialActivityAchievement : findByG_F(
3152                                    groupId, firstInGroup)) {
3153                            remove(socialActivityAchievement);
3154                    }
3155            }
3156    
3157            /**
3158             * Removes the social activity achievement where groupId = &#63; and userId = &#63; and name = &#63; from the database.
3159             *
3160             * @param groupId the group ID
3161             * @param userId the user ID
3162             * @param name the name
3163             * @return the social activity achievement that was removed
3164             * @throws SystemException if a system exception occurred
3165             */
3166            public SocialActivityAchievement removeByG_U_N(long groupId, long userId,
3167                    String name) throws NoSuchActivityAchievementException, SystemException {
3168                    SocialActivityAchievement socialActivityAchievement = findByG_U_N(groupId,
3169                                    userId, name);
3170    
3171                    return remove(socialActivityAchievement);
3172            }
3173    
3174            /**
3175             * Removes all the social activity achievements where groupId = &#63; and userId = &#63; and firstInGroup = &#63; from the database.
3176             *
3177             * @param groupId the group ID
3178             * @param userId the user ID
3179             * @param firstInGroup the first in group
3180             * @throws SystemException if a system exception occurred
3181             */
3182            public void removeByG_U_F(long groupId, long userId, boolean firstInGroup)
3183                    throws SystemException {
3184                    for (SocialActivityAchievement socialActivityAchievement : findByG_U_F(
3185                                    groupId, userId, firstInGroup)) {
3186                            remove(socialActivityAchievement);
3187                    }
3188            }
3189    
3190            /**
3191             * Removes all the social activity achievements from the database.
3192             *
3193             * @throws SystemException if a system exception occurred
3194             */
3195            public void removeAll() throws SystemException {
3196                    for (SocialActivityAchievement socialActivityAchievement : findAll()) {
3197                            remove(socialActivityAchievement);
3198                    }
3199            }
3200    
3201            /**
3202             * Returns the number of social activity achievements where groupId = &#63;.
3203             *
3204             * @param groupId the group ID
3205             * @return the number of matching social activity achievements
3206             * @throws SystemException if a system exception occurred
3207             */
3208            public int countByGroupId(long groupId) throws SystemException {
3209                    Object[] finderArgs = new Object[] { groupId };
3210    
3211                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3212                                    finderArgs, this);
3213    
3214                    if (count == null) {
3215                            StringBundler query = new StringBundler(2);
3216    
3217                            query.append(_SQL_COUNT_SOCIALACTIVITYACHIEVEMENT_WHERE);
3218    
3219                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3220    
3221                            String sql = query.toString();
3222    
3223                            Session session = null;
3224    
3225                            try {
3226                                    session = openSession();
3227    
3228                                    Query q = session.createQuery(sql);
3229    
3230                                    QueryPos qPos = QueryPos.getInstance(q);
3231    
3232                                    qPos.add(groupId);
3233    
3234                                    count = (Long)q.uniqueResult();
3235                            }
3236                            catch (Exception e) {
3237                                    throw processException(e);
3238                            }
3239                            finally {
3240                                    if (count == null) {
3241                                            count = Long.valueOf(0);
3242                                    }
3243    
3244                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3245                                            finderArgs, count);
3246    
3247                                    closeSession(session);
3248                            }
3249                    }
3250    
3251                    return count.intValue();
3252            }
3253    
3254            /**
3255             * Returns the number of social activity achievements where groupId = &#63; and userId = &#63;.
3256             *
3257             * @param groupId the group ID
3258             * @param userId the user ID
3259             * @return the number of matching social activity achievements
3260             * @throws SystemException if a system exception occurred
3261             */
3262            public int countByG_U(long groupId, long userId) throws SystemException {
3263                    Object[] finderArgs = new Object[] { groupId, userId };
3264    
3265                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
3266                                    finderArgs, this);
3267    
3268                    if (count == null) {
3269                            StringBundler query = new StringBundler(3);
3270    
3271                            query.append(_SQL_COUNT_SOCIALACTIVITYACHIEVEMENT_WHERE);
3272    
3273                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
3274    
3275                            query.append(_FINDER_COLUMN_G_U_USERID_2);
3276    
3277                            String sql = query.toString();
3278    
3279                            Session session = null;
3280    
3281                            try {
3282                                    session = openSession();
3283    
3284                                    Query q = session.createQuery(sql);
3285    
3286                                    QueryPos qPos = QueryPos.getInstance(q);
3287    
3288                                    qPos.add(groupId);
3289    
3290                                    qPos.add(userId);
3291    
3292                                    count = (Long)q.uniqueResult();
3293                            }
3294                            catch (Exception e) {
3295                                    throw processException(e);
3296                            }
3297                            finally {
3298                                    if (count == null) {
3299                                            count = Long.valueOf(0);
3300                                    }
3301    
3302                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
3303                                            count);
3304    
3305                                    closeSession(session);
3306                            }
3307                    }
3308    
3309                    return count.intValue();
3310            }
3311    
3312            /**
3313             * Returns the number of social activity achievements where groupId = &#63; and name = &#63;.
3314             *
3315             * @param groupId the group ID
3316             * @param name the name
3317             * @return the number of matching social activity achievements
3318             * @throws SystemException if a system exception occurred
3319             */
3320            public int countByG_N(long groupId, String name) throws SystemException {
3321                    Object[] finderArgs = new Object[] { groupId, name };
3322    
3323                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
3324                                    finderArgs, this);
3325    
3326                    if (count == null) {
3327                            StringBundler query = new StringBundler(3);
3328    
3329                            query.append(_SQL_COUNT_SOCIALACTIVITYACHIEVEMENT_WHERE);
3330    
3331                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
3332    
3333                            if (name == null) {
3334                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
3335                            }
3336                            else {
3337                                    if (name.equals(StringPool.BLANK)) {
3338                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
3339                                    }
3340                                    else {
3341                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
3342                                    }
3343                            }
3344    
3345                            String sql = query.toString();
3346    
3347                            Session session = null;
3348    
3349                            try {
3350                                    session = openSession();
3351    
3352                                    Query q = session.createQuery(sql);
3353    
3354                                    QueryPos qPos = QueryPos.getInstance(q);
3355    
3356                                    qPos.add(groupId);
3357    
3358                                    if (name != null) {
3359                                            qPos.add(name);
3360                                    }
3361    
3362                                    count = (Long)q.uniqueResult();
3363                            }
3364                            catch (Exception e) {
3365                                    throw processException(e);
3366                            }
3367                            finally {
3368                                    if (count == null) {
3369                                            count = Long.valueOf(0);
3370                                    }
3371    
3372                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
3373                                            count);
3374    
3375                                    closeSession(session);
3376                            }
3377                    }
3378    
3379                    return count.intValue();
3380            }
3381    
3382            /**
3383             * Returns the number of social activity achievements where groupId = &#63; and firstInGroup = &#63;.
3384             *
3385             * @param groupId the group ID
3386             * @param firstInGroup the first in group
3387             * @return the number of matching social activity achievements
3388             * @throws SystemException if a system exception occurred
3389             */
3390            public int countByG_F(long groupId, boolean firstInGroup)
3391                    throws SystemException {
3392                    Object[] finderArgs = new Object[] { groupId, firstInGroup };
3393    
3394                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
3395                                    finderArgs, this);
3396    
3397                    if (count == null) {
3398                            StringBundler query = new StringBundler(3);
3399    
3400                            query.append(_SQL_COUNT_SOCIALACTIVITYACHIEVEMENT_WHERE);
3401    
3402                            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
3403    
3404                            query.append(_FINDER_COLUMN_G_F_FIRSTINGROUP_2);
3405    
3406                            String sql = query.toString();
3407    
3408                            Session session = null;
3409    
3410                            try {
3411                                    session = openSession();
3412    
3413                                    Query q = session.createQuery(sql);
3414    
3415                                    QueryPos qPos = QueryPos.getInstance(q);
3416    
3417                                    qPos.add(groupId);
3418    
3419                                    qPos.add(firstInGroup);
3420    
3421                                    count = (Long)q.uniqueResult();
3422                            }
3423                            catch (Exception e) {
3424                                    throw processException(e);
3425                            }
3426                            finally {
3427                                    if (count == null) {
3428                                            count = Long.valueOf(0);
3429                                    }
3430    
3431                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
3432                                            count);
3433    
3434                                    closeSession(session);
3435                            }
3436                    }
3437    
3438                    return count.intValue();
3439            }
3440    
3441            /**
3442             * Returns the number of social activity achievements where groupId = &#63; and userId = &#63; and name = &#63;.
3443             *
3444             * @param groupId the group ID
3445             * @param userId the user ID
3446             * @param name the name
3447             * @return the number of matching social activity achievements
3448             * @throws SystemException if a system exception occurred
3449             */
3450            public int countByG_U_N(long groupId, long userId, String name)
3451                    throws SystemException {
3452                    Object[] finderArgs = new Object[] { groupId, userId, name };
3453    
3454                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_N,
3455                                    finderArgs, this);
3456    
3457                    if (count == null) {
3458                            StringBundler query = new StringBundler(4);
3459    
3460                            query.append(_SQL_COUNT_SOCIALACTIVITYACHIEVEMENT_WHERE);
3461    
3462                            query.append(_FINDER_COLUMN_G_U_N_GROUPID_2);
3463    
3464                            query.append(_FINDER_COLUMN_G_U_N_USERID_2);
3465    
3466                            if (name == null) {
3467                                    query.append(_FINDER_COLUMN_G_U_N_NAME_1);
3468                            }
3469                            else {
3470                                    if (name.equals(StringPool.BLANK)) {
3471                                            query.append(_FINDER_COLUMN_G_U_N_NAME_3);
3472                                    }
3473                                    else {
3474                                            query.append(_FINDER_COLUMN_G_U_N_NAME_2);
3475                                    }
3476                            }
3477    
3478                            String sql = query.toString();
3479    
3480                            Session session = null;
3481    
3482                            try {
3483                                    session = openSession();
3484    
3485                                    Query q = session.createQuery(sql);
3486    
3487                                    QueryPos qPos = QueryPos.getInstance(q);
3488    
3489                                    qPos.add(groupId);
3490    
3491                                    qPos.add(userId);
3492    
3493                                    if (name != null) {
3494                                            qPos.add(name);
3495                                    }
3496    
3497                                    count = (Long)q.uniqueResult();
3498                            }
3499                            catch (Exception e) {
3500                                    throw processException(e);
3501                            }
3502                            finally {
3503                                    if (count == null) {
3504                                            count = Long.valueOf(0);
3505                                    }
3506    
3507                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_N,
3508                                            finderArgs, count);
3509    
3510                                    closeSession(session);
3511                            }
3512                    }
3513    
3514                    return count.intValue();
3515            }
3516    
3517            /**
3518             * Returns the number of social activity achievements where groupId = &#63; and userId = &#63; and firstInGroup = &#63;.
3519             *
3520             * @param groupId the group ID
3521             * @param userId the user ID
3522             * @param firstInGroup the first in group
3523             * @return the number of matching social activity achievements
3524             * @throws SystemException if a system exception occurred
3525             */
3526            public int countByG_U_F(long groupId, long userId, boolean firstInGroup)
3527                    throws SystemException {
3528                    Object[] finderArgs = new Object[] { groupId, userId, firstInGroup };
3529    
3530                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_F,
3531                                    finderArgs, this);
3532    
3533                    if (count == null) {
3534                            StringBundler query = new StringBundler(4);
3535    
3536                            query.append(_SQL_COUNT_SOCIALACTIVITYACHIEVEMENT_WHERE);
3537    
3538                            query.append(_FINDER_COLUMN_G_U_F_GROUPID_2);
3539    
3540                            query.append(_FINDER_COLUMN_G_U_F_USERID_2);
3541    
3542                            query.append(_FINDER_COLUMN_G_U_F_FIRSTINGROUP_2);
3543    
3544                            String sql = query.toString();
3545    
3546                            Session session = null;
3547    
3548                            try {
3549                                    session = openSession();
3550    
3551                                    Query q = session.createQuery(sql);
3552    
3553                                    QueryPos qPos = QueryPos.getInstance(q);
3554    
3555                                    qPos.add(groupId);
3556    
3557                                    qPos.add(userId);
3558    
3559                                    qPos.add(firstInGroup);
3560    
3561                                    count = (Long)q.uniqueResult();
3562                            }
3563                            catch (Exception e) {
3564                                    throw processException(e);
3565                            }
3566                            finally {
3567                                    if (count == null) {
3568                                            count = Long.valueOf(0);
3569                                    }
3570    
3571                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_F,
3572                                            finderArgs, count);
3573    
3574                                    closeSession(session);
3575                            }
3576                    }
3577    
3578                    return count.intValue();
3579            }
3580    
3581            /**
3582             * Returns the number of social activity achievements.
3583             *
3584             * @return the number of social activity achievements
3585             * @throws SystemException if a system exception occurred
3586             */
3587            public int countAll() throws SystemException {
3588                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3589                                    FINDER_ARGS_EMPTY, this);
3590    
3591                    if (count == null) {
3592                            Session session = null;
3593    
3594                            try {
3595                                    session = openSession();
3596    
3597                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYACHIEVEMENT);
3598    
3599                                    count = (Long)q.uniqueResult();
3600                            }
3601                            catch (Exception e) {
3602                                    throw processException(e);
3603                            }
3604                            finally {
3605                                    if (count == null) {
3606                                            count = Long.valueOf(0);
3607                                    }
3608    
3609                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3610                                            FINDER_ARGS_EMPTY, count);
3611    
3612                                    closeSession(session);
3613                            }
3614                    }
3615    
3616                    return count.intValue();
3617            }
3618    
3619            /**
3620             * Initializes the social activity achievement persistence.
3621             */
3622            public void afterPropertiesSet() {
3623                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3624                                            com.liferay.portal.util.PropsUtil.get(
3625                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivityAchievement")));
3626    
3627                    if (listenerClassNames.length > 0) {
3628                            try {
3629                                    List<ModelListener<SocialActivityAchievement>> listenersList = new ArrayList<ModelListener<SocialActivityAchievement>>();
3630    
3631                                    for (String listenerClassName : listenerClassNames) {
3632                                            Class<?> clazz = getClass();
3633    
3634                                            listenersList.add((ModelListener<SocialActivityAchievement>)InstanceFactory.newInstance(
3635                                                            clazz.getClassLoader(), listenerClassName));
3636                                    }
3637    
3638                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3639                            }
3640                            catch (Exception e) {
3641                                    _log.error(e);
3642                            }
3643                    }
3644            }
3645    
3646            public void destroy() {
3647                    EntityCacheUtil.removeCache(SocialActivityAchievementImpl.class.getName());
3648                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3649                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3650            }
3651    
3652            @BeanReference(type = SocialActivityPersistence.class)
3653            protected SocialActivityPersistence socialActivityPersistence;
3654            @BeanReference(type = SocialActivityAchievementPersistence.class)
3655            protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
3656            @BeanReference(type = SocialActivityCounterPersistence.class)
3657            protected SocialActivityCounterPersistence socialActivityCounterPersistence;
3658            @BeanReference(type = SocialActivityLimitPersistence.class)
3659            protected SocialActivityLimitPersistence socialActivityLimitPersistence;
3660            @BeanReference(type = SocialActivitySettingPersistence.class)
3661            protected SocialActivitySettingPersistence socialActivitySettingPersistence;
3662            @BeanReference(type = SocialRelationPersistence.class)
3663            protected SocialRelationPersistence socialRelationPersistence;
3664            @BeanReference(type = SocialRequestPersistence.class)
3665            protected SocialRequestPersistence socialRequestPersistence;
3666            @BeanReference(type = GroupPersistence.class)
3667            protected GroupPersistence groupPersistence;
3668            @BeanReference(type = ResourcePersistence.class)
3669            protected ResourcePersistence resourcePersistence;
3670            @BeanReference(type = UserPersistence.class)
3671            protected UserPersistence userPersistence;
3672            private static final String _SQL_SELECT_SOCIALACTIVITYACHIEVEMENT = "SELECT socialActivityAchievement FROM SocialActivityAchievement socialActivityAchievement";
3673            private static final String _SQL_SELECT_SOCIALACTIVITYACHIEVEMENT_WHERE = "SELECT socialActivityAchievement FROM SocialActivityAchievement socialActivityAchievement WHERE ";
3674            private static final String _SQL_COUNT_SOCIALACTIVITYACHIEVEMENT = "SELECT COUNT(socialActivityAchievement) FROM SocialActivityAchievement socialActivityAchievement";
3675            private static final String _SQL_COUNT_SOCIALACTIVITYACHIEVEMENT_WHERE = "SELECT COUNT(socialActivityAchievement) FROM SocialActivityAchievement socialActivityAchievement WHERE ";
3676            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "socialActivityAchievement.groupId = ?";
3677            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "socialActivityAchievement.groupId = ? AND ";
3678            private static final String _FINDER_COLUMN_G_U_USERID_2 = "socialActivityAchievement.userId = ?";
3679            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "socialActivityAchievement.groupId = ? AND ";
3680            private static final String _FINDER_COLUMN_G_N_NAME_1 = "socialActivityAchievement.name IS NULL";
3681            private static final String _FINDER_COLUMN_G_N_NAME_2 = "socialActivityAchievement.name = ?";
3682            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(socialActivityAchievement.name IS NULL OR socialActivityAchievement.name = ?)";
3683            private static final String _FINDER_COLUMN_G_F_GROUPID_2 = "socialActivityAchievement.groupId = ? AND ";
3684            private static final String _FINDER_COLUMN_G_F_FIRSTINGROUP_2 = "socialActivityAchievement.firstInGroup = ?";
3685            private static final String _FINDER_COLUMN_G_U_N_GROUPID_2 = "socialActivityAchievement.groupId = ? AND ";
3686            private static final String _FINDER_COLUMN_G_U_N_USERID_2 = "socialActivityAchievement.userId = ? AND ";
3687            private static final String _FINDER_COLUMN_G_U_N_NAME_1 = "socialActivityAchievement.name IS NULL";
3688            private static final String _FINDER_COLUMN_G_U_N_NAME_2 = "socialActivityAchievement.name = ?";
3689            private static final String _FINDER_COLUMN_G_U_N_NAME_3 = "(socialActivityAchievement.name IS NULL OR socialActivityAchievement.name = ?)";
3690            private static final String _FINDER_COLUMN_G_U_F_GROUPID_2 = "socialActivityAchievement.groupId = ? AND ";
3691            private static final String _FINDER_COLUMN_G_U_F_USERID_2 = "socialActivityAchievement.userId = ? AND ";
3692            private static final String _FINDER_COLUMN_G_U_F_FIRSTINGROUP_2 = "socialActivityAchievement.firstInGroup = ?";
3693            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivityAchievement.";
3694            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivityAchievement exists with the primary key ";
3695            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivityAchievement exists with the key {";
3696            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3697            private static Log _log = LogFactoryUtil.getLog(SocialActivityAchievementPersistenceImpl.class);
3698            private static SocialActivityAchievement _nullSocialActivityAchievement = new SocialActivityAchievementImpl() {
3699                            @Override
3700                            public Object clone() {
3701                                    return this;
3702                            }
3703    
3704                            @Override
3705                            public CacheModel<SocialActivityAchievement> toCacheModel() {
3706                                    return _nullSocialActivityAchievementCacheModel;
3707                            }
3708                    };
3709    
3710            private static CacheModel<SocialActivityAchievement> _nullSocialActivityAchievementCacheModel =
3711                    new CacheModel<SocialActivityAchievement>() {
3712                            public SocialActivityAchievement toEntityModel() {
3713                                    return _nullSocialActivityAchievement;
3714                            }
3715                    };
3716    }