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