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