1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.shopping.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
27  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28  import com.liferay.portal.kernel.dao.orm.Query;
29  import com.liferay.portal.kernel.dao.orm.QueryPos;
30  import com.liferay.portal.kernel.dao.orm.QueryUtil;
31  import com.liferay.portal.kernel.dao.orm.Session;
32  import com.liferay.portal.kernel.util.GetterUtil;
33  import com.liferay.portal.kernel.util.ListUtil;
34  import com.liferay.portal.kernel.util.OrderByComparator;
35  import com.liferay.portal.kernel.util.StringPool;
36  import com.liferay.portal.kernel.util.StringUtil;
37  import com.liferay.portal.model.ModelListener;
38  import com.liferay.portal.service.persistence.BatchSessionUtil;
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  /**
55   * <a href="ShoppingOrderPersistenceImpl.java.html"><b><i>View Source</i></b></a>
56   *
57   * @author Brian Wing Shun Chan
58   *
59   */
60  public class ShoppingOrderPersistenceImpl extends BasePersistenceImpl
61      implements ShoppingOrderPersistence {
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             if (BatchSessionUtil.isEnabled()) {
131                 Object staleObject = session.get(ShoppingOrderImpl.class,
132                         shoppingOrder.getPrimaryKeyObj());
133 
134                 if (staleObject != null) {
135                     session.evict(staleObject);
136                 }
137             }
138 
139             session.delete(shoppingOrder);
140 
141             session.flush();
142 
143             return shoppingOrder;
144         }
145         catch (Exception e) {
146             throw processException(e);
147         }
148         finally {
149             closeSession(session);
150 
151             FinderCacheUtil.clearCache(ShoppingOrder.class.getName());
152         }
153     }
154 
155     /**
156      * @deprecated Use <code>update(ShoppingOrder shoppingOrder, boolean merge)</code>.
157      */
158     public ShoppingOrder update(ShoppingOrder shoppingOrder)
159         throws SystemException {
160         if (_log.isWarnEnabled()) {
161             _log.warn(
162                 "Using the deprecated update(ShoppingOrder shoppingOrder) method. Use update(ShoppingOrder shoppingOrder, boolean merge) instead.");
163         }
164 
165         return update(shoppingOrder, false);
166     }
167 
168     /**
169      * Add, update, or merge, the entity. This method also calls the model
170      * listeners to trigger the proper events associated with adding, deleting,
171      * or updating an entity.
172      *
173      * @param        shoppingOrder the entity to add, update, or merge
174      * @param        merge boolean value for whether to merge the entity. The
175      *                default value is false. Setting merge to true is more
176      *                expensive and should only be true when shoppingOrder is
177      *                transient. See LEP-5473 for a detailed discussion of this
178      *                method.
179      * @return        true if the portlet can be displayed via Ajax
180      */
181     public ShoppingOrder update(ShoppingOrder shoppingOrder, boolean merge)
182         throws SystemException {
183         boolean isNew = shoppingOrder.isNew();
184 
185         if (_listeners.length > 0) {
186             for (ModelListener listener : _listeners) {
187                 if (isNew) {
188                     listener.onBeforeCreate(shoppingOrder);
189                 }
190                 else {
191                     listener.onBeforeUpdate(shoppingOrder);
192                 }
193             }
194         }
195 
196         shoppingOrder = updateImpl(shoppingOrder, merge);
197 
198         if (_listeners.length > 0) {
199             for (ModelListener listener : _listeners) {
200                 if (isNew) {
201                     listener.onAfterCreate(shoppingOrder);
202                 }
203                 else {
204                     listener.onAfterUpdate(shoppingOrder);
205                 }
206             }
207         }
208 
209         return shoppingOrder;
210     }
211 
212     public ShoppingOrder updateImpl(
213         com.liferay.portlet.shopping.model.ShoppingOrder shoppingOrder,
214         boolean merge) throws SystemException {
215         Session session = null;
216 
217         try {
218             session = openSession();
219 
220             BatchSessionUtil.update(session, shoppingOrder, merge);
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 = null;
1134
1135                if (obc == null) {
1136                    list = (List<ShoppingOrder>)QueryUtil.list(q, getDialect(),
1137                            start, end, false);
1138
1139                    Collections.sort(list);
1140                }
1141                else {
1142                    list = (List<ShoppingOrder>)QueryUtil.list(q, getDialect(),
1143                            start, end);
1144                }
1145
1146                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1147                    finderClassName, finderMethodName, finderParams,
1148                    finderArgs, list);
1149
1150                return list;
1151            }
1152            catch (Exception e) {
1153                throw processException(e);
1154            }
1155            finally {
1156                closeSession(session);
1157            }
1158        }
1159        else {
1160            return (List<ShoppingOrder>)result;
1161        }
1162    }
1163
1164    public void removeByGroupId(long groupId) throws SystemException {
1165        for (ShoppingOrder shoppingOrder : findByGroupId(groupId)) {
1166            remove(shoppingOrder);
1167        }
1168    }
1169
1170    public void removeByNumber(String number)
1171        throws NoSuchOrderException, SystemException {
1172        ShoppingOrder shoppingOrder = findByNumber(number);
1173
1174        remove(shoppingOrder);
1175    }
1176
1177    public void removeByPPTxnId(String ppTxnId)
1178        throws NoSuchOrderException, SystemException {
1179        ShoppingOrder shoppingOrder = findByPPTxnId(ppTxnId);
1180
1181        remove(shoppingOrder);
1182    }
1183
1184    public void removeByG_U_PPPS(long groupId, long userId,
1185        String ppPaymentStatus) throws SystemException {
1186        for (ShoppingOrder shoppingOrder : findByG_U_PPPS(groupId, userId,
1187                ppPaymentStatus)) {
1188            remove(shoppingOrder);
1189        }
1190    }
1191
1192    public void removeAll() throws SystemException {
1193        for (ShoppingOrder shoppingOrder : findAll()) {
1194            remove(shoppingOrder);
1195        }
1196    }
1197
1198    public int countByGroupId(long groupId) throws SystemException {
1199        boolean finderClassNameCacheEnabled = ShoppingOrderModelImpl.CACHE_ENABLED;
1200        String finderClassName = ShoppingOrder.class.getName();
1201        String finderMethodName = "countByGroupId";
1202        String[] finderParams = new String[] { Long.class.getName() };
1203        Object[] finderArgs = new Object[] { new Long(groupId) };
1204
1205        Object result = null;
1206
1207        if (finderClassNameCacheEnabled) {
1208            result = FinderCacheUtil.getResult(finderClassName,
1209                    finderMethodName, finderParams, finderArgs, this);
1210        }
1211
1212        if (result == null) {
1213            Session session = null;
1214
1215            try {
1216                session = openSession();
1217
1218                StringBuilder query = new StringBuilder();
1219
1220                query.append("SELECT COUNT(*) ");
1221                query.append(
1222                    "FROM com.liferay.portlet.shopping.model.ShoppingOrder WHERE ");
1223
1224                query.append("groupId = ?");
1225
1226                query.append(" ");
1227
1228                Query q = session.createQuery(query.toString());
1229
1230                QueryPos qPos = QueryPos.getInstance(q);
1231
1232                qPos.add(groupId);
1233
1234                Long count = null;
1235
1236                Iterator<Long> itr = q.list().iterator();
1237
1238                if (itr.hasNext()) {
1239                    count = itr.next();
1240                }
1241
1242                if (count == null) {
1243                    count = new Long(0);
1244                }
1245
1246                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1247                    finderClassName, finderMethodName, finderParams,
1248                    finderArgs, count);
1249
1250                return count.intValue();
1251            }
1252            catch (Exception e) {
1253                throw processException(e);
1254            }
1255            finally {
1256                closeSession(session);
1257            }
1258        }
1259        else {
1260            return ((Long)result).intValue();
1261        }
1262    }
1263
1264    public int countByNumber(String number) throws SystemException {
1265        boolean finderClassNameCacheEnabled = ShoppingOrderModelImpl.CACHE_ENABLED;
1266        String finderClassName = ShoppingOrder.class.getName();
1267        String finderMethodName = "countByNumber";
1268        String[] finderParams = new String[] { String.class.getName() };
1269        Object[] finderArgs = new Object[] { number };
1270
1271        Object result = null;
1272
1273        if (finderClassNameCacheEnabled) {
1274            result = FinderCacheUtil.getResult(finderClassName,
1275                    finderMethodName, finderParams, finderArgs, this);
1276        }
1277
1278        if (result == null) {
1279            Session session = null;
1280
1281            try {
1282                session = openSession();
1283
1284                StringBuilder query = new StringBuilder();
1285
1286                query.append("SELECT COUNT(*) ");
1287                query.append(
1288                    "FROM com.liferay.portlet.shopping.model.ShoppingOrder WHERE ");
1289
1290                if (number == null) {
1291                    query.append("number_ IS NULL");
1292                }
1293                else {
1294                    query.append("number_ = ?");
1295                }
1296
1297                query.append(" ");
1298
1299                Query q = session.createQuery(query.toString());
1300
1301                QueryPos qPos = QueryPos.getInstance(q);
1302
1303                if (number != null) {
1304                    qPos.add(number);
1305                }
1306
1307                Long count = null;
1308
1309                Iterator<Long> itr = q.list().iterator();
1310
1311                if (itr.hasNext()) {
1312                    count = itr.next();
1313                }
1314
1315                if (count == null) {
1316                    count = new Long(0);
1317                }
1318
1319                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1320                    finderClassName, finderMethodName, finderParams,
1321                    finderArgs, count);
1322
1323                return count.intValue();
1324            }
1325            catch (Exception e) {
1326                throw processException(e);
1327            }
1328            finally {
1329                closeSession(session);
1330            }
1331        }
1332        else {
1333            return ((Long)result).intValue();
1334        }
1335    }
1336
1337    public int countByPPTxnId(String ppTxnId) throws SystemException {
1338        boolean finderClassNameCacheEnabled = ShoppingOrderModelImpl.CACHE_ENABLED;
1339        String finderClassName = ShoppingOrder.class.getName();
1340        String finderMethodName = "countByPPTxnId";
1341        String[] finderParams = new String[] { String.class.getName() };
1342        Object[] finderArgs = new Object[] { ppTxnId };
1343
1344        Object result = null;
1345
1346        if (finderClassNameCacheEnabled) {
1347            result = FinderCacheUtil.getResult(finderClassName,
1348                    finderMethodName, finderParams, finderArgs, this);
1349        }
1350
1351        if (result == null) {
1352            Session session = null;
1353
1354            try {
1355                session = openSession();
1356
1357                StringBuilder query = new StringBuilder();
1358
1359                query.append("SELECT COUNT(*) ");
1360                query.append(
1361                    "FROM com.liferay.portlet.shopping.model.ShoppingOrder WHERE ");
1362
1363                if (ppTxnId == null) {
1364                    query.append("ppTxnId IS NULL");
1365                }
1366                else {
1367                    query.append("ppTxnId = ?");
1368                }
1369
1370                query.append(" ");
1371
1372                Query q = session.createQuery(query.toString());
1373
1374                QueryPos qPos = QueryPos.getInstance(q);
1375
1376                if (ppTxnId != null) {
1377                    qPos.add(ppTxnId);
1378                }
1379
1380                Long count = null;
1381
1382                Iterator<Long> itr = q.list().iterator();
1383
1384                if (itr.hasNext()) {
1385                    count = itr.next();
1386                }
1387
1388                if (count == null) {
1389                    count = new Long(0);
1390                }
1391
1392                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1393                    finderClassName, finderMethodName, finderParams,
1394                    finderArgs, count);
1395
1396                return count.intValue();
1397            }
1398            catch (Exception e) {
1399                throw processException(e);
1400            }
1401            finally {
1402                closeSession(session);
1403            }
1404        }
1405        else {
1406            return ((Long)result).intValue();
1407        }
1408    }
1409
1410    public int countByG_U_PPPS(long groupId, long userId, String ppPaymentStatus)
1411        throws SystemException {
1412        boolean finderClassNameCacheEnabled = ShoppingOrderModelImpl.CACHE_ENABLED;
1413        String finderClassName = ShoppingOrder.class.getName();
1414        String finderMethodName = "countByG_U_PPPS";
1415        String[] finderParams = new String[] {
1416                Long.class.getName(), Long.class.getName(),
1417                String.class.getName()
1418            };
1419        Object[] finderArgs = new Object[] {
1420                new Long(groupId), new Long(userId),
1421                
1422                ppPaymentStatus
1423            };
1424
1425        Object result = null;
1426
1427        if (finderClassNameCacheEnabled) {
1428            result = FinderCacheUtil.getResult(finderClassName,
1429                    finderMethodName, finderParams, finderArgs, this);
1430        }
1431
1432        if (result == null) {
1433            Session session = null;
1434
1435            try {
1436                session = openSession();
1437
1438                StringBuilder query = new StringBuilder();
1439
1440                query.append("SELECT COUNT(*) ");
1441                query.append(
1442                    "FROM com.liferay.portlet.shopping.model.ShoppingOrder WHERE ");
1443
1444                query.append("groupId = ?");
1445
1446                query.append(" AND ");
1447
1448                query.append("userId = ?");
1449
1450                query.append(" AND ");
1451
1452                if (ppPaymentStatus == null) {
1453                    query.append("ppPaymentStatus IS NULL");
1454                }
1455                else {
1456                    query.append("ppPaymentStatus = ?");
1457                }
1458
1459                query.append(" ");
1460
1461                Query q = session.createQuery(query.toString());
1462
1463                QueryPos qPos = QueryPos.getInstance(q);
1464
1465                qPos.add(groupId);
1466
1467                qPos.add(userId);
1468
1469                if (ppPaymentStatus != null) {
1470                    qPos.add(ppPaymentStatus);
1471                }
1472
1473                Long count = null;
1474
1475                Iterator<Long> itr = q.list().iterator();
1476
1477                if (itr.hasNext()) {
1478                    count = itr.next();
1479                }
1480
1481                if (count == null) {
1482                    count = new Long(0);
1483                }
1484
1485                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1486                    finderClassName, finderMethodName, finderParams,
1487                    finderArgs, count);
1488
1489                return count.intValue();
1490            }
1491            catch (Exception e) {
1492                throw processException(e);
1493            }
1494            finally {
1495                closeSession(session);
1496            }
1497        }
1498        else {
1499            return ((Long)result).intValue();
1500        }
1501    }
1502
1503    public int countAll() throws SystemException {
1504        boolean finderClassNameCacheEnabled = ShoppingOrderModelImpl.CACHE_ENABLED;
1505        String finderClassName = ShoppingOrder.class.getName();
1506        String finderMethodName = "countAll";
1507        String[] finderParams = new String[] {  };
1508        Object[] finderArgs = new Object[] {  };
1509
1510        Object result = null;
1511
1512        if (finderClassNameCacheEnabled) {
1513            result = FinderCacheUtil.getResult(finderClassName,
1514                    finderMethodName, finderParams, finderArgs, this);
1515        }
1516
1517        if (result == null) {
1518            Session session = null;
1519
1520            try {
1521                session = openSession();
1522
1523                Query q = session.createQuery(
1524                        "SELECT COUNT(*) FROM com.liferay.portlet.shopping.model.ShoppingOrder");
1525
1526                Long count = null;
1527
1528                Iterator<Long> itr = q.list().iterator();
1529
1530                if (itr.hasNext()) {
1531                    count = itr.next();
1532                }
1533
1534                if (count == null) {
1535                    count = new Long(0);
1536                }
1537
1538                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1539                    finderClassName, finderMethodName, finderParams,
1540                    finderArgs, count);
1541
1542                return count.intValue();
1543            }
1544            catch (Exception e) {
1545                throw processException(e);
1546            }
1547            finally {
1548                closeSession(session);
1549            }
1550        }
1551        else {
1552            return ((Long)result).intValue();
1553        }
1554    }
1555
1556    public void registerListener(ModelListener listener) {
1557        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1558
1559        listeners.add(listener);
1560
1561        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1562    }
1563
1564    public void unregisterListener(ModelListener listener) {
1565        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1566
1567        listeners.remove(listener);
1568
1569        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1570    }
1571
1572    public void afterPropertiesSet() {
1573        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1574                    com.liferay.portal.util.PropsUtil.get(
1575                        "value.object.listener.com.liferay.portlet.shopping.model.ShoppingOrder")));
1576
1577        if (listenerClassNames.length > 0) {
1578            try {
1579                List<ModelListener> listeners = new ArrayList<ModelListener>();
1580
1581                for (String listenerClassName : listenerClassNames) {
1582                    listeners.add((ModelListener)Class.forName(
1583                            listenerClassName).newInstance());
1584                }
1585
1586                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1587            }
1588            catch (Exception e) {
1589                _log.error(e);
1590            }
1591        }
1592    }
1593
1594    private static Log _log = LogFactory.getLog(ShoppingOrderPersistenceImpl.class);
1595    private ModelListener[] _listeners = new ModelListener[0];
1596}