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