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