001
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
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
084 public void cacheResult(SocialEquityHistory socialEquityHistory) {
085 EntityCacheUtil.putResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
086 SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey(),
087 socialEquityHistory);
088 }
089
090
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
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
127 public void clearCache(SocialEquityHistory socialEquityHistory) {
128 EntityCacheUtil.removeResult(SocialEquityHistoryModelImpl.ENTITY_CACHE_ENABLED,
129 SocialEquityHistoryImpl.class, socialEquityHistory.getPrimaryKey());
130 }
131
132
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
155 public SocialEquityHistory remove(Serializable primaryKey)
156 throws NoSuchModelException, SystemException {
157 return remove(((Long)primaryKey).longValue());
158 }
159
160
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
298 public SocialEquityHistory findByPrimaryKey(Serializable primaryKey)
299 throws NoSuchModelException, SystemException {
300 return findByPrimaryKey(((Long)primaryKey).longValue());
301 }
302
303
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
334 public SocialEquityHistory fetchByPrimaryKey(Serializable primaryKey)
335 throws SystemException {
336 return fetchByPrimaryKey(((Long)primaryKey).longValue());
337 }
338
339
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
381 public List<SocialEquityHistory> findAll() throws SystemException {
382 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
383 }
384
385
397 public List<SocialEquityHistory> findAll(int start, int end)
398 throws SystemException {
399 return findAll(start, end, null);
400 }
401
402
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
486 public void removeAll() throws SystemException {
487 for (SocialEquityHistory socialEquityHistory : findAll()) {
488 remove(socialEquityHistory);
489 }
490 }
491
492
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
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 }