1   /**
2    * Copyright (c) 2000-2008 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.bean.InitializingBean;
27  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
28  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
29  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
30  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
31  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
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.SQLQuery;
36  import com.liferay.portal.kernel.dao.orm.Session;
37  import com.liferay.portal.kernel.dao.orm.Type;
38  import com.liferay.portal.kernel.util.GetterUtil;
39  import com.liferay.portal.kernel.util.ListUtil;
40  import com.liferay.portal.kernel.util.OrderByComparator;
41  import com.liferay.portal.kernel.util.StringPool;
42  import com.liferay.portal.kernel.util.StringUtil;
43  import com.liferay.portal.model.ModelListener;
44  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45  
46  import com.liferay.portlet.shopping.NoSuchItemException;
47  import com.liferay.portlet.shopping.model.ShoppingItem;
48  import com.liferay.portlet.shopping.model.impl.ShoppingItemImpl;
49  import com.liferay.portlet.shopping.model.impl.ShoppingItemModelImpl;
50  
51  import org.apache.commons.logging.Log;
52  import org.apache.commons.logging.LogFactory;
53  
54  import java.sql.Types;
55  
56  import java.util.ArrayList;
57  import java.util.Collections;
58  import java.util.Iterator;
59  import java.util.List;
60  
61  /**
62   * <a href="ShoppingItemPersistenceImpl.java.html"><b><i>View Source</i></b></a>
63   *
64   * @author Brian Wing Shun Chan
65   *
66   */
67  public class ShoppingItemPersistenceImpl extends BasePersistenceImpl
68      implements ShoppingItemPersistence, InitializingBean {
69      public ShoppingItem create(long itemId) {
70          ShoppingItem shoppingItem = new ShoppingItemImpl();
71  
72          shoppingItem.setNew(true);
73          shoppingItem.setPrimaryKey(itemId);
74  
75          return shoppingItem;
76      }
77  
78      public ShoppingItem remove(long itemId)
79          throws NoSuchItemException, SystemException {
80          Session session = null;
81  
82          try {
83              session = openSession();
84  
85              ShoppingItem shoppingItem = (ShoppingItem)session.get(ShoppingItemImpl.class,
86                      new Long(itemId));
87  
88              if (shoppingItem == null) {
89                  if (_log.isWarnEnabled()) {
90                      _log.warn("No ShoppingItem exists with the primary key " +
91                          itemId);
92                  }
93  
94                  throw new NoSuchItemException(
95                      "No ShoppingItem exists with the primary key " + itemId);
96              }
97  
98              return remove(shoppingItem);
99          }
100         catch (NoSuchItemException nsee) {
101             throw nsee;
102         }
103         catch (Exception e) {
104             throw processException(e);
105         }
106         finally {
107             closeSession(session);
108         }
109     }
110 
111     public ShoppingItem remove(ShoppingItem shoppingItem)
112         throws SystemException {
113         if (_listeners.length > 0) {
114             for (ModelListener listener : _listeners) {
115                 listener.onBeforeRemove(shoppingItem);
116             }
117         }
118 
119         shoppingItem = removeImpl(shoppingItem);
120 
121         if (_listeners.length > 0) {
122             for (ModelListener listener : _listeners) {
123                 listener.onAfterRemove(shoppingItem);
124             }
125         }
126 
127         return shoppingItem;
128     }
129 
130     protected ShoppingItem removeImpl(ShoppingItem shoppingItem)
131         throws SystemException {
132         Session session = null;
133 
134         try {
135             session = openSession();
136 
137             session.delete(shoppingItem);
138 
139             session.flush();
140 
141             return shoppingItem;
142         }
143         catch (Exception e) {
144             throw processException(e);
145         }
146         finally {
147             closeSession(session);
148 
149             FinderCacheUtil.clearCache(ShoppingItem.class.getName());
150         }
151     }
152 
153     /**
154      * @deprecated Use <code>update(ShoppingItem shoppingItem, boolean merge)</code>.
155      */
156     public ShoppingItem update(ShoppingItem shoppingItem)
157         throws SystemException {
158         if (_log.isWarnEnabled()) {
159             _log.warn(
160                 "Using the deprecated update(ShoppingItem shoppingItem) method. Use update(ShoppingItem shoppingItem, boolean merge) instead.");
161         }
162 
163         return update(shoppingItem, false);
164     }
165 
166     /**
167      * Add, update, or merge, the entity. This method also calls the model
168      * listeners to trigger the proper events associated with adding, deleting,
169      * or updating an entity.
170      *
171      * @param        shoppingItem the entity to add, update, or merge
172      * @param        merge boolean value for whether to merge the entity. The
173      *                default value is false. Setting merge to true is more
174      *                expensive and should only be true when shoppingItem is
175      *                transient. See LEP-5473 for a detailed discussion of this
176      *                method.
177      * @return        true if the portlet can be displayed via Ajax
178      */
179     public ShoppingItem update(ShoppingItem shoppingItem, boolean merge)
180         throws SystemException {
181         boolean isNew = shoppingItem.isNew();
182 
183         if (_listeners.length > 0) {
184             for (ModelListener listener : _listeners) {
185                 if (isNew) {
186                     listener.onBeforeCreate(shoppingItem);
187                 }
188                 else {
189                     listener.onBeforeUpdate(shoppingItem);
190                 }
191             }
192         }
193 
194         shoppingItem = updateImpl(shoppingItem, merge);
195 
196         if (_listeners.length > 0) {
197             for (ModelListener listener : _listeners) {
198                 if (isNew) {
199                     listener.onAfterCreate(shoppingItem);
200                 }
201                 else {
202                     listener.onAfterUpdate(shoppingItem);
203                 }
204             }
205         }
206 
207         return shoppingItem;
208     }
209 
210     public ShoppingItem updateImpl(
211         com.liferay.portlet.shopping.model.ShoppingItem shoppingItem,
212         boolean merge) throws SystemException {
213         Session session = null;
214 
215         try {
216             session = openSession();
217 
218             if (merge) {
219                 session.merge(shoppingItem);
220             }
221             else {
222                 if (shoppingItem.isNew()) {
223                     session.save(shoppingItem);
224                 }
225             }
226 
227             session.flush();
228 
229             shoppingItem.setNew(false);
230 
231             return shoppingItem;
232         }
233         catch (Exception e) {
234             throw processException(e);
235         }
236         finally {
237             closeSession(session);
238 
239             FinderCacheUtil.clearCache(ShoppingItem.class.getName());
240         }
241     }
242 
243     public ShoppingItem findByPrimaryKey(long itemId)
244         throws NoSuchItemException, SystemException {
245         ShoppingItem shoppingItem = fetchByPrimaryKey(itemId);
246 
247         if (shoppingItem == null) {
248             if (_log.isWarnEnabled()) {
249                 _log.warn("No ShoppingItem exists with the primary key " +
250                     itemId);
251             }
252 
253             throw new NoSuchItemException(
254                 "No ShoppingItem exists with the primary key " + itemId);
255         }
256 
257         return shoppingItem;
258     }
259 
260     public ShoppingItem fetchByPrimaryKey(long itemId)
261         throws SystemException {
262         Session session = null;
263 
264         try {
265             session = openSession();
266 
267             return (ShoppingItem)session.get(ShoppingItemImpl.class,
268                 new Long(itemId));
269         }
270         catch (Exception e) {
271             throw processException(e);
272         }
273         finally {
274             closeSession(session);
275         }
276     }
277 
278     public List<ShoppingItem> findByCategoryId(long categoryId)
279         throws SystemException {
280         boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
281         String finderClassName = ShoppingItem.class.getName();
282         String finderMethodName = "findByCategoryId";
283         String[] finderParams = new String[] { Long.class.getName() };
284         Object[] finderArgs = new Object[] { new Long(categoryId) };
285 
286         Object result = null;
287 
288         if (finderClassNameCacheEnabled) {
289             result = FinderCacheUtil.getResult(finderClassName,
290                     finderMethodName, finderParams, finderArgs, this);
291         }
292 
293         if (result == null) {
294             Session session = null;
295 
296             try {
297                 session = openSession();
298 
299                 StringBuilder query = new StringBuilder();
300 
301                 query.append(
302                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
303 
304                 query.append("categoryId = ?");
305 
306                 query.append(" ");
307 
308                 query.append("ORDER BY ");
309 
310                 query.append("itemId ASC");
311 
312                 Query q = session.createQuery(query.toString());
313 
314                 QueryPos qPos = QueryPos.getInstance(q);
315 
316                 qPos.add(categoryId);
317 
318                 List<ShoppingItem> list = q.list();
319 
320                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
321                     finderClassName, finderMethodName, finderParams,
322                     finderArgs, list);
323 
324                 return list;
325             }
326             catch (Exception e) {
327                 throw processException(e);
328             }
329             finally {
330                 closeSession(session);
331             }
332         }
333         else {
334             return (List<ShoppingItem>)result;
335         }
336     }
337 
338     public List<ShoppingItem> findByCategoryId(long categoryId, int start,
339         int end) throws SystemException {
340         return findByCategoryId(categoryId, start, end, null);
341     }
342 
343     public List<ShoppingItem> findByCategoryId(long categoryId, int start,
344         int end, OrderByComparator obc) throws SystemException {
345         boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
346         String finderClassName = ShoppingItem.class.getName();
347         String finderMethodName = "findByCategoryId";
348         String[] finderParams = new String[] {
349                 Long.class.getName(),
350                 
351                 "java.lang.Integer", "java.lang.Integer",
352                 "com.liferay.portal.kernel.util.OrderByComparator"
353             };
354         Object[] finderArgs = new Object[] {
355                 new Long(categoryId),
356                 
357                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
358             };
359 
360         Object result = null;
361 
362         if (finderClassNameCacheEnabled) {
363             result = FinderCacheUtil.getResult(finderClassName,
364                     finderMethodName, finderParams, finderArgs, this);
365         }
366 
367         if (result == null) {
368             Session session = null;
369 
370             try {
371                 session = openSession();
372 
373                 StringBuilder query = new StringBuilder();
374 
375                 query.append(
376                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
377 
378                 query.append("categoryId = ?");
379 
380                 query.append(" ");
381 
382                 if (obc != null) {
383                     query.append("ORDER BY ");
384                     query.append(obc.getOrderBy());
385                 }
386 
387                 else {
388                     query.append("ORDER BY ");
389 
390                     query.append("itemId ASC");
391                 }
392 
393                 Query q = session.createQuery(query.toString());
394 
395                 QueryPos qPos = QueryPos.getInstance(q);
396 
397                 qPos.add(categoryId);
398 
399                 List<ShoppingItem> list = (List<ShoppingItem>)QueryUtil.list(q,
400                         getDialect(), start, end);
401 
402                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
403                     finderClassName, finderMethodName, finderParams,
404                     finderArgs, list);
405 
406                 return list;
407             }
408             catch (Exception e) {
409                 throw processException(e);
410             }
411             finally {
412                 closeSession(session);
413             }
414         }
415         else {
416             return (List<ShoppingItem>)result;
417         }
418     }
419 
420     public ShoppingItem findByCategoryId_First(long categoryId,
421         OrderByComparator obc) throws NoSuchItemException, SystemException {
422         List<ShoppingItem> list = findByCategoryId(categoryId, 0, 1, obc);
423 
424         if (list.size() == 0) {
425             StringBuilder msg = new StringBuilder();
426 
427             msg.append("No ShoppingItem exists with the key {");
428 
429             msg.append("categoryId=" + categoryId);
430 
431             msg.append(StringPool.CLOSE_CURLY_BRACE);
432 
433             throw new NoSuchItemException(msg.toString());
434         }
435         else {
436             return list.get(0);
437         }
438     }
439 
440     public ShoppingItem findByCategoryId_Last(long categoryId,
441         OrderByComparator obc) throws NoSuchItemException, SystemException {
442         int count = countByCategoryId(categoryId);
443 
444         List<ShoppingItem> list = findByCategoryId(categoryId, count - 1,
445                 count, obc);
446 
447         if (list.size() == 0) {
448             StringBuilder msg = new StringBuilder();
449 
450             msg.append("No ShoppingItem exists with the key {");
451 
452             msg.append("categoryId=" + categoryId);
453 
454             msg.append(StringPool.CLOSE_CURLY_BRACE);
455 
456             throw new NoSuchItemException(msg.toString());
457         }
458         else {
459             return list.get(0);
460         }
461     }
462 
463     public ShoppingItem[] findByCategoryId_PrevAndNext(long itemId,
464         long categoryId, OrderByComparator obc)
465         throws NoSuchItemException, SystemException {
466         ShoppingItem shoppingItem = findByPrimaryKey(itemId);
467 
468         int count = countByCategoryId(categoryId);
469 
470         Session session = null;
471 
472         try {
473             session = openSession();
474 
475             StringBuilder query = new StringBuilder();
476 
477             query.append(
478                 "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
479 
480             query.append("categoryId = ?");
481 
482             query.append(" ");
483 
484             if (obc != null) {
485                 query.append("ORDER BY ");
486                 query.append(obc.getOrderBy());
487             }
488 
489             else {
490                 query.append("ORDER BY ");
491 
492                 query.append("itemId ASC");
493             }
494 
495             Query q = session.createQuery(query.toString());
496 
497             QueryPos qPos = QueryPos.getInstance(q);
498 
499             qPos.add(categoryId);
500 
501             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
502                     shoppingItem);
503 
504             ShoppingItem[] array = new ShoppingItemImpl[3];
505 
506             array[0] = (ShoppingItem)objArray[0];
507             array[1] = (ShoppingItem)objArray[1];
508             array[2] = (ShoppingItem)objArray[2];
509 
510             return array;
511         }
512         catch (Exception e) {
513             throw processException(e);
514         }
515         finally {
516             closeSession(session);
517         }
518     }
519 
520     public ShoppingItem findBySmallImageId(long smallImageId)
521         throws NoSuchItemException, SystemException {
522         ShoppingItem shoppingItem = fetchBySmallImageId(smallImageId);
523 
524         if (shoppingItem == null) {
525             StringBuilder msg = new StringBuilder();
526 
527             msg.append("No ShoppingItem exists with the key {");
528 
529             msg.append("smallImageId=" + smallImageId);
530 
531             msg.append(StringPool.CLOSE_CURLY_BRACE);
532 
533             if (_log.isWarnEnabled()) {
534                 _log.warn(msg.toString());
535             }
536 
537             throw new NoSuchItemException(msg.toString());
538         }
539 
540         return shoppingItem;
541     }
542 
543     public ShoppingItem fetchBySmallImageId(long smallImageId)
544         throws SystemException {
545         boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
546         String finderClassName = ShoppingItem.class.getName();
547         String finderMethodName = "fetchBySmallImageId";
548         String[] finderParams = new String[] { Long.class.getName() };
549         Object[] finderArgs = new Object[] { new Long(smallImageId) };
550 
551         Object result = null;
552 
553         if (finderClassNameCacheEnabled) {
554             result = FinderCacheUtil.getResult(finderClassName,
555                     finderMethodName, finderParams, finderArgs, this);
556         }
557 
558         if (result == null) {
559             Session session = null;
560 
561             try {
562                 session = openSession();
563 
564                 StringBuilder query = new StringBuilder();
565 
566                 query.append(
567                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
568 
569                 query.append("smallImageId = ?");
570 
571                 query.append(" ");
572 
573                 query.append("ORDER BY ");
574 
575                 query.append("itemId ASC");
576 
577                 Query q = session.createQuery(query.toString());
578 
579                 QueryPos qPos = QueryPos.getInstance(q);
580 
581                 qPos.add(smallImageId);
582 
583                 List<ShoppingItem> list = q.list();
584 
585                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
586                     finderClassName, finderMethodName, finderParams,
587                     finderArgs, list);
588 
589                 if (list.size() == 0) {
590                     return null;
591                 }
592                 else {
593                     return list.get(0);
594                 }
595             }
596             catch (Exception e) {
597                 throw processException(e);
598             }
599             finally {
600                 closeSession(session);
601             }
602         }
603         else {
604             List<ShoppingItem> list = (List<ShoppingItem>)result;
605 
606             if (list.size() == 0) {
607                 return null;
608             }
609             else {
610                 return list.get(0);
611             }
612         }
613     }
614 
615     public ShoppingItem findByMediumImageId(long mediumImageId)
616         throws NoSuchItemException, SystemException {
617         ShoppingItem shoppingItem = fetchByMediumImageId(mediumImageId);
618 
619         if (shoppingItem == null) {
620             StringBuilder msg = new StringBuilder();
621 
622             msg.append("No ShoppingItem exists with the key {");
623 
624             msg.append("mediumImageId=" + mediumImageId);
625 
626             msg.append(StringPool.CLOSE_CURLY_BRACE);
627 
628             if (_log.isWarnEnabled()) {
629                 _log.warn(msg.toString());
630             }
631 
632             throw new NoSuchItemException(msg.toString());
633         }
634 
635         return shoppingItem;
636     }
637 
638     public ShoppingItem fetchByMediumImageId(long mediumImageId)
639         throws SystemException {
640         boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
641         String finderClassName = ShoppingItem.class.getName();
642         String finderMethodName = "fetchByMediumImageId";
643         String[] finderParams = new String[] { Long.class.getName() };
644         Object[] finderArgs = new Object[] { new Long(mediumImageId) };
645 
646         Object result = null;
647 
648         if (finderClassNameCacheEnabled) {
649             result = FinderCacheUtil.getResult(finderClassName,
650                     finderMethodName, finderParams, finderArgs, this);
651         }
652 
653         if (result == null) {
654             Session session = null;
655 
656             try {
657                 session = openSession();
658 
659                 StringBuilder query = new StringBuilder();
660 
661                 query.append(
662                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
663 
664                 query.append("mediumImageId = ?");
665 
666                 query.append(" ");
667 
668                 query.append("ORDER BY ");
669 
670                 query.append("itemId ASC");
671 
672                 Query q = session.createQuery(query.toString());
673 
674                 QueryPos qPos = QueryPos.getInstance(q);
675 
676                 qPos.add(mediumImageId);
677 
678                 List<ShoppingItem> list = q.list();
679 
680                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
681                     finderClassName, finderMethodName, finderParams,
682                     finderArgs, list);
683 
684                 if (list.size() == 0) {
685                     return null;
686                 }
687                 else {
688                     return list.get(0);
689                 }
690             }
691             catch (Exception e) {
692                 throw processException(e);
693             }
694             finally {
695                 closeSession(session);
696             }
697         }
698         else {
699             List<ShoppingItem> list = (List<ShoppingItem>)result;
700 
701             if (list.size() == 0) {
702                 return null;
703             }
704             else {
705                 return list.get(0);
706             }
707         }
708     }
709 
710     public ShoppingItem findByLargeImageId(long largeImageId)
711         throws NoSuchItemException, SystemException {
712         ShoppingItem shoppingItem = fetchByLargeImageId(largeImageId);
713 
714         if (shoppingItem == null) {
715             StringBuilder msg = new StringBuilder();
716 
717             msg.append("No ShoppingItem exists with the key {");
718 
719             msg.append("largeImageId=" + largeImageId);
720 
721             msg.append(StringPool.CLOSE_CURLY_BRACE);
722 
723             if (_log.isWarnEnabled()) {
724                 _log.warn(msg.toString());
725             }
726 
727             throw new NoSuchItemException(msg.toString());
728         }
729 
730         return shoppingItem;
731     }
732 
733     public ShoppingItem fetchByLargeImageId(long largeImageId)
734         throws SystemException {
735         boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
736         String finderClassName = ShoppingItem.class.getName();
737         String finderMethodName = "fetchByLargeImageId";
738         String[] finderParams = new String[] { Long.class.getName() };
739         Object[] finderArgs = new Object[] { new Long(largeImageId) };
740 
741         Object result = null;
742 
743         if (finderClassNameCacheEnabled) {
744             result = FinderCacheUtil.getResult(finderClassName,
745                     finderMethodName, finderParams, finderArgs, this);
746         }
747 
748         if (result == null) {
749             Session session = null;
750 
751             try {
752                 session = openSession();
753 
754                 StringBuilder query = new StringBuilder();
755 
756                 query.append(
757                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
758 
759                 query.append("largeImageId = ?");
760 
761                 query.append(" ");
762 
763                 query.append("ORDER BY ");
764 
765                 query.append("itemId ASC");
766 
767                 Query q = session.createQuery(query.toString());
768 
769                 QueryPos qPos = QueryPos.getInstance(q);
770 
771                 qPos.add(largeImageId);
772 
773                 List<ShoppingItem> list = q.list();
774 
775                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
776                     finderClassName, finderMethodName, finderParams,
777                     finderArgs, list);
778 
779                 if (list.size() == 0) {
780                     return null;
781                 }
782                 else {
783                     return list.get(0);
784                 }
785             }
786             catch (Exception e) {
787                 throw processException(e);
788             }
789             finally {
790                 closeSession(session);
791             }
792         }
793         else {
794             List<ShoppingItem> list = (List<ShoppingItem>)result;
795 
796             if (list.size() == 0) {
797                 return null;
798             }
799             else {
800                 return list.get(0);
801             }
802         }
803     }
804 
805     public ShoppingItem findByC_S(long companyId, String sku)
806         throws NoSuchItemException, SystemException {
807         ShoppingItem shoppingItem = fetchByC_S(companyId, sku);
808 
809         if (shoppingItem == null) {
810             StringBuilder msg = new StringBuilder();
811 
812             msg.append("No ShoppingItem exists with the key {");
813 
814             msg.append("companyId=" + companyId);
815 
816             msg.append(", ");
817             msg.append("sku=" + sku);
818 
819             msg.append(StringPool.CLOSE_CURLY_BRACE);
820 
821             if (_log.isWarnEnabled()) {
822                 _log.warn(msg.toString());
823             }
824 
825             throw new NoSuchItemException(msg.toString());
826         }
827 
828         return shoppingItem;
829     }
830 
831     public ShoppingItem fetchByC_S(long companyId, String sku)
832         throws SystemException {
833         boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
834         String finderClassName = ShoppingItem.class.getName();
835         String finderMethodName = "fetchByC_S";
836         String[] finderParams = new String[] {
837                 Long.class.getName(), String.class.getName()
838             };
839         Object[] finderArgs = new Object[] { new Long(companyId), sku };
840 
841         Object result = null;
842 
843         if (finderClassNameCacheEnabled) {
844             result = FinderCacheUtil.getResult(finderClassName,
845                     finderMethodName, finderParams, finderArgs, this);
846         }
847 
848         if (result == null) {
849             Session session = null;
850 
851             try {
852                 session = openSession();
853 
854                 StringBuilder query = new StringBuilder();
855 
856                 query.append(
857                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
858 
859                 query.append("companyId = ?");
860 
861                 query.append(" AND ");
862 
863                 if (sku == null) {
864                     query.append("sku IS NULL");
865                 }
866                 else {
867                     query.append("sku = ?");
868                 }
869 
870                 query.append(" ");
871 
872                 query.append("ORDER BY ");
873 
874                 query.append("itemId ASC");
875 
876                 Query q = session.createQuery(query.toString());
877 
878                 QueryPos qPos = QueryPos.getInstance(q);
879 
880                 qPos.add(companyId);
881 
882                 if (sku != null) {
883                     qPos.add(sku);
884                 }
885 
886                 List<ShoppingItem> list = q.list();
887 
888                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
889                     finderClassName, finderMethodName, finderParams,
890                     finderArgs, list);
891 
892                 if (list.size() == 0) {
893                     return null;
894                 }
895                 else {
896                     return list.get(0);
897                 }
898             }
899             catch (Exception e) {
900                 throw processException(e);
901             }
902             finally {
903                 closeSession(session);
904             }
905         }
906         else {
907             List<ShoppingItem> list = (List<ShoppingItem>)result;
908 
909             if (list.size() == 0) {
910                 return null;
911             }
912             else {
913                 return list.get(0);
914             }
915         }
916     }
917 
918     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
919         throws SystemException {
920         Session session = null;
921 
922         try {
923             session = openSession();
924 
925             dynamicQuery.compile(session);
926 
927             return dynamicQuery.list();
928         }
929         catch (Exception e) {
930             throw processException(e);
931         }
932         finally {
933             closeSession(session);
934         }
935     }
936 
937     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
938         int start, int end) throws SystemException {
939         Session session = null;
940 
941         try {
942             session = openSession();
943 
944             dynamicQuery.setLimit(start, end);
945 
946             dynamicQuery.compile(session);
947 
948             return dynamicQuery.list();
949         }
950         catch (Exception e) {
951             throw processException(e);
952         }
953         finally {
954             closeSession(session);
955         }
956     }
957 
958     public List<ShoppingItem> findAll() throws SystemException {
959         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
960     }
961 
962     public List<ShoppingItem> findAll(int start, int end)
963         throws SystemException {
964         return findAll(start, end, null);
965     }
966 
967     public List<ShoppingItem> findAll(int start, int end, OrderByComparator obc)
968         throws SystemException {
969         boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
970         String finderClassName = ShoppingItem.class.getName();
971         String finderMethodName = "findAll";
972         String[] finderParams = new String[] {
973                 "java.lang.Integer", "java.lang.Integer",
974                 "com.liferay.portal.kernel.util.OrderByComparator"
975             };
976         Object[] finderArgs = new Object[] {
977                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
978             };
979 
980         Object result = null;
981 
982         if (finderClassNameCacheEnabled) {
983             result = FinderCacheUtil.getResult(finderClassName,
984                     finderMethodName, finderParams, finderArgs, this);
985         }
986 
987         if (result == null) {
988             Session session = null;
989 
990             try {
991                 session = openSession();
992 
993                 StringBuilder query = new StringBuilder();
994 
995                 query.append(
996                     "FROM com.liferay.portlet.shopping.model.ShoppingItem ");
997 
998                 if (obc != null) {
999                     query.append("ORDER BY ");
1000                    query.append(obc.getOrderBy());
1001                }
1002
1003                else {
1004                    query.append("ORDER BY ");
1005
1006                    query.append("itemId ASC");
1007                }
1008
1009                Query q = session.createQuery(query.toString());
1010
1011                List<ShoppingItem> list = (List<ShoppingItem>)QueryUtil.list(q,
1012                        getDialect(), start, end);
1013
1014                if (obc == null) {
1015                    Collections.sort(list);
1016                }
1017
1018                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1019                    finderClassName, finderMethodName, finderParams,
1020                    finderArgs, list);
1021
1022                return list;
1023            }
1024            catch (Exception e) {
1025                throw processException(e);
1026            }
1027            finally {
1028                closeSession(session);
1029            }
1030        }
1031        else {
1032            return (List<ShoppingItem>)result;
1033        }
1034    }
1035
1036    public void removeByCategoryId(long categoryId) throws SystemException {
1037        for (ShoppingItem shoppingItem : findByCategoryId(categoryId)) {
1038            remove(shoppingItem);
1039        }
1040    }
1041
1042    public void removeBySmallImageId(long smallImageId)
1043        throws NoSuchItemException, SystemException {
1044        ShoppingItem shoppingItem = findBySmallImageId(smallImageId);
1045
1046        remove(shoppingItem);
1047    }
1048
1049    public void removeByMediumImageId(long mediumImageId)
1050        throws NoSuchItemException, SystemException {
1051        ShoppingItem shoppingItem = findByMediumImageId(mediumImageId);
1052
1053        remove(shoppingItem);
1054    }
1055
1056    public void removeByLargeImageId(long largeImageId)
1057        throws NoSuchItemException, SystemException {
1058        ShoppingItem shoppingItem = findByLargeImageId(largeImageId);
1059
1060        remove(shoppingItem);
1061    }
1062
1063    public void removeByC_S(long companyId, String sku)
1064        throws NoSuchItemException, SystemException {
1065        ShoppingItem shoppingItem = findByC_S(companyId, sku);
1066
1067        remove(shoppingItem);
1068    }
1069
1070    public void removeAll() throws SystemException {
1071        for (ShoppingItem shoppingItem : findAll()) {
1072            remove(shoppingItem);
1073        }
1074    }
1075
1076    public int countByCategoryId(long categoryId) throws SystemException {
1077        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1078        String finderClassName = ShoppingItem.class.getName();
1079        String finderMethodName = "countByCategoryId";
1080        String[] finderParams = new String[] { Long.class.getName() };
1081        Object[] finderArgs = new Object[] { new Long(categoryId) };
1082
1083        Object result = null;
1084
1085        if (finderClassNameCacheEnabled) {
1086            result = FinderCacheUtil.getResult(finderClassName,
1087                    finderMethodName, finderParams, finderArgs, this);
1088        }
1089
1090        if (result == null) {
1091            Session session = null;
1092
1093            try {
1094                session = openSession();
1095
1096                StringBuilder query = new StringBuilder();
1097
1098                query.append("SELECT COUNT(*) ");
1099                query.append(
1100                    "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
1101
1102                query.append("categoryId = ?");
1103
1104                query.append(" ");
1105
1106                Query q = session.createQuery(query.toString());
1107
1108                QueryPos qPos = QueryPos.getInstance(q);
1109
1110                qPos.add(categoryId);
1111
1112                Long count = null;
1113
1114                Iterator<Long> itr = q.list().iterator();
1115
1116                if (itr.hasNext()) {
1117                    count = itr.next();
1118                }
1119
1120                if (count == null) {
1121                    count = new Long(0);
1122                }
1123
1124                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1125                    finderClassName, finderMethodName, finderParams,
1126                    finderArgs, count);
1127
1128                return count.intValue();
1129            }
1130            catch (Exception e) {
1131                throw processException(e);
1132            }
1133            finally {
1134                closeSession(session);
1135            }
1136        }
1137        else {
1138            return ((Long)result).intValue();
1139        }
1140    }
1141
1142    public int countBySmallImageId(long smallImageId) throws SystemException {
1143        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1144        String finderClassName = ShoppingItem.class.getName();
1145        String finderMethodName = "countBySmallImageId";
1146        String[] finderParams = new String[] { Long.class.getName() };
1147        Object[] finderArgs = new Object[] { new Long(smallImageId) };
1148
1149        Object result = null;
1150
1151        if (finderClassNameCacheEnabled) {
1152            result = FinderCacheUtil.getResult(finderClassName,
1153                    finderMethodName, finderParams, finderArgs, this);
1154        }
1155
1156        if (result == null) {
1157            Session session = null;
1158
1159            try {
1160                session = openSession();
1161
1162                StringBuilder query = new StringBuilder();
1163
1164                query.append("SELECT COUNT(*) ");
1165                query.append(
1166                    "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
1167
1168                query.append("smallImageId = ?");
1169
1170                query.append(" ");
1171
1172                Query q = session.createQuery(query.toString());
1173
1174                QueryPos qPos = QueryPos.getInstance(q);
1175
1176                qPos.add(smallImageId);
1177
1178                Long count = null;
1179
1180                Iterator<Long> itr = q.list().iterator();
1181
1182                if (itr.hasNext()) {
1183                    count = itr.next();
1184                }
1185
1186                if (count == null) {
1187                    count = new Long(0);
1188                }
1189
1190                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1191                    finderClassName, finderMethodName, finderParams,
1192                    finderArgs, count);
1193
1194                return count.intValue();
1195            }
1196            catch (Exception e) {
1197                throw processException(e);
1198            }
1199            finally {
1200                closeSession(session);
1201            }
1202        }
1203        else {
1204            return ((Long)result).intValue();
1205        }
1206    }
1207
1208    public int countByMediumImageId(long mediumImageId)
1209        throws SystemException {
1210        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1211        String finderClassName = ShoppingItem.class.getName();
1212        String finderMethodName = "countByMediumImageId";
1213        String[] finderParams = new String[] { Long.class.getName() };
1214        Object[] finderArgs = new Object[] { new Long(mediumImageId) };
1215
1216        Object result = null;
1217
1218        if (finderClassNameCacheEnabled) {
1219            result = FinderCacheUtil.getResult(finderClassName,
1220                    finderMethodName, finderParams, finderArgs, this);
1221        }
1222
1223        if (result == null) {
1224            Session session = null;
1225
1226            try {
1227                session = openSession();
1228
1229                StringBuilder query = new StringBuilder();
1230
1231                query.append("SELECT COUNT(*) ");
1232                query.append(
1233                    "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
1234
1235                query.append("mediumImageId = ?");
1236
1237                query.append(" ");
1238
1239                Query q = session.createQuery(query.toString());
1240
1241                QueryPos qPos = QueryPos.getInstance(q);
1242
1243                qPos.add(mediumImageId);
1244
1245                Long count = null;
1246
1247                Iterator<Long> itr = q.list().iterator();
1248
1249                if (itr.hasNext()) {
1250                    count = itr.next();
1251                }
1252
1253                if (count == null) {
1254                    count = new Long(0);
1255                }
1256
1257                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1258                    finderClassName, finderMethodName, finderParams,
1259                    finderArgs, count);
1260
1261                return count.intValue();
1262            }
1263            catch (Exception e) {
1264                throw processException(e);
1265            }
1266            finally {
1267                closeSession(session);
1268            }
1269        }
1270        else {
1271            return ((Long)result).intValue();
1272        }
1273    }
1274
1275    public int countByLargeImageId(long largeImageId) throws SystemException {
1276        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1277        String finderClassName = ShoppingItem.class.getName();
1278        String finderMethodName = "countByLargeImageId";
1279        String[] finderParams = new String[] { Long.class.getName() };
1280        Object[] finderArgs = new Object[] { new Long(largeImageId) };
1281
1282        Object result = null;
1283
1284        if (finderClassNameCacheEnabled) {
1285            result = FinderCacheUtil.getResult(finderClassName,
1286                    finderMethodName, finderParams, finderArgs, this);
1287        }
1288
1289        if (result == null) {
1290            Session session = null;
1291
1292            try {
1293                session = openSession();
1294
1295                StringBuilder query = new StringBuilder();
1296
1297                query.append("SELECT COUNT(*) ");
1298                query.append(
1299                    "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
1300
1301                query.append("largeImageId = ?");
1302
1303                query.append(" ");
1304
1305                Query q = session.createQuery(query.toString());
1306
1307                QueryPos qPos = QueryPos.getInstance(q);
1308
1309                qPos.add(largeImageId);
1310
1311                Long count = null;
1312
1313                Iterator<Long> itr = q.list().iterator();
1314
1315                if (itr.hasNext()) {
1316                    count = itr.next();
1317                }
1318
1319                if (count == null) {
1320                    count = new Long(0);
1321                }
1322
1323                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1324                    finderClassName, finderMethodName, finderParams,
1325                    finderArgs, count);
1326
1327                return count.intValue();
1328            }
1329            catch (Exception e) {
1330                throw processException(e);
1331            }
1332            finally {
1333                closeSession(session);
1334            }
1335        }
1336        else {
1337            return ((Long)result).intValue();
1338        }
1339    }
1340
1341    public int countByC_S(long companyId, String sku) throws SystemException {
1342        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1343        String finderClassName = ShoppingItem.class.getName();
1344        String finderMethodName = "countByC_S";
1345        String[] finderParams = new String[] {
1346                Long.class.getName(), String.class.getName()
1347            };
1348        Object[] finderArgs = new Object[] { new Long(companyId), sku };
1349
1350        Object result = null;
1351
1352        if (finderClassNameCacheEnabled) {
1353            result = FinderCacheUtil.getResult(finderClassName,
1354                    finderMethodName, finderParams, finderArgs, this);
1355        }
1356
1357        if (result == null) {
1358            Session session = null;
1359
1360            try {
1361                session = openSession();
1362
1363                StringBuilder query = new StringBuilder();
1364
1365                query.append("SELECT COUNT(*) ");
1366                query.append(
1367                    "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
1368
1369                query.append("companyId = ?");
1370
1371                query.append(" AND ");
1372
1373                if (sku == null) {
1374                    query.append("sku IS NULL");
1375                }
1376                else {
1377                    query.append("sku = ?");
1378                }
1379
1380                query.append(" ");
1381
1382                Query q = session.createQuery(query.toString());
1383
1384                QueryPos qPos = QueryPos.getInstance(q);
1385
1386                qPos.add(companyId);
1387
1388                if (sku != null) {
1389                    qPos.add(sku);
1390                }
1391
1392                Long count = null;
1393
1394                Iterator<Long> itr = q.list().iterator();
1395
1396                if (itr.hasNext()) {
1397                    count = itr.next();
1398                }
1399
1400                if (count == null) {
1401                    count = new Long(0);
1402                }
1403
1404                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1405                    finderClassName, finderMethodName, finderParams,
1406                    finderArgs, count);
1407
1408                return count.intValue();
1409            }
1410            catch (Exception e) {
1411                throw processException(e);
1412            }
1413            finally {
1414                closeSession(session);
1415            }
1416        }
1417        else {
1418            return ((Long)result).intValue();
1419        }
1420    }
1421
1422    public int countAll() throws SystemException {
1423        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1424        String finderClassName = ShoppingItem.class.getName();
1425        String finderMethodName = "countAll";
1426        String[] finderParams = new String[] {  };
1427        Object[] finderArgs = new Object[] {  };
1428
1429        Object result = null;
1430
1431        if (finderClassNameCacheEnabled) {
1432            result = FinderCacheUtil.getResult(finderClassName,
1433                    finderMethodName, finderParams, finderArgs, this);
1434        }
1435
1436        if (result == null) {
1437            Session session = null;
1438
1439            try {
1440                session = openSession();
1441
1442                Query q = session.createQuery(
1443                        "SELECT COUNT(*) FROM com.liferay.portlet.shopping.model.ShoppingItem");
1444
1445                Long count = null;
1446
1447                Iterator<Long> itr = q.list().iterator();
1448
1449                if (itr.hasNext()) {
1450                    count = itr.next();
1451                }
1452
1453                if (count == null) {
1454                    count = new Long(0);
1455                }
1456
1457                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1458                    finderClassName, finderMethodName, finderParams,
1459                    finderArgs, count);
1460
1461                return count.intValue();
1462            }
1463            catch (Exception e) {
1464                throw processException(e);
1465            }
1466            finally {
1467                closeSession(session);
1468            }
1469        }
1470        else {
1471            return ((Long)result).intValue();
1472        }
1473    }
1474
1475    public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
1476        long pk) throws SystemException {
1477        return getShoppingItemPrices(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1478    }
1479
1480    public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
1481        long pk, int start, int end) throws SystemException {
1482        return getShoppingItemPrices(pk, start, end, null);
1483    }
1484
1485    public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
1486        long pk, int start, int end, OrderByComparator obc)
1487        throws SystemException {
1488        boolean finderClassNameCacheEnabled = com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.CACHE_ENABLED;
1489
1490        String finderClassName = com.liferay.portlet.shopping.model.ShoppingItemPrice.class.getName();
1491
1492        String finderMethodName = "getShoppingItemPrices";
1493        String[] finderParams = new String[] {
1494                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1495                "com.liferay.portal.kernel.util.OrderByComparator"
1496            };
1497        Object[] finderArgs = new Object[] {
1498                new Long(pk), String.valueOf(start), String.valueOf(end),
1499                String.valueOf(obc)
1500            };
1501
1502        Object result = null;
1503
1504        if (finderClassNameCacheEnabled) {
1505            result = FinderCacheUtil.getResult(finderClassName,
1506                    finderMethodName, finderParams, finderArgs, this);
1507        }
1508
1509        if (result == null) {
1510            Session session = null;
1511
1512            try {
1513                session = openSession();
1514
1515                StringBuilder sb = new StringBuilder();
1516
1517                sb.append(_SQL_GETSHOPPINGITEMPRICES);
1518
1519                if (obc != null) {
1520                    sb.append("ORDER BY ");
1521                    sb.append(obc.getOrderBy());
1522                }
1523
1524                else {
1525                    sb.append("ORDER BY ");
1526
1527                    sb.append("ShoppingItemPrice.itemId ASC, ");
1528                    sb.append("ShoppingItemPrice.itemPriceId ASC");
1529                }
1530
1531                String sql = sb.toString();
1532
1533                SQLQuery q = session.createSQLQuery(sql);
1534
1535                q.addEntity("ShoppingItemPrice",
1536                    com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl.class);
1537
1538                QueryPos qPos = QueryPos.getInstance(q);
1539
1540                qPos.add(pk);
1541
1542                List<com.liferay.portlet.shopping.model.ShoppingItemPrice> list = (List<com.liferay.portlet.shopping.model.ShoppingItemPrice>)QueryUtil.list(q,
1543                        getDialect(), start, end);
1544
1545                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1546                    finderClassName, finderMethodName, finderParams,
1547                    finderArgs, list);
1548
1549                return list;
1550            }
1551            catch (Exception e) {
1552                throw processException(e);
1553            }
1554            finally {
1555                closeSession(session);
1556            }
1557        }
1558        else {
1559            return (List<com.liferay.portlet.shopping.model.ShoppingItemPrice>)result;
1560        }
1561    }
1562
1563    public int getShoppingItemPricesSize(long pk) throws SystemException {
1564        boolean finderClassNameCacheEnabled = com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.CACHE_ENABLED;
1565
1566        String finderClassName = com.liferay.portlet.shopping.model.ShoppingItemPrice.class.getName();
1567
1568        String finderMethodName = "getShoppingItemPricesSize";
1569        String[] finderParams = new String[] { Long.class.getName() };
1570        Object[] finderArgs = new Object[] { new Long(pk) };
1571
1572        Object result = null;
1573
1574        if (finderClassNameCacheEnabled) {
1575            result = FinderCacheUtil.getResult(finderClassName,
1576                    finderMethodName, finderParams, finderArgs, this);
1577        }
1578
1579        if (result == null) {
1580            Session session = null;
1581
1582            try {
1583                session = openSession();
1584
1585                SQLQuery q = session.createSQLQuery(_SQL_GETSHOPPINGITEMPRICESSIZE);
1586
1587                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1588
1589                QueryPos qPos = QueryPos.getInstance(q);
1590
1591                qPos.add(pk);
1592
1593                Long count = null;
1594
1595                Iterator<Long> itr = q.list().iterator();
1596
1597                if (itr.hasNext()) {
1598                    count = itr.next();
1599                }
1600
1601                if (count == null) {
1602                    count = new Long(0);
1603                }
1604
1605                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1606                    finderClassName, finderMethodName, finderParams,
1607                    finderArgs, count);
1608
1609                return count.intValue();
1610            }
1611            catch (Exception e) {
1612                throw processException(e);
1613            }
1614            finally {
1615                closeSession(session);
1616            }
1617        }
1618        else {
1619            return ((Long)result).intValue();
1620        }
1621    }
1622
1623    public boolean containsShoppingItemPrice(long pk, long shoppingItemPricePK)
1624        throws SystemException {
1625        boolean finderClassNameCacheEnabled = com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.CACHE_ENABLED;
1626
1627        String finderClassName = com.liferay.portlet.shopping.model.ShoppingItemPrice.class.getName();
1628
1629        String finderMethodName = "containsShoppingItemPrices";
1630        String[] finderParams = new String[] {
1631                Long.class.getName(),
1632                
1633                Long.class.getName()
1634            };
1635        Object[] finderArgs = new Object[] {
1636                new Long(pk),
1637                
1638                new Long(shoppingItemPricePK)
1639            };
1640
1641        Object result = null;
1642
1643        if (finderClassNameCacheEnabled) {
1644            result = FinderCacheUtil.getResult(finderClassName,
1645                    finderMethodName, finderParams, finderArgs, this);
1646        }
1647
1648        if (result == null) {
1649            try {
1650                Boolean value = Boolean.valueOf(containsShoppingItemPrice.contains(
1651                            pk, shoppingItemPricePK));
1652
1653                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1654                    finderClassName, finderMethodName, finderParams,
1655                    finderArgs, value);
1656
1657                return value.booleanValue();
1658            }
1659            catch (Exception e) {
1660                throw processException(e);
1661            }
1662        }
1663        else {
1664            return ((Boolean)result).booleanValue();
1665        }
1666    }
1667
1668    public boolean containsShoppingItemPrices(long pk)
1669        throws SystemException {
1670        if (getShoppingItemPricesSize(pk) > 0) {
1671            return true;
1672        }
1673        else {
1674            return false;
1675        }
1676    }
1677
1678    public void registerListener(ModelListener listener) {
1679        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1680
1681        listeners.add(listener);
1682
1683        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1684    }
1685
1686    public void unregisterListener(ModelListener listener) {
1687        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1688
1689        listeners.remove(listener);
1690
1691        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1692    }
1693
1694    public void afterPropertiesSet() {
1695        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1696                    com.liferay.portal.util.PropsUtil.get(
1697                        "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItem")));
1698
1699        if (listenerClassNames.length > 0) {
1700            try {
1701                List<ModelListener> listeners = new ArrayList<ModelListener>();
1702
1703                for (String listenerClassName : listenerClassNames) {
1704                    listeners.add((ModelListener)Class.forName(
1705                            listenerClassName).newInstance());
1706                }
1707
1708                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1709            }
1710            catch (Exception e) {
1711                _log.error(e);
1712            }
1713        }
1714
1715        containsShoppingItemPrice = new ContainsShoppingItemPrice(this);
1716    }
1717
1718    protected ContainsShoppingItemPrice containsShoppingItemPrice;
1719
1720    protected class ContainsShoppingItemPrice {
1721        protected ContainsShoppingItemPrice(
1722            ShoppingItemPersistenceImpl persistenceImpl) {
1723            super();
1724
1725            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1726                    _SQL_CONTAINSSHOPPINGITEMPRICE,
1727                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1728        }
1729
1730        protected boolean contains(long itemId, long itemPriceId) {
1731            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1732                        new Long(itemId), new Long(itemPriceId)
1733                    });
1734
1735            if (results.size() > 0) {
1736                Integer count = results.get(0);
1737
1738                if (count.intValue() > 0) {
1739                    return true;
1740                }
1741            }
1742
1743            return false;
1744        }
1745
1746        private MappingSqlQuery _mappingSqlQuery;
1747    }
1748
1749    private static final String _SQL_GETSHOPPINGITEMPRICES = "SELECT {ShoppingItemPrice.*} FROM ShoppingItemPrice INNER JOIN ShoppingItem ON (ShoppingItem.itemId = ShoppingItemPrice.itemId) WHERE (ShoppingItem.itemId = ?)";
1750    private static final String _SQL_GETSHOPPINGITEMPRICESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM ShoppingItemPrice WHERE itemId = ?";
1751    private static final String _SQL_CONTAINSSHOPPINGITEMPRICE = "SELECT COUNT(*) AS COUNT_VALUE FROM ShoppingItemPrice WHERE itemId = ? AND itemPriceId = ?";
1752    private static Log _log = LogFactory.getLog(ShoppingItemPersistenceImpl.class);
1753    private ModelListener[] _listeners = new ModelListener[0];
1754}