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