1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portlet.shopping.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.GetterUtil;
31  import com.liferay.portal.kernel.util.OrderByComparator;
32  import com.liferay.portal.kernel.util.StringBundler;
33  import com.liferay.portal.kernel.util.StringPool;
34  import com.liferay.portal.kernel.util.StringUtil;
35  import com.liferay.portal.model.ModelListener;
36  import com.liferay.portal.service.persistence.BatchSessionUtil;
37  import com.liferay.portal.service.persistence.ResourcePersistence;
38  import com.liferay.portal.service.persistence.UserPersistence;
39  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40  
41  import com.liferay.portlet.shopping.NoSuchOrderItemException;
42  import com.liferay.portlet.shopping.model.ShoppingOrderItem;
43  import com.liferay.portlet.shopping.model.impl.ShoppingOrderItemImpl;
44  import com.liferay.portlet.shopping.model.impl.ShoppingOrderItemModelImpl;
45  
46  import java.io.Serializable;
47  
48  import java.util.ArrayList;
49  import java.util.Collections;
50  import java.util.List;
51  
52  /**
53   * <a href="ShoppingOrderItemPersistenceImpl.java.html"><b><i>View Source</i></b></a>
54   *
55   * <p>
56   * ServiceBuilder generated this class. Modifications in this class will be
57   * overwritten the next time is generated.
58   * </p>
59   *
60   * @author    Brian Wing Shun Chan
61   * @see       ShoppingOrderItemPersistence
62   * @see       ShoppingOrderItemUtil
63   * @generated
64   */
65  public class ShoppingOrderItemPersistenceImpl extends BasePersistenceImpl<ShoppingOrderItem>
66      implements ShoppingOrderItemPersistence {
67      public static final String FINDER_CLASS_NAME_ENTITY = ShoppingOrderItemImpl.class.getName();
68      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
69          ".List";
70      public static final FinderPath FINDER_PATH_FIND_BY_ORDERID = new FinderPath(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
71              ShoppingOrderItemModelImpl.FINDER_CACHE_ENABLED,
72              FINDER_CLASS_NAME_LIST, "findByOrderId",
73              new String[] { Long.class.getName() });
74      public static final FinderPath FINDER_PATH_FIND_BY_OBC_ORDERID = new FinderPath(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
75              ShoppingOrderItemModelImpl.FINDER_CACHE_ENABLED,
76              FINDER_CLASS_NAME_LIST, "findByOrderId",
77              new String[] {
78                  Long.class.getName(),
79                  
80              "java.lang.Integer", "java.lang.Integer",
81                  "com.liferay.portal.kernel.util.OrderByComparator"
82              });
83      public static final FinderPath FINDER_PATH_COUNT_BY_ORDERID = new FinderPath(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
84              ShoppingOrderItemModelImpl.FINDER_CACHE_ENABLED,
85              FINDER_CLASS_NAME_LIST, "countByOrderId",
86              new String[] { Long.class.getName() });
87      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
88              ShoppingOrderItemModelImpl.FINDER_CACHE_ENABLED,
89              FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
90      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
91              ShoppingOrderItemModelImpl.FINDER_CACHE_ENABLED,
92              FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
93  
94      public void cacheResult(ShoppingOrderItem shoppingOrderItem) {
95          EntityCacheUtil.putResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
96              ShoppingOrderItemImpl.class, shoppingOrderItem.getPrimaryKey(),
97              shoppingOrderItem);
98      }
99  
100     public void cacheResult(List<ShoppingOrderItem> shoppingOrderItems) {
101         for (ShoppingOrderItem shoppingOrderItem : shoppingOrderItems) {
102             if (EntityCacheUtil.getResult(
103                         ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
104                         ShoppingOrderItemImpl.class,
105                         shoppingOrderItem.getPrimaryKey(), this) == null) {
106                 cacheResult(shoppingOrderItem);
107             }
108         }
109     }
110 
111     public void clearCache() {
112         CacheRegistry.clear(ShoppingOrderItemImpl.class.getName());
113         EntityCacheUtil.clearCache(ShoppingOrderItemImpl.class.getName());
114         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
115         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
116     }
117 
118     public ShoppingOrderItem create(long orderItemId) {
119         ShoppingOrderItem shoppingOrderItem = new ShoppingOrderItemImpl();
120 
121         shoppingOrderItem.setNew(true);
122         shoppingOrderItem.setPrimaryKey(orderItemId);
123 
124         return shoppingOrderItem;
125     }
126 
127     public ShoppingOrderItem remove(Serializable primaryKey)
128         throws NoSuchModelException, SystemException {
129         return remove(((Long)primaryKey).longValue());
130     }
131 
132     public ShoppingOrderItem remove(long orderItemId)
133         throws NoSuchOrderItemException, SystemException {
134         Session session = null;
135 
136         try {
137             session = openSession();
138 
139             ShoppingOrderItem shoppingOrderItem = (ShoppingOrderItem)session.get(ShoppingOrderItemImpl.class,
140                     new Long(orderItemId));
141 
142             if (shoppingOrderItem == null) {
143                 if (_log.isWarnEnabled()) {
144                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orderItemId);
145                 }
146 
147                 throw new NoSuchOrderItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
148                     orderItemId);
149             }
150 
151             return remove(shoppingOrderItem);
152         }
153         catch (NoSuchOrderItemException nsee) {
154             throw nsee;
155         }
156         catch (Exception e) {
157             throw processException(e);
158         }
159         finally {
160             closeSession(session);
161         }
162     }
163 
164     public ShoppingOrderItem remove(ShoppingOrderItem shoppingOrderItem)
165         throws SystemException {
166         for (ModelListener<ShoppingOrderItem> listener : listeners) {
167             listener.onBeforeRemove(shoppingOrderItem);
168         }
169 
170         shoppingOrderItem = removeImpl(shoppingOrderItem);
171 
172         for (ModelListener<ShoppingOrderItem> listener : listeners) {
173             listener.onAfterRemove(shoppingOrderItem);
174         }
175 
176         return shoppingOrderItem;
177     }
178 
179     protected ShoppingOrderItem removeImpl(ShoppingOrderItem shoppingOrderItem)
180         throws SystemException {
181         shoppingOrderItem = toUnwrappedModel(shoppingOrderItem);
182 
183         Session session = null;
184 
185         try {
186             session = openSession();
187 
188             if (shoppingOrderItem.isCachedModel() ||
189                     BatchSessionUtil.isEnabled()) {
190                 Object staleObject = session.get(ShoppingOrderItemImpl.class,
191                         shoppingOrderItem.getPrimaryKeyObj());
192 
193                 if (staleObject != null) {
194                     session.evict(staleObject);
195                 }
196             }
197 
198             session.delete(shoppingOrderItem);
199 
200             session.flush();
201         }
202         catch (Exception e) {
203             throw processException(e);
204         }
205         finally {
206             closeSession(session);
207         }
208 
209         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
210 
211         EntityCacheUtil.removeResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
212             ShoppingOrderItemImpl.class, shoppingOrderItem.getPrimaryKey());
213 
214         return shoppingOrderItem;
215     }
216 
217     /**
218      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
219      */
220     public ShoppingOrderItem update(ShoppingOrderItem shoppingOrderItem)
221         throws SystemException {
222         if (_log.isWarnEnabled()) {
223             _log.warn(
224                 "Using the deprecated update(ShoppingOrderItem shoppingOrderItem) method. Use update(ShoppingOrderItem shoppingOrderItem, boolean merge) instead.");
225         }
226 
227         return update(shoppingOrderItem, false);
228     }
229 
230     public ShoppingOrderItem updateImpl(
231         com.liferay.portlet.shopping.model.ShoppingOrderItem shoppingOrderItem,
232         boolean merge) throws SystemException {
233         shoppingOrderItem = toUnwrappedModel(shoppingOrderItem);
234 
235         Session session = null;
236 
237         try {
238             session = openSession();
239 
240             BatchSessionUtil.update(session, shoppingOrderItem, merge);
241 
242             shoppingOrderItem.setNew(false);
243         }
244         catch (Exception e) {
245             throw processException(e);
246         }
247         finally {
248             closeSession(session);
249         }
250 
251         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
252 
253         EntityCacheUtil.putResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
254             ShoppingOrderItemImpl.class, shoppingOrderItem.getPrimaryKey(),
255             shoppingOrderItem);
256 
257         return shoppingOrderItem;
258     }
259 
260     protected ShoppingOrderItem toUnwrappedModel(
261         ShoppingOrderItem shoppingOrderItem) {
262         if (shoppingOrderItem instanceof ShoppingOrderItemImpl) {
263             return shoppingOrderItem;
264         }
265 
266         ShoppingOrderItemImpl shoppingOrderItemImpl = new ShoppingOrderItemImpl();
267 
268         shoppingOrderItemImpl.setNew(shoppingOrderItem.isNew());
269         shoppingOrderItemImpl.setPrimaryKey(shoppingOrderItem.getPrimaryKey());
270 
271         shoppingOrderItemImpl.setOrderItemId(shoppingOrderItem.getOrderItemId());
272         shoppingOrderItemImpl.setOrderId(shoppingOrderItem.getOrderId());
273         shoppingOrderItemImpl.setItemId(shoppingOrderItem.getItemId());
274         shoppingOrderItemImpl.setSku(shoppingOrderItem.getSku());
275         shoppingOrderItemImpl.setName(shoppingOrderItem.getName());
276         shoppingOrderItemImpl.setDescription(shoppingOrderItem.getDescription());
277         shoppingOrderItemImpl.setProperties(shoppingOrderItem.getProperties());
278         shoppingOrderItemImpl.setPrice(shoppingOrderItem.getPrice());
279         shoppingOrderItemImpl.setQuantity(shoppingOrderItem.getQuantity());
280         shoppingOrderItemImpl.setShippedDate(shoppingOrderItem.getShippedDate());
281 
282         return shoppingOrderItemImpl;
283     }
284 
285     public ShoppingOrderItem findByPrimaryKey(Serializable primaryKey)
286         throws NoSuchModelException, SystemException {
287         return findByPrimaryKey(((Long)primaryKey).longValue());
288     }
289 
290     public ShoppingOrderItem findByPrimaryKey(long orderItemId)
291         throws NoSuchOrderItemException, SystemException {
292         ShoppingOrderItem shoppingOrderItem = fetchByPrimaryKey(orderItemId);
293 
294         if (shoppingOrderItem == null) {
295             if (_log.isWarnEnabled()) {
296                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orderItemId);
297             }
298 
299             throw new NoSuchOrderItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
300                 orderItemId);
301         }
302 
303         return shoppingOrderItem;
304     }
305 
306     public ShoppingOrderItem fetchByPrimaryKey(Serializable primaryKey)
307         throws SystemException {
308         return fetchByPrimaryKey(((Long)primaryKey).longValue());
309     }
310 
311     public ShoppingOrderItem fetchByPrimaryKey(long orderItemId)
312         throws SystemException {
313         ShoppingOrderItem shoppingOrderItem = (ShoppingOrderItem)EntityCacheUtil.getResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
314                 ShoppingOrderItemImpl.class, orderItemId, this);
315 
316         if (shoppingOrderItem == null) {
317             Session session = null;
318 
319             try {
320                 session = openSession();
321 
322                 shoppingOrderItem = (ShoppingOrderItem)session.get(ShoppingOrderItemImpl.class,
323                         new Long(orderItemId));
324             }
325             catch (Exception e) {
326                 throw processException(e);
327             }
328             finally {
329                 if (shoppingOrderItem != null) {
330                     cacheResult(shoppingOrderItem);
331                 }
332 
333                 closeSession(session);
334             }
335         }
336 
337         return shoppingOrderItem;
338     }
339 
340     public List<ShoppingOrderItem> findByOrderId(long orderId)
341         throws SystemException {
342         Object[] finderArgs = new Object[] { new Long(orderId) };
343 
344         List<ShoppingOrderItem> list = (List<ShoppingOrderItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ORDERID,
345                 finderArgs, this);
346 
347         if (list == null) {
348             Session session = null;
349 
350             try {
351                 session = openSession();
352 
353                 StringBundler query = new StringBundler(3);
354 
355                 query.append(_SQL_SELECT_SHOPPINGORDERITEM_WHERE);
356 
357                 query.append(_FINDER_COLUMN_ORDERID_ORDERID_2);
358 
359                 query.append(ShoppingOrderItemModelImpl.ORDER_BY_JPQL);
360 
361                 String sql = query.toString();
362 
363                 Query q = session.createQuery(sql);
364 
365                 QueryPos qPos = QueryPos.getInstance(q);
366 
367                 qPos.add(orderId);
368 
369                 list = q.list();
370             }
371             catch (Exception e) {
372                 throw processException(e);
373             }
374             finally {
375                 if (list == null) {
376                     list = new ArrayList<ShoppingOrderItem>();
377                 }
378 
379                 cacheResult(list);
380 
381                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ORDERID,
382                     finderArgs, list);
383 
384                 closeSession(session);
385             }
386         }
387 
388         return list;
389     }
390 
391     public List<ShoppingOrderItem> findByOrderId(long orderId, int start,
392         int end) throws SystemException {
393         return findByOrderId(orderId, start, end, null);
394     }
395 
396     public List<ShoppingOrderItem> findByOrderId(long orderId, int start,
397         int end, OrderByComparator orderByComparator) throws SystemException {
398         Object[] finderArgs = new Object[] {
399                 new Long(orderId),
400                 
401                 String.valueOf(start), String.valueOf(end),
402                 String.valueOf(orderByComparator)
403             };
404 
405         List<ShoppingOrderItem> list = (List<ShoppingOrderItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ORDERID,
406                 finderArgs, this);
407 
408         if (list == null) {
409             Session session = null;
410 
411             try {
412                 session = openSession();
413 
414                 StringBundler query = null;
415 
416                 if (orderByComparator != null) {
417                     query = new StringBundler(3 +
418                             (orderByComparator.getOrderByFields().length * 3));
419                 }
420                 else {
421                     query = new StringBundler(3);
422                 }
423 
424                 query.append(_SQL_SELECT_SHOPPINGORDERITEM_WHERE);
425 
426                 query.append(_FINDER_COLUMN_ORDERID_ORDERID_2);
427 
428                 if (orderByComparator != null) {
429                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
430                         orderByComparator);
431                 }
432 
433                 else {
434                     query.append(ShoppingOrderItemModelImpl.ORDER_BY_JPQL);
435                 }
436 
437                 String sql = query.toString();
438 
439                 Query q = session.createQuery(sql);
440 
441                 QueryPos qPos = QueryPos.getInstance(q);
442 
443                 qPos.add(orderId);
444 
445                 list = (List<ShoppingOrderItem>)QueryUtil.list(q, getDialect(),
446                         start, end);
447             }
448             catch (Exception e) {
449                 throw processException(e);
450             }
451             finally {
452                 if (list == null) {
453                     list = new ArrayList<ShoppingOrderItem>();
454                 }
455 
456                 cacheResult(list);
457 
458                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ORDERID,
459                     finderArgs, list);
460 
461                 closeSession(session);
462             }
463         }
464 
465         return list;
466     }
467 
468     public ShoppingOrderItem findByOrderId_First(long orderId,
469         OrderByComparator orderByComparator)
470         throws NoSuchOrderItemException, SystemException {
471         List<ShoppingOrderItem> list = findByOrderId(orderId, 0, 1,
472                 orderByComparator);
473 
474         if (list.isEmpty()) {
475             StringBundler msg = new StringBundler(4);
476 
477             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
478 
479             msg.append("orderId=");
480             msg.append(orderId);
481 
482             msg.append(StringPool.CLOSE_CURLY_BRACE);
483 
484             throw new NoSuchOrderItemException(msg.toString());
485         }
486         else {
487             return list.get(0);
488         }
489     }
490 
491     public ShoppingOrderItem findByOrderId_Last(long orderId,
492         OrderByComparator orderByComparator)
493         throws NoSuchOrderItemException, SystemException {
494         int count = countByOrderId(orderId);
495 
496         List<ShoppingOrderItem> list = findByOrderId(orderId, count - 1, count,
497                 orderByComparator);
498 
499         if (list.isEmpty()) {
500             StringBundler msg = new StringBundler(4);
501 
502             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
503 
504             msg.append("orderId=");
505             msg.append(orderId);
506 
507             msg.append(StringPool.CLOSE_CURLY_BRACE);
508 
509             throw new NoSuchOrderItemException(msg.toString());
510         }
511         else {
512             return list.get(0);
513         }
514     }
515 
516     public ShoppingOrderItem[] findByOrderId_PrevAndNext(long orderItemId,
517         long orderId, OrderByComparator orderByComparator)
518         throws NoSuchOrderItemException, SystemException {
519         ShoppingOrderItem shoppingOrderItem = findByPrimaryKey(orderItemId);
520 
521         int count = countByOrderId(orderId);
522 
523         Session session = null;
524 
525         try {
526             session = openSession();
527 
528             StringBundler query = null;
529 
530             if (orderByComparator != null) {
531                 query = new StringBundler(3 +
532                         (orderByComparator.getOrderByFields().length * 3));
533             }
534             else {
535                 query = new StringBundler(3);
536             }
537 
538             query.append(_SQL_SELECT_SHOPPINGORDERITEM_WHERE);
539 
540             query.append(_FINDER_COLUMN_ORDERID_ORDERID_2);
541 
542             if (orderByComparator != null) {
543                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
544                     orderByComparator);
545             }
546 
547             else {
548                 query.append(ShoppingOrderItemModelImpl.ORDER_BY_JPQL);
549             }
550 
551             String sql = query.toString();
552 
553             Query q = session.createQuery(sql);
554 
555             QueryPos qPos = QueryPos.getInstance(q);
556 
557             qPos.add(orderId);
558 
559             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
560                     orderByComparator, shoppingOrderItem);
561 
562             ShoppingOrderItem[] array = new ShoppingOrderItemImpl[3];
563 
564             array[0] = (ShoppingOrderItem)objArray[0];
565             array[1] = (ShoppingOrderItem)objArray[1];
566             array[2] = (ShoppingOrderItem)objArray[2];
567 
568             return array;
569         }
570         catch (Exception e) {
571             throw processException(e);
572         }
573         finally {
574             closeSession(session);
575         }
576     }
577 
578     public List<ShoppingOrderItem> findAll() throws SystemException {
579         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
580     }
581 
582     public List<ShoppingOrderItem> findAll(int start, int end)
583         throws SystemException {
584         return findAll(start, end, null);
585     }
586 
587     public List<ShoppingOrderItem> findAll(int start, int end,
588         OrderByComparator orderByComparator) throws SystemException {
589         Object[] finderArgs = new Object[] {
590                 String.valueOf(start), String.valueOf(end),
591                 String.valueOf(orderByComparator)
592             };
593 
594         List<ShoppingOrderItem> list = (List<ShoppingOrderItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
595                 finderArgs, this);
596 
597         if (list == null) {
598             Session session = null;
599 
600             try {
601                 session = openSession();
602 
603                 StringBundler query = null;
604                 String sql = null;
605 
606                 if (orderByComparator != null) {
607                     query = new StringBundler(2 +
608                             (orderByComparator.getOrderByFields().length * 3));
609 
610                     query.append(_SQL_SELECT_SHOPPINGORDERITEM);
611 
612                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
613                         orderByComparator);
614 
615                     sql = query.toString();
616                 }
617 
618                 else {
619                     sql = _SQL_SELECT_SHOPPINGORDERITEM.concat(ShoppingOrderItemModelImpl.ORDER_BY_JPQL);
620                 }
621 
622                 Query q = session.createQuery(sql);
623 
624                 if (orderByComparator == null) {
625                     list = (List<ShoppingOrderItem>)QueryUtil.list(q,
626                             getDialect(), start, end, false);
627 
628                     Collections.sort(list);
629                 }
630                 else {
631                     list = (List<ShoppingOrderItem>)QueryUtil.list(q,
632                             getDialect(), start, end);
633                 }
634             }
635             catch (Exception e) {
636                 throw processException(e);
637             }
638             finally {
639                 if (list == null) {
640                     list = new ArrayList<ShoppingOrderItem>();
641                 }
642 
643                 cacheResult(list);
644 
645                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
646 
647                 closeSession(session);
648             }
649         }
650 
651         return list;
652     }
653 
654     public void removeByOrderId(long orderId) throws SystemException {
655         for (ShoppingOrderItem shoppingOrderItem : findByOrderId(orderId)) {
656             remove(shoppingOrderItem);
657         }
658     }
659 
660     public void removeAll() throws SystemException {
661         for (ShoppingOrderItem shoppingOrderItem : findAll()) {
662             remove(shoppingOrderItem);
663         }
664     }
665 
666     public int countByOrderId(long orderId) throws SystemException {
667         Object[] finderArgs = new Object[] { new Long(orderId) };
668 
669         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ORDERID,
670                 finderArgs, this);
671 
672         if (count == null) {
673             Session session = null;
674 
675             try {
676                 session = openSession();
677 
678                 StringBundler query = new StringBundler(2);
679 
680                 query.append(_SQL_COUNT_SHOPPINGORDERITEM_WHERE);
681 
682                 query.append(_FINDER_COLUMN_ORDERID_ORDERID_2);
683 
684                 String sql = query.toString();
685 
686                 Query q = session.createQuery(sql);
687 
688                 QueryPos qPos = QueryPos.getInstance(q);
689 
690                 qPos.add(orderId);
691 
692                 count = (Long)q.uniqueResult();
693             }
694             catch (Exception e) {
695                 throw processException(e);
696             }
697             finally {
698                 if (count == null) {
699                     count = Long.valueOf(0);
700                 }
701 
702                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ORDERID,
703                     finderArgs, count);
704 
705                 closeSession(session);
706             }
707         }
708 
709         return count.intValue();
710     }
711 
712     public int countAll() throws SystemException {
713         Object[] finderArgs = new Object[0];
714 
715         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
716                 finderArgs, this);
717 
718         if (count == null) {
719             Session session = null;
720 
721             try {
722                 session = openSession();
723 
724                 Query q = session.createQuery(_SQL_COUNT_SHOPPINGORDERITEM);
725 
726                 count = (Long)q.uniqueResult();
727             }
728             catch (Exception e) {
729                 throw processException(e);
730             }
731             finally {
732                 if (count == null) {
733                     count = Long.valueOf(0);
734                 }
735 
736                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
737                     count);
738 
739                 closeSession(session);
740             }
741         }
742 
743         return count.intValue();
744     }
745 
746     public void afterPropertiesSet() {
747         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
748                     com.liferay.portal.util.PropsUtil.get(
749                         "value.object.listener.com.liferay.portlet.shopping.model.ShoppingOrderItem")));
750 
751         if (listenerClassNames.length > 0) {
752             try {
753                 List<ModelListener<ShoppingOrderItem>> listenersList = new ArrayList<ModelListener<ShoppingOrderItem>>();
754 
755                 for (String listenerClassName : listenerClassNames) {
756                     listenersList.add((ModelListener<ShoppingOrderItem>)Class.forName(
757                             listenerClassName).newInstance());
758                 }
759 
760                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
761             }
762             catch (Exception e) {
763                 _log.error(e);
764             }
765         }
766     }
767 
768     @BeanReference(type = ShoppingCartPersistence.class)
769     protected ShoppingCartPersistence shoppingCartPersistence;
770     @BeanReference(type = ShoppingCategoryPersistence.class)
771     protected ShoppingCategoryPersistence shoppingCategoryPersistence;
772     @BeanReference(type = ShoppingCouponPersistence.class)
773     protected ShoppingCouponPersistence shoppingCouponPersistence;
774     @BeanReference(type = ShoppingItemPersistence.class)
775     protected ShoppingItemPersistence shoppingItemPersistence;
776     @BeanReference(type = ShoppingItemFieldPersistence.class)
777     protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
778     @BeanReference(type = ShoppingItemPricePersistence.class)
779     protected ShoppingItemPricePersistence shoppingItemPricePersistence;
780     @BeanReference(type = ShoppingOrderPersistence.class)
781     protected ShoppingOrderPersistence shoppingOrderPersistence;
782     @BeanReference(type = ShoppingOrderItemPersistence.class)
783     protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
784     @BeanReference(type = ResourcePersistence.class)
785     protected ResourcePersistence resourcePersistence;
786     @BeanReference(type = UserPersistence.class)
787     protected UserPersistence userPersistence;
788     private static final String _SQL_SELECT_SHOPPINGORDERITEM = "SELECT shoppingOrderItem FROM ShoppingOrderItem shoppingOrderItem";
789     private static final String _SQL_SELECT_SHOPPINGORDERITEM_WHERE = "SELECT shoppingOrderItem FROM ShoppingOrderItem shoppingOrderItem WHERE ";
790     private static final String _SQL_COUNT_SHOPPINGORDERITEM = "SELECT COUNT(shoppingOrderItem) FROM ShoppingOrderItem shoppingOrderItem";
791     private static final String _SQL_COUNT_SHOPPINGORDERITEM_WHERE = "SELECT COUNT(shoppingOrderItem) FROM ShoppingOrderItem shoppingOrderItem WHERE ";
792     private static final String _FINDER_COLUMN_ORDERID_ORDERID_2 = "shoppingOrderItem.orderId = ?";
793     private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingOrderItem.";
794     private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingOrderItem exists with the primary key ";
795     private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingOrderItem exists with the key {";
796     private static Log _log = LogFactoryUtil.getLog(ShoppingOrderItemPersistenceImpl.class);
797 }