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