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