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