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