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