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         shoppingItemField = toUnwrappedModel(shoppingItemField);
183 
184         Session session = null;
185 
186         try {
187             session = openSession();
188 
189             if (shoppingItemField.isCachedModel() ||
190                     BatchSessionUtil.isEnabled()) {
191                 Object staleObject = session.get(ShoppingItemFieldImpl.class,
192                         shoppingItemField.getPrimaryKeyObj());
193 
194                 if (staleObject != null) {
195                     session.evict(staleObject);
196                 }
197             }
198 
199             session.delete(shoppingItemField);
200 
201             session.flush();
202         }
203         catch (Exception e) {
204             throw processException(e);
205         }
206         finally {
207             closeSession(session);
208         }
209 
210         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
211 
212         EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
213             ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
214 
215         return shoppingItemField;
216     }
217 
218     /**
219      * @deprecated Use {@link #update(ShoppingItemField, boolean merge)}.
220      */
221     public ShoppingItemField update(ShoppingItemField shoppingItemField)
222         throws SystemException {
223         if (_log.isWarnEnabled()) {
224             _log.warn(
225                 "Using the deprecated update(ShoppingItemField shoppingItemField) method. Use update(ShoppingItemField shoppingItemField, boolean merge) instead.");
226         }
227 
228         return update(shoppingItemField, false);
229     }
230 
231     /**
232      * Add, update, or merge, the entity. This method also calls the model
233      * listeners to trigger the proper events associated with adding, deleting,
234      * or updating an entity.
235      *
236      * @param  shoppingItemField the entity to add, update, or merge
237      * @param  merge boolean value for whether to merge the entity. The default
238      *         value is false. Setting merge to true is more expensive and
239      *         should only be true when shoppingItemField is transient. See
240      *         LEP-5473 for a detailed discussion of this method.
241      * @return the entity that was added, updated, or merged
242      */
243     public ShoppingItemField update(ShoppingItemField shoppingItemField,
244         boolean merge) throws SystemException {
245         boolean isNew = shoppingItemField.isNew();
246 
247         for (ModelListener<ShoppingItemField> listener : listeners) {
248             if (isNew) {
249                 listener.onBeforeCreate(shoppingItemField);
250             }
251             else {
252                 listener.onBeforeUpdate(shoppingItemField);
253             }
254         }
255 
256         shoppingItemField = updateImpl(shoppingItemField, merge);
257 
258         for (ModelListener<ShoppingItemField> listener : listeners) {
259             if (isNew) {
260                 listener.onAfterCreate(shoppingItemField);
261             }
262             else {
263                 listener.onAfterUpdate(shoppingItemField);
264             }
265         }
266 
267         return shoppingItemField;
268     }
269 
270     public ShoppingItemField updateImpl(
271         com.liferay.portlet.shopping.model.ShoppingItemField shoppingItemField,
272         boolean merge) throws SystemException {
273         shoppingItemField = toUnwrappedModel(shoppingItemField);
274 
275         Session session = null;
276 
277         try {
278             session = openSession();
279 
280             BatchSessionUtil.update(session, shoppingItemField, merge);
281 
282             shoppingItemField.setNew(false);
283         }
284         catch (Exception e) {
285             throw processException(e);
286         }
287         finally {
288             closeSession(session);
289         }
290 
291         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
292 
293         EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
294             ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
295             shoppingItemField);
296 
297         return shoppingItemField;
298     }
299 
300     protected ShoppingItemField toUnwrappedModel(
301         ShoppingItemField shoppingItemField) {
302         if (shoppingItemField instanceof ShoppingItemFieldImpl) {
303             return shoppingItemField;
304         }
305 
306         ShoppingItemFieldImpl shoppingItemFieldImpl = new ShoppingItemFieldImpl();
307 
308         shoppingItemFieldImpl.setNew(shoppingItemField.isNew());
309         shoppingItemFieldImpl.setPrimaryKey(shoppingItemField.getPrimaryKey());
310 
311         shoppingItemFieldImpl.setItemFieldId(shoppingItemField.getItemFieldId());
312         shoppingItemFieldImpl.setItemId(shoppingItemField.getItemId());
313         shoppingItemFieldImpl.setName(shoppingItemField.getName());
314         shoppingItemFieldImpl.setValues(shoppingItemField.getValues());
315         shoppingItemFieldImpl.setDescription(shoppingItemField.getDescription());
316 
317         return shoppingItemFieldImpl;
318     }
319 
320     public ShoppingItemField findByPrimaryKey(long itemFieldId)
321         throws NoSuchItemFieldException, SystemException {
322         ShoppingItemField shoppingItemField = fetchByPrimaryKey(itemFieldId);
323 
324         if (shoppingItemField == null) {
325             if (_log.isWarnEnabled()) {
326                 _log.warn("No ShoppingItemField exists with the primary key " +
327                     itemFieldId);
328             }
329 
330             throw new NoSuchItemFieldException(
331                 "No ShoppingItemField exists with the primary key " +
332                 itemFieldId);
333         }
334 
335         return shoppingItemField;
336     }
337 
338     public ShoppingItemField fetchByPrimaryKey(long itemFieldId)
339         throws SystemException {
340         ShoppingItemField shoppingItemField = (ShoppingItemField)EntityCacheUtil.getResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
341                 ShoppingItemFieldImpl.class, itemFieldId, this);
342 
343         if (shoppingItemField == null) {
344             Session session = null;
345 
346             try {
347                 session = openSession();
348 
349                 shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
350                         new Long(itemFieldId));
351             }
352             catch (Exception e) {
353                 throw processException(e);
354             }
355             finally {
356                 if (shoppingItemField != null) {
357                     cacheResult(shoppingItemField);
358                 }
359 
360                 closeSession(session);
361             }
362         }
363 
364         return shoppingItemField;
365     }
366 
367     public List<ShoppingItemField> findByItemId(long itemId)
368         throws SystemException {
369         Object[] finderArgs = new Object[] { new Long(itemId) };
370 
371         List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ITEMID,
372                 finderArgs, this);
373 
374         if (list == null) {
375             Session session = null;
376 
377             try {
378                 session = openSession();
379 
380                 StringBuilder query = new StringBuilder();
381 
382                 query.append(
383                     "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField WHERE ");
384 
385                 query.append("shoppingItemField.itemId = ?");
386 
387                 query.append(" ");
388 
389                 query.append("ORDER BY ");
390 
391                 query.append("shoppingItemField.itemId ASC, ");
392                 query.append("shoppingItemField.name ASC");
393 
394                 Query q = session.createQuery(query.toString());
395 
396                 QueryPos qPos = QueryPos.getInstance(q);
397 
398                 qPos.add(itemId);
399 
400                 list = q.list();
401             }
402             catch (Exception e) {
403                 throw processException(e);
404             }
405             finally {
406                 if (list == null) {
407                     list = new ArrayList<ShoppingItemField>();
408                 }
409 
410                 cacheResult(list);
411 
412                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ITEMID,
413                     finderArgs, list);
414 
415                 closeSession(session);
416             }
417         }
418 
419         return list;
420     }
421 
422     public List<ShoppingItemField> findByItemId(long itemId, int start, int end)
423         throws SystemException {
424         return findByItemId(itemId, start, end, null);
425     }
426 
427     public List<ShoppingItemField> findByItemId(long itemId, int start,
428         int end, OrderByComparator obc) throws SystemException {
429         Object[] finderArgs = new Object[] {
430                 new Long(itemId),
431                 
432                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
433             };
434 
435         List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ITEMID,
436                 finderArgs, this);
437 
438         if (list == null) {
439             Session session = null;
440 
441             try {
442                 session = openSession();
443 
444                 StringBuilder query = new StringBuilder();
445 
446                 query.append(
447                     "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField WHERE ");
448 
449                 query.append("shoppingItemField.itemId = ?");
450 
451                 query.append(" ");
452 
453                 if (obc != null) {
454                     query.append("ORDER BY ");
455 
456                     String[] orderByFields = obc.getOrderByFields();
457 
458                     for (int i = 0; i < orderByFields.length; i++) {
459                         query.append("shoppingItemField.");
460                         query.append(orderByFields[i]);
461 
462                         if (obc.isAscending()) {
463                             query.append(" ASC");
464                         }
465                         else {
466                             query.append(" DESC");
467                         }
468 
469                         if ((i + 1) < orderByFields.length) {
470                             query.append(", ");
471                         }
472                     }
473                 }
474 
475                 else {
476                     query.append("ORDER BY ");
477 
478                     query.append("shoppingItemField.itemId ASC, ");
479                     query.append("shoppingItemField.name ASC");
480                 }
481 
482                 Query q = session.createQuery(query.toString());
483 
484                 QueryPos qPos = QueryPos.getInstance(q);
485 
486                 qPos.add(itemId);
487 
488                 list = (List<ShoppingItemField>)QueryUtil.list(q, getDialect(),
489                         start, end);
490             }
491             catch (Exception e) {
492                 throw processException(e);
493             }
494             finally {
495                 if (list == null) {
496                     list = new ArrayList<ShoppingItemField>();
497                 }
498 
499                 cacheResult(list);
500 
501                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ITEMID,
502                     finderArgs, list);
503 
504                 closeSession(session);
505             }
506         }
507 
508         return list;
509     }
510 
511     public ShoppingItemField findByItemId_First(long itemId,
512         OrderByComparator obc) throws NoSuchItemFieldException, SystemException {
513         List<ShoppingItemField> list = findByItemId(itemId, 0, 1, obc);
514 
515         if (list.isEmpty()) {
516             StringBuilder msg = new StringBuilder();
517 
518             msg.append("No ShoppingItemField exists with the key {");
519 
520             msg.append("itemId=" + itemId);
521 
522             msg.append(StringPool.CLOSE_CURLY_BRACE);
523 
524             throw new NoSuchItemFieldException(msg.toString());
525         }
526         else {
527             return list.get(0);
528         }
529     }
530 
531     public ShoppingItemField findByItemId_Last(long itemId,
532         OrderByComparator obc) throws NoSuchItemFieldException, SystemException {
533         int count = countByItemId(itemId);
534 
535         List<ShoppingItemField> list = findByItemId(itemId, count - 1, count,
536                 obc);
537 
538         if (list.isEmpty()) {
539             StringBuilder msg = new StringBuilder();
540 
541             msg.append("No ShoppingItemField exists with the key {");
542 
543             msg.append("itemId=" + itemId);
544 
545             msg.append(StringPool.CLOSE_CURLY_BRACE);
546 
547             throw new NoSuchItemFieldException(msg.toString());
548         }
549         else {
550             return list.get(0);
551         }
552     }
553 
554     public ShoppingItemField[] findByItemId_PrevAndNext(long itemFieldId,
555         long itemId, OrderByComparator obc)
556         throws NoSuchItemFieldException, SystemException {
557         ShoppingItemField shoppingItemField = findByPrimaryKey(itemFieldId);
558 
559         int count = countByItemId(itemId);
560 
561         Session session = null;
562 
563         try {
564             session = openSession();
565 
566             StringBuilder query = new StringBuilder();
567 
568             query.append(
569                 "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField WHERE ");
570 
571             query.append("shoppingItemField.itemId = ?");
572 
573             query.append(" ");
574 
575             if (obc != null) {
576                 query.append("ORDER BY ");
577 
578                 String[] orderByFields = obc.getOrderByFields();
579 
580                 for (int i = 0; i < orderByFields.length; i++) {
581                     query.append("shoppingItemField.");
582                     query.append(orderByFields[i]);
583 
584                     if (obc.isAscending()) {
585                         query.append(" ASC");
586                     }
587                     else {
588                         query.append(" DESC");
589                     }
590 
591                     if ((i + 1) < orderByFields.length) {
592                         query.append(", ");
593                     }
594                 }
595             }
596 
597             else {
598                 query.append("ORDER BY ");
599 
600                 query.append("shoppingItemField.itemId ASC, ");
601                 query.append("shoppingItemField.name ASC");
602             }
603 
604             Query q = session.createQuery(query.toString());
605 
606             QueryPos qPos = QueryPos.getInstance(q);
607 
608             qPos.add(itemId);
609 
610             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
611                     shoppingItemField);
612 
613             ShoppingItemField[] array = new ShoppingItemFieldImpl[3];
614 
615             array[0] = (ShoppingItemField)objArray[0];
616             array[1] = (ShoppingItemField)objArray[1];
617             array[2] = (ShoppingItemField)objArray[2];
618 
619             return array;
620         }
621         catch (Exception e) {
622             throw processException(e);
623         }
624         finally {
625             closeSession(session);
626         }
627     }
628 
629     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
630         throws SystemException {
631         Session session = null;
632 
633         try {
634             session = openSession();
635 
636             dynamicQuery.compile(session);
637 
638             return dynamicQuery.list();
639         }
640         catch (Exception e) {
641             throw processException(e);
642         }
643         finally {
644             closeSession(session);
645         }
646     }
647 
648     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
649         int start, int end) throws SystemException {
650         Session session = null;
651 
652         try {
653             session = openSession();
654 
655             dynamicQuery.setLimit(start, end);
656 
657             dynamicQuery.compile(session);
658 
659             return dynamicQuery.list();
660         }
661         catch (Exception e) {
662             throw processException(e);
663         }
664         finally {
665             closeSession(session);
666         }
667     }
668 
669     public List<ShoppingItemField> findAll() throws SystemException {
670         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
671     }
672 
673     public List<ShoppingItemField> findAll(int start, int end)
674         throws SystemException {
675         return findAll(start, end, null);
676     }
677 
678     public List<ShoppingItemField> findAll(int start, int end,
679         OrderByComparator obc) throws SystemException {
680         Object[] finderArgs = new Object[] {
681                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
682             };
683 
684         List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
685                 finderArgs, this);
686 
687         if (list == null) {
688             Session session = null;
689 
690             try {
691                 session = openSession();
692 
693                 StringBuilder query = new StringBuilder();
694 
695                 query.append(
696                     "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField ");
697 
698                 if (obc != null) {
699                     query.append("ORDER BY ");
700 
701                     String[] orderByFields = obc.getOrderByFields();
702 
703                     for (int i = 0; i < orderByFields.length; i++) {
704                         query.append("shoppingItemField.");
705                         query.append(orderByFields[i]);
706 
707                         if (obc.isAscending()) {
708                             query.append(" ASC");
709                         }
710                         else {
711                             query.append(" DESC");
712                         }
713 
714                         if ((i + 1) < orderByFields.length) {
715                             query.append(", ");
716                         }
717                     }
718                 }
719 
720                 else {
721                     query.append("ORDER BY ");
722 
723                     query.append("shoppingItemField.itemId ASC, ");
724                     query.append("shoppingItemField.name ASC");
725                 }
726 
727                 Query q = session.createQuery(query.toString());
728 
729                 if (obc == null) {
730                     list = (List<ShoppingItemField>)QueryUtil.list(q,
731                             getDialect(), start, end, false);
732 
733                     Collections.sort(list);
734                 }
735                 else {
736                     list = (List<ShoppingItemField>)QueryUtil.list(q,
737                             getDialect(), start, end);
738                 }
739             }
740             catch (Exception e) {
741                 throw processException(e);
742             }
743             finally {
744                 if (list == null) {
745                     list = new ArrayList<ShoppingItemField>();
746                 }
747 
748                 cacheResult(list);
749 
750                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
751 
752                 closeSession(session);
753             }
754         }
755 
756         return list;
757     }
758 
759     public void removeByItemId(long itemId) throws SystemException {
760         for (ShoppingItemField shoppingItemField : findByItemId(itemId)) {
761             remove(shoppingItemField);
762         }
763     }
764 
765     public void removeAll() throws SystemException {
766         for (ShoppingItemField shoppingItemField : findAll()) {
767             remove(shoppingItemField);
768         }
769     }
770 
771     public int countByItemId(long itemId) throws SystemException {
772         Object[] finderArgs = new Object[] { new Long(itemId) };
773 
774         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
775                 finderArgs, this);
776 
777         if (count == null) {
778             Session session = null;
779 
780             try {
781                 session = openSession();
782 
783                 StringBuilder query = new StringBuilder();
784 
785                 query.append("SELECT COUNT(shoppingItemField) ");
786                 query.append("FROM ShoppingItemField shoppingItemField WHERE ");
787 
788                 query.append("shoppingItemField.itemId = ?");
789 
790                 query.append(" ");
791 
792                 Query q = session.createQuery(query.toString());
793 
794                 QueryPos qPos = QueryPos.getInstance(q);
795 
796                 qPos.add(itemId);
797 
798                 count = (Long)q.uniqueResult();
799             }
800             catch (Exception e) {
801                 throw processException(e);
802             }
803             finally {
804                 if (count == null) {
805                     count = Long.valueOf(0);
806                 }
807 
808                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
809                     finderArgs, count);
810 
811                 closeSession(session);
812             }
813         }
814 
815         return count.intValue();
816     }
817 
818     public int countAll() throws SystemException {
819         Object[] finderArgs = new Object[0];
820 
821         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
822                 finderArgs, this);
823 
824         if (count == null) {
825             Session session = null;
826 
827             try {
828                 session = openSession();
829 
830                 Query q = session.createQuery(
831                         "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField");
832 
833                 count = (Long)q.uniqueResult();
834             }
835             catch (Exception e) {
836                 throw processException(e);
837             }
838             finally {
839                 if (count == null) {
840                     count = Long.valueOf(0);
841                 }
842 
843                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
844                     count);
845 
846                 closeSession(session);
847             }
848         }
849 
850         return count.intValue();
851     }
852 
853     public void afterPropertiesSet() {
854         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
855                     com.liferay.portal.util.PropsUtil.get(
856                         "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemField")));
857 
858         if (listenerClassNames.length > 0) {
859             try {
860                 List<ModelListener<ShoppingItemField>> listenersList = new ArrayList<ModelListener<ShoppingItemField>>();
861 
862                 for (String listenerClassName : listenerClassNames) {
863                     listenersList.add((ModelListener<ShoppingItemField>)Class.forName(
864                             listenerClassName).newInstance());
865                 }
866 
867                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
868             }
869             catch (Exception e) {
870                 _log.error(e);
871             }
872         }
873     }
874 
875     @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCartPersistence.impl")
876     protected com.liferay.portlet.shopping.service.persistence.ShoppingCartPersistence shoppingCartPersistence;
877     @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCategoryPersistence.impl")
878     protected com.liferay.portlet.shopping.service.persistence.ShoppingCategoryPersistence shoppingCategoryPersistence;
879     @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCouponPersistence.impl")
880     protected com.liferay.portlet.shopping.service.persistence.ShoppingCouponPersistence shoppingCouponPersistence;
881     @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingItemPersistence.impl")
882     protected com.liferay.portlet.shopping.service.persistence.ShoppingItemPersistence shoppingItemPersistence;
883     @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingItemFieldPersistence.impl")
884     protected com.liferay.portlet.shopping.service.persistence.ShoppingItemFieldPersistence shoppingItemFieldPersistence;
885     @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistence.impl")
886     protected com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistence shoppingItemPricePersistence;
887     @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingOrderPersistence.impl")
888     protected com.liferay.portlet.shopping.service.persistence.ShoppingOrderPersistence shoppingOrderPersistence;
889     @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingOrderItemPersistence.impl")
890     protected com.liferay.portlet.shopping.service.persistence.ShoppingOrderItemPersistence shoppingOrderItemPersistence;
891     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
892     protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
893     @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
894     protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
895     private static Log _log = LogFactoryUtil.getLog(ShoppingItemFieldPersistenceImpl.class);
896 }