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