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