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