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