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