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