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