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