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