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