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