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