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