1   /**
2    * Copyright (c) 2000-2007 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.OrderByComparator;
29  import com.liferay.portal.kernel.util.StringMaker;
30  import com.liferay.portal.kernel.util.StringPool;
31  import com.liferay.portal.service.persistence.BasePersistence;
32  import com.liferay.portal.spring.hibernate.FinderCache;
33  import com.liferay.portal.spring.hibernate.HibernateUtil;
34  
35  import com.liferay.portlet.shopping.NoSuchOrderException;
36  import com.liferay.portlet.shopping.model.ShoppingOrder;
37  import com.liferay.portlet.shopping.model.impl.ShoppingOrderImpl;
38  
39  import com.liferay.util.dao.hibernate.QueryUtil;
40  
41  import org.apache.commons.logging.Log;
42  import org.apache.commons.logging.LogFactory;
43  
44  import org.hibernate.Query;
45  import org.hibernate.Session;
46  
47  import java.util.Collections;
48  import java.util.Iterator;
49  import java.util.List;
50  
51  /**
52   * <a href="ShoppingOrderPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class ShoppingOrderPersistenceImpl extends BasePersistence
58      implements ShoppingOrderPersistence {
59      public ShoppingOrder create(long orderId) {
60          ShoppingOrder shoppingOrder = new ShoppingOrderImpl();
61          shoppingOrder.setNew(true);
62          shoppingOrder.setPrimaryKey(orderId);
63  
64          return shoppingOrder;
65      }
66  
67      public ShoppingOrder remove(long orderId)
68          throws NoSuchOrderException, SystemException {
69          Session session = null;
70  
71          try {
72              session = openSession();
73  
74              ShoppingOrder shoppingOrder = (ShoppingOrder)session.get(ShoppingOrderImpl.class,
75                      new Long(orderId));
76  
77              if (shoppingOrder == null) {
78                  if (_log.isWarnEnabled()) {
79                      _log.warn("No ShoppingOrder exists with the primary key " +
80                          orderId);
81                  }
82  
83                  throw new NoSuchOrderException(
84                      "No ShoppingOrder exists with the primary key " + orderId);
85              }
86  
87              return remove(shoppingOrder);
88          }
89          catch (NoSuchOrderException nsee) {
90              throw nsee;
91          }
92          catch (Exception e) {
93              throw HibernateUtil.processException(e);
94          }
95          finally {
96              closeSession(session);
97          }
98      }
99  
100     public ShoppingOrder remove(ShoppingOrder shoppingOrder)
101         throws SystemException {
102         Session session = null;
103 
104         try {
105             session = openSession();
106             session.delete(shoppingOrder);
107             session.flush();
108 
109             return shoppingOrder;
110         }
111         catch (Exception e) {
112             throw HibernateUtil.processException(e);
113         }
114         finally {
115             closeSession(session);
116             FinderCache.clearCache(ShoppingOrder.class.getName());
117         }
118     }
119 
120     public ShoppingOrder update(
121         com.liferay.portlet.shopping.model.ShoppingOrder shoppingOrder)
122         throws SystemException {
123         return update(shoppingOrder, false);
124     }
125 
126     public ShoppingOrder update(
127         com.liferay.portlet.shopping.model.ShoppingOrder shoppingOrder,
128         boolean merge) throws SystemException {
129         Session session = null;
130 
131         try {
132             session = openSession();
133 
134             if (merge) {
135                 session.merge(shoppingOrder);
136             }
137             else {
138                 if (shoppingOrder.isNew()) {
139                     session.save(shoppingOrder);
140                 }
141             }
142 
143             session.flush();
144             shoppingOrder.setNew(false);
145 
146             return shoppingOrder;
147         }
148         catch (Exception e) {
149             throw HibernateUtil.processException(e);
150         }
151         finally {
152             closeSession(session);
153             FinderCache.clearCache(ShoppingOrder.class.getName());
154         }
155     }
156 
157     public ShoppingOrder findByPrimaryKey(long orderId)
158         throws NoSuchOrderException, SystemException {
159         ShoppingOrder shoppingOrder = fetchByPrimaryKey(orderId);
160 
161         if (shoppingOrder == null) {
162             if (_log.isWarnEnabled()) {
163                 _log.warn("No ShoppingOrder exists with the primary key " +
164                     orderId);
165             }
166 
167             throw new NoSuchOrderException(
168                 "No ShoppingOrder exists with the primary key " + orderId);
169         }
170 
171         return shoppingOrder;
172     }
173 
174     public ShoppingOrder fetchByPrimaryKey(long orderId)
175         throws SystemException {
176         Session session = null;
177 
178         try {
179             session = openSession();
180 
181             return (ShoppingOrder)session.get(ShoppingOrderImpl.class,
182                 new Long(orderId));
183         }
184         catch (Exception e) {
185             throw HibernateUtil.processException(e);
186         }
187         finally {
188             closeSession(session);
189         }
190     }
191 
192     public ShoppingOrder findByNumber(String number)
193         throws NoSuchOrderException, SystemException {
194         ShoppingOrder shoppingOrder = fetchByNumber(number);
195 
196         if (shoppingOrder == null) {
197             StringMaker msg = new StringMaker();
198             msg.append("No ShoppingOrder exists with the key ");
199             msg.append(StringPool.OPEN_CURLY_BRACE);
200             msg.append("number=");
201             msg.append(number);
202             msg.append(StringPool.CLOSE_CURLY_BRACE);
203 
204             if (_log.isWarnEnabled()) {
205                 _log.warn(msg.toString());
206             }
207 
208             throw new NoSuchOrderException(msg.toString());
209         }
210 
211         return shoppingOrder;
212     }
213 
214     public ShoppingOrder fetchByNumber(String number) throws SystemException {
215         String finderClassName = ShoppingOrder.class.getName();
216         String finderMethodName = "fetchByNumber";
217         String[] finderParams = new String[] { String.class.getName() };
218         Object[] finderArgs = new Object[] { number };
219         Object result = FinderCache.getResult(finderClassName,
220                 finderMethodName, finderParams, finderArgs, getSessionFactory());
221 
222         if (result == null) {
223             Session session = null;
224 
225             try {
226                 session = openSession();
227 
228                 StringMaker query = new StringMaker();
229                 query.append(
230                     "FROM com.liferay.portlet.shopping.model.ShoppingOrder WHERE ");
231 
232                 if (number == null) {
233                     query.append("number_ IS NULL");
234                 }
235                 else {
236                     query.append("number_ = ?");
237                 }
238 
239                 query.append(" ");
240                 query.append("ORDER BY ");
241                 query.append("createDate DESC");
242 
243                 Query q = session.createQuery(query.toString());
244                 int queryPos = 0;
245 
246                 if (number != null) {
247                     q.setString(queryPos++, number);
248                 }
249 
250                 List list = q.list();
251                 FinderCache.putResult(finderClassName, finderMethodName,
252                     finderParams, finderArgs, list);
253 
254                 if (list.size() == 0) {
255                     return null;
256                 }
257                 else {
258                     return (ShoppingOrder)list.get(0);
259                 }
260             }
261             catch (Exception e) {
262                 throw HibernateUtil.processException(e);
263             }
264             finally {
265                 closeSession(session);
266             }
267         }
268         else {
269             List list = (List)result;
270 
271             if (list.size() == 0) {
272                 return null;
273             }
274             else {
275                 return (ShoppingOrder)list.get(0);
276             }
277         }
278     }
279 
280     public List findByG_U_PPPS(long groupId, long userId, String ppPaymentStatus)
281         throws SystemException {
282         String finderClassName = ShoppingOrder.class.getName();
283         String finderMethodName = "findByG_U_PPPS";
284         String[] finderParams = new String[] {
285                 Long.class.getName(), Long.class.getName(),
286                 String.class.getName()
287             };
288         Object[] finderArgs = new Object[] {
289                 new Long(groupId), new Long(userId), ppPaymentStatus
290             };
291         Object result = FinderCache.getResult(finderClassName,
292                 finderMethodName, finderParams, finderArgs, getSessionFactory());
293 
294         if (result == null) {
295             Session session = null;
296 
297             try {
298                 session = openSession();
299 
300                 StringMaker query = new StringMaker();
301                 query.append(
302                     "FROM com.liferay.portlet.shopping.model.ShoppingOrder WHERE ");
303                 query.append("groupId = ?");
304                 query.append(" AND ");
305                 query.append("userId = ?");
306                 query.append(" AND ");
307 
308                 if (ppPaymentStatus == null) {
309                     query.append("ppPaymentStatus IS NULL");
310                 }
311                 else {
312                     query.append("ppPaymentStatus = ?");
313                 }
314 
315                 query.append(" ");
316                 query.append("ORDER BY ");
317                 query.append("createDate DESC");
318 
319                 Query q = session.createQuery(query.toString());
320                 int queryPos = 0;
321                 q.setLong(queryPos++, groupId);
322                 q.setLong(queryPos++, userId);
323 
324                 if (ppPaymentStatus != null) {
325                     q.setString(queryPos++, ppPaymentStatus);
326                 }
327 
328                 List list = q.list();
329                 FinderCache.putResult(finderClassName, finderMethodName,
330                     finderParams, finderArgs, list);
331 
332                 return list;
333             }
334             catch (Exception e) {
335                 throw HibernateUtil.processException(e);
336             }
337             finally {
338                 closeSession(session);
339             }
340         }
341         else {
342             return (List)result;
343         }
344     }
345 
346     public List findByG_U_PPPS(long groupId, long userId,
347         String ppPaymentStatus, int begin, int end) throws SystemException {
348         return findByG_U_PPPS(groupId, userId, ppPaymentStatus, begin, end, null);
349     }
350 
351     public List findByG_U_PPPS(long groupId, long userId,
352         String ppPaymentStatus, int begin, int end, OrderByComparator obc)
353         throws SystemException {
354         String finderClassName = ShoppingOrder.class.getName();
355         String finderMethodName = "findByG_U_PPPS";
356         String[] finderParams = new String[] {
357                 Long.class.getName(), Long.class.getName(),
358                 String.class.getName(), "java.lang.Integer", "java.lang.Integer",
359                 "com.liferay.portal.kernel.util.OrderByComparator"
360             };
361         Object[] finderArgs = new Object[] {
362                 new Long(groupId), new Long(userId), ppPaymentStatus,
363                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
364             };
365         Object result = FinderCache.getResult(finderClassName,
366                 finderMethodName, finderParams, finderArgs, getSessionFactory());
367 
368         if (result == null) {
369             Session session = null;
370 
371             try {
372                 session = openSession();
373 
374                 StringMaker query = new StringMaker();
375                 query.append(
376                     "FROM com.liferay.portlet.shopping.model.ShoppingOrder WHERE ");
377                 query.append("groupId = ?");
378                 query.append(" AND ");
379                 query.append("userId = ?");
380                 query.append(" AND ");
381 
382                 if (ppPaymentStatus == null) {
383                     query.append("ppPaymentStatus IS NULL");
384                 }
385                 else {
386                     query.append("ppPaymentStatus = ?");
387                 }
388 
389                 query.append(" ");
390 
391                 if (obc != null) {
392                     query.append("ORDER BY ");
393                     query.append(obc.getOrderBy());
394                 }
395                 else {
396                     query.append("ORDER BY ");
397                     query.append("createDate DESC");
398                 }
399 
400                 Query q = session.createQuery(query.toString());
401                 int queryPos = 0;
402                 q.setLong(queryPos++, groupId);
403                 q.setLong(queryPos++, userId);
404 
405                 if (ppPaymentStatus != null) {
406                     q.setString(queryPos++, ppPaymentStatus);
407                 }
408 
409                 List list = QueryUtil.list(q, getDialect(), begin, end);
410                 FinderCache.putResult(finderClassName, finderMethodName,
411                     finderParams, finderArgs, list);
412 
413                 return list;
414             }
415             catch (Exception e) {
416                 throw HibernateUtil.processException(e);
417             }
418             finally {
419                 closeSession(session);
420             }
421         }
422         else {
423             return (List)result;
424         }
425     }
426 
427     public ShoppingOrder findByG_U_PPPS_First(long groupId, long userId,
428         String ppPaymentStatus, OrderByComparator obc)
429         throws NoSuchOrderException, SystemException {
430         List list = findByG_U_PPPS(groupId, userId, ppPaymentStatus, 0, 1, obc);
431 
432         if (list.size() == 0) {
433             StringMaker msg = new StringMaker();
434             msg.append("No ShoppingOrder exists with the key ");
435             msg.append(StringPool.OPEN_CURLY_BRACE);
436             msg.append("groupId=");
437             msg.append(groupId);
438             msg.append(", ");
439             msg.append("userId=");
440             msg.append(userId);
441             msg.append(", ");
442             msg.append("ppPaymentStatus=");
443             msg.append(ppPaymentStatus);
444             msg.append(StringPool.CLOSE_CURLY_BRACE);
445             throw new NoSuchOrderException(msg.toString());
446         }
447         else {
448             return (ShoppingOrder)list.get(0);
449         }
450     }
451 
452     public ShoppingOrder findByG_U_PPPS_Last(long groupId, long userId,
453         String ppPaymentStatus, OrderByComparator obc)
454         throws NoSuchOrderException, SystemException {
455         int count = countByG_U_PPPS(groupId, userId, ppPaymentStatus);
456         List list = findByG_U_PPPS(groupId, userId, ppPaymentStatus, count - 1,
457                 count, obc);
458 
459         if (list.size() == 0) {
460             StringMaker msg = new StringMaker();
461             msg.append("No ShoppingOrder exists with the key ");
462             msg.append(StringPool.OPEN_CURLY_BRACE);
463             msg.append("groupId=");
464             msg.append(groupId);
465             msg.append(", ");
466             msg.append("userId=");
467             msg.append(userId);
468             msg.append(", ");
469             msg.append("ppPaymentStatus=");
470             msg.append(ppPaymentStatus);
471             msg.append(StringPool.CLOSE_CURLY_BRACE);
472             throw new NoSuchOrderException(msg.toString());
473         }
474         else {
475             return (ShoppingOrder)list.get(0);
476         }
477     }
478 
479     public ShoppingOrder[] findByG_U_PPPS_PrevAndNext(long orderId,
480         long groupId, long userId, String ppPaymentStatus, OrderByComparator obc)
481         throws NoSuchOrderException, SystemException {
482         ShoppingOrder shoppingOrder = findByPrimaryKey(orderId);
483         int count = countByG_U_PPPS(groupId, userId, ppPaymentStatus);
484         Session session = null;
485 
486         try {
487             session = openSession();
488 
489             StringMaker query = new StringMaker();
490             query.append(
491                 "FROM com.liferay.portlet.shopping.model.ShoppingOrder WHERE ");
492             query.append("groupId = ?");
493             query.append(" AND ");
494             query.append("userId = ?");
495             query.append(" AND ");
496 
497             if (ppPaymentStatus == null) {
498                 query.append("ppPaymentStatus IS NULL");
499             }
500             else {
501                 query.append("ppPaymentStatus = ?");
502             }
503 
504             query.append(" ");
505 
506             if (obc != null) {
507                 query.append("ORDER BY ");
508                 query.append(obc.getOrderBy());
509             }
510             else {
511                 query.append("ORDER BY ");
512                 query.append("createDate DESC");
513             }
514 
515             Query q = session.createQuery(query.toString());
516             int queryPos = 0;
517             q.setLong(queryPos++, groupId);
518             q.setLong(queryPos++, userId);
519 
520             if (ppPaymentStatus != null) {
521                 q.setString(queryPos++, ppPaymentStatus);
522             }
523 
524             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
525                     shoppingOrder);
526             ShoppingOrder[] array = new ShoppingOrderImpl[3];
527             array[0] = (ShoppingOrder)objArray[0];
528             array[1] = (ShoppingOrder)objArray[1];
529             array[2] = (ShoppingOrder)objArray[2];
530 
531             return array;
532         }
533         catch (Exception e) {
534             throw HibernateUtil.processException(e);
535         }
536         finally {
537             closeSession(session);
538         }
539     }
540 
541     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
542         throws SystemException {
543         Session session = null;
544 
545         try {
546             session = openSession();
547 
548             DynamicQuery query = queryInitializer.initialize(session);
549 
550             return query.list();
551         }
552         catch (Exception e) {
553             throw HibernateUtil.processException(e);
554         }
555         finally {
556             closeSession(session);
557         }
558     }
559 
560     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
561         int begin, int end) throws SystemException {
562         Session session = null;
563 
564         try {
565             session = openSession();
566 
567             DynamicQuery query = queryInitializer.initialize(session);
568             query.setLimit(begin, end);
569 
570             return query.list();
571         }
572         catch (Exception e) {
573             throw HibernateUtil.processException(e);
574         }
575         finally {
576             closeSession(session);
577         }
578     }
579 
580     public List findAll() throws SystemException {
581         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
582     }
583 
584     public List findAll(int begin, int end) throws SystemException {
585         return findAll(begin, end, null);
586     }
587 
588     public List findAll(int begin, int end, OrderByComparator obc)
589         throws SystemException {
590         String finderClassName = ShoppingOrder.class.getName();
591         String finderMethodName = "findAll";
592         String[] finderParams = new String[] {
593                 "java.lang.Integer", "java.lang.Integer",
594                 "com.liferay.portal.kernel.util.OrderByComparator"
595             };
596         Object[] finderArgs = new Object[] {
597                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
598             };
599         Object result = FinderCache.getResult(finderClassName,
600                 finderMethodName, finderParams, finderArgs, getSessionFactory());
601 
602         if (result == null) {
603             Session session = null;
604 
605             try {
606                 session = openSession();
607 
608                 StringMaker query = new StringMaker();
609                 query.append(
610                     "FROM com.liferay.portlet.shopping.model.ShoppingOrder ");
611 
612                 if (obc != null) {
613                     query.append("ORDER BY ");
614                     query.append(obc.getOrderBy());
615                 }
616                 else {
617                     query.append("ORDER BY ");
618                     query.append("createDate DESC");
619                 }
620 
621                 Query q = session.createQuery(query.toString());
622                 List list = QueryUtil.list(q, getDialect(), begin, end);
623 
624                 if (obc == null) {
625                     Collections.sort(list);
626                 }
627 
628                 FinderCache.putResult(finderClassName, finderMethodName,
629                     finderParams, finderArgs, list);
630 
631                 return list;
632             }
633             catch (Exception e) {
634                 throw HibernateUtil.processException(e);
635             }
636             finally {
637                 closeSession(session);
638             }
639         }
640         else {
641             return (List)result;
642         }
643     }
644 
645     public void removeByNumber(String number)
646         throws NoSuchOrderException, SystemException {
647         ShoppingOrder shoppingOrder = findByNumber(number);
648         remove(shoppingOrder);
649     }
650 
651     public void removeByG_U_PPPS(long groupId, long userId,
652         String ppPaymentStatus) throws SystemException {
653         Iterator itr = findByG_U_PPPS(groupId, userId, ppPaymentStatus)
654                            .iterator();
655 
656         while (itr.hasNext()) {
657             ShoppingOrder shoppingOrder = (ShoppingOrder)itr.next();
658             remove(shoppingOrder);
659         }
660     }
661 
662     public void removeAll() throws SystemException {
663         Iterator itr = findAll().iterator();
664 
665         while (itr.hasNext()) {
666             remove((ShoppingOrder)itr.next());
667         }
668     }
669 
670     public int countByNumber(String number) throws SystemException {
671         String finderClassName = ShoppingOrder.class.getName();
672         String finderMethodName = "countByNumber";
673         String[] finderParams = new String[] { String.class.getName() };
674         Object[] finderArgs = new Object[] { number };
675         Object result = FinderCache.getResult(finderClassName,
676                 finderMethodName, finderParams, finderArgs, getSessionFactory());
677 
678         if (result == null) {
679             Session session = null;
680 
681             try {
682                 session = openSession();
683 
684                 StringMaker query = new StringMaker();
685                 query.append("SELECT COUNT(*) ");
686                 query.append(
687                     "FROM com.liferay.portlet.shopping.model.ShoppingOrder WHERE ");
688 
689                 if (number == null) {
690                     query.append("number_ IS NULL");
691                 }
692                 else {
693                     query.append("number_ = ?");
694                 }
695 
696                 query.append(" ");
697 
698                 Query q = session.createQuery(query.toString());
699                 int queryPos = 0;
700 
701                 if (number != null) {
702                     q.setString(queryPos++, number);
703                 }
704 
705                 Long count = null;
706                 Iterator itr = q.list().iterator();
707 
708                 if (itr.hasNext()) {
709                     count = (Long)itr.next();
710                 }
711 
712                 if (count == null) {
713                     count = new Long(0);
714                 }
715 
716                 FinderCache.putResult(finderClassName, finderMethodName,
717                     finderParams, finderArgs, count);
718 
719                 return count.intValue();
720             }
721             catch (Exception e) {
722                 throw HibernateUtil.processException(e);
723             }
724             finally {
725                 closeSession(session);
726             }
727         }
728         else {
729             return ((Long)result).intValue();
730         }
731     }
732 
733     public int countByG_U_PPPS(long groupId, long userId, String ppPaymentStatus)
734         throws SystemException {
735         String finderClassName = ShoppingOrder.class.getName();
736         String finderMethodName = "countByG_U_PPPS";
737         String[] finderParams = new String[] {
738                 Long.class.getName(), Long.class.getName(),
739                 String.class.getName()
740             };
741         Object[] finderArgs = new Object[] {
742                 new Long(groupId), new Long(userId), ppPaymentStatus
743             };
744         Object result = FinderCache.getResult(finderClassName,
745                 finderMethodName, finderParams, finderArgs, getSessionFactory());
746 
747         if (result == null) {
748             Session session = null;
749 
750             try {
751                 session = openSession();
752 
753                 StringMaker query = new StringMaker();
754                 query.append("SELECT COUNT(*) ");
755                 query.append(
756                     "FROM com.liferay.portlet.shopping.model.ShoppingOrder WHERE ");
757                 query.append("groupId = ?");
758                 query.append(" AND ");
759                 query.append("userId = ?");
760                 query.append(" AND ");
761 
762                 if (ppPaymentStatus == null) {
763                     query.append("ppPaymentStatus IS NULL");
764                 }
765                 else {
766                     query.append("ppPaymentStatus = ?");
767                 }
768 
769                 query.append(" ");
770 
771                 Query q = session.createQuery(query.toString());
772                 int queryPos = 0;
773                 q.setLong(queryPos++, groupId);
774                 q.setLong(queryPos++, userId);
775 
776                 if (ppPaymentStatus != null) {
777                     q.setString(queryPos++, ppPaymentStatus);
778                 }
779 
780                 Long count = null;
781                 Iterator itr = q.list().iterator();
782 
783                 if (itr.hasNext()) {
784                     count = (Long)itr.next();
785                 }
786 
787                 if (count == null) {
788                     count = new Long(0);
789                 }
790 
791                 FinderCache.putResult(finderClassName, finderMethodName,
792                     finderParams, finderArgs, count);
793 
794                 return count.intValue();
795             }
796             catch (Exception e) {
797                 throw HibernateUtil.processException(e);
798             }
799             finally {
800                 closeSession(session);
801             }
802         }
803         else {
804             return ((Long)result).intValue();
805         }
806     }
807 
808     public int countAll() throws SystemException {
809         String finderClassName = ShoppingOrder.class.getName();
810         String finderMethodName = "countAll";
811         String[] finderParams = new String[] {  };
812         Object[] finderArgs = new Object[] {  };
813         Object result = FinderCache.getResult(finderClassName,
814                 finderMethodName, finderParams, finderArgs, getSessionFactory());
815 
816         if (result == null) {
817             Session session = null;
818 
819             try {
820                 session = openSession();
821 
822                 StringMaker query = new StringMaker();
823                 query.append("SELECT COUNT(*) ");
824                 query.append(
825                     "FROM com.liferay.portlet.shopping.model.ShoppingOrder");
826 
827                 Query q = session.createQuery(query.toString());
828                 Long count = null;
829                 Iterator itr = q.list().iterator();
830 
831                 if (itr.hasNext()) {
832                     count = (Long)itr.next();
833                 }
834 
835                 if (count == null) {
836                     count = new Long(0);
837                 }
838 
839                 FinderCache.putResult(finderClassName, finderMethodName,
840                     finderParams, finderArgs, count);
841 
842                 return count.intValue();
843             }
844             catch (Exception e) {
845                 throw HibernateUtil.processException(e);
846             }
847             finally {
848                 closeSession(session);
849             }
850         }
851         else {
852             return ((Long)result).intValue();
853         }
854     }
855 
856     protected void initDao() {
857     }
858 
859     private static Log _log = LogFactory.getLog(ShoppingOrderPersistenceImpl.class);
860 }