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