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