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