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