001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryUtil;
023    import com.liferay.portal.kernel.dao.orm.Session;
024    import com.liferay.portal.kernel.exception.SystemException;
025    import com.liferay.portal.kernel.log.Log;
026    import com.liferay.portal.kernel.log.LogFactoryUtil;
027    import com.liferay.portal.kernel.util.GetterUtil;
028    import com.liferay.portal.kernel.util.InstanceFactory;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.StringBundler;
031    import com.liferay.portal.kernel.util.StringUtil;
032    import com.liferay.portal.kernel.util.UnmodifiableList;
033    import com.liferay.portal.model.CacheModel;
034    import com.liferay.portal.model.ModelListener;
035    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
036    
037    import com.liferay.portlet.social.NoSuchActivitySetException;
038    import com.liferay.portlet.social.model.SocialActivitySet;
039    import com.liferay.portlet.social.model.impl.SocialActivitySetImpl;
040    import com.liferay.portlet.social.model.impl.SocialActivitySetModelImpl;
041    
042    import java.io.Serializable;
043    
044    import java.util.ArrayList;
045    import java.util.Collections;
046    import java.util.List;
047    
048    /**
049     * The persistence implementation for the social activity set service.
050     *
051     * <p>
052     * Caching information and settings can be found in <code>portal.properties</code>
053     * </p>
054     *
055     * @author Brian Wing Shun Chan
056     * @see SocialActivitySetPersistence
057     * @see SocialActivitySetUtil
058     * @generated
059     */
060    public class SocialActivitySetPersistenceImpl extends BasePersistenceImpl<SocialActivitySet>
061            implements SocialActivitySetPersistence {
062            /*
063             * NOTE FOR DEVELOPERS:
064             *
065             * Never modify or reference this class directly. Always use {@link SocialActivitySetUtil} to access the social activity set persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
066             */
067            public static final String FINDER_CLASS_NAME_ENTITY = SocialActivitySetImpl.class.getName();
068            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
069                    ".List1";
070            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List2";
072            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
073                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED,
074                            SocialActivitySetImpl.class,
075                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
076            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
077                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED,
078                            SocialActivitySetImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
081                            SocialActivitySetModelImpl.FINDER_CACHE_ENABLED, Long.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083    
084            /**
085             * Caches the social activity set in the entity cache if it is enabled.
086             *
087             * @param socialActivitySet the social activity set
088             */
089            public void cacheResult(SocialActivitySet socialActivitySet) {
090                    EntityCacheUtil.putResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
091                            SocialActivitySetImpl.class, socialActivitySet.getPrimaryKey(),
092                            socialActivitySet);
093    
094                    socialActivitySet.resetOriginalValues();
095            }
096    
097            /**
098             * Caches the social activity sets in the entity cache if it is enabled.
099             *
100             * @param socialActivitySets the social activity sets
101             */
102            public void cacheResult(List<SocialActivitySet> socialActivitySets) {
103                    for (SocialActivitySet socialActivitySet : socialActivitySets) {
104                            if (EntityCacheUtil.getResult(
105                                                    SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
106                                                    SocialActivitySetImpl.class,
107                                                    socialActivitySet.getPrimaryKey()) == null) {
108                                    cacheResult(socialActivitySet);
109                            }
110                            else {
111                                    socialActivitySet.resetOriginalValues();
112                            }
113                    }
114            }
115    
116            /**
117             * Clears the cache for all social activity sets.
118             *
119             * <p>
120             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
121             * </p>
122             */
123            @Override
124            public void clearCache() {
125                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
126                            CacheRegistryUtil.clear(SocialActivitySetImpl.class.getName());
127                    }
128    
129                    EntityCacheUtil.clearCache(SocialActivitySetImpl.class.getName());
130    
131                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
132                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
133                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
134            }
135    
136            /**
137             * Clears the cache for the social activity set.
138             *
139             * <p>
140             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
141             * </p>
142             */
143            @Override
144            public void clearCache(SocialActivitySet socialActivitySet) {
145                    EntityCacheUtil.removeResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
146                            SocialActivitySetImpl.class, socialActivitySet.getPrimaryKey());
147    
148                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
149                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
150            }
151    
152            @Override
153            public void clearCache(List<SocialActivitySet> socialActivitySets) {
154                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
155                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
156    
157                    for (SocialActivitySet socialActivitySet : socialActivitySets) {
158                            EntityCacheUtil.removeResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
159                                    SocialActivitySetImpl.class, socialActivitySet.getPrimaryKey());
160                    }
161            }
162    
163            /**
164             * Creates a new social activity set with the primary key. Does not add the social activity set to the database.
165             *
166             * @param activitySetId the primary key for the new social activity set
167             * @return the new social activity set
168             */
169            public SocialActivitySet create(long activitySetId) {
170                    SocialActivitySet socialActivitySet = new SocialActivitySetImpl();
171    
172                    socialActivitySet.setNew(true);
173                    socialActivitySet.setPrimaryKey(activitySetId);
174    
175                    return socialActivitySet;
176            }
177    
178            /**
179             * Removes the social activity set with the primary key from the database. Also notifies the appropriate model listeners.
180             *
181             * @param activitySetId the primary key of the social activity set
182             * @return the social activity set that was removed
183             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
184             * @throws SystemException if a system exception occurred
185             */
186            public SocialActivitySet remove(long activitySetId)
187                    throws NoSuchActivitySetException, SystemException {
188                    return remove((Serializable)activitySetId);
189            }
190    
191            /**
192             * Removes the social activity set with the primary key from the database. Also notifies the appropriate model listeners.
193             *
194             * @param primaryKey the primary key of the social activity set
195             * @return the social activity set that was removed
196             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
197             * @throws SystemException if a system exception occurred
198             */
199            @Override
200            public SocialActivitySet remove(Serializable primaryKey)
201                    throws NoSuchActivitySetException, SystemException {
202                    Session session = null;
203    
204                    try {
205                            session = openSession();
206    
207                            SocialActivitySet socialActivitySet = (SocialActivitySet)session.get(SocialActivitySetImpl.class,
208                                            primaryKey);
209    
210                            if (socialActivitySet == null) {
211                                    if (_log.isWarnEnabled()) {
212                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
213                                    }
214    
215                                    throw new NoSuchActivitySetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
216                                            primaryKey);
217                            }
218    
219                            return remove(socialActivitySet);
220                    }
221                    catch (NoSuchActivitySetException nsee) {
222                            throw nsee;
223                    }
224                    catch (Exception e) {
225                            throw processException(e);
226                    }
227                    finally {
228                            closeSession(session);
229                    }
230            }
231    
232            @Override
233            protected SocialActivitySet removeImpl(SocialActivitySet socialActivitySet)
234                    throws SystemException {
235                    socialActivitySet = toUnwrappedModel(socialActivitySet);
236    
237                    Session session = null;
238    
239                    try {
240                            session = openSession();
241    
242                            if (!session.contains(socialActivitySet)) {
243                                    socialActivitySet = (SocialActivitySet)session.get(SocialActivitySetImpl.class,
244                                                    socialActivitySet.getPrimaryKeyObj());
245                            }
246    
247                            if (socialActivitySet != null) {
248                                    session.delete(socialActivitySet);
249                            }
250                    }
251                    catch (Exception e) {
252                            throw processException(e);
253                    }
254                    finally {
255                            closeSession(session);
256                    }
257    
258                    if (socialActivitySet != null) {
259                            clearCache(socialActivitySet);
260                    }
261    
262                    return socialActivitySet;
263            }
264    
265            @Override
266            public SocialActivitySet updateImpl(
267                    com.liferay.portlet.social.model.SocialActivitySet socialActivitySet)
268                    throws SystemException {
269                    socialActivitySet = toUnwrappedModel(socialActivitySet);
270    
271                    boolean isNew = socialActivitySet.isNew();
272    
273                    Session session = null;
274    
275                    try {
276                            session = openSession();
277    
278                            if (socialActivitySet.isNew()) {
279                                    session.save(socialActivitySet);
280    
281                                    socialActivitySet.setNew(false);
282                            }
283                            else {
284                                    session.merge(socialActivitySet);
285                            }
286                    }
287                    catch (Exception e) {
288                            throw processException(e);
289                    }
290                    finally {
291                            closeSession(session);
292                    }
293    
294                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
295    
296                    if (isNew) {
297                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
298                    }
299    
300                    EntityCacheUtil.putResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
301                            SocialActivitySetImpl.class, socialActivitySet.getPrimaryKey(),
302                            socialActivitySet);
303    
304                    return socialActivitySet;
305            }
306    
307            protected SocialActivitySet toUnwrappedModel(
308                    SocialActivitySet socialActivitySet) {
309                    if (socialActivitySet instanceof SocialActivitySetImpl) {
310                            return socialActivitySet;
311                    }
312    
313                    SocialActivitySetImpl socialActivitySetImpl = new SocialActivitySetImpl();
314    
315                    socialActivitySetImpl.setNew(socialActivitySet.isNew());
316                    socialActivitySetImpl.setPrimaryKey(socialActivitySet.getPrimaryKey());
317    
318                    socialActivitySetImpl.setActivitySetId(socialActivitySet.getActivitySetId());
319                    socialActivitySetImpl.setGroupId(socialActivitySet.getGroupId());
320                    socialActivitySetImpl.setCompanyId(socialActivitySet.getCompanyId());
321                    socialActivitySetImpl.setUserId(socialActivitySet.getUserId());
322                    socialActivitySetImpl.setCreateDate(socialActivitySet.getCreateDate());
323                    socialActivitySetImpl.setModifiedDate(socialActivitySet.getModifiedDate());
324                    socialActivitySetImpl.setClassNameId(socialActivitySet.getClassNameId());
325                    socialActivitySetImpl.setClassPK(socialActivitySet.getClassPK());
326                    socialActivitySetImpl.setType(socialActivitySet.getType());
327                    socialActivitySetImpl.setActivityCount(socialActivitySet.getActivityCount());
328    
329                    return socialActivitySetImpl;
330            }
331    
332            /**
333             * Returns the social activity set with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
334             *
335             * @param primaryKey the primary key of the social activity set
336             * @return the social activity set
337             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
338             * @throws SystemException if a system exception occurred
339             */
340            @Override
341            public SocialActivitySet findByPrimaryKey(Serializable primaryKey)
342                    throws NoSuchActivitySetException, SystemException {
343                    SocialActivitySet socialActivitySet = fetchByPrimaryKey(primaryKey);
344    
345                    if (socialActivitySet == null) {
346                            if (_log.isWarnEnabled()) {
347                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
348                            }
349    
350                            throw new NoSuchActivitySetException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
351                                    primaryKey);
352                    }
353    
354                    return socialActivitySet;
355            }
356    
357            /**
358             * Returns the social activity set with the primary key or throws a {@link com.liferay.portlet.social.NoSuchActivitySetException} if it could not be found.
359             *
360             * @param activitySetId the primary key of the social activity set
361             * @return the social activity set
362             * @throws com.liferay.portlet.social.NoSuchActivitySetException if a social activity set with the primary key could not be found
363             * @throws SystemException if a system exception occurred
364             */
365            public SocialActivitySet findByPrimaryKey(long activitySetId)
366                    throws NoSuchActivitySetException, SystemException {
367                    return findByPrimaryKey((Serializable)activitySetId);
368            }
369    
370            /**
371             * Returns the social activity set with the primary key or returns <code>null</code> if it could not be found.
372             *
373             * @param primaryKey the primary key of the social activity set
374             * @return the social activity set, or <code>null</code> if a social activity set with the primary key could not be found
375             * @throws SystemException if a system exception occurred
376             */
377            @Override
378            public SocialActivitySet fetchByPrimaryKey(Serializable primaryKey)
379                    throws SystemException {
380                    SocialActivitySet socialActivitySet = (SocialActivitySet)EntityCacheUtil.getResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
381                                    SocialActivitySetImpl.class, primaryKey);
382    
383                    if (socialActivitySet == _nullSocialActivitySet) {
384                            return null;
385                    }
386    
387                    if (socialActivitySet == null) {
388                            Session session = null;
389    
390                            try {
391                                    session = openSession();
392    
393                                    socialActivitySet = (SocialActivitySet)session.get(SocialActivitySetImpl.class,
394                                                    primaryKey);
395    
396                                    if (socialActivitySet != null) {
397                                            cacheResult(socialActivitySet);
398                                    }
399                                    else {
400                                            EntityCacheUtil.putResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
401                                                    SocialActivitySetImpl.class, primaryKey,
402                                                    _nullSocialActivitySet);
403                                    }
404                            }
405                            catch (Exception e) {
406                                    EntityCacheUtil.removeResult(SocialActivitySetModelImpl.ENTITY_CACHE_ENABLED,
407                                            SocialActivitySetImpl.class, primaryKey);
408    
409                                    throw processException(e);
410                            }
411                            finally {
412                                    closeSession(session);
413                            }
414                    }
415    
416                    return socialActivitySet;
417            }
418    
419            /**
420             * Returns the social activity set with the primary key or returns <code>null</code> if it could not be found.
421             *
422             * @param activitySetId the primary key of the social activity set
423             * @return the social activity set, or <code>null</code> if a social activity set with the primary key could not be found
424             * @throws SystemException if a system exception occurred
425             */
426            public SocialActivitySet fetchByPrimaryKey(long activitySetId)
427                    throws SystemException {
428                    return fetchByPrimaryKey((Serializable)activitySetId);
429            }
430    
431            /**
432             * Returns all the social activity sets.
433             *
434             * @return the social activity sets
435             * @throws SystemException if a system exception occurred
436             */
437            public List<SocialActivitySet> findAll() throws SystemException {
438                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
439            }
440    
441            /**
442             * Returns a range of all the social activity sets.
443             *
444             * <p>
445             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.SocialActivitySetModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
446             * </p>
447             *
448             * @param start the lower bound of the range of social activity sets
449             * @param end the upper bound of the range of social activity sets (not inclusive)
450             * @return the range of social activity sets
451             * @throws SystemException if a system exception occurred
452             */
453            public List<SocialActivitySet> findAll(int start, int end)
454                    throws SystemException {
455                    return findAll(start, end, null);
456            }
457    
458            /**
459             * Returns an ordered range of all the social activity sets.
460             *
461             * <p>
462             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.social.model.impl.SocialActivitySetModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
463             * </p>
464             *
465             * @param start the lower bound of the range of social activity sets
466             * @param end the upper bound of the range of social activity sets (not inclusive)
467             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
468             * @return the ordered range of social activity sets
469             * @throws SystemException if a system exception occurred
470             */
471            public List<SocialActivitySet> findAll(int start, int end,
472                    OrderByComparator orderByComparator) throws SystemException {
473                    boolean pagination = true;
474                    FinderPath finderPath = null;
475                    Object[] finderArgs = null;
476    
477                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
478                                    (orderByComparator == null)) {
479                            pagination = false;
480                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
481                            finderArgs = FINDER_ARGS_EMPTY;
482                    }
483                    else {
484                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
485                            finderArgs = new Object[] { start, end, orderByComparator };
486                    }
487    
488                    List<SocialActivitySet> list = (List<SocialActivitySet>)FinderCacheUtil.getResult(finderPath,
489                                    finderArgs, this);
490    
491                    if (list == null) {
492                            StringBundler query = null;
493                            String sql = null;
494    
495                            if (orderByComparator != null) {
496                                    query = new StringBundler(2 +
497                                                    (orderByComparator.getOrderByFields().length * 3));
498    
499                                    query.append(_SQL_SELECT_SOCIALACTIVITYSET);
500    
501                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
502                                            orderByComparator);
503    
504                                    sql = query.toString();
505                            }
506                            else {
507                                    sql = _SQL_SELECT_SOCIALACTIVITYSET;
508    
509                                    if (pagination) {
510                                            sql = sql.concat(SocialActivitySetModelImpl.ORDER_BY_JPQL);
511                                    }
512                            }
513    
514                            Session session = null;
515    
516                            try {
517                                    session = openSession();
518    
519                                    Query q = session.createQuery(sql);
520    
521                                    if (!pagination) {
522                                            list = (List<SocialActivitySet>)QueryUtil.list(q,
523                                                            getDialect(), start, end, false);
524    
525                                            Collections.sort(list);
526    
527                                            list = new UnmodifiableList<SocialActivitySet>(list);
528                                    }
529                                    else {
530                                            list = (List<SocialActivitySet>)QueryUtil.list(q,
531                                                            getDialect(), start, end);
532                                    }
533    
534                                    cacheResult(list);
535    
536                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
537                            }
538                            catch (Exception e) {
539                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
540    
541                                    throw processException(e);
542                            }
543                            finally {
544                                    closeSession(session);
545                            }
546                    }
547    
548                    return list;
549            }
550    
551            /**
552             * Removes all the social activity sets from the database.
553             *
554             * @throws SystemException if a system exception occurred
555             */
556            public void removeAll() throws SystemException {
557                    for (SocialActivitySet socialActivitySet : findAll()) {
558                            remove(socialActivitySet);
559                    }
560            }
561    
562            /**
563             * Returns the number of social activity sets.
564             *
565             * @return the number of social activity sets
566             * @throws SystemException if a system exception occurred
567             */
568            public int countAll() throws SystemException {
569                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
570                                    FINDER_ARGS_EMPTY, this);
571    
572                    if (count == null) {
573                            Session session = null;
574    
575                            try {
576                                    session = openSession();
577    
578                                    Query q = session.createQuery(_SQL_COUNT_SOCIALACTIVITYSET);
579    
580                                    count = (Long)q.uniqueResult();
581    
582                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
583                                            FINDER_ARGS_EMPTY, count);
584                            }
585                            catch (Exception e) {
586                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
587                                            FINDER_ARGS_EMPTY);
588    
589                                    throw processException(e);
590                            }
591                            finally {
592                                    closeSession(session);
593                            }
594                    }
595    
596                    return count.intValue();
597            }
598    
599            /**
600             * Initializes the social activity set persistence.
601             */
602            public void afterPropertiesSet() {
603                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
604                                            com.liferay.portal.util.PropsUtil.get(
605                                                    "value.object.listener.com.liferay.portlet.social.model.SocialActivitySet")));
606    
607                    if (listenerClassNames.length > 0) {
608                            try {
609                                    List<ModelListener<SocialActivitySet>> listenersList = new ArrayList<ModelListener<SocialActivitySet>>();
610    
611                                    for (String listenerClassName : listenerClassNames) {
612                                            listenersList.add((ModelListener<SocialActivitySet>)InstanceFactory.newInstance(
613                                                            listenerClassName));
614                                    }
615    
616                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
617                            }
618                            catch (Exception e) {
619                                    _log.error(e);
620                            }
621                    }
622            }
623    
624            public void destroy() {
625                    EntityCacheUtil.removeCache(SocialActivitySetImpl.class.getName());
626                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
627                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
628                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
629            }
630    
631            private static final String _SQL_SELECT_SOCIALACTIVITYSET = "SELECT socialActivitySet FROM SocialActivitySet socialActivitySet";
632            private static final String _SQL_COUNT_SOCIALACTIVITYSET = "SELECT COUNT(socialActivitySet) FROM SocialActivitySet socialActivitySet";
633            private static final String _ORDER_BY_ENTITY_ALIAS = "socialActivitySet.";
634            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialActivitySet exists with the primary key ";
635            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
636            private static Log _log = LogFactoryUtil.getLog(SocialActivitySetPersistenceImpl.class);
637            private static SocialActivitySet _nullSocialActivitySet = new SocialActivitySetImpl() {
638                            @Override
639                            public Object clone() {
640                                    return this;
641                            }
642    
643                            @Override
644                            public CacheModel<SocialActivitySet> toCacheModel() {
645                                    return _nullSocialActivitySetCacheModel;
646                            }
647                    };
648    
649            private static CacheModel<SocialActivitySet> _nullSocialActivitySetCacheModel =
650                    new CacheModel<SocialActivitySet>() {
651                            public SocialActivitySet toEntityModel() {
652                                    return _nullSocialActivitySet;
653                            }
654                    };
655    }