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