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