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