1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.shopping.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
21  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderPath;
23  import com.liferay.portal.kernel.dao.orm.Query;
24  import com.liferay.portal.kernel.dao.orm.QueryPos;
25  import com.liferay.portal.kernel.dao.orm.QueryUtil;
26  import com.liferay.portal.kernel.dao.orm.Session;
27  import com.liferay.portal.kernel.exception.SystemException;
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     public ShoppingItemPrice remove(ShoppingItemPrice shoppingItemPrice)
167         throws SystemException {
168         for (ModelListener<ShoppingItemPrice> listener : listeners) {
169             listener.onBeforeRemove(shoppingItemPrice);
170         }
171 
172         shoppingItemPrice = removeImpl(shoppingItemPrice);
173 
174         for (ModelListener<ShoppingItemPrice> listener : listeners) {
175             listener.onAfterRemove(shoppingItemPrice);
176         }
177 
178         return shoppingItemPrice;
179     }
180 
181     protected ShoppingItemPrice removeImpl(ShoppingItemPrice shoppingItemPrice)
182         throws SystemException {
183         shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
184 
185         Session session = null;
186 
187         try {
188             session = openSession();
189 
190             if (shoppingItemPrice.isCachedModel() ||
191                     BatchSessionUtil.isEnabled()) {
192                 Object staleObject = session.get(ShoppingItemPriceImpl.class,
193                         shoppingItemPrice.getPrimaryKeyObj());
194 
195                 if (staleObject != null) {
196                     session.evict(staleObject);
197                 }
198             }
199 
200             session.delete(shoppingItemPrice);
201 
202             session.flush();
203         }
204         catch (Exception e) {
205             throw processException(e);
206         }
207         finally {
208             closeSession(session);
209         }
210 
211         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
212 
213         EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
214             ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
215 
216         return shoppingItemPrice;
217     }
218 
219     public ShoppingItemPrice updateImpl(
220         com.liferay.portlet.shopping.model.ShoppingItemPrice shoppingItemPrice,
221         boolean merge) throws SystemException {
222         shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
223 
224         Session session = null;
225 
226         try {
227             session = openSession();
228 
229             BatchSessionUtil.update(session, shoppingItemPrice, merge);
230 
231             shoppingItemPrice.setNew(false);
232         }
233         catch (Exception e) {
234             throw processException(e);
235         }
236         finally {
237             closeSession(session);
238         }
239 
240         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
241 
242         EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
243             ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
244             shoppingItemPrice);
245 
246         return shoppingItemPrice;
247     }
248 
249     protected ShoppingItemPrice toUnwrappedModel(
250         ShoppingItemPrice shoppingItemPrice) {
251         if (shoppingItemPrice instanceof ShoppingItemPriceImpl) {
252             return shoppingItemPrice;
253         }
254 
255         ShoppingItemPriceImpl shoppingItemPriceImpl = new ShoppingItemPriceImpl();
256 
257         shoppingItemPriceImpl.setNew(shoppingItemPrice.isNew());
258         shoppingItemPriceImpl.setPrimaryKey(shoppingItemPrice.getPrimaryKey());
259 
260         shoppingItemPriceImpl.setItemPriceId(shoppingItemPrice.getItemPriceId());
261         shoppingItemPriceImpl.setItemId(shoppingItemPrice.getItemId());
262         shoppingItemPriceImpl.setMinQuantity(shoppingItemPrice.getMinQuantity());
263         shoppingItemPriceImpl.setMaxQuantity(shoppingItemPrice.getMaxQuantity());
264         shoppingItemPriceImpl.setPrice(shoppingItemPrice.getPrice());
265         shoppingItemPriceImpl.setDiscount(shoppingItemPrice.getDiscount());
266         shoppingItemPriceImpl.setTaxable(shoppingItemPrice.isTaxable());
267         shoppingItemPriceImpl.setShipping(shoppingItemPrice.getShipping());
268         shoppingItemPriceImpl.setUseShippingFormula(shoppingItemPrice.isUseShippingFormula());
269         shoppingItemPriceImpl.setStatus(shoppingItemPrice.getStatus());
270 
271         return shoppingItemPriceImpl;
272     }
273 
274     public ShoppingItemPrice findByPrimaryKey(Serializable primaryKey)
275         throws NoSuchModelException, SystemException {
276         return findByPrimaryKey(((Long)primaryKey).longValue());
277     }
278 
279     public ShoppingItemPrice findByPrimaryKey(long itemPriceId)
280         throws NoSuchItemPriceException, SystemException {
281         ShoppingItemPrice shoppingItemPrice = fetchByPrimaryKey(itemPriceId);
282 
283         if (shoppingItemPrice == null) {
284             if (_log.isWarnEnabled()) {
285                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemPriceId);
286             }
287 
288             throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
289                 itemPriceId);
290         }
291 
292         return shoppingItemPrice;
293     }
294 
295     public ShoppingItemPrice fetchByPrimaryKey(Serializable primaryKey)
296         throws SystemException {
297         return fetchByPrimaryKey(((Long)primaryKey).longValue());
298     }
299 
300     public ShoppingItemPrice fetchByPrimaryKey(long itemPriceId)
301         throws SystemException {
302         ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)EntityCacheUtil.getResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
303                 ShoppingItemPriceImpl.class, itemPriceId, this);
304 
305         if (shoppingItemPrice == null) {
306             Session session = null;
307 
308             try {
309                 session = openSession();
310 
311                 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
312                         new Long(itemPriceId));
313             }
314             catch (Exception e) {
315                 throw processException(e);
316             }
317             finally {
318                 if (shoppingItemPrice != null) {
319                     cacheResult(shoppingItemPrice);
320                 }
321 
322                 closeSession(session);
323             }
324         }
325 
326         return shoppingItemPrice;
327     }
328 
329     public List<ShoppingItemPrice> findByItemId(long itemId)
330         throws SystemException {
331         return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
332     }
333 
334     public List<ShoppingItemPrice> findByItemId(long itemId, int start, int end)
335         throws SystemException {
336         return findByItemId(itemId, start, end, null);
337     }
338 
339     public List<ShoppingItemPrice> findByItemId(long itemId, int start,
340         int end, OrderByComparator orderByComparator) throws SystemException {
341         Object[] finderArgs = new Object[] {
342                 new Long(itemId),
343                 
344                 String.valueOf(start), String.valueOf(end),
345                 String.valueOf(orderByComparator)
346             };
347 
348         List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ITEMID,
349                 finderArgs, this);
350 
351         if (list == null) {
352             Session session = null;
353 
354             try {
355                 session = openSession();
356 
357                 StringBundler query = null;
358 
359                 if (orderByComparator != null) {
360                     query = new StringBundler(3 +
361                             (orderByComparator.getOrderByFields().length * 3));
362                 }
363                 else {
364                     query = new StringBundler(3);
365                 }
366 
367                 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
368 
369                 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
370 
371                 if (orderByComparator != null) {
372                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
373                         orderByComparator);
374                 }
375 
376                 else {
377                     query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
378                 }
379 
380                 String sql = query.toString();
381 
382                 Query q = session.createQuery(sql);
383 
384                 QueryPos qPos = QueryPos.getInstance(q);
385 
386                 qPos.add(itemId);
387 
388                 list = (List<ShoppingItemPrice>)QueryUtil.list(q, getDialect(),
389                         start, end);
390             }
391             catch (Exception e) {
392                 throw processException(e);
393             }
394             finally {
395                 if (list == null) {
396                     list = new ArrayList<ShoppingItemPrice>();
397                 }
398 
399                 cacheResult(list);
400 
401                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ITEMID,
402                     finderArgs, list);
403 
404                 closeSession(session);
405             }
406         }
407 
408         return list;
409     }
410 
411     public ShoppingItemPrice findByItemId_First(long itemId,
412         OrderByComparator orderByComparator)
413         throws NoSuchItemPriceException, SystemException {
414         List<ShoppingItemPrice> list = findByItemId(itemId, 0, 1,
415                 orderByComparator);
416 
417         if (list.isEmpty()) {
418             StringBundler msg = new StringBundler(4);
419 
420             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
421 
422             msg.append("itemId=");
423             msg.append(itemId);
424 
425             msg.append(StringPool.CLOSE_CURLY_BRACE);
426 
427             throw new NoSuchItemPriceException(msg.toString());
428         }
429         else {
430             return list.get(0);
431         }
432     }
433 
434     public ShoppingItemPrice findByItemId_Last(long itemId,
435         OrderByComparator orderByComparator)
436         throws NoSuchItemPriceException, SystemException {
437         int count = countByItemId(itemId);
438 
439         List<ShoppingItemPrice> list = findByItemId(itemId, count - 1, count,
440                 orderByComparator);
441 
442         if (list.isEmpty()) {
443             StringBundler msg = new StringBundler(4);
444 
445             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
446 
447             msg.append("itemId=");
448             msg.append(itemId);
449 
450             msg.append(StringPool.CLOSE_CURLY_BRACE);
451 
452             throw new NoSuchItemPriceException(msg.toString());
453         }
454         else {
455             return list.get(0);
456         }
457     }
458 
459     public ShoppingItemPrice[] findByItemId_PrevAndNext(long itemPriceId,
460         long itemId, OrderByComparator orderByComparator)
461         throws NoSuchItemPriceException, SystemException {
462         ShoppingItemPrice shoppingItemPrice = findByPrimaryKey(itemPriceId);
463 
464         Session session = null;
465 
466         try {
467             session = openSession();
468 
469             ShoppingItemPrice[] array = new ShoppingItemPriceImpl[3];
470 
471             array[0] = getByItemId_PrevAndNext(session, shoppingItemPrice,
472                     itemId, orderByComparator, true);
473 
474             array[1] = shoppingItemPrice;
475 
476             array[2] = getByItemId_PrevAndNext(session, shoppingItemPrice,
477                     itemId, orderByComparator, false);
478 
479             return array;
480         }
481         catch (Exception e) {
482             throw processException(e);
483         }
484         finally {
485             closeSession(session);
486         }
487     }
488 
489     protected ShoppingItemPrice getByItemId_PrevAndNext(Session session,
490         ShoppingItemPrice shoppingItemPrice, long itemId,
491         OrderByComparator orderByComparator, boolean previous) {
492         StringBundler query = null;
493 
494         if (orderByComparator != null) {
495             query = new StringBundler(6 +
496                     (orderByComparator.getOrderByFields().length * 6));
497         }
498         else {
499             query = new StringBundler(3);
500         }
501 
502         query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
503 
504         query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
505 
506         if (orderByComparator != null) {
507             String[] orderByFields = orderByComparator.getOrderByFields();
508 
509             if (orderByFields.length > 0) {
510                 query.append(WHERE_AND);
511             }
512 
513             for (int i = 0; i < orderByFields.length; i++) {
514                 query.append(_ORDER_BY_ENTITY_ALIAS);
515                 query.append(orderByFields[i]);
516 
517                 if ((i + 1) < orderByFields.length) {
518                     if (orderByComparator.isAscending() ^ previous) {
519                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
520                     }
521                     else {
522                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
523                     }
524                 }
525                 else {
526                     if (orderByComparator.isAscending() ^ previous) {
527                         query.append(WHERE_GREATER_THAN);
528                     }
529                     else {
530                         query.append(WHERE_LESSER_THAN);
531                     }
532                 }
533             }
534 
535             query.append(ORDER_BY_CLAUSE);
536 
537             for (int i = 0; i < orderByFields.length; i++) {
538                 query.append(_ORDER_BY_ENTITY_ALIAS);
539                 query.append(orderByFields[i]);
540 
541                 if ((i + 1) < orderByFields.length) {
542                     if (orderByComparator.isAscending() ^ previous) {
543                         query.append(ORDER_BY_ASC_HAS_NEXT);
544                     }
545                     else {
546                         query.append(ORDER_BY_DESC_HAS_NEXT);
547                     }
548                 }
549                 else {
550                     if (orderByComparator.isAscending() ^ previous) {
551                         query.append(ORDER_BY_ASC);
552                     }
553                     else {
554                         query.append(ORDER_BY_DESC);
555                     }
556                 }
557             }
558         }
559 
560         else {
561             query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
562         }
563 
564         String sql = query.toString();
565 
566         Query q = session.createQuery(sql);
567 
568         q.setFirstResult(0);
569         q.setMaxResults(2);
570 
571         QueryPos qPos = QueryPos.getInstance(q);
572 
573         qPos.add(itemId);
574 
575         if (orderByComparator != null) {
576             Object[] values = orderByComparator.getOrderByValues(shoppingItemPrice);
577 
578             for (Object value : values) {
579                 qPos.add(value);
580             }
581         }
582 
583         List<ShoppingItemPrice> list = q.list();
584 
585         if (list.size() == 2) {
586             return list.get(1);
587         }
588         else {
589             return null;
590         }
591     }
592 
593     public List<ShoppingItemPrice> findAll() throws SystemException {
594         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
595     }
596 
597     public List<ShoppingItemPrice> findAll(int start, int end)
598         throws SystemException {
599         return findAll(start, end, null);
600     }
601 
602     public List<ShoppingItemPrice> findAll(int start, int end,
603         OrderByComparator orderByComparator) throws SystemException {
604         Object[] finderArgs = new Object[] {
605                 String.valueOf(start), String.valueOf(end),
606                 String.valueOf(orderByComparator)
607             };
608 
609         List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
610                 finderArgs, this);
611 
612         if (list == null) {
613             Session session = null;
614 
615             try {
616                 session = openSession();
617 
618                 StringBundler query = null;
619                 String sql = null;
620 
621                 if (orderByComparator != null) {
622                     query = new StringBundler(2 +
623                             (orderByComparator.getOrderByFields().length * 3));
624 
625                     query.append(_SQL_SELECT_SHOPPINGITEMPRICE);
626 
627                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
628                         orderByComparator);
629 
630                     sql = query.toString();
631                 }
632 
633                 else {
634                     sql = _SQL_SELECT_SHOPPINGITEMPRICE.concat(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
635                 }
636 
637                 Query q = session.createQuery(sql);
638 
639                 if (orderByComparator == null) {
640                     list = (List<ShoppingItemPrice>)QueryUtil.list(q,
641                             getDialect(), start, end, false);
642 
643                     Collections.sort(list);
644                 }
645                 else {
646                     list = (List<ShoppingItemPrice>)QueryUtil.list(q,
647                             getDialect(), start, end);
648                 }
649             }
650             catch (Exception e) {
651                 throw processException(e);
652             }
653             finally {
654                 if (list == null) {
655                     list = new ArrayList<ShoppingItemPrice>();
656                 }
657 
658                 cacheResult(list);
659 
660                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
661 
662                 closeSession(session);
663             }
664         }
665 
666         return list;
667     }
668 
669     public void removeByItemId(long itemId) throws SystemException {
670         for (ShoppingItemPrice shoppingItemPrice : findByItemId(itemId)) {
671             remove(shoppingItemPrice);
672         }
673     }
674 
675     public void removeAll() throws SystemException {
676         for (ShoppingItemPrice shoppingItemPrice : findAll()) {
677             remove(shoppingItemPrice);
678         }
679     }
680 
681     public int countByItemId(long itemId) throws SystemException {
682         Object[] finderArgs = new Object[] { new Long(itemId) };
683 
684         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
685                 finderArgs, this);
686 
687         if (count == null) {
688             Session session = null;
689 
690             try {
691                 session = openSession();
692 
693                 StringBundler query = new StringBundler(2);
694 
695                 query.append(_SQL_COUNT_SHOPPINGITEMPRICE_WHERE);
696 
697                 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
698 
699                 String sql = query.toString();
700 
701                 Query q = session.createQuery(sql);
702 
703                 QueryPos qPos = QueryPos.getInstance(q);
704 
705                 qPos.add(itemId);
706 
707                 count = (Long)q.uniqueResult();
708             }
709             catch (Exception e) {
710                 throw processException(e);
711             }
712             finally {
713                 if (count == null) {
714                     count = Long.valueOf(0);
715                 }
716 
717                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
718                     finderArgs, count);
719 
720                 closeSession(session);
721             }
722         }
723 
724         return count.intValue();
725     }
726 
727     public int countAll() throws SystemException {
728         Object[] finderArgs = new Object[0];
729 
730         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
731                 finderArgs, this);
732 
733         if (count == null) {
734             Session session = null;
735 
736             try {
737                 session = openSession();
738 
739                 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMPRICE);
740 
741                 count = (Long)q.uniqueResult();
742             }
743             catch (Exception e) {
744                 throw processException(e);
745             }
746             finally {
747                 if (count == null) {
748                     count = Long.valueOf(0);
749                 }
750 
751                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
752                     count);
753 
754                 closeSession(session);
755             }
756         }
757 
758         return count.intValue();
759     }
760 
761     public void afterPropertiesSet() {
762         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
763                     com.liferay.portal.util.PropsUtil.get(
764                         "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemPrice")));
765 
766         if (listenerClassNames.length > 0) {
767             try {
768                 List<ModelListener<ShoppingItemPrice>> listenersList = new ArrayList<ModelListener<ShoppingItemPrice>>();
769 
770                 for (String listenerClassName : listenerClassNames) {
771                     listenersList.add((ModelListener<ShoppingItemPrice>)InstanceFactory.newInstance(
772                             listenerClassName));
773                 }
774 
775                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
776             }
777             catch (Exception e) {
778                 _log.error(e);
779             }
780         }
781     }
782 
783     @BeanReference(type = ShoppingCartPersistence.class)
784     protected ShoppingCartPersistence shoppingCartPersistence;
785     @BeanReference(type = ShoppingCategoryPersistence.class)
786     protected ShoppingCategoryPersistence shoppingCategoryPersistence;
787     @BeanReference(type = ShoppingCouponPersistence.class)
788     protected ShoppingCouponPersistence shoppingCouponPersistence;
789     @BeanReference(type = ShoppingItemPersistence.class)
790     protected ShoppingItemPersistence shoppingItemPersistence;
791     @BeanReference(type = ShoppingItemFieldPersistence.class)
792     protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
793     @BeanReference(type = ShoppingItemPricePersistence.class)
794     protected ShoppingItemPricePersistence shoppingItemPricePersistence;
795     @BeanReference(type = ShoppingOrderPersistence.class)
796     protected ShoppingOrderPersistence shoppingOrderPersistence;
797     @BeanReference(type = ShoppingOrderItemPersistence.class)
798     protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
799     @BeanReference(type = ResourcePersistence.class)
800     protected ResourcePersistence resourcePersistence;
801     @BeanReference(type = UserPersistence.class)
802     protected UserPersistence userPersistence;
803     private static final String _SQL_SELECT_SHOPPINGITEMPRICE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice";
804     private static final String _SQL_SELECT_SHOPPINGITEMPRICE_WHERE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice WHERE ";
805     private static final String _SQL_COUNT_SHOPPINGITEMPRICE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice";
806     private static final String _SQL_COUNT_SHOPPINGITEMPRICE_WHERE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice WHERE ";
807     private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemPrice.itemId = ?";
808     private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemPrice.";
809     private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemPrice exists with the primary key ";
810     private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemPrice exists with the key {";
811     private static Log _log = LogFactoryUtil.getLog(ShoppingItemPricePersistenceImpl.class);
812 }