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