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