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