1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.shopping.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.dao.DynamicQuery;
27  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28  import com.liferay.portal.kernel.util.OrderByComparator;
29  import com.liferay.portal.kernel.util.StringMaker;
30  import com.liferay.portal.kernel.util.StringPool;
31  import com.liferay.portal.service.persistence.BasePersistence;
32  import com.liferay.portal.spring.hibernate.FinderCache;
33  import com.liferay.portal.spring.hibernate.HibernateUtil;
34  
35  import com.liferay.portlet.shopping.NoSuchItemException;
36  import com.liferay.portlet.shopping.model.ShoppingItem;
37  import com.liferay.portlet.shopping.model.impl.ShoppingItemImpl;
38  
39  import com.liferay.util.dao.hibernate.QueryPos;
40  import com.liferay.util.dao.hibernate.QueryUtil;
41  
42  import org.apache.commons.logging.Log;
43  import org.apache.commons.logging.LogFactory;
44  
45  import org.hibernate.Hibernate;
46  import org.hibernate.Query;
47  import org.hibernate.SQLQuery;
48  import org.hibernate.Session;
49  
50  import org.springframework.dao.DataAccessException;
51  
52  import org.springframework.jdbc.core.SqlParameter;
53  import org.springframework.jdbc.object.MappingSqlQuery;
54  
55  import java.sql.ResultSet;
56  import java.sql.SQLException;
57  import java.sql.Types;
58  
59  import java.util.Collections;
60  import java.util.Iterator;
61  import java.util.List;
62  
63  /**
64   * <a href="ShoppingItemPersistenceImpl.java.html"><b><i>View Source</i></b></a>
65   *
66   * @author Brian Wing Shun Chan
67   *
68   */
69  public class ShoppingItemPersistenceImpl extends BasePersistence
70      implements ShoppingItemPersistence {
71      public ShoppingItem create(long itemId) {
72          ShoppingItem shoppingItem = new ShoppingItemImpl();
73          shoppingItem.setNew(true);
74          shoppingItem.setPrimaryKey(itemId);
75  
76          return shoppingItem;
77      }
78  
79      public ShoppingItem remove(long itemId)
80          throws NoSuchItemException, SystemException {
81          Session session = null;
82  
83          try {
84              session = openSession();
85  
86              ShoppingItem shoppingItem = (ShoppingItem)session.get(ShoppingItemImpl.class,
87                      new Long(itemId));
88  
89              if (shoppingItem == null) {
90                  if (_log.isWarnEnabled()) {
91                      _log.warn("No ShoppingItem exists with the primary key " +
92                          itemId);
93                  }
94  
95                  throw new NoSuchItemException(
96                      "No ShoppingItem exists with the primary key " + itemId);
97              }
98  
99              return remove(shoppingItem);
100         }
101         catch (NoSuchItemException nsee) {
102             throw nsee;
103         }
104         catch (Exception e) {
105             throw HibernateUtil.processException(e);
106         }
107         finally {
108             closeSession(session);
109         }
110     }
111 
112     public ShoppingItem remove(ShoppingItem shoppingItem)
113         throws SystemException {
114         Session session = null;
115 
116         try {
117             session = openSession();
118             session.delete(shoppingItem);
119             session.flush();
120 
121             return shoppingItem;
122         }
123         catch (Exception e) {
124             throw HibernateUtil.processException(e);
125         }
126         finally {
127             closeSession(session);
128             FinderCache.clearCache(ShoppingItem.class.getName());
129         }
130     }
131 
132     public ShoppingItem update(
133         com.liferay.portlet.shopping.model.ShoppingItem shoppingItem)
134         throws SystemException {
135         return update(shoppingItem, false);
136     }
137 
138     public ShoppingItem update(
139         com.liferay.portlet.shopping.model.ShoppingItem shoppingItem,
140         boolean merge) throws SystemException {
141         Session session = null;
142 
143         try {
144             session = openSession();
145 
146             if (merge) {
147                 session.merge(shoppingItem);
148             }
149             else {
150                 if (shoppingItem.isNew()) {
151                     session.save(shoppingItem);
152                 }
153             }
154 
155             session.flush();
156             shoppingItem.setNew(false);
157 
158             return shoppingItem;
159         }
160         catch (Exception e) {
161             throw HibernateUtil.processException(e);
162         }
163         finally {
164             closeSession(session);
165             FinderCache.clearCache(ShoppingItem.class.getName());
166         }
167     }
168 
169     public ShoppingItem findByPrimaryKey(long itemId)
170         throws NoSuchItemException, SystemException {
171         ShoppingItem shoppingItem = fetchByPrimaryKey(itemId);
172 
173         if (shoppingItem == null) {
174             if (_log.isWarnEnabled()) {
175                 _log.warn("No ShoppingItem exists with the primary key " +
176                     itemId);
177             }
178 
179             throw new NoSuchItemException(
180                 "No ShoppingItem exists with the primary key " + itemId);
181         }
182 
183         return shoppingItem;
184     }
185 
186     public ShoppingItem fetchByPrimaryKey(long itemId)
187         throws SystemException {
188         Session session = null;
189 
190         try {
191             session = openSession();
192 
193             return (ShoppingItem)session.get(ShoppingItemImpl.class,
194                 new Long(itemId));
195         }
196         catch (Exception e) {
197             throw HibernateUtil.processException(e);
198         }
199         finally {
200             closeSession(session);
201         }
202     }
203 
204     public List findByCategoryId(long categoryId) throws SystemException {
205         String finderClassName = ShoppingItem.class.getName();
206         String finderMethodName = "findByCategoryId";
207         String[] finderParams = new String[] { Long.class.getName() };
208         Object[] finderArgs = new Object[] { new Long(categoryId) };
209         Object result = FinderCache.getResult(finderClassName,
210                 finderMethodName, finderParams, finderArgs, getSessionFactory());
211 
212         if (result == null) {
213             Session session = null;
214 
215             try {
216                 session = openSession();
217 
218                 StringMaker query = new StringMaker();
219                 query.append(
220                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
221                 query.append("categoryId = ?");
222                 query.append(" ");
223                 query.append("ORDER BY ");
224                 query.append("itemId ASC");
225 
226                 Query q = session.createQuery(query.toString());
227                 int queryPos = 0;
228                 q.setLong(queryPos++, categoryId);
229 
230                 List list = q.list();
231                 FinderCache.putResult(finderClassName, finderMethodName,
232                     finderParams, finderArgs, list);
233 
234                 return list;
235             }
236             catch (Exception e) {
237                 throw HibernateUtil.processException(e);
238             }
239             finally {
240                 closeSession(session);
241             }
242         }
243         else {
244             return (List)result;
245         }
246     }
247 
248     public List findByCategoryId(long categoryId, int begin, int end)
249         throws SystemException {
250         return findByCategoryId(categoryId, begin, end, null);
251     }
252 
253     public List findByCategoryId(long categoryId, int begin, int end,
254         OrderByComparator obc) throws SystemException {
255         String finderClassName = ShoppingItem.class.getName();
256         String finderMethodName = "findByCategoryId";
257         String[] finderParams = new String[] {
258                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
259                 "com.liferay.portal.kernel.util.OrderByComparator"
260             };
261         Object[] finderArgs = new Object[] {
262                 new Long(categoryId), String.valueOf(begin), String.valueOf(end),
263                 String.valueOf(obc)
264             };
265         Object result = FinderCache.getResult(finderClassName,
266                 finderMethodName, finderParams, finderArgs, getSessionFactory());
267 
268         if (result == null) {
269             Session session = null;
270 
271             try {
272                 session = openSession();
273 
274                 StringMaker query = new StringMaker();
275                 query.append(
276                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
277                 query.append("categoryId = ?");
278                 query.append(" ");
279 
280                 if (obc != null) {
281                     query.append("ORDER BY ");
282                     query.append(obc.getOrderBy());
283                 }
284                 else {
285                     query.append("ORDER BY ");
286                     query.append("itemId ASC");
287                 }
288 
289                 Query q = session.createQuery(query.toString());
290                 int queryPos = 0;
291                 q.setLong(queryPos++, categoryId);
292 
293                 List list = QueryUtil.list(q, getDialect(), begin, end);
294                 FinderCache.putResult(finderClassName, finderMethodName,
295                     finderParams, finderArgs, list);
296 
297                 return list;
298             }
299             catch (Exception e) {
300                 throw HibernateUtil.processException(e);
301             }
302             finally {
303                 closeSession(session);
304             }
305         }
306         else {
307             return (List)result;
308         }
309     }
310 
311     public ShoppingItem findByCategoryId_First(long categoryId,
312         OrderByComparator obc) throws NoSuchItemException, SystemException {
313         List list = findByCategoryId(categoryId, 0, 1, obc);
314 
315         if (list.size() == 0) {
316             StringMaker msg = new StringMaker();
317             msg.append("No ShoppingItem exists with the key ");
318             msg.append(StringPool.OPEN_CURLY_BRACE);
319             msg.append("categoryId=");
320             msg.append(categoryId);
321             msg.append(StringPool.CLOSE_CURLY_BRACE);
322             throw new NoSuchItemException(msg.toString());
323         }
324         else {
325             return (ShoppingItem)list.get(0);
326         }
327     }
328 
329     public ShoppingItem findByCategoryId_Last(long categoryId,
330         OrderByComparator obc) throws NoSuchItemException, SystemException {
331         int count = countByCategoryId(categoryId);
332         List list = findByCategoryId(categoryId, count - 1, count, obc);
333 
334         if (list.size() == 0) {
335             StringMaker msg = new StringMaker();
336             msg.append("No ShoppingItem exists with the key ");
337             msg.append(StringPool.OPEN_CURLY_BRACE);
338             msg.append("categoryId=");
339             msg.append(categoryId);
340             msg.append(StringPool.CLOSE_CURLY_BRACE);
341             throw new NoSuchItemException(msg.toString());
342         }
343         else {
344             return (ShoppingItem)list.get(0);
345         }
346     }
347 
348     public ShoppingItem[] findByCategoryId_PrevAndNext(long itemId,
349         long categoryId, OrderByComparator obc)
350         throws NoSuchItemException, SystemException {
351         ShoppingItem shoppingItem = findByPrimaryKey(itemId);
352         int count = countByCategoryId(categoryId);
353         Session session = null;
354 
355         try {
356             session = openSession();
357 
358             StringMaker query = new StringMaker();
359             query.append(
360                 "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
361             query.append("categoryId = ?");
362             query.append(" ");
363 
364             if (obc != null) {
365                 query.append("ORDER BY ");
366                 query.append(obc.getOrderBy());
367             }
368             else {
369                 query.append("ORDER BY ");
370                 query.append("itemId ASC");
371             }
372 
373             Query q = session.createQuery(query.toString());
374             int queryPos = 0;
375             q.setLong(queryPos++, categoryId);
376 
377             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
378                     shoppingItem);
379             ShoppingItem[] array = new ShoppingItemImpl[3];
380             array[0] = (ShoppingItem)objArray[0];
381             array[1] = (ShoppingItem)objArray[1];
382             array[2] = (ShoppingItem)objArray[2];
383 
384             return array;
385         }
386         catch (Exception e) {
387             throw HibernateUtil.processException(e);
388         }
389         finally {
390             closeSession(session);
391         }
392     }
393 
394     public ShoppingItem findByC_S(long companyId, String sku)
395         throws NoSuchItemException, SystemException {
396         ShoppingItem shoppingItem = fetchByC_S(companyId, sku);
397 
398         if (shoppingItem == null) {
399             StringMaker msg = new StringMaker();
400             msg.append("No ShoppingItem exists with the key ");
401             msg.append(StringPool.OPEN_CURLY_BRACE);
402             msg.append("companyId=");
403             msg.append(companyId);
404             msg.append(", ");
405             msg.append("sku=");
406             msg.append(sku);
407             msg.append(StringPool.CLOSE_CURLY_BRACE);
408 
409             if (_log.isWarnEnabled()) {
410                 _log.warn(msg.toString());
411             }
412 
413             throw new NoSuchItemException(msg.toString());
414         }
415 
416         return shoppingItem;
417     }
418 
419     public ShoppingItem fetchByC_S(long companyId, String sku)
420         throws SystemException {
421         String finderClassName = ShoppingItem.class.getName();
422         String finderMethodName = "fetchByC_S";
423         String[] finderParams = new String[] {
424                 Long.class.getName(), String.class.getName()
425             };
426         Object[] finderArgs = new Object[] { new Long(companyId), sku };
427         Object result = FinderCache.getResult(finderClassName,
428                 finderMethodName, finderParams, finderArgs, getSessionFactory());
429 
430         if (result == null) {
431             Session session = null;
432 
433             try {
434                 session = openSession();
435 
436                 StringMaker query = new StringMaker();
437                 query.append(
438                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
439                 query.append("companyId = ?");
440                 query.append(" AND ");
441 
442                 if (sku == null) {
443                     query.append("sku IS NULL");
444                 }
445                 else {
446                     query.append("sku = ?");
447                 }
448 
449                 query.append(" ");
450                 query.append("ORDER BY ");
451                 query.append("itemId ASC");
452 
453                 Query q = session.createQuery(query.toString());
454                 int queryPos = 0;
455                 q.setLong(queryPos++, companyId);
456 
457                 if (sku != null) {
458                     q.setString(queryPos++, sku);
459                 }
460 
461                 List list = q.list();
462                 FinderCache.putResult(finderClassName, finderMethodName,
463                     finderParams, finderArgs, list);
464 
465                 if (list.size() == 0) {
466                     return null;
467                 }
468                 else {
469                     return (ShoppingItem)list.get(0);
470                 }
471             }
472             catch (Exception e) {
473                 throw HibernateUtil.processException(e);
474             }
475             finally {
476                 closeSession(session);
477             }
478         }
479         else {
480             List list = (List)result;
481 
482             if (list.size() == 0) {
483                 return null;
484             }
485             else {
486                 return (ShoppingItem)list.get(0);
487             }
488         }
489     }
490 
491     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
492         throws SystemException {
493         Session session = null;
494 
495         try {
496             session = openSession();
497 
498             DynamicQuery query = queryInitializer.initialize(session);
499 
500             return query.list();
501         }
502         catch (Exception e) {
503             throw HibernateUtil.processException(e);
504         }
505         finally {
506             closeSession(session);
507         }
508     }
509 
510     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
511         int begin, int end) throws SystemException {
512         Session session = null;
513 
514         try {
515             session = openSession();
516 
517             DynamicQuery query = queryInitializer.initialize(session);
518             query.setLimit(begin, end);
519 
520             return query.list();
521         }
522         catch (Exception e) {
523             throw HibernateUtil.processException(e);
524         }
525         finally {
526             closeSession(session);
527         }
528     }
529 
530     public List findAll() throws SystemException {
531         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
532     }
533 
534     public List findAll(int begin, int end) throws SystemException {
535         return findAll(begin, end, null);
536     }
537 
538     public List findAll(int begin, int end, OrderByComparator obc)
539         throws SystemException {
540         String finderClassName = ShoppingItem.class.getName();
541         String finderMethodName = "findAll";
542         String[] finderParams = new String[] {
543                 "java.lang.Integer", "java.lang.Integer",
544                 "com.liferay.portal.kernel.util.OrderByComparator"
545             };
546         Object[] finderArgs = new Object[] {
547                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
548             };
549         Object result = FinderCache.getResult(finderClassName,
550                 finderMethodName, finderParams, finderArgs, getSessionFactory());
551 
552         if (result == null) {
553             Session session = null;
554 
555             try {
556                 session = openSession();
557 
558                 StringMaker query = new StringMaker();
559                 query.append(
560                     "FROM com.liferay.portlet.shopping.model.ShoppingItem ");
561 
562                 if (obc != null) {
563                     query.append("ORDER BY ");
564                     query.append(obc.getOrderBy());
565                 }
566                 else {
567                     query.append("ORDER BY ");
568                     query.append("itemId ASC");
569                 }
570 
571                 Query q = session.createQuery(query.toString());
572                 List list = QueryUtil.list(q, getDialect(), begin, end);
573 
574                 if (obc == null) {
575                     Collections.sort(list);
576                 }
577 
578                 FinderCache.putResult(finderClassName, finderMethodName,
579                     finderParams, finderArgs, list);
580 
581                 return list;
582             }
583             catch (Exception e) {
584                 throw HibernateUtil.processException(e);
585             }
586             finally {
587                 closeSession(session);
588             }
589         }
590         else {
591             return (List)result;
592         }
593     }
594 
595     public void removeByCategoryId(long categoryId) throws SystemException {
596         Iterator itr = findByCategoryId(categoryId).iterator();
597 
598         while (itr.hasNext()) {
599             ShoppingItem shoppingItem = (ShoppingItem)itr.next();
600             remove(shoppingItem);
601         }
602     }
603 
604     public void removeByC_S(long companyId, String sku)
605         throws NoSuchItemException, SystemException {
606         ShoppingItem shoppingItem = findByC_S(companyId, sku);
607         remove(shoppingItem);
608     }
609 
610     public void removeAll() throws SystemException {
611         Iterator itr = findAll().iterator();
612 
613         while (itr.hasNext()) {
614             remove((ShoppingItem)itr.next());
615         }
616     }
617 
618     public int countByCategoryId(long categoryId) throws SystemException {
619         String finderClassName = ShoppingItem.class.getName();
620         String finderMethodName = "countByCategoryId";
621         String[] finderParams = new String[] { Long.class.getName() };
622         Object[] finderArgs = new Object[] { new Long(categoryId) };
623         Object result = FinderCache.getResult(finderClassName,
624                 finderMethodName, finderParams, finderArgs, getSessionFactory());
625 
626         if (result == null) {
627             Session session = null;
628 
629             try {
630                 session = openSession();
631 
632                 StringMaker query = new StringMaker();
633                 query.append("SELECT COUNT(*) ");
634                 query.append(
635                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
636                 query.append("categoryId = ?");
637                 query.append(" ");
638 
639                 Query q = session.createQuery(query.toString());
640                 int queryPos = 0;
641                 q.setLong(queryPos++, categoryId);
642 
643                 Long count = null;
644                 Iterator itr = q.list().iterator();
645 
646                 if (itr.hasNext()) {
647                     count = (Long)itr.next();
648                 }
649 
650                 if (count == null) {
651                     count = new Long(0);
652                 }
653 
654                 FinderCache.putResult(finderClassName, finderMethodName,
655                     finderParams, finderArgs, count);
656 
657                 return count.intValue();
658             }
659             catch (Exception e) {
660                 throw HibernateUtil.processException(e);
661             }
662             finally {
663                 closeSession(session);
664             }
665         }
666         else {
667             return ((Long)result).intValue();
668         }
669     }
670 
671     public int countByC_S(long companyId, String sku) throws SystemException {
672         String finderClassName = ShoppingItem.class.getName();
673         String finderMethodName = "countByC_S";
674         String[] finderParams = new String[] {
675                 Long.class.getName(), String.class.getName()
676             };
677         Object[] finderArgs = new Object[] { new Long(companyId), sku };
678         Object result = FinderCache.getResult(finderClassName,
679                 finderMethodName, finderParams, finderArgs, getSessionFactory());
680 
681         if (result == null) {
682             Session session = null;
683 
684             try {
685                 session = openSession();
686 
687                 StringMaker query = new StringMaker();
688                 query.append("SELECT COUNT(*) ");
689                 query.append(
690                     "FROM com.liferay.portlet.shopping.model.ShoppingItem WHERE ");
691                 query.append("companyId = ?");
692                 query.append(" AND ");
693 
694                 if (sku == null) {
695                     query.append("sku IS NULL");
696                 }
697                 else {
698                     query.append("sku = ?");
699                 }
700 
701                 query.append(" ");
702 
703                 Query q = session.createQuery(query.toString());
704                 int queryPos = 0;
705                 q.setLong(queryPos++, companyId);
706 
707                 if (sku != null) {
708                     q.setString(queryPos++, sku);
709                 }
710 
711                 Long count = null;
712                 Iterator itr = q.list().iterator();
713 
714                 if (itr.hasNext()) {
715                     count = (Long)itr.next();
716                 }
717 
718                 if (count == null) {
719                     count = new Long(0);
720                 }
721 
722                 FinderCache.putResult(finderClassName, finderMethodName,
723                     finderParams, finderArgs, count);
724 
725                 return count.intValue();
726             }
727             catch (Exception e) {
728                 throw HibernateUtil.processException(e);
729             }
730             finally {
731                 closeSession(session);
732             }
733         }
734         else {
735             return ((Long)result).intValue();
736         }
737     }
738 
739     public int countAll() throws SystemException {
740         String finderClassName = ShoppingItem.class.getName();
741         String finderMethodName = "countAll";
742         String[] finderParams = new String[] {  };
743         Object[] finderArgs = new Object[] {  };
744         Object result = FinderCache.getResult(finderClassName,
745                 finderMethodName, finderParams, finderArgs, getSessionFactory());
746 
747         if (result == null) {
748             Session session = null;
749 
750             try {
751                 session = openSession();
752 
753                 StringMaker query = new StringMaker();
754                 query.append("SELECT COUNT(*) ");
755                 query.append(
756                     "FROM com.liferay.portlet.shopping.model.ShoppingItem");
757 
758                 Query q = session.createQuery(query.toString());
759                 Long count = null;
760                 Iterator itr = q.list().iterator();
761 
762                 if (itr.hasNext()) {
763                     count = (Long)itr.next();
764                 }
765 
766                 if (count == null) {
767                     count = new Long(0);
768                 }
769 
770                 FinderCache.putResult(finderClassName, finderMethodName,
771                     finderParams, finderArgs, count);
772 
773                 return count.intValue();
774             }
775             catch (Exception e) {
776                 throw HibernateUtil.processException(e);
777             }
778             finally {
779                 closeSession(session);
780             }
781         }
782         else {
783             return ((Long)result).intValue();
784         }
785     }
786 
787     public List getShoppingItemPrices(long pk)
788         throws NoSuchItemException, SystemException {
789         return getShoppingItemPrices(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
790     }
791 
792     public List getShoppingItemPrices(long pk, int begin, int end)
793         throws NoSuchItemException, SystemException {
794         return getShoppingItemPrices(pk, begin, end, null);
795     }
796 
797     public List getShoppingItemPrices(long pk, int begin, int end,
798         OrderByComparator obc) throws NoSuchItemException, SystemException {
799         String finderClassName = "null";
800         String finderMethodName = "getShoppingItemPrices";
801         String[] finderParams = new String[] {
802                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
803                 "com.liferay.portal.kernel.util.OrderByComparator"
804             };
805         Object[] finderArgs = new Object[] {
806                 new Long(pk), String.valueOf(begin), String.valueOf(end),
807                 String.valueOf(obc)
808             };
809         Object result = FinderCache.getResult(finderClassName,
810                 finderMethodName, finderParams, finderArgs, getSessionFactory());
811 
812         if (result == null) {
813             Session session = null;
814 
815             try {
816                 session = HibernateUtil.openSession();
817 
818                 StringMaker sm = new StringMaker();
819                 sm.append(_SQL_GETSHOPPINGITEMPRICES);
820 
821                 if (obc != null) {
822                     sm.append("ORDER BY ");
823                     sm.append(obc.getOrderBy());
824                 }
825                 else {
826                     sm.append("ORDER BY ");
827                     sm.append("ShoppingItemPrice.itemId ASC");
828                     sm.append(", ");
829                     sm.append("ShoppingItemPrice.itemPriceId ASC");
830                 }
831 
832                 String sql = sm.toString();
833                 SQLQuery q = session.createSQLQuery(sql);
834                 q.addEntity("ShoppingItemPrice",
835                     com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl.class);
836 
837                 QueryPos qPos = QueryPos.getInstance(q);
838                 qPos.add(pk);
839 
840                 List list = QueryUtil.list(q, getDialect(), begin, end);
841                 FinderCache.putResult(finderClassName, finderMethodName,
842                     finderParams, finderArgs, list);
843 
844                 return list;
845             }
846             catch (Exception e) {
847                 throw new SystemException(e);
848             }
849             finally {
850                 closeSession(session);
851             }
852         }
853         else {
854             return (List)result;
855         }
856     }
857 
858     public int getShoppingItemPricesSize(long pk) throws SystemException {
859         String finderClassName = "null";
860         String finderMethodName = "getShoppingItemPricesSize";
861         String[] finderParams = new String[] { Long.class.getName() };
862         Object[] finderArgs = new Object[] { new Long(pk) };
863         Object result = FinderCache.getResult(finderClassName,
864                 finderMethodName, finderParams, finderArgs, getSessionFactory());
865 
866         if (result == null) {
867             Session session = null;
868 
869             try {
870                 session = openSession();
871 
872                 SQLQuery q = session.createSQLQuery(_SQL_GETSHOPPINGITEMPRICESSIZE);
873                 q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
874 
875                 QueryPos qPos = QueryPos.getInstance(q);
876                 qPos.add(pk);
877 
878                 Long count = null;
879                 Iterator itr = q.list().iterator();
880 
881                 if (itr.hasNext()) {
882                     count = (Long)itr.next();
883                 }
884 
885                 if (count == null) {
886                     count = new Long(0);
887                 }
888 
889                 FinderCache.putResult(finderClassName, finderMethodName,
890                     finderParams, finderArgs, count);
891 
892                 return count.intValue();
893             }
894             catch (Exception e) {
895                 throw HibernateUtil.processException(e);
896             }
897             finally {
898                 closeSession(session);
899             }
900         }
901         else {
902             return ((Long)result).intValue();
903         }
904     }
905 
906     public boolean containsShoppingItemPrice(long pk, long shoppingItemPricePK)
907         throws SystemException {
908         String finderClassName = "null";
909         String finderMethodName = "containsShoppingItemPrices";
910         String[] finderParams = new String[] {
911                 Long.class.getName(), Long.class.getName()
912             };
913         Object[] finderArgs = new Object[] {
914                 new Long(pk), new Long(shoppingItemPricePK)
915             };
916         Object result = FinderCache.getResult(finderClassName,
917                 finderMethodName, finderParams, finderArgs, getSessionFactory());
918 
919         if (result == null) {
920             try {
921                 Boolean value = Boolean.valueOf(containsShoppingItemPrice.contains(
922                             pk, shoppingItemPricePK));
923                 FinderCache.putResult(finderClassName, finderMethodName,
924                     finderParams, finderArgs, value);
925 
926                 return value.booleanValue();
927             }
928             catch (DataAccessException dae) {
929                 throw new SystemException(dae);
930             }
931         }
932         else {
933             return ((Boolean)result).booleanValue();
934         }
935     }
936 
937     public boolean containsShoppingItemPrices(long pk)
938         throws SystemException {
939         if (getShoppingItemPricesSize(pk) > 0) {
940             return true;
941         }
942         else {
943             return false;
944         }
945     }
946 
947     protected void initDao() {
948         containsShoppingItemPrice = new ContainsShoppingItemPrice(this);
949     }
950 
951     protected ContainsShoppingItemPrice containsShoppingItemPrice;
952 
953     protected class ContainsShoppingItemPrice extends MappingSqlQuery {
954         protected ContainsShoppingItemPrice(
955             ShoppingItemPersistenceImpl persistenceImpl) {
956             super(persistenceImpl.getDataSource(),
957                 _SQL_CONTAINSSHOPPINGITEMPRICE);
958             declareParameter(new SqlParameter(Types.BIGINT));
959             declareParameter(new SqlParameter(Types.BIGINT));
960             compile();
961         }
962 
963         protected Object mapRow(ResultSet rs, int rowNumber)
964             throws SQLException {
965             return new Integer(rs.getInt("COUNT_VALUE"));
966         }
967 
968         protected boolean contains(long itemId, long itemPriceId) {
969             List results = execute(new Object[] {
970                         new Long(itemId), new Long(itemPriceId)
971                     });
972 
973             if (results.size() > 0) {
974                 Integer count = (Integer)results.get(0);
975 
976                 if (count.intValue() > 0) {
977                     return true;
978                 }
979             }
980 
981             return false;
982         }
983     }
984 
985     private static final String _SQL_GETSHOPPINGITEMPRICES = "SELECT {ShoppingItemPrice.*} FROM ShoppingItemPrice INNER JOIN ShoppingItem ON (ShoppingItem.itemId = ShoppingItemPrice.itemId) WHERE (ShoppingItem.itemId = ?)";
986     private static final String _SQL_GETSHOPPINGITEMPRICESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM ShoppingItemPrice WHERE itemId = ?";
987     private static final String _SQL_CONTAINSSHOPPINGITEMPRICE = "SELECT COUNT(*) AS COUNT_VALUE FROM ShoppingItemPrice WHERE itemId = ? AND itemPriceId = ?";
988     private static Log _log = LogFactory.getLog(ShoppingItemPersistenceImpl.class);
989 }