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