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