001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.social.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.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                            Session session = null;
415    
416                            try {
417                                    session = openSession();
418    
419                                    StringBundler query = null;
420                                    String sql = null;
421    
422                                    if (orderByComparator != null) {
423                                            query = new StringBundler(2 +
424                                                            (orderByComparator.getOrderByFields().length * 3));
425    
426                                            query.append(_SQL_SELECT_SOCIALEQUITYHISTORY);
427    
428                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
429                                                    orderByComparator);
430    
431                                            sql = query.toString();
432                                    }
433                                    else {
434                                            sql = _SQL_SELECT_SOCIALEQUITYHISTORY;
435                                    }
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                                            list = new ArrayList<SocialEquityHistory>();
456                                    }
457    
458                                    cacheResult(list);
459    
460                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
461    
462                                    closeSession(session);
463                            }
464                    }
465    
466                    return list;
467            }
468    
469            /**
470             * Removes all the social equity histories from the database.
471             *
472             * @throws SystemException if a system exception occurred
473             */
474            public void removeAll() throws SystemException {
475                    for (SocialEquityHistory socialEquityHistory : findAll()) {
476                            remove(socialEquityHistory);
477                    }
478            }
479    
480            /**
481             * Counts all the social equity histories.
482             *
483             * @return the number of social equity histories
484             * @throws SystemException if a system exception occurred
485             */
486            public int countAll() throws SystemException {
487                    Object[] finderArgs = new Object[0];
488    
489                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
490                                    finderArgs, this);
491    
492                    if (count == null) {
493                            Session session = null;
494    
495                            try {
496                                    session = openSession();
497    
498                                    Query q = session.createQuery(_SQL_COUNT_SOCIALEQUITYHISTORY);
499    
500                                    count = (Long)q.uniqueResult();
501                            }
502                            catch (Exception e) {
503                                    throw processException(e);
504                            }
505                            finally {
506                                    if (count == null) {
507                                            count = Long.valueOf(0);
508                                    }
509    
510                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
511                                            count);
512    
513                                    closeSession(session);
514                            }
515                    }
516    
517                    return count.intValue();
518            }
519    
520            /**
521             * Initializes the social equity history persistence.
522             */
523            public void afterPropertiesSet() {
524                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
525                                            com.liferay.portal.util.PropsUtil.get(
526                                                    "value.object.listener.com.liferay.portlet.social.model.SocialEquityHistory")));
527    
528                    if (listenerClassNames.length > 0) {
529                            try {
530                                    List<ModelListener<SocialEquityHistory>> listenersList = new ArrayList<ModelListener<SocialEquityHistory>>();
531    
532                                    for (String listenerClassName : listenerClassNames) {
533                                            listenersList.add((ModelListener<SocialEquityHistory>)InstanceFactory.newInstance(
534                                                            listenerClassName));
535                                    }
536    
537                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
538                            }
539                            catch (Exception e) {
540                                    _log.error(e);
541                            }
542                    }
543            }
544    
545            public void destroy() {
546                    EntityCacheUtil.removeCache(SocialEquityHistoryImpl.class.getName());
547                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
548                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
549            }
550    
551            @BeanReference(type = SocialActivityPersistence.class)
552            protected SocialActivityPersistence socialActivityPersistence;
553            @BeanReference(type = SocialEquityAssetEntryPersistence.class)
554            protected SocialEquityAssetEntryPersistence socialEquityAssetEntryPersistence;
555            @BeanReference(type = SocialEquityGroupSettingPersistence.class)
556            protected SocialEquityGroupSettingPersistence socialEquityGroupSettingPersistence;
557            @BeanReference(type = SocialEquityHistoryPersistence.class)
558            protected SocialEquityHistoryPersistence socialEquityHistoryPersistence;
559            @BeanReference(type = SocialEquityLogPersistence.class)
560            protected SocialEquityLogPersistence socialEquityLogPersistence;
561            @BeanReference(type = SocialEquitySettingPersistence.class)
562            protected SocialEquitySettingPersistence socialEquitySettingPersistence;
563            @BeanReference(type = SocialEquityUserPersistence.class)
564            protected SocialEquityUserPersistence socialEquityUserPersistence;
565            @BeanReference(type = SocialRelationPersistence.class)
566            protected SocialRelationPersistence socialRelationPersistence;
567            @BeanReference(type = SocialRequestPersistence.class)
568            protected SocialRequestPersistence socialRequestPersistence;
569            @BeanReference(type = ResourcePersistence.class)
570            protected ResourcePersistence resourcePersistence;
571            @BeanReference(type = UserPersistence.class)
572            protected UserPersistence userPersistence;
573            private static final String _SQL_SELECT_SOCIALEQUITYHISTORY = "SELECT socialEquityHistory FROM SocialEquityHistory socialEquityHistory";
574            private static final String _SQL_COUNT_SOCIALEQUITYHISTORY = "SELECT COUNT(socialEquityHistory) FROM SocialEquityHistory socialEquityHistory";
575            private static final String _ORDER_BY_ENTITY_ALIAS = "socialEquityHistory.";
576            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialEquityHistory exists with the primary key ";
577            private static Log _log = LogFactoryUtil.getLog(SocialEquityHistoryPersistenceImpl.class);
578    }