1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.social.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
21  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderPath;
23  import com.liferay.portal.kernel.dao.orm.Query;
24  import com.liferay.portal.kernel.dao.orm.QueryUtil;
25  import com.liferay.portal.kernel.dao.orm.Session;
26  import com.liferay.portal.kernel.exception.SystemException;
27  import com.liferay.portal.kernel.log.Log;
28  import com.liferay.portal.kernel.log.LogFactoryUtil;
29  import com.liferay.portal.kernel.util.GetterUtil;
30  import com.liferay.portal.kernel.util.InstanceFactory;
31  import com.liferay.portal.kernel.util.OrderByComparator;
32  import com.liferay.portal.kernel.util.StringBundler;
33  import com.liferay.portal.kernel.util.StringUtil;
34  import com.liferay.portal.model.ModelListener;
35  import com.liferay.portal.service.persistence.BatchSessionUtil;
36  import com.liferay.portal.service.persistence.ResourcePersistence;
37  import com.liferay.portal.service.persistence.UserPersistence;
38  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
39  
40  import com.liferay.portlet.social.NoSuchEquityHistoryException;
41  import com.liferay.portlet.social.model.SocialEquityHistory;
42  import com.liferay.portlet.social.model.impl.SocialEquityHistoryImpl;
43  import com.liferay.portlet.social.model.impl.SocialEquityHistoryModelImpl;
44  
45  import java.io.Serializable;
46  
47  import java.util.ArrayList;
48  import java.util.Collections;
49  import java.util.List;
50  
51  /**
52   * <a href="SocialEquityHistoryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * <p>
55   * ServiceBuilder generated this class. Modifications in this class will be
56   * overwritten the next time is generated.
57   * </p>
58   *
59   * @author    Brian Wing Shun Chan
60   * @see       SocialEquityHistoryPersistence
61   * @see       SocialEquityHistoryUtil
62   * @generated
63   */
64  public class SocialEquityHistoryPersistenceImpl extends BasePersistenceImpl<SocialEquityHistory>
65      implements SocialEquityHistoryPersistence {
66      public static final String FINDER_CLASS_NAME_ENTITY = SocialEquityHistoryImpl.class.getName();
67      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
68          ".List";
69      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
70              SocialEquityHistoryModelImpl.FINDER_CACHE_ENABLED,
71              FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
72      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
73              SocialEquityHistoryModelImpl.FINDER_CACHE_ENABLED,
74              FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
75  
76      public void cacheResult(SocialEquityHistory socialEquityHistory) {
77          EntityCacheUtil.putResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
78              SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey(),
79              socialEquityHistory);
80      }
81  
82      public void cacheResult(List<SocialEquityHistory> socialEquityHistories) {
83          for (SocialEquityHistory socialEquityHistory : socialEquityHistories) {
84              if (EntityCacheUtil.getResult(
85                          SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
86                          SocialEquityHistoryImpl.class,
87                          socialEquityHistory.getPrimaryKey(), this) == null) {
88                  cacheResult(socialEquityHistory);
89              }
90          }
91      }
92  
93      public void clearCache() {
94          CacheRegistry.clear(SocialEquityHistoryImpl.class.getName());
95          EntityCacheUtil.clearCache(SocialEquityHistoryImpl.class.getName());
96          FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
97          FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
98      }
99  
100     public void clearCache(SocialEquityHistory socialEquityHistory) {
101         EntityCacheUtil.removeResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
102             SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey());
103     }
104 
105     public SocialEquityHistory create(long equityHistoryId) {
106         SocialEquityHistory socialEquityHistory = new SocialEquityHistoryImpl();
107 
108         socialEquityHistory.setNew(true);
109         socialEquityHistory.setPrimaryKey(equityHistoryId);
110 
111         return socialEquityHistory;
112     }
113 
114     public SocialEquityHistory remove(Serializable primaryKey)
115         throws NoSuchModelException, SystemException {
116         return remove(((Long)primaryKey).longValue());
117     }
118 
119     public SocialEquityHistory remove(long equityHistoryId)
120         throws NoSuchEquityHistoryException, SystemException {
121         Session session = null;
122 
123         try {
124             session = openSession();
125 
126             SocialEquityHistory socialEquityHistory = (SocialEquityHistory)session.get(SocialEquityHistoryImpl.class,
127                     new Long(equityHistoryId));
128 
129             if (socialEquityHistory == null) {
130                 if (_log.isWarnEnabled()) {
131                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
132                         equityHistoryId);
133                 }
134 
135                 throw new NoSuchEquityHistoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
136                     equityHistoryId);
137             }
138 
139             return remove(socialEquityHistory);
140         }
141         catch (NoSuchEquityHistoryException nsee) {
142             throw nsee;
143         }
144         catch (Exception e) {
145             throw processException(e);
146         }
147         finally {
148             closeSession(session);
149         }
150     }
151 
152     public SocialEquityHistory remove(SocialEquityHistory socialEquityHistory)
153         throws SystemException {
154         for (ModelListener<SocialEquityHistory> listener : listeners) {
155             listener.onBeforeRemove(socialEquityHistory);
156         }
157 
158         socialEquityHistory = removeImpl(socialEquityHistory);
159 
160         for (ModelListener<SocialEquityHistory> listener : listeners) {
161             listener.onAfterRemove(socialEquityHistory);
162         }
163 
164         return socialEquityHistory;
165     }
166 
167     protected SocialEquityHistory removeImpl(
168         SocialEquityHistory socialEquityHistory) throws SystemException {
169         socialEquityHistory = toUnwrappedModel(socialEquityHistory);
170 
171         Session session = null;
172 
173         try {
174             session = openSession();
175 
176             if (socialEquityHistory.isCachedModel() ||
177                     BatchSessionUtil.isEnabled()) {
178                 Object staleObject = session.get(SocialEquityHistoryImpl.class,
179                         socialEquityHistory.getPrimaryKeyObj());
180 
181                 if (staleObject != null) {
182                     session.evict(staleObject);
183                 }
184             }
185 
186             session.delete(socialEquityHistory);
187 
188             session.flush();
189         }
190         catch (Exception e) {
191             throw processException(e);
192         }
193         finally {
194             closeSession(session);
195         }
196 
197         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
198 
199         EntityCacheUtil.removeResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
200             SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey());
201 
202         return socialEquityHistory;
203     }
204 
205     public SocialEquityHistory updateImpl(
206         com.liferay.portlet.social.model.SocialEquityHistory socialEquityHistory,
207         boolean merge) throws SystemException {
208         socialEquityHistory = toUnwrappedModel(socialEquityHistory);
209 
210         Session session = null;
211 
212         try {
213             session = openSession();
214 
215             BatchSessionUtil.update(session, socialEquityHistory, merge);
216 
217             socialEquityHistory.setNew(false);
218         }
219         catch (Exception e) {
220             throw processException(e);
221         }
222         finally {
223             closeSession(session);
224         }
225 
226         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
227 
228         EntityCacheUtil.putResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
229             SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey(),
230             socialEquityHistory);
231 
232         return socialEquityHistory;
233     }
234 
235     protected SocialEquityHistory toUnwrappedModel(
236         SocialEquityHistory socialEquityHistory) {
237         if (socialEquityHistory instanceof SocialEquityHistoryImpl) {
238             return socialEquityHistory;
239         }
240 
241         SocialEquityHistoryImpl socialEquityHistoryImpl = new SocialEquityHistoryImpl();
242 
243         socialEquityHistoryImpl.setNew(socialEquityHistory.isNew());
244         socialEquityHistoryImpl.setPrimaryKey(socialEquityHistory.getPrimaryKey());
245 
246         socialEquityHistoryImpl.setEquityHistoryId(socialEquityHistory.getEquityHistoryId());
247         socialEquityHistoryImpl.setGroupId(socialEquityHistory.getGroupId());
248         socialEquityHistoryImpl.setCompanyId(socialEquityHistory.getCompanyId());
249         socialEquityHistoryImpl.setUserId(socialEquityHistory.getUserId());
250         socialEquityHistoryImpl.setCreateDate(socialEquityHistory.getCreateDate());
251         socialEquityHistoryImpl.setPersonalEquity(socialEquityHistory.getPersonalEquity());
252 
253         return socialEquityHistoryImpl;
254     }
255 
256     public SocialEquityHistory findByPrimaryKey(Serializable primaryKey)
257         throws NoSuchModelException, SystemException {
258         return findByPrimaryKey(((Long)primaryKey).longValue());
259     }
260 
261     public SocialEquityHistory findByPrimaryKey(long equityHistoryId)
262         throws NoSuchEquityHistoryException, SystemException {
263         SocialEquityHistory socialEquityHistory = fetchByPrimaryKey(equityHistoryId);
264 
265         if (socialEquityHistory == null) {
266             if (_log.isWarnEnabled()) {
267                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + equityHistoryId);
268             }
269 
270             throw new NoSuchEquityHistoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
271                 equityHistoryId);
272         }
273 
274         return socialEquityHistory;
275     }
276 
277     public SocialEquityHistory fetchByPrimaryKey(Serializable primaryKey)
278         throws SystemException {
279         return fetchByPrimaryKey(((Long)primaryKey).longValue());
280     }
281 
282     public SocialEquityHistory fetchByPrimaryKey(long equityHistoryId)
283         throws SystemException {
284         SocialEquityHistory socialEquityHistory = (SocialEquityHistory)EntityCacheUtil.getResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
285                 SocialEquityHistoryImpl.class, equityHistoryId, this);
286 
287         if (socialEquityHistory == null) {
288             Session session = null;
289 
290             try {
291                 session = openSession();
292 
293                 socialEquityHistory = (SocialEquityHistory)session.get(SocialEquityHistoryImpl.class,
294                         new Long(equityHistoryId));
295             }
296             catch (Exception e) {
297                 throw processException(e);
298             }
299             finally {
300                 if (socialEquityHistory != null) {
301                     cacheResult(socialEquityHistory);
302                 }
303 
304                 closeSession(session);
305             }
306         }
307 
308         return socialEquityHistory;
309     }
310 
311     public List<SocialEquityHistory> findAll() throws SystemException {
312         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
313     }
314 
315     public List<SocialEquityHistory> findAll(int start, int end)
316         throws SystemException {
317         return findAll(start, end, null);
318     }
319 
320     public List<SocialEquityHistory> findAll(int start, int end,
321         OrderByComparator orderByComparator) throws SystemException {
322         Object[] finderArgs = new Object[] {
323                 String.valueOf(start), String.valueOf(end),
324                 String.valueOf(orderByComparator)
325             };
326 
327         List<SocialEquityHistory> list = (List<SocialEquityHistory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
328                 finderArgs, this);
329 
330         if (list == null) {
331             Session session = null;
332 
333             try {
334                 session = openSession();
335 
336                 StringBundler query = null;
337                 String sql = null;
338 
339                 if (orderByComparator != null) {
340                     query = new StringBundler(2 +
341                             (orderByComparator.getOrderByFields().length * 3));
342 
343                     query.append(_SQL_SELECT_SOCIALEQUITYHISTORY);
344 
345                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
346                         orderByComparator);
347 
348                     sql = query.toString();
349                 }
350 
351                 sql = _SQL_SELECT_SOCIALEQUITYHISTORY;
352 
353                 Query q = session.createQuery(sql);
354 
355                 if (orderByComparator == null) {
356                     list = (List<SocialEquityHistory>)QueryUtil.list(q,
357                             getDialect(), start, end, false);
358 
359                     Collections.sort(list);
360                 }
361                 else {
362                     list = (List<SocialEquityHistory>)QueryUtil.list(q,
363                             getDialect(), start, end);
364                 }
365             }
366             catch (Exception e) {
367                 throw processException(e);
368             }
369             finally {
370                 if (list == null) {
371                     list = new ArrayList<SocialEquityHistory>();
372                 }
373 
374                 cacheResult(list);
375 
376                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
377 
378                 closeSession(session);
379             }
380         }
381 
382         return list;
383     }
384 
385     public void removeAll() throws SystemException {
386         for (SocialEquityHistory socialEquityHistory : findAll()) {
387             remove(socialEquityHistory);
388         }
389     }
390 
391     public int countAll() throws SystemException {
392         Object[] finderArgs = new Object[0];
393 
394         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
395                 finderArgs, this);
396 
397         if (count == null) {
398             Session session = null;
399 
400             try {
401                 session = openSession();
402 
403                 Query q = session.createQuery(_SQL_COUNT_SOCIALEQUITYHISTORY);
404 
405                 count = (Long)q.uniqueResult();
406             }
407             catch (Exception e) {
408                 throw processException(e);
409             }
410             finally {
411                 if (count == null) {
412                     count = Long.valueOf(0);
413                 }
414 
415                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
416                     count);
417 
418                 closeSession(session);
419             }
420         }
421 
422         return count.intValue();
423     }
424 
425     public void afterPropertiesSet() {
426         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
427                     com.liferay.portal.util.PropsUtil.get(
428                         "value.object.listener.com.liferay.portlet.social.model.SocialEquityHistory")));
429 
430         if (listenerClassNames.length > 0) {
431             try {
432                 List<ModelListener<SocialEquityHistory>> listenersList = new ArrayList<ModelListener<SocialEquityHistory>>();
433 
434                 for (String listenerClassName : listenerClassNames) {
435                     listenersList.add((ModelListener<SocialEquityHistory>)InstanceFactory.newInstance(
436                             listenerClassName));
437                 }
438 
439                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
440             }
441             catch (Exception e) {
442                 _log.error(e);
443             }
444         }
445     }
446 
447     @BeanReference(type = SocialActivityPersistence.class)
448     protected SocialActivityPersistence socialActivityPersistence;
449     @BeanReference(type = SocialEquityAssetEntryPersistence.class)
450     protected SocialEquityAssetEntryPersistence socialEquityAssetEntryPersistence;
451     @BeanReference(type = SocialEquityHistoryPersistence.class)
452     protected SocialEquityHistoryPersistence socialEquityHistoryPersistence;
453     @BeanReference(type = SocialEquityLogPersistence.class)
454     protected SocialEquityLogPersistence socialEquityLogPersistence;
455     @BeanReference(type = SocialEquitySettingPersistence.class)
456     protected SocialEquitySettingPersistence socialEquitySettingPersistence;
457     @BeanReference(type = SocialEquityUserPersistence.class)
458     protected SocialEquityUserPersistence socialEquityUserPersistence;
459     @BeanReference(type = SocialRelationPersistence.class)
460     protected SocialRelationPersistence socialRelationPersistence;
461     @BeanReference(type = SocialRequestPersistence.class)
462     protected SocialRequestPersistence socialRequestPersistence;
463     @BeanReference(type = ResourcePersistence.class)
464     protected ResourcePersistence resourcePersistence;
465     @BeanReference(type = UserPersistence.class)
466     protected UserPersistence userPersistence;
467     private static final String _SQL_SELECT_SOCIALEQUITYHISTORY = "SELECT socialEquityHistory FROM SocialEquityHistory socialEquityHistory";
468     private static final String _SQL_COUNT_SOCIALEQUITYHISTORY = "SELECT COUNT(socialEquityHistory) FROM SocialEquityHistory socialEquityHistory";
469     private static final String _ORDER_BY_ENTITY_ALIAS = "socialEquityHistory.";
470     private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialEquityHistory exists with the primary key ";
471     private static Log _log = LogFactoryUtil.getLog(SocialEquityHistoryPersistenceImpl.class);
472 }