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