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