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