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