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