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