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