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