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