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