001    /**
002     * Copyright (c) 2000-2013 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;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstanceFactory;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.SetUtil;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039    
040    import com.liferay.portlet.social.NoSuchActivitySetException;
041    import com.liferay.portlet.social.model.SocialActivitySet;
042    import com.liferay.portlet.social.model.impl.SocialActivitySetImpl;
043    import com.liferay.portlet.social.model.impl.SocialActivitySetModelImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.List;
050    import java.util.Set;
051    
052    /**
053     * The persistence implementation for the social activity set service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see SocialActivitySetPersistence
061     * @see SocialActivitySetUtil
062     * @generated
063     */
064    public class SocialActivitySetPersistenceImpl extends BasePersistenceImpl<SocialActivitySet>
065            implements SocialActivitySetPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link SocialActivitySetUtil} to access the social activity set persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivitySetImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
077                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED,
078                            SocialActivitySetImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
081                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED,
082                            SocialActivitySetImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
085                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_T = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
088                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED,
089                            SocialActivitySetImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_T",
091                            new String[] {
092                                    Long.class.getName(), Long.class.getName(),
093                                    Integer.class.getName(),
094                                    
095                            Integer.class.getName(), Integer.class.getName(),
096                                    OrderByComparator.class.getName()
097                            });
098            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_T = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
099                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED,
100                            SocialActivitySetImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_T",
102                            new String[] {
103                                    Long.class.getName(), Long.class.getName(),
104                                    Integer.class.getName()
105                            },
106                            SocialActivitySetModelImpl.GROUPID_COLUMN_BITMASK |
107                            SocialActivitySetModelImpl.USERID_COLUMN_BITMASK |
108                            SocialActivitySetModelImpl.TYPE_COLUMN_BITMASK |
109                            SocialActivitySetModelImpl.MODIFIEDDATE_COLUMN_BITMASK);
110            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_T = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
111                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED, Long.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_T",
113                            new String[] {
114                                    Long.class.getName(), Long.class.getName(),
115                                    Integer.class.getName()
116                            });
117    
118            /**
119             * Returns all the social activity sets where groupId = &#63; and userId = &#63; and type = &#63;.
120             *
121             * @param groupId the group ID
122             * @param userId the user ID
123             * @param type the type
124             * @return the matching social activity sets
125             * @throws SystemException if a system exception occurred
126             */
127            public List<SocialActivitySet> findByG_U_T(long groupId, long userId,
128                    int type) throws SystemException {
129                    return findByG_U_T(groupId, userId, type, QueryUtil.ALL_POS,
130                            QueryUtil.ALL_POS, null);
131            }
132    
133            /**
134             * Returns a range of all the social activity sets where groupId = &#63; and userId = &#63; and type = &#63;.
135             *
136             * <p>
137             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
138             * </p>
139             *
140             * @param groupId the group ID
141             * @param userId the user ID
142             * @param type the type
143             * @param start the lower bound of the range of social activity sets
144             * @param end the upper bound of the range of social activity sets (not inclusive)
145             * @return the range of matching social activity sets
146             * @throws SystemException if a system exception occurred
147             */
148            public List<SocialActivitySet> findByG_U_T(long groupId, long userId,
149                    int type, int start, int end) throws SystemException {
150                    return findByG_U_T(groupId, userId, type, start, end, null);
151            }
152    
153            /**
154             * Returns an ordered range of all the social activity sets where groupId = &#63; and userId = &#63; and type = &#63;.
155             *
156             * <p>
157             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
158             * </p>
159             *
160             * @param groupId the group ID
161             * @param userId the user ID
162             * @param type the type
163             * @param start the lower bound of the range of social activity sets
164             * @param end the upper bound of the range of social activity sets (not inclusive)
165             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
166             * @return the ordered range of matching social activity sets
167             * @throws SystemException if a system exception occurred
168             */
169            public List<SocialActivitySet> findByG_U_T(long groupId, long userId,
170                    int type, int start, int end, OrderByComparator orderByComparator)
171                    throws SystemException {
172                    boolean pagination = true;
173                    FinderPath finderPath = null;
174                    Object[] finderArgs = null;
175    
176                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
177                                    (orderByComparator == null)) {
178                            pagination = false;
179                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_T;
180                            finderArgs = new Object[] { groupId, userId, type };
181                    }
182                    else {
183                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_T;
184                            finderArgs = new Object[] {
185                                            groupId, userId, type,
186                                            
187                                            start, end, orderByComparator
188                                    };
189                    }
190    
191                    List<SocialActivitySet> list = (List<SocialActivitySet>)FinderCacheUtil.getResult(finderPath,
192                                    finderArgs, this);
193    
194                    if ((list != null) && !list.isEmpty()) {
195                            for (SocialActivitySet socialActivitySet : list) {
196                                    if ((groupId != socialActivitySet.getGroupId()) ||
197                                                    (userId != socialActivitySet.getUserId()) ||
198                                                    (type != socialActivitySet.getType())) {
199                                            list = null;
200    
201                                            break;
202                                    }
203                            }
204                    }
205    
206                    if (list == null) {
207                            StringBundler query = null;
208    
209                            if (orderByComparator != null) {
210                                    query = new StringBundler(5 +
211                                                    (orderByComparator.getOrderByFields().length * 3));
212                            }
213                            else {
214                                    query = new StringBundler(5);
215                            }
216    
217                            query.append(_SQL_SELECT_SOCIALACTIVITYSET_WHERE);
218    
219                            query.append(_FINDER_COLUMN_G_U_T_GROUPID_2);
220    
221                            query.append(_FINDER_COLUMN_G_U_T_USERID_2);
222    
223                            query.append(_FINDER_COLUMN_G_U_T_TYPE_2);
224    
225                            if (orderByComparator != null) {
226                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
227                                            orderByComparator);
228                            }
229                            else
230                             if (pagination) {
231                                    query.append(SocialActivitySetModelImpl.ORDER_BY_JPQL);
232                            }
233    
234                            String sql = query.toString();
235    
236                            Session session = null;
237    
238                            try {
239                                    session = openSession();
240    
241                                    Query q = session.createQuery(sql);
242    
243                                    QueryPos qPos = QueryPos.getInstance(q);
244    
245                                    qPos.add(groupId);
246    
247                                    qPos.add(userId);
248    
249                                    qPos.add(type);
250    
251                                    if (!pagination) {
252                                            list = (List<SocialActivitySet>)QueryUtil.list(q,
253                                                            getDialect(), start, end, false);
254    
255                                            Collections.sort(list);
256    
257                                            list = new UnmodifiableList<SocialActivitySet>(list);
258                                    }
259                                    else {
260                                            list = (List<SocialActivitySet>)QueryUtil.list(q,
261                                                            getDialect(), start, end);
262                                    }
263    
264                                    cacheResult(list);
265    
266                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
267                            }
268                            catch (Exception e) {
269                                    FinderCacheUtil.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; and userId = &#63; and type = &#63;.
283             *
284             * @param groupId the group ID
285             * @param userId the user ID
286             * @param type the type
287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
288             * @return the first matching social activity set
289             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a matching social activity set could not be found
290             * @throws SystemException if a system exception occurred
291             */
292            public SocialActivitySet findByG_U_T_First(long groupId, long userId,
293                    int type, OrderByComparator orderByComparator)
294                    throws NoSuchActivitySetException, SystemException {
295                    SocialActivitySet socialActivitySet = fetchByG_U_T_First(groupId,
296                                    userId, type, orderByComparator);
297    
298                    if (socialActivitySet != null) {
299                            return socialActivitySet;
300                    }
301    
302                    StringBundler msg = new StringBundler(8);
303    
304                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
305    
306                    msg.append("groupId=");
307                    msg.append(groupId);
308    
309                    msg.append(", userId=");
310                    msg.append(userId);
311    
312                    msg.append(", type=");
313                    msg.append(type);
314    
315                    msg.append(StringPool.CLOSE_CURLY_BRACE);
316    
317                    throw new NoSuchActivitySetException(msg.toString());
318            }
319    
320            /**
321             * Returns the first social activity set in the ordered set where groupId = &#63; and userId = &#63; and type = &#63;.
322             *
323             * @param groupId the group ID
324             * @param userId the user ID
325             * @param type the type
326             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
327             * @return the first matching social activity set, or <code>null</code> if a matching social activity set could not be found
328             * @throws SystemException if a system exception occurred
329             */
330            public SocialActivitySet fetchByG_U_T_First(long groupId, long userId,
331                    int type, OrderByComparator orderByComparator)
332                    throws SystemException {
333                    List<SocialActivitySet> list = findByG_U_T(groupId, userId, type, 0, 1,
334                                    orderByComparator);
335    
336                    if (!list.isEmpty()) {
337                            return list.get(0);
338                    }
339    
340                    return null;
341            }
342    
343            /**
344             * Returns the last social activity set in the ordered set where groupId = &#63; and userId = &#63; and type = &#63;.
345             *
346             * @param groupId the group ID
347             * @param userId the user ID
348             * @param type the type
349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
350             * @return the last matching social activity set
351             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a matching social activity set could not be found
352             * @throws SystemException if a system exception occurred
353             */
354            public SocialActivitySet findByG_U_T_Last(long groupId, long userId,
355                    int type, OrderByComparator orderByComparator)
356                    throws NoSuchActivitySetException, SystemException {
357                    SocialActivitySet socialActivitySet = fetchByG_U_T_Last(groupId,
358                                    userId, type, orderByComparator);
359    
360                    if (socialActivitySet != null) {
361                            return socialActivitySet;
362                    }
363    
364                    StringBundler msg = new StringBundler(8);
365    
366                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
367    
368                    msg.append("groupId=");
369                    msg.append(groupId);
370    
371                    msg.append(", userId=");
372                    msg.append(userId);
373    
374                    msg.append(", type=");
375                    msg.append(type);
376    
377                    msg.append(StringPool.CLOSE_CURLY_BRACE);
378    
379                    throw new NoSuchActivitySetException(msg.toString());
380            }
381    
382            /**
383             * Returns the last social activity set in the ordered set where groupId = &#63; and userId = &#63; and type = &#63;.
384             *
385             * @param groupId the group ID
386             * @param userId the user ID
387             * @param type the type
388             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
389             * @return the last matching social activity set, or <code>null</code> if a matching social activity set could not be found
390             * @throws SystemException if a system exception occurred
391             */
392            public SocialActivitySet fetchByG_U_T_Last(long groupId, long userId,
393                    int type, OrderByComparator orderByComparator)
394                    throws SystemException {
395                    int count = countByG_U_T(groupId, userId, type);
396    
397                    List<SocialActivitySet> list = findByG_U_T(groupId, userId, type,
398                                    count - 1, count, orderByComparator);
399    
400                    if (!list.isEmpty()) {
401                            return list.get(0);
402                    }
403    
404                    return null;
405            }
406    
407            /**
408             * 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;.
409             *
410             * @param activitySetId the primary key of the current social activity set
411             * @param groupId the group ID
412             * @param userId the user ID
413             * @param type the type
414             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
415             * @return the previous, current, and next social activity set
416             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
417             * @throws SystemException if a system exception occurred
418             */
419            public SocialActivitySet[] findByG_U_T_PrevAndNext(long activitySetId,
420                    long groupId, long userId, int type, OrderByComparator orderByComparator)
421                    throws NoSuchActivitySetException, SystemException {
422                    SocialActivitySet socialActivitySet = findByPrimaryKey(activitySetId);
423    
424                    Session session = null;
425    
426                    try {
427                            session = openSession();
428    
429                            SocialActivitySet[] array = new SocialActivitySetImpl[3];
430    
431                            array[0] = getByG_U_T_PrevAndNext(session, socialActivitySet,
432                                            groupId, userId, type, orderByComparator, true);
433    
434                            array[1] = socialActivitySet;
435    
436                            array[2] = getByG_U_T_PrevAndNext(session, socialActivitySet,
437                                            groupId, userId, type, orderByComparator, false);
438    
439                            return array;
440                    }
441                    catch (Exception e) {
442                            throw processException(e);
443                    }
444                    finally {
445                            closeSession(session);
446                    }
447            }
448    
449            protected SocialActivitySet getByG_U_T_PrevAndNext(Session session,
450                    SocialActivitySet socialActivitySet, long groupId, long userId,
451                    int type, OrderByComparator orderByComparator, boolean previous) {
452                    StringBundler query = null;
453    
454                    if (orderByComparator != null) {
455                            query = new StringBundler(6 +
456                                            (orderByComparator.getOrderByFields().length * 6));
457                    }
458                    else {
459                            query = new StringBundler(3);
460                    }
461    
462                    query.append(_SQL_SELECT_SOCIALACTIVITYSET_WHERE);
463    
464                    query.append(_FINDER_COLUMN_G_U_T_GROUPID_2);
465    
466                    query.append(_FINDER_COLUMN_G_U_T_USERID_2);
467    
468                    query.append(_FINDER_COLUMN_G_U_T_TYPE_2);
469    
470                    if (orderByComparator != null) {
471                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
472    
473                            if (orderByConditionFields.length > 0) {
474                                    query.append(WHERE_AND);
475                            }
476    
477                            for (int i = 0; i < orderByConditionFields.length; i++) {
478                                    query.append(_ORDER_BY_ENTITY_ALIAS);
479                                    query.append(orderByConditionFields[i]);
480    
481                                    if ((i + 1) < orderByConditionFields.length) {
482                                            if (orderByComparator.isAscending() ^ previous) {
483                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
484                                            }
485                                            else {
486                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
487                                            }
488                                    }
489                                    else {
490                                            if (orderByComparator.isAscending() ^ previous) {
491                                                    query.append(WHERE_GREATER_THAN);
492                                            }
493                                            else {
494                                                    query.append(WHERE_LESSER_THAN);
495                                            }
496                                    }
497                            }
498    
499                            query.append(ORDER_BY_CLAUSE);
500    
501                            String[] orderByFields = orderByComparator.getOrderByFields();
502    
503                            for (int i = 0; i < orderByFields.length; i++) {
504                                    query.append(_ORDER_BY_ENTITY_ALIAS);
505                                    query.append(orderByFields[i]);
506    
507                                    if ((i + 1) < orderByFields.length) {
508                                            if (orderByComparator.isAscending() ^ previous) {
509                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
510                                            }
511                                            else {
512                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
513                                            }
514                                    }
515                                    else {
516                                            if (orderByComparator.isAscending() ^ previous) {
517                                                    query.append(ORDER_BY_ASC);
518                                            }
519                                            else {
520                                                    query.append(ORDER_BY_DESC);
521                                            }
522                                    }
523                            }
524                    }
525                    else {
526                            query.append(SocialActivitySetModelImpl.ORDER_BY_JPQL);
527                    }
528    
529                    String sql = query.toString();
530    
531                    Query q = session.createQuery(sql);
532    
533                    q.setFirstResult(0);
534                    q.setMaxResults(2);
535    
536                    QueryPos qPos = QueryPos.getInstance(q);
537    
538                    qPos.add(groupId);
539    
540                    qPos.add(userId);
541    
542                    qPos.add(type);
543    
544                    if (orderByComparator != null) {
545                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivitySet);
546    
547                            for (Object value : values) {
548                                    qPos.add(value);
549                            }
550                    }
551    
552                    List<SocialActivitySet> list = q.list();
553    
554                    if (list.size() == 2) {
555                            return list.get(1);
556                    }
557                    else {
558                            return null;
559                    }
560            }
561    
562            /**
563             * Removes all the social activity sets where groupId = &#63; and userId = &#63; and type = &#63; from the database.
564             *
565             * @param groupId the group ID
566             * @param userId the user ID
567             * @param type the type
568             * @throws SystemException if a system exception occurred
569             */
570            public void removeByG_U_T(long groupId, long userId, int type)
571                    throws SystemException {
572                    for (SocialActivitySet socialActivitySet : findByG_U_T(groupId, userId,
573                                    type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
574                            remove(socialActivitySet);
575                    }
576            }
577    
578            /**
579             * Returns the number of social activity sets where groupId = &#63; and userId = &#63; and type = &#63;.
580             *
581             * @param groupId the group ID
582             * @param userId the user ID
583             * @param type the type
584             * @return the number of matching social activity sets
585             * @throws SystemException if a system exception occurred
586             */
587            public int countByG_U_T(long groupId, long userId, int type)
588                    throws SystemException {
589                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_T;
590    
591                    Object[] finderArgs = new Object[] { groupId, userId, type };
592    
593                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
594                                    this);
595    
596                    if (count == null) {
597                            StringBundler query = new StringBundler(4);
598    
599                            query.append(_SQL_COUNT_SOCIALACTIVITYSET_WHERE);
600    
601                            query.append(_FINDER_COLUMN_G_U_T_GROUPID_2);
602    
603                            query.append(_FINDER_COLUMN_G_U_T_USERID_2);
604    
605                            query.append(_FINDER_COLUMN_G_U_T_TYPE_2);
606    
607                            String sql = query.toString();
608    
609                            Session session = null;
610    
611                            try {
612                                    session = openSession();
613    
614                                    Query q = session.createQuery(sql);
615    
616                                    QueryPos qPos = QueryPos.getInstance(q);
617    
618                                    qPos.add(groupId);
619    
620                                    qPos.add(userId);
621    
622                                    qPos.add(type);
623    
624                                    count = (Long)q.uniqueResult();
625    
626                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
627                            }
628                            catch (Exception e) {
629                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
630    
631                                    throw processException(e);
632                            }
633                            finally {
634                                    closeSession(session);
635                            }
636                    }
637    
638                    return count.intValue();
639            }
640    
641            private static final String _FINDER_COLUMN_G_U_T_GROUPID_2 = "socialActivitySet.groupId = ? AND ";
642            private static final String _FINDER_COLUMN_G_U_T_USERID_2 = "socialActivitySet.userId = ? AND ";
643            private static final String _FINDER_COLUMN_G_U_T_TYPE_2 = "socialActivitySet.type = ?";
644            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
645                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED,
646                            SocialActivitySetImpl.class,
647                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_T",
648                            new String[] {
649                                    Long.class.getName(), Long.class.getName(),
650                                    Integer.class.getName(),
651                                    
652                            Integer.class.getName(), Integer.class.getName(),
653                                    OrderByComparator.class.getName()
654                            });
655            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
656                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED,
657                            SocialActivitySetImpl.class,
658                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_T",
659                            new String[] {
660                                    Long.class.getName(), Long.class.getName(),
661                                    Integer.class.getName()
662                            },
663                            SocialActivitySetModelImpl.CLASSNAMEID_COLUMN_BITMASK |
664                            SocialActivitySetModelImpl.CLASSPK_COLUMN_BITMASK |
665                            SocialActivitySetModelImpl.TYPE_COLUMN_BITMASK |
666                            SocialActivitySetModelImpl.MODIFIEDDATE_COLUMN_BITMASK);
667            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
668                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED, Long.class,
669                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_T",
670                            new String[] {
671                                    Long.class.getName(), Long.class.getName(),
672                                    Integer.class.getName()
673                            });
674    
675            /**
676             * Returns all the social activity sets where classNameId = &#63; and classPK = &#63; and type = &#63;.
677             *
678             * @param classNameId the class name ID
679             * @param classPK the class p k
680             * @param type the type
681             * @return the matching social activity sets
682             * @throws SystemException if a system exception occurred
683             */
684            public List<SocialActivitySet> findByC_C_T(long classNameId, long classPK,
685                    int type) throws SystemException {
686                    return findByC_C_T(classNameId, classPK, type, QueryUtil.ALL_POS,
687                            QueryUtil.ALL_POS, null);
688            }
689    
690            /**
691             * Returns a range of all the social activity sets where classNameId = &#63; and classPK = &#63; and type = &#63;.
692             *
693             * <p>
694             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
695             * </p>
696             *
697             * @param classNameId the class name ID
698             * @param classPK the class p k
699             * @param type the type
700             * @param start the lower bound of the range of social activity sets
701             * @param end the upper bound of the range of social activity sets (not inclusive)
702             * @return the range of matching social activity sets
703             * @throws SystemException if a system exception occurred
704             */
705            public List<SocialActivitySet> findByC_C_T(long classNameId, long classPK,
706                    int type, int start, int end) throws SystemException {
707                    return findByC_C_T(classNameId, classPK, type, start, end, null);
708            }
709    
710            /**
711             * Returns an ordered range of all the social activity sets where classNameId = &#63; and classPK = &#63; and type = &#63;.
712             *
713             * <p>
714             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
715             * </p>
716             *
717             * @param classNameId the class name ID
718             * @param classPK the class p k
719             * @param type the type
720             * @param start the lower bound of the range of social activity sets
721             * @param end the upper bound of the range of social activity sets (not inclusive)
722             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
723             * @return the ordered range of matching social activity sets
724             * @throws SystemException if a system exception occurred
725             */
726            public List<SocialActivitySet> findByC_C_T(long classNameId, long classPK,
727                    int type, int start, int end, OrderByComparator orderByComparator)
728                    throws SystemException {
729                    boolean pagination = true;
730                    FinderPath finderPath = null;
731                    Object[] finderArgs = null;
732    
733                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
734                                    (orderByComparator == null)) {
735                            pagination = false;
736                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T;
737                            finderArgs = new Object[] { classNameId, classPK, type };
738                    }
739                    else {
740                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T;
741                            finderArgs = new Object[] {
742                                            classNameId, classPK, type,
743                                            
744                                            start, end, orderByComparator
745                                    };
746                    }
747    
748                    List<SocialActivitySet> list = (List<SocialActivitySet>)FinderCacheUtil.getResult(finderPath,
749                                    finderArgs, this);
750    
751                    if ((list != null) && !list.isEmpty()) {
752                            for (SocialActivitySet socialActivitySet : list) {
753                                    if ((classNameId != socialActivitySet.getClassNameId()) ||
754                                                    (classPK != socialActivitySet.getClassPK()) ||
755                                                    (type != socialActivitySet.getType())) {
756                                            list = null;
757    
758                                            break;
759                                    }
760                            }
761                    }
762    
763                    if (list == null) {
764                            StringBundler query = null;
765    
766                            if (orderByComparator != null) {
767                                    query = new StringBundler(5 +
768                                                    (orderByComparator.getOrderByFields().length * 3));
769                            }
770                            else {
771                                    query = new StringBundler(5);
772                            }
773    
774                            query.append(_SQL_SELECT_SOCIALACTIVITYSET_WHERE);
775    
776                            query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
777    
778                            query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
779    
780                            query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
781    
782                            if (orderByComparator != null) {
783                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
784                                            orderByComparator);
785                            }
786                            else
787                             if (pagination) {
788                                    query.append(SocialActivitySetModelImpl.ORDER_BY_JPQL);
789                            }
790    
791                            String sql = query.toString();
792    
793                            Session session = null;
794    
795                            try {
796                                    session = openSession();
797    
798                                    Query q = session.createQuery(sql);
799    
800                                    QueryPos qPos = QueryPos.getInstance(q);
801    
802                                    qPos.add(classNameId);
803    
804                                    qPos.add(classPK);
805    
806                                    qPos.add(type);
807    
808                                    if (!pagination) {
809                                            list = (List<SocialActivitySet>)QueryUtil.list(q,
810                                                            getDialect(), start, end, false);
811    
812                                            Collections.sort(list);
813    
814                                            list = new UnmodifiableList<SocialActivitySet>(list);
815                                    }
816                                    else {
817                                            list = (List<SocialActivitySet>)QueryUtil.list(q,
818                                                            getDialect(), start, end);
819                                    }
820    
821                                    cacheResult(list);
822    
823                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
824                            }
825                            catch (Exception e) {
826                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
827    
828                                    throw processException(e);
829                            }
830                            finally {
831                                    closeSession(session);
832                            }
833                    }
834    
835                    return list;
836            }
837    
838            /**
839             * Returns the first social activity set in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
840             *
841             * @param classNameId the class name ID
842             * @param classPK the class p k
843             * @param type the type
844             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
845             * @return the first matching social activity set
846             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a matching social activity set could not be found
847             * @throws SystemException if a system exception occurred
848             */
849            public SocialActivitySet findByC_C_T_First(long classNameId, long classPK,
850                    int type, OrderByComparator orderByComparator)
851                    throws NoSuchActivitySetException, SystemException {
852                    SocialActivitySet socialActivitySet = fetchByC_C_T_First(classNameId,
853                                    classPK, type, orderByComparator);
854    
855                    if (socialActivitySet != null) {
856                            return socialActivitySet;
857                    }
858    
859                    StringBundler msg = new StringBundler(8);
860    
861                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
862    
863                    msg.append("classNameId=");
864                    msg.append(classNameId);
865    
866                    msg.append(", classPK=");
867                    msg.append(classPK);
868    
869                    msg.append(", type=");
870                    msg.append(type);
871    
872                    msg.append(StringPool.CLOSE_CURLY_BRACE);
873    
874                    throw new NoSuchActivitySetException(msg.toString());
875            }
876    
877            /**
878             * Returns the first social activity set in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
879             *
880             * @param classNameId the class name ID
881             * @param classPK the class p k
882             * @param type the type
883             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
884             * @return the first matching social activity set, or <code>null</code> if a matching social activity set could not be found
885             * @throws SystemException if a system exception occurred
886             */
887            public SocialActivitySet fetchByC_C_T_First(long classNameId, long classPK,
888                    int type, OrderByComparator orderByComparator)
889                    throws SystemException {
890                    List<SocialActivitySet> list = findByC_C_T(classNameId, classPK, type,
891                                    0, 1, orderByComparator);
892    
893                    if (!list.isEmpty()) {
894                            return list.get(0);
895                    }
896    
897                    return null;
898            }
899    
900            /**
901             * Returns the last social activity set in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
902             *
903             * @param classNameId the class name ID
904             * @param classPK the class p k
905             * @param type the type
906             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
907             * @return the last matching social activity set
908             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a matching social activity set could not be found
909             * @throws SystemException if a system exception occurred
910             */
911            public SocialActivitySet findByC_C_T_Last(long classNameId, long classPK,
912                    int type, OrderByComparator orderByComparator)
913                    throws NoSuchActivitySetException, SystemException {
914                    SocialActivitySet socialActivitySet = fetchByC_C_T_Last(classNameId,
915                                    classPK, type, orderByComparator);
916    
917                    if (socialActivitySet != null) {
918                            return socialActivitySet;
919                    }
920    
921                    StringBundler msg = new StringBundler(8);
922    
923                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
924    
925                    msg.append("classNameId=");
926                    msg.append(classNameId);
927    
928                    msg.append(", classPK=");
929                    msg.append(classPK);
930    
931                    msg.append(", type=");
932                    msg.append(type);
933    
934                    msg.append(StringPool.CLOSE_CURLY_BRACE);
935    
936                    throw new NoSuchActivitySetException(msg.toString());
937            }
938    
939            /**
940             * Returns the last social activity set in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63;.
941             *
942             * @param classNameId the class name ID
943             * @param classPK the class p k
944             * @param type the type
945             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
946             * @return the last matching social activity set, or <code>null</code> if a matching social activity set could not be found
947             * @throws SystemException if a system exception occurred
948             */
949            public SocialActivitySet fetchByC_C_T_Last(long classNameId, long classPK,
950                    int type, OrderByComparator orderByComparator)
951                    throws SystemException {
952                    int count = countByC_C_T(classNameId, classPK, type);
953    
954                    List<SocialActivitySet> list = findByC_C_T(classNameId, classPK, type,
955                                    count - 1, count, orderByComparator);
956    
957                    if (!list.isEmpty()) {
958                            return list.get(0);
959                    }
960    
961                    return null;
962            }
963    
964            /**
965             * 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;.
966             *
967             * @param activitySetId the primary key of the current social activity set
968             * @param classNameId the class name ID
969             * @param classPK the class p k
970             * @param type the type
971             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
972             * @return the previous, current, and next social activity set
973             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
974             * @throws SystemException if a system exception occurred
975             */
976            public SocialActivitySet[] findByC_C_T_PrevAndNext(long activitySetId,
977                    long classNameId, long classPK, int type,
978                    OrderByComparator orderByComparator)
979                    throws NoSuchActivitySetException, SystemException {
980                    SocialActivitySet socialActivitySet = findByPrimaryKey(activitySetId);
981    
982                    Session session = null;
983    
984                    try {
985                            session = openSession();
986    
987                            SocialActivitySet[] array = new SocialActivitySetImpl[3];
988    
989                            array[0] = getByC_C_T_PrevAndNext(session, socialActivitySet,
990                                            classNameId, classPK, type, orderByComparator, true);
991    
992                            array[1] = socialActivitySet;
993    
994                            array[2] = getByC_C_T_PrevAndNext(session, socialActivitySet,
995                                            classNameId, classPK, type, orderByComparator, false);
996    
997                            return array;
998                    }
999                    catch (Exception e) {
1000                            throw processException(e);
1001                    }
1002                    finally {
1003                            closeSession(session);
1004                    }
1005            }
1006    
1007            protected SocialActivitySet getByC_C_T_PrevAndNext(Session session,
1008                    SocialActivitySet socialActivitySet, long classNameId, long classPK,
1009                    int type, OrderByComparator orderByComparator, boolean previous) {
1010                    StringBundler query = null;
1011    
1012                    if (orderByComparator != null) {
1013                            query = new StringBundler(6 +
1014                                            (orderByComparator.getOrderByFields().length * 6));
1015                    }
1016                    else {
1017                            query = new StringBundler(3);
1018                    }
1019    
1020                    query.append(_SQL_SELECT_SOCIALACTIVITYSET_WHERE);
1021    
1022                    query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
1023    
1024                    query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
1025    
1026                    query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
1027    
1028                    if (orderByComparator != null) {
1029                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1030    
1031                            if (orderByConditionFields.length > 0) {
1032                                    query.append(WHERE_AND);
1033                            }
1034    
1035                            for (int i = 0; i < orderByConditionFields.length; i++) {
1036                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1037                                    query.append(orderByConditionFields[i]);
1038    
1039                                    if ((i + 1) < orderByConditionFields.length) {
1040                                            if (orderByComparator.isAscending() ^ previous) {
1041                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1042                                            }
1043                                            else {
1044                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1045                                            }
1046                                    }
1047                                    else {
1048                                            if (orderByComparator.isAscending() ^ previous) {
1049                                                    query.append(WHERE_GREATER_THAN);
1050                                            }
1051                                            else {
1052                                                    query.append(WHERE_LESSER_THAN);
1053                                            }
1054                                    }
1055                            }
1056    
1057                            query.append(ORDER_BY_CLAUSE);
1058    
1059                            String[] orderByFields = orderByComparator.getOrderByFields();
1060    
1061                            for (int i = 0; i < orderByFields.length; i++) {
1062                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1063                                    query.append(orderByFields[i]);
1064    
1065                                    if ((i + 1) < orderByFields.length) {
1066                                            if (orderByComparator.isAscending() ^ previous) {
1067                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1068                                            }
1069                                            else {
1070                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1071                                            }
1072                                    }
1073                                    else {
1074                                            if (orderByComparator.isAscending() ^ previous) {
1075                                                    query.append(ORDER_BY_ASC);
1076                                            }
1077                                            else {
1078                                                    query.append(ORDER_BY_DESC);
1079                                            }
1080                                    }
1081                            }
1082                    }
1083                    else {
1084                            query.append(SocialActivitySetModelImpl.ORDER_BY_JPQL);
1085                    }
1086    
1087                    String sql = query.toString();
1088    
1089                    Query q = session.createQuery(sql);
1090    
1091                    q.setFirstResult(0);
1092                    q.setMaxResults(2);
1093    
1094                    QueryPos qPos = QueryPos.getInstance(q);
1095    
1096                    qPos.add(classNameId);
1097    
1098                    qPos.add(classPK);
1099    
1100                    qPos.add(type);
1101    
1102                    if (orderByComparator != null) {
1103                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivitySet);
1104    
1105                            for (Object value : values) {
1106                                    qPos.add(value);
1107                            }
1108                    }
1109    
1110                    List<SocialActivitySet> list = q.list();
1111    
1112                    if (list.size() == 2) {
1113                            return list.get(1);
1114                    }
1115                    else {
1116                            return null;
1117                    }
1118            }
1119    
1120            /**
1121             * Removes all the social activity sets where classNameId = &#63; and classPK = &#63; and type = &#63; from the database.
1122             *
1123             * @param classNameId the class name ID
1124             * @param classPK the class p k
1125             * @param type the type
1126             * @throws SystemException if a system exception occurred
1127             */
1128            public void removeByC_C_T(long classNameId, long classPK, int type)
1129                    throws SystemException {
1130                    for (SocialActivitySet socialActivitySet : findByC_C_T(classNameId,
1131                                    classPK, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1132                            remove(socialActivitySet);
1133                    }
1134            }
1135    
1136            /**
1137             * Returns the number of social activity sets where classNameId = &#63; and classPK = &#63; and type = &#63;.
1138             *
1139             * @param classNameId the class name ID
1140             * @param classPK the class p k
1141             * @param type the type
1142             * @return the number of matching social activity sets
1143             * @throws SystemException if a system exception occurred
1144             */
1145            public int countByC_C_T(long classNameId, long classPK, int type)
1146                    throws SystemException {
1147                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_T;
1148    
1149                    Object[] finderArgs = new Object[] { classNameId, classPK, type };
1150    
1151                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1152                                    this);
1153    
1154                    if (count == null) {
1155                            StringBundler query = new StringBundler(4);
1156    
1157                            query.append(_SQL_COUNT_SOCIALACTIVITYSET_WHERE);
1158    
1159                            query.append(_FINDER_COLUMN_C_C_T_CLASSNAMEID_2);
1160    
1161                            query.append(_FINDER_COLUMN_C_C_T_CLASSPK_2);
1162    
1163                            query.append(_FINDER_COLUMN_C_C_T_TYPE_2);
1164    
1165                            String sql = query.toString();
1166    
1167                            Session session = null;
1168    
1169                            try {
1170                                    session = openSession();
1171    
1172                                    Query q = session.createQuery(sql);
1173    
1174                                    QueryPos qPos = QueryPos.getInstance(q);
1175    
1176                                    qPos.add(classNameId);
1177    
1178                                    qPos.add(classPK);
1179    
1180                                    qPos.add(type);
1181    
1182                                    count = (Long)q.uniqueResult();
1183    
1184                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1185                            }
1186                            catch (Exception e) {
1187                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1188    
1189                                    throw processException(e);
1190                            }
1191                            finally {
1192                                    closeSession(session);
1193                            }
1194                    }
1195    
1196                    return count.intValue();
1197            }
1198    
1199            private static final String _FINDER_COLUMN_C_C_T_CLASSNAMEID_2 = "socialActivitySet.classNameId = ? AND ";
1200            private static final String _FINDER_COLUMN_C_C_T_CLASSPK_2 = "socialActivitySet.classPK = ? AND ";
1201            private static final String _FINDER_COLUMN_C_C_T_TYPE_2 = "socialActivitySet.type = ?";
1202            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_T = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
1203                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED,
1204                            SocialActivitySetImpl.class,
1205                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_T",
1206                            new String[] {
1207                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1208                                    Integer.class.getName(),
1209                                    
1210                            Integer.class.getName(), Integer.class.getName(),
1211                                    OrderByComparator.class.getName()
1212                            });
1213            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T =
1214                    new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
1215                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED,
1216                            SocialActivitySetImpl.class,
1217                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_T",
1218                            new String[] {
1219                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1220                                    Integer.class.getName()
1221                            },
1222                            SocialActivitySetModelImpl.USERID_COLUMN_BITMASK |
1223                            SocialActivitySetModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1224                            SocialActivitySetModelImpl.CLASSPK_COLUMN_BITMASK |
1225                            SocialActivitySetModelImpl.TYPE_COLUMN_BITMASK |
1226                            SocialActivitySetModelImpl.MODIFIEDDATE_COLUMN_BITMASK);
1227            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
1228                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED, Long.class,
1229                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_T",
1230                            new String[] {
1231                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
1232                                    Integer.class.getName()
1233                            });
1234    
1235            /**
1236             * Returns all the social activity sets where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1237             *
1238             * @param userId the user ID
1239             * @param classNameId the class name ID
1240             * @param classPK the class p k
1241             * @param type the type
1242             * @return the matching social activity sets
1243             * @throws SystemException if a system exception occurred
1244             */
1245            public List<SocialActivitySet> findByU_C_C_T(long userId, long classNameId,
1246                    long classPK, int type) throws SystemException {
1247                    return findByU_C_C_T(userId, classNameId, classPK, type,
1248                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1249            }
1250    
1251            /**
1252             * Returns a range of all the social activity sets where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1253             *
1254             * <p>
1255             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
1256             * </p>
1257             *
1258             * @param userId the user ID
1259             * @param classNameId the class name ID
1260             * @param classPK the class p k
1261             * @param type the type
1262             * @param start the lower bound of the range of social activity sets
1263             * @param end the upper bound of the range of social activity sets (not inclusive)
1264             * @return the range of matching social activity sets
1265             * @throws SystemException if a system exception occurred
1266             */
1267            public List<SocialActivitySet> findByU_C_C_T(long userId, long classNameId,
1268                    long classPK, int type, int start, int end) throws SystemException {
1269                    return findByU_C_C_T(userId, classNameId, classPK, type, start, end,
1270                            null);
1271            }
1272    
1273            /**
1274             * Returns an ordered range of all the social activity sets where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1275             *
1276             * <p>
1277             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
1278             * </p>
1279             *
1280             * @param userId the user ID
1281             * @param classNameId the class name ID
1282             * @param classPK the class p k
1283             * @param type the type
1284             * @param start the lower bound of the range of social activity sets
1285             * @param end the upper bound of the range of social activity sets (not inclusive)
1286             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1287             * @return the ordered range of matching social activity sets
1288             * @throws SystemException if a system exception occurred
1289             */
1290            public List<SocialActivitySet> findByU_C_C_T(long userId, long classNameId,
1291                    long classPK, int type, int start, int end,
1292                    OrderByComparator orderByComparator) throws SystemException {
1293                    boolean pagination = true;
1294                    FinderPath finderPath = null;
1295                    Object[] finderArgs = null;
1296    
1297                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1298                                    (orderByComparator == null)) {
1299                            pagination = false;
1300                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T;
1301                            finderArgs = new Object[] { userId, classNameId, classPK, type };
1302                    }
1303                    else {
1304                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_T;
1305                            finderArgs = new Object[] {
1306                                            userId, classNameId, classPK, type,
1307                                            
1308                                            start, end, orderByComparator
1309                                    };
1310                    }
1311    
1312                    List<SocialActivitySet> list = (List<SocialActivitySet>)FinderCacheUtil.getResult(finderPath,
1313                                    finderArgs, this);
1314    
1315                    if ((list != null) && !list.isEmpty()) {
1316                            for (SocialActivitySet socialActivitySet : list) {
1317                                    if ((userId != socialActivitySet.getUserId()) ||
1318                                                    (classNameId != socialActivitySet.getClassNameId()) ||
1319                                                    (classPK != socialActivitySet.getClassPK()) ||
1320                                                    (type != socialActivitySet.getType())) {
1321                                            list = null;
1322    
1323                                            break;
1324                                    }
1325                            }
1326                    }
1327    
1328                    if (list == null) {
1329                            StringBundler query = null;
1330    
1331                            if (orderByComparator != null) {
1332                                    query = new StringBundler(6 +
1333                                                    (orderByComparator.getOrderByFields().length * 3));
1334                            }
1335                            else {
1336                                    query = new StringBundler(6);
1337                            }
1338    
1339                            query.append(_SQL_SELECT_SOCIALACTIVITYSET_WHERE);
1340    
1341                            query.append(_FINDER_COLUMN_U_C_C_T_USERID_2);
1342    
1343                            query.append(_FINDER_COLUMN_U_C_C_T_CLASSNAMEID_2);
1344    
1345                            query.append(_FINDER_COLUMN_U_C_C_T_CLASSPK_2);
1346    
1347                            query.append(_FINDER_COLUMN_U_C_C_T_TYPE_2);
1348    
1349                            if (orderByComparator != null) {
1350                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1351                                            orderByComparator);
1352                            }
1353                            else
1354                             if (pagination) {
1355                                    query.append(SocialActivitySetModelImpl.ORDER_BY_JPQL);
1356                            }
1357    
1358                            String sql = query.toString();
1359    
1360                            Session session = null;
1361    
1362                            try {
1363                                    session = openSession();
1364    
1365                                    Query q = session.createQuery(sql);
1366    
1367                                    QueryPos qPos = QueryPos.getInstance(q);
1368    
1369                                    qPos.add(userId);
1370    
1371                                    qPos.add(classNameId);
1372    
1373                                    qPos.add(classPK);
1374    
1375                                    qPos.add(type);
1376    
1377                                    if (!pagination) {
1378                                            list = (List<SocialActivitySet>)QueryUtil.list(q,
1379                                                            getDialect(), start, end, false);
1380    
1381                                            Collections.sort(list);
1382    
1383                                            list = new UnmodifiableList<SocialActivitySet>(list);
1384                                    }
1385                                    else {
1386                                            list = (List<SocialActivitySet>)QueryUtil.list(q,
1387                                                            getDialect(), start, end);
1388                                    }
1389    
1390                                    cacheResult(list);
1391    
1392                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1393                            }
1394                            catch (Exception e) {
1395                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1396    
1397                                    throw processException(e);
1398                            }
1399                            finally {
1400                                    closeSession(session);
1401                            }
1402                    }
1403    
1404                    return list;
1405            }
1406    
1407            /**
1408             * Returns the first social activity set in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1409             *
1410             * @param userId the user ID
1411             * @param classNameId the class name ID
1412             * @param classPK the class p k
1413             * @param type the type
1414             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1415             * @return the first matching social activity set
1416             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a matching social activity set could not be found
1417             * @throws SystemException if a system exception occurred
1418             */
1419            public SocialActivitySet findByU_C_C_T_First(long userId, long classNameId,
1420                    long classPK, int type, OrderByComparator orderByComparator)
1421                    throws NoSuchActivitySetException, SystemException {
1422                    SocialActivitySet socialActivitySet = fetchByU_C_C_T_First(userId,
1423                                    classNameId, classPK, type, orderByComparator);
1424    
1425                    if (socialActivitySet != null) {
1426                            return socialActivitySet;
1427                    }
1428    
1429                    StringBundler msg = new StringBundler(10);
1430    
1431                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1432    
1433                    msg.append("userId=");
1434                    msg.append(userId);
1435    
1436                    msg.append(", classNameId=");
1437                    msg.append(classNameId);
1438    
1439                    msg.append(", classPK=");
1440                    msg.append(classPK);
1441    
1442                    msg.append(", type=");
1443                    msg.append(type);
1444    
1445                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1446    
1447                    throw new NoSuchActivitySetException(msg.toString());
1448            }
1449    
1450            /**
1451             * Returns the first social activity set in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1452             *
1453             * @param userId the user ID
1454             * @param classNameId the class name ID
1455             * @param classPK the class p k
1456             * @param type the type
1457             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1458             * @return the first matching social activity set, or <code>null</code> if a matching social activity set could not be found
1459             * @throws SystemException if a system exception occurred
1460             */
1461            public SocialActivitySet fetchByU_C_C_T_First(long userId,
1462                    long classNameId, long classPK, int type,
1463                    OrderByComparator orderByComparator) throws SystemException {
1464                    List<SocialActivitySet> list = findByU_C_C_T(userId, classNameId,
1465                                    classPK, type, 0, 1, orderByComparator);
1466    
1467                    if (!list.isEmpty()) {
1468                            return list.get(0);
1469                    }
1470    
1471                    return null;
1472            }
1473    
1474            /**
1475             * Returns the last social activity set in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1476             *
1477             * @param userId the user ID
1478             * @param classNameId the class name ID
1479             * @param classPK the class p k
1480             * @param type the type
1481             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1482             * @return the last matching social activity set
1483             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a matching social activity set could not be found
1484             * @throws SystemException if a system exception occurred
1485             */
1486            public SocialActivitySet findByU_C_C_T_Last(long userId, long classNameId,
1487                    long classPK, int type, OrderByComparator orderByComparator)
1488                    throws NoSuchActivitySetException, SystemException {
1489                    SocialActivitySet socialActivitySet = fetchByU_C_C_T_Last(userId,
1490                                    classNameId, classPK, type, orderByComparator);
1491    
1492                    if (socialActivitySet != null) {
1493                            return socialActivitySet;
1494                    }
1495    
1496                    StringBundler msg = new StringBundler(10);
1497    
1498                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1499    
1500                    msg.append("userId=");
1501                    msg.append(userId);
1502    
1503                    msg.append(", classNameId=");
1504                    msg.append(classNameId);
1505    
1506                    msg.append(", classPK=");
1507                    msg.append(classPK);
1508    
1509                    msg.append(", type=");
1510                    msg.append(type);
1511    
1512                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1513    
1514                    throw new NoSuchActivitySetException(msg.toString());
1515            }
1516    
1517            /**
1518             * Returns the last social activity set in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1519             *
1520             * @param userId the user ID
1521             * @param classNameId the class name ID
1522             * @param classPK the class p k
1523             * @param type the type
1524             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1525             * @return the last matching social activity set, or <code>null</code> if a matching social activity set could not be found
1526             * @throws SystemException if a system exception occurred
1527             */
1528            public SocialActivitySet fetchByU_C_C_T_Last(long userId, long classNameId,
1529                    long classPK, int type, OrderByComparator orderByComparator)
1530                    throws SystemException {
1531                    int count = countByU_C_C_T(userId, classNameId, classPK, type);
1532    
1533                    List<SocialActivitySet> list = findByU_C_C_T(userId, classNameId,
1534                                    classPK, type, count - 1, count, orderByComparator);
1535    
1536                    if (!list.isEmpty()) {
1537                            return list.get(0);
1538                    }
1539    
1540                    return null;
1541            }
1542    
1543            /**
1544             * 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;.
1545             *
1546             * @param activitySetId the primary key of the current social activity set
1547             * @param userId the user ID
1548             * @param classNameId the class name ID
1549             * @param classPK the class p k
1550             * @param type the type
1551             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1552             * @return the previous, current, and next social activity set
1553             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
1554             * @throws SystemException if a system exception occurred
1555             */
1556            public SocialActivitySet[] findByU_C_C_T_PrevAndNext(long activitySetId,
1557                    long userId, long classNameId, long classPK, int type,
1558                    OrderByComparator orderByComparator)
1559                    throws NoSuchActivitySetException, SystemException {
1560                    SocialActivitySet socialActivitySet = findByPrimaryKey(activitySetId);
1561    
1562                    Session session = null;
1563    
1564                    try {
1565                            session = openSession();
1566    
1567                            SocialActivitySet[] array = new SocialActivitySetImpl[3];
1568    
1569                            array[0] = getByU_C_C_T_PrevAndNext(session, socialActivitySet,
1570                                            userId, classNameId, classPK, type, orderByComparator, true);
1571    
1572                            array[1] = socialActivitySet;
1573    
1574                            array[2] = getByU_C_C_T_PrevAndNext(session, socialActivitySet,
1575                                            userId, classNameId, classPK, type, orderByComparator, false);
1576    
1577                            return array;
1578                    }
1579                    catch (Exception e) {
1580                            throw processException(e);
1581                    }
1582                    finally {
1583                            closeSession(session);
1584                    }
1585            }
1586    
1587            protected SocialActivitySet getByU_C_C_T_PrevAndNext(Session session,
1588                    SocialActivitySet socialActivitySet, long userId, long classNameId,
1589                    long classPK, int type, OrderByComparator orderByComparator,
1590                    boolean previous) {
1591                    StringBundler query = null;
1592    
1593                    if (orderByComparator != null) {
1594                            query = new StringBundler(6 +
1595                                            (orderByComparator.getOrderByFields().length * 6));
1596                    }
1597                    else {
1598                            query = new StringBundler(3);
1599                    }
1600    
1601                    query.append(_SQL_SELECT_SOCIALACTIVITYSET_WHERE);
1602    
1603                    query.append(_FINDER_COLUMN_U_C_C_T_USERID_2);
1604    
1605                    query.append(_FINDER_COLUMN_U_C_C_T_CLASSNAMEID_2);
1606    
1607                    query.append(_FINDER_COLUMN_U_C_C_T_CLASSPK_2);
1608    
1609                    query.append(_FINDER_COLUMN_U_C_C_T_TYPE_2);
1610    
1611                    if (orderByComparator != null) {
1612                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1613    
1614                            if (orderByConditionFields.length > 0) {
1615                                    query.append(WHERE_AND);
1616                            }
1617    
1618                            for (int i = 0; i < orderByConditionFields.length; i++) {
1619                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1620                                    query.append(orderByConditionFields[i]);
1621    
1622                                    if ((i + 1) < orderByConditionFields.length) {
1623                                            if (orderByComparator.isAscending() ^ previous) {
1624                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1625                                            }
1626                                            else {
1627                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1628                                            }
1629                                    }
1630                                    else {
1631                                            if (orderByComparator.isAscending() ^ previous) {
1632                                                    query.append(WHERE_GREATER_THAN);
1633                                            }
1634                                            else {
1635                                                    query.append(WHERE_LESSER_THAN);
1636                                            }
1637                                    }
1638                            }
1639    
1640                            query.append(ORDER_BY_CLAUSE);
1641    
1642                            String[] orderByFields = orderByComparator.getOrderByFields();
1643    
1644                            for (int i = 0; i < orderByFields.length; i++) {
1645                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1646                                    query.append(orderByFields[i]);
1647    
1648                                    if ((i + 1) < orderByFields.length) {
1649                                            if (orderByComparator.isAscending() ^ previous) {
1650                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1651                                            }
1652                                            else {
1653                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1654                                            }
1655                                    }
1656                                    else {
1657                                            if (orderByComparator.isAscending() ^ previous) {
1658                                                    query.append(ORDER_BY_ASC);
1659                                            }
1660                                            else {
1661                                                    query.append(ORDER_BY_DESC);
1662                                            }
1663                                    }
1664                            }
1665                    }
1666                    else {
1667                            query.append(SocialActivitySetModelImpl.ORDER_BY_JPQL);
1668                    }
1669    
1670                    String sql = query.toString();
1671    
1672                    Query q = session.createQuery(sql);
1673    
1674                    q.setFirstResult(0);
1675                    q.setMaxResults(2);
1676    
1677                    QueryPos qPos = QueryPos.getInstance(q);
1678    
1679                    qPos.add(userId);
1680    
1681                    qPos.add(classNameId);
1682    
1683                    qPos.add(classPK);
1684    
1685                    qPos.add(type);
1686    
1687                    if (orderByComparator != null) {
1688                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivitySet);
1689    
1690                            for (Object value : values) {
1691                                    qPos.add(value);
1692                            }
1693                    }
1694    
1695                    List<SocialActivitySet> list = q.list();
1696    
1697                    if (list.size() == 2) {
1698                            return list.get(1);
1699                    }
1700                    else {
1701                            return null;
1702                    }
1703            }
1704    
1705            /**
1706             * Removes all the social activity sets where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; from the database.
1707             *
1708             * @param userId the user ID
1709             * @param classNameId the class name ID
1710             * @param classPK the class p k
1711             * @param type the type
1712             * @throws SystemException if a system exception occurred
1713             */
1714            public void removeByU_C_C_T(long userId, long classNameId, long classPK,
1715                    int type) throws SystemException {
1716                    for (SocialActivitySet socialActivitySet : findByU_C_C_T(userId,
1717                                    classNameId, classPK, type, QueryUtil.ALL_POS,
1718                                    QueryUtil.ALL_POS, null)) {
1719                            remove(socialActivitySet);
1720                    }
1721            }
1722    
1723            /**
1724             * Returns the number of social activity sets where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63;.
1725             *
1726             * @param userId the user ID
1727             * @param classNameId the class name ID
1728             * @param classPK the class p k
1729             * @param type the type
1730             * @return the number of matching social activity sets
1731             * @throws SystemException if a system exception occurred
1732             */
1733            public int countByU_C_C_T(long userId, long classNameId, long classPK,
1734                    int type) throws SystemException {
1735                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_T;
1736    
1737                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, type };
1738    
1739                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1740                                    this);
1741    
1742                    if (count == null) {
1743                            StringBundler query = new StringBundler(5);
1744    
1745                            query.append(_SQL_COUNT_SOCIALACTIVITYSET_WHERE);
1746    
1747                            query.append(_FINDER_COLUMN_U_C_C_T_USERID_2);
1748    
1749                            query.append(_FINDER_COLUMN_U_C_C_T_CLASSNAMEID_2);
1750    
1751                            query.append(_FINDER_COLUMN_U_C_C_T_CLASSPK_2);
1752    
1753                            query.append(_FINDER_COLUMN_U_C_C_T_TYPE_2);
1754    
1755                            String sql = query.toString();
1756    
1757                            Session session = null;
1758    
1759                            try {
1760                                    session = openSession();
1761    
1762                                    Query q = session.createQuery(sql);
1763    
1764                                    QueryPos qPos = QueryPos.getInstance(q);
1765    
1766                                    qPos.add(userId);
1767    
1768                                    qPos.add(classNameId);
1769    
1770                                    qPos.add(classPK);
1771    
1772                                    qPos.add(type);
1773    
1774                                    count = (Long)q.uniqueResult();
1775    
1776                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1777                            }
1778                            catch (Exception e) {
1779                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1780    
1781                                    throw processException(e);
1782                            }
1783                            finally {
1784                                    closeSession(session);
1785                            }
1786                    }
1787    
1788                    return count.intValue();
1789            }
1790    
1791            private static final String _FINDER_COLUMN_U_C_C_T_USERID_2 = "socialActivitySet.userId = ? AND ";
1792            private static final String _FINDER_COLUMN_U_C_C_T_CLASSNAMEID_2 = "socialActivitySet.classNameId = ? AND ";
1793            private static final String _FINDER_COLUMN_U_C_C_T_CLASSPK_2 = "socialActivitySet.classPK = ? AND ";
1794            private static final String _FINDER_COLUMN_U_C_C_T_TYPE_2 = "socialActivitySet.type = ?";
1795    
1796            /**
1797             * Caches the social activity set in the entity cache if it is enabled.
1798             *
1799             * @param socialActivitySet the social activity set
1800             */
1801            public void cacheResult(SocialActivitySet socialActivitySet) {
1802                    EntityCacheUtil.putResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
1803                            SocialActivitySetImpl.class, socialActivitySet.getPrimaryKey(),
1804                            socialActivitySet);
1805    
1806                    socialActivitySet.resetOriginalValues();
1807            }
1808    
1809            /**
1810             * Caches the social activity sets in the entity cache if it is enabled.
1811             *
1812             * @param socialActivitySets the social activity sets
1813             */
1814            public void cacheResult(List<SocialActivitySet> socialActivitySets) {
1815                    for (SocialActivitySet socialActivitySet : socialActivitySets) {
1816                            if (EntityCacheUtil.getResult(
1817                                                    SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
1818                                                    SocialActivitySetImpl.class,
1819                                                    socialActivitySet.getPrimaryKey()) == null) {
1820                                    cacheResult(socialActivitySet);
1821                            }
1822                            else {
1823                                    socialActivitySet.resetOriginalValues();
1824                            }
1825                    }
1826            }
1827    
1828            /**
1829             * Clears the cache for all social activity sets.
1830             *
1831             * <p>
1832             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1833             * </p>
1834             */
1835            @Override
1836            public void clearCache() {
1837                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1838                            CacheRegistryUtil.clear(SocialActivitySetImpl.class.getName());
1839                    }
1840    
1841                    EntityCacheUtil.clearCache(SocialActivitySetImpl.class.getName());
1842    
1843                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1844                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1845                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1846            }
1847    
1848            /**
1849             * Clears the cache for the social activity set.
1850             *
1851             * <p>
1852             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1853             * </p>
1854             */
1855            @Override
1856            public void clearCache(SocialActivitySet socialActivitySet) {
1857                    EntityCacheUtil.removeResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
1858                            SocialActivitySetImpl.class, socialActivitySet.getPrimaryKey());
1859    
1860                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1861                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1862            }
1863    
1864            @Override
1865            public void clearCache(List<SocialActivitySet> socialActivitySets) {
1866                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1867                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1868    
1869                    for (SocialActivitySet socialActivitySet : socialActivitySets) {
1870                            EntityCacheUtil.removeResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
1871                                    SocialActivitySetImpl.class, socialActivitySet.getPrimaryKey());
1872                    }
1873            }
1874    
1875            /**
1876             * Creates a new social activity set with the primary key. Does not add the social activity set to the database.
1877             *
1878             * @param activitySetId the primary key for the new social activity set
1879             * @return the new social activity set
1880             */
1881            public SocialActivitySet create(long activitySetId) {
1882                    SocialActivitySet socialActivitySet = new SocialActivitySetImpl();
1883    
1884                    socialActivitySet.setNew(true);
1885                    socialActivitySet.setPrimaryKey(activitySetId);
1886    
1887                    return socialActivitySet;
1888            }
1889    
1890            /**
1891             * Removes the social activity set with the primary key from the database. Also notifies the appropriate model listeners.
1892             *
1893             * @param activitySetId the primary key of the social activity set
1894             * @return the social activity set that was removed
1895             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
1896             * @throws SystemException if a system exception occurred
1897             */
1898            public SocialActivitySet remove(long activitySetId)
1899                    throws NoSuchActivitySetException, SystemException {
1900                    return remove((Serializable)activitySetId);
1901            }
1902    
1903            /**
1904             * Removes the social activity set with the primary key from the database. Also notifies the appropriate model listeners.
1905             *
1906             * @param primaryKey the primary key of the social activity set
1907             * @return the social activity set that was removed
1908             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
1909             * @throws SystemException if a system exception occurred
1910             */
1911            @Override
1912            public SocialActivitySet remove(Serializable primaryKey)
1913                    throws NoSuchActivitySetException, SystemException {
1914                    Session session = null;
1915    
1916                    try {
1917                            session = openSession();
1918    
1919                            SocialActivitySet socialActivitySet = (SocialActivitySet)session.get(SocialActivitySetImpl.class,
1920                                            primaryKey);
1921    
1922                            if (socialActivitySet == null) {
1923                                    if (_log.isWarnEnabled()) {
1924                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1925                                    }
1926    
1927                                    throw new NoSuchActivitySetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1928                                            primaryKey);
1929                            }
1930    
1931                            return remove(socialActivitySet);
1932                    }
1933                    catch (NoSuchActivitySetException nsee) {
1934                            throw nsee;
1935                    }
1936                    catch (Exception e) {
1937                            throw processException(e);
1938                    }
1939                    finally {
1940                            closeSession(session);
1941                    }
1942            }
1943    
1944            @Override
1945            protected SocialActivitySet removeImpl(SocialActivitySet socialActivitySet)
1946                    throws SystemException {
1947                    socialActivitySet = toUnwrappedModel(socialActivitySet);
1948    
1949                    Session session = null;
1950    
1951                    try {
1952                            session = openSession();
1953    
1954                            if (!session.contains(socialActivitySet)) {
1955                                    socialActivitySet = (SocialActivitySet)session.get(SocialActivitySetImpl.class,
1956                                                    socialActivitySet.getPrimaryKeyObj());
1957                            }
1958    
1959                            if (socialActivitySet != null) {
1960                                    session.delete(socialActivitySet);
1961                            }
1962                    }
1963                    catch (Exception e) {
1964                            throw processException(e);
1965                    }
1966                    finally {
1967                            closeSession(session);
1968                    }
1969    
1970                    if (socialActivitySet != null) {
1971                            clearCache(socialActivitySet);
1972                    }
1973    
1974                    return socialActivitySet;
1975            }
1976    
1977            @Override
1978            public SocialActivitySet updateImpl(
1979                    com.liferay.portlet.social.model.SocialActivitySet socialActivitySet)
1980                    throws SystemException {
1981                    socialActivitySet = toUnwrappedModel(socialActivitySet);
1982    
1983                    boolean isNew = socialActivitySet.isNew();
1984    
1985                    SocialActivitySetModelImpl socialActivitySetModelImpl = (SocialActivitySetModelImpl)socialActivitySet;
1986    
1987                    Session session = null;
1988    
1989                    try {
1990                            session = openSession();
1991    
1992                            if (socialActivitySet.isNew()) {
1993                                    session.save(socialActivitySet);
1994    
1995                                    socialActivitySet.setNew(false);
1996                            }
1997                            else {
1998                                    session.merge(socialActivitySet);
1999                            }
2000                    }
2001                    catch (Exception e) {
2002                            throw processException(e);
2003                    }
2004                    finally {
2005                            closeSession(session);
2006                    }
2007    
2008                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2009    
2010                    if (isNew || !SocialActivitySetModelImpl.COLUMN_BITMASK_ENABLED) {
2011                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2012                    }
2013    
2014                    else {
2015                            if ((socialActivitySetModelImpl.getColumnBitmask() &
2016                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_T.getColumnBitmask()) != 0) {
2017                                    Object[] args = new Object[] {
2018                                                    socialActivitySetModelImpl.getOriginalGroupId(),
2019                                                    socialActivitySetModelImpl.getOriginalUserId(),
2020                                                    socialActivitySetModelImpl.getOriginalType()
2021                                            };
2022    
2023                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_T, args);
2024                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_T,
2025                                            args);
2026    
2027                                    args = new Object[] {
2028                                                    socialActivitySetModelImpl.getGroupId(),
2029                                                    socialActivitySetModelImpl.getUserId(),
2030                                                    socialActivitySetModelImpl.getType()
2031                                            };
2032    
2033                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_T, args);
2034                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_T,
2035                                            args);
2036                            }
2037    
2038                            if ((socialActivitySetModelImpl.getColumnBitmask() &
2039                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T.getColumnBitmask()) != 0) {
2040                                    Object[] args = new Object[] {
2041                                                    socialActivitySetModelImpl.getOriginalClassNameId(),
2042                                                    socialActivitySetModelImpl.getOriginalClassPK(),
2043                                                    socialActivitySetModelImpl.getOriginalType()
2044                                            };
2045    
2046                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T, args);
2047                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T,
2048                                            args);
2049    
2050                                    args = new Object[] {
2051                                                    socialActivitySetModelImpl.getClassNameId(),
2052                                                    socialActivitySetModelImpl.getClassPK(),
2053                                                    socialActivitySetModelImpl.getType()
2054                                            };
2055    
2056                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T, args);
2057                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T,
2058                                            args);
2059                            }
2060    
2061                            if ((socialActivitySetModelImpl.getColumnBitmask() &
2062                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T.getColumnBitmask()) != 0) {
2063                                    Object[] args = new Object[] {
2064                                                    socialActivitySetModelImpl.getOriginalUserId(),
2065                                                    socialActivitySetModelImpl.getOriginalClassNameId(),
2066                                                    socialActivitySetModelImpl.getOriginalClassPK(),
2067                                                    socialActivitySetModelImpl.getOriginalType()
2068                                            };
2069    
2070                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T, args);
2071                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T,
2072                                            args);
2073    
2074                                    args = new Object[] {
2075                                                    socialActivitySetModelImpl.getUserId(),
2076                                                    socialActivitySetModelImpl.getClassNameId(),
2077                                                    socialActivitySetModelImpl.getClassPK(),
2078                                                    socialActivitySetModelImpl.getType()
2079                                            };
2080    
2081                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T, args);
2082                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T,
2083                                            args);
2084                            }
2085                    }
2086    
2087                    EntityCacheUtil.putResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
2088                            SocialActivitySetImpl.class, socialActivitySet.getPrimaryKey(),
2089                            socialActivitySet);
2090    
2091                    return socialActivitySet;
2092            }
2093    
2094            protected SocialActivitySet toUnwrappedModel(
2095                    SocialActivitySet socialActivitySet) {
2096                    if (socialActivitySet instanceof SocialActivitySetImpl) {
2097                            return socialActivitySet;
2098                    }
2099    
2100                    SocialActivitySetImpl socialActivitySetImpl = new SocialActivitySetImpl();
2101    
2102                    socialActivitySetImpl.setNew(socialActivitySet.isNew());
2103                    socialActivitySetImpl.setPrimaryKey(socialActivitySet.getPrimaryKey());
2104    
2105                    socialActivitySetImpl.setActivitySetId(socialActivitySet.getActivitySetId());
2106                    socialActivitySetImpl.setGroupId(socialActivitySet.getGroupId());
2107                    socialActivitySetImpl.setCompanyId(socialActivitySet.getCompanyId());
2108                    socialActivitySetImpl.setUserId(socialActivitySet.getUserId());
2109                    socialActivitySetImpl.setCreateDate(socialActivitySet.getCreateDate());
2110                    socialActivitySetImpl.setModifiedDate(socialActivitySet.getModifiedDate());
2111                    socialActivitySetImpl.setClassNameId(socialActivitySet.getClassNameId());
2112                    socialActivitySetImpl.setClassPK(socialActivitySet.getClassPK());
2113                    socialActivitySetImpl.setType(socialActivitySet.getType());
2114                    socialActivitySetImpl.setActivityCount(socialActivitySet.getActivityCount());
2115    
2116                    return socialActivitySetImpl;
2117            }
2118    
2119            /**
2120             * Returns the social activity set with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2121             *
2122             * @param primaryKey the primary key of the social activity set
2123             * @return the social activity set
2124             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
2125             * @throws SystemException if a system exception occurred
2126             */
2127            @Override
2128            public SocialActivitySet findByPrimaryKey(Serializable primaryKey)
2129                    throws NoSuchActivitySetException, SystemException {
2130                    SocialActivitySet socialActivitySet = fetchByPrimaryKey(primaryKey);
2131    
2132                    if (socialActivitySet == null) {
2133                            if (_log.isWarnEnabled()) {
2134                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2135                            }
2136    
2137                            throw new NoSuchActivitySetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2138                                    primaryKey);
2139                    }
2140    
2141                    return socialActivitySet;
2142            }
2143    
2144            /**
2145             * Returns the social activity set with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivitySetException} if it could not be found.
2146             *
2147             * @param activitySetId the primary key of the social activity set
2148             * @return the social activity set
2149             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
2150             * @throws SystemException if a system exception occurred
2151             */
2152            public SocialActivitySet findByPrimaryKey(long activitySetId)
2153                    throws NoSuchActivitySetException, SystemException {
2154                    return findByPrimaryKey((Serializable)activitySetId);
2155            }
2156    
2157            /**
2158             * Returns the social activity set with the primary key or returns <code>null</code> if it could not be found.
2159             *
2160             * @param primaryKey the primary key of the social activity set
2161             * @return the social activity set, or <code>null</code> if a social activity set with the primary key could not be found
2162             * @throws SystemException if a system exception occurred
2163             */
2164            @Override
2165            public SocialActivitySet fetchByPrimaryKey(Serializable primaryKey)
2166                    throws SystemException {
2167                    SocialActivitySet socialActivitySet = (SocialActivitySet)EntityCacheUtil.getResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
2168                                    SocialActivitySetImpl.class, primaryKey);
2169    
2170                    if (socialActivitySet == _nullSocialActivitySet) {
2171                            return null;
2172                    }
2173    
2174                    if (socialActivitySet == null) {
2175                            Session session = null;
2176    
2177                            try {
2178                                    session = openSession();
2179    
2180                                    socialActivitySet = (SocialActivitySet)session.get(SocialActivitySetImpl.class,
2181                                                    primaryKey);
2182    
2183                                    if (socialActivitySet != null) {
2184                                            cacheResult(socialActivitySet);
2185                                    }
2186                                    else {
2187                                            EntityCacheUtil.putResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
2188                                                    SocialActivitySetImpl.class, primaryKey,
2189                                                    _nullSocialActivitySet);
2190                                    }
2191                            }
2192                            catch (Exception e) {
2193                                    EntityCacheUtil.removeResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
2194                                            SocialActivitySetImpl.class, primaryKey);
2195    
2196                                    throw processException(e);
2197                            }
2198                            finally {
2199                                    closeSession(session);
2200                            }
2201                    }
2202    
2203                    return socialActivitySet;
2204            }
2205    
2206            /**
2207             * Returns the social activity set with the primary key or returns <code>null</code> if it could not be found.
2208             *
2209             * @param activitySetId the primary key of the social activity set
2210             * @return the social activity set, or <code>null</code> if a social activity set with the primary key could not be found
2211             * @throws SystemException if a system exception occurred
2212             */
2213            public SocialActivitySet fetchByPrimaryKey(long activitySetId)
2214                    throws SystemException {
2215                    return fetchByPrimaryKey((Serializable)activitySetId);
2216            }
2217    
2218            /**
2219             * Returns all the social activity sets.
2220             *
2221             * @return the social activity sets
2222             * @throws SystemException if a system exception occurred
2223             */
2224            public List<SocialActivitySet> findAll() throws SystemException {
2225                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2226            }
2227    
2228            /**
2229             * Returns a range of all the social activity sets.
2230             *
2231             * <p>
2232             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
2233             * </p>
2234             *
2235             * @param start the lower bound of the range of social activity sets
2236             * @param end the upper bound of the range of social activity sets (not inclusive)
2237             * @return the range of social activity sets
2238             * @throws SystemException if a system exception occurred
2239             */
2240            public List<SocialActivitySet> findAll(int start, int end)
2241                    throws SystemException {
2242                    return findAll(start, end, null);
2243            }
2244    
2245            /**
2246             * Returns an ordered range of all the social activity sets.
2247             *
2248             * <p>
2249             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.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.
2250             * </p>
2251             *
2252             * @param start the lower bound of the range of social activity sets
2253             * @param end the upper bound of the range of social activity sets (not inclusive)
2254             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2255             * @return the ordered range of social activity sets
2256             * @throws SystemException if a system exception occurred
2257             */
2258            public List<SocialActivitySet> findAll(int start, int end,
2259                    OrderByComparator orderByComparator) throws SystemException {
2260                    boolean pagination = true;
2261                    FinderPath finderPath = null;
2262                    Object[] finderArgs = null;
2263    
2264                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2265                                    (orderByComparator == null)) {
2266                            pagination = false;
2267                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2268                            finderArgs = FINDER_ARGS_EMPTY;
2269                    }
2270                    else {
2271                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2272                            finderArgs = new Object[] { start, end, orderByComparator };
2273                    }
2274    
2275                    List<SocialActivitySet> list = (List<SocialActivitySet>)FinderCacheUtil.getResult(finderPath,
2276                                    finderArgs, this);
2277    
2278                    if (list == null) {
2279                            StringBundler query = null;
2280                            String sql = null;
2281    
2282                            if (orderByComparator != null) {
2283                                    query = new StringBundler(2 +
2284                                                    (orderByComparator.getOrderByFields().length * 3));
2285    
2286                                    query.append(_SQL_SELECT_SOCIALACTIVITYSET);
2287    
2288                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2289                                            orderByComparator);
2290    
2291                                    sql = query.toString();
2292                            }
2293                            else {
2294                                    sql = _SQL_SELECT_SOCIALACTIVITYSET;
2295    
2296                                    if (pagination) {
2297                                            sql = sql.concat(SocialActivitySetModelImpl.ORDER_BY_JPQL);
2298                                    }
2299                            }
2300    
2301                            Session session = null;
2302    
2303                            try {
2304                                    session = openSession();
2305    
2306                                    Query q = session.createQuery(sql);
2307    
2308                                    if (!pagination) {
2309                                            list = (List<SocialActivitySet>)QueryUtil.list(q,
2310                                                            getDialect(), start, end, false);
2311    
2312                                            Collections.sort(list);
2313    
2314                                            list = new UnmodifiableList<SocialActivitySet>(list);
2315                                    }
2316                                    else {
2317                                            list = (List<SocialActivitySet>)QueryUtil.list(q,
2318                                                            getDialect(), start, end);
2319                                    }
2320    
2321                                    cacheResult(list);
2322    
2323                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2324                            }
2325                            catch (Exception e) {
2326                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2327    
2328                                    throw processException(e);
2329                            }
2330                            finally {
2331                                    closeSession(session);
2332                            }
2333                    }
2334    
2335                    return list;
2336            }
2337    
2338            /**
2339             * Removes all the social activity sets from the database.
2340             *
2341             * @throws SystemException if a system exception occurred
2342             */
2343            public void removeAll() throws SystemException {
2344                    for (SocialActivitySet socialActivitySet : findAll()) {
2345                            remove(socialActivitySet);
2346                    }
2347            }
2348    
2349            /**
2350             * Returns the number of social activity sets.
2351             *
2352             * @return the number of social activity sets
2353             * @throws SystemException if a system exception occurred
2354             */
2355            public int countAll() throws SystemException {
2356                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2357                                    FINDER_ARGS_EMPTY, this);
2358    
2359                    if (count == null) {
2360                            Session session = null;
2361    
2362                            try {
2363                                    session = openSession();
2364    
2365                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYSET);
2366    
2367                                    count = (Long)q.uniqueResult();
2368    
2369                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2370                                            FINDER_ARGS_EMPTY, count);
2371                            }
2372                            catch (Exception e) {
2373                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2374                                            FINDER_ARGS_EMPTY);
2375    
2376                                    throw processException(e);
2377                            }
2378                            finally {
2379                                    closeSession(session);
2380                            }
2381                    }
2382    
2383                    return count.intValue();
2384            }
2385    
2386            @Override
2387            protected Set<String> getBadColumnNames() {
2388                    return _badColumnNames;
2389            }
2390    
2391            /**
2392             * Initializes the social activity set persistence.
2393             */
2394            public void afterPropertiesSet() {
2395                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2396                                            com.liferay.portal.util.PropsUtil.get(
2397                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivitySet")));
2398    
2399                    if (listenerClassNames.length > 0) {
2400                            try {
2401                                    List<ModelListener<SocialActivitySet>> listenersList = new ArrayList<ModelListener<SocialActivitySet>>();
2402    
2403                                    for (String listenerClassName : listenerClassNames) {
2404                                            listenersList.add((ModelListener<SocialActivitySet>)InstanceFactory.newInstance(
2405                                                            getClassLoader(), listenerClassName));
2406                                    }
2407    
2408                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2409                            }
2410                            catch (Exception e) {
2411                                    _log.error(e);
2412                            }
2413                    }
2414            }
2415    
2416            public void destroy() {
2417                    EntityCacheUtil.removeCache(SocialActivitySetImpl.class.getName());
2418                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2419                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2420                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2421            }
2422    
2423            private static final String _SQL_SELECT_SOCIALACTIVITYSET = "SELECT socialActivitySet FROM SocialActivitySet socialActivitySet";
2424            private static final String _SQL_SELECT_SOCIALACTIVITYSET_WHERE = "SELECT socialActivitySet FROM SocialActivitySet socialActivitySet WHERE ";
2425            private static final String _SQL_COUNT_SOCIALACTIVITYSET = "SELECT COUNT(socialActivitySet) FROM SocialActivitySet socialActivitySet";
2426            private static final String _SQL_COUNT_SOCIALACTIVITYSET_WHERE = "SELECT COUNT(socialActivitySet) FROM SocialActivitySet socialActivitySet WHERE ";
2427            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivitySet.";
2428            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivitySet exists with the primary key ";
2429            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivitySet exists with the key {";
2430            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2431            private static Log _log = LogFactoryUtil.getLog(SocialActivitySetPersistenceImpl.class);
2432            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2433                                    "type"
2434                            });
2435            private static SocialActivitySet _nullSocialActivitySet = new SocialActivitySetImpl() {
2436                            @Override
2437                            public Object clone() {
2438                                    return this;
2439                            }
2440    
2441                            @Override
2442                            public CacheModel<SocialActivitySet> toCacheModel() {
2443                                    return _nullSocialActivitySetCacheModel;
2444                            }
2445                    };
2446    
2447            private static CacheModel<SocialActivitySet> _nullSocialActivitySetCacheModel =
2448                    new CacheModel<SocialActivitySet>() {
2449                            public SocialActivitySet toEntityModel() {
2450                                    return _nullSocialActivitySet;
2451                            }
2452                    };
2453    }