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