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