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