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