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