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