001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.OrderByComparator;
029    import com.liferay.portal.kernel.util.StringBundler;
030    import com.liferay.portal.kernel.util.StringPool;
031    import com.liferay.portal.kernel.util.StringUtil;
032    import com.liferay.portal.kernel.util.Validator;
033    import com.liferay.portal.model.CacheModel;
034    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
035    
036    import com.liferay.portlet.social.NoSuchActivitySettingException;
037    import com.liferay.portlet.social.model.SocialActivitySetting;
038    import com.liferay.portlet.social.model.impl.SocialActivitySettingImpl;
039    import com.liferay.portlet.social.model.impl.SocialActivitySettingModelImpl;
040    import com.liferay.portlet.social.service.persistence.SocialActivitySettingPersistence;
041    
042    import java.io.Serializable;
043    
044    import java.util.Collections;
045    import java.util.HashMap;
046    import java.util.HashSet;
047    import java.util.Iterator;
048    import java.util.List;
049    import java.util.Map;
050    import java.util.Set;
051    
052    /**
053     * The persistence implementation for the social activity setting 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 SocialActivitySettingPersistence
061     * @see com.liferay.portlet.social.service.persistence.SocialActivitySettingUtil
062     * @generated
063     */
064    @ProviderType
065    public class SocialActivitySettingPersistenceImpl extends BasePersistenceImpl<SocialActivitySetting>
066            implements SocialActivitySettingPersistence {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * Never modify or reference this class directly. Always use {@link SocialActivitySettingUtil} to access the social activity setting persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
071             */
072            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivitySettingImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List1";
075            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List2";
077            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
078                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
079                            SocialActivitySettingImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
082                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
083                            SocialActivitySettingImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
086                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
089                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
090                            SocialActivitySettingImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
092                            new String[] {
093                                    Long.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_GROUPID =
099                    new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
100                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
101                            SocialActivitySettingImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
103                            new String[] { Long.class.getName() },
104                            SocialActivitySettingModelImpl.GROUPID_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
106                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
108                            new String[] { Long.class.getName() });
109    
110            /**
111             * Returns all the social activity settings where groupId = &#63;.
112             *
113             * @param groupId the group ID
114             * @return the matching social activity settings
115             */
116            @Override
117            public List<SocialActivitySetting> findByGroupId(long groupId) {
118                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119            }
120    
121            /**
122             * Returns a range of all the social activity settings where groupId = &#63;.
123             *
124             * <p>
125             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialActivitySettingModelImpl}. 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.
126             * </p>
127             *
128             * @param groupId the group ID
129             * @param start the lower bound of the range of social activity settings
130             * @param end the upper bound of the range of social activity settings (not inclusive)
131             * @return the range of matching social activity settings
132             */
133            @Override
134            public List<SocialActivitySetting> findByGroupId(long groupId, int start,
135                    int end) {
136                    return findByGroupId(groupId, start, end, null);
137            }
138    
139            /**
140             * Returns an ordered range of all the social activity settings where groupId = &#63;.
141             *
142             * <p>
143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialActivitySettingModelImpl}. 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.
144             * </p>
145             *
146             * @param groupId the group ID
147             * @param start the lower bound of the range of social activity settings
148             * @param end the upper bound of the range of social activity settings (not inclusive)
149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
150             * @return the ordered range of matching social activity settings
151             */
152            @Override
153            public List<SocialActivitySetting> findByGroupId(long groupId, int start,
154                    int end, OrderByComparator<SocialActivitySetting> orderByComparator) {
155                    boolean pagination = true;
156                    FinderPath finderPath = null;
157                    Object[] finderArgs = null;
158    
159                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160                                    (orderByComparator == null)) {
161                            pagination = false;
162                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
163                            finderArgs = new Object[] { groupId };
164                    }
165                    else {
166                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
167                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
168                    }
169    
170                    List<SocialActivitySetting> list = (List<SocialActivitySetting>)FinderCacheUtil.getResult(finderPath,
171                                    finderArgs, this);
172    
173                    if ((list != null) && !list.isEmpty()) {
174                            for (SocialActivitySetting socialActivitySetting : list) {
175                                    if ((groupId != socialActivitySetting.getGroupId())) {
176                                            list = null;
177    
178                                            break;
179                                    }
180                            }
181                    }
182    
183                    if (list == null) {
184                            StringBundler query = null;
185    
186                            if (orderByComparator != null) {
187                                    query = new StringBundler(3 +
188                                                    (orderByComparator.getOrderByFields().length * 3));
189                            }
190                            else {
191                                    query = new StringBundler(3);
192                            }
193    
194                            query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
195    
196                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
197    
198                            if (orderByComparator != null) {
199                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
200                                            orderByComparator);
201                            }
202                            else
203                             if (pagination) {
204                                    query.append(SocialActivitySettingModelImpl.ORDER_BY_JPQL);
205                            }
206    
207                            String sql = query.toString();
208    
209                            Session session = null;
210    
211                            try {
212                                    session = openSession();
213    
214                                    Query q = session.createQuery(sql);
215    
216                                    QueryPos qPos = QueryPos.getInstance(q);
217    
218                                    qPos.add(groupId);
219    
220                                    if (!pagination) {
221                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
222                                                            getDialect(), start, end, false);
223    
224                                            Collections.sort(list);
225    
226                                            list = Collections.unmodifiableList(list);
227                                    }
228                                    else {
229                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
230                                                            getDialect(), start, end);
231                                    }
232    
233                                    cacheResult(list);
234    
235                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
236                            }
237                            catch (Exception e) {
238                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
239    
240                                    throw processException(e);
241                            }
242                            finally {
243                                    closeSession(session);
244                            }
245                    }
246    
247                    return list;
248            }
249    
250            /**
251             * Returns the first social activity setting in the ordered set where groupId = &#63;.
252             *
253             * @param groupId the group ID
254             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
255             * @return the first matching social activity setting
256             * @throws NoSuchActivitySettingException if a matching social activity setting could not be found
257             */
258            @Override
259            public SocialActivitySetting findByGroupId_First(long groupId,
260                    OrderByComparator<SocialActivitySetting> orderByComparator)
261                    throws NoSuchActivitySettingException {
262                    SocialActivitySetting socialActivitySetting = fetchByGroupId_First(groupId,
263                                    orderByComparator);
264    
265                    if (socialActivitySetting != null) {
266                            return socialActivitySetting;
267                    }
268    
269                    StringBundler msg = new StringBundler(4);
270    
271                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
272    
273                    msg.append("groupId=");
274                    msg.append(groupId);
275    
276                    msg.append(StringPool.CLOSE_CURLY_BRACE);
277    
278                    throw new NoSuchActivitySettingException(msg.toString());
279            }
280    
281            /**
282             * Returns the first social activity setting in the ordered set where groupId = &#63;.
283             *
284             * @param groupId the group ID
285             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
286             * @return the first matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
287             */
288            @Override
289            public SocialActivitySetting fetchByGroupId_First(long groupId,
290                    OrderByComparator<SocialActivitySetting> orderByComparator) {
291                    List<SocialActivitySetting> list = findByGroupId(groupId, 0, 1,
292                                    orderByComparator);
293    
294                    if (!list.isEmpty()) {
295                            return list.get(0);
296                    }
297    
298                    return null;
299            }
300    
301            /**
302             * Returns the last social activity setting in the ordered set where groupId = &#63;.
303             *
304             * @param groupId the group ID
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the last matching social activity setting
307             * @throws NoSuchActivitySettingException if a matching social activity setting could not be found
308             */
309            @Override
310            public SocialActivitySetting findByGroupId_Last(long groupId,
311                    OrderByComparator<SocialActivitySetting> orderByComparator)
312                    throws NoSuchActivitySettingException {
313                    SocialActivitySetting socialActivitySetting = fetchByGroupId_Last(groupId,
314                                    orderByComparator);
315    
316                    if (socialActivitySetting != null) {
317                            return socialActivitySetting;
318                    }
319    
320                    StringBundler msg = new StringBundler(4);
321    
322                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
323    
324                    msg.append("groupId=");
325                    msg.append(groupId);
326    
327                    msg.append(StringPool.CLOSE_CURLY_BRACE);
328    
329                    throw new NoSuchActivitySettingException(msg.toString());
330            }
331    
332            /**
333             * Returns the last social activity setting in the ordered set where groupId = &#63;.
334             *
335             * @param groupId the group ID
336             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
337             * @return the last matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
338             */
339            @Override
340            public SocialActivitySetting fetchByGroupId_Last(long groupId,
341                    OrderByComparator<SocialActivitySetting> orderByComparator) {
342                    int count = countByGroupId(groupId);
343    
344                    if (count == 0) {
345                            return null;
346                    }
347    
348                    List<SocialActivitySetting> list = findByGroupId(groupId, count - 1,
349                                    count, orderByComparator);
350    
351                    if (!list.isEmpty()) {
352                            return list.get(0);
353                    }
354    
355                    return null;
356            }
357    
358            /**
359             * Returns the social activity settings before and after the current social activity setting in the ordered set where groupId = &#63;.
360             *
361             * @param activitySettingId the primary key of the current social activity setting
362             * @param groupId the group ID
363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
364             * @return the previous, current, and next social activity setting
365             * @throws NoSuchActivitySettingException if a social activity setting with the primary key could not be found
366             */
367            @Override
368            public SocialActivitySetting[] findByGroupId_PrevAndNext(
369                    long activitySettingId, long groupId,
370                    OrderByComparator<SocialActivitySetting> orderByComparator)
371                    throws NoSuchActivitySettingException {
372                    SocialActivitySetting socialActivitySetting = findByPrimaryKey(activitySettingId);
373    
374                    Session session = null;
375    
376                    try {
377                            session = openSession();
378    
379                            SocialActivitySetting[] array = new SocialActivitySettingImpl[3];
380    
381                            array[0] = getByGroupId_PrevAndNext(session, socialActivitySetting,
382                                            groupId, orderByComparator, true);
383    
384                            array[1] = socialActivitySetting;
385    
386                            array[2] = getByGroupId_PrevAndNext(session, socialActivitySetting,
387                                            groupId, orderByComparator, false);
388    
389                            return array;
390                    }
391                    catch (Exception e) {
392                            throw processException(e);
393                    }
394                    finally {
395                            closeSession(session);
396                    }
397            }
398    
399            protected SocialActivitySetting getByGroupId_PrevAndNext(Session session,
400                    SocialActivitySetting socialActivitySetting, long groupId,
401                    OrderByComparator<SocialActivitySetting> orderByComparator,
402                    boolean previous) {
403                    StringBundler query = null;
404    
405                    if (orderByComparator != null) {
406                            query = new StringBundler(6 +
407                                            (orderByComparator.getOrderByFields().length * 6));
408                    }
409                    else {
410                            query = new StringBundler(3);
411                    }
412    
413                    query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
414    
415                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
416    
417                    if (orderByComparator != null) {
418                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
419    
420                            if (orderByConditionFields.length > 0) {
421                                    query.append(WHERE_AND);
422                            }
423    
424                            for (int i = 0; i < orderByConditionFields.length; i++) {
425                                    query.append(_ORDER_BY_ENTITY_ALIAS);
426                                    query.append(orderByConditionFields[i]);
427    
428                                    if ((i + 1) < orderByConditionFields.length) {
429                                            if (orderByComparator.isAscending() ^ previous) {
430                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
431                                            }
432                                            else {
433                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
434                                            }
435                                    }
436                                    else {
437                                            if (orderByComparator.isAscending() ^ previous) {
438                                                    query.append(WHERE_GREATER_THAN);
439                                            }
440                                            else {
441                                                    query.append(WHERE_LESSER_THAN);
442                                            }
443                                    }
444                            }
445    
446                            query.append(ORDER_BY_CLAUSE);
447    
448                            String[] orderByFields = orderByComparator.getOrderByFields();
449    
450                            for (int i = 0; i < orderByFields.length; i++) {
451                                    query.append(_ORDER_BY_ENTITY_ALIAS);
452                                    query.append(orderByFields[i]);
453    
454                                    if ((i + 1) < orderByFields.length) {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
457                                            }
458                                            else {
459                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
460                                            }
461                                    }
462                                    else {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(ORDER_BY_ASC);
465                                            }
466                                            else {
467                                                    query.append(ORDER_BY_DESC);
468                                            }
469                                    }
470                            }
471                    }
472                    else {
473                            query.append(SocialActivitySettingModelImpl.ORDER_BY_JPQL);
474                    }
475    
476                    String sql = query.toString();
477    
478                    Query q = session.createQuery(sql);
479    
480                    q.setFirstResult(0);
481                    q.setMaxResults(2);
482    
483                    QueryPos qPos = QueryPos.getInstance(q);
484    
485                    qPos.add(groupId);
486    
487                    if (orderByComparator != null) {
488                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivitySetting);
489    
490                            for (Object value : values) {
491                                    qPos.add(value);
492                            }
493                    }
494    
495                    List<SocialActivitySetting> list = q.list();
496    
497                    if (list.size() == 2) {
498                            return list.get(1);
499                    }
500                    else {
501                            return null;
502                    }
503            }
504    
505            /**
506             * Removes all the social activity settings where groupId = &#63; from the database.
507             *
508             * @param groupId the group ID
509             */
510            @Override
511            public void removeByGroupId(long groupId) {
512                    for (SocialActivitySetting socialActivitySetting : findByGroupId(
513                                    groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
514                            remove(socialActivitySetting);
515                    }
516            }
517    
518            /**
519             * Returns the number of social activity settings where groupId = &#63;.
520             *
521             * @param groupId the group ID
522             * @return the number of matching social activity settings
523             */
524            @Override
525            public int countByGroupId(long groupId) {
526                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
527    
528                    Object[] finderArgs = new Object[] { groupId };
529    
530                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
531                                    this);
532    
533                    if (count == null) {
534                            StringBundler query = new StringBundler(2);
535    
536                            query.append(_SQL_COUNT_SOCIALACTIVITYSETTING_WHERE);
537    
538                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
539    
540                            String sql = query.toString();
541    
542                            Session session = null;
543    
544                            try {
545                                    session = openSession();
546    
547                                    Query q = session.createQuery(sql);
548    
549                                    QueryPos qPos = QueryPos.getInstance(q);
550    
551                                    qPos.add(groupId);
552    
553                                    count = (Long)q.uniqueResult();
554    
555                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
556                            }
557                            catch (Exception e) {
558                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
559    
560                                    throw processException(e);
561                            }
562                            finally {
563                                    closeSession(session);
564                            }
565                    }
566    
567                    return count.intValue();
568            }
569    
570            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "socialActivitySetting.groupId = ?";
571            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
572                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
573                            SocialActivitySettingImpl.class,
574                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
575                            new String[] {
576                                    Long.class.getName(), Long.class.getName(),
577                                    
578                            Integer.class.getName(), Integer.class.getName(),
579                                    OrderByComparator.class.getName()
580                            });
581            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
582                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
583                            SocialActivitySettingImpl.class,
584                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
585                            new String[] { Long.class.getName(), Long.class.getName() },
586                            SocialActivitySettingModelImpl.GROUPID_COLUMN_BITMASK |
587                            SocialActivitySettingModelImpl.CLASSNAMEID_COLUMN_BITMASK);
588            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
589                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
590                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
591                            new String[] { Long.class.getName(), Long.class.getName() });
592    
593            /**
594             * Returns all the social activity settings where groupId = &#63; and classNameId = &#63;.
595             *
596             * @param groupId the group ID
597             * @param classNameId the class name ID
598             * @return the matching social activity settings
599             */
600            @Override
601            public List<SocialActivitySetting> findByG_C(long groupId, long classNameId) {
602                    return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
603                            QueryUtil.ALL_POS, null);
604            }
605    
606            /**
607             * Returns a range of all the social activity settings where groupId = &#63; and classNameId = &#63;.
608             *
609             * <p>
610             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialActivitySettingModelImpl}. 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.
611             * </p>
612             *
613             * @param groupId the group ID
614             * @param classNameId the class name ID
615             * @param start the lower bound of the range of social activity settings
616             * @param end the upper bound of the range of social activity settings (not inclusive)
617             * @return the range of matching social activity settings
618             */
619            @Override
620            public List<SocialActivitySetting> findByG_C(long groupId,
621                    long classNameId, int start, int end) {
622                    return findByG_C(groupId, classNameId, start, end, null);
623            }
624    
625            /**
626             * Returns an ordered range of all the social activity settings where groupId = &#63; and classNameId = &#63;.
627             *
628             * <p>
629             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialActivitySettingModelImpl}. 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.
630             * </p>
631             *
632             * @param groupId the group ID
633             * @param classNameId the class name ID
634             * @param start the lower bound of the range of social activity settings
635             * @param end the upper bound of the range of social activity settings (not inclusive)
636             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
637             * @return the ordered range of matching social activity settings
638             */
639            @Override
640            public List<SocialActivitySetting> findByG_C(long groupId,
641                    long classNameId, int start, int end,
642                    OrderByComparator<SocialActivitySetting> orderByComparator) {
643                    boolean pagination = true;
644                    FinderPath finderPath = null;
645                    Object[] finderArgs = null;
646    
647                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
648                                    (orderByComparator == null)) {
649                            pagination = false;
650                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
651                            finderArgs = new Object[] { groupId, classNameId };
652                    }
653                    else {
654                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
655                            finderArgs = new Object[] {
656                                            groupId, classNameId,
657                                            
658                                            start, end, orderByComparator
659                                    };
660                    }
661    
662                    List<SocialActivitySetting> list = (List<SocialActivitySetting>)FinderCacheUtil.getResult(finderPath,
663                                    finderArgs, this);
664    
665                    if ((list != null) && !list.isEmpty()) {
666                            for (SocialActivitySetting socialActivitySetting : list) {
667                                    if ((groupId != socialActivitySetting.getGroupId()) ||
668                                                    (classNameId != socialActivitySetting.getClassNameId())) {
669                                            list = null;
670    
671                                            break;
672                                    }
673                            }
674                    }
675    
676                    if (list == null) {
677                            StringBundler query = null;
678    
679                            if (orderByComparator != null) {
680                                    query = new StringBundler(4 +
681                                                    (orderByComparator.getOrderByFields().length * 3));
682                            }
683                            else {
684                                    query = new StringBundler(4);
685                            }
686    
687                            query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
688    
689                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
690    
691                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
692    
693                            if (orderByComparator != null) {
694                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
695                                            orderByComparator);
696                            }
697                            else
698                             if (pagination) {
699                                    query.append(SocialActivitySettingModelImpl.ORDER_BY_JPQL);
700                            }
701    
702                            String sql = query.toString();
703    
704                            Session session = null;
705    
706                            try {
707                                    session = openSession();
708    
709                                    Query q = session.createQuery(sql);
710    
711                                    QueryPos qPos = QueryPos.getInstance(q);
712    
713                                    qPos.add(groupId);
714    
715                                    qPos.add(classNameId);
716    
717                                    if (!pagination) {
718                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
719                                                            getDialect(), start, end, false);
720    
721                                            Collections.sort(list);
722    
723                                            list = Collections.unmodifiableList(list);
724                                    }
725                                    else {
726                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
727                                                            getDialect(), start, end);
728                                    }
729    
730                                    cacheResult(list);
731    
732                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
733                            }
734                            catch (Exception e) {
735                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
736    
737                                    throw processException(e);
738                            }
739                            finally {
740                                    closeSession(session);
741                            }
742                    }
743    
744                    return list;
745            }
746    
747            /**
748             * Returns the first social activity setting in the ordered set where groupId = &#63; and classNameId = &#63;.
749             *
750             * @param groupId the group ID
751             * @param classNameId the class name ID
752             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
753             * @return the first matching social activity setting
754             * @throws NoSuchActivitySettingException if a matching social activity setting could not be found
755             */
756            @Override
757            public SocialActivitySetting findByG_C_First(long groupId,
758                    long classNameId,
759                    OrderByComparator<SocialActivitySetting> orderByComparator)
760                    throws NoSuchActivitySettingException {
761                    SocialActivitySetting socialActivitySetting = fetchByG_C_First(groupId,
762                                    classNameId, orderByComparator);
763    
764                    if (socialActivitySetting != null) {
765                            return socialActivitySetting;
766                    }
767    
768                    StringBundler msg = new StringBundler(6);
769    
770                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
771    
772                    msg.append("groupId=");
773                    msg.append(groupId);
774    
775                    msg.append(", classNameId=");
776                    msg.append(classNameId);
777    
778                    msg.append(StringPool.CLOSE_CURLY_BRACE);
779    
780                    throw new NoSuchActivitySettingException(msg.toString());
781            }
782    
783            /**
784             * Returns the first social activity setting in the ordered set where groupId = &#63; and classNameId = &#63;.
785             *
786             * @param groupId the group ID
787             * @param classNameId the class name ID
788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
789             * @return the first matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
790             */
791            @Override
792            public SocialActivitySetting fetchByG_C_First(long groupId,
793                    long classNameId,
794                    OrderByComparator<SocialActivitySetting> orderByComparator) {
795                    List<SocialActivitySetting> list = findByG_C(groupId, classNameId, 0,
796                                    1, orderByComparator);
797    
798                    if (!list.isEmpty()) {
799                            return list.get(0);
800                    }
801    
802                    return null;
803            }
804    
805            /**
806             * Returns the last social activity setting in the ordered set where groupId = &#63; and classNameId = &#63;.
807             *
808             * @param groupId the group ID
809             * @param classNameId the class name ID
810             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
811             * @return the last matching social activity setting
812             * @throws NoSuchActivitySettingException if a matching social activity setting could not be found
813             */
814            @Override
815            public SocialActivitySetting findByG_C_Last(long groupId, long classNameId,
816                    OrderByComparator<SocialActivitySetting> orderByComparator)
817                    throws NoSuchActivitySettingException {
818                    SocialActivitySetting socialActivitySetting = fetchByG_C_Last(groupId,
819                                    classNameId, orderByComparator);
820    
821                    if (socialActivitySetting != null) {
822                            return socialActivitySetting;
823                    }
824    
825                    StringBundler msg = new StringBundler(6);
826    
827                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
828    
829                    msg.append("groupId=");
830                    msg.append(groupId);
831    
832                    msg.append(", classNameId=");
833                    msg.append(classNameId);
834    
835                    msg.append(StringPool.CLOSE_CURLY_BRACE);
836    
837                    throw new NoSuchActivitySettingException(msg.toString());
838            }
839    
840            /**
841             * Returns the last social activity setting in the ordered set where groupId = &#63; and classNameId = &#63;.
842             *
843             * @param groupId the group ID
844             * @param classNameId the class name ID
845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
846             * @return the last matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
847             */
848            @Override
849            public SocialActivitySetting fetchByG_C_Last(long groupId,
850                    long classNameId,
851                    OrderByComparator<SocialActivitySetting> orderByComparator) {
852                    int count = countByG_C(groupId, classNameId);
853    
854                    if (count == 0) {
855                            return null;
856                    }
857    
858                    List<SocialActivitySetting> list = findByG_C(groupId, classNameId,
859                                    count - 1, count, orderByComparator);
860    
861                    if (!list.isEmpty()) {
862                            return list.get(0);
863                    }
864    
865                    return null;
866            }
867    
868            /**
869             * Returns the social activity settings before and after the current social activity setting in the ordered set where groupId = &#63; and classNameId = &#63;.
870             *
871             * @param activitySettingId the primary key of the current social activity setting
872             * @param groupId the group ID
873             * @param classNameId the class name ID
874             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
875             * @return the previous, current, and next social activity setting
876             * @throws NoSuchActivitySettingException if a social activity setting with the primary key could not be found
877             */
878            @Override
879            public SocialActivitySetting[] findByG_C_PrevAndNext(
880                    long activitySettingId, long groupId, long classNameId,
881                    OrderByComparator<SocialActivitySetting> orderByComparator)
882                    throws NoSuchActivitySettingException {
883                    SocialActivitySetting socialActivitySetting = findByPrimaryKey(activitySettingId);
884    
885                    Session session = null;
886    
887                    try {
888                            session = openSession();
889    
890                            SocialActivitySetting[] array = new SocialActivitySettingImpl[3];
891    
892                            array[0] = getByG_C_PrevAndNext(session, socialActivitySetting,
893                                            groupId, classNameId, orderByComparator, true);
894    
895                            array[1] = socialActivitySetting;
896    
897                            array[2] = getByG_C_PrevAndNext(session, socialActivitySetting,
898                                            groupId, classNameId, orderByComparator, false);
899    
900                            return array;
901                    }
902                    catch (Exception e) {
903                            throw processException(e);
904                    }
905                    finally {
906                            closeSession(session);
907                    }
908            }
909    
910            protected SocialActivitySetting getByG_C_PrevAndNext(Session session,
911                    SocialActivitySetting socialActivitySetting, long groupId,
912                    long classNameId,
913                    OrderByComparator<SocialActivitySetting> orderByComparator,
914                    boolean previous) {
915                    StringBundler query = null;
916    
917                    if (orderByComparator != null) {
918                            query = new StringBundler(6 +
919                                            (orderByComparator.getOrderByFields().length * 6));
920                    }
921                    else {
922                            query = new StringBundler(3);
923                    }
924    
925                    query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
926    
927                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
928    
929                    query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
930    
931                    if (orderByComparator != null) {
932                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
933    
934                            if (orderByConditionFields.length > 0) {
935                                    query.append(WHERE_AND);
936                            }
937    
938                            for (int i = 0; i < orderByConditionFields.length; i++) {
939                                    query.append(_ORDER_BY_ENTITY_ALIAS);
940                                    query.append(orderByConditionFields[i]);
941    
942                                    if ((i + 1) < orderByConditionFields.length) {
943                                            if (orderByComparator.isAscending() ^ previous) {
944                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
945                                            }
946                                            else {
947                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
948                                            }
949                                    }
950                                    else {
951                                            if (orderByComparator.isAscending() ^ previous) {
952                                                    query.append(WHERE_GREATER_THAN);
953                                            }
954                                            else {
955                                                    query.append(WHERE_LESSER_THAN);
956                                            }
957                                    }
958                            }
959    
960                            query.append(ORDER_BY_CLAUSE);
961    
962                            String[] orderByFields = orderByComparator.getOrderByFields();
963    
964                            for (int i = 0; i < orderByFields.length; i++) {
965                                    query.append(_ORDER_BY_ENTITY_ALIAS);
966                                    query.append(orderByFields[i]);
967    
968                                    if ((i + 1) < orderByFields.length) {
969                                            if (orderByComparator.isAscending() ^ previous) {
970                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
971                                            }
972                                            else {
973                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
974                                            }
975                                    }
976                                    else {
977                                            if (orderByComparator.isAscending() ^ previous) {
978                                                    query.append(ORDER_BY_ASC);
979                                            }
980                                            else {
981                                                    query.append(ORDER_BY_DESC);
982                                            }
983                                    }
984                            }
985                    }
986                    else {
987                            query.append(SocialActivitySettingModelImpl.ORDER_BY_JPQL);
988                    }
989    
990                    String sql = query.toString();
991    
992                    Query q = session.createQuery(sql);
993    
994                    q.setFirstResult(0);
995                    q.setMaxResults(2);
996    
997                    QueryPos qPos = QueryPos.getInstance(q);
998    
999                    qPos.add(groupId);
1000    
1001                    qPos.add(classNameId);
1002    
1003                    if (orderByComparator != null) {
1004                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivitySetting);
1005    
1006                            for (Object value : values) {
1007                                    qPos.add(value);
1008                            }
1009                    }
1010    
1011                    List<SocialActivitySetting> list = q.list();
1012    
1013                    if (list.size() == 2) {
1014                            return list.get(1);
1015                    }
1016                    else {
1017                            return null;
1018                    }
1019            }
1020    
1021            /**
1022             * Removes all the social activity settings where groupId = &#63; and classNameId = &#63; from the database.
1023             *
1024             * @param groupId the group ID
1025             * @param classNameId the class name ID
1026             */
1027            @Override
1028            public void removeByG_C(long groupId, long classNameId) {
1029                    for (SocialActivitySetting socialActivitySetting : findByG_C(groupId,
1030                                    classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1031                            remove(socialActivitySetting);
1032                    }
1033            }
1034    
1035            /**
1036             * Returns the number of social activity settings where groupId = &#63; and classNameId = &#63;.
1037             *
1038             * @param groupId the group ID
1039             * @param classNameId the class name ID
1040             * @return the number of matching social activity settings
1041             */
1042            @Override
1043            public int countByG_C(long groupId, long classNameId) {
1044                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
1045    
1046                    Object[] finderArgs = new Object[] { groupId, classNameId };
1047    
1048                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1049                                    this);
1050    
1051                    if (count == null) {
1052                            StringBundler query = new StringBundler(3);
1053    
1054                            query.append(_SQL_COUNT_SOCIALACTIVITYSETTING_WHERE);
1055    
1056                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1057    
1058                            query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
1059    
1060                            String sql = query.toString();
1061    
1062                            Session session = null;
1063    
1064                            try {
1065                                    session = openSession();
1066    
1067                                    Query q = session.createQuery(sql);
1068    
1069                                    QueryPos qPos = QueryPos.getInstance(q);
1070    
1071                                    qPos.add(groupId);
1072    
1073                                    qPos.add(classNameId);
1074    
1075                                    count = (Long)q.uniqueResult();
1076    
1077                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1078                            }
1079                            catch (Exception e) {
1080                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1081    
1082                                    throw processException(e);
1083                            }
1084                            finally {
1085                                    closeSession(session);
1086                            }
1087                    }
1088    
1089                    return count.intValue();
1090            }
1091    
1092            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "socialActivitySetting.groupId = ? AND ";
1093            private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "socialActivitySetting.classNameId = ?";
1094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
1095                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
1096                            SocialActivitySettingImpl.class,
1097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_A",
1098                            new String[] {
1099                                    Long.class.getName(), Integer.class.getName(),
1100                                    
1101                            Integer.class.getName(), Integer.class.getName(),
1102                                    OrderByComparator.class.getName()
1103                            });
1104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
1105                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
1106                            SocialActivitySettingImpl.class,
1107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_A",
1108                            new String[] { Long.class.getName(), Integer.class.getName() },
1109                            SocialActivitySettingModelImpl.GROUPID_COLUMN_BITMASK |
1110                            SocialActivitySettingModelImpl.ACTIVITYTYPE_COLUMN_BITMASK);
1111            public static final FinderPath FINDER_PATH_COUNT_BY_G_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
1112                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
1113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_A",
1114                            new String[] { Long.class.getName(), Integer.class.getName() });
1115    
1116            /**
1117             * Returns all the social activity settings where groupId = &#63; and activityType = &#63;.
1118             *
1119             * @param groupId the group ID
1120             * @param activityType the activity type
1121             * @return the matching social activity settings
1122             */
1123            @Override
1124            public List<SocialActivitySetting> findByG_A(long groupId, int activityType) {
1125                    return findByG_A(groupId, activityType, QueryUtil.ALL_POS,
1126                            QueryUtil.ALL_POS, null);
1127            }
1128    
1129            /**
1130             * Returns a range of all the social activity settings where groupId = &#63; and activityType = &#63;.
1131             *
1132             * <p>
1133             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialActivitySettingModelImpl}. 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.
1134             * </p>
1135             *
1136             * @param groupId the group ID
1137             * @param activityType the activity type
1138             * @param start the lower bound of the range of social activity settings
1139             * @param end the upper bound of the range of social activity settings (not inclusive)
1140             * @return the range of matching social activity settings
1141             */
1142            @Override
1143            public List<SocialActivitySetting> findByG_A(long groupId,
1144                    int activityType, int start, int end) {
1145                    return findByG_A(groupId, activityType, start, end, null);
1146            }
1147    
1148            /**
1149             * Returns an ordered range of all the social activity settings where groupId = &#63; and activityType = &#63;.
1150             *
1151             * <p>
1152             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialActivitySettingModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1153             * </p>
1154             *
1155             * @param groupId the group ID
1156             * @param activityType the activity type
1157             * @param start the lower bound of the range of social activity settings
1158             * @param end the upper bound of the range of social activity settings (not inclusive)
1159             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1160             * @return the ordered range of matching social activity settings
1161             */
1162            @Override
1163            public List<SocialActivitySetting> findByG_A(long groupId,
1164                    int activityType, int start, int end,
1165                    OrderByComparator<SocialActivitySetting> orderByComparator) {
1166                    boolean pagination = true;
1167                    FinderPath finderPath = null;
1168                    Object[] finderArgs = null;
1169    
1170                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1171                                    (orderByComparator == null)) {
1172                            pagination = false;
1173                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A;
1174                            finderArgs = new Object[] { groupId, activityType };
1175                    }
1176                    else {
1177                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A;
1178                            finderArgs = new Object[] {
1179                                            groupId, activityType,
1180                                            
1181                                            start, end, orderByComparator
1182                                    };
1183                    }
1184    
1185                    List<SocialActivitySetting> list = (List<SocialActivitySetting>)FinderCacheUtil.getResult(finderPath,
1186                                    finderArgs, this);
1187    
1188                    if ((list != null) && !list.isEmpty()) {
1189                            for (SocialActivitySetting socialActivitySetting : list) {
1190                                    if ((groupId != socialActivitySetting.getGroupId()) ||
1191                                                    (activityType != socialActivitySetting.getActivityType())) {
1192                                            list = null;
1193    
1194                                            break;
1195                                    }
1196                            }
1197                    }
1198    
1199                    if (list == null) {
1200                            StringBundler query = null;
1201    
1202                            if (orderByComparator != null) {
1203                                    query = new StringBundler(4 +
1204                                                    (orderByComparator.getOrderByFields().length * 3));
1205                            }
1206                            else {
1207                                    query = new StringBundler(4);
1208                            }
1209    
1210                            query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
1211    
1212                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
1213    
1214                            query.append(_FINDER_COLUMN_G_A_ACTIVITYTYPE_2);
1215    
1216                            if (orderByComparator != null) {
1217                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1218                                            orderByComparator);
1219                            }
1220                            else
1221                             if (pagination) {
1222                                    query.append(SocialActivitySettingModelImpl.ORDER_BY_JPQL);
1223                            }
1224    
1225                            String sql = query.toString();
1226    
1227                            Session session = null;
1228    
1229                            try {
1230                                    session = openSession();
1231    
1232                                    Query q = session.createQuery(sql);
1233    
1234                                    QueryPos qPos = QueryPos.getInstance(q);
1235    
1236                                    qPos.add(groupId);
1237    
1238                                    qPos.add(activityType);
1239    
1240                                    if (!pagination) {
1241                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
1242                                                            getDialect(), start, end, false);
1243    
1244                                            Collections.sort(list);
1245    
1246                                            list = Collections.unmodifiableList(list);
1247                                    }
1248                                    else {
1249                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
1250                                                            getDialect(), start, end);
1251                                    }
1252    
1253                                    cacheResult(list);
1254    
1255                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1256                            }
1257                            catch (Exception e) {
1258                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1259    
1260                                    throw processException(e);
1261                            }
1262                            finally {
1263                                    closeSession(session);
1264                            }
1265                    }
1266    
1267                    return list;
1268            }
1269    
1270            /**
1271             * Returns the first social activity setting in the ordered set where groupId = &#63; and activityType = &#63;.
1272             *
1273             * @param groupId the group ID
1274             * @param activityType the activity type
1275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1276             * @return the first matching social activity setting
1277             * @throws NoSuchActivitySettingException if a matching social activity setting could not be found
1278             */
1279            @Override
1280            public SocialActivitySetting findByG_A_First(long groupId,
1281                    int activityType,
1282                    OrderByComparator<SocialActivitySetting> orderByComparator)
1283                    throws NoSuchActivitySettingException {
1284                    SocialActivitySetting socialActivitySetting = fetchByG_A_First(groupId,
1285                                    activityType, orderByComparator);
1286    
1287                    if (socialActivitySetting != null) {
1288                            return socialActivitySetting;
1289                    }
1290    
1291                    StringBundler msg = new StringBundler(6);
1292    
1293                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1294    
1295                    msg.append("groupId=");
1296                    msg.append(groupId);
1297    
1298                    msg.append(", activityType=");
1299                    msg.append(activityType);
1300    
1301                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1302    
1303                    throw new NoSuchActivitySettingException(msg.toString());
1304            }
1305    
1306            /**
1307             * Returns the first social activity setting in the ordered set where groupId = &#63; and activityType = &#63;.
1308             *
1309             * @param groupId the group ID
1310             * @param activityType the activity type
1311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1312             * @return the first matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
1313             */
1314            @Override
1315            public SocialActivitySetting fetchByG_A_First(long groupId,
1316                    int activityType,
1317                    OrderByComparator<SocialActivitySetting> orderByComparator) {
1318                    List<SocialActivitySetting> list = findByG_A(groupId, activityType, 0,
1319                                    1, orderByComparator);
1320    
1321                    if (!list.isEmpty()) {
1322                            return list.get(0);
1323                    }
1324    
1325                    return null;
1326            }
1327    
1328            /**
1329             * Returns the last social activity setting in the ordered set where groupId = &#63; and activityType = &#63;.
1330             *
1331             * @param groupId the group ID
1332             * @param activityType the activity type
1333             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1334             * @return the last matching social activity setting
1335             * @throws NoSuchActivitySettingException if a matching social activity setting could not be found
1336             */
1337            @Override
1338            public SocialActivitySetting findByG_A_Last(long groupId, int activityType,
1339                    OrderByComparator<SocialActivitySetting> orderByComparator)
1340                    throws NoSuchActivitySettingException {
1341                    SocialActivitySetting socialActivitySetting = fetchByG_A_Last(groupId,
1342                                    activityType, orderByComparator);
1343    
1344                    if (socialActivitySetting != null) {
1345                            return socialActivitySetting;
1346                    }
1347    
1348                    StringBundler msg = new StringBundler(6);
1349    
1350                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1351    
1352                    msg.append("groupId=");
1353                    msg.append(groupId);
1354    
1355                    msg.append(", activityType=");
1356                    msg.append(activityType);
1357    
1358                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1359    
1360                    throw new NoSuchActivitySettingException(msg.toString());
1361            }
1362    
1363            /**
1364             * Returns the last social activity setting in the ordered set where groupId = &#63; and activityType = &#63;.
1365             *
1366             * @param groupId the group ID
1367             * @param activityType the activity type
1368             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1369             * @return the last matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
1370             */
1371            @Override
1372            public SocialActivitySetting fetchByG_A_Last(long groupId,
1373                    int activityType,
1374                    OrderByComparator<SocialActivitySetting> orderByComparator) {
1375                    int count = countByG_A(groupId, activityType);
1376    
1377                    if (count == 0) {
1378                            return null;
1379                    }
1380    
1381                    List<SocialActivitySetting> list = findByG_A(groupId, activityType,
1382                                    count - 1, count, orderByComparator);
1383    
1384                    if (!list.isEmpty()) {
1385                            return list.get(0);
1386                    }
1387    
1388                    return null;
1389            }
1390    
1391            /**
1392             * Returns the social activity settings before and after the current social activity setting in the ordered set where groupId = &#63; and activityType = &#63;.
1393             *
1394             * @param activitySettingId the primary key of the current social activity setting
1395             * @param groupId the group ID
1396             * @param activityType the activity type
1397             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1398             * @return the previous, current, and next social activity setting
1399             * @throws NoSuchActivitySettingException if a social activity setting with the primary key could not be found
1400             */
1401            @Override
1402            public SocialActivitySetting[] findByG_A_PrevAndNext(
1403                    long activitySettingId, long groupId, int activityType,
1404                    OrderByComparator<SocialActivitySetting> orderByComparator)
1405                    throws NoSuchActivitySettingException {
1406                    SocialActivitySetting socialActivitySetting = findByPrimaryKey(activitySettingId);
1407    
1408                    Session session = null;
1409    
1410                    try {
1411                            session = openSession();
1412    
1413                            SocialActivitySetting[] array = new SocialActivitySettingImpl[3];
1414    
1415                            array[0] = getByG_A_PrevAndNext(session, socialActivitySetting,
1416                                            groupId, activityType, orderByComparator, true);
1417    
1418                            array[1] = socialActivitySetting;
1419    
1420                            array[2] = getByG_A_PrevAndNext(session, socialActivitySetting,
1421                                            groupId, activityType, orderByComparator, false);
1422    
1423                            return array;
1424                    }
1425                    catch (Exception e) {
1426                            throw processException(e);
1427                    }
1428                    finally {
1429                            closeSession(session);
1430                    }
1431            }
1432    
1433            protected SocialActivitySetting getByG_A_PrevAndNext(Session session,
1434                    SocialActivitySetting socialActivitySetting, long groupId,
1435                    int activityType,
1436                    OrderByComparator<SocialActivitySetting> orderByComparator,
1437                    boolean previous) {
1438                    StringBundler query = null;
1439    
1440                    if (orderByComparator != null) {
1441                            query = new StringBundler(6 +
1442                                            (orderByComparator.getOrderByFields().length * 6));
1443                    }
1444                    else {
1445                            query = new StringBundler(3);
1446                    }
1447    
1448                    query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
1449    
1450                    query.append(_FINDER_COLUMN_G_A_GROUPID_2);
1451    
1452                    query.append(_FINDER_COLUMN_G_A_ACTIVITYTYPE_2);
1453    
1454                    if (orderByComparator != null) {
1455                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1456    
1457                            if (orderByConditionFields.length > 0) {
1458                                    query.append(WHERE_AND);
1459                            }
1460    
1461                            for (int i = 0; i < orderByConditionFields.length; i++) {
1462                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1463                                    query.append(orderByConditionFields[i]);
1464    
1465                                    if ((i + 1) < orderByConditionFields.length) {
1466                                            if (orderByComparator.isAscending() ^ previous) {
1467                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1468                                            }
1469                                            else {
1470                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1471                                            }
1472                                    }
1473                                    else {
1474                                            if (orderByComparator.isAscending() ^ previous) {
1475                                                    query.append(WHERE_GREATER_THAN);
1476                                            }
1477                                            else {
1478                                                    query.append(WHERE_LESSER_THAN);
1479                                            }
1480                                    }
1481                            }
1482    
1483                            query.append(ORDER_BY_CLAUSE);
1484    
1485                            String[] orderByFields = orderByComparator.getOrderByFields();
1486    
1487                            for (int i = 0; i < orderByFields.length; i++) {
1488                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1489                                    query.append(orderByFields[i]);
1490    
1491                                    if ((i + 1) < orderByFields.length) {
1492                                            if (orderByComparator.isAscending() ^ previous) {
1493                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1494                                            }
1495                                            else {
1496                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1497                                            }
1498                                    }
1499                                    else {
1500                                            if (orderByComparator.isAscending() ^ previous) {
1501                                                    query.append(ORDER_BY_ASC);
1502                                            }
1503                                            else {
1504                                                    query.append(ORDER_BY_DESC);
1505                                            }
1506                                    }
1507                            }
1508                    }
1509                    else {
1510                            query.append(SocialActivitySettingModelImpl.ORDER_BY_JPQL);
1511                    }
1512    
1513                    String sql = query.toString();
1514    
1515                    Query q = session.createQuery(sql);
1516    
1517                    q.setFirstResult(0);
1518                    q.setMaxResults(2);
1519    
1520                    QueryPos qPos = QueryPos.getInstance(q);
1521    
1522                    qPos.add(groupId);
1523    
1524                    qPos.add(activityType);
1525    
1526                    if (orderByComparator != null) {
1527                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivitySetting);
1528    
1529                            for (Object value : values) {
1530                                    qPos.add(value);
1531                            }
1532                    }
1533    
1534                    List<SocialActivitySetting> list = q.list();
1535    
1536                    if (list.size() == 2) {
1537                            return list.get(1);
1538                    }
1539                    else {
1540                            return null;
1541                    }
1542            }
1543    
1544            /**
1545             * Removes all the social activity settings where groupId = &#63; and activityType = &#63; from the database.
1546             *
1547             * @param groupId the group ID
1548             * @param activityType the activity type
1549             */
1550            @Override
1551            public void removeByG_A(long groupId, int activityType) {
1552                    for (SocialActivitySetting socialActivitySetting : findByG_A(groupId,
1553                                    activityType, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1554                            remove(socialActivitySetting);
1555                    }
1556            }
1557    
1558            /**
1559             * Returns the number of social activity settings where groupId = &#63; and activityType = &#63;.
1560             *
1561             * @param groupId the group ID
1562             * @param activityType the activity type
1563             * @return the number of matching social activity settings
1564             */
1565            @Override
1566            public int countByG_A(long groupId, int activityType) {
1567                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_A;
1568    
1569                    Object[] finderArgs = new Object[] { groupId, activityType };
1570    
1571                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1572                                    this);
1573    
1574                    if (count == null) {
1575                            StringBundler query = new StringBundler(3);
1576    
1577                            query.append(_SQL_COUNT_SOCIALACTIVITYSETTING_WHERE);
1578    
1579                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
1580    
1581                            query.append(_FINDER_COLUMN_G_A_ACTIVITYTYPE_2);
1582    
1583                            String sql = query.toString();
1584    
1585                            Session session = null;
1586    
1587                            try {
1588                                    session = openSession();
1589    
1590                                    Query q = session.createQuery(sql);
1591    
1592                                    QueryPos qPos = QueryPos.getInstance(q);
1593    
1594                                    qPos.add(groupId);
1595    
1596                                    qPos.add(activityType);
1597    
1598                                    count = (Long)q.uniqueResult();
1599    
1600                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1601                            }
1602                            catch (Exception e) {
1603                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1604    
1605                                    throw processException(e);
1606                            }
1607                            finally {
1608                                    closeSession(session);
1609                            }
1610                    }
1611    
1612                    return count.intValue();
1613            }
1614    
1615            private static final String _FINDER_COLUMN_G_A_GROUPID_2 = "socialActivitySetting.groupId = ? AND ";
1616            private static final String _FINDER_COLUMN_G_A_ACTIVITYTYPE_2 = "socialActivitySetting.activityType = ?";
1617            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
1618                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
1619                            SocialActivitySettingImpl.class,
1620                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_A",
1621                            new String[] {
1622                                    Long.class.getName(), Long.class.getName(),
1623                                    Integer.class.getName(),
1624                                    
1625                            Integer.class.getName(), Integer.class.getName(),
1626                                    OrderByComparator.class.getName()
1627                            });
1628            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
1629                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
1630                            SocialActivitySettingImpl.class,
1631                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_A",
1632                            new String[] {
1633                                    Long.class.getName(), Long.class.getName(),
1634                                    Integer.class.getName()
1635                            },
1636                            SocialActivitySettingModelImpl.GROUPID_COLUMN_BITMASK |
1637                            SocialActivitySettingModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1638                            SocialActivitySettingModelImpl.ACTIVITYTYPE_COLUMN_BITMASK);
1639            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
1640                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
1641                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_A",
1642                            new String[] {
1643                                    Long.class.getName(), Long.class.getName(),
1644                                    Integer.class.getName()
1645                            });
1646    
1647            /**
1648             * Returns all the social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1649             *
1650             * @param groupId the group ID
1651             * @param classNameId the class name ID
1652             * @param activityType the activity type
1653             * @return the matching social activity settings
1654             */
1655            @Override
1656            public List<SocialActivitySetting> findByG_C_A(long groupId,
1657                    long classNameId, int activityType) {
1658                    return findByG_C_A(groupId, classNameId, activityType,
1659                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1660            }
1661    
1662            /**
1663             * Returns a range of all the social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1664             *
1665             * <p>
1666             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialActivitySettingModelImpl}. 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.
1667             * </p>
1668             *
1669             * @param groupId the group ID
1670             * @param classNameId the class name ID
1671             * @param activityType the activity type
1672             * @param start the lower bound of the range of social activity settings
1673             * @param end the upper bound of the range of social activity settings (not inclusive)
1674             * @return the range of matching social activity settings
1675             */
1676            @Override
1677            public List<SocialActivitySetting> findByG_C_A(long groupId,
1678                    long classNameId, int activityType, int start, int end) {
1679                    return findByG_C_A(groupId, classNameId, activityType, start, end, null);
1680            }
1681    
1682            /**
1683             * Returns an ordered range of all the social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1684             *
1685             * <p>
1686             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialActivitySettingModelImpl}. 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.
1687             * </p>
1688             *
1689             * @param groupId the group ID
1690             * @param classNameId the class name ID
1691             * @param activityType the activity type
1692             * @param start the lower bound of the range of social activity settings
1693             * @param end the upper bound of the range of social activity settings (not inclusive)
1694             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1695             * @return the ordered range of matching social activity settings
1696             */
1697            @Override
1698            public List<SocialActivitySetting> findByG_C_A(long groupId,
1699                    long classNameId, int activityType, int start, int end,
1700                    OrderByComparator<SocialActivitySetting> orderByComparator) {
1701                    boolean pagination = true;
1702                    FinderPath finderPath = null;
1703                    Object[] finderArgs = null;
1704    
1705                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1706                                    (orderByComparator == null)) {
1707                            pagination = false;
1708                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_A;
1709                            finderArgs = new Object[] { groupId, classNameId, activityType };
1710                    }
1711                    else {
1712                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_A;
1713                            finderArgs = new Object[] {
1714                                            groupId, classNameId, activityType,
1715                                            
1716                                            start, end, orderByComparator
1717                                    };
1718                    }
1719    
1720                    List<SocialActivitySetting> list = (List<SocialActivitySetting>)FinderCacheUtil.getResult(finderPath,
1721                                    finderArgs, this);
1722    
1723                    if ((list != null) && !list.isEmpty()) {
1724                            for (SocialActivitySetting socialActivitySetting : list) {
1725                                    if ((groupId != socialActivitySetting.getGroupId()) ||
1726                                                    (classNameId != socialActivitySetting.getClassNameId()) ||
1727                                                    (activityType != socialActivitySetting.getActivityType())) {
1728                                            list = null;
1729    
1730                                            break;
1731                                    }
1732                            }
1733                    }
1734    
1735                    if (list == null) {
1736                            StringBundler query = null;
1737    
1738                            if (orderByComparator != null) {
1739                                    query = new StringBundler(5 +
1740                                                    (orderByComparator.getOrderByFields().length * 3));
1741                            }
1742                            else {
1743                                    query = new StringBundler(5);
1744                            }
1745    
1746                            query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
1747    
1748                            query.append(_FINDER_COLUMN_G_C_A_GROUPID_2);
1749    
1750                            query.append(_FINDER_COLUMN_G_C_A_CLASSNAMEID_2);
1751    
1752                            query.append(_FINDER_COLUMN_G_C_A_ACTIVITYTYPE_2);
1753    
1754                            if (orderByComparator != null) {
1755                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1756                                            orderByComparator);
1757                            }
1758                            else
1759                             if (pagination) {
1760                                    query.append(SocialActivitySettingModelImpl.ORDER_BY_JPQL);
1761                            }
1762    
1763                            String sql = query.toString();
1764    
1765                            Session session = null;
1766    
1767                            try {
1768                                    session = openSession();
1769    
1770                                    Query q = session.createQuery(sql);
1771    
1772                                    QueryPos qPos = QueryPos.getInstance(q);
1773    
1774                                    qPos.add(groupId);
1775    
1776                                    qPos.add(classNameId);
1777    
1778                                    qPos.add(activityType);
1779    
1780                                    if (!pagination) {
1781                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
1782                                                            getDialect(), start, end, false);
1783    
1784                                            Collections.sort(list);
1785    
1786                                            list = Collections.unmodifiableList(list);
1787                                    }
1788                                    else {
1789                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
1790                                                            getDialect(), start, end);
1791                                    }
1792    
1793                                    cacheResult(list);
1794    
1795                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1796                            }
1797                            catch (Exception e) {
1798                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1799    
1800                                    throw processException(e);
1801                            }
1802                            finally {
1803                                    closeSession(session);
1804                            }
1805                    }
1806    
1807                    return list;
1808            }
1809    
1810            /**
1811             * Returns the first social activity setting in the ordered set where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1812             *
1813             * @param groupId the group ID
1814             * @param classNameId the class name ID
1815             * @param activityType the activity type
1816             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1817             * @return the first matching social activity setting
1818             * @throws NoSuchActivitySettingException if a matching social activity setting could not be found
1819             */
1820            @Override
1821            public SocialActivitySetting findByG_C_A_First(long groupId,
1822                    long classNameId, int activityType,
1823                    OrderByComparator<SocialActivitySetting> orderByComparator)
1824                    throws NoSuchActivitySettingException {
1825                    SocialActivitySetting socialActivitySetting = fetchByG_C_A_First(groupId,
1826                                    classNameId, activityType, orderByComparator);
1827    
1828                    if (socialActivitySetting != null) {
1829                            return socialActivitySetting;
1830                    }
1831    
1832                    StringBundler msg = new StringBundler(8);
1833    
1834                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1835    
1836                    msg.append("groupId=");
1837                    msg.append(groupId);
1838    
1839                    msg.append(", classNameId=");
1840                    msg.append(classNameId);
1841    
1842                    msg.append(", activityType=");
1843                    msg.append(activityType);
1844    
1845                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1846    
1847                    throw new NoSuchActivitySettingException(msg.toString());
1848            }
1849    
1850            /**
1851             * Returns the first social activity setting in the ordered set where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1852             *
1853             * @param groupId the group ID
1854             * @param classNameId the class name ID
1855             * @param activityType the activity type
1856             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1857             * @return the first matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
1858             */
1859            @Override
1860            public SocialActivitySetting fetchByG_C_A_First(long groupId,
1861                    long classNameId, int activityType,
1862                    OrderByComparator<SocialActivitySetting> orderByComparator) {
1863                    List<SocialActivitySetting> list = findByG_C_A(groupId, classNameId,
1864                                    activityType, 0, 1, orderByComparator);
1865    
1866                    if (!list.isEmpty()) {
1867                            return list.get(0);
1868                    }
1869    
1870                    return null;
1871            }
1872    
1873            /**
1874             * Returns the last social activity setting in the ordered set where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1875             *
1876             * @param groupId the group ID
1877             * @param classNameId the class name ID
1878             * @param activityType the activity type
1879             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1880             * @return the last matching social activity setting
1881             * @throws NoSuchActivitySettingException if a matching social activity setting could not be found
1882             */
1883            @Override
1884            public SocialActivitySetting findByG_C_A_Last(long groupId,
1885                    long classNameId, int activityType,
1886                    OrderByComparator<SocialActivitySetting> orderByComparator)
1887                    throws NoSuchActivitySettingException {
1888                    SocialActivitySetting socialActivitySetting = fetchByG_C_A_Last(groupId,
1889                                    classNameId, activityType, orderByComparator);
1890    
1891                    if (socialActivitySetting != null) {
1892                            return socialActivitySetting;
1893                    }
1894    
1895                    StringBundler msg = new StringBundler(8);
1896    
1897                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1898    
1899                    msg.append("groupId=");
1900                    msg.append(groupId);
1901    
1902                    msg.append(", classNameId=");
1903                    msg.append(classNameId);
1904    
1905                    msg.append(", activityType=");
1906                    msg.append(activityType);
1907    
1908                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1909    
1910                    throw new NoSuchActivitySettingException(msg.toString());
1911            }
1912    
1913            /**
1914             * Returns the last social activity setting in the ordered set where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1915             *
1916             * @param groupId the group ID
1917             * @param classNameId the class name ID
1918             * @param activityType the activity type
1919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1920             * @return the last matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
1921             */
1922            @Override
1923            public SocialActivitySetting fetchByG_C_A_Last(long groupId,
1924                    long classNameId, int activityType,
1925                    OrderByComparator<SocialActivitySetting> orderByComparator) {
1926                    int count = countByG_C_A(groupId, classNameId, activityType);
1927    
1928                    if (count == 0) {
1929                            return null;
1930                    }
1931    
1932                    List<SocialActivitySetting> list = findByG_C_A(groupId, classNameId,
1933                                    activityType, count - 1, count, orderByComparator);
1934    
1935                    if (!list.isEmpty()) {
1936                            return list.get(0);
1937                    }
1938    
1939                    return null;
1940            }
1941    
1942            /**
1943             * Returns the social activity settings before and after the current social activity setting in the ordered set where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1944             *
1945             * @param activitySettingId the primary key of the current social activity setting
1946             * @param groupId the group ID
1947             * @param classNameId the class name ID
1948             * @param activityType the activity type
1949             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1950             * @return the previous, current, and next social activity setting
1951             * @throws NoSuchActivitySettingException if a social activity setting with the primary key could not be found
1952             */
1953            @Override
1954            public SocialActivitySetting[] findByG_C_A_PrevAndNext(
1955                    long activitySettingId, long groupId, long classNameId,
1956                    int activityType,
1957                    OrderByComparator<SocialActivitySetting> orderByComparator)
1958                    throws NoSuchActivitySettingException {
1959                    SocialActivitySetting socialActivitySetting = findByPrimaryKey(activitySettingId);
1960    
1961                    Session session = null;
1962    
1963                    try {
1964                            session = openSession();
1965    
1966                            SocialActivitySetting[] array = new SocialActivitySettingImpl[3];
1967    
1968                            array[0] = getByG_C_A_PrevAndNext(session, socialActivitySetting,
1969                                            groupId, classNameId, activityType, orderByComparator, true);
1970    
1971                            array[1] = socialActivitySetting;
1972    
1973                            array[2] = getByG_C_A_PrevAndNext(session, socialActivitySetting,
1974                                            groupId, classNameId, activityType, orderByComparator, false);
1975    
1976                            return array;
1977                    }
1978                    catch (Exception e) {
1979                            throw processException(e);
1980                    }
1981                    finally {
1982                            closeSession(session);
1983                    }
1984            }
1985    
1986            protected SocialActivitySetting getByG_C_A_PrevAndNext(Session session,
1987                    SocialActivitySetting socialActivitySetting, long groupId,
1988                    long classNameId, int activityType,
1989                    OrderByComparator<SocialActivitySetting> orderByComparator,
1990                    boolean previous) {
1991                    StringBundler query = null;
1992    
1993                    if (orderByComparator != null) {
1994                            query = new StringBundler(6 +
1995                                            (orderByComparator.getOrderByFields().length * 6));
1996                    }
1997                    else {
1998                            query = new StringBundler(3);
1999                    }
2000    
2001                    query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
2002    
2003                    query.append(_FINDER_COLUMN_G_C_A_GROUPID_2);
2004    
2005                    query.append(_FINDER_COLUMN_G_C_A_CLASSNAMEID_2);
2006    
2007                    query.append(_FINDER_COLUMN_G_C_A_ACTIVITYTYPE_2);
2008    
2009                    if (orderByComparator != null) {
2010                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2011    
2012                            if (orderByConditionFields.length > 0) {
2013                                    query.append(WHERE_AND);
2014                            }
2015    
2016                            for (int i = 0; i < orderByConditionFields.length; i++) {
2017                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2018                                    query.append(orderByConditionFields[i]);
2019    
2020                                    if ((i + 1) < orderByConditionFields.length) {
2021                                            if (orderByComparator.isAscending() ^ previous) {
2022                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2023                                            }
2024                                            else {
2025                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2026                                            }
2027                                    }
2028                                    else {
2029                                            if (orderByComparator.isAscending() ^ previous) {
2030                                                    query.append(WHERE_GREATER_THAN);
2031                                            }
2032                                            else {
2033                                                    query.append(WHERE_LESSER_THAN);
2034                                            }
2035                                    }
2036                            }
2037    
2038                            query.append(ORDER_BY_CLAUSE);
2039    
2040                            String[] orderByFields = orderByComparator.getOrderByFields();
2041    
2042                            for (int i = 0; i < orderByFields.length; i++) {
2043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2044                                    query.append(orderByFields[i]);
2045    
2046                                    if ((i + 1) < orderByFields.length) {
2047                                            if (orderByComparator.isAscending() ^ previous) {
2048                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2049                                            }
2050                                            else {
2051                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2052                                            }
2053                                    }
2054                                    else {
2055                                            if (orderByComparator.isAscending() ^ previous) {
2056                                                    query.append(ORDER_BY_ASC);
2057                                            }
2058                                            else {
2059                                                    query.append(ORDER_BY_DESC);
2060                                            }
2061                                    }
2062                            }
2063                    }
2064                    else {
2065                            query.append(SocialActivitySettingModelImpl.ORDER_BY_JPQL);
2066                    }
2067    
2068                    String sql = query.toString();
2069    
2070                    Query q = session.createQuery(sql);
2071    
2072                    q.setFirstResult(0);
2073                    q.setMaxResults(2);
2074    
2075                    QueryPos qPos = QueryPos.getInstance(q);
2076    
2077                    qPos.add(groupId);
2078    
2079                    qPos.add(classNameId);
2080    
2081                    qPos.add(activityType);
2082    
2083                    if (orderByComparator != null) {
2084                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivitySetting);
2085    
2086                            for (Object value : values) {
2087                                    qPos.add(value);
2088                            }
2089                    }
2090    
2091                    List<SocialActivitySetting> list = q.list();
2092    
2093                    if (list.size() == 2) {
2094                            return list.get(1);
2095                    }
2096                    else {
2097                            return null;
2098                    }
2099            }
2100    
2101            /**
2102             * Removes all the social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63; from the database.
2103             *
2104             * @param groupId the group ID
2105             * @param classNameId the class name ID
2106             * @param activityType the activity type
2107             */
2108            @Override
2109            public void removeByG_C_A(long groupId, long classNameId, int activityType) {
2110                    for (SocialActivitySetting socialActivitySetting : findByG_C_A(
2111                                    groupId, classNameId, activityType, QueryUtil.ALL_POS,
2112                                    QueryUtil.ALL_POS, null)) {
2113                            remove(socialActivitySetting);
2114                    }
2115            }
2116    
2117            /**
2118             * Returns the number of social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
2119             *
2120             * @param groupId the group ID
2121             * @param classNameId the class name ID
2122             * @param activityType the activity type
2123             * @return the number of matching social activity settings
2124             */
2125            @Override
2126            public int countByG_C_A(long groupId, long classNameId, int activityType) {
2127                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_A;
2128    
2129                    Object[] finderArgs = new Object[] { groupId, classNameId, activityType };
2130    
2131                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2132                                    this);
2133    
2134                    if (count == null) {
2135                            StringBundler query = new StringBundler(4);
2136    
2137                            query.append(_SQL_COUNT_SOCIALACTIVITYSETTING_WHERE);
2138    
2139                            query.append(_FINDER_COLUMN_G_C_A_GROUPID_2);
2140    
2141                            query.append(_FINDER_COLUMN_G_C_A_CLASSNAMEID_2);
2142    
2143                            query.append(_FINDER_COLUMN_G_C_A_ACTIVITYTYPE_2);
2144    
2145                            String sql = query.toString();
2146    
2147                            Session session = null;
2148    
2149                            try {
2150                                    session = openSession();
2151    
2152                                    Query q = session.createQuery(sql);
2153    
2154                                    QueryPos qPos = QueryPos.getInstance(q);
2155    
2156                                    qPos.add(groupId);
2157    
2158                                    qPos.add(classNameId);
2159    
2160                                    qPos.add(activityType);
2161    
2162                                    count = (Long)q.uniqueResult();
2163    
2164                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2165                            }
2166                            catch (Exception e) {
2167                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2168    
2169                                    throw processException(e);
2170                            }
2171                            finally {
2172                                    closeSession(session);
2173                            }
2174                    }
2175    
2176                    return count.intValue();
2177            }
2178    
2179            private static final String _FINDER_COLUMN_G_C_A_GROUPID_2 = "socialActivitySetting.groupId = ? AND ";
2180            private static final String _FINDER_COLUMN_G_C_A_CLASSNAMEID_2 = "socialActivitySetting.classNameId = ? AND ";
2181            private static final String _FINDER_COLUMN_G_C_A_ACTIVITYTYPE_2 = "socialActivitySetting.activityType = ?";
2182            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_A_N = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
2183                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
2184                            SocialActivitySettingImpl.class, FINDER_CLASS_NAME_ENTITY,
2185                            "fetchByG_C_A_N",
2186                            new String[] {
2187                                    Long.class.getName(), Long.class.getName(),
2188                                    Integer.class.getName(), String.class.getName()
2189                            },
2190                            SocialActivitySettingModelImpl.GROUPID_COLUMN_BITMASK |
2191                            SocialActivitySettingModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2192                            SocialActivitySettingModelImpl.ACTIVITYTYPE_COLUMN_BITMASK |
2193                            SocialActivitySettingModelImpl.NAME_COLUMN_BITMASK);
2194            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_A_N = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
2195                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
2196                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_A_N",
2197                            new String[] {
2198                                    Long.class.getName(), Long.class.getName(),
2199                                    Integer.class.getName(), String.class.getName()
2200                            });
2201    
2202            /**
2203             * Returns the social activity setting where groupId = &#63; and classNameId = &#63; and activityType = &#63; and name = &#63; or throws a {@link NoSuchActivitySettingException} if it could not be found.
2204             *
2205             * @param groupId the group ID
2206             * @param classNameId the class name ID
2207             * @param activityType the activity type
2208             * @param name the name
2209             * @return the matching social activity setting
2210             * @throws NoSuchActivitySettingException if a matching social activity setting could not be found
2211             */
2212            @Override
2213            public SocialActivitySetting findByG_C_A_N(long groupId, long classNameId,
2214                    int activityType, String name) throws NoSuchActivitySettingException {
2215                    SocialActivitySetting socialActivitySetting = fetchByG_C_A_N(groupId,
2216                                    classNameId, activityType, name);
2217    
2218                    if (socialActivitySetting == null) {
2219                            StringBundler msg = new StringBundler(10);
2220    
2221                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2222    
2223                            msg.append("groupId=");
2224                            msg.append(groupId);
2225    
2226                            msg.append(", classNameId=");
2227                            msg.append(classNameId);
2228    
2229                            msg.append(", activityType=");
2230                            msg.append(activityType);
2231    
2232                            msg.append(", name=");
2233                            msg.append(name);
2234    
2235                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2236    
2237                            if (_log.isWarnEnabled()) {
2238                                    _log.warn(msg.toString());
2239                            }
2240    
2241                            throw new NoSuchActivitySettingException(msg.toString());
2242                    }
2243    
2244                    return socialActivitySetting;
2245            }
2246    
2247            /**
2248             * Returns the social activity setting where groupId = &#63; and classNameId = &#63; and activityType = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2249             *
2250             * @param groupId the group ID
2251             * @param classNameId the class name ID
2252             * @param activityType the activity type
2253             * @param name the name
2254             * @return the matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
2255             */
2256            @Override
2257            public SocialActivitySetting fetchByG_C_A_N(long groupId, long classNameId,
2258                    int activityType, String name) {
2259                    return fetchByG_C_A_N(groupId, classNameId, activityType, name, true);
2260            }
2261    
2262            /**
2263             * Returns the social activity setting where groupId = &#63; and classNameId = &#63; and activityType = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2264             *
2265             * @param groupId the group ID
2266             * @param classNameId the class name ID
2267             * @param activityType the activity type
2268             * @param name the name
2269             * @param retrieveFromCache whether to use the finder cache
2270             * @return the matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
2271             */
2272            @Override
2273            public SocialActivitySetting fetchByG_C_A_N(long groupId, long classNameId,
2274                    int activityType, String name, boolean retrieveFromCache) {
2275                    Object[] finderArgs = new Object[] {
2276                                    groupId, classNameId, activityType, name
2277                            };
2278    
2279                    Object result = null;
2280    
2281                    if (retrieveFromCache) {
2282                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_A_N,
2283                                            finderArgs, this);
2284                    }
2285    
2286                    if (result instanceof SocialActivitySetting) {
2287                            SocialActivitySetting socialActivitySetting = (SocialActivitySetting)result;
2288    
2289                            if ((groupId != socialActivitySetting.getGroupId()) ||
2290                                            (classNameId != socialActivitySetting.getClassNameId()) ||
2291                                            (activityType != socialActivitySetting.getActivityType()) ||
2292                                            !Validator.equals(name, socialActivitySetting.getName())) {
2293                                    result = null;
2294                            }
2295                    }
2296    
2297                    if (result == null) {
2298                            StringBundler query = new StringBundler(6);
2299    
2300                            query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
2301    
2302                            query.append(_FINDER_COLUMN_G_C_A_N_GROUPID_2);
2303    
2304                            query.append(_FINDER_COLUMN_G_C_A_N_CLASSNAMEID_2);
2305    
2306                            query.append(_FINDER_COLUMN_G_C_A_N_ACTIVITYTYPE_2);
2307    
2308                            boolean bindName = false;
2309    
2310                            if (name == null) {
2311                                    query.append(_FINDER_COLUMN_G_C_A_N_NAME_1);
2312                            }
2313                            else if (name.equals(StringPool.BLANK)) {
2314                                    query.append(_FINDER_COLUMN_G_C_A_N_NAME_3);
2315                            }
2316                            else {
2317                                    bindName = true;
2318    
2319                                    query.append(_FINDER_COLUMN_G_C_A_N_NAME_2);
2320                            }
2321    
2322                            String sql = query.toString();
2323    
2324                            Session session = null;
2325    
2326                            try {
2327                                    session = openSession();
2328    
2329                                    Query q = session.createQuery(sql);
2330    
2331                                    QueryPos qPos = QueryPos.getInstance(q);
2332    
2333                                    qPos.add(groupId);
2334    
2335                                    qPos.add(classNameId);
2336    
2337                                    qPos.add(activityType);
2338    
2339                                    if (bindName) {
2340                                            qPos.add(name);
2341                                    }
2342    
2343                                    List<SocialActivitySetting> list = q.list();
2344    
2345                                    if (list.isEmpty()) {
2346                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_A_N,
2347                                                    finderArgs, list);
2348                                    }
2349                                    else {
2350                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2351                                                    _log.warn(
2352                                                            "SocialActivitySettingPersistenceImpl.fetchByG_C_A_N(long, long, int, String, boolean) with parameters (" +
2353                                                            StringUtil.merge(finderArgs) +
2354                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
2355                                            }
2356    
2357                                            SocialActivitySetting socialActivitySetting = list.get(0);
2358    
2359                                            result = socialActivitySetting;
2360    
2361                                            cacheResult(socialActivitySetting);
2362    
2363                                            if ((socialActivitySetting.getGroupId() != groupId) ||
2364                                                            (socialActivitySetting.getClassNameId() != classNameId) ||
2365                                                            (socialActivitySetting.getActivityType() != activityType) ||
2366                                                            (socialActivitySetting.getName() == null) ||
2367                                                            !socialActivitySetting.getName().equals(name)) {
2368                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_A_N,
2369                                                            finderArgs, socialActivitySetting);
2370                                            }
2371                                    }
2372                            }
2373                            catch (Exception e) {
2374                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_A_N,
2375                                            finderArgs);
2376    
2377                                    throw processException(e);
2378                            }
2379                            finally {
2380                                    closeSession(session);
2381                            }
2382                    }
2383    
2384                    if (result instanceof List<?>) {
2385                            return null;
2386                    }
2387                    else {
2388                            return (SocialActivitySetting)result;
2389                    }
2390            }
2391    
2392            /**
2393             * Removes the social activity setting where groupId = &#63; and classNameId = &#63; and activityType = &#63; and name = &#63; from the database.
2394             *
2395             * @param groupId the group ID
2396             * @param classNameId the class name ID
2397             * @param activityType the activity type
2398             * @param name the name
2399             * @return the social activity setting that was removed
2400             */
2401            @Override
2402            public SocialActivitySetting removeByG_C_A_N(long groupId,
2403                    long classNameId, int activityType, String name)
2404                    throws NoSuchActivitySettingException {
2405                    SocialActivitySetting socialActivitySetting = findByG_C_A_N(groupId,
2406                                    classNameId, activityType, name);
2407    
2408                    return remove(socialActivitySetting);
2409            }
2410    
2411            /**
2412             * Returns the number of social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63; and name = &#63;.
2413             *
2414             * @param groupId the group ID
2415             * @param classNameId the class name ID
2416             * @param activityType the activity type
2417             * @param name the name
2418             * @return the number of matching social activity settings
2419             */
2420            @Override
2421            public int countByG_C_A_N(long groupId, long classNameId, int activityType,
2422                    String name) {
2423                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_A_N;
2424    
2425                    Object[] finderArgs = new Object[] {
2426                                    groupId, classNameId, activityType, name
2427                            };
2428    
2429                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2430                                    this);
2431    
2432                    if (count == null) {
2433                            StringBundler query = new StringBundler(5);
2434    
2435                            query.append(_SQL_COUNT_SOCIALACTIVITYSETTING_WHERE);
2436    
2437                            query.append(_FINDER_COLUMN_G_C_A_N_GROUPID_2);
2438    
2439                            query.append(_FINDER_COLUMN_G_C_A_N_CLASSNAMEID_2);
2440    
2441                            query.append(_FINDER_COLUMN_G_C_A_N_ACTIVITYTYPE_2);
2442    
2443                            boolean bindName = false;
2444    
2445                            if (name == null) {
2446                                    query.append(_FINDER_COLUMN_G_C_A_N_NAME_1);
2447                            }
2448                            else if (name.equals(StringPool.BLANK)) {
2449                                    query.append(_FINDER_COLUMN_G_C_A_N_NAME_3);
2450                            }
2451                            else {
2452                                    bindName = true;
2453    
2454                                    query.append(_FINDER_COLUMN_G_C_A_N_NAME_2);
2455                            }
2456    
2457                            String sql = query.toString();
2458    
2459                            Session session = null;
2460    
2461                            try {
2462                                    session = openSession();
2463    
2464                                    Query q = session.createQuery(sql);
2465    
2466                                    QueryPos qPos = QueryPos.getInstance(q);
2467    
2468                                    qPos.add(groupId);
2469    
2470                                    qPos.add(classNameId);
2471    
2472                                    qPos.add(activityType);
2473    
2474                                    if (bindName) {
2475                                            qPos.add(name);
2476                                    }
2477    
2478                                    count = (Long)q.uniqueResult();
2479    
2480                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2481                            }
2482                            catch (Exception e) {
2483                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2484    
2485                                    throw processException(e);
2486                            }
2487                            finally {
2488                                    closeSession(session);
2489                            }
2490                    }
2491    
2492                    return count.intValue();
2493            }
2494    
2495            private static final String _FINDER_COLUMN_G_C_A_N_GROUPID_2 = "socialActivitySetting.groupId = ? AND ";
2496            private static final String _FINDER_COLUMN_G_C_A_N_CLASSNAMEID_2 = "socialActivitySetting.classNameId = ? AND ";
2497            private static final String _FINDER_COLUMN_G_C_A_N_ACTIVITYTYPE_2 = "socialActivitySetting.activityType = ? AND ";
2498            private static final String _FINDER_COLUMN_G_C_A_N_NAME_1 = "socialActivitySetting.name IS NULL";
2499            private static final String _FINDER_COLUMN_G_C_A_N_NAME_2 = "socialActivitySetting.name = ?";
2500            private static final String _FINDER_COLUMN_G_C_A_N_NAME_3 = "(socialActivitySetting.name IS NULL OR socialActivitySetting.name = '')";
2501    
2502            public SocialActivitySettingPersistenceImpl() {
2503                    setModelClass(SocialActivitySetting.class);
2504            }
2505    
2506            /**
2507             * Caches the social activity setting in the entity cache if it is enabled.
2508             *
2509             * @param socialActivitySetting the social activity setting
2510             */
2511            @Override
2512            public void cacheResult(SocialActivitySetting socialActivitySetting) {
2513                    EntityCacheUtil.putResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
2514                            SocialActivitySettingImpl.class,
2515                            socialActivitySetting.getPrimaryKey(), socialActivitySetting);
2516    
2517                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_A_N,
2518                            new Object[] {
2519                                    socialActivitySetting.getGroupId(),
2520                                    socialActivitySetting.getClassNameId(),
2521                                    socialActivitySetting.getActivityType(),
2522                                    socialActivitySetting.getName()
2523                            }, socialActivitySetting);
2524    
2525                    socialActivitySetting.resetOriginalValues();
2526            }
2527    
2528            /**
2529             * Caches the social activity settings in the entity cache if it is enabled.
2530             *
2531             * @param socialActivitySettings the social activity settings
2532             */
2533            @Override
2534            public void cacheResult(List<SocialActivitySetting> socialActivitySettings) {
2535                    for (SocialActivitySetting socialActivitySetting : socialActivitySettings) {
2536                            if (EntityCacheUtil.getResult(
2537                                                    SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
2538                                                    SocialActivitySettingImpl.class,
2539                                                    socialActivitySetting.getPrimaryKey()) == null) {
2540                                    cacheResult(socialActivitySetting);
2541                            }
2542                            else {
2543                                    socialActivitySetting.resetOriginalValues();
2544                            }
2545                    }
2546            }
2547    
2548            /**
2549             * Clears the cache for all social activity settings.
2550             *
2551             * <p>
2552             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2553             * </p>
2554             */
2555            @Override
2556            public void clearCache() {
2557                    EntityCacheUtil.clearCache(SocialActivitySettingImpl.class);
2558    
2559                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2560                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2561                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2562            }
2563    
2564            /**
2565             * Clears the cache for the social activity setting.
2566             *
2567             * <p>
2568             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2569             * </p>
2570             */
2571            @Override
2572            public void clearCache(SocialActivitySetting socialActivitySetting) {
2573                    EntityCacheUtil.removeResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
2574                            SocialActivitySettingImpl.class,
2575                            socialActivitySetting.getPrimaryKey());
2576    
2577                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2578                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2579    
2580                    clearUniqueFindersCache(socialActivitySetting);
2581            }
2582    
2583            @Override
2584            public void clearCache(List<SocialActivitySetting> socialActivitySettings) {
2585                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2586                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2587    
2588                    for (SocialActivitySetting socialActivitySetting : socialActivitySettings) {
2589                            EntityCacheUtil.removeResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
2590                                    SocialActivitySettingImpl.class,
2591                                    socialActivitySetting.getPrimaryKey());
2592    
2593                            clearUniqueFindersCache(socialActivitySetting);
2594                    }
2595            }
2596    
2597            protected void cacheUniqueFindersCache(
2598                    SocialActivitySetting socialActivitySetting) {
2599                    if (socialActivitySetting.isNew()) {
2600                            Object[] args = new Object[] {
2601                                            socialActivitySetting.getGroupId(),
2602                                            socialActivitySetting.getClassNameId(),
2603                                            socialActivitySetting.getActivityType(),
2604                                            socialActivitySetting.getName()
2605                                    };
2606    
2607                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_A_N, args,
2608                                    Long.valueOf(1));
2609                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_A_N, args,
2610                                    socialActivitySetting);
2611                    }
2612                    else {
2613                            SocialActivitySettingModelImpl socialActivitySettingModelImpl = (SocialActivitySettingModelImpl)socialActivitySetting;
2614    
2615                            if ((socialActivitySettingModelImpl.getColumnBitmask() &
2616                                            FINDER_PATH_FETCH_BY_G_C_A_N.getColumnBitmask()) != 0) {
2617                                    Object[] args = new Object[] {
2618                                                    socialActivitySetting.getGroupId(),
2619                                                    socialActivitySetting.getClassNameId(),
2620                                                    socialActivitySetting.getActivityType(),
2621                                                    socialActivitySetting.getName()
2622                                            };
2623    
2624                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_A_N, args,
2625                                            Long.valueOf(1));
2626                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_A_N, args,
2627                                            socialActivitySetting);
2628                            }
2629                    }
2630            }
2631    
2632            protected void clearUniqueFindersCache(
2633                    SocialActivitySetting socialActivitySetting) {
2634                    SocialActivitySettingModelImpl socialActivitySettingModelImpl = (SocialActivitySettingModelImpl)socialActivitySetting;
2635    
2636                    Object[] args = new Object[] {
2637                                    socialActivitySetting.getGroupId(),
2638                                    socialActivitySetting.getClassNameId(),
2639                                    socialActivitySetting.getActivityType(),
2640                                    socialActivitySetting.getName()
2641                            };
2642    
2643                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_A_N, args);
2644                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_A_N, args);
2645    
2646                    if ((socialActivitySettingModelImpl.getColumnBitmask() &
2647                                    FINDER_PATH_FETCH_BY_G_C_A_N.getColumnBitmask()) != 0) {
2648                            args = new Object[] {
2649                                            socialActivitySettingModelImpl.getOriginalGroupId(),
2650                                            socialActivitySettingModelImpl.getOriginalClassNameId(),
2651                                            socialActivitySettingModelImpl.getOriginalActivityType(),
2652                                            socialActivitySettingModelImpl.getOriginalName()
2653                                    };
2654    
2655                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_A_N, args);
2656                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_A_N, args);
2657                    }
2658            }
2659    
2660            /**
2661             * Creates a new social activity setting with the primary key. Does not add the social activity setting to the database.
2662             *
2663             * @param activitySettingId the primary key for the new social activity setting
2664             * @return the new social activity setting
2665             */
2666            @Override
2667            public SocialActivitySetting create(long activitySettingId) {
2668                    SocialActivitySetting socialActivitySetting = new SocialActivitySettingImpl();
2669    
2670                    socialActivitySetting.setNew(true);
2671                    socialActivitySetting.setPrimaryKey(activitySettingId);
2672    
2673                    return socialActivitySetting;
2674            }
2675    
2676            /**
2677             * Removes the social activity setting with the primary key from the database. Also notifies the appropriate model listeners.
2678             *
2679             * @param activitySettingId the primary key of the social activity setting
2680             * @return the social activity setting that was removed
2681             * @throws NoSuchActivitySettingException if a social activity setting with the primary key could not be found
2682             */
2683            @Override
2684            public SocialActivitySetting remove(long activitySettingId)
2685                    throws NoSuchActivitySettingException {
2686                    return remove((Serializable)activitySettingId);
2687            }
2688    
2689            /**
2690             * Removes the social activity setting with the primary key from the database. Also notifies the appropriate model listeners.
2691             *
2692             * @param primaryKey the primary key of the social activity setting
2693             * @return the social activity setting that was removed
2694             * @throws NoSuchActivitySettingException if a social activity setting with the primary key could not be found
2695             */
2696            @Override
2697            public SocialActivitySetting remove(Serializable primaryKey)
2698                    throws NoSuchActivitySettingException {
2699                    Session session = null;
2700    
2701                    try {
2702                            session = openSession();
2703    
2704                            SocialActivitySetting socialActivitySetting = (SocialActivitySetting)session.get(SocialActivitySettingImpl.class,
2705                                            primaryKey);
2706    
2707                            if (socialActivitySetting == null) {
2708                                    if (_log.isWarnEnabled()) {
2709                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2710                                    }
2711    
2712                                    throw new NoSuchActivitySettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2713                                            primaryKey);
2714                            }
2715    
2716                            return remove(socialActivitySetting);
2717                    }
2718                    catch (NoSuchActivitySettingException nsee) {
2719                            throw nsee;
2720                    }
2721                    catch (Exception e) {
2722                            throw processException(e);
2723                    }
2724                    finally {
2725                            closeSession(session);
2726                    }
2727            }
2728    
2729            @Override
2730            protected SocialActivitySetting removeImpl(
2731                    SocialActivitySetting socialActivitySetting) {
2732                    socialActivitySetting = toUnwrappedModel(socialActivitySetting);
2733    
2734                    Session session = null;
2735    
2736                    try {
2737                            session = openSession();
2738    
2739                            if (!session.contains(socialActivitySetting)) {
2740                                    socialActivitySetting = (SocialActivitySetting)session.get(SocialActivitySettingImpl.class,
2741                                                    socialActivitySetting.getPrimaryKeyObj());
2742                            }
2743    
2744                            if (socialActivitySetting != null) {
2745                                    session.delete(socialActivitySetting);
2746                            }
2747                    }
2748                    catch (Exception e) {
2749                            throw processException(e);
2750                    }
2751                    finally {
2752                            closeSession(session);
2753                    }
2754    
2755                    if (socialActivitySetting != null) {
2756                            clearCache(socialActivitySetting);
2757                    }
2758    
2759                    return socialActivitySetting;
2760            }
2761    
2762            @Override
2763            public SocialActivitySetting updateImpl(
2764                    SocialActivitySetting socialActivitySetting) {
2765                    socialActivitySetting = toUnwrappedModel(socialActivitySetting);
2766    
2767                    boolean isNew = socialActivitySetting.isNew();
2768    
2769                    SocialActivitySettingModelImpl socialActivitySettingModelImpl = (SocialActivitySettingModelImpl)socialActivitySetting;
2770    
2771                    Session session = null;
2772    
2773                    try {
2774                            session = openSession();
2775    
2776                            if (socialActivitySetting.isNew()) {
2777                                    session.save(socialActivitySetting);
2778    
2779                                    socialActivitySetting.setNew(false);
2780                            }
2781                            else {
2782                                    session.merge(socialActivitySetting);
2783                            }
2784                    }
2785                    catch (Exception e) {
2786                            throw processException(e);
2787                    }
2788                    finally {
2789                            closeSession(session);
2790                    }
2791    
2792                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2793    
2794                    if (isNew || !SocialActivitySettingModelImpl.COLUMN_BITMASK_ENABLED) {
2795                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2796                    }
2797    
2798                    else {
2799                            if ((socialActivitySettingModelImpl.getColumnBitmask() &
2800                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2801                                    Object[] args = new Object[] {
2802                                                    socialActivitySettingModelImpl.getOriginalGroupId()
2803                                            };
2804    
2805                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2806                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2807                                            args);
2808    
2809                                    args = new Object[] { socialActivitySettingModelImpl.getGroupId() };
2810    
2811                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2812                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2813                                            args);
2814                            }
2815    
2816                            if ((socialActivitySettingModelImpl.getColumnBitmask() &
2817                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
2818                                    Object[] args = new Object[] {
2819                                                    socialActivitySettingModelImpl.getOriginalGroupId(),
2820                                                    socialActivitySettingModelImpl.getOriginalClassNameId()
2821                                            };
2822    
2823                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2824                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
2825                                            args);
2826    
2827                                    args = new Object[] {
2828                                                    socialActivitySettingModelImpl.getGroupId(),
2829                                                    socialActivitySettingModelImpl.getClassNameId()
2830                                            };
2831    
2832                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2833                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
2834                                            args);
2835                            }
2836    
2837                            if ((socialActivitySettingModelImpl.getColumnBitmask() &
2838                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A.getColumnBitmask()) != 0) {
2839                                    Object[] args = new Object[] {
2840                                                    socialActivitySettingModelImpl.getOriginalGroupId(),
2841                                                    socialActivitySettingModelImpl.getOriginalActivityType()
2842                                            };
2843    
2844                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A, args);
2845                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A,
2846                                            args);
2847    
2848                                    args = new Object[] {
2849                                                    socialActivitySettingModelImpl.getGroupId(),
2850                                                    socialActivitySettingModelImpl.getActivityType()
2851                                            };
2852    
2853                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A, args);
2854                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A,
2855                                            args);
2856                            }
2857    
2858                            if ((socialActivitySettingModelImpl.getColumnBitmask() &
2859                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_A.getColumnBitmask()) != 0) {
2860                                    Object[] args = new Object[] {
2861                                                    socialActivitySettingModelImpl.getOriginalGroupId(),
2862                                                    socialActivitySettingModelImpl.getOriginalClassNameId(),
2863                                                    socialActivitySettingModelImpl.getOriginalActivityType()
2864                                            };
2865    
2866                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_A, args);
2867                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_A,
2868                                            args);
2869    
2870                                    args = new Object[] {
2871                                                    socialActivitySettingModelImpl.getGroupId(),
2872                                                    socialActivitySettingModelImpl.getClassNameId(),
2873                                                    socialActivitySettingModelImpl.getActivityType()
2874                                            };
2875    
2876                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_A, args);
2877                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_A,
2878                                            args);
2879                            }
2880                    }
2881    
2882                    EntityCacheUtil.putResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
2883                            SocialActivitySettingImpl.class,
2884                            socialActivitySetting.getPrimaryKey(), socialActivitySetting, false);
2885    
2886                    clearUniqueFindersCache(socialActivitySetting);
2887                    cacheUniqueFindersCache(socialActivitySetting);
2888    
2889                    socialActivitySetting.resetOriginalValues();
2890    
2891                    return socialActivitySetting;
2892            }
2893    
2894            protected SocialActivitySetting toUnwrappedModel(
2895                    SocialActivitySetting socialActivitySetting) {
2896                    if (socialActivitySetting instanceof SocialActivitySettingImpl) {
2897                            return socialActivitySetting;
2898                    }
2899    
2900                    SocialActivitySettingImpl socialActivitySettingImpl = new SocialActivitySettingImpl();
2901    
2902                    socialActivitySettingImpl.setNew(socialActivitySetting.isNew());
2903                    socialActivitySettingImpl.setPrimaryKey(socialActivitySetting.getPrimaryKey());
2904    
2905                    socialActivitySettingImpl.setActivitySettingId(socialActivitySetting.getActivitySettingId());
2906                    socialActivitySettingImpl.setGroupId(socialActivitySetting.getGroupId());
2907                    socialActivitySettingImpl.setCompanyId(socialActivitySetting.getCompanyId());
2908                    socialActivitySettingImpl.setClassNameId(socialActivitySetting.getClassNameId());
2909                    socialActivitySettingImpl.setActivityType(socialActivitySetting.getActivityType());
2910                    socialActivitySettingImpl.setName(socialActivitySetting.getName());
2911                    socialActivitySettingImpl.setValue(socialActivitySetting.getValue());
2912    
2913                    return socialActivitySettingImpl;
2914            }
2915    
2916            /**
2917             * Returns the social activity setting with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2918             *
2919             * @param primaryKey the primary key of the social activity setting
2920             * @return the social activity setting
2921             * @throws NoSuchActivitySettingException if a social activity setting with the primary key could not be found
2922             */
2923            @Override
2924            public SocialActivitySetting findByPrimaryKey(Serializable primaryKey)
2925                    throws NoSuchActivitySettingException {
2926                    SocialActivitySetting socialActivitySetting = fetchByPrimaryKey(primaryKey);
2927    
2928                    if (socialActivitySetting == null) {
2929                            if (_log.isWarnEnabled()) {
2930                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2931                            }
2932    
2933                            throw new NoSuchActivitySettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2934                                    primaryKey);
2935                    }
2936    
2937                    return socialActivitySetting;
2938            }
2939    
2940            /**
2941             * Returns the social activity setting with the primary key or throws a {@link NoSuchActivitySettingException} if it could not be found.
2942             *
2943             * @param activitySettingId the primary key of the social activity setting
2944             * @return the social activity setting
2945             * @throws NoSuchActivitySettingException if a social activity setting with the primary key could not be found
2946             */
2947            @Override
2948            public SocialActivitySetting findByPrimaryKey(long activitySettingId)
2949                    throws NoSuchActivitySettingException {
2950                    return findByPrimaryKey((Serializable)activitySettingId);
2951            }
2952    
2953            /**
2954             * Returns the social activity setting with the primary key or returns <code>null</code> if it could not be found.
2955             *
2956             * @param primaryKey the primary key of the social activity setting
2957             * @return the social activity setting, or <code>null</code> if a social activity setting with the primary key could not be found
2958             */
2959            @Override
2960            public SocialActivitySetting fetchByPrimaryKey(Serializable primaryKey) {
2961                    SocialActivitySetting socialActivitySetting = (SocialActivitySetting)EntityCacheUtil.getResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
2962                                    SocialActivitySettingImpl.class, primaryKey);
2963    
2964                    if (socialActivitySetting == _nullSocialActivitySetting) {
2965                            return null;
2966                    }
2967    
2968                    if (socialActivitySetting == null) {
2969                            Session session = null;
2970    
2971                            try {
2972                                    session = openSession();
2973    
2974                                    socialActivitySetting = (SocialActivitySetting)session.get(SocialActivitySettingImpl.class,
2975                                                    primaryKey);
2976    
2977                                    if (socialActivitySetting != null) {
2978                                            cacheResult(socialActivitySetting);
2979                                    }
2980                                    else {
2981                                            EntityCacheUtil.putResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
2982                                                    SocialActivitySettingImpl.class, primaryKey,
2983                                                    _nullSocialActivitySetting);
2984                                    }
2985                            }
2986                            catch (Exception e) {
2987                                    EntityCacheUtil.removeResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
2988                                            SocialActivitySettingImpl.class, primaryKey);
2989    
2990                                    throw processException(e);
2991                            }
2992                            finally {
2993                                    closeSession(session);
2994                            }
2995                    }
2996    
2997                    return socialActivitySetting;
2998            }
2999    
3000            /**
3001             * Returns the social activity setting with the primary key or returns <code>null</code> if it could not be found.
3002             *
3003             * @param activitySettingId the primary key of the social activity setting
3004             * @return the social activity setting, or <code>null</code> if a social activity setting with the primary key could not be found
3005             */
3006            @Override
3007            public SocialActivitySetting fetchByPrimaryKey(long activitySettingId) {
3008                    return fetchByPrimaryKey((Serializable)activitySettingId);
3009            }
3010    
3011            @Override
3012            public Map<Serializable, SocialActivitySetting> fetchByPrimaryKeys(
3013                    Set<Serializable> primaryKeys) {
3014                    if (primaryKeys.isEmpty()) {
3015                            return Collections.emptyMap();
3016                    }
3017    
3018                    Map<Serializable, SocialActivitySetting> map = new HashMap<Serializable, SocialActivitySetting>();
3019    
3020                    if (primaryKeys.size() == 1) {
3021                            Iterator<Serializable> iterator = primaryKeys.iterator();
3022    
3023                            Serializable primaryKey = iterator.next();
3024    
3025                            SocialActivitySetting socialActivitySetting = fetchByPrimaryKey(primaryKey);
3026    
3027                            if (socialActivitySetting != null) {
3028                                    map.put(primaryKey, socialActivitySetting);
3029                            }
3030    
3031                            return map;
3032                    }
3033    
3034                    Set<Serializable> uncachedPrimaryKeys = null;
3035    
3036                    for (Serializable primaryKey : primaryKeys) {
3037                            SocialActivitySetting socialActivitySetting = (SocialActivitySetting)EntityCacheUtil.getResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
3038                                            SocialActivitySettingImpl.class, primaryKey);
3039    
3040                            if (socialActivitySetting == null) {
3041                                    if (uncachedPrimaryKeys == null) {
3042                                            uncachedPrimaryKeys = new HashSet<Serializable>();
3043                                    }
3044    
3045                                    uncachedPrimaryKeys.add(primaryKey);
3046                            }
3047                            else {
3048                                    map.put(primaryKey, socialActivitySetting);
3049                            }
3050                    }
3051    
3052                    if (uncachedPrimaryKeys == null) {
3053                            return map;
3054                    }
3055    
3056                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3057                                    1);
3058    
3059                    query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE_PKS_IN);
3060    
3061                    for (Serializable primaryKey : uncachedPrimaryKeys) {
3062                            query.append(String.valueOf(primaryKey));
3063    
3064                            query.append(StringPool.COMMA);
3065                    }
3066    
3067                    query.setIndex(query.index() - 1);
3068    
3069                    query.append(StringPool.CLOSE_PARENTHESIS);
3070    
3071                    String sql = query.toString();
3072    
3073                    Session session = null;
3074    
3075                    try {
3076                            session = openSession();
3077    
3078                            Query q = session.createQuery(sql);
3079    
3080                            for (SocialActivitySetting socialActivitySetting : (List<SocialActivitySetting>)q.list()) {
3081                                    map.put(socialActivitySetting.getPrimaryKeyObj(),
3082                                            socialActivitySetting);
3083    
3084                                    cacheResult(socialActivitySetting);
3085    
3086                                    uncachedPrimaryKeys.remove(socialActivitySetting.getPrimaryKeyObj());
3087                            }
3088    
3089                            for (Serializable primaryKey : uncachedPrimaryKeys) {
3090                                    EntityCacheUtil.putResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
3091                                            SocialActivitySettingImpl.class, primaryKey,
3092                                            _nullSocialActivitySetting);
3093                            }
3094                    }
3095                    catch (Exception e) {
3096                            throw processException(e);
3097                    }
3098                    finally {
3099                            closeSession(session);
3100                    }
3101    
3102                    return map;
3103            }
3104    
3105            /**
3106             * Returns all the social activity settings.
3107             *
3108             * @return the social activity settings
3109             */
3110            @Override
3111            public List<SocialActivitySetting> findAll() {
3112                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3113            }
3114    
3115            /**
3116             * Returns a range of all the social activity settings.
3117             *
3118             * <p>
3119             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialActivitySettingModelImpl}. 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.
3120             * </p>
3121             *
3122             * @param start the lower bound of the range of social activity settings
3123             * @param end the upper bound of the range of social activity settings (not inclusive)
3124             * @return the range of social activity settings
3125             */
3126            @Override
3127            public List<SocialActivitySetting> findAll(int start, int end) {
3128                    return findAll(start, end, null);
3129            }
3130    
3131            /**
3132             * Returns an ordered range of all the social activity settings.
3133             *
3134             * <p>
3135             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialActivitySettingModelImpl}. 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.
3136             * </p>
3137             *
3138             * @param start the lower bound of the range of social activity settings
3139             * @param end the upper bound of the range of social activity settings (not inclusive)
3140             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3141             * @return the ordered range of social activity settings
3142             */
3143            @Override
3144            public List<SocialActivitySetting> findAll(int start, int end,
3145                    OrderByComparator<SocialActivitySetting> orderByComparator) {
3146                    boolean pagination = true;
3147                    FinderPath finderPath = null;
3148                    Object[] finderArgs = null;
3149    
3150                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3151                                    (orderByComparator == null)) {
3152                            pagination = false;
3153                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3154                            finderArgs = FINDER_ARGS_EMPTY;
3155                    }
3156                    else {
3157                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3158                            finderArgs = new Object[] { start, end, orderByComparator };
3159                    }
3160    
3161                    List<SocialActivitySetting> list = (List<SocialActivitySetting>)FinderCacheUtil.getResult(finderPath,
3162                                    finderArgs, this);
3163    
3164                    if (list == null) {
3165                            StringBundler query = null;
3166                            String sql = null;
3167    
3168                            if (orderByComparator != null) {
3169                                    query = new StringBundler(2 +
3170                                                    (orderByComparator.getOrderByFields().length * 3));
3171    
3172                                    query.append(_SQL_SELECT_SOCIALACTIVITYSETTING);
3173    
3174                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3175                                            orderByComparator);
3176    
3177                                    sql = query.toString();
3178                            }
3179                            else {
3180                                    sql = _SQL_SELECT_SOCIALACTIVITYSETTING;
3181    
3182                                    if (pagination) {
3183                                            sql = sql.concat(SocialActivitySettingModelImpl.ORDER_BY_JPQL);
3184                                    }
3185                            }
3186    
3187                            Session session = null;
3188    
3189                            try {
3190                                    session = openSession();
3191    
3192                                    Query q = session.createQuery(sql);
3193    
3194                                    if (!pagination) {
3195                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
3196                                                            getDialect(), start, end, false);
3197    
3198                                            Collections.sort(list);
3199    
3200                                            list = Collections.unmodifiableList(list);
3201                                    }
3202                                    else {
3203                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
3204                                                            getDialect(), start, end);
3205                                    }
3206    
3207                                    cacheResult(list);
3208    
3209                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3210                            }
3211                            catch (Exception e) {
3212                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3213    
3214                                    throw processException(e);
3215                            }
3216                            finally {
3217                                    closeSession(session);
3218                            }
3219                    }
3220    
3221                    return list;
3222            }
3223    
3224            /**
3225             * Removes all the social activity settings from the database.
3226             *
3227             */
3228            @Override
3229            public void removeAll() {
3230                    for (SocialActivitySetting socialActivitySetting : findAll()) {
3231                            remove(socialActivitySetting);
3232                    }
3233            }
3234    
3235            /**
3236             * Returns the number of social activity settings.
3237             *
3238             * @return the number of social activity settings
3239             */
3240            @Override
3241            public int countAll() {
3242                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3243                                    FINDER_ARGS_EMPTY, this);
3244    
3245                    if (count == null) {
3246                            Session session = null;
3247    
3248                            try {
3249                                    session = openSession();
3250    
3251                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYSETTING);
3252    
3253                                    count = (Long)q.uniqueResult();
3254    
3255                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3256                                            FINDER_ARGS_EMPTY, count);
3257                            }
3258                            catch (Exception e) {
3259                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3260                                            FINDER_ARGS_EMPTY);
3261    
3262                                    throw processException(e);
3263                            }
3264                            finally {
3265                                    closeSession(session);
3266                            }
3267                    }
3268    
3269                    return count.intValue();
3270            }
3271    
3272            /**
3273             * Initializes the social activity setting persistence.
3274             */
3275            public void afterPropertiesSet() {
3276            }
3277    
3278            public void destroy() {
3279                    EntityCacheUtil.removeCache(SocialActivitySettingImpl.class.getName());
3280                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3281                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3282                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3283            }
3284    
3285            private static final String _SQL_SELECT_SOCIALACTIVITYSETTING = "SELECT socialActivitySetting FROM SocialActivitySetting socialActivitySetting";
3286            private static final String _SQL_SELECT_SOCIALACTIVITYSETTING_WHERE_PKS_IN = "SELECT socialActivitySetting FROM SocialActivitySetting socialActivitySetting WHERE activitySettingId IN (";
3287            private static final String _SQL_SELECT_SOCIALACTIVITYSETTING_WHERE = "SELECT socialActivitySetting FROM SocialActivitySetting socialActivitySetting WHERE ";
3288            private static final String _SQL_COUNT_SOCIALACTIVITYSETTING = "SELECT COUNT(socialActivitySetting) FROM SocialActivitySetting socialActivitySetting";
3289            private static final String _SQL_COUNT_SOCIALACTIVITYSETTING_WHERE = "SELECT COUNT(socialActivitySetting) FROM SocialActivitySetting socialActivitySetting WHERE ";
3290            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivitySetting.";
3291            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivitySetting exists with the primary key ";
3292            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivitySetting exists with the key {";
3293            private static final Log _log = LogFactoryUtil.getLog(SocialActivitySettingPersistenceImpl.class);
3294            private static final SocialActivitySetting _nullSocialActivitySetting = new SocialActivitySettingImpl() {
3295                            @Override
3296                            public Object clone() {
3297                                    return this;
3298                            }
3299    
3300                            @Override
3301                            public CacheModel<SocialActivitySetting> toCacheModel() {
3302                                    return _nullSocialActivitySettingCacheModel;
3303                            }
3304                    };
3305    
3306            private static final CacheModel<SocialActivitySetting> _nullSocialActivitySettingCacheModel =
3307                    new CacheModel<SocialActivitySetting>() {
3308                            @Override
3309                            public SocialActivitySetting toEntityModel() {
3310                                    return _nullSocialActivitySetting;
3311                            }
3312                    };
3313    }