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