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