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