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