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