001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.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.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringUtil;
034    import com.liferay.portal.model.ModelListener;
035    import com.liferay.portal.service.persistence.BatchSessionUtil;
036    import com.liferay.portal.service.persistence.ResourcePersistence;
037    import com.liferay.portal.service.persistence.UserPersistence;
038    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039    
040    import com.liferay.portlet.social.NoSuchEquityHistoryException;
041    import com.liferay.portlet.social.model.SocialEquityHistory;
042    import com.liferay.portlet.social.model.impl.SocialEquityHistoryImpl;
043    import com.liferay.portlet.social.model.impl.SocialEquityHistoryModelImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.ArrayList;
048    import java.util.Collections;
049    import java.util.List;
050    
051    /**
052     * The persistence implementation for the social equity history service.
053     *
054     * <p>
055     * Never modify or reference this class directly. Always use {@link SocialEquityHistoryUtil} to access the social equity history persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
056     * </p>
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 SocialEquityHistoryPersistence
064     * @see SocialEquityHistoryUtil
065     * @generated
066     */
067    public class SocialEquityHistoryPersistenceImpl extends BasePersistenceImpl<SocialEquityHistory>
068            implements SocialEquityHistoryPersistence {
069            public static final String FINDER_CLASS_NAME_ENTITY = SocialEquityHistoryImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
071                    ".List";
072            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
073                            SocialEquityHistoryModelImpl.FINDER_CACHE_ENABLED,
074                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
075            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
076                            SocialEquityHistoryModelImpl.FINDER_CACHE_ENABLED,
077                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
078    
079            /**
080             * Caches the social equity history in the entity cache if it is enabled.
081             *
082             * @param socialEquityHistory the social equity history to cache
083             */
084            public void cacheResult(SocialEquityHistory socialEquityHistory) {
085                    EntityCacheUtil.putResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
086                            SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey(),
087                            socialEquityHistory);
088            }
089    
090            /**
091             * Caches the social equity histories in the entity cache if it is enabled.
092             *
093             * @param socialEquityHistories the social equity histories to cache
094             */
095            public void cacheResult(List<SocialEquityHistory> socialEquityHistories) {
096                    for (SocialEquityHistory socialEquityHistory : socialEquityHistories) {
097                            if (EntityCacheUtil.getResult(
098                                                    SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
099                                                    SocialEquityHistoryImpl.class,
100                                                    socialEquityHistory.getPrimaryKey(), this) == null) {
101                                    cacheResult(socialEquityHistory);
102                            }
103                    }
104            }
105    
106            /**
107             * Clears the cache for all social equity histories.
108             *
109             * <p>
110             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
111             * </p>
112             */
113            public void clearCache() {
114                    CacheRegistryUtil.clear(SocialEquityHistoryImpl.class.getName());
115                    EntityCacheUtil.clearCache(SocialEquityHistoryImpl.class.getName());
116                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
117                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
118            }
119    
120            /**
121             * Clears the cache for the social equity history.
122             *
123             * <p>
124             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
125             * </p>
126             */
127            public void clearCache(SocialEquityHistory socialEquityHistory) {
128                    EntityCacheUtil.removeResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
129                            SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey());
130            }
131    
132            /**
133             * Creates a new social equity history with the primary key. Does not add the social equity history to the database.
134             *
135             * @param equityHistoryId the primary key for the new social equity history
136             * @return the new social equity history
137             */
138            public SocialEquityHistory create(long equityHistoryId) {
139                    SocialEquityHistory socialEquityHistory = new SocialEquityHistoryImpl();
140    
141                    socialEquityHistory.setNew(true);
142                    socialEquityHistory.setPrimaryKey(equityHistoryId);
143    
144                    return socialEquityHistory;
145            }
146    
147            /**
148             * Removes the social equity history with the primary key from the database. Also notifies the appropriate model listeners.
149             *
150             * @param primaryKey the primary key of the social equity history to remove
151             * @return the social equity history that was removed
152             * @throws com.liferay.portal.NoSuchModelException if a social equity history with the primary key could not be found
153             * @throws SystemException if a system exception occurred
154             */
155            public SocialEquityHistory remove(Serializable primaryKey)
156                    throws NoSuchModelException, SystemException {
157                    return remove(((Long)primaryKey).longValue());
158            }
159    
160            /**
161             * Removes the social equity history with the primary key from the database. Also notifies the appropriate model listeners.
162             *
163             * @param equityHistoryId the primary key of the social equity history to remove
164             * @return the social equity history that was removed
165             * @throws com.liferay.portlet.social.NoSuchEquityHistoryException if a social equity history with the primary key could not be found
166             * @throws SystemException if a system exception occurred
167             */
168            public SocialEquityHistory remove(long equityHistoryId)
169                    throws NoSuchEquityHistoryException, SystemException {
170                    Session session = null;
171    
172                    try {
173                            session = openSession();
174    
175                            SocialEquityHistory socialEquityHistory = (SocialEquityHistory)session.get(SocialEquityHistoryImpl.class,
176                                            new Long(equityHistoryId));
177    
178                            if (socialEquityHistory == null) {
179                                    if (_log.isWarnEnabled()) {
180                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
181                                                    equityHistoryId);
182                                    }
183    
184                                    throw new NoSuchEquityHistoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
185                                            equityHistoryId);
186                            }
187    
188                            return remove(socialEquityHistory);
189                    }
190                    catch (NoSuchEquityHistoryException nsee) {
191                            throw nsee;
192                    }
193                    catch (Exception e) {
194                            throw processException(e);
195                    }
196                    finally {
197                            closeSession(session);
198                    }
199            }
200    
201            protected SocialEquityHistory removeImpl(
202                    SocialEquityHistory socialEquityHistory) throws SystemException {
203                    socialEquityHistory = toUnwrappedModel(socialEquityHistory);
204    
205                    Session session = null;
206    
207                    try {
208                            session = openSession();
209    
210                            BatchSessionUtil.delete(session, socialEquityHistory);
211                    }
212                    catch (Exception e) {
213                            throw processException(e);
214                    }
215                    finally {
216                            closeSession(session);
217                    }
218    
219                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
220    
221                    EntityCacheUtil.removeResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
222                            SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey());
223    
224                    return socialEquityHistory;
225            }
226    
227            public SocialEquityHistory updateImpl(
228                    com.liferay.portlet.social.model.SocialEquityHistory socialEquityHistory,
229                    boolean merge) throws SystemException {
230                    socialEquityHistory = toUnwrappedModel(socialEquityHistory);
231    
232                    Session session = null;
233    
234                    try {
235                            session = openSession();
236    
237                            BatchSessionUtil.update(session, socialEquityHistory, merge);
238    
239                            socialEquityHistory.setNew(false);
240                    }
241                    catch (Exception e) {
242                            throw processException(e);
243                    }
244                    finally {
245                            closeSession(session);
246                    }
247    
248                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
249    
250                    EntityCacheUtil.putResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
251                            SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey(),
252                            socialEquityHistory);
253    
254                    return socialEquityHistory;
255            }
256    
257            protected SocialEquityHistory toUnwrappedModel(
258                    SocialEquityHistory socialEquityHistory) {
259                    if (socialEquityHistory instanceof SocialEquityHistoryImpl) {
260                            return socialEquityHistory;
261                    }
262    
263                    SocialEquityHistoryImpl socialEquityHistoryImpl = new SocialEquityHistoryImpl();
264    
265                    socialEquityHistoryImpl.setNew(socialEquityHistory.isNew());
266                    socialEquityHistoryImpl.setPrimaryKey(socialEquityHistory.getPrimaryKey());
267    
268                    socialEquityHistoryImpl.setEquityHistoryId(socialEquityHistory.getEquityHistoryId());
269                    socialEquityHistoryImpl.setGroupId(socialEquityHistory.getGroupId());
270                    socialEquityHistoryImpl.setCompanyId(socialEquityHistory.getCompanyId());
271                    socialEquityHistoryImpl.setUserId(socialEquityHistory.getUserId());
272                    socialEquityHistoryImpl.setCreateDate(socialEquityHistory.getCreateDate());
273                    socialEquityHistoryImpl.setPersonalEquity(socialEquityHistory.getPersonalEquity());
274    
275                    return socialEquityHistoryImpl;
276            }
277    
278            /**
279             * Finds the social equity history with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
280             *
281             * @param primaryKey the primary key of the social equity history to find
282             * @return the social equity history
283             * @throws com.liferay.portal.NoSuchModelException if a social equity history with the primary key could not be found
284             * @throws SystemException if a system exception occurred
285             */
286            public SocialEquityHistory findByPrimaryKey(Serializable primaryKey)
287                    throws NoSuchModelException, SystemException {
288                    return findByPrimaryKey(((Long)primaryKey).longValue());
289            }
290    
291            /**
292             * Finds the social equity history with the primary key or throws a {@link com.liferay.portlet.social.NoSuchEquityHistoryException} if it could not be found.
293             *
294             * @param equityHistoryId the primary key of the social equity history to find
295             * @return the social equity history
296             * @throws com.liferay.portlet.social.NoSuchEquityHistoryException if a social equity history with the primary key could not be found
297             * @throws SystemException if a system exception occurred
298             */
299            public SocialEquityHistory findByPrimaryKey(long equityHistoryId)
300                    throws NoSuchEquityHistoryException, SystemException {
301                    SocialEquityHistory socialEquityHistory = fetchByPrimaryKey(equityHistoryId);
302    
303                    if (socialEquityHistory == null) {
304                            if (_log.isWarnEnabled()) {
305                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + equityHistoryId);
306                            }
307    
308                            throw new NoSuchEquityHistoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
309                                    equityHistoryId);
310                    }
311    
312                    return socialEquityHistory;
313            }
314    
315            /**
316             * Finds the social equity history with the primary key or returns <code>null</code> if it could not be found.
317             *
318             * @param primaryKey the primary key of the social equity history to find
319             * @return the social equity history, or <code>null</code> if a social equity history with the primary key could not be found
320             * @throws SystemException if a system exception occurred
321             */
322            public SocialEquityHistory fetchByPrimaryKey(Serializable primaryKey)
323                    throws SystemException {
324                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
325            }
326    
327            /**
328             * Finds the social equity history with the primary key or returns <code>null</code> if it could not be found.
329             *
330             * @param equityHistoryId the primary key of the social equity history to find
331             * @return the social equity history, or <code>null</code> if a social equity history with the primary key could not be found
332             * @throws SystemException if a system exception occurred
333             */
334            public SocialEquityHistory fetchByPrimaryKey(long equityHistoryId)
335                    throws SystemException {
336                    SocialEquityHistory socialEquityHistory = (SocialEquityHistory)EntityCacheUtil.getResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
337                                    SocialEquityHistoryImpl.class, equityHistoryId, this);
338    
339                    if (socialEquityHistory == null) {
340                            Session session = null;
341    
342                            try {
343                                    session = openSession();
344    
345                                    socialEquityHistory = (SocialEquityHistory)session.get(SocialEquityHistoryImpl.class,
346                                                    new Long(equityHistoryId));
347                            }
348                            catch (Exception e) {
349                                    throw processException(e);
350                            }
351                            finally {
352                                    if (socialEquityHistory != null) {
353                                            cacheResult(socialEquityHistory);
354                                    }
355    
356                                    closeSession(session);
357                            }
358                    }
359    
360                    return socialEquityHistory;
361            }
362    
363            /**
364             * Finds all the social equity histories.
365             *
366             * @return the social equity histories
367             * @throws SystemException if a system exception occurred
368             */
369            public List<SocialEquityHistory> findAll() throws SystemException {
370                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
371            }
372    
373            /**
374             * Finds a range of all the social equity histories.
375             *
376             * <p>
377             * 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.
378             * </p>
379             *
380             * @param start the lower bound of the range of social equity histories to return
381             * @param end the upper bound of the range of social equity histories to return (not inclusive)
382             * @return the range of social equity histories
383             * @throws SystemException if a system exception occurred
384             */
385            public List<SocialEquityHistory> findAll(int start, int end)
386                    throws SystemException {
387                    return findAll(start, end, null);
388            }
389    
390            /**
391             * Finds an ordered range of all the social equity histories.
392             *
393             * <p>
394             * 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.
395             * </p>
396             *
397             * @param start the lower bound of the range of social equity histories to return
398             * @param end the upper bound of the range of social equity histories to return (not inclusive)
399             * @param orderByComparator the comparator to order the results by
400             * @return the ordered range of social equity histories
401             * @throws SystemException if a system exception occurred
402             */
403            public List<SocialEquityHistory> findAll(int start, int end,
404                    OrderByComparator orderByComparator) throws SystemException {
405                    Object[] finderArgs = new Object[] {
406                                    String.valueOf(start), String.valueOf(end),
407                                    String.valueOf(orderByComparator)
408                            };
409    
410                    List<SocialEquityHistory> list = (List<SocialEquityHistory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
411                                    finderArgs, this);
412    
413                    if (list == null) {
414                            StringBundler query = null;
415                            String sql = null;
416    
417                            if (orderByComparator != null) {
418                                    query = new StringBundler(2 +
419                                                    (orderByComparator.getOrderByFields().length * 3));
420    
421                                    query.append(_SQL_SELECT_SOCIALEQUITYHISTORY);
422    
423                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
424                                            orderByComparator);
425    
426                                    sql = query.toString();
427                            }
428                            else {
429                                    sql = _SQL_SELECT_SOCIALEQUITYHISTORY;
430                            }
431    
432                            Session session = null;
433    
434                            try {
435                                    session = openSession();
436    
437                                    Query q = session.createQuery(sql);
438    
439                                    if (orderByComparator == null) {
440                                            list = (List<SocialEquityHistory>)QueryUtil.list(q,
441                                                            getDialect(), start, end, false);
442    
443                                            Collections.sort(list);
444                                    }
445                                    else {
446                                            list = (List<SocialEquityHistory>)QueryUtil.list(q,
447                                                            getDialect(), start, end);
448                                    }
449                            }
450                            catch (Exception e) {
451                                    throw processException(e);
452                            }
453                            finally {
454                                    if (list == null) {
455                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
456                                                    finderArgs);
457                                    }
458                                    else {
459                                            cacheResult(list);
460    
461                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
462                                                    list);
463                                    }
464    
465                                    closeSession(session);
466                            }
467                    }
468    
469                    return list;
470            }
471    
472            /**
473             * Removes all the social equity histories from the database.
474             *
475             * @throws SystemException if a system exception occurred
476             */
477            public void removeAll() throws SystemException {
478                    for (SocialEquityHistory socialEquityHistory : findAll()) {
479                            remove(socialEquityHistory);
480                    }
481            }
482    
483            /**
484             * Counts all the social equity histories.
485             *
486             * @return the number of social equity histories
487             * @throws SystemException if a system exception occurred
488             */
489            public int countAll() throws SystemException {
490                    Object[] finderArgs = new Object[0];
491    
492                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
493                                    finderArgs, this);
494    
495                    if (count == null) {
496                            Session session = null;
497    
498                            try {
499                                    session = openSession();
500    
501                                    Query q = session.createQuery(_SQL_COUNT_SOCIALEQUITYHISTORY);
502    
503                                    count = (Long)q.uniqueResult();
504                            }
505                            catch (Exception e) {
506                                    throw processException(e);
507                            }
508                            finally {
509                                    if (count == null) {
510                                            count = Long.valueOf(0);
511                                    }
512    
513                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
514                                            count);
515    
516                                    closeSession(session);
517                            }
518                    }
519    
520                    return count.intValue();
521            }
522    
523            /**
524             * Initializes the social equity history persistence.
525             */
526            public void afterPropertiesSet() {
527                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
528                                            com.liferay.portal.util.PropsUtil.get(
529                                                    "value.object.listener.com.liferay.portlet.social.model.SocialEquityHistory")));
530    
531                    if (listenerClassNames.length > 0) {
532                            try {
533                                    List<ModelListener<SocialEquityHistory>> listenersList = new ArrayList<ModelListener<SocialEquityHistory>>();
534    
535                                    for (String listenerClassName : listenerClassNames) {
536                                            listenersList.add((ModelListener<SocialEquityHistory>)InstanceFactory.newInstance(
537                                                            listenerClassName));
538                                    }
539    
540                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
541                            }
542                            catch (Exception e) {
543                                    _log.error(e);
544                            }
545                    }
546            }
547    
548            public void destroy() {
549                    EntityCacheUtil.removeCache(SocialEquityHistoryImpl.class.getName());
550                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
551                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
552            }
553    
554            @BeanReference(type = SocialActivityPersistence.class)
555            protected SocialActivityPersistence socialActivityPersistence;
556            @BeanReference(type = SocialEquityAssetEntryPersistence.class)
557            protected SocialEquityAssetEntryPersistence socialEquityAssetEntryPersistence;
558            @BeanReference(type = SocialEquityGroupSettingPersistence.class)
559            protected SocialEquityGroupSettingPersistence socialEquityGroupSettingPersistence;
560            @BeanReference(type = SocialEquityHistoryPersistence.class)
561            protected SocialEquityHistoryPersistence socialEquityHistoryPersistence;
562            @BeanReference(type = SocialEquityLogPersistence.class)
563            protected SocialEquityLogPersistence socialEquityLogPersistence;
564            @BeanReference(type = SocialEquitySettingPersistence.class)
565            protected SocialEquitySettingPersistence socialEquitySettingPersistence;
566            @BeanReference(type = SocialEquityUserPersistence.class)
567            protected SocialEquityUserPersistence socialEquityUserPersistence;
568            @BeanReference(type = SocialRelationPersistence.class)
569            protected SocialRelationPersistence socialRelationPersistence;
570            @BeanReference(type = SocialRequestPersistence.class)
571            protected SocialRequestPersistence socialRequestPersistence;
572            @BeanReference(type = ResourcePersistence.class)
573            protected ResourcePersistence resourcePersistence;
574            @BeanReference(type = UserPersistence.class)
575            protected UserPersistence userPersistence;
576            private static final String _SQL_SELECT_SOCIALEQUITYHISTORY = "SELECT socialEquityHistory FROM SocialEquityHistory socialEquityHistory";
577            private static final String _SQL_COUNT_SOCIALEQUITYHISTORY = "SELECT COUNT(socialEquityHistory) FROM SocialEquityHistory socialEquityHistory";
578            private static final String _ORDER_BY_ENTITY_ALIAS = "socialEquityHistory.";
579            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialEquityHistory exists with the primary key ";
580            private static Log _log = LogFactoryUtil.getLog(SocialEquityHistoryPersistenceImpl.class);
581    }