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