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 "SELECT shoppingItem FROM ShoppingItem shoppingItem WHERE ");
499
500 query.append("shoppingItem.categoryId = ?");
501
502 query.append(" ");
503
504 query.append("ORDER BY ");
505
506 query.append("shoppingItem.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 "SELECT shoppingItem FROM ShoppingItem shoppingItem WHERE ");
562
563 query.append("shoppingItem.categoryId = ?");
564
565 query.append(" ");
566
567 if (obc != null) {
568 query.append("ORDER BY ");
569
570 String[] orderByFields = obc.getOrderByFields();
571
572 for (int i = 0; i < orderByFields.length; i++) {
573 query.append("shoppingItem.");
574 query.append(orderByFields[i]);
575
576 if (obc.isAscending()) {
577 query.append(" ASC");
578 }
579 else {
580 query.append(" DESC");
581 }
582
583 if ((i + 1) < orderByFields.length) {
584 query.append(", ");
585 }
586 }
587 }
588
589 else {
590 query.append("ORDER BY ");
591
592 query.append("shoppingItem.itemId ASC");
593 }
594
595 Query q = session.createQuery(query.toString());
596
597 QueryPos qPos = QueryPos.getInstance(q);
598
599 qPos.add(categoryId);
600
601 list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
602 start, end);
603 }
604 catch (Exception e) {
605 throw processException(e);
606 }
607 finally {
608 if (list == null) {
609 list = new ArrayList<ShoppingItem>();
610 }
611
612 cacheResult(list);
613
614 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_CATEGORYID,
615 finderArgs, list);
616
617 closeSession(session);
618 }
619 }
620
621 return list;
622 }
623
624 public ShoppingItem findByCategoryId_First(long categoryId,
625 OrderByComparator obc) throws NoSuchItemException, SystemException {
626 List<ShoppingItem> list = findByCategoryId(categoryId, 0, 1, obc);
627
628 if (list.isEmpty()) {
629 StringBuilder msg = new StringBuilder();
630
631 msg.append("No ShoppingItem exists with the key {");
632
633 msg.append("categoryId=" + categoryId);
634
635 msg.append(StringPool.CLOSE_CURLY_BRACE);
636
637 throw new NoSuchItemException(msg.toString());
638 }
639 else {
640 return list.get(0);
641 }
642 }
643
644 public ShoppingItem findByCategoryId_Last(long categoryId,
645 OrderByComparator obc) throws NoSuchItemException, SystemException {
646 int count = countByCategoryId(categoryId);
647
648 List<ShoppingItem> list = findByCategoryId(categoryId, count - 1,
649 count, obc);
650
651 if (list.isEmpty()) {
652 StringBuilder msg = new StringBuilder();
653
654 msg.append("No ShoppingItem exists with the key {");
655
656 msg.append("categoryId=" + categoryId);
657
658 msg.append(StringPool.CLOSE_CURLY_BRACE);
659
660 throw new NoSuchItemException(msg.toString());
661 }
662 else {
663 return list.get(0);
664 }
665 }
666
667 public ShoppingItem[] findByCategoryId_PrevAndNext(long itemId,
668 long categoryId, OrderByComparator obc)
669 throws NoSuchItemException, SystemException {
670 ShoppingItem shoppingItem = findByPrimaryKey(itemId);
671
672 int count = countByCategoryId(categoryId);
673
674 Session session = null;
675
676 try {
677 session = openSession();
678
679 StringBuilder query = new StringBuilder();
680
681 query.append(
682 "SELECT shoppingItem FROM ShoppingItem shoppingItem WHERE ");
683
684 query.append("shoppingItem.categoryId = ?");
685
686 query.append(" ");
687
688 if (obc != null) {
689 query.append("ORDER BY ");
690
691 String[] orderByFields = obc.getOrderByFields();
692
693 for (int i = 0; i < orderByFields.length; i++) {
694 query.append("shoppingItem.");
695 query.append(orderByFields[i]);
696
697 if (obc.isAscending()) {
698 query.append(" ASC");
699 }
700 else {
701 query.append(" DESC");
702 }
703
704 if ((i + 1) < orderByFields.length) {
705 query.append(", ");
706 }
707 }
708 }
709
710 else {
711 query.append("ORDER BY ");
712
713 query.append("shoppingItem.itemId ASC");
714 }
715
716 Query q = session.createQuery(query.toString());
717
718 QueryPos qPos = QueryPos.getInstance(q);
719
720 qPos.add(categoryId);
721
722 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
723 shoppingItem);
724
725 ShoppingItem[] array = new ShoppingItemImpl[3];
726
727 array[0] = (ShoppingItem)objArray[0];
728 array[1] = (ShoppingItem)objArray[1];
729 array[2] = (ShoppingItem)objArray[2];
730
731 return array;
732 }
733 catch (Exception e) {
734 throw processException(e);
735 }
736 finally {
737 closeSession(session);
738 }
739 }
740
741 public ShoppingItem findBySmallImageId(long smallImageId)
742 throws NoSuchItemException, SystemException {
743 ShoppingItem shoppingItem = fetchBySmallImageId(smallImageId);
744
745 if (shoppingItem == null) {
746 StringBuilder msg = new StringBuilder();
747
748 msg.append("No ShoppingItem exists with the key {");
749
750 msg.append("smallImageId=" + smallImageId);
751
752 msg.append(StringPool.CLOSE_CURLY_BRACE);
753
754 if (_log.isWarnEnabled()) {
755 _log.warn(msg.toString());
756 }
757
758 throw new NoSuchItemException(msg.toString());
759 }
760
761 return shoppingItem;
762 }
763
764 public ShoppingItem fetchBySmallImageId(long smallImageId)
765 throws SystemException {
766 return fetchBySmallImageId(smallImageId, true);
767 }
768
769 public ShoppingItem fetchBySmallImageId(long smallImageId,
770 boolean retrieveFromCache) throws SystemException {
771 Object[] finderArgs = new Object[] { new Long(smallImageId) };
772
773 Object result = null;
774
775 if (retrieveFromCache) {
776 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
777 finderArgs, this);
778 }
779
780 if (result == null) {
781 Session session = null;
782
783 try {
784 session = openSession();
785
786 StringBuilder query = new StringBuilder();
787
788 query.append(
789 "SELECT shoppingItem FROM ShoppingItem shoppingItem WHERE ");
790
791 query.append("shoppingItem.smallImageId = ?");
792
793 query.append(" ");
794
795 query.append("ORDER BY ");
796
797 query.append("shoppingItem.itemId ASC");
798
799 Query q = session.createQuery(query.toString());
800
801 QueryPos qPos = QueryPos.getInstance(q);
802
803 qPos.add(smallImageId);
804
805 List<ShoppingItem> list = q.list();
806
807 result = list;
808
809 ShoppingItem shoppingItem = null;
810
811 if (list.isEmpty()) {
812 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
813 finderArgs, list);
814 }
815 else {
816 shoppingItem = list.get(0);
817
818 cacheResult(shoppingItem);
819
820 if ((shoppingItem.getSmallImageId() != smallImageId)) {
821 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
822 finderArgs, shoppingItem);
823 }
824 }
825
826 return shoppingItem;
827 }
828 catch (Exception e) {
829 throw processException(e);
830 }
831 finally {
832 if (result == null) {
833 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
834 finderArgs, new ArrayList<ShoppingItem>());
835 }
836
837 closeSession(session);
838 }
839 }
840 else {
841 if (result instanceof List) {
842 return null;
843 }
844 else {
845 return (ShoppingItem)result;
846 }
847 }
848 }
849
850 public ShoppingItem findByMediumImageId(long mediumImageId)
851 throws NoSuchItemException, SystemException {
852 ShoppingItem shoppingItem = fetchByMediumImageId(mediumImageId);
853
854 if (shoppingItem == null) {
855 StringBuilder msg = new StringBuilder();
856
857 msg.append("No ShoppingItem exists with the key {");
858
859 msg.append("mediumImageId=" + mediumImageId);
860
861 msg.append(StringPool.CLOSE_CURLY_BRACE);
862
863 if (_log.isWarnEnabled()) {
864 _log.warn(msg.toString());
865 }
866
867 throw new NoSuchItemException(msg.toString());
868 }
869
870 return shoppingItem;
871 }
872
873 public ShoppingItem fetchByMediumImageId(long mediumImageId)
874 throws SystemException {
875 return fetchByMediumImageId(mediumImageId, true);
876 }
877
878 public ShoppingItem fetchByMediumImageId(long mediumImageId,
879 boolean retrieveFromCache) throws SystemException {
880 Object[] finderArgs = new Object[] { new Long(mediumImageId) };
881
882 Object result = null;
883
884 if (retrieveFromCache) {
885 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
886 finderArgs, this);
887 }
888
889 if (result == null) {
890 Session session = null;
891
892 try {
893 session = openSession();
894
895 StringBuilder query = new StringBuilder();
896
897 query.append(
898 "SELECT shoppingItem FROM ShoppingItem shoppingItem WHERE ");
899
900 query.append("shoppingItem.mediumImageId = ?");
901
902 query.append(" ");
903
904 query.append("ORDER BY ");
905
906 query.append("shoppingItem.itemId ASC");
907
908 Query q = session.createQuery(query.toString());
909
910 QueryPos qPos = QueryPos.getInstance(q);
911
912 qPos.add(mediumImageId);
913
914 List<ShoppingItem> list = q.list();
915
916 result = list;
917
918 ShoppingItem shoppingItem = null;
919
920 if (list.isEmpty()) {
921 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
922 finderArgs, list);
923 }
924 else {
925 shoppingItem = list.get(0);
926
927 cacheResult(shoppingItem);
928
929 if ((shoppingItem.getMediumImageId() != mediumImageId)) {
930 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
931 finderArgs, shoppingItem);
932 }
933 }
934
935 return shoppingItem;
936 }
937 catch (Exception e) {
938 throw processException(e);
939 }
940 finally {
941 if (result == null) {
942 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
943 finderArgs, new ArrayList<ShoppingItem>());
944 }
945
946 closeSession(session);
947 }
948 }
949 else {
950 if (result instanceof List) {
951 return null;
952 }
953 else {
954 return (ShoppingItem)result;
955 }
956 }
957 }
958
959 public ShoppingItem findByLargeImageId(long largeImageId)
960 throws NoSuchItemException, SystemException {
961 ShoppingItem shoppingItem = fetchByLargeImageId(largeImageId);
962
963 if (shoppingItem == null) {
964 StringBuilder msg = new StringBuilder();
965
966 msg.append("No ShoppingItem exists with the key {");
967
968 msg.append("largeImageId=" + largeImageId);
969
970 msg.append(StringPool.CLOSE_CURLY_BRACE);
971
972 if (_log.isWarnEnabled()) {
973 _log.warn(msg.toString());
974 }
975
976 throw new NoSuchItemException(msg.toString());
977 }
978
979 return shoppingItem;
980 }
981
982 public ShoppingItem fetchByLargeImageId(long largeImageId)
983 throws SystemException {
984 return fetchByLargeImageId(largeImageId, true);
985 }
986
987 public ShoppingItem fetchByLargeImageId(long largeImageId,
988 boolean retrieveFromCache) throws SystemException {
989 Object[] finderArgs = new Object[] { new Long(largeImageId) };
990
991 Object result = null;
992
993 if (retrieveFromCache) {
994 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
995 finderArgs, this);
996 }
997
998 if (result == null) {
999 Session session = null;
1000
1001 try {
1002 session = openSession();
1003
1004 StringBuilder query = new StringBuilder();
1005
1006 query.append(
1007 "SELECT shoppingItem FROM ShoppingItem shoppingItem WHERE ");
1008
1009 query.append("shoppingItem.largeImageId = ?");
1010
1011 query.append(" ");
1012
1013 query.append("ORDER BY ");
1014
1015 query.append("shoppingItem.itemId ASC");
1016
1017 Query q = session.createQuery(query.toString());
1018
1019 QueryPos qPos = QueryPos.getInstance(q);
1020
1021 qPos.add(largeImageId);
1022
1023 List<ShoppingItem> list = q.list();
1024
1025 result = list;
1026
1027 ShoppingItem shoppingItem = null;
1028
1029 if (list.isEmpty()) {
1030 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1031 finderArgs, list);
1032 }
1033 else {
1034 shoppingItem = list.get(0);
1035
1036 cacheResult(shoppingItem);
1037
1038 if ((shoppingItem.getLargeImageId() != largeImageId)) {
1039 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1040 finderArgs, shoppingItem);
1041 }
1042 }
1043
1044 return shoppingItem;
1045 }
1046 catch (Exception e) {
1047 throw processException(e);
1048 }
1049 finally {
1050 if (result == null) {
1051 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1052 finderArgs, new ArrayList<ShoppingItem>());
1053 }
1054
1055 closeSession(session);
1056 }
1057 }
1058 else {
1059 if (result instanceof List) {
1060 return null;
1061 }
1062 else {
1063 return (ShoppingItem)result;
1064 }
1065 }
1066 }
1067
1068 public ShoppingItem findByC_S(long companyId, String sku)
1069 throws NoSuchItemException, SystemException {
1070 ShoppingItem shoppingItem = fetchByC_S(companyId, sku);
1071
1072 if (shoppingItem == null) {
1073 StringBuilder msg = new StringBuilder();
1074
1075 msg.append("No ShoppingItem exists with the key {");
1076
1077 msg.append("companyId=" + companyId);
1078
1079 msg.append(", ");
1080 msg.append("sku=" + sku);
1081
1082 msg.append(StringPool.CLOSE_CURLY_BRACE);
1083
1084 if (_log.isWarnEnabled()) {
1085 _log.warn(msg.toString());
1086 }
1087
1088 throw new NoSuchItemException(msg.toString());
1089 }
1090
1091 return shoppingItem;
1092 }
1093
1094 public ShoppingItem fetchByC_S(long companyId, String sku)
1095 throws SystemException {
1096 return fetchByC_S(companyId, sku, true);
1097 }
1098
1099 public ShoppingItem fetchByC_S(long companyId, String sku,
1100 boolean retrieveFromCache) throws SystemException {
1101 Object[] finderArgs = new Object[] { new Long(companyId), sku };
1102
1103 Object result = null;
1104
1105 if (retrieveFromCache) {
1106 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_S,
1107 finderArgs, this);
1108 }
1109
1110 if (result == null) {
1111 Session session = null;
1112
1113 try {
1114 session = openSession();
1115
1116 StringBuilder query = new StringBuilder();
1117
1118 query.append(
1119 "SELECT shoppingItem FROM ShoppingItem shoppingItem WHERE ");
1120
1121 query.append("shoppingItem.companyId = ?");
1122
1123 query.append(" AND ");
1124
1125 if (sku == null) {
1126 query.append("shoppingItem.sku IS NULL");
1127 }
1128 else {
1129 query.append("shoppingItem.sku = ?");
1130 }
1131
1132 query.append(" ");
1133
1134 query.append("ORDER BY ");
1135
1136 query.append("shoppingItem.itemId ASC");
1137
1138 Query q = session.createQuery(query.toString());
1139
1140 QueryPos qPos = QueryPos.getInstance(q);
1141
1142 qPos.add(companyId);
1143
1144 if (sku != null) {
1145 qPos.add(sku);
1146 }
1147
1148 List<ShoppingItem> list = q.list();
1149
1150 result = list;
1151
1152 ShoppingItem shoppingItem = null;
1153
1154 if (list.isEmpty()) {
1155 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S,
1156 finderArgs, list);
1157 }
1158 else {
1159 shoppingItem = list.get(0);
1160
1161 cacheResult(shoppingItem);
1162
1163 if ((shoppingItem.getCompanyId() != companyId) ||
1164 (shoppingItem.getSku() == null) ||
1165 !shoppingItem.getSku().equals(sku)) {
1166 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S,
1167 finderArgs, shoppingItem);
1168 }
1169 }
1170
1171 return shoppingItem;
1172 }
1173 catch (Exception e) {
1174 throw processException(e);
1175 }
1176 finally {
1177 if (result == null) {
1178 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S,
1179 finderArgs, new ArrayList<ShoppingItem>());
1180 }
1181
1182 closeSession(session);
1183 }
1184 }
1185 else {
1186 if (result instanceof List) {
1187 return null;
1188 }
1189 else {
1190 return (ShoppingItem)result;
1191 }
1192 }
1193 }
1194
1195 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1196 throws SystemException {
1197 Session session = null;
1198
1199 try {
1200 session = openSession();
1201
1202 dynamicQuery.compile(session);
1203
1204 return dynamicQuery.list();
1205 }
1206 catch (Exception e) {
1207 throw processException(e);
1208 }
1209 finally {
1210 closeSession(session);
1211 }
1212 }
1213
1214 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1215 int start, int end) throws SystemException {
1216 Session session = null;
1217
1218 try {
1219 session = openSession();
1220
1221 dynamicQuery.setLimit(start, end);
1222
1223 dynamicQuery.compile(session);
1224
1225 return dynamicQuery.list();
1226 }
1227 catch (Exception e) {
1228 throw processException(e);
1229 }
1230 finally {
1231 closeSession(session);
1232 }
1233 }
1234
1235 public List<ShoppingItem> findAll() throws SystemException {
1236 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1237 }
1238
1239 public List<ShoppingItem> findAll(int start, int end)
1240 throws SystemException {
1241 return findAll(start, end, null);
1242 }
1243
1244 public List<ShoppingItem> findAll(int start, int end, OrderByComparator obc)
1245 throws SystemException {
1246 Object[] finderArgs = new Object[] {
1247 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1248 };
1249
1250 List<ShoppingItem> list = (List<ShoppingItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1251 finderArgs, this);
1252
1253 if (list == null) {
1254 Session session = null;
1255
1256 try {
1257 session = openSession();
1258
1259 StringBuilder query = new StringBuilder();
1260
1261 query.append(
1262 "SELECT shoppingItem FROM ShoppingItem shoppingItem ");
1263
1264 if (obc != null) {
1265 query.append("ORDER BY ");
1266
1267 String[] orderByFields = obc.getOrderByFields();
1268
1269 for (int i = 0; i < orderByFields.length; i++) {
1270 query.append("shoppingItem.");
1271 query.append(orderByFields[i]);
1272
1273 if (obc.isAscending()) {
1274 query.append(" ASC");
1275 }
1276 else {
1277 query.append(" DESC");
1278 }
1279
1280 if ((i + 1) < orderByFields.length) {
1281 query.append(", ");
1282 }
1283 }
1284 }
1285
1286 else {
1287 query.append("ORDER BY ");
1288
1289 query.append("shoppingItem.itemId ASC");
1290 }
1291
1292 Query q = session.createQuery(query.toString());
1293
1294 if (obc == null) {
1295 list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
1296 start, end, false);
1297
1298 Collections.sort(list);
1299 }
1300 else {
1301 list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
1302 start, end);
1303 }
1304 }
1305 catch (Exception e) {
1306 throw processException(e);
1307 }
1308 finally {
1309 if (list == null) {
1310 list = new ArrayList<ShoppingItem>();
1311 }
1312
1313 cacheResult(list);
1314
1315 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1316
1317 closeSession(session);
1318 }
1319 }
1320
1321 return list;
1322 }
1323
1324 public void removeByCategoryId(long categoryId) throws SystemException {
1325 for (ShoppingItem shoppingItem : findByCategoryId(categoryId)) {
1326 remove(shoppingItem);
1327 }
1328 }
1329
1330 public void removeBySmallImageId(long smallImageId)
1331 throws NoSuchItemException, SystemException {
1332 ShoppingItem shoppingItem = findBySmallImageId(smallImageId);
1333
1334 remove(shoppingItem);
1335 }
1336
1337 public void removeByMediumImageId(long mediumImageId)
1338 throws NoSuchItemException, SystemException {
1339 ShoppingItem shoppingItem = findByMediumImageId(mediumImageId);
1340
1341 remove(shoppingItem);
1342 }
1343
1344 public void removeByLargeImageId(long largeImageId)
1345 throws NoSuchItemException, SystemException {
1346 ShoppingItem shoppingItem = findByLargeImageId(largeImageId);
1347
1348 remove(shoppingItem);
1349 }
1350
1351 public void removeByC_S(long companyId, String sku)
1352 throws NoSuchItemException, SystemException {
1353 ShoppingItem shoppingItem = findByC_S(companyId, sku);
1354
1355 remove(shoppingItem);
1356 }
1357
1358 public void removeAll() throws SystemException {
1359 for (ShoppingItem shoppingItem : findAll()) {
1360 remove(shoppingItem);
1361 }
1362 }
1363
1364 public int countByCategoryId(long categoryId) throws SystemException {
1365 Object[] finderArgs = new Object[] { new Long(categoryId) };
1366
1367 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CATEGORYID,
1368 finderArgs, this);
1369
1370 if (count == null) {
1371 Session session = null;
1372
1373 try {
1374 session = openSession();
1375
1376 StringBuilder query = new StringBuilder();
1377
1378 query.append("SELECT COUNT(shoppingItem) ");
1379 query.append("FROM ShoppingItem shoppingItem WHERE ");
1380
1381 query.append("shoppingItem.categoryId = ?");
1382
1383 query.append(" ");
1384
1385 Query q = session.createQuery(query.toString());
1386
1387 QueryPos qPos = QueryPos.getInstance(q);
1388
1389 qPos.add(categoryId);
1390
1391 count = (Long)q.uniqueResult();
1392 }
1393 catch (Exception e) {
1394 throw processException(e);
1395 }
1396 finally {
1397 if (count == null) {
1398 count = Long.valueOf(0);
1399 }
1400
1401 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CATEGORYID,
1402 finderArgs, count);
1403
1404 closeSession(session);
1405 }
1406 }
1407
1408 return count.intValue();
1409 }
1410
1411 public int countBySmallImageId(long smallImageId) throws SystemException {
1412 Object[] finderArgs = new Object[] { new Long(smallImageId) };
1413
1414 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
1415 finderArgs, this);
1416
1417 if (count == null) {
1418 Session session = null;
1419
1420 try {
1421 session = openSession();
1422
1423 StringBuilder query = new StringBuilder();
1424
1425 query.append("SELECT COUNT(shoppingItem) ");
1426 query.append("FROM ShoppingItem shoppingItem WHERE ");
1427
1428 query.append("shoppingItem.smallImageId = ?");
1429
1430 query.append(" ");
1431
1432 Query q = session.createQuery(query.toString());
1433
1434 QueryPos qPos = QueryPos.getInstance(q);
1435
1436 qPos.add(smallImageId);
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_SMALLIMAGEID,
1449 finderArgs, count);
1450
1451 closeSession(session);
1452 }
1453 }
1454
1455 return count.intValue();
1456 }
1457
1458 public int countByMediumImageId(long mediumImageId)
1459 throws SystemException {
1460 Object[] finderArgs = new Object[] { new Long(mediumImageId) };
1461
1462 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MEDIUMIMAGEID,
1463 finderArgs, this);
1464
1465 if (count == null) {
1466 Session session = null;
1467
1468 try {
1469 session = openSession();
1470
1471 StringBuilder query = new StringBuilder();
1472
1473 query.append("SELECT COUNT(shoppingItem) ");
1474 query.append("FROM ShoppingItem shoppingItem WHERE ");
1475
1476 query.append("shoppingItem.mediumImageId = ?");
1477
1478 query.append(" ");
1479
1480 Query q = session.createQuery(query.toString());
1481
1482 QueryPos qPos = QueryPos.getInstance(q);
1483
1484 qPos.add(mediumImageId);
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_MEDIUMIMAGEID,
1497 finderArgs, count);
1498
1499 closeSession(session);
1500 }
1501 }
1502
1503 return count.intValue();
1504 }
1505
1506 public int countByLargeImageId(long largeImageId) throws SystemException {
1507 Object[] finderArgs = new Object[] { new Long(largeImageId) };
1508
1509 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID,
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(shoppingItem) ");
1521 query.append("FROM ShoppingItem shoppingItem WHERE ");
1522
1523 query.append("shoppingItem.largeImageId = ?");
1524
1525 query.append(" ");
1526
1527 Query q = session.createQuery(query.toString());
1528
1529 QueryPos qPos = QueryPos.getInstance(q);
1530
1531 qPos.add(largeImageId);
1532
1533 count = (Long)q.uniqueResult();
1534 }
1535 catch (Exception e) {
1536 throw processException(e);
1537 }
1538 finally {
1539 if (count == null) {
1540 count = Long.valueOf(0);
1541 }
1542
1543 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID,
1544 finderArgs, count);
1545
1546 closeSession(session);
1547 }
1548 }
1549
1550 return count.intValue();
1551 }
1552
1553 public int countByC_S(long companyId, String sku) throws SystemException {
1554 Object[] finderArgs = new Object[] { new Long(companyId), sku };
1555
1556 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_S,
1557 finderArgs, this);
1558
1559 if (count == null) {
1560 Session session = null;
1561
1562 try {
1563 session = openSession();
1564
1565 StringBuilder query = new StringBuilder();
1566
1567 query.append("SELECT COUNT(shoppingItem) ");
1568 query.append("FROM ShoppingItem shoppingItem WHERE ");
1569
1570 query.append("shoppingItem.companyId = ?");
1571
1572 query.append(" AND ");
1573
1574 if (sku == null) {
1575 query.append("shoppingItem.sku IS NULL");
1576 }
1577 else {
1578 query.append("shoppingItem.sku = ?");
1579 }
1580
1581 query.append(" ");
1582
1583 Query q = session.createQuery(query.toString());
1584
1585 QueryPos qPos = QueryPos.getInstance(q);
1586
1587 qPos.add(companyId);
1588
1589 if (sku != null) {
1590 qPos.add(sku);
1591 }
1592
1593 count = (Long)q.uniqueResult();
1594 }
1595 catch (Exception e) {
1596 throw processException(e);
1597 }
1598 finally {
1599 if (count == null) {
1600 count = Long.valueOf(0);
1601 }
1602
1603 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, finderArgs,
1604 count);
1605
1606 closeSession(session);
1607 }
1608 }
1609
1610 return count.intValue();
1611 }
1612
1613 public int countAll() throws SystemException {
1614 Object[] finderArgs = new Object[0];
1615
1616 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1617 finderArgs, this);
1618
1619 if (count == null) {
1620 Session session = null;
1621
1622 try {
1623 session = openSession();
1624
1625 Query q = session.createQuery(
1626 "SELECT COUNT(shoppingItem) FROM ShoppingItem shoppingItem");
1627
1628 count = (Long)q.uniqueResult();
1629 }
1630 catch (Exception e) {
1631 throw processException(e);
1632 }
1633 finally {
1634 if (count == null) {
1635 count = Long.valueOf(0);
1636 }
1637
1638 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1639 count);
1640
1641 closeSession(session);
1642 }
1643 }
1644
1645 return count.intValue();
1646 }
1647
1648 public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
1649 long pk) throws SystemException {
1650 return getShoppingItemPrices(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1651 }
1652
1653 public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
1654 long pk, int start, int end) throws SystemException {
1655 return getShoppingItemPrices(pk, start, end, null);
1656 }
1657
1658 public static final FinderPath FINDER_PATH_GET_SHOPPINGITEMPRICES = new FinderPath(com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
1659 com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
1660 com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistenceImpl.FINDER_CLASS_NAME_LIST,
1661 "getShoppingItemPrices",
1662 new String[] {
1663 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1664 "com.liferay.portal.kernel.util.OrderByComparator"
1665 });
1666
1667 public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
1668 long pk, int start, int end, OrderByComparator obc)
1669 throws SystemException {
1670 Object[] finderArgs = new Object[] {
1671 new Long(pk), String.valueOf(start), String.valueOf(end),
1672 String.valueOf(obc)
1673 };
1674
1675 List<com.liferay.portlet.shopping.model.ShoppingItemPrice> list = (List<com.liferay.portlet.shopping.model.ShoppingItemPrice>)FinderCacheUtil.getResult(FINDER_PATH_GET_SHOPPINGITEMPRICES,
1676 finderArgs, this);
1677
1678 if (list == null) {
1679 Session session = null;
1680
1681 try {
1682 session = openSession();
1683
1684 StringBuilder sb = new StringBuilder();
1685
1686 sb.append(_SQL_GETSHOPPINGITEMPRICES);
1687
1688 if (obc != null) {
1689 sb.append("ORDER BY ");
1690 sb.append(obc.getOrderBy());
1691 }
1692
1693 else {
1694 sb.append("ORDER BY ");
1695
1696 sb.append("ShoppingItemPrice.itemId ASC, ");
1697 sb.append("ShoppingItemPrice.itemPriceId ASC");
1698 }
1699
1700 String sql = sb.toString();
1701
1702 SQLQuery q = session.createSQLQuery(sql);
1703
1704 q.addEntity("ShoppingItemPrice",
1705 com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl.class);
1706
1707 QueryPos qPos = QueryPos.getInstance(q);
1708
1709 qPos.add(pk);
1710
1711 list = (List<com.liferay.portlet.shopping.model.ShoppingItemPrice>)QueryUtil.list(q,
1712 getDialect(), start, end);
1713 }
1714 catch (Exception e) {
1715 throw processException(e);
1716 }
1717 finally {
1718 if (list == null) {
1719 list = new ArrayList<com.liferay.portlet.shopping.model.ShoppingItemPrice>();
1720 }
1721
1722 shoppingItemPricePersistence.cacheResult(list);
1723
1724 FinderCacheUtil.putResult(FINDER_PATH_GET_SHOPPINGITEMPRICES,
1725 finderArgs, list);
1726
1727 closeSession(session);
1728 }
1729 }
1730
1731 return list;
1732 }
1733
1734 public static final FinderPath FINDER_PATH_GET_SHOPPINGITEMPRICES_SIZE = new FinderPath(com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
1735 com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
1736 com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistenceImpl.FINDER_CLASS_NAME_LIST,
1737 "getShoppingItemPricesSize", new String[] { Long.class.getName() });
1738
1739 public int getShoppingItemPricesSize(long pk) throws SystemException {
1740 Object[] finderArgs = new Object[] { new Long(pk) };
1741
1742 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_SHOPPINGITEMPRICES_SIZE,
1743 finderArgs, this);
1744
1745 if (count == null) {
1746 Session session = null;
1747
1748 try {
1749 session = openSession();
1750
1751 SQLQuery q = session.createSQLQuery(_SQL_GETSHOPPINGITEMPRICESSIZE);
1752
1753 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1754
1755 QueryPos qPos = QueryPos.getInstance(q);
1756
1757 qPos.add(pk);
1758
1759 count = (Long)q.uniqueResult();
1760 }
1761 catch (Exception e) {
1762 throw processException(e);
1763 }
1764 finally {
1765 if (count == null) {
1766 count = Long.valueOf(0);
1767 }
1768
1769 FinderCacheUtil.putResult(FINDER_PATH_GET_SHOPPINGITEMPRICES_SIZE,
1770 finderArgs, count);
1771
1772 closeSession(session);
1773 }
1774 }
1775
1776 return count.intValue();
1777 }
1778
1779 public static final FinderPath FINDER_PATH_CONTAINS_SHOPPINGITEMPRICE = new FinderPath(com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
1780 com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
1781 com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistenceImpl.FINDER_CLASS_NAME_LIST,
1782 "containsShoppingItemPrice",
1783 new String[] { Long.class.getName(), Long.class.getName() });
1784
1785 public boolean containsShoppingItemPrice(long pk, long shoppingItemPricePK)
1786 throws SystemException {
1787 Object[] finderArgs = new Object[] {
1788 new Long(pk),
1789
1790 new Long(shoppingItemPricePK)
1791 };
1792
1793 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_SHOPPINGITEMPRICE,
1794 finderArgs, this);
1795
1796 if (value == null) {
1797 try {
1798 value = Boolean.valueOf(containsShoppingItemPrice.contains(pk,
1799 shoppingItemPricePK));
1800 }
1801 catch (Exception e) {
1802 throw processException(e);
1803 }
1804 finally {
1805 if (value == null) {
1806 value = Boolean.FALSE;
1807 }
1808
1809 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_SHOPPINGITEMPRICE,
1810 finderArgs, value);
1811 }
1812 }
1813
1814 return value.booleanValue();
1815 }
1816
1817 public boolean containsShoppingItemPrices(long pk)
1818 throws SystemException {
1819 if (getShoppingItemPricesSize(pk) > 0) {
1820 return true;
1821 }
1822 else {
1823 return false;
1824 }
1825 }
1826
1827 public void afterPropertiesSet() {
1828 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1829 com.liferay.portal.util.PropsUtil.get(
1830 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItem")));
1831
1832 if (listenerClassNames.length > 0) {
1833 try {
1834 List<ModelListener<ShoppingItem>> listenersList = new ArrayList<ModelListener<ShoppingItem>>();
1835
1836 for (String listenerClassName : listenerClassNames) {
1837 listenersList.add((ModelListener<ShoppingItem>)Class.forName(
1838 listenerClassName).newInstance());
1839 }
1840
1841 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1842 }
1843 catch (Exception e) {
1844 _log.error(e);
1845 }
1846 }
1847
1848 containsShoppingItemPrice = new ContainsShoppingItemPrice(this);
1849 }
1850
1851 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCartPersistence.impl")
1852 protected com.liferay.portlet.shopping.service.persistence.ShoppingCartPersistence shoppingCartPersistence;
1853 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCategoryPersistence.impl")
1854 protected com.liferay.portlet.shopping.service.persistence.ShoppingCategoryPersistence shoppingCategoryPersistence;
1855 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCouponPersistence.impl")
1856 protected com.liferay.portlet.shopping.service.persistence.ShoppingCouponPersistence shoppingCouponPersistence;
1857 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingItemPersistence.impl")
1858 protected com.liferay.portlet.shopping.service.persistence.ShoppingItemPersistence shoppingItemPersistence;
1859 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingItemFieldPersistence.impl")
1860 protected com.liferay.portlet.shopping.service.persistence.ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1861 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistence.impl")
1862 protected com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistence shoppingItemPricePersistence;
1863 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingOrderPersistence.impl")
1864 protected com.liferay.portlet.shopping.service.persistence.ShoppingOrderPersistence shoppingOrderPersistence;
1865 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingOrderItemPersistence.impl")
1866 protected com.liferay.portlet.shopping.service.persistence.ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1867 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1868 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1869 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1870 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1871 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1872 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1873 protected ContainsShoppingItemPrice containsShoppingItemPrice;
1874
1875 protected class ContainsShoppingItemPrice {
1876 protected ContainsShoppingItemPrice(
1877 ShoppingItemPersistenceImpl persistenceImpl) {
1878 super();
1879
1880 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1881 _SQL_CONTAINSSHOPPINGITEMPRICE,
1882 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1883 }
1884
1885 protected boolean contains(long itemId, long itemPriceId) {
1886 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1887 new Long(itemId), new Long(itemPriceId)
1888 });
1889
1890 if (results.size() > 0) {
1891 Integer count = results.get(0);
1892
1893 if (count.intValue() > 0) {
1894 return true;
1895 }
1896 }
1897
1898 return false;
1899 }
1900
1901 private MappingSqlQuery _mappingSqlQuery;
1902 }
1903
1904 private static final String _SQL_GETSHOPPINGITEMPRICES = "SELECT {ShoppingItemPrice.*} FROM ShoppingItemPrice INNER JOIN ShoppingItem ON (ShoppingItem.itemId = ShoppingItemPrice.itemId) WHERE (ShoppingItem.itemId = ?)";
1905 private static final String _SQL_GETSHOPPINGITEMPRICESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM ShoppingItemPrice WHERE itemId = ?";
1906 private static final String _SQL_CONTAINSSHOPPINGITEMPRICE = "SELECT COUNT(*) AS COUNT_VALUE FROM ShoppingItemPrice WHERE itemId = ? AND itemPriceId = ?";
1907 private static Log _log = LogFactoryUtil.getLog(ShoppingItemPersistenceImpl.class);
1908}