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