1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.tasks.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.annotation.BeanReference;
27  import com.liferay.portal.kernel.cache.CacheRegistry;
28  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
30  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderPath;
32  import com.liferay.portal.kernel.dao.orm.Query;
33  import com.liferay.portal.kernel.dao.orm.QueryPos;
34  import com.liferay.portal.kernel.dao.orm.QueryUtil;
35  import com.liferay.portal.kernel.dao.orm.Session;
36  import com.liferay.portal.kernel.log.Log;
37  import com.liferay.portal.kernel.log.LogFactoryUtil;
38  import com.liferay.portal.kernel.util.GetterUtil;
39  import com.liferay.portal.kernel.util.OrderByComparator;
40  import com.liferay.portal.kernel.util.StringPool;
41  import com.liferay.portal.kernel.util.StringUtil;
42  import com.liferay.portal.model.ModelListener;
43  import com.liferay.portal.service.persistence.BatchSessionUtil;
44  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45  
46  import com.liferay.portlet.tasks.NoSuchProposalException;
47  import com.liferay.portlet.tasks.model.TasksProposal;
48  import com.liferay.portlet.tasks.model.impl.TasksProposalImpl;
49  import com.liferay.portlet.tasks.model.impl.TasksProposalModelImpl;
50  
51  import java.util.ArrayList;
52  import java.util.Collections;
53  import java.util.List;
54  
55  /**
56   * <a href="TasksProposalPersistenceImpl.java.html"><b><i>View Source</i></b></a>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   */
61  public class TasksProposalPersistenceImpl extends BasePersistenceImpl
62      implements TasksProposalPersistence {
63      public static final String FINDER_CLASS_NAME_ENTITY = TasksProposalImpl.class.getName();
64      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
65          ".List";
66      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
67              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
68              FINDER_CLASS_NAME_LIST, "findByGroupId",
69              new String[] { Long.class.getName() });
70      public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
71              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
72              FINDER_CLASS_NAME_LIST, "findByGroupId",
73              new String[] {
74                  Long.class.getName(),
75                  
76              "java.lang.Integer", "java.lang.Integer",
77                  "com.liferay.portal.kernel.util.OrderByComparator"
78              });
79      public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
80              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
81              FINDER_CLASS_NAME_LIST, "countByGroupId",
82              new String[] { Long.class.getName() });
83      public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
84              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
85              FINDER_CLASS_NAME_LIST, "findByG_U",
86              new String[] { Long.class.getName(), Long.class.getName() });
87      public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_U = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
88              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
89              FINDER_CLASS_NAME_LIST, "findByG_U",
90              new String[] {
91                  Long.class.getName(), Long.class.getName(),
92                  
93              "java.lang.Integer", "java.lang.Integer",
94                  "com.liferay.portal.kernel.util.OrderByComparator"
95              });
96      public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
97              TasksProposalModelImpl.FINDER_CACHE_ENABLED,
98              FINDER_CLASS_NAME_LIST, "countByG_U",
99              new String[] { Long.class.getName(), Long.class.getName() });
100     public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
101             TasksProposalModelImpl.FINDER_CACHE_ENABLED,
102             FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
103             new String[] { Long.class.getName(), String.class.getName() });
104     public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
105             TasksProposalModelImpl.FINDER_CACHE_ENABLED,
106             FINDER_CLASS_NAME_LIST, "countByC_C",
107             new String[] { Long.class.getName(), String.class.getName() });
108     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
109             TasksProposalModelImpl.FINDER_CACHE_ENABLED,
110             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
111     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
112             TasksProposalModelImpl.FINDER_CACHE_ENABLED,
113             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
114 
115     public void cacheResult(TasksProposal tasksProposal) {
116         EntityCacheUtil.putResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
117             TasksProposalImpl.class, tasksProposal.getPrimaryKey(),
118             tasksProposal);
119 
120         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
121             new Object[] {
122                 new Long(tasksProposal.getClassNameId()),
123                 
124             tasksProposal.getClassPK()
125             }, tasksProposal);
126     }
127 
128     public void cacheResult(List<TasksProposal> tasksProposals) {
129         for (TasksProposal tasksProposal : tasksProposals) {
130             if (EntityCacheUtil.getResult(
131                         TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
132                         TasksProposalImpl.class, tasksProposal.getPrimaryKey(),
133                         this) == null) {
134                 cacheResult(tasksProposal);
135             }
136         }
137     }
138 
139     public void clearCache() {
140         CacheRegistry.clear(TasksProposalImpl.class.getName());
141         EntityCacheUtil.clearCache(TasksProposalImpl.class.getName());
142         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
143         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
144     }
145 
146     public TasksProposal create(long proposalId) {
147         TasksProposal tasksProposal = new TasksProposalImpl();
148 
149         tasksProposal.setNew(true);
150         tasksProposal.setPrimaryKey(proposalId);
151 
152         return tasksProposal;
153     }
154 
155     public TasksProposal remove(long proposalId)
156         throws NoSuchProposalException, SystemException {
157         Session session = null;
158 
159         try {
160             session = openSession();
161 
162             TasksProposal tasksProposal = (TasksProposal)session.get(TasksProposalImpl.class,
163                     new Long(proposalId));
164 
165             if (tasksProposal == null) {
166                 if (_log.isWarnEnabled()) {
167                     _log.warn("No TasksProposal exists with the primary key " +
168                         proposalId);
169                 }
170 
171                 throw new NoSuchProposalException(
172                     "No TasksProposal exists with the primary key " +
173                     proposalId);
174             }
175 
176             return remove(tasksProposal);
177         }
178         catch (NoSuchProposalException nsee) {
179             throw nsee;
180         }
181         catch (Exception e) {
182             throw processException(e);
183         }
184         finally {
185             closeSession(session);
186         }
187     }
188 
189     public TasksProposal remove(TasksProposal tasksProposal)
190         throws SystemException {
191         for (ModelListener<TasksProposal> listener : listeners) {
192             listener.onBeforeRemove(tasksProposal);
193         }
194 
195         tasksProposal = removeImpl(tasksProposal);
196 
197         for (ModelListener<TasksProposal> listener : listeners) {
198             listener.onAfterRemove(tasksProposal);
199         }
200 
201         return tasksProposal;
202     }
203 
204     protected TasksProposal removeImpl(TasksProposal tasksProposal)
205         throws SystemException {
206         Session session = null;
207 
208         try {
209             session = openSession();
210 
211             if (tasksProposal.isCachedModel() || BatchSessionUtil.isEnabled()) {
212                 Object staleObject = session.get(TasksProposalImpl.class,
213                         tasksProposal.getPrimaryKeyObj());
214 
215                 if (staleObject != null) {
216                     session.evict(staleObject);
217                 }
218             }
219 
220             session.delete(tasksProposal);
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         TasksProposalModelImpl tasksProposalModelImpl = (TasksProposalModelImpl)tasksProposal;
234 
235         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
236             new Object[] {
237                 new Long(tasksProposalModelImpl.getOriginalClassNameId()),
238                 
239             tasksProposalModelImpl.getOriginalClassPK()
240             });
241 
242         EntityCacheUtil.removeResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
243             TasksProposalImpl.class, tasksProposal.getPrimaryKey());
244 
245         return tasksProposal;
246     }
247 
248     /**
249      * @deprecated Use <code>update(TasksProposal tasksProposal, boolean merge)</code>.
250      */
251     public TasksProposal update(TasksProposal tasksProposal)
252         throws SystemException {
253         if (_log.isWarnEnabled()) {
254             _log.warn(
255                 "Using the deprecated update(TasksProposal tasksProposal) method. Use update(TasksProposal tasksProposal, boolean merge) instead.");
256         }
257 
258         return update(tasksProposal, false);
259     }
260 
261     /**
262      * Add, update, or merge, the entity. This method also calls the model
263      * listeners to trigger the proper events associated with adding, deleting,
264      * or updating an entity.
265      *
266      * @param        tasksProposal the entity to add, update, or merge
267      * @param        merge boolean value for whether to merge the entity. The
268      *                default value is false. Setting merge to true is more
269      *                expensive and should only be true when tasksProposal is
270      *                transient. See LEP-5473 for a detailed discussion of this
271      *                method.
272      * @return        true if the portlet can be displayed via Ajax
273      */
274     public TasksProposal update(TasksProposal tasksProposal, boolean merge)
275         throws SystemException {
276         boolean isNew = tasksProposal.isNew();
277 
278         for (ModelListener<TasksProposal> listener : listeners) {
279             if (isNew) {
280                 listener.onBeforeCreate(tasksProposal);
281             }
282             else {
283                 listener.onBeforeUpdate(tasksProposal);
284             }
285         }
286 
287         tasksProposal = updateImpl(tasksProposal, merge);
288 
289         for (ModelListener<TasksProposal> listener : listeners) {
290             if (isNew) {
291                 listener.onAfterCreate(tasksProposal);
292             }
293             else {
294                 listener.onAfterUpdate(tasksProposal);
295             }
296         }
297 
298         return tasksProposal;
299     }
300 
301     public TasksProposal updateImpl(
302         com.liferay.portlet.tasks.model.TasksProposal tasksProposal,
303         boolean merge) throws SystemException {
304         boolean isNew = tasksProposal.isNew();
305 
306         TasksProposalModelImpl tasksProposalModelImpl = (TasksProposalModelImpl)tasksProposal;
307 
308         Session session = null;
309 
310         try {
311             session = openSession();
312 
313             BatchSessionUtil.update(session, tasksProposal, merge);
314 
315             tasksProposal.setNew(false);
316         }
317         catch (Exception e) {
318             throw processException(e);
319         }
320         finally {
321             closeSession(session);
322         }
323 
324         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
325 
326         EntityCacheUtil.putResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
327             TasksProposalImpl.class, tasksProposal.getPrimaryKey(),
328             tasksProposal);
329 
330         if (!isNew &&
331                 ((tasksProposal.getClassNameId() != tasksProposalModelImpl.getOriginalClassNameId()) ||
332                 !tasksProposal.getClassPK()
333                                   .equals(tasksProposalModelImpl.getOriginalClassPK()))) {
334             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
335                 new Object[] {
336                     new Long(tasksProposalModelImpl.getOriginalClassNameId()),
337                     
338                 tasksProposalModelImpl.getOriginalClassPK()
339                 });
340         }
341 
342         if (isNew ||
343                 ((tasksProposal.getClassNameId() != tasksProposalModelImpl.getOriginalClassNameId()) ||
344                 !tasksProposal.getClassPK()
345                                   .equals(tasksProposalModelImpl.getOriginalClassPK()))) {
346             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
347                 new Object[] {
348                     new Long(tasksProposal.getClassNameId()),
349                     
350                 tasksProposal.getClassPK()
351                 }, tasksProposal);
352         }
353 
354         return tasksProposal;
355     }
356 
357     public TasksProposal findByPrimaryKey(long proposalId)
358         throws NoSuchProposalException, SystemException {
359         TasksProposal tasksProposal = fetchByPrimaryKey(proposalId);
360 
361         if (tasksProposal == null) {
362             if (_log.isWarnEnabled()) {
363                 _log.warn("No TasksProposal exists with the primary key " +
364                     proposalId);
365             }
366 
367             throw new NoSuchProposalException(
368                 "No TasksProposal exists with the primary key " + proposalId);
369         }
370 
371         return tasksProposal;
372     }
373 
374     public TasksProposal fetchByPrimaryKey(long proposalId)
375         throws SystemException {
376         TasksProposal tasksProposal = (TasksProposal)EntityCacheUtil.getResult(TasksProposalModelImpl.ENTITY_CACHE_ENABLED,
377                 TasksProposalImpl.class, proposalId, this);
378 
379         if (tasksProposal == null) {
380             Session session = null;
381 
382             try {
383                 session = openSession();
384 
385                 tasksProposal = (TasksProposal)session.get(TasksProposalImpl.class,
386                         new Long(proposalId));
387             }
388             catch (Exception e) {
389                 throw processException(e);
390             }
391             finally {
392                 if (tasksProposal != null) {
393                     cacheResult(tasksProposal);
394                 }
395 
396                 closeSession(session);
397             }
398         }
399 
400         return tasksProposal;
401     }
402 
403     public List<TasksProposal> findByGroupId(long groupId)
404         throws SystemException {
405         Object[] finderArgs = new Object[] { new Long(groupId) };
406 
407         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
408                 finderArgs, this);
409 
410         if (list == null) {
411             Session session = null;
412 
413             try {
414                 session = openSession();
415 
416                 StringBuilder query = new StringBuilder();
417 
418                 query.append(
419                     "FROM com.liferay.portlet.tasks.model.TasksProposal WHERE ");
420 
421                 query.append("groupId = ?");
422 
423                 query.append(" ");
424 
425                 query.append("ORDER BY ");
426 
427                 query.append("dueDate ASC, ");
428                 query.append("createDate ASC");
429 
430                 Query q = session.createQuery(query.toString());
431 
432                 QueryPos qPos = QueryPos.getInstance(q);
433 
434                 qPos.add(groupId);
435 
436                 list = q.list();
437             }
438             catch (Exception e) {
439                 throw processException(e);
440             }
441             finally {
442                 if (list == null) {
443                     list = new ArrayList<TasksProposal>();
444                 }
445 
446                 cacheResult(list);
447 
448                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
449                     finderArgs, list);
450 
451                 closeSession(session);
452             }
453         }
454 
455         return list;
456     }
457 
458     public List<TasksProposal> findByGroupId(long groupId, int start, int end)
459         throws SystemException {
460         return findByGroupId(groupId, start, end, null);
461     }
462 
463     public List<TasksProposal> findByGroupId(long groupId, int start, int end,
464         OrderByComparator obc) throws SystemException {
465         Object[] finderArgs = new Object[] {
466                 new Long(groupId),
467                 
468                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
469             };
470 
471         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
472                 finderArgs, this);
473 
474         if (list == null) {
475             Session session = null;
476 
477             try {
478                 session = openSession();
479 
480                 StringBuilder query = new StringBuilder();
481 
482                 query.append(
483                     "FROM com.liferay.portlet.tasks.model.TasksProposal WHERE ");
484 
485                 query.append("groupId = ?");
486 
487                 query.append(" ");
488 
489                 if (obc != null) {
490                     query.append("ORDER BY ");
491                     query.append(obc.getOrderBy());
492                 }
493 
494                 else {
495                     query.append("ORDER BY ");
496 
497                     query.append("dueDate ASC, ");
498                     query.append("createDate ASC");
499                 }
500 
501                 Query q = session.createQuery(query.toString());
502 
503                 QueryPos qPos = QueryPos.getInstance(q);
504 
505                 qPos.add(groupId);
506 
507                 list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
508                         start, end);
509             }
510             catch (Exception e) {
511                 throw processException(e);
512             }
513             finally {
514                 if (list == null) {
515                     list = new ArrayList<TasksProposal>();
516                 }
517 
518                 cacheResult(list);
519 
520                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
521                     finderArgs, list);
522 
523                 closeSession(session);
524             }
525         }
526 
527         return list;
528     }
529 
530     public TasksProposal findByGroupId_First(long groupId, OrderByComparator obc)
531         throws NoSuchProposalException, SystemException {
532         List<TasksProposal> list = findByGroupId(groupId, 0, 1, obc);
533 
534         if (list.isEmpty()) {
535             StringBuilder msg = new StringBuilder();
536 
537             msg.append("No TasksProposal exists with the key {");
538 
539             msg.append("groupId=" + groupId);
540 
541             msg.append(StringPool.CLOSE_CURLY_BRACE);
542 
543             throw new NoSuchProposalException(msg.toString());
544         }
545         else {
546             return list.get(0);
547         }
548     }
549 
550     public TasksProposal findByGroupId_Last(long groupId, OrderByComparator obc)
551         throws NoSuchProposalException, SystemException {
552         int count = countByGroupId(groupId);
553 
554         List<TasksProposal> list = findByGroupId(groupId, count - 1, count, obc);
555 
556         if (list.isEmpty()) {
557             StringBuilder msg = new StringBuilder();
558 
559             msg.append("No TasksProposal exists with the key {");
560 
561             msg.append("groupId=" + groupId);
562 
563             msg.append(StringPool.CLOSE_CURLY_BRACE);
564 
565             throw new NoSuchProposalException(msg.toString());
566         }
567         else {
568             return list.get(0);
569         }
570     }
571 
572     public TasksProposal[] findByGroupId_PrevAndNext(long proposalId,
573         long groupId, OrderByComparator obc)
574         throws NoSuchProposalException, SystemException {
575         TasksProposal tasksProposal = findByPrimaryKey(proposalId);
576 
577         int count = countByGroupId(groupId);
578 
579         Session session = null;
580 
581         try {
582             session = openSession();
583 
584             StringBuilder query = new StringBuilder();
585 
586             query.append(
587                 "FROM com.liferay.portlet.tasks.model.TasksProposal WHERE ");
588 
589             query.append("groupId = ?");
590 
591             query.append(" ");
592 
593             if (obc != null) {
594                 query.append("ORDER BY ");
595                 query.append(obc.getOrderBy());
596             }
597 
598             else {
599                 query.append("ORDER BY ");
600 
601                 query.append("dueDate ASC, ");
602                 query.append("createDate ASC");
603             }
604 
605             Query q = session.createQuery(query.toString());
606 
607             QueryPos qPos = QueryPos.getInstance(q);
608 
609             qPos.add(groupId);
610 
611             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
612                     tasksProposal);
613 
614             TasksProposal[] array = new TasksProposalImpl[3];
615 
616             array[0] = (TasksProposal)objArray[0];
617             array[1] = (TasksProposal)objArray[1];
618             array[2] = (TasksProposal)objArray[2];
619 
620             return array;
621         }
622         catch (Exception e) {
623             throw processException(e);
624         }
625         finally {
626             closeSession(session);
627         }
628     }
629 
630     public List<TasksProposal> findByG_U(long groupId, long userId)
631         throws SystemException {
632         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
633 
634         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
635                 finderArgs, this);
636 
637         if (list == null) {
638             Session session = null;
639 
640             try {
641                 session = openSession();
642 
643                 StringBuilder query = new StringBuilder();
644 
645                 query.append(
646                     "FROM com.liferay.portlet.tasks.model.TasksProposal WHERE ");
647 
648                 query.append("groupId = ?");
649 
650                 query.append(" AND ");
651 
652                 query.append("userId = ?");
653 
654                 query.append(" ");
655 
656                 query.append("ORDER BY ");
657 
658                 query.append("dueDate ASC, ");
659                 query.append("createDate ASC");
660 
661                 Query q = session.createQuery(query.toString());
662 
663                 QueryPos qPos = QueryPos.getInstance(q);
664 
665                 qPos.add(groupId);
666 
667                 qPos.add(userId);
668 
669                 list = q.list();
670             }
671             catch (Exception e) {
672                 throw processException(e);
673             }
674             finally {
675                 if (list == null) {
676                     list = new ArrayList<TasksProposal>();
677                 }
678 
679                 cacheResult(list);
680 
681                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
682                     list);
683 
684                 closeSession(session);
685             }
686         }
687 
688         return list;
689     }
690 
691     public List<TasksProposal> findByG_U(long groupId, long userId, int start,
692         int end) throws SystemException {
693         return findByG_U(groupId, userId, start, end, null);
694     }
695 
696     public List<TasksProposal> findByG_U(long groupId, long userId, int start,
697         int end, OrderByComparator obc) throws SystemException {
698         Object[] finderArgs = new Object[] {
699                 new Long(groupId), new Long(userId),
700                 
701                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
702             };
703 
704         List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_U,
705                 finderArgs, this);
706 
707         if (list == null) {
708             Session session = null;
709 
710             try {
711                 session = openSession();
712 
713                 StringBuilder query = new StringBuilder();
714 
715                 query.append(
716                     "FROM com.liferay.portlet.tasks.model.TasksProposal WHERE ");
717 
718                 query.append("groupId = ?");
719 
720                 query.append(" AND ");
721 
722                 query.append("userId = ?");
723 
724                 query.append(" ");
725 
726                 if (obc != null) {
727                     query.append("ORDER BY ");
728                     query.append(obc.getOrderBy());
729                 }
730 
731                 else {
732                     query.append("ORDER BY ");
733 
734                     query.append("dueDate ASC, ");
735                     query.append("createDate ASC");
736                 }
737 
738                 Query q = session.createQuery(query.toString());
739 
740                 QueryPos qPos = QueryPos.getInstance(q);
741 
742                 qPos.add(groupId);
743 
744                 qPos.add(userId);
745 
746                 list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
747                         start, end);
748             }
749             catch (Exception e) {
750                 throw processException(e);
751             }
752             finally {
753                 if (list == null) {
754                     list = new ArrayList<TasksProposal>();
755                 }
756 
757                 cacheResult(list);
758 
759                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_U,
760                     finderArgs, list);
761 
762                 closeSession(session);
763             }
764         }
765 
766         return list;
767     }
768 
769     public TasksProposal findByG_U_First(long groupId, long userId,
770         OrderByComparator obc) throws NoSuchProposalException, SystemException {
771         List<TasksProposal> list = findByG_U(groupId, userId, 0, 1, obc);
772 
773         if (list.isEmpty()) {
774             StringBuilder msg = new StringBuilder();
775 
776             msg.append("No TasksProposal exists with the key {");
777 
778             msg.append("groupId=" + groupId);
779 
780             msg.append(", ");
781             msg.append("userId=" + userId);
782 
783             msg.append(StringPool.CLOSE_CURLY_BRACE);
784 
785             throw new NoSuchProposalException(msg.toString());
786         }
787         else {
788             return list.get(0);
789         }
790     }
791 
792     public TasksProposal findByG_U_Last(long groupId, long userId,
793         OrderByComparator obc) throws NoSuchProposalException, SystemException {
794         int count = countByG_U(groupId, userId);
795 
796         List<TasksProposal> list = findByG_U(groupId, userId, count - 1, count,
797                 obc);
798 
799         if (list.isEmpty()) {
800             StringBuilder msg = new StringBuilder();
801 
802             msg.append("No TasksProposal exists with the key {");
803 
804             msg.append("groupId=" + groupId);
805 
806             msg.append(", ");
807             msg.append("userId=" + userId);
808 
809             msg.append(StringPool.CLOSE_CURLY_BRACE);
810 
811             throw new NoSuchProposalException(msg.toString());
812         }
813         else {
814             return list.get(0);
815         }
816     }
817 
818     public TasksProposal[] findByG_U_PrevAndNext(long proposalId, long groupId,
819         long userId, OrderByComparator obc)
820         throws NoSuchProposalException, SystemException {
821         TasksProposal tasksProposal = findByPrimaryKey(proposalId);
822 
823         int count = countByG_U(groupId, userId);
824 
825         Session session = null;
826 
827         try {
828             session = openSession();
829 
830             StringBuilder query = new StringBuilder();
831 
832             query.append(
833                 "FROM com.liferay.portlet.tasks.model.TasksProposal WHERE ");
834 
835             query.append("groupId = ?");
836 
837             query.append(" AND ");
838 
839             query.append("userId = ?");
840 
841             query.append(" ");
842 
843             if (obc != null) {
844                 query.append("ORDER BY ");
845                 query.append(obc.getOrderBy());
846             }
847 
848             else {
849                 query.append("ORDER BY ");
850 
851                 query.append("dueDate ASC, ");
852                 query.append("createDate ASC");
853             }
854 
855             Query q = session.createQuery(query.toString());
856 
857             QueryPos qPos = QueryPos.getInstance(q);
858 
859             qPos.add(groupId);
860 
861             qPos.add(userId);
862 
863             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
864                     tasksProposal);
865 
866             TasksProposal[] array = new TasksProposalImpl[3];
867 
868             array[0] = (TasksProposal)objArray[0];
869             array[1] = (TasksProposal)objArray[1];
870             array[2] = (TasksProposal)objArray[2];
871 
872             return array;
873         }
874         catch (Exception e) {
875             throw processException(e);
876         }
877         finally {
878             closeSession(session);
879         }
880     }
881 
882     public TasksProposal findByC_C(long classNameId, String classPK)
883         throws NoSuchProposalException, SystemException {
884         TasksProposal tasksProposal = fetchByC_C(classNameId, classPK);
885 
886         if (tasksProposal == null) {
887             StringBuilder msg = new StringBuilder();
888 
889             msg.append("No TasksProposal exists with the key {");
890 
891             msg.append("classNameId=" + classNameId);
892 
893             msg.append(", ");
894             msg.append("classPK=" + classPK);
895 
896             msg.append(StringPool.CLOSE_CURLY_BRACE);
897 
898             if (_log.isWarnEnabled()) {
899                 _log.warn(msg.toString());
900             }
901 
902             throw new NoSuchProposalException(msg.toString());
903         }
904 
905         return tasksProposal;
906     }
907 
908     public TasksProposal fetchByC_C(long classNameId, String classPK)
909         throws SystemException {
910         return fetchByC_C(classNameId, classPK, true);
911     }
912 
913     public TasksProposal fetchByC_C(long classNameId, String classPK,
914         boolean retrieveFromCache) throws SystemException {
915         Object[] finderArgs = new Object[] { new Long(classNameId), classPK };
916 
917         Object result = null;
918 
919         if (retrieveFromCache) {
920             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
921                     finderArgs, this);
922         }
923 
924         if (result == null) {
925             Session session = null;
926 
927             try {
928                 session = openSession();
929 
930                 StringBuilder query = new StringBuilder();
931 
932                 query.append(
933                     "FROM com.liferay.portlet.tasks.model.TasksProposal WHERE ");
934 
935                 query.append("classNameId = ?");
936 
937                 query.append(" AND ");
938 
939                 if (classPK == null) {
940                     query.append("classPK IS NULL");
941                 }
942                 else {
943                     query.append("classPK = ?");
944                 }
945 
946                 query.append(" ");
947 
948                 query.append("ORDER BY ");
949 
950                 query.append("dueDate ASC, ");
951                 query.append("createDate ASC");
952 
953                 Query q = session.createQuery(query.toString());
954 
955                 QueryPos qPos = QueryPos.getInstance(q);
956 
957                 qPos.add(classNameId);
958 
959                 if (classPK != null) {
960                     qPos.add(classPK);
961                 }
962 
963                 List<TasksProposal> list = q.list();
964 
965                 result = list;
966 
967                 TasksProposal tasksProposal = null;
968 
969                 if (list.isEmpty()) {
970                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
971                         finderArgs, list);
972                 }
973                 else {
974                     tasksProposal = list.get(0);
975 
976                     cacheResult(tasksProposal);
977 
978                     if ((tasksProposal.getClassNameId() != classNameId) ||
979                             (tasksProposal.getClassPK() == null) ||
980                             !tasksProposal.getClassPK().equals(classPK)) {
981                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
982                             finderArgs, list);
983                     }
984                 }
985 
986                 return tasksProposal;
987             }
988             catch (Exception e) {
989                 throw processException(e);
990             }
991             finally {
992                 if (result == null) {
993                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
994                         finderArgs, new ArrayList<TasksProposal>());
995                 }
996 
997                 closeSession(session);
998             }
999         }
1000        else {
1001            if (result instanceof List) {
1002                return null;
1003            }
1004            else {
1005                return (TasksProposal)result;
1006            }
1007        }
1008    }
1009
1010    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1011        throws SystemException {
1012        Session session = null;
1013
1014        try {
1015            session = openSession();
1016
1017            dynamicQuery.compile(session);
1018
1019            return dynamicQuery.list();
1020        }
1021        catch (Exception e) {
1022            throw processException(e);
1023        }
1024        finally {
1025            closeSession(session);
1026        }
1027    }
1028
1029    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1030        int start, int end) throws SystemException {
1031        Session session = null;
1032
1033        try {
1034            session = openSession();
1035
1036            dynamicQuery.setLimit(start, end);
1037
1038            dynamicQuery.compile(session);
1039
1040            return dynamicQuery.list();
1041        }
1042        catch (Exception e) {
1043            throw processException(e);
1044        }
1045        finally {
1046            closeSession(session);
1047        }
1048    }
1049
1050    public List<TasksProposal> findAll() throws SystemException {
1051        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1052    }
1053
1054    public List<TasksProposal> findAll(int start, int end)
1055        throws SystemException {
1056        return findAll(start, end, null);
1057    }
1058
1059    public List<TasksProposal> findAll(int start, int end, OrderByComparator obc)
1060        throws SystemException {
1061        Object[] finderArgs = new Object[] {
1062                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1063            };
1064
1065        List<TasksProposal> list = (List<TasksProposal>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1066                finderArgs, this);
1067
1068        if (list == null) {
1069            Session session = null;
1070
1071            try {
1072                session = openSession();
1073
1074                StringBuilder query = new StringBuilder();
1075
1076                query.append(
1077                    "FROM com.liferay.portlet.tasks.model.TasksProposal ");
1078
1079                if (obc != null) {
1080                    query.append("ORDER BY ");
1081                    query.append(obc.getOrderBy());
1082                }
1083
1084                else {
1085                    query.append("ORDER BY ");
1086
1087                    query.append("dueDate ASC, ");
1088                    query.append("createDate ASC");
1089                }
1090
1091                Query q = session.createQuery(query.toString());
1092
1093                if (obc == null) {
1094                    list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1095                            start, end, false);
1096
1097                    Collections.sort(list);
1098                }
1099                else {
1100                    list = (List<TasksProposal>)QueryUtil.list(q, getDialect(),
1101                            start, end);
1102                }
1103            }
1104            catch (Exception e) {
1105                throw processException(e);
1106            }
1107            finally {
1108                if (list == null) {
1109                    list = new ArrayList<TasksProposal>();
1110                }
1111
1112                cacheResult(list);
1113
1114                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1115
1116                closeSession(session);
1117            }
1118        }
1119
1120        return list;
1121    }
1122
1123    public void removeByGroupId(long groupId) throws SystemException {
1124        for (TasksProposal tasksProposal : findByGroupId(groupId)) {
1125            remove(tasksProposal);
1126        }
1127    }
1128
1129    public void removeByG_U(long groupId, long userId)
1130        throws SystemException {
1131        for (TasksProposal tasksProposal : findByG_U(groupId, userId)) {
1132            remove(tasksProposal);
1133        }
1134    }
1135
1136    public void removeByC_C(long classNameId, String classPK)
1137        throws NoSuchProposalException, SystemException {
1138        TasksProposal tasksProposal = findByC_C(classNameId, classPK);
1139
1140        remove(tasksProposal);
1141    }
1142
1143    public void removeAll() throws SystemException {
1144        for (TasksProposal tasksProposal : findAll()) {
1145            remove(tasksProposal);
1146        }
1147    }
1148
1149    public int countByGroupId(long groupId) throws SystemException {
1150        Object[] finderArgs = new Object[] { new Long(groupId) };
1151
1152        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1153                finderArgs, this);
1154
1155        if (count == null) {
1156            Session session = null;
1157
1158            try {
1159                session = openSession();
1160
1161                StringBuilder query = new StringBuilder();
1162
1163                query.append("SELECT COUNT(*) ");
1164                query.append(
1165                    "FROM com.liferay.portlet.tasks.model.TasksProposal WHERE ");
1166
1167                query.append("groupId = ?");
1168
1169                query.append(" ");
1170
1171                Query q = session.createQuery(query.toString());
1172
1173                QueryPos qPos = QueryPos.getInstance(q);
1174
1175                qPos.add(groupId);
1176
1177                count = (Long)q.uniqueResult();
1178            }
1179            catch (Exception e) {
1180                throw processException(e);
1181            }
1182            finally {
1183                if (count == null) {
1184                    count = Long.valueOf(0);
1185                }
1186
1187                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1188                    finderArgs, count);
1189
1190                closeSession(session);
1191            }
1192        }
1193
1194        return count.intValue();
1195    }
1196
1197    public int countByG_U(long groupId, long userId) throws SystemException {
1198        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1199
1200        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1201                finderArgs, this);
1202
1203        if (count == null) {
1204            Session session = null;
1205
1206            try {
1207                session = openSession();
1208
1209                StringBuilder query = new StringBuilder();
1210
1211                query.append("SELECT COUNT(*) ");
1212                query.append(
1213                    "FROM com.liferay.portlet.tasks.model.TasksProposal WHERE ");
1214
1215                query.append("groupId = ?");
1216
1217                query.append(" AND ");
1218
1219                query.append("userId = ?");
1220
1221                query.append(" ");
1222
1223                Query q = session.createQuery(query.toString());
1224
1225                QueryPos qPos = QueryPos.getInstance(q);
1226
1227                qPos.add(groupId);
1228
1229                qPos.add(userId);
1230
1231                count = (Long)q.uniqueResult();
1232            }
1233            catch (Exception e) {
1234                throw processException(e);
1235            }
1236            finally {
1237                if (count == null) {
1238                    count = Long.valueOf(0);
1239                }
1240
1241                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1242                    count);
1243
1244                closeSession(session);
1245            }
1246        }
1247
1248        return count.intValue();
1249    }
1250
1251    public int countByC_C(long classNameId, String classPK)
1252        throws SystemException {
1253        Object[] finderArgs = new Object[] { new Long(classNameId), classPK };
1254
1255        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1256                finderArgs, this);
1257
1258        if (count == null) {
1259            Session session = null;
1260
1261            try {
1262                session = openSession();
1263
1264                StringBuilder query = new StringBuilder();
1265
1266                query.append("SELECT COUNT(*) ");
1267                query.append(
1268                    "FROM com.liferay.portlet.tasks.model.TasksProposal WHERE ");
1269
1270                query.append("classNameId = ?");
1271
1272                query.append(" AND ");
1273
1274                if (classPK == null) {
1275                    query.append("classPK IS NULL");
1276                }
1277                else {
1278                    query.append("classPK = ?");
1279                }
1280
1281                query.append(" ");
1282
1283                Query q = session.createQuery(query.toString());
1284
1285                QueryPos qPos = QueryPos.getInstance(q);
1286
1287                qPos.add(classNameId);
1288
1289                if (classPK != null) {
1290                    qPos.add(classPK);
1291                }
1292
1293                count = (Long)q.uniqueResult();
1294            }
1295            catch (Exception e) {
1296                throw processException(e);
1297            }
1298            finally {
1299                if (count == null) {
1300                    count = Long.valueOf(0);
1301                }
1302
1303                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1304                    count);
1305
1306                closeSession(session);
1307            }
1308        }
1309
1310        return count.intValue();
1311    }
1312
1313    public int countAll() throws SystemException {
1314        Object[] finderArgs = new Object[0];
1315
1316        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1317                finderArgs, this);
1318
1319        if (count == null) {
1320            Session session = null;
1321
1322            try {
1323                session = openSession();
1324
1325                Query q = session.createQuery(
1326                        "SELECT COUNT(*) FROM com.liferay.portlet.tasks.model.TasksProposal");
1327
1328                count = (Long)q.uniqueResult();
1329            }
1330            catch (Exception e) {
1331                throw processException(e);
1332            }
1333            finally {
1334                if (count == null) {
1335                    count = Long.valueOf(0);
1336                }
1337
1338                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1339                    count);
1340
1341                closeSession(session);
1342            }
1343        }
1344
1345        return count.intValue();
1346    }
1347
1348    public void afterPropertiesSet() {
1349        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1350                    com.liferay.portal.util.PropsUtil.get(
1351                        "value.object.listener.com.liferay.portlet.tasks.model.TasksProposal")));
1352
1353        if (listenerClassNames.length > 0) {
1354            try {
1355                List<ModelListener<TasksProposal>> listenersList = new ArrayList<ModelListener<TasksProposal>>();
1356
1357                for (String listenerClassName : listenerClassNames) {
1358                    listenersList.add((ModelListener<TasksProposal>)Class.forName(
1359                            listenerClassName).newInstance());
1360                }
1361
1362                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1363            }
1364            catch (Exception e) {
1365                _log.error(e);
1366            }
1367        }
1368    }
1369
1370    @BeanReference(name = "com.liferay.portlet.tasks.service.persistence.TasksReviewPersistence.impl")
1371    protected com.liferay.portlet.tasks.service.persistence.TasksReviewPersistence tasksReviewPersistence;
1372    @BeanReference(name = "com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence.impl")
1373    protected com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence tasksProposalPersistence;
1374    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1375    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1376    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1377    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1378    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence.impl")
1379    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
1380    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialActivityPersistence.impl")
1381    protected com.liferay.portlet.social.service.persistence.SocialActivityPersistence socialActivityPersistence;
1382    private static Log _log = LogFactoryUtil.getLog(TasksProposalPersistenceImpl.class);
1383}