001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
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.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.GroupPersistence;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.social.NoSuchActivitySettingException;
046    import com.liferay.portlet.social.model.SocialActivitySetting;
047    import com.liferay.portlet.social.model.impl.SocialActivitySettingImpl;
048    import com.liferay.portlet.social.model.impl.SocialActivitySettingModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the social activity setting service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see SocialActivitySettingPersistence
065     * @see SocialActivitySettingUtil
066     * @generated
067     */
068    public class SocialActivitySettingPersistenceImpl extends BasePersistenceImpl<SocialActivitySetting>
069            implements SocialActivitySettingPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * 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.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivitySettingImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
081                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
082                            SocialActivitySettingImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_A",
084                            new String[] {
085                                    Long.class.getName(), Integer.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
091                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
092                            SocialActivitySettingImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_A",
094                            new String[] { Long.class.getName(), Integer.class.getName() },
095                            SocialActivitySettingModelImpl.GROUPID_COLUMN_BITMASK |
096                            SocialActivitySettingModelImpl.ACTIVITYTYPE_COLUMN_BITMASK);
097            public static final FinderPath FINDER_PATH_COUNT_BY_G_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
098                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_A",
100                            new String[] { Long.class.getName(), Integer.class.getName() });
101            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
102                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
103                            SocialActivitySettingImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_A",
105                            new String[] {
106                                    Long.class.getName(), Long.class.getName(),
107                                    Integer.class.getName(),
108                                    
109                            "java.lang.Integer", "java.lang.Integer",
110                                    "com.liferay.portal.kernel.util.OrderByComparator"
111                            });
112            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
113                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
114                            SocialActivitySettingImpl.class,
115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_A",
116                            new String[] {
117                                    Long.class.getName(), Long.class.getName(),
118                                    Integer.class.getName()
119                            },
120                            SocialActivitySettingModelImpl.GROUPID_COLUMN_BITMASK |
121                            SocialActivitySettingModelImpl.CLASSNAMEID_COLUMN_BITMASK |
122                            SocialActivitySettingModelImpl.ACTIVITYTYPE_COLUMN_BITMASK);
123            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_A = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
124                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
125                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_A",
126                            new String[] {
127                                    Long.class.getName(), Long.class.getName(),
128                                    Integer.class.getName()
129                            });
130            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_A_N = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
131                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
132                            SocialActivitySettingImpl.class, FINDER_CLASS_NAME_ENTITY,
133                            "fetchByG_C_A_N",
134                            new String[] {
135                                    Long.class.getName(), Long.class.getName(),
136                                    Integer.class.getName(), String.class.getName()
137                            },
138                            SocialActivitySettingModelImpl.GROUPID_COLUMN_BITMASK |
139                            SocialActivitySettingModelImpl.CLASSNAMEID_COLUMN_BITMASK |
140                            SocialActivitySettingModelImpl.ACTIVITYTYPE_COLUMN_BITMASK |
141                            SocialActivitySettingModelImpl.NAME_COLUMN_BITMASK);
142            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_A_N = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
143                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
144                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_A_N",
145                            new String[] {
146                                    Long.class.getName(), Long.class.getName(),
147                                    Integer.class.getName(), String.class.getName()
148                            });
149            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
150                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
151                            SocialActivitySettingImpl.class,
152                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
153            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
154                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED,
155                            SocialActivitySettingImpl.class,
156                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
157            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
158                            SocialActivitySettingModelImpl.FINDER_CACHE_ENABLED, Long.class,
159                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
160    
161            /**
162             * Caches the social activity setting in the entity cache if it is enabled.
163             *
164             * @param socialActivitySetting the social activity setting
165             */
166            public void cacheResult(SocialActivitySetting socialActivitySetting) {
167                    EntityCacheUtil.putResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
168                            SocialActivitySettingImpl.class,
169                            socialActivitySetting.getPrimaryKey(), socialActivitySetting);
170    
171                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_A_N,
172                            new Object[] {
173                                    Long.valueOf(socialActivitySetting.getGroupId()),
174                                    Long.valueOf(socialActivitySetting.getClassNameId()),
175                                    Integer.valueOf(socialActivitySetting.getActivityType()),
176                                    
177                            socialActivitySetting.getName()
178                            }, socialActivitySetting);
179    
180                    socialActivitySetting.resetOriginalValues();
181            }
182    
183            /**
184             * Caches the social activity settings in the entity cache if it is enabled.
185             *
186             * @param socialActivitySettings the social activity settings
187             */
188            public void cacheResult(List<SocialActivitySetting> socialActivitySettings) {
189                    for (SocialActivitySetting socialActivitySetting : socialActivitySettings) {
190                            if (EntityCacheUtil.getResult(
191                                                    SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
192                                                    SocialActivitySettingImpl.class,
193                                                    socialActivitySetting.getPrimaryKey()) == null) {
194                                    cacheResult(socialActivitySetting);
195                            }
196                            else {
197                                    socialActivitySetting.resetOriginalValues();
198                            }
199                    }
200            }
201    
202            /**
203             * Clears the cache for all social activity settings.
204             *
205             * <p>
206             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
207             * </p>
208             */
209            @Override
210            public void clearCache() {
211                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
212                            CacheRegistryUtil.clear(SocialActivitySettingImpl.class.getName());
213                    }
214    
215                    EntityCacheUtil.clearCache(SocialActivitySettingImpl.class.getName());
216    
217                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
219                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
220            }
221    
222            /**
223             * Clears the cache for the social activity setting.
224             *
225             * <p>
226             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
227             * </p>
228             */
229            @Override
230            public void clearCache(SocialActivitySetting socialActivitySetting) {
231                    EntityCacheUtil.removeResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
232                            SocialActivitySettingImpl.class,
233                            socialActivitySetting.getPrimaryKey());
234    
235                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
236                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
237    
238                    clearUniqueFindersCache(socialActivitySetting);
239            }
240    
241            @Override
242            public void clearCache(List<SocialActivitySetting> socialActivitySettings) {
243                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
244                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
245    
246                    for (SocialActivitySetting socialActivitySetting : socialActivitySettings) {
247                            EntityCacheUtil.removeResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
248                                    SocialActivitySettingImpl.class,
249                                    socialActivitySetting.getPrimaryKey());
250    
251                            clearUniqueFindersCache(socialActivitySetting);
252                    }
253            }
254    
255            protected void cacheUniqueFindersCache(
256                    SocialActivitySetting socialActivitySetting) {
257                    if (socialActivitySetting.isNew()) {
258                            Object[] args = new Object[] {
259                                            Long.valueOf(socialActivitySetting.getGroupId()),
260                                            Long.valueOf(socialActivitySetting.getClassNameId()),
261                                            Integer.valueOf(socialActivitySetting.getActivityType()),
262                                            
263                                            socialActivitySetting.getName()
264                                    };
265    
266                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_A_N, args,
267                                    Long.valueOf(1));
268                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_A_N, args,
269                                    socialActivitySetting);
270                    }
271                    else {
272                            SocialActivitySettingModelImpl socialActivitySettingModelImpl = (SocialActivitySettingModelImpl)socialActivitySetting;
273    
274                            if ((socialActivitySettingModelImpl.getColumnBitmask() &
275                                            FINDER_PATH_FETCH_BY_G_C_A_N.getColumnBitmask()) != 0) {
276                                    Object[] args = new Object[] {
277                                                    Long.valueOf(socialActivitySetting.getGroupId()),
278                                                    Long.valueOf(socialActivitySetting.getClassNameId()),
279                                                    Integer.valueOf(socialActivitySetting.getActivityType()),
280                                                    
281                                                    socialActivitySetting.getName()
282                                            };
283    
284                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_A_N, args,
285                                            Long.valueOf(1));
286                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_A_N, args,
287                                            socialActivitySetting);
288                            }
289                    }
290            }
291    
292            protected void clearUniqueFindersCache(
293                    SocialActivitySetting socialActivitySetting) {
294                    SocialActivitySettingModelImpl socialActivitySettingModelImpl = (SocialActivitySettingModelImpl)socialActivitySetting;
295    
296                    Object[] args = new Object[] {
297                                    Long.valueOf(socialActivitySetting.getGroupId()),
298                                    Long.valueOf(socialActivitySetting.getClassNameId()),
299                                    Integer.valueOf(socialActivitySetting.getActivityType()),
300                                    
301                                    socialActivitySetting.getName()
302                            };
303    
304                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_A_N, args);
305                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_A_N, args);
306    
307                    if ((socialActivitySettingModelImpl.getColumnBitmask() &
308                                    FINDER_PATH_FETCH_BY_G_C_A_N.getColumnBitmask()) != 0) {
309                            args = new Object[] {
310                                            Long.valueOf(socialActivitySettingModelImpl.getOriginalGroupId()),
311                                            Long.valueOf(socialActivitySettingModelImpl.getOriginalClassNameId()),
312                                            Integer.valueOf(socialActivitySettingModelImpl.getOriginalActivityType()),
313                                            
314                                            socialActivitySettingModelImpl.getOriginalName()
315                                    };
316    
317                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_A_N, args);
318                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_A_N, args);
319                    }
320            }
321    
322            /**
323             * Creates a new social activity setting with the primary key. Does not add the social activity setting to the database.
324             *
325             * @param activitySettingId the primary key for the new social activity setting
326             * @return the new social activity setting
327             */
328            public SocialActivitySetting create(long activitySettingId) {
329                    SocialActivitySetting socialActivitySetting = new SocialActivitySettingImpl();
330    
331                    socialActivitySetting.setNew(true);
332                    socialActivitySetting.setPrimaryKey(activitySettingId);
333    
334                    return socialActivitySetting;
335            }
336    
337            /**
338             * Removes the social activity setting with the primary key from the database. Also notifies the appropriate model listeners.
339             *
340             * @param activitySettingId the primary key of the social activity setting
341             * @return the social activity setting that was removed
342             * @throws com.liferay.portlet.social.NoSuchActivitySettingException if a social activity setting with the primary key could not be found
343             * @throws SystemException if a system exception occurred
344             */
345            public SocialActivitySetting remove(long activitySettingId)
346                    throws NoSuchActivitySettingException, SystemException {
347                    return remove(Long.valueOf(activitySettingId));
348            }
349    
350            /**
351             * Removes the social activity setting with the primary key from the database. Also notifies the appropriate model listeners.
352             *
353             * @param primaryKey the primary key of the social activity setting
354             * @return the social activity setting that was removed
355             * @throws com.liferay.portlet.social.NoSuchActivitySettingException if a social activity setting with the primary key could not be found
356             * @throws SystemException if a system exception occurred
357             */
358            @Override
359            public SocialActivitySetting remove(Serializable primaryKey)
360                    throws NoSuchActivitySettingException, SystemException {
361                    Session session = null;
362    
363                    try {
364                            session = openSession();
365    
366                            SocialActivitySetting socialActivitySetting = (SocialActivitySetting)session.get(SocialActivitySettingImpl.class,
367                                            primaryKey);
368    
369                            if (socialActivitySetting == null) {
370                                    if (_log.isWarnEnabled()) {
371                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
372                                    }
373    
374                                    throw new NoSuchActivitySettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
375                                            primaryKey);
376                            }
377    
378                            return remove(socialActivitySetting);
379                    }
380                    catch (NoSuchActivitySettingException nsee) {
381                            throw nsee;
382                    }
383                    catch (Exception e) {
384                            throw processException(e);
385                    }
386                    finally {
387                            closeSession(session);
388                    }
389            }
390    
391            @Override
392            protected SocialActivitySetting removeImpl(
393                    SocialActivitySetting socialActivitySetting) throws SystemException {
394                    socialActivitySetting = toUnwrappedModel(socialActivitySetting);
395    
396                    Session session = null;
397    
398                    try {
399                            session = openSession();
400    
401                            BatchSessionUtil.delete(session, socialActivitySetting);
402                    }
403                    catch (Exception e) {
404                            throw processException(e);
405                    }
406                    finally {
407                            closeSession(session);
408                    }
409    
410                    clearCache(socialActivitySetting);
411    
412                    return socialActivitySetting;
413            }
414    
415            @Override
416            public SocialActivitySetting updateImpl(
417                    com.liferay.portlet.social.model.SocialActivitySetting socialActivitySetting,
418                    boolean merge) throws SystemException {
419                    socialActivitySetting = toUnwrappedModel(socialActivitySetting);
420    
421                    boolean isNew = socialActivitySetting.isNew();
422    
423                    SocialActivitySettingModelImpl socialActivitySettingModelImpl = (SocialActivitySettingModelImpl)socialActivitySetting;
424    
425                    Session session = null;
426    
427                    try {
428                            session = openSession();
429    
430                            BatchSessionUtil.update(session, socialActivitySetting, merge);
431    
432                            socialActivitySetting.setNew(false);
433                    }
434                    catch (Exception e) {
435                            throw processException(e);
436                    }
437                    finally {
438                            closeSession(session);
439                    }
440    
441                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
442    
443                    if (isNew || !SocialActivitySettingModelImpl.COLUMN_BITMASK_ENABLED) {
444                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
445                    }
446    
447                    else {
448                            if ((socialActivitySettingModelImpl.getColumnBitmask() &
449                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A.getColumnBitmask()) != 0) {
450                                    Object[] args = new Object[] {
451                                                    Long.valueOf(socialActivitySettingModelImpl.getOriginalGroupId()),
452                                                    Integer.valueOf(socialActivitySettingModelImpl.getOriginalActivityType())
453                                            };
454    
455                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A, args);
456                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A,
457                                            args);
458    
459                                    args = new Object[] {
460                                                    Long.valueOf(socialActivitySettingModelImpl.getGroupId()),
461                                                    Integer.valueOf(socialActivitySettingModelImpl.getActivityType())
462                                            };
463    
464                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A, args);
465                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A,
466                                            args);
467                            }
468    
469                            if ((socialActivitySettingModelImpl.getColumnBitmask() &
470                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_A.getColumnBitmask()) != 0) {
471                                    Object[] args = new Object[] {
472                                                    Long.valueOf(socialActivitySettingModelImpl.getOriginalGroupId()),
473                                                    Long.valueOf(socialActivitySettingModelImpl.getOriginalClassNameId()),
474                                                    Integer.valueOf(socialActivitySettingModelImpl.getOriginalActivityType())
475                                            };
476    
477                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_A, args);
478                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_A,
479                                            args);
480    
481                                    args = new Object[] {
482                                                    Long.valueOf(socialActivitySettingModelImpl.getGroupId()),
483                                                    Long.valueOf(socialActivitySettingModelImpl.getClassNameId()),
484                                                    Integer.valueOf(socialActivitySettingModelImpl.getActivityType())
485                                            };
486    
487                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_A, args);
488                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_A,
489                                            args);
490                            }
491                    }
492    
493                    EntityCacheUtil.putResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
494                            SocialActivitySettingImpl.class,
495                            socialActivitySetting.getPrimaryKey(), socialActivitySetting);
496    
497                    clearUniqueFindersCache(socialActivitySetting);
498                    cacheUniqueFindersCache(socialActivitySetting);
499    
500                    return socialActivitySetting;
501            }
502    
503            protected SocialActivitySetting toUnwrappedModel(
504                    SocialActivitySetting socialActivitySetting) {
505                    if (socialActivitySetting instanceof SocialActivitySettingImpl) {
506                            return socialActivitySetting;
507                    }
508    
509                    SocialActivitySettingImpl socialActivitySettingImpl = new SocialActivitySettingImpl();
510    
511                    socialActivitySettingImpl.setNew(socialActivitySetting.isNew());
512                    socialActivitySettingImpl.setPrimaryKey(socialActivitySetting.getPrimaryKey());
513    
514                    socialActivitySettingImpl.setActivitySettingId(socialActivitySetting.getActivitySettingId());
515                    socialActivitySettingImpl.setGroupId(socialActivitySetting.getGroupId());
516                    socialActivitySettingImpl.setCompanyId(socialActivitySetting.getCompanyId());
517                    socialActivitySettingImpl.setClassNameId(socialActivitySetting.getClassNameId());
518                    socialActivitySettingImpl.setActivityType(socialActivitySetting.getActivityType());
519                    socialActivitySettingImpl.setName(socialActivitySetting.getName());
520                    socialActivitySettingImpl.setValue(socialActivitySetting.getValue());
521    
522                    return socialActivitySettingImpl;
523            }
524    
525            /**
526             * Returns the social activity setting with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
527             *
528             * @param primaryKey the primary key of the social activity setting
529             * @return the social activity setting
530             * @throws com.liferay.portal.NoSuchModelException if a social activity setting with the primary key could not be found
531             * @throws SystemException if a system exception occurred
532             */
533            @Override
534            public SocialActivitySetting findByPrimaryKey(Serializable primaryKey)
535                    throws NoSuchModelException, SystemException {
536                    return findByPrimaryKey(((Long)primaryKey).longValue());
537            }
538    
539            /**
540             * Returns the social activity setting with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivitySettingException} if it could not be found.
541             *
542             * @param activitySettingId the primary key of the social activity setting
543             * @return the social activity setting
544             * @throws com.liferay.portlet.social.NoSuchActivitySettingException if a social activity setting with the primary key could not be found
545             * @throws SystemException if a system exception occurred
546             */
547            public SocialActivitySetting findByPrimaryKey(long activitySettingId)
548                    throws NoSuchActivitySettingException, SystemException {
549                    SocialActivitySetting socialActivitySetting = fetchByPrimaryKey(activitySettingId);
550    
551                    if (socialActivitySetting == null) {
552                            if (_log.isWarnEnabled()) {
553                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + activitySettingId);
554                            }
555    
556                            throw new NoSuchActivitySettingException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
557                                    activitySettingId);
558                    }
559    
560                    return socialActivitySetting;
561            }
562    
563            /**
564             * Returns the social activity setting with the primary key or returns <code>null</code> if it could not be found.
565             *
566             * @param primaryKey the primary key of the social activity setting
567             * @return the social activity setting, or <code>null</code> if a social activity setting with the primary key could not be found
568             * @throws SystemException if a system exception occurred
569             */
570            @Override
571            public SocialActivitySetting fetchByPrimaryKey(Serializable primaryKey)
572                    throws SystemException {
573                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
574            }
575    
576            /**
577             * Returns the social activity setting with the primary key or returns <code>null</code> if it could not be found.
578             *
579             * @param activitySettingId the primary key of the social activity setting
580             * @return the social activity setting, or <code>null</code> if a social activity setting with the primary key could not be found
581             * @throws SystemException if a system exception occurred
582             */
583            public SocialActivitySetting fetchByPrimaryKey(long activitySettingId)
584                    throws SystemException {
585                    SocialActivitySetting socialActivitySetting = (SocialActivitySetting)EntityCacheUtil.getResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
586                                    SocialActivitySettingImpl.class, activitySettingId);
587    
588                    if (socialActivitySetting == _nullSocialActivitySetting) {
589                            return null;
590                    }
591    
592                    if (socialActivitySetting == null) {
593                            Session session = null;
594    
595                            boolean hasException = false;
596    
597                            try {
598                                    session = openSession();
599    
600                                    socialActivitySetting = (SocialActivitySetting)session.get(SocialActivitySettingImpl.class,
601                                                    Long.valueOf(activitySettingId));
602                            }
603                            catch (Exception e) {
604                                    hasException = true;
605    
606                                    throw processException(e);
607                            }
608                            finally {
609                                    if (socialActivitySetting != null) {
610                                            cacheResult(socialActivitySetting);
611                                    }
612                                    else if (!hasException) {
613                                            EntityCacheUtil.putResult(SocialActivitySettingModelImpl.ENTITY_CACHE_ENABLED,
614                                                    SocialActivitySettingImpl.class, activitySettingId,
615                                                    _nullSocialActivitySetting);
616                                    }
617    
618                                    closeSession(session);
619                            }
620                    }
621    
622                    return socialActivitySetting;
623            }
624    
625            /**
626             * Returns all the social activity settings where groupId = &#63; and activityType = &#63;.
627             *
628             * @param groupId the group ID
629             * @param activityType the activity type
630             * @return the matching social activity settings
631             * @throws SystemException if a system exception occurred
632             */
633            public List<SocialActivitySetting> findByG_A(long groupId, int activityType)
634                    throws SystemException {
635                    return findByG_A(groupId, activityType, QueryUtil.ALL_POS,
636                            QueryUtil.ALL_POS, null);
637            }
638    
639            /**
640             * Returns a range of all the social activity settings where groupId = &#63; and activityType = &#63;.
641             *
642             * <p>
643             * 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.
644             * </p>
645             *
646             * @param groupId the group ID
647             * @param activityType the activity type
648             * @param start the lower bound of the range of social activity settings
649             * @param end the upper bound of the range of social activity settings (not inclusive)
650             * @return the range of matching social activity settings
651             * @throws SystemException if a system exception occurred
652             */
653            public List<SocialActivitySetting> findByG_A(long groupId,
654                    int activityType, int start, int end) throws SystemException {
655                    return findByG_A(groupId, activityType, start, end, null);
656            }
657    
658            /**
659             * Returns an ordered range of all the social activity settings where groupId = &#63; and activityType = &#63;.
660             *
661             * <p>
662             * 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.
663             * </p>
664             *
665             * @param groupId the group ID
666             * @param activityType the activity type
667             * @param start the lower bound of the range of social activity settings
668             * @param end the upper bound of the range of social activity settings (not inclusive)
669             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
670             * @return the ordered range of matching social activity settings
671             * @throws SystemException if a system exception occurred
672             */
673            public List<SocialActivitySetting> findByG_A(long groupId,
674                    int activityType, int start, int end,
675                    OrderByComparator orderByComparator) throws SystemException {
676                    FinderPath finderPath = null;
677                    Object[] finderArgs = null;
678    
679                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
680                                    (orderByComparator == null)) {
681                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A;
682                            finderArgs = new Object[] { groupId, activityType };
683                    }
684                    else {
685                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A;
686                            finderArgs = new Object[] {
687                                            groupId, activityType,
688                                            
689                                            start, end, orderByComparator
690                                    };
691                    }
692    
693                    List<SocialActivitySetting> list = (List<SocialActivitySetting>)FinderCacheUtil.getResult(finderPath,
694                                    finderArgs, this);
695    
696                    if ((list != null) && !list.isEmpty()) {
697                            for (SocialActivitySetting socialActivitySetting : list) {
698                                    if ((groupId != socialActivitySetting.getGroupId()) ||
699                                                    (activityType != socialActivitySetting.getActivityType())) {
700                                            list = null;
701    
702                                            break;
703                                    }
704                            }
705                    }
706    
707                    if (list == null) {
708                            StringBundler query = null;
709    
710                            if (orderByComparator != null) {
711                                    query = new StringBundler(4 +
712                                                    (orderByComparator.getOrderByFields().length * 3));
713                            }
714                            else {
715                                    query = new StringBundler(3);
716                            }
717    
718                            query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
719    
720                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
721    
722                            query.append(_FINDER_COLUMN_G_A_ACTIVITYTYPE_2);
723    
724                            if (orderByComparator != null) {
725                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
726                                            orderByComparator);
727                            }
728    
729                            String sql = query.toString();
730    
731                            Session session = null;
732    
733                            try {
734                                    session = openSession();
735    
736                                    Query q = session.createQuery(sql);
737    
738                                    QueryPos qPos = QueryPos.getInstance(q);
739    
740                                    qPos.add(groupId);
741    
742                                    qPos.add(activityType);
743    
744                                    list = (List<SocialActivitySetting>)QueryUtil.list(q,
745                                                    getDialect(), start, end);
746                            }
747                            catch (Exception e) {
748                                    throw processException(e);
749                            }
750                            finally {
751                                    if (list == null) {
752                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
753                                    }
754                                    else {
755                                            cacheResult(list);
756    
757                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
758                                    }
759    
760                                    closeSession(session);
761                            }
762                    }
763    
764                    return list;
765            }
766    
767            /**
768             * Returns the first social activity setting in the ordered set where groupId = &#63; and activityType = &#63;.
769             *
770             * @param groupId the group ID
771             * @param activityType the activity type
772             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
773             * @return the first matching social activity setting
774             * @throws com.liferay.portlet.social.NoSuchActivitySettingException if a matching social activity setting could not be found
775             * @throws SystemException if a system exception occurred
776             */
777            public SocialActivitySetting findByG_A_First(long groupId,
778                    int activityType, OrderByComparator orderByComparator)
779                    throws NoSuchActivitySettingException, SystemException {
780                    SocialActivitySetting socialActivitySetting = fetchByG_A_First(groupId,
781                                    activityType, orderByComparator);
782    
783                    if (socialActivitySetting != null) {
784                            return socialActivitySetting;
785                    }
786    
787                    StringBundler msg = new StringBundler(6);
788    
789                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
790    
791                    msg.append("groupId=");
792                    msg.append(groupId);
793    
794                    msg.append(", activityType=");
795                    msg.append(activityType);
796    
797                    msg.append(StringPool.CLOSE_CURLY_BRACE);
798    
799                    throw new NoSuchActivitySettingException(msg.toString());
800            }
801    
802            /**
803             * Returns the first social activity setting in the ordered set where groupId = &#63; and activityType = &#63;.
804             *
805             * @param groupId the group ID
806             * @param activityType the activity type
807             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
808             * @return the first matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
809             * @throws SystemException if a system exception occurred
810             */
811            public SocialActivitySetting fetchByG_A_First(long groupId,
812                    int activityType, OrderByComparator orderByComparator)
813                    throws SystemException {
814                    List<SocialActivitySetting> list = findByG_A(groupId, activityType, 0,
815                                    1, orderByComparator);
816    
817                    if (!list.isEmpty()) {
818                            return list.get(0);
819                    }
820    
821                    return null;
822            }
823    
824            /**
825             * Returns the last social activity setting in the ordered set where groupId = &#63; and activityType = &#63;.
826             *
827             * @param groupId the group ID
828             * @param activityType the activity type
829             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
830             * @return the last matching social activity setting
831             * @throws com.liferay.portlet.social.NoSuchActivitySettingException if a matching social activity setting could not be found
832             * @throws SystemException if a system exception occurred
833             */
834            public SocialActivitySetting findByG_A_Last(long groupId, int activityType,
835                    OrderByComparator orderByComparator)
836                    throws NoSuchActivitySettingException, SystemException {
837                    SocialActivitySetting socialActivitySetting = fetchByG_A_Last(groupId,
838                                    activityType, orderByComparator);
839    
840                    if (socialActivitySetting != null) {
841                            return socialActivitySetting;
842                    }
843    
844                    StringBundler msg = new StringBundler(6);
845    
846                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
847    
848                    msg.append("groupId=");
849                    msg.append(groupId);
850    
851                    msg.append(", activityType=");
852                    msg.append(activityType);
853    
854                    msg.append(StringPool.CLOSE_CURLY_BRACE);
855    
856                    throw new NoSuchActivitySettingException(msg.toString());
857            }
858    
859            /**
860             * Returns the last social activity setting in the ordered set where groupId = &#63; and activityType = &#63;.
861             *
862             * @param groupId the group ID
863             * @param activityType the activity type
864             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
865             * @return the last matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
866             * @throws SystemException if a system exception occurred
867             */
868            public SocialActivitySetting fetchByG_A_Last(long groupId,
869                    int activityType, OrderByComparator orderByComparator)
870                    throws SystemException {
871                    int count = countByG_A(groupId, activityType);
872    
873                    List<SocialActivitySetting> list = findByG_A(groupId, activityType,
874                                    count - 1, count, orderByComparator);
875    
876                    if (!list.isEmpty()) {
877                            return list.get(0);
878                    }
879    
880                    return null;
881            }
882    
883            /**
884             * Returns the social activity settings before and after the current social activity setting in the ordered set where groupId = &#63; and activityType = &#63;.
885             *
886             * @param activitySettingId the primary key of the current social activity setting
887             * @param groupId the group ID
888             * @param activityType the activity type
889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
890             * @return the previous, current, and next social activity setting
891             * @throws com.liferay.portlet.social.NoSuchActivitySettingException if a social activity setting with the primary key could not be found
892             * @throws SystemException if a system exception occurred
893             */
894            public SocialActivitySetting[] findByG_A_PrevAndNext(
895                    long activitySettingId, long groupId, int activityType,
896                    OrderByComparator orderByComparator)
897                    throws NoSuchActivitySettingException, SystemException {
898                    SocialActivitySetting socialActivitySetting = findByPrimaryKey(activitySettingId);
899    
900                    Session session = null;
901    
902                    try {
903                            session = openSession();
904    
905                            SocialActivitySetting[] array = new SocialActivitySettingImpl[3];
906    
907                            array[0] = getByG_A_PrevAndNext(session, socialActivitySetting,
908                                            groupId, activityType, orderByComparator, true);
909    
910                            array[1] = socialActivitySetting;
911    
912                            array[2] = getByG_A_PrevAndNext(session, socialActivitySetting,
913                                            groupId, activityType, orderByComparator, false);
914    
915                            return array;
916                    }
917                    catch (Exception e) {
918                            throw processException(e);
919                    }
920                    finally {
921                            closeSession(session);
922                    }
923            }
924    
925            protected SocialActivitySetting getByG_A_PrevAndNext(Session session,
926                    SocialActivitySetting socialActivitySetting, long groupId,
927                    int activityType, OrderByComparator orderByComparator, boolean previous) {
928                    StringBundler query = null;
929    
930                    if (orderByComparator != null) {
931                            query = new StringBundler(6 +
932                                            (orderByComparator.getOrderByFields().length * 6));
933                    }
934                    else {
935                            query = new StringBundler(3);
936                    }
937    
938                    query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
939    
940                    query.append(_FINDER_COLUMN_G_A_GROUPID_2);
941    
942                    query.append(_FINDER_COLUMN_G_A_ACTIVITYTYPE_2);
943    
944                    if (orderByComparator != null) {
945                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
946    
947                            if (orderByConditionFields.length > 0) {
948                                    query.append(WHERE_AND);
949                            }
950    
951                            for (int i = 0; i < orderByConditionFields.length; i++) {
952                                    query.append(_ORDER_BY_ENTITY_ALIAS);
953                                    query.append(orderByConditionFields[i]);
954    
955                                    if ((i + 1) < orderByConditionFields.length) {
956                                            if (orderByComparator.isAscending() ^ previous) {
957                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
958                                            }
959                                            else {
960                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
961                                            }
962                                    }
963                                    else {
964                                            if (orderByComparator.isAscending() ^ previous) {
965                                                    query.append(WHERE_GREATER_THAN);
966                                            }
967                                            else {
968                                                    query.append(WHERE_LESSER_THAN);
969                                            }
970                                    }
971                            }
972    
973                            query.append(ORDER_BY_CLAUSE);
974    
975                            String[] orderByFields = orderByComparator.getOrderByFields();
976    
977                            for (int i = 0; i < orderByFields.length; i++) {
978                                    query.append(_ORDER_BY_ENTITY_ALIAS);
979                                    query.append(orderByFields[i]);
980    
981                                    if ((i + 1) < orderByFields.length) {
982                                            if (orderByComparator.isAscending() ^ previous) {
983                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
984                                            }
985                                            else {
986                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
987                                            }
988                                    }
989                                    else {
990                                            if (orderByComparator.isAscending() ^ previous) {
991                                                    query.append(ORDER_BY_ASC);
992                                            }
993                                            else {
994                                                    query.append(ORDER_BY_DESC);
995                                            }
996                                    }
997                            }
998                    }
999    
1000                    String sql = query.toString();
1001    
1002                    Query q = session.createQuery(sql);
1003    
1004                    q.setFirstResult(0);
1005                    q.setMaxResults(2);
1006    
1007                    QueryPos qPos = QueryPos.getInstance(q);
1008    
1009                    qPos.add(groupId);
1010    
1011                    qPos.add(activityType);
1012    
1013                    if (orderByComparator != null) {
1014                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivitySetting);
1015    
1016                            for (Object value : values) {
1017                                    qPos.add(value);
1018                            }
1019                    }
1020    
1021                    List<SocialActivitySetting> list = q.list();
1022    
1023                    if (list.size() == 2) {
1024                            return list.get(1);
1025                    }
1026                    else {
1027                            return null;
1028                    }
1029            }
1030    
1031            /**
1032             * Returns all the social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1033             *
1034             * @param groupId the group ID
1035             * @param classNameId the class name ID
1036             * @param activityType the activity type
1037             * @return the matching social activity settings
1038             * @throws SystemException if a system exception occurred
1039             */
1040            public List<SocialActivitySetting> findByG_C_A(long groupId,
1041                    long classNameId, int activityType) throws SystemException {
1042                    return findByG_C_A(groupId, classNameId, activityType,
1043                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1044            }
1045    
1046            /**
1047             * Returns a range of all the social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1048             *
1049             * <p>
1050             * 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.
1051             * </p>
1052             *
1053             * @param groupId the group ID
1054             * @param classNameId the class name ID
1055             * @param activityType the activity type
1056             * @param start the lower bound of the range of social activity settings
1057             * @param end the upper bound of the range of social activity settings (not inclusive)
1058             * @return the range of matching social activity settings
1059             * @throws SystemException if a system exception occurred
1060             */
1061            public List<SocialActivitySetting> findByG_C_A(long groupId,
1062                    long classNameId, int activityType, int start, int end)
1063                    throws SystemException {
1064                    return findByG_C_A(groupId, classNameId, activityType, start, end, null);
1065            }
1066    
1067            /**
1068             * Returns an ordered range of all the social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1069             *
1070             * <p>
1071             * 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.
1072             * </p>
1073             *
1074             * @param groupId the group ID
1075             * @param classNameId the class name ID
1076             * @param activityType the activity type
1077             * @param start the lower bound of the range of social activity settings
1078             * @param end the upper bound of the range of social activity settings (not inclusive)
1079             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1080             * @return the ordered range of matching social activity settings
1081             * @throws SystemException if a system exception occurred
1082             */
1083            public List<SocialActivitySetting> findByG_C_A(long groupId,
1084                    long classNameId, int activityType, int start, int end,
1085                    OrderByComparator orderByComparator) throws SystemException {
1086                    FinderPath finderPath = null;
1087                    Object[] finderArgs = null;
1088    
1089                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1090                                    (orderByComparator == null)) {
1091                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_A;
1092                            finderArgs = new Object[] { groupId, classNameId, activityType };
1093                    }
1094                    else {
1095                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_A;
1096                            finderArgs = new Object[] {
1097                                            groupId, classNameId, activityType,
1098                                            
1099                                            start, end, orderByComparator
1100                                    };
1101                    }
1102    
1103                    List<SocialActivitySetting> list = (List<SocialActivitySetting>)FinderCacheUtil.getResult(finderPath,
1104                                    finderArgs, this);
1105    
1106                    if ((list != null) && !list.isEmpty()) {
1107                            for (SocialActivitySetting socialActivitySetting : list) {
1108                                    if ((groupId != socialActivitySetting.getGroupId()) ||
1109                                                    (classNameId != socialActivitySetting.getClassNameId()) ||
1110                                                    (activityType != socialActivitySetting.getActivityType())) {
1111                                            list = null;
1112    
1113                                            break;
1114                                    }
1115                            }
1116                    }
1117    
1118                    if (list == null) {
1119                            StringBundler query = null;
1120    
1121                            if (orderByComparator != null) {
1122                                    query = new StringBundler(5 +
1123                                                    (orderByComparator.getOrderByFields().length * 3));
1124                            }
1125                            else {
1126                                    query = new StringBundler(4);
1127                            }
1128    
1129                            query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
1130    
1131                            query.append(_FINDER_COLUMN_G_C_A_GROUPID_2);
1132    
1133                            query.append(_FINDER_COLUMN_G_C_A_CLASSNAMEID_2);
1134    
1135                            query.append(_FINDER_COLUMN_G_C_A_ACTIVITYTYPE_2);
1136    
1137                            if (orderByComparator != null) {
1138                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1139                                            orderByComparator);
1140                            }
1141    
1142                            String sql = query.toString();
1143    
1144                            Session session = null;
1145    
1146                            try {
1147                                    session = openSession();
1148    
1149                                    Query q = session.createQuery(sql);
1150    
1151                                    QueryPos qPos = QueryPos.getInstance(q);
1152    
1153                                    qPos.add(groupId);
1154    
1155                                    qPos.add(classNameId);
1156    
1157                                    qPos.add(activityType);
1158    
1159                                    list = (List<SocialActivitySetting>)QueryUtil.list(q,
1160                                                    getDialect(), start, end);
1161                            }
1162                            catch (Exception e) {
1163                                    throw processException(e);
1164                            }
1165                            finally {
1166                                    if (list == null) {
1167                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1168                                    }
1169                                    else {
1170                                            cacheResult(list);
1171    
1172                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1173                                    }
1174    
1175                                    closeSession(session);
1176                            }
1177                    }
1178    
1179                    return list;
1180            }
1181    
1182            /**
1183             * Returns the first social activity setting in the ordered set where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1184             *
1185             * @param groupId the group ID
1186             * @param classNameId the class name ID
1187             * @param activityType the activity type
1188             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1189             * @return the first matching social activity setting
1190             * @throws com.liferay.portlet.social.NoSuchActivitySettingException if a matching social activity setting could not be found
1191             * @throws SystemException if a system exception occurred
1192             */
1193            public SocialActivitySetting findByG_C_A_First(long groupId,
1194                    long classNameId, int activityType, OrderByComparator orderByComparator)
1195                    throws NoSuchActivitySettingException, SystemException {
1196                    SocialActivitySetting socialActivitySetting = fetchByG_C_A_First(groupId,
1197                                    classNameId, activityType, orderByComparator);
1198    
1199                    if (socialActivitySetting != null) {
1200                            return socialActivitySetting;
1201                    }
1202    
1203                    StringBundler msg = new StringBundler(8);
1204    
1205                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1206    
1207                    msg.append("groupId=");
1208                    msg.append(groupId);
1209    
1210                    msg.append(", classNameId=");
1211                    msg.append(classNameId);
1212    
1213                    msg.append(", activityType=");
1214                    msg.append(activityType);
1215    
1216                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1217    
1218                    throw new NoSuchActivitySettingException(msg.toString());
1219            }
1220    
1221            /**
1222             * Returns the first social activity setting in the ordered set where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1223             *
1224             * @param groupId the group ID
1225             * @param classNameId the class name ID
1226             * @param activityType the activity type
1227             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1228             * @return the first matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
1229             * @throws SystemException if a system exception occurred
1230             */
1231            public SocialActivitySetting fetchByG_C_A_First(long groupId,
1232                    long classNameId, int activityType, OrderByComparator orderByComparator)
1233                    throws SystemException {
1234                    List<SocialActivitySetting> list = findByG_C_A(groupId, classNameId,
1235                                    activityType, 0, 1, orderByComparator);
1236    
1237                    if (!list.isEmpty()) {
1238                            return list.get(0);
1239                    }
1240    
1241                    return null;
1242            }
1243    
1244            /**
1245             * Returns the last social activity setting in the ordered set where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1246             *
1247             * @param groupId the group ID
1248             * @param classNameId the class name ID
1249             * @param activityType the activity type
1250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1251             * @return the last matching social activity setting
1252             * @throws com.liferay.portlet.social.NoSuchActivitySettingException if a matching social activity setting could not be found
1253             * @throws SystemException if a system exception occurred
1254             */
1255            public SocialActivitySetting findByG_C_A_Last(long groupId,
1256                    long classNameId, int activityType, OrderByComparator orderByComparator)
1257                    throws NoSuchActivitySettingException, SystemException {
1258                    SocialActivitySetting socialActivitySetting = fetchByG_C_A_Last(groupId,
1259                                    classNameId, activityType, orderByComparator);
1260    
1261                    if (socialActivitySetting != null) {
1262                            return socialActivitySetting;
1263                    }
1264    
1265                    StringBundler msg = new StringBundler(8);
1266    
1267                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1268    
1269                    msg.append("groupId=");
1270                    msg.append(groupId);
1271    
1272                    msg.append(", classNameId=");
1273                    msg.append(classNameId);
1274    
1275                    msg.append(", activityType=");
1276                    msg.append(activityType);
1277    
1278                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1279    
1280                    throw new NoSuchActivitySettingException(msg.toString());
1281            }
1282    
1283            /**
1284             * Returns the last social activity setting in the ordered set where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1285             *
1286             * @param groupId the group ID
1287             * @param classNameId the class name ID
1288             * @param activityType the activity type
1289             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1290             * @return the last matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
1291             * @throws SystemException if a system exception occurred
1292             */
1293            public SocialActivitySetting fetchByG_C_A_Last(long groupId,
1294                    long classNameId, int activityType, OrderByComparator orderByComparator)
1295                    throws SystemException {
1296                    int count = countByG_C_A(groupId, classNameId, activityType);
1297    
1298                    List<SocialActivitySetting> list = findByG_C_A(groupId, classNameId,
1299                                    activityType, count - 1, count, orderByComparator);
1300    
1301                    if (!list.isEmpty()) {
1302                            return list.get(0);
1303                    }
1304    
1305                    return null;
1306            }
1307    
1308            /**
1309             * 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;.
1310             *
1311             * @param activitySettingId the primary key of the current social activity setting
1312             * @param groupId the group ID
1313             * @param classNameId the class name ID
1314             * @param activityType the activity type
1315             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1316             * @return the previous, current, and next social activity setting
1317             * @throws com.liferay.portlet.social.NoSuchActivitySettingException if a social activity setting with the primary key could not be found
1318             * @throws SystemException if a system exception occurred
1319             */
1320            public SocialActivitySetting[] findByG_C_A_PrevAndNext(
1321                    long activitySettingId, long groupId, long classNameId,
1322                    int activityType, OrderByComparator orderByComparator)
1323                    throws NoSuchActivitySettingException, SystemException {
1324                    SocialActivitySetting socialActivitySetting = findByPrimaryKey(activitySettingId);
1325    
1326                    Session session = null;
1327    
1328                    try {
1329                            session = openSession();
1330    
1331                            SocialActivitySetting[] array = new SocialActivitySettingImpl[3];
1332    
1333                            array[0] = getByG_C_A_PrevAndNext(session, socialActivitySetting,
1334                                            groupId, classNameId, activityType, orderByComparator, true);
1335    
1336                            array[1] = socialActivitySetting;
1337    
1338                            array[2] = getByG_C_A_PrevAndNext(session, socialActivitySetting,
1339                                            groupId, classNameId, activityType, orderByComparator, false);
1340    
1341                            return array;
1342                    }
1343                    catch (Exception e) {
1344                            throw processException(e);
1345                    }
1346                    finally {
1347                            closeSession(session);
1348                    }
1349            }
1350    
1351            protected SocialActivitySetting getByG_C_A_PrevAndNext(Session session,
1352                    SocialActivitySetting socialActivitySetting, long groupId,
1353                    long classNameId, int activityType,
1354                    OrderByComparator orderByComparator, boolean previous) {
1355                    StringBundler query = null;
1356    
1357                    if (orderByComparator != null) {
1358                            query = new StringBundler(6 +
1359                                            (orderByComparator.getOrderByFields().length * 6));
1360                    }
1361                    else {
1362                            query = new StringBundler(3);
1363                    }
1364    
1365                    query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
1366    
1367                    query.append(_FINDER_COLUMN_G_C_A_GROUPID_2);
1368    
1369                    query.append(_FINDER_COLUMN_G_C_A_CLASSNAMEID_2);
1370    
1371                    query.append(_FINDER_COLUMN_G_C_A_ACTIVITYTYPE_2);
1372    
1373                    if (orderByComparator != null) {
1374                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1375    
1376                            if (orderByConditionFields.length > 0) {
1377                                    query.append(WHERE_AND);
1378                            }
1379    
1380                            for (int i = 0; i < orderByConditionFields.length; i++) {
1381                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1382                                    query.append(orderByConditionFields[i]);
1383    
1384                                    if ((i + 1) < orderByConditionFields.length) {
1385                                            if (orderByComparator.isAscending() ^ previous) {
1386                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1387                                            }
1388                                            else {
1389                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1390                                            }
1391                                    }
1392                                    else {
1393                                            if (orderByComparator.isAscending() ^ previous) {
1394                                                    query.append(WHERE_GREATER_THAN);
1395                                            }
1396                                            else {
1397                                                    query.append(WHERE_LESSER_THAN);
1398                                            }
1399                                    }
1400                            }
1401    
1402                            query.append(ORDER_BY_CLAUSE);
1403    
1404                            String[] orderByFields = orderByComparator.getOrderByFields();
1405    
1406                            for (int i = 0; i < orderByFields.length; i++) {
1407                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1408                                    query.append(orderByFields[i]);
1409    
1410                                    if ((i + 1) < orderByFields.length) {
1411                                            if (orderByComparator.isAscending() ^ previous) {
1412                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1413                                            }
1414                                            else {
1415                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1416                                            }
1417                                    }
1418                                    else {
1419                                            if (orderByComparator.isAscending() ^ previous) {
1420                                                    query.append(ORDER_BY_ASC);
1421                                            }
1422                                            else {
1423                                                    query.append(ORDER_BY_DESC);
1424                                            }
1425                                    }
1426                            }
1427                    }
1428    
1429                    String sql = query.toString();
1430    
1431                    Query q = session.createQuery(sql);
1432    
1433                    q.setFirstResult(0);
1434                    q.setMaxResults(2);
1435    
1436                    QueryPos qPos = QueryPos.getInstance(q);
1437    
1438                    qPos.add(groupId);
1439    
1440                    qPos.add(classNameId);
1441    
1442                    qPos.add(activityType);
1443    
1444                    if (orderByComparator != null) {
1445                            Object[] values = orderByComparator.getOrderByConditionValues(socialActivitySetting);
1446    
1447                            for (Object value : values) {
1448                                    qPos.add(value);
1449                            }
1450                    }
1451    
1452                    List<SocialActivitySetting> list = q.list();
1453    
1454                    if (list.size() == 2) {
1455                            return list.get(1);
1456                    }
1457                    else {
1458                            return null;
1459                    }
1460            }
1461    
1462            /**
1463             * 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.
1464             *
1465             * @param groupId the group ID
1466             * @param classNameId the class name ID
1467             * @param activityType the activity type
1468             * @param name the name
1469             * @return the matching social activity setting
1470             * @throws com.liferay.portlet.social.NoSuchActivitySettingException if a matching social activity setting could not be found
1471             * @throws SystemException if a system exception occurred
1472             */
1473            public SocialActivitySetting findByG_C_A_N(long groupId, long classNameId,
1474                    int activityType, String name)
1475                    throws NoSuchActivitySettingException, SystemException {
1476                    SocialActivitySetting socialActivitySetting = fetchByG_C_A_N(groupId,
1477                                    classNameId, activityType, name);
1478    
1479                    if (socialActivitySetting == null) {
1480                            StringBundler msg = new StringBundler(10);
1481    
1482                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1483    
1484                            msg.append("groupId=");
1485                            msg.append(groupId);
1486    
1487                            msg.append(", classNameId=");
1488                            msg.append(classNameId);
1489    
1490                            msg.append(", activityType=");
1491                            msg.append(activityType);
1492    
1493                            msg.append(", name=");
1494                            msg.append(name);
1495    
1496                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1497    
1498                            if (_log.isWarnEnabled()) {
1499                                    _log.warn(msg.toString());
1500                            }
1501    
1502                            throw new NoSuchActivitySettingException(msg.toString());
1503                    }
1504    
1505                    return socialActivitySetting;
1506            }
1507    
1508            /**
1509             * 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.
1510             *
1511             * @param groupId the group ID
1512             * @param classNameId the class name ID
1513             * @param activityType the activity type
1514             * @param name the name
1515             * @return the matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
1516             * @throws SystemException if a system exception occurred
1517             */
1518            public SocialActivitySetting fetchByG_C_A_N(long groupId, long classNameId,
1519                    int activityType, String name) throws SystemException {
1520                    return fetchByG_C_A_N(groupId, classNameId, activityType, name, true);
1521            }
1522    
1523            /**
1524             * 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.
1525             *
1526             * @param groupId the group ID
1527             * @param classNameId the class name ID
1528             * @param activityType the activity type
1529             * @param name the name
1530             * @param retrieveFromCache whether to use the finder cache
1531             * @return the matching social activity setting, or <code>null</code> if a matching social activity setting could not be found
1532             * @throws SystemException if a system exception occurred
1533             */
1534            public SocialActivitySetting fetchByG_C_A_N(long groupId, long classNameId,
1535                    int activityType, String name, boolean retrieveFromCache)
1536                    throws SystemException {
1537                    Object[] finderArgs = new Object[] {
1538                                    groupId, classNameId, activityType, name
1539                            };
1540    
1541                    Object result = null;
1542    
1543                    if (retrieveFromCache) {
1544                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_A_N,
1545                                            finderArgs, this);
1546                    }
1547    
1548                    if (result instanceof SocialActivitySetting) {
1549                            SocialActivitySetting socialActivitySetting = (SocialActivitySetting)result;
1550    
1551                            if ((groupId != socialActivitySetting.getGroupId()) ||
1552                                            (classNameId != socialActivitySetting.getClassNameId()) ||
1553                                            (activityType != socialActivitySetting.getActivityType()) ||
1554                                            !Validator.equals(name, socialActivitySetting.getName())) {
1555                                    result = null;
1556                            }
1557                    }
1558    
1559                    if (result == null) {
1560                            StringBundler query = new StringBundler(5);
1561    
1562                            query.append(_SQL_SELECT_SOCIALACTIVITYSETTING_WHERE);
1563    
1564                            query.append(_FINDER_COLUMN_G_C_A_N_GROUPID_2);
1565    
1566                            query.append(_FINDER_COLUMN_G_C_A_N_CLASSNAMEID_2);
1567    
1568                            query.append(_FINDER_COLUMN_G_C_A_N_ACTIVITYTYPE_2);
1569    
1570                            if (name == null) {
1571                                    query.append(_FINDER_COLUMN_G_C_A_N_NAME_1);
1572                            }
1573                            else {
1574                                    if (name.equals(StringPool.BLANK)) {
1575                                            query.append(_FINDER_COLUMN_G_C_A_N_NAME_3);
1576                                    }
1577                                    else {
1578                                            query.append(_FINDER_COLUMN_G_C_A_N_NAME_2);
1579                                    }
1580                            }
1581    
1582                            String sql = query.toString();
1583    
1584                            Session session = null;
1585    
1586                            try {
1587                                    session = openSession();
1588    
1589                                    Query q = session.createQuery(sql);
1590    
1591                                    QueryPos qPos = QueryPos.getInstance(q);
1592    
1593                                    qPos.add(groupId);
1594    
1595                                    qPos.add(classNameId);
1596    
1597                                    qPos.add(activityType);
1598    
1599                                    if (name != null) {
1600                                            qPos.add(name);
1601                                    }
1602    
1603                                    List<SocialActivitySetting> list = q.list();
1604    
1605                                    result = list;
1606    
1607                                    SocialActivitySetting socialActivitySetting = null;
1608    
1609                                    if (list.isEmpty()) {
1610                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_A_N,
1611                                                    finderArgs, list);
1612                                    }
1613                                    else {
1614                                            socialActivitySetting = list.get(0);
1615    
1616                                            cacheResult(socialActivitySetting);
1617    
1618                                            if ((socialActivitySetting.getGroupId() != groupId) ||
1619                                                            (socialActivitySetting.getClassNameId() != classNameId) ||
1620                                                            (socialActivitySetting.getActivityType() != activityType) ||
1621                                                            (socialActivitySetting.getName() == null) ||
1622                                                            !socialActivitySetting.getName().equals(name)) {
1623                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_A_N,
1624                                                            finderArgs, socialActivitySetting);
1625                                            }
1626                                    }
1627    
1628                                    return socialActivitySetting;
1629                            }
1630                            catch (Exception e) {
1631                                    throw processException(e);
1632                            }
1633                            finally {
1634                                    if (result == null) {
1635                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_A_N,
1636                                                    finderArgs);
1637                                    }
1638    
1639                                    closeSession(session);
1640                            }
1641                    }
1642                    else {
1643                            if (result instanceof List<?>) {
1644                                    return null;
1645                            }
1646                            else {
1647                                    return (SocialActivitySetting)result;
1648                            }
1649                    }
1650            }
1651    
1652            /**
1653             * Returns all the social activity settings.
1654             *
1655             * @return the social activity settings
1656             * @throws SystemException if a system exception occurred
1657             */
1658            public List<SocialActivitySetting> findAll() throws SystemException {
1659                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1660            }
1661    
1662            /**
1663             * Returns a range of all the social activity settings.
1664             *
1665             * <p>
1666             * 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.
1667             * </p>
1668             *
1669             * @param start the lower bound of the range of social activity settings
1670             * @param end the upper bound of the range of social activity settings (not inclusive)
1671             * @return the range of social activity settings
1672             * @throws SystemException if a system exception occurred
1673             */
1674            public List<SocialActivitySetting> findAll(int start, int end)
1675                    throws SystemException {
1676                    return findAll(start, end, null);
1677            }
1678    
1679            /**
1680             * Returns an ordered range of all the social activity settings.
1681             *
1682             * <p>
1683             * 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.
1684             * </p>
1685             *
1686             * @param start the lower bound of the range of social activity settings
1687             * @param end the upper bound of the range of social activity settings (not inclusive)
1688             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1689             * @return the ordered range of social activity settings
1690             * @throws SystemException if a system exception occurred
1691             */
1692            public List<SocialActivitySetting> findAll(int start, int end,
1693                    OrderByComparator orderByComparator) throws SystemException {
1694                    FinderPath finderPath = null;
1695                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1696    
1697                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1698                                    (orderByComparator == null)) {
1699                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1700                            finderArgs = FINDER_ARGS_EMPTY;
1701                    }
1702                    else {
1703                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1704                            finderArgs = new Object[] { start, end, orderByComparator };
1705                    }
1706    
1707                    List<SocialActivitySetting> list = (List<SocialActivitySetting>)FinderCacheUtil.getResult(finderPath,
1708                                    finderArgs, this);
1709    
1710                    if (list == null) {
1711                            StringBundler query = null;
1712                            String sql = null;
1713    
1714                            if (orderByComparator != null) {
1715                                    query = new StringBundler(2 +
1716                                                    (orderByComparator.getOrderByFields().length * 3));
1717    
1718                                    query.append(_SQL_SELECT_SOCIALACTIVITYSETTING);
1719    
1720                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1721                                            orderByComparator);
1722    
1723                                    sql = query.toString();
1724                            }
1725                            else {
1726                                    sql = _SQL_SELECT_SOCIALACTIVITYSETTING;
1727                            }
1728    
1729                            Session session = null;
1730    
1731                            try {
1732                                    session = openSession();
1733    
1734                                    Query q = session.createQuery(sql);
1735    
1736                                    if (orderByComparator == null) {
1737                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
1738                                                            getDialect(), start, end, false);
1739    
1740                                            Collections.sort(list);
1741                                    }
1742                                    else {
1743                                            list = (List<SocialActivitySetting>)QueryUtil.list(q,
1744                                                            getDialect(), start, end);
1745                                    }
1746                            }
1747                            catch (Exception e) {
1748                                    throw processException(e);
1749                            }
1750                            finally {
1751                                    if (list == null) {
1752                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1753                                    }
1754                                    else {
1755                                            cacheResult(list);
1756    
1757                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1758                                    }
1759    
1760                                    closeSession(session);
1761                            }
1762                    }
1763    
1764                    return list;
1765            }
1766    
1767            /**
1768             * Removes all the social activity settings where groupId = &#63; and activityType = &#63; from the database.
1769             *
1770             * @param groupId the group ID
1771             * @param activityType the activity type
1772             * @throws SystemException if a system exception occurred
1773             */
1774            public void removeByG_A(long groupId, int activityType)
1775                    throws SystemException {
1776                    for (SocialActivitySetting socialActivitySetting : findByG_A(groupId,
1777                                    activityType)) {
1778                            remove(socialActivitySetting);
1779                    }
1780            }
1781    
1782            /**
1783             * Removes all the social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63; from the database.
1784             *
1785             * @param groupId the group ID
1786             * @param classNameId the class name ID
1787             * @param activityType the activity type
1788             * @throws SystemException if a system exception occurred
1789             */
1790            public void removeByG_C_A(long groupId, long classNameId, int activityType)
1791                    throws SystemException {
1792                    for (SocialActivitySetting socialActivitySetting : findByG_C_A(
1793                                    groupId, classNameId, activityType)) {
1794                            remove(socialActivitySetting);
1795                    }
1796            }
1797    
1798            /**
1799             * Removes the social activity setting where groupId = &#63; and classNameId = &#63; and activityType = &#63; and name = &#63; from the database.
1800             *
1801             * @param groupId the group ID
1802             * @param classNameId the class name ID
1803             * @param activityType the activity type
1804             * @param name the name
1805             * @return the social activity setting that was removed
1806             * @throws SystemException if a system exception occurred
1807             */
1808            public SocialActivitySetting removeByG_C_A_N(long groupId,
1809                    long classNameId, int activityType, String name)
1810                    throws NoSuchActivitySettingException, SystemException {
1811                    SocialActivitySetting socialActivitySetting = findByG_C_A_N(groupId,
1812                                    classNameId, activityType, name);
1813    
1814                    return remove(socialActivitySetting);
1815            }
1816    
1817            /**
1818             * Removes all the social activity settings from the database.
1819             *
1820             * @throws SystemException if a system exception occurred
1821             */
1822            public void removeAll() throws SystemException {
1823                    for (SocialActivitySetting socialActivitySetting : findAll()) {
1824                            remove(socialActivitySetting);
1825                    }
1826            }
1827    
1828            /**
1829             * Returns the number of social activity settings where groupId = &#63; and activityType = &#63;.
1830             *
1831             * @param groupId the group ID
1832             * @param activityType the activity type
1833             * @return the number of matching social activity settings
1834             * @throws SystemException if a system exception occurred
1835             */
1836            public int countByG_A(long groupId, int activityType)
1837                    throws SystemException {
1838                    Object[] finderArgs = new Object[] { groupId, activityType };
1839    
1840                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_A,
1841                                    finderArgs, this);
1842    
1843                    if (count == null) {
1844                            StringBundler query = new StringBundler(3);
1845    
1846                            query.append(_SQL_COUNT_SOCIALACTIVITYSETTING_WHERE);
1847    
1848                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
1849    
1850                            query.append(_FINDER_COLUMN_G_A_ACTIVITYTYPE_2);
1851    
1852                            String sql = query.toString();
1853    
1854                            Session session = null;
1855    
1856                            try {
1857                                    session = openSession();
1858    
1859                                    Query q = session.createQuery(sql);
1860    
1861                                    QueryPos qPos = QueryPos.getInstance(q);
1862    
1863                                    qPos.add(groupId);
1864    
1865                                    qPos.add(activityType);
1866    
1867                                    count = (Long)q.uniqueResult();
1868                            }
1869                            catch (Exception e) {
1870                                    throw processException(e);
1871                            }
1872                            finally {
1873                                    if (count == null) {
1874                                            count = Long.valueOf(0);
1875                                    }
1876    
1877                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A, finderArgs,
1878                                            count);
1879    
1880                                    closeSession(session);
1881                            }
1882                    }
1883    
1884                    return count.intValue();
1885            }
1886    
1887            /**
1888             * Returns the number of social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63;.
1889             *
1890             * @param groupId the group ID
1891             * @param classNameId the class name ID
1892             * @param activityType the activity type
1893             * @return the number of matching social activity settings
1894             * @throws SystemException if a system exception occurred
1895             */
1896            public int countByG_C_A(long groupId, long classNameId, int activityType)
1897                    throws SystemException {
1898                    Object[] finderArgs = new Object[] { groupId, classNameId, activityType };
1899    
1900                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_A,
1901                                    finderArgs, this);
1902    
1903                    if (count == null) {
1904                            StringBundler query = new StringBundler(4);
1905    
1906                            query.append(_SQL_COUNT_SOCIALACTIVITYSETTING_WHERE);
1907    
1908                            query.append(_FINDER_COLUMN_G_C_A_GROUPID_2);
1909    
1910                            query.append(_FINDER_COLUMN_G_C_A_CLASSNAMEID_2);
1911    
1912                            query.append(_FINDER_COLUMN_G_C_A_ACTIVITYTYPE_2);
1913    
1914                            String sql = query.toString();
1915    
1916                            Session session = null;
1917    
1918                            try {
1919                                    session = openSession();
1920    
1921                                    Query q = session.createQuery(sql);
1922    
1923                                    QueryPos qPos = QueryPos.getInstance(q);
1924    
1925                                    qPos.add(groupId);
1926    
1927                                    qPos.add(classNameId);
1928    
1929                                    qPos.add(activityType);
1930    
1931                                    count = (Long)q.uniqueResult();
1932                            }
1933                            catch (Exception e) {
1934                                    throw processException(e);
1935                            }
1936                            finally {
1937                                    if (count == null) {
1938                                            count = Long.valueOf(0);
1939                                    }
1940    
1941                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_A,
1942                                            finderArgs, count);
1943    
1944                                    closeSession(session);
1945                            }
1946                    }
1947    
1948                    return count.intValue();
1949            }
1950    
1951            /**
1952             * Returns the number of social activity settings where groupId = &#63; and classNameId = &#63; and activityType = &#63; and name = &#63;.
1953             *
1954             * @param groupId the group ID
1955             * @param classNameId the class name ID
1956             * @param activityType the activity type
1957             * @param name the name
1958             * @return the number of matching social activity settings
1959             * @throws SystemException if a system exception occurred
1960             */
1961            public int countByG_C_A_N(long groupId, long classNameId, int activityType,
1962                    String name) throws SystemException {
1963                    Object[] finderArgs = new Object[] {
1964                                    groupId, classNameId, activityType, name
1965                            };
1966    
1967                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_A_N,
1968                                    finderArgs, this);
1969    
1970                    if (count == null) {
1971                            StringBundler query = new StringBundler(5);
1972    
1973                            query.append(_SQL_COUNT_SOCIALACTIVITYSETTING_WHERE);
1974    
1975                            query.append(_FINDER_COLUMN_G_C_A_N_GROUPID_2);
1976    
1977                            query.append(_FINDER_COLUMN_G_C_A_N_CLASSNAMEID_2);
1978    
1979                            query.append(_FINDER_COLUMN_G_C_A_N_ACTIVITYTYPE_2);
1980    
1981                            if (name == null) {
1982                                    query.append(_FINDER_COLUMN_G_C_A_N_NAME_1);
1983                            }
1984                            else {
1985                                    if (name.equals(StringPool.BLANK)) {
1986                                            query.append(_FINDER_COLUMN_G_C_A_N_NAME_3);
1987                                    }
1988                                    else {
1989                                            query.append(_FINDER_COLUMN_G_C_A_N_NAME_2);
1990                                    }
1991                            }
1992    
1993                            String sql = query.toString();
1994    
1995                            Session session = null;
1996    
1997                            try {
1998                                    session = openSession();
1999    
2000                                    Query q = session.createQuery(sql);
2001    
2002                                    QueryPos qPos = QueryPos.getInstance(q);
2003    
2004                                    qPos.add(groupId);
2005    
2006                                    qPos.add(classNameId);
2007    
2008                                    qPos.add(activityType);
2009    
2010                                    if (name != null) {
2011                                            qPos.add(name);
2012                                    }
2013    
2014                                    count = (Long)q.uniqueResult();
2015                            }
2016                            catch (Exception e) {
2017                                    throw processException(e);
2018                            }
2019                            finally {
2020                                    if (count == null) {
2021                                            count = Long.valueOf(0);
2022                                    }
2023    
2024                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_A_N,
2025                                            finderArgs, count);
2026    
2027                                    closeSession(session);
2028                            }
2029                    }
2030    
2031                    return count.intValue();
2032            }
2033    
2034            /**
2035             * Returns the number of social activity settings.
2036             *
2037             * @return the number of social activity settings
2038             * @throws SystemException if a system exception occurred
2039             */
2040            public int countAll() throws SystemException {
2041                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2042                                    FINDER_ARGS_EMPTY, this);
2043    
2044                    if (count == null) {
2045                            Session session = null;
2046    
2047                            try {
2048                                    session = openSession();
2049    
2050                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYSETTING);
2051    
2052                                    count = (Long)q.uniqueResult();
2053                            }
2054                            catch (Exception e) {
2055                                    throw processException(e);
2056                            }
2057                            finally {
2058                                    if (count == null) {
2059                                            count = Long.valueOf(0);
2060                                    }
2061    
2062                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2063                                            FINDER_ARGS_EMPTY, count);
2064    
2065                                    closeSession(session);
2066                            }
2067                    }
2068    
2069                    return count.intValue();
2070            }
2071    
2072            /**
2073             * Initializes the social activity setting persistence.
2074             */
2075            public void afterPropertiesSet() {
2076                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2077                                            com.liferay.portal.util.PropsUtil.get(
2078                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivitySetting")));
2079    
2080                    if (listenerClassNames.length > 0) {
2081                            try {
2082                                    List<ModelListener<SocialActivitySetting>> listenersList = new ArrayList<ModelListener<SocialActivitySetting>>();
2083    
2084                                    for (String listenerClassName : listenerClassNames) {
2085                                            Class<?> clazz = getClass();
2086    
2087                                            listenersList.add((ModelListener<SocialActivitySetting>)InstanceFactory.newInstance(
2088                                                            clazz.getClassLoader(), listenerClassName));
2089                                    }
2090    
2091                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2092                            }
2093                            catch (Exception e) {
2094                                    _log.error(e);
2095                            }
2096                    }
2097            }
2098    
2099            public void destroy() {
2100                    EntityCacheUtil.removeCache(SocialActivitySettingImpl.class.getName());
2101                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2102                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2103            }
2104    
2105            @BeanReference(type = SocialActivityPersistence.class)
2106            protected SocialActivityPersistence socialActivityPersistence;
2107            @BeanReference(type = SocialActivityAchievementPersistence.class)
2108            protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
2109            @BeanReference(type = SocialActivityCounterPersistence.class)
2110            protected SocialActivityCounterPersistence socialActivityCounterPersistence;
2111            @BeanReference(type = SocialActivityLimitPersistence.class)
2112            protected SocialActivityLimitPersistence socialActivityLimitPersistence;
2113            @BeanReference(type = SocialActivitySettingPersistence.class)
2114            protected SocialActivitySettingPersistence socialActivitySettingPersistence;
2115            @BeanReference(type = SocialRelationPersistence.class)
2116            protected SocialRelationPersistence socialRelationPersistence;
2117            @BeanReference(type = SocialRequestPersistence.class)
2118            protected SocialRequestPersistence socialRequestPersistence;
2119            @BeanReference(type = GroupPersistence.class)
2120            protected GroupPersistence groupPersistence;
2121            @BeanReference(type = ResourcePersistence.class)
2122            protected ResourcePersistence resourcePersistence;
2123            @BeanReference(type = UserPersistence.class)
2124            protected UserPersistence userPersistence;
2125            private static final String _SQL_SELECT_SOCIALACTIVITYSETTING = "SELECT socialActivitySetting FROM SocialActivitySetting socialActivitySetting";
2126            private static final String _SQL_SELECT_SOCIALACTIVITYSETTING_WHERE = "SELECT socialActivitySetting FROM SocialActivitySetting socialActivitySetting WHERE ";
2127            private static final String _SQL_COUNT_SOCIALACTIVITYSETTING = "SELECT COUNT(socialActivitySetting) FROM SocialActivitySetting socialActivitySetting";
2128            private static final String _SQL_COUNT_SOCIALACTIVITYSETTING_WHERE = "SELECT COUNT(socialActivitySetting) FROM SocialActivitySetting socialActivitySetting WHERE ";
2129            private static final String _FINDER_COLUMN_G_A_GROUPID_2 = "socialActivitySetting.groupId = ? AND ";
2130            private static final String _FINDER_COLUMN_G_A_ACTIVITYTYPE_2 = "socialActivitySetting.activityType = ?";
2131            private static final String _FINDER_COLUMN_G_C_A_GROUPID_2 = "socialActivitySetting.groupId = ? AND ";
2132            private static final String _FINDER_COLUMN_G_C_A_CLASSNAMEID_2 = "socialActivitySetting.classNameId = ? AND ";
2133            private static final String _FINDER_COLUMN_G_C_A_ACTIVITYTYPE_2 = "socialActivitySetting.activityType = ?";
2134            private static final String _FINDER_COLUMN_G_C_A_N_GROUPID_2 = "socialActivitySetting.groupId = ? AND ";
2135            private static final String _FINDER_COLUMN_G_C_A_N_CLASSNAMEID_2 = "socialActivitySetting.classNameId = ? AND ";
2136            private static final String _FINDER_COLUMN_G_C_A_N_ACTIVITYTYPE_2 = "socialActivitySetting.activityType = ? AND ";
2137            private static final String _FINDER_COLUMN_G_C_A_N_NAME_1 = "socialActivitySetting.name IS NULL";
2138            private static final String _FINDER_COLUMN_G_C_A_N_NAME_2 = "socialActivitySetting.name = ?";
2139            private static final String _FINDER_COLUMN_G_C_A_N_NAME_3 = "(socialActivitySetting.name IS NULL OR socialActivitySetting.name = ?)";
2140            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivitySetting.";
2141            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivitySetting exists with the primary key ";
2142            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialActivitySetting exists with the key {";
2143            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2144            private static Log _log = LogFactoryUtil.getLog(SocialActivitySettingPersistenceImpl.class);
2145            private static SocialActivitySetting _nullSocialActivitySetting = new SocialActivitySettingImpl() {
2146                            @Override
2147                            public Object clone() {
2148                                    return this;
2149                            }
2150    
2151                            @Override
2152                            public CacheModel<SocialActivitySetting> toCacheModel() {
2153                                    return _nullSocialActivitySettingCacheModel;
2154                            }
2155                    };
2156    
2157            private static CacheModel<SocialActivitySetting> _nullSocialActivitySettingCacheModel =
2158                    new CacheModel<SocialActivitySetting>() {
2159                            public SocialActivitySetting toEntityModel() {
2160                                    return _nullSocialActivitySetting;
2161                            }
2162                    };
2163    }