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