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