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