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.dao.jdbc.MappingSqlQuery;
27  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
28  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
29  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.Query;
32  import com.liferay.portal.kernel.dao.orm.QueryPos;
33  import com.liferay.portal.kernel.dao.orm.QueryUtil;
34  import com.liferay.portal.kernel.dao.orm.SQLQuery;
35  import com.liferay.portal.kernel.dao.orm.Session;
36  import com.liferay.portal.kernel.dao.orm.Type;
37  import com.liferay.portal.kernel.util.GetterUtil;
38  import com.liferay.portal.kernel.util.ListUtil;
39  import com.liferay.portal.kernel.util.OrderByComparator;
40  import com.liferay.portal.kernel.util.StringPool;
41  import com.liferay.portal.kernel.util.StringUtil;
42  import com.liferay.portal.model.ModelListener;
43  import com.liferay.portal.service.persistence.BatchSessionUtil;
44  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45  
46  import com.liferay.portlet.shopping.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 {
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             if (BatchSessionUtil.isEnabled()) {
138                 Object staleObject = session.get(ShoppingItemImpl.class,
139                         shoppingItem.getPrimaryKeyObj());
140 
141                 if (staleObject != null) {
142                     session.evict(staleObject);
143                 }
144             }
145 
146             session.delete(shoppingItem);
147 
148             session.flush();
149 
150             return shoppingItem;
151         }
152         catch (Exception e) {
153             throw processException(e);
154         }
155         finally {
156             closeSession(session);
157 
158             FinderCacheUtil.clearCache(ShoppingItem.class.getName());
159         }
160     }
161 
162     /**
163      * @deprecated Use <code>update(ShoppingItem shoppingItem, boolean merge)</code>.
164      */
165     public ShoppingItem update(ShoppingItem shoppingItem)
166         throws SystemException {
167         if (_log.isWarnEnabled()) {
168             _log.warn(
169                 "Using the deprecated update(ShoppingItem shoppingItem) method. Use update(ShoppingItem shoppingItem, boolean merge) instead.");
170         }
171 
172         return update(shoppingItem, false);
173     }
174 
175     /**
176      * Add, update, or merge, the entity. This method also calls the model
177      * listeners to trigger the proper events associated with adding, deleting,
178      * or updating an entity.
179      *
180      * @param        shoppingItem the entity to add, update, or merge
181      * @param        merge boolean value for whether to merge the entity. The
182      *                default value is false. Setting merge to true is more
183      *                expensive and should only be true when shoppingItem is
184      *                transient. See LEP-5473 for a detailed discussion of this
185      *                method.
186      * @return        true if the portlet can be displayed via Ajax
187      */
188     public ShoppingItem update(ShoppingItem shoppingItem, boolean merge)
189         throws SystemException {
190         boolean isNew = shoppingItem.isNew();
191 
192         if (_listeners.length > 0) {
193             for (ModelListener listener : _listeners) {
194                 if (isNew) {
195                     listener.onBeforeCreate(shoppingItem);
196                 }
197                 else {
198                     listener.onBeforeUpdate(shoppingItem);
199                 }
200             }
201         }
202 
203         shoppingItem = updateImpl(shoppingItem, merge);
204 
205         if (_listeners.length > 0) {
206             for (ModelListener listener : _listeners) {
207                 if (isNew) {
208                     listener.onAfterCreate(shoppingItem);
209                 }
210                 else {
211                     listener.onAfterUpdate(shoppingItem);
212                 }
213             }
214         }
215 
216         return shoppingItem;
217     }
218 
219     public ShoppingItem updateImpl(
220         com.liferay.portlet.shopping.model.ShoppingItem shoppingItem,
221         boolean merge) throws SystemException {
222         Session session = null;
223 
224         try {
225             session = openSession();
226 
227             BatchSessionUtil.update(session, shoppingItem, merge);
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 = null;
1012
1013                if (obc == null) {
1014                    list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
1015                            start, end, false);
1016
1017                    Collections.sort(list);
1018                }
1019                else {
1020                    list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
1021                            start, end);
1022                }
1023
1024                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1025                    finderClassName, finderMethodName, finderParams,
1026                    finderArgs, list);
1027
1028                return list;
1029            }
1030            catch (Exception e) {
1031                throw processException(e);
1032            }
1033            finally {
1034                closeSession(session);
1035            }
1036        }
1037        else {
1038            return (List<ShoppingItem>)result;
1039        }
1040    }
1041
1042    public void removeByCategoryId(long categoryId) throws SystemException {
1043        for (ShoppingItem shoppingItem : findByCategoryId(categoryId)) {
1044            remove(shoppingItem);
1045        }
1046    }
1047
1048    public void removeBySmallImageId(long smallImageId)
1049        throws NoSuchItemException, SystemException {
1050        ShoppingItem shoppingItem = findBySmallImageId(smallImageId);
1051
1052        remove(shoppingItem);
1053    }
1054
1055    public void removeByMediumImageId(long mediumImageId)
1056        throws NoSuchItemException, SystemException {
1057        ShoppingItem shoppingItem = findByMediumImageId(mediumImageId);
1058
1059        remove(shoppingItem);
1060    }
1061
1062    public void removeByLargeImageId(long largeImageId)
1063        throws NoSuchItemException, SystemException {
1064        ShoppingItem shoppingItem = findByLargeImageId(largeImageId);
1065
1066        remove(shoppingItem);
1067    }
1068
1069    public void removeByC_S(long companyId, String sku)
1070        throws NoSuchItemException, SystemException {
1071        ShoppingItem shoppingItem = findByC_S(companyId, sku);
1072
1073        remove(shoppingItem);
1074    }
1075
1076    public void removeAll() throws SystemException {
1077        for (ShoppingItem shoppingItem : findAll()) {
1078            remove(shoppingItem);
1079        }
1080    }
1081
1082    public int countByCategoryId(long categoryId) throws SystemException {
1083        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1084        String finderClassName = ShoppingItem.class.getName();
1085        String finderMethodName = "countByCategoryId";
1086        String[] finderParams = new String[] { Long.class.getName() };
1087        Object[] finderArgs = new Object[] { new Long(categoryId) };
1088
1089        Object result = null;
1090
1091        if (finderClassNameCacheEnabled) {
1092            result = FinderCacheUtil.getResult(finderClassName,
1093                    finderMethodName, finderParams, finderArgs, this);
1094        }
1095
1096        if (result == null) {
1097            Session session = null;
1098
1099            try {
1100                session = openSession();
1101
1102                StringBuilder query = new StringBuilder();
1103
1104                query.append("SELECT COUNT(*) ");
1105                query.append(
1106                    "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
1107
1108                query.append("categoryId = ?");
1109
1110                query.append(" ");
1111
1112                Query q = session.createQuery(query.toString());
1113
1114                QueryPos qPos = QueryPos.getInstance(q);
1115
1116                qPos.add(categoryId);
1117
1118                Long count = null;
1119
1120                Iterator<Long> itr = q.list().iterator();
1121
1122                if (itr.hasNext()) {
1123                    count = itr.next();
1124                }
1125
1126                if (count == null) {
1127                    count = new Long(0);
1128                }
1129
1130                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1131                    finderClassName, finderMethodName, finderParams,
1132                    finderArgs, count);
1133
1134                return count.intValue();
1135            }
1136            catch (Exception e) {
1137                throw processException(e);
1138            }
1139            finally {
1140                closeSession(session);
1141            }
1142        }
1143        else {
1144            return ((Long)result).intValue();
1145        }
1146    }
1147
1148    public int countBySmallImageId(long smallImageId) throws SystemException {
1149        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1150        String finderClassName = ShoppingItem.class.getName();
1151        String finderMethodName = "countBySmallImageId";
1152        String[] finderParams = new String[] { Long.class.getName() };
1153        Object[] finderArgs = new Object[] { new Long(smallImageId) };
1154
1155        Object result = null;
1156
1157        if (finderClassNameCacheEnabled) {
1158            result = FinderCacheUtil.getResult(finderClassName,
1159                    finderMethodName, finderParams, finderArgs, this);
1160        }
1161
1162        if (result == null) {
1163            Session session = null;
1164
1165            try {
1166                session = openSession();
1167
1168                StringBuilder query = new StringBuilder();
1169
1170                query.append("SELECT COUNT(*) ");
1171                query.append(
1172                    "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
1173
1174                query.append("smallImageId = ?");
1175
1176                query.append(" ");
1177
1178                Query q = session.createQuery(query.toString());
1179
1180                QueryPos qPos = QueryPos.getInstance(q);
1181
1182                qPos.add(smallImageId);
1183
1184                Long count = null;
1185
1186                Iterator<Long> itr = q.list().iterator();
1187
1188                if (itr.hasNext()) {
1189                    count = itr.next();
1190                }
1191
1192                if (count == null) {
1193                    count = new Long(0);
1194                }
1195
1196                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1197                    finderClassName, finderMethodName, finderParams,
1198                    finderArgs, count);
1199
1200                return count.intValue();
1201            }
1202            catch (Exception e) {
1203                throw processException(e);
1204            }
1205            finally {
1206                closeSession(session);
1207            }
1208        }
1209        else {
1210            return ((Long)result).intValue();
1211        }
1212    }
1213
1214    public int countByMediumImageId(long mediumImageId)
1215        throws SystemException {
1216        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1217        String finderClassName = ShoppingItem.class.getName();
1218        String finderMethodName = "countByMediumImageId";
1219        String[] finderParams = new String[] { Long.class.getName() };
1220        Object[] finderArgs = new Object[] { new Long(mediumImageId) };
1221
1222        Object result = null;
1223
1224        if (finderClassNameCacheEnabled) {
1225            result = FinderCacheUtil.getResult(finderClassName,
1226                    finderMethodName, finderParams, finderArgs, this);
1227        }
1228
1229        if (result == null) {
1230            Session session = null;
1231
1232            try {
1233                session = openSession();
1234
1235                StringBuilder query = new StringBuilder();
1236
1237                query.append("SELECT COUNT(*) ");
1238                query.append(
1239                    "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
1240
1241                query.append("mediumImageId = ?");
1242
1243                query.append(" ");
1244
1245                Query q = session.createQuery(query.toString());
1246
1247                QueryPos qPos = QueryPos.getInstance(q);
1248
1249                qPos.add(mediumImageId);
1250
1251                Long count = null;
1252
1253                Iterator<Long> itr = q.list().iterator();
1254
1255                if (itr.hasNext()) {
1256                    count = itr.next();
1257                }
1258
1259                if (count == null) {
1260                    count = new Long(0);
1261                }
1262
1263                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1264                    finderClassName, finderMethodName, finderParams,
1265                    finderArgs, count);
1266
1267                return count.intValue();
1268            }
1269            catch (Exception e) {
1270                throw processException(e);
1271            }
1272            finally {
1273                closeSession(session);
1274            }
1275        }
1276        else {
1277            return ((Long)result).intValue();
1278        }
1279    }
1280
1281    public int countByLargeImageId(long largeImageId) throws SystemException {
1282        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1283        String finderClassName = ShoppingItem.class.getName();
1284        String finderMethodName = "countByLargeImageId";
1285        String[] finderParams = new String[] { Long.class.getName() };
1286        Object[] finderArgs = new Object[] { new Long(largeImageId) };
1287
1288        Object result = null;
1289
1290        if (finderClassNameCacheEnabled) {
1291            result = FinderCacheUtil.getResult(finderClassName,
1292                    finderMethodName, finderParams, finderArgs, this);
1293        }
1294
1295        if (result == null) {
1296            Session session = null;
1297
1298            try {
1299                session = openSession();
1300
1301                StringBuilder query = new StringBuilder();
1302
1303                query.append("SELECT COUNT(*) ");
1304                query.append(
1305                    "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
1306
1307                query.append("largeImageId = ?");
1308
1309                query.append(" ");
1310
1311                Query q = session.createQuery(query.toString());
1312
1313                QueryPos qPos = QueryPos.getInstance(q);
1314
1315                qPos.add(largeImageId);
1316
1317                Long count = null;
1318
1319                Iterator<Long> itr = q.list().iterator();
1320
1321                if (itr.hasNext()) {
1322                    count = itr.next();
1323                }
1324
1325                if (count == null) {
1326                    count = new Long(0);
1327                }
1328
1329                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1330                    finderClassName, finderMethodName, finderParams,
1331                    finderArgs, count);
1332
1333                return count.intValue();
1334            }
1335            catch (Exception e) {
1336                throw processException(e);
1337            }
1338            finally {
1339                closeSession(session);
1340            }
1341        }
1342        else {
1343            return ((Long)result).intValue();
1344        }
1345    }
1346
1347    public int countByC_S(long companyId, String sku) throws SystemException {
1348        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1349        String finderClassName = ShoppingItem.class.getName();
1350        String finderMethodName = "countByC_S";
1351        String[] finderParams = new String[] {
1352                Long.class.getName(), String.class.getName()
1353            };
1354        Object[] finderArgs = new Object[] { new Long(companyId), sku };
1355
1356        Object result = null;
1357
1358        if (finderClassNameCacheEnabled) {
1359            result = FinderCacheUtil.getResult(finderClassName,
1360                    finderMethodName, finderParams, finderArgs, this);
1361        }
1362
1363        if (result == null) {
1364            Session session = null;
1365
1366            try {
1367                session = openSession();
1368
1369                StringBuilder query = new StringBuilder();
1370
1371                query.append("SELECT COUNT(*) ");
1372                query.append(
1373                    "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
1374
1375                query.append("companyId = ?");
1376
1377                query.append(" AND ");
1378
1379                if (sku == null) {
1380                    query.append("sku IS NULL");
1381                }
1382                else {
1383                    query.append("sku = ?");
1384                }
1385
1386                query.append(" ");
1387
1388                Query q = session.createQuery(query.toString());
1389
1390                QueryPos qPos = QueryPos.getInstance(q);
1391
1392                qPos.add(companyId);
1393
1394                if (sku != null) {
1395                    qPos.add(sku);
1396                }
1397
1398                Long count = null;
1399
1400                Iterator<Long> itr = q.list().iterator();
1401
1402                if (itr.hasNext()) {
1403                    count = itr.next();
1404                }
1405
1406                if (count == null) {
1407                    count = new Long(0);
1408                }
1409
1410                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1411                    finderClassName, finderMethodName, finderParams,
1412                    finderArgs, count);
1413
1414                return count.intValue();
1415            }
1416            catch (Exception e) {
1417                throw processException(e);
1418            }
1419            finally {
1420                closeSession(session);
1421            }
1422        }
1423        else {
1424            return ((Long)result).intValue();
1425        }
1426    }
1427
1428    public int countAll() throws SystemException {
1429        boolean finderClassNameCacheEnabled = ShoppingItemModelImpl.CACHE_ENABLED;
1430        String finderClassName = ShoppingItem.class.getName();
1431        String finderMethodName = "countAll";
1432        String[] finderParams = new String[] {  };
1433        Object[] finderArgs = new Object[] {  };
1434
1435        Object result = null;
1436
1437        if (finderClassNameCacheEnabled) {
1438            result = FinderCacheUtil.getResult(finderClassName,
1439                    finderMethodName, finderParams, finderArgs, this);
1440        }
1441
1442        if (result == null) {
1443            Session session = null;
1444
1445            try {
1446                session = openSession();
1447
1448                Query q = session.createQuery(
1449                        "SELECT COUNT(*) FROM com.liferay.portlet.shopping.model.ShoppingItem");
1450
1451                Long count = null;
1452
1453                Iterator<Long> itr = q.list().iterator();
1454
1455                if (itr.hasNext()) {
1456                    count = itr.next();
1457                }
1458
1459                if (count == null) {
1460                    count = new Long(0);
1461                }
1462
1463                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1464                    finderClassName, finderMethodName, finderParams,
1465                    finderArgs, count);
1466
1467                return count.intValue();
1468            }
1469            catch (Exception e) {
1470                throw processException(e);
1471            }
1472            finally {
1473                closeSession(session);
1474            }
1475        }
1476        else {
1477            return ((Long)result).intValue();
1478        }
1479    }
1480
1481    public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
1482        long pk) throws SystemException {
1483        return getShoppingItemPrices(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1484    }
1485
1486    public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
1487        long pk, int start, int end) throws SystemException {
1488        return getShoppingItemPrices(pk, start, end, null);
1489    }
1490
1491    public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
1492        long pk, int start, int end, OrderByComparator obc)
1493        throws SystemException {
1494        boolean finderClassNameCacheEnabled = com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.CACHE_ENABLED;
1495
1496        String finderClassName = com.liferay.portlet.shopping.model.ShoppingItemPrice.class.getName();
1497
1498        String finderMethodName = "getShoppingItemPrices";
1499        String[] finderParams = new String[] {
1500                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1501                "com.liferay.portal.kernel.util.OrderByComparator"
1502            };
1503        Object[] finderArgs = new Object[] {
1504                new Long(pk), String.valueOf(start), String.valueOf(end),
1505                String.valueOf(obc)
1506            };
1507
1508        Object result = null;
1509
1510        if (finderClassNameCacheEnabled) {
1511            result = FinderCacheUtil.getResult(finderClassName,
1512                    finderMethodName, finderParams, finderArgs, this);
1513        }
1514
1515        if (result == null) {
1516            Session session = null;
1517
1518            try {
1519                session = openSession();
1520
1521                StringBuilder sb = new StringBuilder();
1522
1523                sb.append(_SQL_GETSHOPPINGITEMPRICES);
1524
1525                if (obc != null) {
1526                    sb.append("ORDER BY ");
1527                    sb.append(obc.getOrderBy());
1528                }
1529
1530                else {
1531                    sb.append("ORDER BY ");
1532
1533                    sb.append("ShoppingItemPrice.itemId ASC, ");
1534                    sb.append("ShoppingItemPrice.itemPriceId ASC");
1535                }
1536
1537                String sql = sb.toString();
1538
1539                SQLQuery q = session.createSQLQuery(sql);
1540
1541                q.addEntity("ShoppingItemPrice",
1542                    com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl.class);
1543
1544                QueryPos qPos = QueryPos.getInstance(q);
1545
1546                qPos.add(pk);
1547
1548                List<com.liferay.portlet.shopping.model.ShoppingItemPrice> list = (List<com.liferay.portlet.shopping.model.ShoppingItemPrice>)QueryUtil.list(q,
1549                        getDialect(), start, end);
1550
1551                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1552                    finderClassName, finderMethodName, finderParams,
1553                    finderArgs, list);
1554
1555                return list;
1556            }
1557            catch (Exception e) {
1558                throw processException(e);
1559            }
1560            finally {
1561                closeSession(session);
1562            }
1563        }
1564        else {
1565            return (List<com.liferay.portlet.shopping.model.ShoppingItemPrice>)result;
1566        }
1567    }
1568
1569    public int getShoppingItemPricesSize(long pk) throws SystemException {
1570        boolean finderClassNameCacheEnabled = com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.CACHE_ENABLED;
1571
1572        String finderClassName = com.liferay.portlet.shopping.model.ShoppingItemPrice.class.getName();
1573
1574        String finderMethodName = "getShoppingItemPricesSize";
1575        String[] finderParams = new String[] { Long.class.getName() };
1576        Object[] finderArgs = new Object[] { new Long(pk) };
1577
1578        Object result = null;
1579
1580        if (finderClassNameCacheEnabled) {
1581            result = FinderCacheUtil.getResult(finderClassName,
1582                    finderMethodName, finderParams, finderArgs, this);
1583        }
1584
1585        if (result == null) {
1586            Session session = null;
1587
1588            try {
1589                session = openSession();
1590
1591                SQLQuery q = session.createSQLQuery(_SQL_GETSHOPPINGITEMPRICESSIZE);
1592
1593                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1594
1595                QueryPos qPos = QueryPos.getInstance(q);
1596
1597                qPos.add(pk);
1598
1599                Long count = null;
1600
1601                Iterator<Long> itr = q.list().iterator();
1602
1603                if (itr.hasNext()) {
1604                    count = itr.next();
1605                }
1606
1607                if (count == null) {
1608                    count = new Long(0);
1609                }
1610
1611                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1612                    finderClassName, finderMethodName, finderParams,
1613                    finderArgs, count);
1614
1615                return count.intValue();
1616            }
1617            catch (Exception e) {
1618                throw processException(e);
1619            }
1620            finally {
1621                closeSession(session);
1622            }
1623        }
1624        else {
1625            return ((Long)result).intValue();
1626        }
1627    }
1628
1629    public boolean containsShoppingItemPrice(long pk, long shoppingItemPricePK)
1630        throws SystemException {
1631        boolean finderClassNameCacheEnabled = com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.CACHE_ENABLED;
1632
1633        String finderClassName = com.liferay.portlet.shopping.model.ShoppingItemPrice.class.getName();
1634
1635        String finderMethodName = "containsShoppingItemPrices";
1636        String[] finderParams = new String[] {
1637                Long.class.getName(),
1638                
1639                Long.class.getName()
1640            };
1641        Object[] finderArgs = new Object[] {
1642                new Long(pk),
1643                
1644                new Long(shoppingItemPricePK)
1645            };
1646
1647        Object result = null;
1648
1649        if (finderClassNameCacheEnabled) {
1650            result = FinderCacheUtil.getResult(finderClassName,
1651                    finderMethodName, finderParams, finderArgs, this);
1652        }
1653
1654        if (result == null) {
1655            try {
1656                Boolean value = Boolean.valueOf(containsShoppingItemPrice.contains(
1657                            pk, shoppingItemPricePK));
1658
1659                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1660                    finderClassName, finderMethodName, finderParams,
1661                    finderArgs, value);
1662
1663                return value.booleanValue();
1664            }
1665            catch (Exception e) {
1666                throw processException(e);
1667            }
1668        }
1669        else {
1670            return ((Boolean)result).booleanValue();
1671        }
1672    }
1673
1674    public boolean containsShoppingItemPrices(long pk)
1675        throws SystemException {
1676        if (getShoppingItemPricesSize(pk) > 0) {
1677            return true;
1678        }
1679        else {
1680            return false;
1681        }
1682    }
1683
1684    public void registerListener(ModelListener listener) {
1685        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1686
1687        listeners.add(listener);
1688
1689        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1690    }
1691
1692    public void unregisterListener(ModelListener listener) {
1693        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1694
1695        listeners.remove(listener);
1696
1697        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1698    }
1699
1700    public void afterPropertiesSet() {
1701        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1702                    com.liferay.portal.util.PropsUtil.get(
1703                        "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItem")));
1704
1705        if (listenerClassNames.length > 0) {
1706            try {
1707                List<ModelListener> listeners = new ArrayList<ModelListener>();
1708
1709                for (String listenerClassName : listenerClassNames) {
1710                    listeners.add((ModelListener)Class.forName(
1711                            listenerClassName).newInstance());
1712                }
1713
1714                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1715            }
1716            catch (Exception e) {
1717                _log.error(e);
1718            }
1719        }
1720
1721        containsShoppingItemPrice = new ContainsShoppingItemPrice(this);
1722    }
1723
1724    protected ContainsShoppingItemPrice containsShoppingItemPrice;
1725
1726    protected class ContainsShoppingItemPrice {
1727        protected ContainsShoppingItemPrice(
1728            ShoppingItemPersistenceImpl persistenceImpl) {
1729            super();
1730
1731            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1732                    _SQL_CONTAINSSHOPPINGITEMPRICE,
1733                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1734        }
1735
1736        protected boolean contains(long itemId, long itemPriceId) {
1737            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1738                        new Long(itemId), new Long(itemPriceId)
1739                    });
1740
1741            if (results.size() > 0) {
1742                Integer count = results.get(0);
1743
1744                if (count.intValue() > 0) {
1745                    return true;
1746                }
1747            }
1748
1749            return false;
1750        }
1751
1752        private MappingSqlQuery _mappingSqlQuery;
1753    }
1754
1755    private static final String _SQL_GETSHOPPINGITEMPRICES = "SELECT {ShoppingItemPrice.*} FROM ShoppingItemPrice INNER JOIN ShoppingItem ON (ShoppingItem.itemId = ShoppingItemPrice.itemId) WHERE (ShoppingItem.itemId = ?)";
1756    private static final String _SQL_GETSHOPPINGITEMPRICESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM ShoppingItemPrice WHERE itemId = ?";
1757    private static final String _SQL_CONTAINSSHOPPINGITEMPRICE = "SELECT COUNT(*) AS COUNT_VALUE FROM ShoppingItemPrice WHERE itemId = ? AND itemPriceId = ?";
1758    private static Log _log = LogFactory.getLog(ShoppingItemPersistenceImpl.class);
1759    private ModelListener[] _listeners = new ModelListener[0];
1760}