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.QueryPos;
25  import com.liferay.portal.kernel.dao.orm.QueryUtil;
26  import com.liferay.portal.kernel.dao.orm.Session;
27  import com.liferay.portal.kernel.exception.SystemException;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.GetterUtil;
31  import com.liferay.portal.kernel.util.InstanceFactory;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.model.ModelListener;
37  import com.liferay.portal.service.persistence.BatchSessionUtil;
38  import com.liferay.portal.service.persistence.ResourcePersistence;
39  import com.liferay.portal.service.persistence.UserPersistence;
40  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41  
42  import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
43  import com.liferay.portlet.social.NoSuchEquityLogException;
44  import com.liferay.portlet.social.model.SocialEquityLog;
45  import com.liferay.portlet.social.model.impl.SocialEquityLogImpl;
46  import com.liferay.portlet.social.model.impl.SocialEquityLogModelImpl;
47  
48  import java.io.Serializable;
49  
50  import java.util.ArrayList;
51  import java.util.Collections;
52  import java.util.List;
53  
54  /**
55   * <a href="SocialEquityLogPersistenceImpl.java.html"><b><i>View Source</i></b></a>
56   *
57   * <p>
58   * ServiceBuilder generated this class. Modifications in this class will be
59   * overwritten the next time is generated.
60   * </p>
61   *
62   * @author    Brian Wing Shun Chan
63   * @see       SocialEquityLogPersistence
64   * @see       SocialEquityLogUtil
65   * @generated
66   */
67  public class SocialEquityLogPersistenceImpl extends BasePersistenceImpl<SocialEquityLog>
68      implements SocialEquityLogPersistence {
69      public static final String FINDER_CLASS_NAME_ENTITY = SocialEquityLogImpl.class.getName();
70      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
71          ".List";
72      public static final FinderPath FINDER_PATH_FIND_BY_AEI_T_A = new FinderPath(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
73              SocialEquityLogModelImpl.FINDER_CACHE_ENABLED,
74              FINDER_CLASS_NAME_LIST, "findByAEI_T_A",
75              new String[] {
76                  Long.class.getName(), Integer.class.getName(),
77                  Boolean.class.getName(),
78                  
79              "java.lang.Integer", "java.lang.Integer",
80                  "com.liferay.portal.kernel.util.OrderByComparator"
81              });
82      public static final FinderPath FINDER_PATH_COUNT_BY_AEI_T_A = new FinderPath(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
83              SocialEquityLogModelImpl.FINDER_CACHE_ENABLED,
84              FINDER_CLASS_NAME_LIST, "countByAEI_T_A",
85              new String[] {
86                  Long.class.getName(), Integer.class.getName(),
87                  Boolean.class.getName()
88              });
89      public static final FinderPath FINDER_PATH_FIND_BY_U_AEI_A_A = new FinderPath(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
90              SocialEquityLogModelImpl.FINDER_CACHE_ENABLED,
91              FINDER_CLASS_NAME_LIST, "findByU_AEI_A_A",
92              new String[] {
93                  Long.class.getName(), Long.class.getName(),
94                  String.class.getName(), Boolean.class.getName(),
95                  
96              "java.lang.Integer", "java.lang.Integer",
97                  "com.liferay.portal.kernel.util.OrderByComparator"
98              });
99      public static final FinderPath FINDER_PATH_COUNT_BY_U_AEI_A_A = new FinderPath(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
100             SocialEquityLogModelImpl.FINDER_CACHE_ENABLED,
101             FINDER_CLASS_NAME_LIST, "countByU_AEI_A_A",
102             new String[] {
103                 Long.class.getName(), Long.class.getName(),
104                 String.class.getName(), Boolean.class.getName()
105             });
106     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
107             SocialEquityLogModelImpl.FINDER_CACHE_ENABLED,
108             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
109     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
110             SocialEquityLogModelImpl.FINDER_CACHE_ENABLED,
111             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
112 
113     public void cacheResult(SocialEquityLog socialEquityLog) {
114         EntityCacheUtil.putResult(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
115             SocialEquityLogImpl.class, socialEquityLog.getPrimaryKey(),
116             socialEquityLog);
117     }
118 
119     public void cacheResult(List<SocialEquityLog> socialEquityLogs) {
120         for (SocialEquityLog socialEquityLog : socialEquityLogs) {
121             if (EntityCacheUtil.getResult(
122                         SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
123                         SocialEquityLogImpl.class,
124                         socialEquityLog.getPrimaryKey(), this) == null) {
125                 cacheResult(socialEquityLog);
126             }
127         }
128     }
129 
130     public void clearCache() {
131         CacheRegistry.clear(SocialEquityLogImpl.class.getName());
132         EntityCacheUtil.clearCache(SocialEquityLogImpl.class.getName());
133         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
134         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
135     }
136 
137     public void clearCache(SocialEquityLog socialEquityLog) {
138         EntityCacheUtil.removeResult(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
139             SocialEquityLogImpl.class, socialEquityLog.getPrimaryKey());
140     }
141 
142     public SocialEquityLog create(long equityLogId) {
143         SocialEquityLog socialEquityLog = new SocialEquityLogImpl();
144 
145         socialEquityLog.setNew(true);
146         socialEquityLog.setPrimaryKey(equityLogId);
147 
148         return socialEquityLog;
149     }
150 
151     public SocialEquityLog remove(Serializable primaryKey)
152         throws NoSuchModelException, SystemException {
153         return remove(((Long)primaryKey).longValue());
154     }
155 
156     public SocialEquityLog remove(long equityLogId)
157         throws NoSuchEquityLogException, SystemException {
158         Session session = null;
159 
160         try {
161             session = openSession();
162 
163             SocialEquityLog socialEquityLog = (SocialEquityLog)session.get(SocialEquityLogImpl.class,
164                     new Long(equityLogId));
165 
166             if (socialEquityLog == null) {
167                 if (_log.isWarnEnabled()) {
168                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + equityLogId);
169                 }
170 
171                 throw new NoSuchEquityLogException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
172                     equityLogId);
173             }
174 
175             return remove(socialEquityLog);
176         }
177         catch (NoSuchEquityLogException nsee) {
178             throw nsee;
179         }
180         catch (Exception e) {
181             throw processException(e);
182         }
183         finally {
184             closeSession(session);
185         }
186     }
187 
188     public SocialEquityLog remove(SocialEquityLog socialEquityLog)
189         throws SystemException {
190         for (ModelListener<SocialEquityLog> listener : listeners) {
191             listener.onBeforeRemove(socialEquityLog);
192         }
193 
194         socialEquityLog = removeImpl(socialEquityLog);
195 
196         for (ModelListener<SocialEquityLog> listener : listeners) {
197             listener.onAfterRemove(socialEquityLog);
198         }
199 
200         return socialEquityLog;
201     }
202 
203     protected SocialEquityLog removeImpl(SocialEquityLog socialEquityLog)
204         throws SystemException {
205         socialEquityLog = toUnwrappedModel(socialEquityLog);
206 
207         Session session = null;
208 
209         try {
210             session = openSession();
211 
212             if (socialEquityLog.isCachedModel() ||
213                     BatchSessionUtil.isEnabled()) {
214                 Object staleObject = session.get(SocialEquityLogImpl.class,
215                         socialEquityLog.getPrimaryKeyObj());
216 
217                 if (staleObject != null) {
218                     session.evict(staleObject);
219                 }
220             }
221 
222             session.delete(socialEquityLog);
223 
224             session.flush();
225         }
226         catch (Exception e) {
227             throw processException(e);
228         }
229         finally {
230             closeSession(session);
231         }
232 
233         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
234 
235         EntityCacheUtil.removeResult(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
236             SocialEquityLogImpl.class, socialEquityLog.getPrimaryKey());
237 
238         return socialEquityLog;
239     }
240 
241     public SocialEquityLog updateImpl(
242         com.liferay.portlet.social.model.SocialEquityLog socialEquityLog,
243         boolean merge) throws SystemException {
244         socialEquityLog = toUnwrappedModel(socialEquityLog);
245 
246         Session session = null;
247 
248         try {
249             session = openSession();
250 
251             BatchSessionUtil.update(session, socialEquityLog, merge);
252 
253             socialEquityLog.setNew(false);
254         }
255         catch (Exception e) {
256             throw processException(e);
257         }
258         finally {
259             closeSession(session);
260         }
261 
262         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
263 
264         EntityCacheUtil.putResult(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
265             SocialEquityLogImpl.class, socialEquityLog.getPrimaryKey(),
266             socialEquityLog);
267 
268         return socialEquityLog;
269     }
270 
271     protected SocialEquityLog toUnwrappedModel(SocialEquityLog socialEquityLog) {
272         if (socialEquityLog instanceof SocialEquityLogImpl) {
273             return socialEquityLog;
274         }
275 
276         SocialEquityLogImpl socialEquityLogImpl = new SocialEquityLogImpl();
277 
278         socialEquityLogImpl.setNew(socialEquityLog.isNew());
279         socialEquityLogImpl.setPrimaryKey(socialEquityLog.getPrimaryKey());
280 
281         socialEquityLogImpl.setEquityLogId(socialEquityLog.getEquityLogId());
282         socialEquityLogImpl.setGroupId(socialEquityLog.getGroupId());
283         socialEquityLogImpl.setCompanyId(socialEquityLog.getCompanyId());
284         socialEquityLogImpl.setUserId(socialEquityLog.getUserId());
285         socialEquityLogImpl.setAssetEntryId(socialEquityLog.getAssetEntryId());
286         socialEquityLogImpl.setActionId(socialEquityLog.getActionId());
287         socialEquityLogImpl.setActionDate(socialEquityLog.getActionDate());
288         socialEquityLogImpl.setType(socialEquityLog.getType());
289         socialEquityLogImpl.setValue(socialEquityLog.getValue());
290         socialEquityLogImpl.setValidity(socialEquityLog.getValidity());
291         socialEquityLogImpl.setActive(socialEquityLog.isActive());
292 
293         return socialEquityLogImpl;
294     }
295 
296     public SocialEquityLog findByPrimaryKey(Serializable primaryKey)
297         throws NoSuchModelException, SystemException {
298         return findByPrimaryKey(((Long)primaryKey).longValue());
299     }
300 
301     public SocialEquityLog findByPrimaryKey(long equityLogId)
302         throws NoSuchEquityLogException, SystemException {
303         SocialEquityLog socialEquityLog = fetchByPrimaryKey(equityLogId);
304 
305         if (socialEquityLog == null) {
306             if (_log.isWarnEnabled()) {
307                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + equityLogId);
308             }
309 
310             throw new NoSuchEquityLogException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
311                 equityLogId);
312         }
313 
314         return socialEquityLog;
315     }
316 
317     public SocialEquityLog fetchByPrimaryKey(Serializable primaryKey)
318         throws SystemException {
319         return fetchByPrimaryKey(((Long)primaryKey).longValue());
320     }
321 
322     public SocialEquityLog fetchByPrimaryKey(long equityLogId)
323         throws SystemException {
324         SocialEquityLog socialEquityLog = (SocialEquityLog)EntityCacheUtil.getResult(SocialEquityLogModelImpl.ENTITY_CACHE_ENABLED,
325                 SocialEquityLogImpl.class, equityLogId, this);
326 
327         if (socialEquityLog == null) {
328             Session session = null;
329 
330             try {
331                 session = openSession();
332 
333                 socialEquityLog = (SocialEquityLog)session.get(SocialEquityLogImpl.class,
334                         new Long(equityLogId));
335             }
336             catch (Exception e) {
337                 throw processException(e);
338             }
339             finally {
340                 if (socialEquityLog != null) {
341                     cacheResult(socialEquityLog);
342                 }
343 
344                 closeSession(session);
345             }
346         }
347 
348         return socialEquityLog;
349     }
350 
351     public List<SocialEquityLog> findByAEI_T_A(long assetEntryId, int type,
352         boolean active) throws SystemException {
353         return findByAEI_T_A(assetEntryId, type, active, QueryUtil.ALL_POS,
354             QueryUtil.ALL_POS, null);
355     }
356 
357     public List<SocialEquityLog> findByAEI_T_A(long assetEntryId, int type,
358         boolean active, int start, int end) throws SystemException {
359         return findByAEI_T_A(assetEntryId, type, active, start, end, null);
360     }
361 
362     public List<SocialEquityLog> findByAEI_T_A(long assetEntryId, int type,
363         boolean active, int start, int end, OrderByComparator orderByComparator)
364         throws SystemException {
365         Object[] finderArgs = new Object[] {
366                 new Long(assetEntryId), new Integer(type),
367                 Boolean.valueOf(active),
368                 
369                 String.valueOf(start), String.valueOf(end),
370                 String.valueOf(orderByComparator)
371             };
372 
373         List<SocialEquityLog> list = (List<SocialEquityLog>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_AEI_T_A,
374                 finderArgs, this);
375 
376         if (list == null) {
377             Session session = null;
378 
379             try {
380                 session = openSession();
381 
382                 StringBundler query = null;
383 
384                 if (orderByComparator != null) {
385                     query = new StringBundler(5 +
386                             (orderByComparator.getOrderByFields().length * 3));
387                 }
388                 else {
389                     query = new StringBundler(4);
390                 }
391 
392                 query.append(_SQL_SELECT_SOCIALEQUITYLOG_WHERE);
393 
394                 query.append(_FINDER_COLUMN_AEI_T_A_ASSETENTRYID_2);
395 
396                 query.append(_FINDER_COLUMN_AEI_T_A_TYPE_2);
397 
398                 query.append(_FINDER_COLUMN_AEI_T_A_ACTIVE_2);
399 
400                 if (orderByComparator != null) {
401                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
402                         orderByComparator);
403                 }
404 
405                 String sql = query.toString();
406 
407                 Query q = session.createQuery(sql);
408 
409                 QueryPos qPos = QueryPos.getInstance(q);
410 
411                 qPos.add(assetEntryId);
412 
413                 qPos.add(type);
414 
415                 qPos.add(active);
416 
417                 list = (List<SocialEquityLog>)QueryUtil.list(q, getDialect(),
418                         start, end);
419             }
420             catch (Exception e) {
421                 throw processException(e);
422             }
423             finally {
424                 if (list == null) {
425                     list = new ArrayList<SocialEquityLog>();
426                 }
427 
428                 cacheResult(list);
429 
430                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_AEI_T_A,
431                     finderArgs, list);
432 
433                 closeSession(session);
434             }
435         }
436 
437         return list;
438     }
439 
440     public SocialEquityLog findByAEI_T_A_First(long assetEntryId, int type,
441         boolean active, OrderByComparator orderByComparator)
442         throws NoSuchEquityLogException, SystemException {
443         List<SocialEquityLog> list = findByAEI_T_A(assetEntryId, type, active,
444                 0, 1, orderByComparator);
445 
446         if (list.isEmpty()) {
447             StringBundler msg = new StringBundler(8);
448 
449             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
450 
451             msg.append("assetEntryId=");
452             msg.append(assetEntryId);
453 
454             msg.append(", type=");
455             msg.append(type);
456 
457             msg.append(", active=");
458             msg.append(active);
459 
460             msg.append(StringPool.CLOSE_CURLY_BRACE);
461 
462             throw new NoSuchEquityLogException(msg.toString());
463         }
464         else {
465             return list.get(0);
466         }
467     }
468 
469     public SocialEquityLog findByAEI_T_A_Last(long assetEntryId, int type,
470         boolean active, OrderByComparator orderByComparator)
471         throws NoSuchEquityLogException, SystemException {
472         int count = countByAEI_T_A(assetEntryId, type, active);
473 
474         List<SocialEquityLog> list = findByAEI_T_A(assetEntryId, type, active,
475                 count - 1, count, orderByComparator);
476 
477         if (list.isEmpty()) {
478             StringBundler msg = new StringBundler(8);
479 
480             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
481 
482             msg.append("assetEntryId=");
483             msg.append(assetEntryId);
484 
485             msg.append(", type=");
486             msg.append(type);
487 
488             msg.append(", active=");
489             msg.append(active);
490 
491             msg.append(StringPool.CLOSE_CURLY_BRACE);
492 
493             throw new NoSuchEquityLogException(msg.toString());
494         }
495         else {
496             return list.get(0);
497         }
498     }
499 
500     public SocialEquityLog[] findByAEI_T_A_PrevAndNext(long equityLogId,
501         long assetEntryId, int type, boolean active,
502         OrderByComparator orderByComparator)
503         throws NoSuchEquityLogException, SystemException {
504         SocialEquityLog socialEquityLog = findByPrimaryKey(equityLogId);
505 
506         Session session = null;
507 
508         try {
509             session = openSession();
510 
511             SocialEquityLog[] array = new SocialEquityLogImpl[3];
512 
513             array[0] = getByAEI_T_A_PrevAndNext(session, socialEquityLog,
514                     assetEntryId, type, active, orderByComparator, true);
515 
516             array[1] = socialEquityLog;
517 
518             array[2] = getByAEI_T_A_PrevAndNext(session, socialEquityLog,
519                     assetEntryId, type, active, orderByComparator, false);
520 
521             return array;
522         }
523         catch (Exception e) {
524             throw processException(e);
525         }
526         finally {
527             closeSession(session);
528         }
529     }
530 
531     protected SocialEquityLog getByAEI_T_A_PrevAndNext(Session session,
532         SocialEquityLog socialEquityLog, long assetEntryId, int type,
533         boolean active, OrderByComparator orderByComparator, boolean previous) {
534         StringBundler query = null;
535 
536         if (orderByComparator != null) {
537             query = new StringBundler(6 +
538                     (orderByComparator.getOrderByFields().length * 6));
539         }
540         else {
541             query = new StringBundler(3);
542         }
543 
544         query.append(_SQL_SELECT_SOCIALEQUITYLOG_WHERE);
545 
546         query.append(_FINDER_COLUMN_AEI_T_A_ASSETENTRYID_2);
547 
548         query.append(_FINDER_COLUMN_AEI_T_A_TYPE_2);
549 
550         query.append(_FINDER_COLUMN_AEI_T_A_ACTIVE_2);
551 
552         if (orderByComparator != null) {
553             String[] orderByFields = orderByComparator.getOrderByFields();
554 
555             if (orderByFields.length > 0) {
556                 query.append(WHERE_AND);
557             }
558 
559             for (int i = 0; i < orderByFields.length; i++) {
560                 query.append(_ORDER_BY_ENTITY_ALIAS);
561                 query.append(orderByFields[i]);
562 
563                 if ((i + 1) < orderByFields.length) {
564                     if (orderByComparator.isAscending() ^ previous) {
565                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
566                     }
567                     else {
568                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
569                     }
570                 }
571                 else {
572                     if (orderByComparator.isAscending() ^ previous) {
573                         query.append(WHERE_GREATER_THAN);
574                     }
575                     else {
576                         query.append(WHERE_LESSER_THAN);
577                     }
578                 }
579             }
580 
581             query.append(ORDER_BY_CLAUSE);
582 
583             for (int i = 0; i < orderByFields.length; i++) {
584                 query.append(_ORDER_BY_ENTITY_ALIAS);
585                 query.append(orderByFields[i]);
586 
587                 if ((i + 1) < orderByFields.length) {
588                     if (orderByComparator.isAscending() ^ previous) {
589                         query.append(ORDER_BY_ASC_HAS_NEXT);
590                     }
591                     else {
592                         query.append(ORDER_BY_DESC_HAS_NEXT);
593                     }
594                 }
595                 else {
596                     if (orderByComparator.isAscending() ^ previous) {
597                         query.append(ORDER_BY_ASC);
598                     }
599                     else {
600                         query.append(ORDER_BY_DESC);
601                     }
602                 }
603             }
604         }
605 
606         String sql = query.toString();
607 
608         Query q = session.createQuery(sql);
609 
610         q.setFirstResult(0);
611         q.setMaxResults(2);
612 
613         QueryPos qPos = QueryPos.getInstance(q);
614 
615         qPos.add(assetEntryId);
616 
617         qPos.add(type);
618 
619         qPos.add(active);
620 
621         if (orderByComparator != null) {
622             Object[] values = orderByComparator.getOrderByValues(socialEquityLog);
623 
624             for (Object value : values) {
625                 qPos.add(value);
626             }
627         }
628 
629         List<SocialEquityLog> list = q.list();
630 
631         if (list.size() == 2) {
632             return list.get(1);
633         }
634         else {
635             return null;
636         }
637     }
638 
639     public List<SocialEquityLog> findByU_AEI_A_A(long userId,
640         long assetEntryId, String actionId, boolean active)
641         throws SystemException {
642         return findByU_AEI_A_A(userId, assetEntryId, actionId, active,
643             QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
644     }
645 
646     public List<SocialEquityLog> findByU_AEI_A_A(long userId,
647         long assetEntryId, String actionId, boolean active, int start, int end)
648         throws SystemException {
649         return findByU_AEI_A_A(userId, assetEntryId, actionId, active, start,
650             end, null);
651     }
652 
653     public List<SocialEquityLog> findByU_AEI_A_A(long userId,
654         long assetEntryId, String actionId, boolean active, int start, int end,
655         OrderByComparator orderByComparator) throws SystemException {
656         Object[] finderArgs = new Object[] {
657                 new Long(userId), new Long(assetEntryId),
658                 
659                 actionId, Boolean.valueOf(active),
660                 
661                 String.valueOf(start), String.valueOf(end),
662                 String.valueOf(orderByComparator)
663             };
664 
665         List<SocialEquityLog> list = (List<SocialEquityLog>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_AEI_A_A,
666                 finderArgs, this);
667 
668         if (list == null) {
669             Session session = null;
670 
671             try {
672                 session = openSession();
673 
674                 StringBundler query = null;
675 
676                 if (orderByComparator != null) {
677                     query = new StringBundler(6 +
678                             (orderByComparator.getOrderByFields().length * 3));
679                 }
680                 else {
681                     query = new StringBundler(5);
682                 }
683 
684                 query.append(_SQL_SELECT_SOCIALEQUITYLOG_WHERE);
685 
686                 query.append(_FINDER_COLUMN_U_AEI_A_A_USERID_2);
687 
688                 query.append(_FINDER_COLUMN_U_AEI_A_A_ASSETENTRYID_2);
689 
690                 if (actionId == null) {
691                     query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIONID_1);
692                 }
693                 else {
694                     if (actionId.equals(StringPool.BLANK)) {
695                         query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIONID_3);
696                     }
697                     else {
698                         query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIONID_2);
699                     }
700                 }
701 
702                 query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIVE_2);
703 
704                 if (orderByComparator != null) {
705                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
706                         orderByComparator);
707                 }
708 
709                 String sql = query.toString();
710 
711                 Query q = session.createQuery(sql);
712 
713                 QueryPos qPos = QueryPos.getInstance(q);
714 
715                 qPos.add(userId);
716 
717                 qPos.add(assetEntryId);
718 
719                 if (actionId != null) {
720                     qPos.add(actionId);
721                 }
722 
723                 qPos.add(active);
724 
725                 list = (List<SocialEquityLog>)QueryUtil.list(q, getDialect(),
726                         start, end);
727             }
728             catch (Exception e) {
729                 throw processException(e);
730             }
731             finally {
732                 if (list == null) {
733                     list = new ArrayList<SocialEquityLog>();
734                 }
735 
736                 cacheResult(list);
737 
738                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_AEI_A_A,
739                     finderArgs, list);
740 
741                 closeSession(session);
742             }
743         }
744 
745         return list;
746     }
747 
748     public SocialEquityLog findByU_AEI_A_A_First(long userId,
749         long assetEntryId, String actionId, boolean active,
750         OrderByComparator orderByComparator)
751         throws NoSuchEquityLogException, SystemException {
752         List<SocialEquityLog> list = findByU_AEI_A_A(userId, assetEntryId,
753                 actionId, active, 0, 1, orderByComparator);
754 
755         if (list.isEmpty()) {
756             StringBundler msg = new StringBundler(10);
757 
758             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
759 
760             msg.append("userId=");
761             msg.append(userId);
762 
763             msg.append(", assetEntryId=");
764             msg.append(assetEntryId);
765 
766             msg.append(", actionId=");
767             msg.append(actionId);
768 
769             msg.append(", active=");
770             msg.append(active);
771 
772             msg.append(StringPool.CLOSE_CURLY_BRACE);
773 
774             throw new NoSuchEquityLogException(msg.toString());
775         }
776         else {
777             return list.get(0);
778         }
779     }
780 
781     public SocialEquityLog findByU_AEI_A_A_Last(long userId, long assetEntryId,
782         String actionId, boolean active, OrderByComparator orderByComparator)
783         throws NoSuchEquityLogException, SystemException {
784         int count = countByU_AEI_A_A(userId, assetEntryId, actionId, active);
785 
786         List<SocialEquityLog> list = findByU_AEI_A_A(userId, assetEntryId,
787                 actionId, active, count - 1, count, orderByComparator);
788 
789         if (list.isEmpty()) {
790             StringBundler msg = new StringBundler(10);
791 
792             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
793 
794             msg.append("userId=");
795             msg.append(userId);
796 
797             msg.append(", assetEntryId=");
798             msg.append(assetEntryId);
799 
800             msg.append(", actionId=");
801             msg.append(actionId);
802 
803             msg.append(", active=");
804             msg.append(active);
805 
806             msg.append(StringPool.CLOSE_CURLY_BRACE);
807 
808             throw new NoSuchEquityLogException(msg.toString());
809         }
810         else {
811             return list.get(0);
812         }
813     }
814 
815     public SocialEquityLog[] findByU_AEI_A_A_PrevAndNext(long equityLogId,
816         long userId, long assetEntryId, String actionId, boolean active,
817         OrderByComparator orderByComparator)
818         throws NoSuchEquityLogException, SystemException {
819         SocialEquityLog socialEquityLog = findByPrimaryKey(equityLogId);
820 
821         Session session = null;
822 
823         try {
824             session = openSession();
825 
826             SocialEquityLog[] array = new SocialEquityLogImpl[3];
827 
828             array[0] = getByU_AEI_A_A_PrevAndNext(session, socialEquityLog,
829                     userId, assetEntryId, actionId, active, orderByComparator,
830                     true);
831 
832             array[1] = socialEquityLog;
833 
834             array[2] = getByU_AEI_A_A_PrevAndNext(session, socialEquityLog,
835                     userId, assetEntryId, actionId, active, orderByComparator,
836                     false);
837 
838             return array;
839         }
840         catch (Exception e) {
841             throw processException(e);
842         }
843         finally {
844             closeSession(session);
845         }
846     }
847 
848     protected SocialEquityLog getByU_AEI_A_A_PrevAndNext(Session session,
849         SocialEquityLog socialEquityLog, long userId, long assetEntryId,
850         String actionId, boolean active, OrderByComparator orderByComparator,
851         boolean previous) {
852         StringBundler query = null;
853 
854         if (orderByComparator != null) {
855             query = new StringBundler(6 +
856                     (orderByComparator.getOrderByFields().length * 6));
857         }
858         else {
859             query = new StringBundler(3);
860         }
861 
862         query.append(_SQL_SELECT_SOCIALEQUITYLOG_WHERE);
863 
864         query.append(_FINDER_COLUMN_U_AEI_A_A_USERID_2);
865 
866         query.append(_FINDER_COLUMN_U_AEI_A_A_ASSETENTRYID_2);
867 
868         if (actionId == null) {
869             query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIONID_1);
870         }
871         else {
872             if (actionId.equals(StringPool.BLANK)) {
873                 query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIONID_3);
874             }
875             else {
876                 query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIONID_2);
877             }
878         }
879 
880         query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIVE_2);
881 
882         if (orderByComparator != null) {
883             String[] orderByFields = orderByComparator.getOrderByFields();
884 
885             if (orderByFields.length > 0) {
886                 query.append(WHERE_AND);
887             }
888 
889             for (int i = 0; i < orderByFields.length; i++) {
890                 query.append(_ORDER_BY_ENTITY_ALIAS);
891                 query.append(orderByFields[i]);
892 
893                 if ((i + 1) < orderByFields.length) {
894                     if (orderByComparator.isAscending() ^ previous) {
895                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
896                     }
897                     else {
898                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
899                     }
900                 }
901                 else {
902                     if (orderByComparator.isAscending() ^ previous) {
903                         query.append(WHERE_GREATER_THAN);
904                     }
905                     else {
906                         query.append(WHERE_LESSER_THAN);
907                     }
908                 }
909             }
910 
911             query.append(ORDER_BY_CLAUSE);
912 
913             for (int i = 0; i < orderByFields.length; i++) {
914                 query.append(_ORDER_BY_ENTITY_ALIAS);
915                 query.append(orderByFields[i]);
916 
917                 if ((i + 1) < orderByFields.length) {
918                     if (orderByComparator.isAscending() ^ previous) {
919                         query.append(ORDER_BY_ASC_HAS_NEXT);
920                     }
921                     else {
922                         query.append(ORDER_BY_DESC_HAS_NEXT);
923                     }
924                 }
925                 else {
926                     if (orderByComparator.isAscending() ^ previous) {
927                         query.append(ORDER_BY_ASC);
928                     }
929                     else {
930                         query.append(ORDER_BY_DESC);
931                     }
932                 }
933             }
934         }
935 
936         String sql = query.toString();
937 
938         Query q = session.createQuery(sql);
939 
940         q.setFirstResult(0);
941         q.setMaxResults(2);
942 
943         QueryPos qPos = QueryPos.getInstance(q);
944 
945         qPos.add(userId);
946 
947         qPos.add(assetEntryId);
948 
949         if (actionId != null) {
950             qPos.add(actionId);
951         }
952 
953         qPos.add(active);
954 
955         if (orderByComparator != null) {
956             Object[] values = orderByComparator.getOrderByValues(socialEquityLog);
957 
958             for (Object value : values) {
959                 qPos.add(value);
960             }
961         }
962 
963         List<SocialEquityLog> list = q.list();
964 
965         if (list.size() == 2) {
966             return list.get(1);
967         }
968         else {
969             return null;
970         }
971     }
972 
973     public List<SocialEquityLog> findAll() throws SystemException {
974         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
975     }
976 
977     public List<SocialEquityLog> findAll(int start, int end)
978         throws SystemException {
979         return findAll(start, end, null);
980     }
981 
982     public List<SocialEquityLog> findAll(int start, int end,
983         OrderByComparator orderByComparator) throws SystemException {
984         Object[] finderArgs = new Object[] {
985                 String.valueOf(start), String.valueOf(end),
986                 String.valueOf(orderByComparator)
987             };
988 
989         List<SocialEquityLog> list = (List<SocialEquityLog>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
990                 finderArgs, this);
991 
992         if (list == null) {
993             Session session = null;
994 
995             try {
996                 session = openSession();
997 
998                 StringBundler query = null;
999                 String sql = null;
1000
1001                if (orderByComparator != null) {
1002                    query = new StringBundler(2 +
1003                            (orderByComparator.getOrderByFields().length * 3));
1004
1005                    query.append(_SQL_SELECT_SOCIALEQUITYLOG);
1006
1007                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1008                        orderByComparator);
1009
1010                    sql = query.toString();
1011                }
1012
1013                sql = _SQL_SELECT_SOCIALEQUITYLOG;
1014
1015                Query q = session.createQuery(sql);
1016
1017                if (orderByComparator == null) {
1018                    list = (List<SocialEquityLog>)QueryUtil.list(q,
1019                            getDialect(), start, end, false);
1020
1021                    Collections.sort(list);
1022                }
1023                else {
1024                    list = (List<SocialEquityLog>)QueryUtil.list(q,
1025                            getDialect(), start, end);
1026                }
1027            }
1028            catch (Exception e) {
1029                throw processException(e);
1030            }
1031            finally {
1032                if (list == null) {
1033                    list = new ArrayList<SocialEquityLog>();
1034                }
1035
1036                cacheResult(list);
1037
1038                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1039
1040                closeSession(session);
1041            }
1042        }
1043
1044        return list;
1045    }
1046
1047    public void removeByAEI_T_A(long assetEntryId, int type, boolean active)
1048        throws SystemException {
1049        for (SocialEquityLog socialEquityLog : findByAEI_T_A(assetEntryId,
1050                type, active)) {
1051            remove(socialEquityLog);
1052        }
1053    }
1054
1055    public void removeByU_AEI_A_A(long userId, long assetEntryId,
1056        String actionId, boolean active) throws SystemException {
1057        for (SocialEquityLog socialEquityLog : findByU_AEI_A_A(userId,
1058                assetEntryId, actionId, active)) {
1059            remove(socialEquityLog);
1060        }
1061    }
1062
1063    public void removeAll() throws SystemException {
1064        for (SocialEquityLog socialEquityLog : findAll()) {
1065            remove(socialEquityLog);
1066        }
1067    }
1068
1069    public int countByAEI_T_A(long assetEntryId, int type, boolean active)
1070        throws SystemException {
1071        Object[] finderArgs = new Object[] {
1072                new Long(assetEntryId), new Integer(type),
1073                Boolean.valueOf(active)
1074            };
1075
1076        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_AEI_T_A,
1077                finderArgs, this);
1078
1079        if (count == null) {
1080            Session session = null;
1081
1082            try {
1083                session = openSession();
1084
1085                StringBundler query = new StringBundler(4);
1086
1087                query.append(_SQL_COUNT_SOCIALEQUITYLOG_WHERE);
1088
1089                query.append(_FINDER_COLUMN_AEI_T_A_ASSETENTRYID_2);
1090
1091                query.append(_FINDER_COLUMN_AEI_T_A_TYPE_2);
1092
1093                query.append(_FINDER_COLUMN_AEI_T_A_ACTIVE_2);
1094
1095                String sql = query.toString();
1096
1097                Query q = session.createQuery(sql);
1098
1099                QueryPos qPos = QueryPos.getInstance(q);
1100
1101                qPos.add(assetEntryId);
1102
1103                qPos.add(type);
1104
1105                qPos.add(active);
1106
1107                count = (Long)q.uniqueResult();
1108            }
1109            catch (Exception e) {
1110                throw processException(e);
1111            }
1112            finally {
1113                if (count == null) {
1114                    count = Long.valueOf(0);
1115                }
1116
1117                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_AEI_T_A,
1118                    finderArgs, count);
1119
1120                closeSession(session);
1121            }
1122        }
1123
1124        return count.intValue();
1125    }
1126
1127    public int countByU_AEI_A_A(long userId, long assetEntryId,
1128        String actionId, boolean active) throws SystemException {
1129        Object[] finderArgs = new Object[] {
1130                new Long(userId), new Long(assetEntryId),
1131                
1132                actionId, Boolean.valueOf(active)
1133            };
1134
1135        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_AEI_A_A,
1136                finderArgs, this);
1137
1138        if (count == null) {
1139            Session session = null;
1140
1141            try {
1142                session = openSession();
1143
1144                StringBundler query = new StringBundler(5);
1145
1146                query.append(_SQL_COUNT_SOCIALEQUITYLOG_WHERE);
1147
1148                query.append(_FINDER_COLUMN_U_AEI_A_A_USERID_2);
1149
1150                query.append(_FINDER_COLUMN_U_AEI_A_A_ASSETENTRYID_2);
1151
1152                if (actionId == null) {
1153                    query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIONID_1);
1154                }
1155                else {
1156                    if (actionId.equals(StringPool.BLANK)) {
1157                        query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIONID_3);
1158                    }
1159                    else {
1160                        query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIONID_2);
1161                    }
1162                }
1163
1164                query.append(_FINDER_COLUMN_U_AEI_A_A_ACTIVE_2);
1165
1166                String sql = query.toString();
1167
1168                Query q = session.createQuery(sql);
1169
1170                QueryPos qPos = QueryPos.getInstance(q);
1171
1172                qPos.add(userId);
1173
1174                qPos.add(assetEntryId);
1175
1176                if (actionId != null) {
1177                    qPos.add(actionId);
1178                }
1179
1180                qPos.add(active);
1181
1182                count = (Long)q.uniqueResult();
1183            }
1184            catch (Exception e) {
1185                throw processException(e);
1186            }
1187            finally {
1188                if (count == null) {
1189                    count = Long.valueOf(0);
1190                }
1191
1192                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_AEI_A_A,
1193                    finderArgs, count);
1194
1195                closeSession(session);
1196            }
1197        }
1198
1199        return count.intValue();
1200    }
1201
1202    public int countAll() throws SystemException {
1203        Object[] finderArgs = new Object[0];
1204
1205        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1206                finderArgs, this);
1207
1208        if (count == null) {
1209            Session session = null;
1210
1211            try {
1212                session = openSession();
1213
1214                Query q = session.createQuery(_SQL_COUNT_SOCIALEQUITYLOG);
1215
1216                count = (Long)q.uniqueResult();
1217            }
1218            catch (Exception e) {
1219                throw processException(e);
1220            }
1221            finally {
1222                if (count == null) {
1223                    count = Long.valueOf(0);
1224                }
1225
1226                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1227                    count);
1228
1229                closeSession(session);
1230            }
1231        }
1232
1233        return count.intValue();
1234    }
1235
1236    public void afterPropertiesSet() {
1237        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1238                    com.liferay.portal.util.PropsUtil.get(
1239                        "value.object.listener.com.liferay.portlet.social.model.SocialEquityLog")));
1240
1241        if (listenerClassNames.length > 0) {
1242            try {
1243                List<ModelListener<SocialEquityLog>> listenersList = new ArrayList<ModelListener<SocialEquityLog>>();
1244
1245                for (String listenerClassName : listenerClassNames) {
1246                    listenersList.add((ModelListener<SocialEquityLog>)InstanceFactory.newInstance(
1247                            listenerClassName));
1248                }
1249
1250                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1251            }
1252            catch (Exception e) {
1253                _log.error(e);
1254            }
1255        }
1256    }
1257
1258    @BeanReference(type = SocialActivityPersistence.class)
1259    protected SocialActivityPersistence socialActivityPersistence;
1260    @BeanReference(type = SocialEquityAssetEntryPersistence.class)
1261    protected SocialEquityAssetEntryPersistence socialEquityAssetEntryPersistence;
1262    @BeanReference(type = SocialEquityHistoryPersistence.class)
1263    protected SocialEquityHistoryPersistence socialEquityHistoryPersistence;
1264    @BeanReference(type = SocialEquityLogPersistence.class)
1265    protected SocialEquityLogPersistence socialEquityLogPersistence;
1266    @BeanReference(type = SocialEquitySettingPersistence.class)
1267    protected SocialEquitySettingPersistence socialEquitySettingPersistence;
1268    @BeanReference(type = SocialEquityUserPersistence.class)
1269    protected SocialEquityUserPersistence socialEquityUserPersistence;
1270    @BeanReference(type = SocialRelationPersistence.class)
1271    protected SocialRelationPersistence socialRelationPersistence;
1272    @BeanReference(type = SocialRequestPersistence.class)
1273    protected SocialRequestPersistence socialRequestPersistence;
1274    @BeanReference(type = ResourcePersistence.class)
1275    protected ResourcePersistence resourcePersistence;
1276    @BeanReference(type = UserPersistence.class)
1277    protected UserPersistence userPersistence;
1278    @BeanReference(type = AssetEntryPersistence.class)
1279    protected AssetEntryPersistence assetEntryPersistence;
1280    private static final String _SQL_SELECT_SOCIALEQUITYLOG = "SELECT socialEquityLog FROM SocialEquityLog socialEquityLog";
1281    private static final String _SQL_SELECT_SOCIALEQUITYLOG_WHERE = "SELECT socialEquityLog FROM SocialEquityLog socialEquityLog WHERE ";
1282    private static final String _SQL_COUNT_SOCIALEQUITYLOG = "SELECT COUNT(socialEquityLog) FROM SocialEquityLog socialEquityLog";
1283    private static final String _SQL_COUNT_SOCIALEQUITYLOG_WHERE = "SELECT COUNT(socialEquityLog) FROM SocialEquityLog socialEquityLog WHERE ";
1284    private static final String _FINDER_COLUMN_AEI_T_A_ASSETENTRYID_2 = "socialEquityLog.assetEntryId = ? AND ";
1285    private static final String _FINDER_COLUMN_AEI_T_A_TYPE_2 = "socialEquityLog.type = ? AND ";
1286    private static final String _FINDER_COLUMN_AEI_T_A_ACTIVE_2 = "socialEquityLog.active = ?";
1287    private static final String _FINDER_COLUMN_U_AEI_A_A_USERID_2 = "socialEquityLog.userId = ? AND ";
1288    private static final String _FINDER_COLUMN_U_AEI_A_A_ASSETENTRYID_2 = "socialEquityLog.assetEntryId = ? AND ";
1289    private static final String _FINDER_COLUMN_U_AEI_A_A_ACTIONID_1 = "socialEquityLog.actionId IS NULL AND ";
1290    private static final String _FINDER_COLUMN_U_AEI_A_A_ACTIONID_2 = "socialEquityLog.actionId = ? AND ";
1291    private static final String _FINDER_COLUMN_U_AEI_A_A_ACTIONID_3 = "(socialEquityLog.actionId IS NULL OR socialEquityLog.actionId = ?) AND ";
1292    private static final String _FINDER_COLUMN_U_AEI_A_A_ACTIVE_2 = "socialEquityLog.active = ?";
1293    private static final String _ORDER_BY_ENTITY_ALIAS = "socialEquityLog.";
1294    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialEquityLog exists with the primary key ";
1295    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialEquityLog exists with the key {";
1296    private static Log _log = LogFactoryUtil.getLog(SocialEquityLogPersistenceImpl.class);
1297}