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