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