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