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