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