001    /**
002     * Copyright (c) 2000-2010 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                            if (socialEquityHistory.isCachedModel() ||
211                                            BatchSessionUtil.isEnabled()) {
212                                    Object staleObject = session.get(SocialEquityHistoryImpl.class,
213                                                    socialEquityHistory.getPrimaryKeyObj());
214    
215                                    if (staleObject != null) {
216                                            session.evict(staleObject);
217                                    }
218                            }
219    
220                            session.delete(socialEquityHistory);
221    
222                            session.flush();
223                    }
224                    catch (Exception e) {
225                            throw processException(e);
226                    }
227                    finally {
228                            closeSession(session);
229                    }
230    
231                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
232    
233                    EntityCacheUtil.removeResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
234                            SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey());
235    
236                    return socialEquityHistory;
237            }
238    
239            public SocialEquityHistory updateImpl(
240                    com.liferay.portlet.social.model.SocialEquityHistory socialEquityHistory,
241                    boolean merge) throws SystemException {
242                    socialEquityHistory = toUnwrappedModel(socialEquityHistory);
243    
244                    Session session = null;
245    
246                    try {
247                            session = openSession();
248    
249                            BatchSessionUtil.update(session, socialEquityHistory, merge);
250    
251                            socialEquityHistory.setNew(false);
252                    }
253                    catch (Exception e) {
254                            throw processException(e);
255                    }
256                    finally {
257                            closeSession(session);
258                    }
259    
260                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
261    
262                    EntityCacheUtil.putResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
263                            SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey(),
264                            socialEquityHistory);
265    
266                    return socialEquityHistory;
267            }
268    
269            protected SocialEquityHistory toUnwrappedModel(
270                    SocialEquityHistory socialEquityHistory) {
271                    if (socialEquityHistory instanceof SocialEquityHistoryImpl) {
272                            return socialEquityHistory;
273                    }
274    
275                    SocialEquityHistoryImpl socialEquityHistoryImpl = new SocialEquityHistoryImpl();
276    
277                    socialEquityHistoryImpl.setNew(socialEquityHistory.isNew());
278                    socialEquityHistoryImpl.setPrimaryKey(socialEquityHistory.getPrimaryKey());
279    
280                    socialEquityHistoryImpl.setEquityHistoryId(socialEquityHistory.getEquityHistoryId());
281                    socialEquityHistoryImpl.setGroupId(socialEquityHistory.getGroupId());
282                    socialEquityHistoryImpl.setCompanyId(socialEquityHistory.getCompanyId());
283                    socialEquityHistoryImpl.setUserId(socialEquityHistory.getUserId());
284                    socialEquityHistoryImpl.setCreateDate(socialEquityHistory.getCreateDate());
285                    socialEquityHistoryImpl.setPersonalEquity(socialEquityHistory.getPersonalEquity());
286    
287                    return socialEquityHistoryImpl;
288            }
289    
290            /**
291             * Finds the social equity history with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
292             *
293             * @param primaryKey the primary key of the social equity history to find
294             * @return the social equity history
295             * @throws com.liferay.portal.NoSuchModelException if a social equity history with the primary key could not be found
296             * @throws SystemException if a system exception occurred
297             */
298            public SocialEquityHistory findByPrimaryKey(Serializable primaryKey)
299                    throws NoSuchModelException, SystemException {
300                    return findByPrimaryKey(((Long)primaryKey).longValue());
301            }
302    
303            /**
304             * Finds the social equity history with the primary key or throws a {@link com.liferay.portlet.social.NoSuchEquityHistoryException} if it could not be found.
305             *
306             * @param equityHistoryId the primary key of the social equity history to find
307             * @return the social equity history
308             * @throws com.liferay.portlet.social.NoSuchEquityHistoryException if a social equity history with the primary key could not be found
309             * @throws SystemException if a system exception occurred
310             */
311            public SocialEquityHistory findByPrimaryKey(long equityHistoryId)
312                    throws NoSuchEquityHistoryException, SystemException {
313                    SocialEquityHistory socialEquityHistory = fetchByPrimaryKey(equityHistoryId);
314    
315                    if (socialEquityHistory == null) {
316                            if (_log.isWarnEnabled()) {
317                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + equityHistoryId);
318                            }
319    
320                            throw new NoSuchEquityHistoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
321                                    equityHistoryId);
322                    }
323    
324                    return socialEquityHistory;
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 primaryKey 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(Serializable primaryKey)
335                    throws SystemException {
336                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
337            }
338    
339            /**
340             * Finds the social equity history with the primary key or returns <code>null</code> if it could not be found.
341             *
342             * @param equityHistoryId the primary key of the social equity history to find
343             * @return the social equity history, or <code>null</code> if a social equity history with the primary key could not be found
344             * @throws SystemException if a system exception occurred
345             */
346            public SocialEquityHistory fetchByPrimaryKey(long equityHistoryId)
347                    throws SystemException {
348                    SocialEquityHistory socialEquityHistory = (SocialEquityHistory)EntityCacheUtil.getResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
349                                    SocialEquityHistoryImpl.class, equityHistoryId, this);
350    
351                    if (socialEquityHistory == null) {
352                            Session session = null;
353    
354                            try {
355                                    session = openSession();
356    
357                                    socialEquityHistory = (SocialEquityHistory)session.get(SocialEquityHistoryImpl.class,
358                                                    new Long(equityHistoryId));
359                            }
360                            catch (Exception e) {
361                                    throw processException(e);
362                            }
363                            finally {
364                                    if (socialEquityHistory != null) {
365                                            cacheResult(socialEquityHistory);
366                                    }
367    
368                                    closeSession(session);
369                            }
370                    }
371    
372                    return socialEquityHistory;
373            }
374    
375            /**
376             * Finds all the social equity histories.
377             *
378             * @return the social equity histories
379             * @throws SystemException if a system exception occurred
380             */
381            public List<SocialEquityHistory> findAll() throws SystemException {
382                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
383            }
384    
385            /**
386             * Finds a range of all the social equity histories.
387             *
388             * <p>
389             * 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.
390             * </p>
391             *
392             * @param start the lower bound of the range of social equity histories to return
393             * @param end the upper bound of the range of social equity histories to return (not inclusive)
394             * @return the range of social equity histories
395             * @throws SystemException if a system exception occurred
396             */
397            public List<SocialEquityHistory> findAll(int start, int end)
398                    throws SystemException {
399                    return findAll(start, end, null);
400            }
401    
402            /**
403             * Finds an ordered range of all the social equity histories.
404             *
405             * <p>
406             * 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.
407             * </p>
408             *
409             * @param start the lower bound of the range of social equity histories to return
410             * @param end the upper bound of the range of social equity histories to return (not inclusive)
411             * @param orderByComparator the comparator to order the results by
412             * @return the ordered range of social equity histories
413             * @throws SystemException if a system exception occurred
414             */
415            public List<SocialEquityHistory> findAll(int start, int end,
416                    OrderByComparator orderByComparator) throws SystemException {
417                    Object[] finderArgs = new Object[] {
418                                    String.valueOf(start), String.valueOf(end),
419                                    String.valueOf(orderByComparator)
420                            };
421    
422                    List<SocialEquityHistory> list = (List<SocialEquityHistory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
423                                    finderArgs, this);
424    
425                    if (list == null) {
426                            Session session = null;
427    
428                            try {
429                                    session = openSession();
430    
431                                    StringBundler query = null;
432                                    String sql = null;
433    
434                                    if (orderByComparator != null) {
435                                            query = new StringBundler(2 +
436                                                            (orderByComparator.getOrderByFields().length * 3));
437    
438                                            query.append(_SQL_SELECT_SOCIALEQUITYHISTORY);
439    
440                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
441                                                    orderByComparator);
442    
443                                            sql = query.toString();
444                                    }
445                                    else {
446                                            sql = _SQL_SELECT_SOCIALEQUITYHISTORY;
447                                    }
448    
449                                    Query q = session.createQuery(sql);
450    
451                                    if (orderByComparator == null) {
452                                            list = (List<SocialEquityHistory>)QueryUtil.list(q,
453                                                            getDialect(), start, end, false);
454    
455                                            Collections.sort(list);
456                                    }
457                                    else {
458                                            list = (List<SocialEquityHistory>)QueryUtil.list(q,
459                                                            getDialect(), start, end);
460                                    }
461                            }
462                            catch (Exception e) {
463                                    throw processException(e);
464                            }
465                            finally {
466                                    if (list == null) {
467                                            list = new ArrayList<SocialEquityHistory>();
468                                    }
469    
470                                    cacheResult(list);
471    
472                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
473    
474                                    closeSession(session);
475                            }
476                    }
477    
478                    return list;
479            }
480    
481            /**
482             * Removes all the social equity histories from the database.
483             *
484             * @throws SystemException if a system exception occurred
485             */
486            public void removeAll() throws SystemException {
487                    for (SocialEquityHistory socialEquityHistory : findAll()) {
488                            remove(socialEquityHistory);
489                    }
490            }
491    
492            /**
493             * Counts all the social equity histories.
494             *
495             * @return the number of social equity histories
496             * @throws SystemException if a system exception occurred
497             */
498            public int countAll() throws SystemException {
499                    Object[] finderArgs = new Object[0];
500    
501                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
502                                    finderArgs, this);
503    
504                    if (count == null) {
505                            Session session = null;
506    
507                            try {
508                                    session = openSession();
509    
510                                    Query q = session.createQuery(_SQL_COUNT_SOCIALEQUITYHISTORY);
511    
512                                    count = (Long)q.uniqueResult();
513                            }
514                            catch (Exception e) {
515                                    throw processException(e);
516                            }
517                            finally {
518                                    if (count == null) {
519                                            count = Long.valueOf(0);
520                                    }
521    
522                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
523                                            count);
524    
525                                    closeSession(session);
526                            }
527                    }
528    
529                    return count.intValue();
530            }
531    
532            /**
533             * Initializes the social equity history persistence.
534             */
535            public void afterPropertiesSet() {
536                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
537                                            com.liferay.portal.util.PropsUtil.get(
538                                                    "value.object.listener.com.liferay.portlet.social.model.SocialEquityHistory")));
539    
540                    if (listenerClassNames.length > 0) {
541                            try {
542                                    List<ModelListener<SocialEquityHistory>> listenersList = new ArrayList<ModelListener<SocialEquityHistory>>();
543    
544                                    for (String listenerClassName : listenerClassNames) {
545                                            listenersList.add((ModelListener<SocialEquityHistory>)InstanceFactory.newInstance(
546                                                            listenerClassName));
547                                    }
548    
549                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
550                            }
551                            catch (Exception e) {
552                                    _log.error(e);
553                            }
554                    }
555            }
556    
557            @BeanReference(type = SocialActivityPersistence.class)
558            protected SocialActivityPersistence socialActivityPersistence;
559            @BeanReference(type = SocialEquityAssetEntryPersistence.class)
560            protected SocialEquityAssetEntryPersistence socialEquityAssetEntryPersistence;
561            @BeanReference(type = SocialEquityHistoryPersistence.class)
562            protected SocialEquityHistoryPersistence socialEquityHistoryPersistence;
563            @BeanReference(type = SocialEquityLogPersistence.class)
564            protected SocialEquityLogPersistence socialEquityLogPersistence;
565            @BeanReference(type = SocialEquitySettingPersistence.class)
566            protected SocialEquitySettingPersistence socialEquitySettingPersistence;
567            @BeanReference(type = SocialEquityUserPersistence.class)
568            protected SocialEquityUserPersistence socialEquityUserPersistence;
569            @BeanReference(type = SocialRelationPersistence.class)
570            protected SocialRelationPersistence socialRelationPersistence;
571            @BeanReference(type = SocialRequestPersistence.class)
572            protected SocialRequestPersistence socialRequestPersistence;
573            @BeanReference(type = ResourcePersistence.class)
574            protected ResourcePersistence resourcePersistence;
575            @BeanReference(type = UserPersistence.class)
576            protected UserPersistence userPersistence;
577            private static final String _SQL_SELECT_SOCIALEQUITYHISTORY = "SELECT socialEquityHistory FROM SocialEquityHistory socialEquityHistory";
578            private static final String _SQL_COUNT_SOCIALEQUITYHISTORY = "SELECT COUNT(socialEquityHistory) FROM SocialEquityHistory socialEquityHistory";
579            private static final String _ORDER_BY_ENTITY_ALIAS = "socialEquityHistory.";
580            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialEquityHistory exists with the primary key ";
581            private static Log _log = LogFactoryUtil.getLog(SocialEquityHistoryPersistenceImpl.class);
582    }