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