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