1   /**
2    * Copyright (c) 2000-2010 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   *
12   * 
13   */
14  
15  package com.liferay.portlet.shopping.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.GetterUtil;
31  import com.liferay.portal.kernel.util.OrderByComparator;
32  import com.liferay.portal.kernel.util.StringBundler;
33  import com.liferay.portal.kernel.util.StringPool;
34  import com.liferay.portal.kernel.util.StringUtil;
35  import com.liferay.portal.model.ModelListener;
36  import com.liferay.portal.service.persistence.BatchSessionUtil;
37  import com.liferay.portal.service.persistence.ResourcePersistence;
38  import com.liferay.portal.service.persistence.UserPersistence;
39  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40  
41  import com.liferay.portlet.shopping.NoSuchItemPriceException;
42  import com.liferay.portlet.shopping.model.ShoppingItemPrice;
43  import com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl;
44  import com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl;
45  
46  import java.io.Serializable;
47  
48  import java.util.ArrayList;
49  import java.util.Collections;
50  import java.util.List;
51  
52  /**
53   * <a href="ShoppingItemPricePersistenceImpl.java.html"><b><i>View Source</i></b></a>
54   *
55   * <p>
56   * ServiceBuilder generated this class. Modifications in this class will be
57   * overwritten the next time is generated.
58   * </p>
59   *
60   * @author    Brian Wing Shun Chan
61   * @see       ShoppingItemPricePersistence
62   * @see       ShoppingItemPriceUtil
63   * @generated
64   */
65  public class ShoppingItemPricePersistenceImpl extends BasePersistenceImpl<ShoppingItemPrice>
66      implements ShoppingItemPricePersistence {
67      public static final String FINDER_CLASS_NAME_ENTITY = ShoppingItemPriceImpl.class.getName();
68      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
69          ".List";
70      public static final FinderPath FINDER_PATH_FIND_BY_ITEMID = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
71              ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
72              FINDER_CLASS_NAME_LIST, "findByItemId",
73              new String[] { Long.class.getName() });
74      public static final FinderPath FINDER_PATH_FIND_BY_OBC_ITEMID = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
75              ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
76              FINDER_CLASS_NAME_LIST, "findByItemId",
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_ITEMID = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
84              ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
85              FINDER_CLASS_NAME_LIST, "countByItemId",
86              new String[] { Long.class.getName() });
87      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
88              ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
89              FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
90      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
91              ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
92              FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
93  
94      public void cacheResult(ShoppingItemPrice shoppingItemPrice) {
95          EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
96              ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
97              shoppingItemPrice);
98      }
99  
100     public void cacheResult(List<ShoppingItemPrice> shoppingItemPrices) {
101         for (ShoppingItemPrice shoppingItemPrice : shoppingItemPrices) {
102             if (EntityCacheUtil.getResult(
103                         ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
104                         ShoppingItemPriceImpl.class,
105                         shoppingItemPrice.getPrimaryKey(), this) == null) {
106                 cacheResult(shoppingItemPrice);
107             }
108         }
109     }
110 
111     public void clearCache() {
112         CacheRegistry.clear(ShoppingItemPriceImpl.class.getName());
113         EntityCacheUtil.clearCache(ShoppingItemPriceImpl.class.getName());
114         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
115         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
116     }
117 
118     public ShoppingItemPrice create(long itemPriceId) {
119         ShoppingItemPrice shoppingItemPrice = new ShoppingItemPriceImpl();
120 
121         shoppingItemPrice.setNew(true);
122         shoppingItemPrice.setPrimaryKey(itemPriceId);
123 
124         return shoppingItemPrice;
125     }
126 
127     public ShoppingItemPrice remove(Serializable primaryKey)
128         throws NoSuchModelException, SystemException {
129         return remove(((Long)primaryKey).longValue());
130     }
131 
132     public ShoppingItemPrice remove(long itemPriceId)
133         throws NoSuchItemPriceException, SystemException {
134         Session session = null;
135 
136         try {
137             session = openSession();
138 
139             ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
140                     new Long(itemPriceId));
141 
142             if (shoppingItemPrice == null) {
143                 if (_log.isWarnEnabled()) {
144                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemPriceId);
145                 }
146 
147                 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
148                     itemPriceId);
149             }
150 
151             return remove(shoppingItemPrice);
152         }
153         catch (NoSuchItemPriceException nsee) {
154             throw nsee;
155         }
156         catch (Exception e) {
157             throw processException(e);
158         }
159         finally {
160             closeSession(session);
161         }
162     }
163 
164     public ShoppingItemPrice remove(ShoppingItemPrice shoppingItemPrice)
165         throws SystemException {
166         for (ModelListener<ShoppingItemPrice> listener : listeners) {
167             listener.onBeforeRemove(shoppingItemPrice);
168         }
169 
170         shoppingItemPrice = removeImpl(shoppingItemPrice);
171 
172         for (ModelListener<ShoppingItemPrice> listener : listeners) {
173             listener.onAfterRemove(shoppingItemPrice);
174         }
175 
176         return shoppingItemPrice;
177     }
178 
179     protected ShoppingItemPrice removeImpl(ShoppingItemPrice shoppingItemPrice)
180         throws SystemException {
181         shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
182 
183         Session session = null;
184 
185         try {
186             session = openSession();
187 
188             if (shoppingItemPrice.isCachedModel() ||
189                     BatchSessionUtil.isEnabled()) {
190                 Object staleObject = session.get(ShoppingItemPriceImpl.class,
191                         shoppingItemPrice.getPrimaryKeyObj());
192 
193                 if (staleObject != null) {
194                     session.evict(staleObject);
195                 }
196             }
197 
198             session.delete(shoppingItemPrice);
199 
200             session.flush();
201         }
202         catch (Exception e) {
203             throw processException(e);
204         }
205         finally {
206             closeSession(session);
207         }
208 
209         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
210 
211         EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
212             ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
213 
214         return shoppingItemPrice;
215     }
216 
217     /**
218      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
219      */
220     public ShoppingItemPrice update(ShoppingItemPrice shoppingItemPrice)
221         throws SystemException {
222         if (_log.isWarnEnabled()) {
223             _log.warn(
224                 "Using the deprecated update(ShoppingItemPrice shoppingItemPrice) method. Use update(ShoppingItemPrice shoppingItemPrice, boolean merge) instead.");
225         }
226 
227         return update(shoppingItemPrice, false);
228     }
229 
230     public ShoppingItemPrice updateImpl(
231         com.liferay.portlet.shopping.model.ShoppingItemPrice shoppingItemPrice,
232         boolean merge) throws SystemException {
233         shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
234 
235         Session session = null;
236 
237         try {
238             session = openSession();
239 
240             BatchSessionUtil.update(session, shoppingItemPrice, merge);
241 
242             shoppingItemPrice.setNew(false);
243         }
244         catch (Exception e) {
245             throw processException(e);
246         }
247         finally {
248             closeSession(session);
249         }
250 
251         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
252 
253         EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
254             ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
255             shoppingItemPrice);
256 
257         return shoppingItemPrice;
258     }
259 
260     protected ShoppingItemPrice toUnwrappedModel(
261         ShoppingItemPrice shoppingItemPrice) {
262         if (shoppingItemPrice instanceof ShoppingItemPriceImpl) {
263             return shoppingItemPrice;
264         }
265 
266         ShoppingItemPriceImpl shoppingItemPriceImpl = new ShoppingItemPriceImpl();
267 
268         shoppingItemPriceImpl.setNew(shoppingItemPrice.isNew());
269         shoppingItemPriceImpl.setPrimaryKey(shoppingItemPrice.getPrimaryKey());
270 
271         shoppingItemPriceImpl.setItemPriceId(shoppingItemPrice.getItemPriceId());
272         shoppingItemPriceImpl.setItemId(shoppingItemPrice.getItemId());
273         shoppingItemPriceImpl.setMinQuantity(shoppingItemPrice.getMinQuantity());
274         shoppingItemPriceImpl.setMaxQuantity(shoppingItemPrice.getMaxQuantity());
275         shoppingItemPriceImpl.setPrice(shoppingItemPrice.getPrice());
276         shoppingItemPriceImpl.setDiscount(shoppingItemPrice.getDiscount());
277         shoppingItemPriceImpl.setTaxable(shoppingItemPrice.isTaxable());
278         shoppingItemPriceImpl.setShipping(shoppingItemPrice.getShipping());
279         shoppingItemPriceImpl.setUseShippingFormula(shoppingItemPrice.isUseShippingFormula());
280         shoppingItemPriceImpl.setStatus(shoppingItemPrice.getStatus());
281 
282         return shoppingItemPriceImpl;
283     }
284 
285     public ShoppingItemPrice findByPrimaryKey(Serializable primaryKey)
286         throws NoSuchModelException, SystemException {
287         return findByPrimaryKey(((Long)primaryKey).longValue());
288     }
289 
290     public ShoppingItemPrice findByPrimaryKey(long itemPriceId)
291         throws NoSuchItemPriceException, SystemException {
292         ShoppingItemPrice shoppingItemPrice = fetchByPrimaryKey(itemPriceId);
293 
294         if (shoppingItemPrice == null) {
295             if (_log.isWarnEnabled()) {
296                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemPriceId);
297             }
298 
299             throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
300                 itemPriceId);
301         }
302 
303         return shoppingItemPrice;
304     }
305 
306     public ShoppingItemPrice fetchByPrimaryKey(Serializable primaryKey)
307         throws SystemException {
308         return fetchByPrimaryKey(((Long)primaryKey).longValue());
309     }
310 
311     public ShoppingItemPrice fetchByPrimaryKey(long itemPriceId)
312         throws SystemException {
313         ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)EntityCacheUtil.getResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
314                 ShoppingItemPriceImpl.class, itemPriceId, this);
315 
316         if (shoppingItemPrice == null) {
317             Session session = null;
318 
319             try {
320                 session = openSession();
321 
322                 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
323                         new Long(itemPriceId));
324             }
325             catch (Exception e) {
326                 throw processException(e);
327             }
328             finally {
329                 if (shoppingItemPrice != null) {
330                     cacheResult(shoppingItemPrice);
331                 }
332 
333                 closeSession(session);
334             }
335         }
336 
337         return shoppingItemPrice;
338     }
339 
340     public List<ShoppingItemPrice> findByItemId(long itemId)
341         throws SystemException {
342         Object[] finderArgs = new Object[] { new Long(itemId) };
343 
344         List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ITEMID,
345                 finderArgs, this);
346 
347         if (list == null) {
348             Session session = null;
349 
350             try {
351                 session = openSession();
352 
353                 StringBundler query = new StringBundler(3);
354 
355                 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
356 
357                 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
358 
359                 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
360 
361                 String sql = query.toString();
362 
363                 Query q = session.createQuery(sql);
364 
365                 QueryPos qPos = QueryPos.getInstance(q);
366 
367                 qPos.add(itemId);
368 
369                 list = q.list();
370             }
371             catch (Exception e) {
372                 throw processException(e);
373             }
374             finally {
375                 if (list == null) {
376                     list = new ArrayList<ShoppingItemPrice>();
377                 }
378 
379                 cacheResult(list);
380 
381                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ITEMID,
382                     finderArgs, list);
383 
384                 closeSession(session);
385             }
386         }
387 
388         return list;
389     }
390 
391     public List<ShoppingItemPrice> findByItemId(long itemId, int start, int end)
392         throws SystemException {
393         return findByItemId(itemId, start, end, null);
394     }
395 
396     public List<ShoppingItemPrice> findByItemId(long itemId, int start,
397         int end, OrderByComparator orderByComparator) throws SystemException {
398         Object[] finderArgs = new Object[] {
399                 new Long(itemId),
400                 
401                 String.valueOf(start), String.valueOf(end),
402                 String.valueOf(orderByComparator)
403             };
404 
405         List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ITEMID,
406                 finderArgs, this);
407 
408         if (list == null) {
409             Session session = null;
410 
411             try {
412                 session = openSession();
413 
414                 StringBundler query = null;
415 
416                 if (orderByComparator != null) {
417                     query = new StringBundler(3 +
418                             (orderByComparator.getOrderByFields().length * 3));
419                 }
420                 else {
421                     query = new StringBundler(3);
422                 }
423 
424                 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
425 
426                 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
427 
428                 if (orderByComparator != null) {
429                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
430                         orderByComparator);
431                 }
432 
433                 else {
434                     query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
435                 }
436 
437                 String sql = query.toString();
438 
439                 Query q = session.createQuery(sql);
440 
441                 QueryPos qPos = QueryPos.getInstance(q);
442 
443                 qPos.add(itemId);
444 
445                 list = (List<ShoppingItemPrice>)QueryUtil.list(q, getDialect(),
446                         start, end);
447             }
448             catch (Exception e) {
449                 throw processException(e);
450             }
451             finally {
452                 if (list == null) {
453                     list = new ArrayList<ShoppingItemPrice>();
454                 }
455 
456                 cacheResult(list);
457 
458                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ITEMID,
459                     finderArgs, list);
460 
461                 closeSession(session);
462             }
463         }
464 
465         return list;
466     }
467 
468     public ShoppingItemPrice findByItemId_First(long itemId,
469         OrderByComparator orderByComparator)
470         throws NoSuchItemPriceException, SystemException {
471         List<ShoppingItemPrice> list = findByItemId(itemId, 0, 1,
472                 orderByComparator);
473 
474         if (list.isEmpty()) {
475             StringBundler msg = new StringBundler(4);
476 
477             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
478 
479             msg.append("itemId=");
480             msg.append(itemId);
481 
482             msg.append(StringPool.CLOSE_CURLY_BRACE);
483 
484             throw new NoSuchItemPriceException(msg.toString());
485         }
486         else {
487             return list.get(0);
488         }
489     }
490 
491     public ShoppingItemPrice findByItemId_Last(long itemId,
492         OrderByComparator orderByComparator)
493         throws NoSuchItemPriceException, SystemException {
494         int count = countByItemId(itemId);
495 
496         List<ShoppingItemPrice> list = findByItemId(itemId, count - 1, count,
497                 orderByComparator);
498 
499         if (list.isEmpty()) {
500             StringBundler msg = new StringBundler(4);
501 
502             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
503 
504             msg.append("itemId=");
505             msg.append(itemId);
506 
507             msg.append(StringPool.CLOSE_CURLY_BRACE);
508 
509             throw new NoSuchItemPriceException(msg.toString());
510         }
511         else {
512             return list.get(0);
513         }
514     }
515 
516     public ShoppingItemPrice[] findByItemId_PrevAndNext(long itemPriceId,
517         long itemId, OrderByComparator orderByComparator)
518         throws NoSuchItemPriceException, SystemException {
519         ShoppingItemPrice shoppingItemPrice = findByPrimaryKey(itemPriceId);
520 
521         int count = countByItemId(itemId);
522 
523         Session session = null;
524 
525         try {
526             session = openSession();
527 
528             StringBundler query = null;
529 
530             if (orderByComparator != null) {
531                 query = new StringBundler(3 +
532                         (orderByComparator.getOrderByFields().length * 3));
533             }
534             else {
535                 query = new StringBundler(3);
536             }
537 
538             query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
539 
540             query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
541 
542             if (orderByComparator != null) {
543                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
544                     orderByComparator);
545             }
546 
547             else {
548                 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
549             }
550 
551             String sql = query.toString();
552 
553             Query q = session.createQuery(sql);
554 
555             QueryPos qPos = QueryPos.getInstance(q);
556 
557             qPos.add(itemId);
558 
559             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
560                     orderByComparator, shoppingItemPrice);
561 
562             ShoppingItemPrice[] array = new ShoppingItemPriceImpl[3];
563 
564             array[0] = (ShoppingItemPrice)objArray[0];
565             array[1] = (ShoppingItemPrice)objArray[1];
566             array[2] = (ShoppingItemPrice)objArray[2];
567 
568             return array;
569         }
570         catch (Exception e) {
571             throw processException(e);
572         }
573         finally {
574             closeSession(session);
575         }
576     }
577 
578     public List<ShoppingItemPrice> findAll() throws SystemException {
579         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
580     }
581 
582     public List<ShoppingItemPrice> findAll(int start, int end)
583         throws SystemException {
584         return findAll(start, end, null);
585     }
586 
587     public List<ShoppingItemPrice> findAll(int start, int end,
588         OrderByComparator orderByComparator) throws SystemException {
589         Object[] finderArgs = new Object[] {
590                 String.valueOf(start), String.valueOf(end),
591                 String.valueOf(orderByComparator)
592             };
593 
594         List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
595                 finderArgs, this);
596 
597         if (list == null) {
598             Session session = null;
599 
600             try {
601                 session = openSession();
602 
603                 StringBundler query = null;
604                 String sql = null;
605 
606                 if (orderByComparator != null) {
607                     query = new StringBundler(2 +
608                             (orderByComparator.getOrderByFields().length * 3));
609 
610                     query.append(_SQL_SELECT_SHOPPINGITEMPRICE);
611 
612                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
613                         orderByComparator);
614 
615                     sql = query.toString();
616                 }
617 
618                 else {
619                     sql = _SQL_SELECT_SHOPPINGITEMPRICE.concat(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
620                 }
621 
622                 Query q = session.createQuery(sql);
623 
624                 if (orderByComparator == null) {
625                     list = (List<ShoppingItemPrice>)QueryUtil.list(q,
626                             getDialect(), start, end, false);
627 
628                     Collections.sort(list);
629                 }
630                 else {
631                     list = (List<ShoppingItemPrice>)QueryUtil.list(q,
632                             getDialect(), start, end);
633                 }
634             }
635             catch (Exception e) {
636                 throw processException(e);
637             }
638             finally {
639                 if (list == null) {
640                     list = new ArrayList<ShoppingItemPrice>();
641                 }
642 
643                 cacheResult(list);
644 
645                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
646 
647                 closeSession(session);
648             }
649         }
650 
651         return list;
652     }
653 
654     public void removeByItemId(long itemId) throws SystemException {
655         for (ShoppingItemPrice shoppingItemPrice : findByItemId(itemId)) {
656             remove(shoppingItemPrice);
657         }
658     }
659 
660     public void removeAll() throws SystemException {
661         for (ShoppingItemPrice shoppingItemPrice : findAll()) {
662             remove(shoppingItemPrice);
663         }
664     }
665 
666     public int countByItemId(long itemId) throws SystemException {
667         Object[] finderArgs = new Object[] { new Long(itemId) };
668 
669         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
670                 finderArgs, this);
671 
672         if (count == null) {
673             Session session = null;
674 
675             try {
676                 session = openSession();
677 
678                 StringBundler query = new StringBundler(2);
679 
680                 query.append(_SQL_COUNT_SHOPPINGITEMPRICE_WHERE);
681 
682                 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
683 
684                 String sql = query.toString();
685 
686                 Query q = session.createQuery(sql);
687 
688                 QueryPos qPos = QueryPos.getInstance(q);
689 
690                 qPos.add(itemId);
691 
692                 count = (Long)q.uniqueResult();
693             }
694             catch (Exception e) {
695                 throw processException(e);
696             }
697             finally {
698                 if (count == null) {
699                     count = Long.valueOf(0);
700                 }
701 
702                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
703                     finderArgs, count);
704 
705                 closeSession(session);
706             }
707         }
708 
709         return count.intValue();
710     }
711 
712     public int countAll() throws SystemException {
713         Object[] finderArgs = new Object[0];
714 
715         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
716                 finderArgs, this);
717 
718         if (count == null) {
719             Session session = null;
720 
721             try {
722                 session = openSession();
723 
724                 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMPRICE);
725 
726                 count = (Long)q.uniqueResult();
727             }
728             catch (Exception e) {
729                 throw processException(e);
730             }
731             finally {
732                 if (count == null) {
733                     count = Long.valueOf(0);
734                 }
735 
736                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
737                     count);
738 
739                 closeSession(session);
740             }
741         }
742 
743         return count.intValue();
744     }
745 
746     public void afterPropertiesSet() {
747         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
748                     com.liferay.portal.util.PropsUtil.get(
749                         "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemPrice")));
750 
751         if (listenerClassNames.length > 0) {
752             try {
753                 List<ModelListener<ShoppingItemPrice>> listenersList = new ArrayList<ModelListener<ShoppingItemPrice>>();
754 
755                 for (String listenerClassName : listenerClassNames) {
756                     listenersList.add((ModelListener<ShoppingItemPrice>)Class.forName(
757                             listenerClassName).newInstance());
758                 }
759 
760                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
761             }
762             catch (Exception e) {
763                 _log.error(e);
764             }
765         }
766     }
767 
768     @BeanReference(type = ShoppingCartPersistence.class)
769     protected ShoppingCartPersistence shoppingCartPersistence;
770     @BeanReference(type = ShoppingCategoryPersistence.class)
771     protected ShoppingCategoryPersistence shoppingCategoryPersistence;
772     @BeanReference(type = ShoppingCouponPersistence.class)
773     protected ShoppingCouponPersistence shoppingCouponPersistence;
774     @BeanReference(type = ShoppingItemPersistence.class)
775     protected ShoppingItemPersistence shoppingItemPersistence;
776     @BeanReference(type = ShoppingItemFieldPersistence.class)
777     protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
778     @BeanReference(type = ShoppingItemPricePersistence.class)
779     protected ShoppingItemPricePersistence shoppingItemPricePersistence;
780     @BeanReference(type = ShoppingOrderPersistence.class)
781     protected ShoppingOrderPersistence shoppingOrderPersistence;
782     @BeanReference(type = ShoppingOrderItemPersistence.class)
783     protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
784     @BeanReference(type = ResourcePersistence.class)
785     protected ResourcePersistence resourcePersistence;
786     @BeanReference(type = UserPersistence.class)
787     protected UserPersistence userPersistence;
788     private static final String _SQL_SELECT_SHOPPINGITEMPRICE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice";
789     private static final String _SQL_SELECT_SHOPPINGITEMPRICE_WHERE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice WHERE ";
790     private static final String _SQL_COUNT_SHOPPINGITEMPRICE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice";
791     private static final String _SQL_COUNT_SHOPPINGITEMPRICE_WHERE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice WHERE ";
792     private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemPrice.itemId = ?";
793     private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemPrice.";
794     private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemPrice exists with the primary key ";
795     private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemPrice exists with the key {";
796     private static Log _log = LogFactoryUtil.getLog(ShoppingItemPricePersistenceImpl.class);
797 }