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