001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.shopping.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.ResourcePersistence;
039    import com.liferay.portal.service.persistence.UserPersistence;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.shopping.NoSuchItemFieldException;
043    import com.liferay.portlet.shopping.model.ShoppingItemField;
044    import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldImpl;
045    import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    
053    /**
054     * The persistence implementation for the shopping item field service.
055     *
056     * <p>
057     * Never modify or reference this class directly. Always use {@link ShoppingItemFieldUtil} to access the shopping item field persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
058     * </p>
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see ShoppingItemFieldPersistence
066     * @see ShoppingItemFieldUtil
067     * @generated
068     */
069    public class ShoppingItemFieldPersistenceImpl extends BasePersistenceImpl<ShoppingItemField>
070            implements ShoppingItemFieldPersistence {
071            public static final String FINDER_CLASS_NAME_ENTITY = ShoppingItemFieldImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073                    ".List";
074            public static final FinderPath FINDER_PATH_FIND_BY_ITEMID = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
075                            ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
076                            FINDER_CLASS_NAME_LIST, "findByItemId",
077                            new String[] {
078                                    Long.class.getName(),
079                                    
080                            "java.lang.Integer", "java.lang.Integer",
081                                    "com.liferay.portal.kernel.util.OrderByComparator"
082                            });
083            public static final FinderPath FINDER_PATH_COUNT_BY_ITEMID = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
084                            ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
085                            FINDER_CLASS_NAME_LIST, "countByItemId",
086                            new String[] { Long.class.getName() });
087            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
088                            ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
089                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
091                            ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
092                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
093    
094            /**
095             * Caches the shopping item field in the entity cache if it is enabled.
096             *
097             * @param shoppingItemField the shopping item field to cache
098             */
099            public void cacheResult(ShoppingItemField shoppingItemField) {
100                    EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
101                            ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
102                            shoppingItemField);
103            }
104    
105            /**
106             * Caches the shopping item fields in the entity cache if it is enabled.
107             *
108             * @param shoppingItemFields the shopping item fields to cache
109             */
110            public void cacheResult(List<ShoppingItemField> shoppingItemFields) {
111                    for (ShoppingItemField shoppingItemField : shoppingItemFields) {
112                            if (EntityCacheUtil.getResult(
113                                                    ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
114                                                    ShoppingItemFieldImpl.class,
115                                                    shoppingItemField.getPrimaryKey(), this) == null) {
116                                    cacheResult(shoppingItemField);
117                            }
118                    }
119            }
120    
121            /**
122             * Clears the cache for all shopping item fields.
123             *
124             * <p>
125             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
126             * </p>
127             */
128            public void clearCache() {
129                    CacheRegistryUtil.clear(ShoppingItemFieldImpl.class.getName());
130                    EntityCacheUtil.clearCache(ShoppingItemFieldImpl.class.getName());
131                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
132                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
133            }
134    
135            /**
136             * Clears the cache for the shopping item field.
137             *
138             * <p>
139             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
140             * </p>
141             */
142            public void clearCache(ShoppingItemField shoppingItemField) {
143                    EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
144                            ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
145            }
146    
147            /**
148             * Creates a new shopping item field with the primary key. Does not add the shopping item field to the database.
149             *
150             * @param itemFieldId the primary key for the new shopping item field
151             * @return the new shopping item field
152             */
153            public ShoppingItemField create(long itemFieldId) {
154                    ShoppingItemField shoppingItemField = new ShoppingItemFieldImpl();
155    
156                    shoppingItemField.setNew(true);
157                    shoppingItemField.setPrimaryKey(itemFieldId);
158    
159                    return shoppingItemField;
160            }
161    
162            /**
163             * Removes the shopping item field with the primary key from the database. Also notifies the appropriate model listeners.
164             *
165             * @param primaryKey the primary key of the shopping item field to remove
166             * @return the shopping item field that was removed
167             * @throws com.liferay.portal.NoSuchModelException if a shopping item field with the primary key could not be found
168             * @throws SystemException if a system exception occurred
169             */
170            public ShoppingItemField remove(Serializable primaryKey)
171                    throws NoSuchModelException, SystemException {
172                    return remove(((Long)primaryKey).longValue());
173            }
174    
175            /**
176             * Removes the shopping item field with the primary key from the database. Also notifies the appropriate model listeners.
177             *
178             * @param itemFieldId the primary key of the shopping item field to remove
179             * @return the shopping item field that was removed
180             * @throws com.liferay.portlet.shopping.NoSuchItemFieldException if a shopping item field with the primary key could not be found
181             * @throws SystemException if a system exception occurred
182             */
183            public ShoppingItemField remove(long itemFieldId)
184                    throws NoSuchItemFieldException, SystemException {
185                    Session session = null;
186    
187                    try {
188                            session = openSession();
189    
190                            ShoppingItemField shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
191                                            new Long(itemFieldId));
192    
193                            if (shoppingItemField == null) {
194                                    if (_log.isWarnEnabled()) {
195                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
196                                    }
197    
198                                    throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
199                                            itemFieldId);
200                            }
201    
202                            return remove(shoppingItemField);
203                    }
204                    catch (NoSuchItemFieldException nsee) {
205                            throw nsee;
206                    }
207                    catch (Exception e) {
208                            throw processException(e);
209                    }
210                    finally {
211                            closeSession(session);
212                    }
213            }
214    
215            protected ShoppingItemField removeImpl(ShoppingItemField shoppingItemField)
216                    throws SystemException {
217                    shoppingItemField = toUnwrappedModel(shoppingItemField);
218    
219                    Session session = null;
220    
221                    try {
222                            session = openSession();
223    
224                            if (shoppingItemField.isCachedModel() ||
225                                            BatchSessionUtil.isEnabled()) {
226                                    Object staleObject = session.get(ShoppingItemFieldImpl.class,
227                                                    shoppingItemField.getPrimaryKeyObj());
228    
229                                    if (staleObject != null) {
230                                            session.evict(staleObject);
231                                    }
232                            }
233    
234                            session.delete(shoppingItemField);
235    
236                            session.flush();
237                    }
238                    catch (Exception e) {
239                            throw processException(e);
240                    }
241                    finally {
242                            closeSession(session);
243                    }
244    
245                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
246    
247                    EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
248                            ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
249    
250                    return shoppingItemField;
251            }
252    
253            public ShoppingItemField updateImpl(
254                    com.liferay.portlet.shopping.model.ShoppingItemField shoppingItemField,
255                    boolean merge) throws SystemException {
256                    shoppingItemField = toUnwrappedModel(shoppingItemField);
257    
258                    Session session = null;
259    
260                    try {
261                            session = openSession();
262    
263                            BatchSessionUtil.update(session, shoppingItemField, merge);
264    
265                            shoppingItemField.setNew(false);
266                    }
267                    catch (Exception e) {
268                            throw processException(e);
269                    }
270                    finally {
271                            closeSession(session);
272                    }
273    
274                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
275    
276                    EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
277                            ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
278                            shoppingItemField);
279    
280                    return shoppingItemField;
281            }
282    
283            protected ShoppingItemField toUnwrappedModel(
284                    ShoppingItemField shoppingItemField) {
285                    if (shoppingItemField instanceof ShoppingItemFieldImpl) {
286                            return shoppingItemField;
287                    }
288    
289                    ShoppingItemFieldImpl shoppingItemFieldImpl = new ShoppingItemFieldImpl();
290    
291                    shoppingItemFieldImpl.setNew(shoppingItemField.isNew());
292                    shoppingItemFieldImpl.setPrimaryKey(shoppingItemField.getPrimaryKey());
293    
294                    shoppingItemFieldImpl.setItemFieldId(shoppingItemField.getItemFieldId());
295                    shoppingItemFieldImpl.setItemId(shoppingItemField.getItemId());
296                    shoppingItemFieldImpl.setName(shoppingItemField.getName());
297                    shoppingItemFieldImpl.setValues(shoppingItemField.getValues());
298                    shoppingItemFieldImpl.setDescription(shoppingItemField.getDescription());
299    
300                    return shoppingItemFieldImpl;
301            }
302    
303            /**
304             * Finds the shopping item field with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
305             *
306             * @param primaryKey the primary key of the shopping item field to find
307             * @return the shopping item field
308             * @throws com.liferay.portal.NoSuchModelException if a shopping item field with the primary key could not be found
309             * @throws SystemException if a system exception occurred
310             */
311            public ShoppingItemField findByPrimaryKey(Serializable primaryKey)
312                    throws NoSuchModelException, SystemException {
313                    return findByPrimaryKey(((Long)primaryKey).longValue());
314            }
315    
316            /**
317             * Finds the shopping item field with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchItemFieldException} if it could not be found.
318             *
319             * @param itemFieldId the primary key of the shopping item field to find
320             * @return the shopping item field
321             * @throws com.liferay.portlet.shopping.NoSuchItemFieldException if a shopping item field with the primary key could not be found
322             * @throws SystemException if a system exception occurred
323             */
324            public ShoppingItemField findByPrimaryKey(long itemFieldId)
325                    throws NoSuchItemFieldException, SystemException {
326                    ShoppingItemField shoppingItemField = fetchByPrimaryKey(itemFieldId);
327    
328                    if (shoppingItemField == null) {
329                            if (_log.isWarnEnabled()) {
330                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
331                            }
332    
333                            throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
334                                    itemFieldId);
335                    }
336    
337                    return shoppingItemField;
338            }
339    
340            /**
341             * Finds the shopping item field with the primary key or returns <code>null</code> if it could not be found.
342             *
343             * @param primaryKey the primary key of the shopping item field to find
344             * @return the shopping item field, or <code>null</code> if a shopping item field with the primary key could not be found
345             * @throws SystemException if a system exception occurred
346             */
347            public ShoppingItemField fetchByPrimaryKey(Serializable primaryKey)
348                    throws SystemException {
349                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
350            }
351    
352            /**
353             * Finds the shopping item field with the primary key or returns <code>null</code> if it could not be found.
354             *
355             * @param itemFieldId the primary key of the shopping item field to find
356             * @return the shopping item field, or <code>null</code> if a shopping item field with the primary key could not be found
357             * @throws SystemException if a system exception occurred
358             */
359            public ShoppingItemField fetchByPrimaryKey(long itemFieldId)
360                    throws SystemException {
361                    ShoppingItemField shoppingItemField = (ShoppingItemField)EntityCacheUtil.getResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
362                                    ShoppingItemFieldImpl.class, itemFieldId, this);
363    
364                    if (shoppingItemField == null) {
365                            Session session = null;
366    
367                            try {
368                                    session = openSession();
369    
370                                    shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
371                                                    new Long(itemFieldId));
372                            }
373                            catch (Exception e) {
374                                    throw processException(e);
375                            }
376                            finally {
377                                    if (shoppingItemField != null) {
378                                            cacheResult(shoppingItemField);
379                                    }
380    
381                                    closeSession(session);
382                            }
383                    }
384    
385                    return shoppingItemField;
386            }
387    
388            /**
389             * Finds all the shopping item fields where itemId = &#63;.
390             *
391             * @param itemId the item id to search with
392             * @return the matching shopping item fields
393             * @throws SystemException if a system exception occurred
394             */
395            public List<ShoppingItemField> findByItemId(long itemId)
396                    throws SystemException {
397                    return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
398            }
399    
400            /**
401             * Finds a range of all the shopping item fields where itemId = &#63;.
402             *
403             * <p>
404             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
405             * </p>
406             *
407             * @param itemId the item id to search with
408             * @param start the lower bound of the range of shopping item fields to return
409             * @param end the upper bound of the range of shopping item fields to return (not inclusive)
410             * @return the range of matching shopping item fields
411             * @throws SystemException if a system exception occurred
412             */
413            public List<ShoppingItemField> findByItemId(long itemId, int start, int end)
414                    throws SystemException {
415                    return findByItemId(itemId, start, end, null);
416            }
417    
418            /**
419             * Finds an ordered range of all the shopping item fields where itemId = &#63;.
420             *
421             * <p>
422             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
423             * </p>
424             *
425             * @param itemId the item id to search with
426             * @param start the lower bound of the range of shopping item fields to return
427             * @param end the upper bound of the range of shopping item fields to return (not inclusive)
428             * @param orderByComparator the comparator to order the results by
429             * @return the ordered range of matching shopping item fields
430             * @throws SystemException if a system exception occurred
431             */
432            public List<ShoppingItemField> findByItemId(long itemId, int start,
433                    int end, OrderByComparator orderByComparator) throws SystemException {
434                    Object[] finderArgs = new Object[] {
435                                    itemId,
436                                    
437                                    String.valueOf(start), String.valueOf(end),
438                                    String.valueOf(orderByComparator)
439                            };
440    
441                    List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ITEMID,
442                                    finderArgs, this);
443    
444                    if (list == null) {
445                            Session session = null;
446    
447                            try {
448                                    session = openSession();
449    
450                                    StringBundler query = null;
451    
452                                    if (orderByComparator != null) {
453                                            query = new StringBundler(3 +
454                                                            (orderByComparator.getOrderByFields().length * 3));
455                                    }
456                                    else {
457                                            query = new StringBundler(3);
458                                    }
459    
460                                    query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
461    
462                                    query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
463    
464                                    if (orderByComparator != null) {
465                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
466                                                    orderByComparator);
467                                    }
468    
469                                    else {
470                                            query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
471                                    }
472    
473                                    String sql = query.toString();
474    
475                                    Query q = session.createQuery(sql);
476    
477                                    QueryPos qPos = QueryPos.getInstance(q);
478    
479                                    qPos.add(itemId);
480    
481                                    list = (List<ShoppingItemField>)QueryUtil.list(q, getDialect(),
482                                                    start, end);
483                            }
484                            catch (Exception e) {
485                                    throw processException(e);
486                            }
487                            finally {
488                                    if (list == null) {
489                                            list = new ArrayList<ShoppingItemField>();
490                                    }
491    
492                                    cacheResult(list);
493    
494                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ITEMID,
495                                            finderArgs, list);
496    
497                                    closeSession(session);
498                            }
499                    }
500    
501                    return list;
502            }
503    
504            /**
505             * Finds the first shopping item field in the ordered set where itemId = &#63;.
506             *
507             * <p>
508             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
509             * </p>
510             *
511             * @param itemId the item id to search with
512             * @param orderByComparator the comparator to order the set by
513             * @return the first matching shopping item field
514             * @throws com.liferay.portlet.shopping.NoSuchItemFieldException if a matching shopping item field could not be found
515             * @throws SystemException if a system exception occurred
516             */
517            public ShoppingItemField findByItemId_First(long itemId,
518                    OrderByComparator orderByComparator)
519                    throws NoSuchItemFieldException, SystemException {
520                    List<ShoppingItemField> list = findByItemId(itemId, 0, 1,
521                                    orderByComparator);
522    
523                    if (list.isEmpty()) {
524                            StringBundler msg = new StringBundler(4);
525    
526                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
527    
528                            msg.append("itemId=");
529                            msg.append(itemId);
530    
531                            msg.append(StringPool.CLOSE_CURLY_BRACE);
532    
533                            throw new NoSuchItemFieldException(msg.toString());
534                    }
535                    else {
536                            return list.get(0);
537                    }
538            }
539    
540            /**
541             * Finds the last shopping item field in the ordered set where itemId = &#63;.
542             *
543             * <p>
544             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
545             * </p>
546             *
547             * @param itemId the item id to search with
548             * @param orderByComparator the comparator to order the set by
549             * @return the last matching shopping item field
550             * @throws com.liferay.portlet.shopping.NoSuchItemFieldException if a matching shopping item field could not be found
551             * @throws SystemException if a system exception occurred
552             */
553            public ShoppingItemField findByItemId_Last(long itemId,
554                    OrderByComparator orderByComparator)
555                    throws NoSuchItemFieldException, SystemException {
556                    int count = countByItemId(itemId);
557    
558                    List<ShoppingItemField> list = findByItemId(itemId, count - 1, count,
559                                    orderByComparator);
560    
561                    if (list.isEmpty()) {
562                            StringBundler msg = new StringBundler(4);
563    
564                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
565    
566                            msg.append("itemId=");
567                            msg.append(itemId);
568    
569                            msg.append(StringPool.CLOSE_CURLY_BRACE);
570    
571                            throw new NoSuchItemFieldException(msg.toString());
572                    }
573                    else {
574                            return list.get(0);
575                    }
576            }
577    
578            /**
579             * Finds the shopping item fields before and after the current shopping item field in the ordered set where itemId = &#63;.
580             *
581             * <p>
582             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
583             * </p>
584             *
585             * @param itemFieldId the primary key of the current shopping item field
586             * @param itemId the item id to search with
587             * @param orderByComparator the comparator to order the set by
588             * @return the previous, current, and next shopping item field
589             * @throws com.liferay.portlet.shopping.NoSuchItemFieldException if a shopping item field with the primary key could not be found
590             * @throws SystemException if a system exception occurred
591             */
592            public ShoppingItemField[] findByItemId_PrevAndNext(long itemFieldId,
593                    long itemId, OrderByComparator orderByComparator)
594                    throws NoSuchItemFieldException, SystemException {
595                    ShoppingItemField shoppingItemField = findByPrimaryKey(itemFieldId);
596    
597                    Session session = null;
598    
599                    try {
600                            session = openSession();
601    
602                            ShoppingItemField[] array = new ShoppingItemFieldImpl[3];
603    
604                            array[0] = getByItemId_PrevAndNext(session, shoppingItemField,
605                                            itemId, orderByComparator, true);
606    
607                            array[1] = shoppingItemField;
608    
609                            array[2] = getByItemId_PrevAndNext(session, shoppingItemField,
610                                            itemId, orderByComparator, false);
611    
612                            return array;
613                    }
614                    catch (Exception e) {
615                            throw processException(e);
616                    }
617                    finally {
618                            closeSession(session);
619                    }
620            }
621    
622            protected ShoppingItemField getByItemId_PrevAndNext(Session session,
623                    ShoppingItemField shoppingItemField, long itemId,
624                    OrderByComparator orderByComparator, boolean previous) {
625                    StringBundler query = null;
626    
627                    if (orderByComparator != null) {
628                            query = new StringBundler(6 +
629                                            (orderByComparator.getOrderByFields().length * 6));
630                    }
631                    else {
632                            query = new StringBundler(3);
633                    }
634    
635                    query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
636    
637                    query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
638    
639                    if (orderByComparator != null) {
640                            String[] orderByFields = orderByComparator.getOrderByFields();
641    
642                            if (orderByFields.length > 0) {
643                                    query.append(WHERE_AND);
644                            }
645    
646                            for (int i = 0; i < orderByFields.length; i++) {
647                                    query.append(_ORDER_BY_ENTITY_ALIAS);
648                                    query.append(orderByFields[i]);
649    
650                                    if ((i + 1) < orderByFields.length) {
651                                            if (orderByComparator.isAscending() ^ previous) {
652                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
653                                            }
654                                            else {
655                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
656                                            }
657                                    }
658                                    else {
659                                            if (orderByComparator.isAscending() ^ previous) {
660                                                    query.append(WHERE_GREATER_THAN);
661                                            }
662                                            else {
663                                                    query.append(WHERE_LESSER_THAN);
664                                            }
665                                    }
666                            }
667    
668                            query.append(ORDER_BY_CLAUSE);
669    
670                            for (int i = 0; i < orderByFields.length; i++) {
671                                    query.append(_ORDER_BY_ENTITY_ALIAS);
672                                    query.append(orderByFields[i]);
673    
674                                    if ((i + 1) < orderByFields.length) {
675                                            if (orderByComparator.isAscending() ^ previous) {
676                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
677                                            }
678                                            else {
679                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
680                                            }
681                                    }
682                                    else {
683                                            if (orderByComparator.isAscending() ^ previous) {
684                                                    query.append(ORDER_BY_ASC);
685                                            }
686                                            else {
687                                                    query.append(ORDER_BY_DESC);
688                                            }
689                                    }
690                            }
691                    }
692    
693                    else {
694                            query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
695                    }
696    
697                    String sql = query.toString();
698    
699                    Query q = session.createQuery(sql);
700    
701                    q.setFirstResult(0);
702                    q.setMaxResults(2);
703    
704                    QueryPos qPos = QueryPos.getInstance(q);
705    
706                    qPos.add(itemId);
707    
708                    if (orderByComparator != null) {
709                            Object[] values = orderByComparator.getOrderByValues(shoppingItemField);
710    
711                            for (Object value : values) {
712                                    qPos.add(value);
713                            }
714                    }
715    
716                    List<ShoppingItemField> list = q.list();
717    
718                    if (list.size() == 2) {
719                            return list.get(1);
720                    }
721                    else {
722                            return null;
723                    }
724            }
725    
726            /**
727             * Finds all the shopping item fields.
728             *
729             * @return the shopping item fields
730             * @throws SystemException if a system exception occurred
731             */
732            public List<ShoppingItemField> findAll() throws SystemException {
733                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
734            }
735    
736            /**
737             * Finds a range of all the shopping item fields.
738             *
739             * <p>
740             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
741             * </p>
742             *
743             * @param start the lower bound of the range of shopping item fields to return
744             * @param end the upper bound of the range of shopping item fields to return (not inclusive)
745             * @return the range of shopping item fields
746             * @throws SystemException if a system exception occurred
747             */
748            public List<ShoppingItemField> findAll(int start, int end)
749                    throws SystemException {
750                    return findAll(start, end, null);
751            }
752    
753            /**
754             * Finds an ordered range of all the shopping item fields.
755             *
756             * <p>
757             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
758             * </p>
759             *
760             * @param start the lower bound of the range of shopping item fields to return
761             * @param end the upper bound of the range of shopping item fields to return (not inclusive)
762             * @param orderByComparator the comparator to order the results by
763             * @return the ordered range of shopping item fields
764             * @throws SystemException if a system exception occurred
765             */
766            public List<ShoppingItemField> findAll(int start, int end,
767                    OrderByComparator orderByComparator) throws SystemException {
768                    Object[] finderArgs = new Object[] {
769                                    String.valueOf(start), String.valueOf(end),
770                                    String.valueOf(orderByComparator)
771                            };
772    
773                    List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
774                                    finderArgs, this);
775    
776                    if (list == null) {
777                            Session session = null;
778    
779                            try {
780                                    session = openSession();
781    
782                                    StringBundler query = null;
783                                    String sql = null;
784    
785                                    if (orderByComparator != null) {
786                                            query = new StringBundler(2 +
787                                                            (orderByComparator.getOrderByFields().length * 3));
788    
789                                            query.append(_SQL_SELECT_SHOPPINGITEMFIELD);
790    
791                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
792                                                    orderByComparator);
793    
794                                            sql = query.toString();
795                                    }
796                                    else {
797                                            sql = _SQL_SELECT_SHOPPINGITEMFIELD.concat(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
798                                    }
799    
800                                    Query q = session.createQuery(sql);
801    
802                                    if (orderByComparator == null) {
803                                            list = (List<ShoppingItemField>)QueryUtil.list(q,
804                                                            getDialect(), start, end, false);
805    
806                                            Collections.sort(list);
807                                    }
808                                    else {
809                                            list = (List<ShoppingItemField>)QueryUtil.list(q,
810                                                            getDialect(), start, end);
811                                    }
812                            }
813                            catch (Exception e) {
814                                    throw processException(e);
815                            }
816                            finally {
817                                    if (list == null) {
818                                            list = new ArrayList<ShoppingItemField>();
819                                    }
820    
821                                    cacheResult(list);
822    
823                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
824    
825                                    closeSession(session);
826                            }
827                    }
828    
829                    return list;
830            }
831    
832            /**
833             * Removes all the shopping item fields where itemId = &#63; from the database.
834             *
835             * @param itemId the item id to search with
836             * @throws SystemException if a system exception occurred
837             */
838            public void removeByItemId(long itemId) throws SystemException {
839                    for (ShoppingItemField shoppingItemField : findByItemId(itemId)) {
840                            remove(shoppingItemField);
841                    }
842            }
843    
844            /**
845             * Removes all the shopping item fields from the database.
846             *
847             * @throws SystemException if a system exception occurred
848             */
849            public void removeAll() throws SystemException {
850                    for (ShoppingItemField shoppingItemField : findAll()) {
851                            remove(shoppingItemField);
852                    }
853            }
854    
855            /**
856             * Counts all the shopping item fields where itemId = &#63;.
857             *
858             * @param itemId the item id to search with
859             * @return the number of matching shopping item fields
860             * @throws SystemException if a system exception occurred
861             */
862            public int countByItemId(long itemId) throws SystemException {
863                    Object[] finderArgs = new Object[] { itemId };
864    
865                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
866                                    finderArgs, this);
867    
868                    if (count == null) {
869                            Session session = null;
870    
871                            try {
872                                    session = openSession();
873    
874                                    StringBundler query = new StringBundler(2);
875    
876                                    query.append(_SQL_COUNT_SHOPPINGITEMFIELD_WHERE);
877    
878                                    query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
879    
880                                    String sql = query.toString();
881    
882                                    Query q = session.createQuery(sql);
883    
884                                    QueryPos qPos = QueryPos.getInstance(q);
885    
886                                    qPos.add(itemId);
887    
888                                    count = (Long)q.uniqueResult();
889                            }
890                            catch (Exception e) {
891                                    throw processException(e);
892                            }
893                            finally {
894                                    if (count == null) {
895                                            count = Long.valueOf(0);
896                                    }
897    
898                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
899                                            finderArgs, count);
900    
901                                    closeSession(session);
902                            }
903                    }
904    
905                    return count.intValue();
906            }
907    
908            /**
909             * Counts all the shopping item fields.
910             *
911             * @return the number of shopping item fields
912             * @throws SystemException if a system exception occurred
913             */
914            public int countAll() throws SystemException {
915                    Object[] finderArgs = new Object[0];
916    
917                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
918                                    finderArgs, this);
919    
920                    if (count == null) {
921                            Session session = null;
922    
923                            try {
924                                    session = openSession();
925    
926                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMFIELD);
927    
928                                    count = (Long)q.uniqueResult();
929                            }
930                            catch (Exception e) {
931                                    throw processException(e);
932                            }
933                            finally {
934                                    if (count == null) {
935                                            count = Long.valueOf(0);
936                                    }
937    
938                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
939                                            count);
940    
941                                    closeSession(session);
942                            }
943                    }
944    
945                    return count.intValue();
946            }
947    
948            /**
949             * Initializes the shopping item field persistence.
950             */
951            public void afterPropertiesSet() {
952                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
953                                            com.liferay.portal.util.PropsUtil.get(
954                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemField")));
955    
956                    if (listenerClassNames.length > 0) {
957                            try {
958                                    List<ModelListener<ShoppingItemField>> listenersList = new ArrayList<ModelListener<ShoppingItemField>>();
959    
960                                    for (String listenerClassName : listenerClassNames) {
961                                            listenersList.add((ModelListener<ShoppingItemField>)InstanceFactory.newInstance(
962                                                            listenerClassName));
963                                    }
964    
965                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
966                            }
967                            catch (Exception e) {
968                                    _log.error(e);
969                            }
970                    }
971            }
972    
973            @BeanReference(type = ShoppingCartPersistence.class)
974            protected ShoppingCartPersistence shoppingCartPersistence;
975            @BeanReference(type = ShoppingCategoryPersistence.class)
976            protected ShoppingCategoryPersistence shoppingCategoryPersistence;
977            @BeanReference(type = ShoppingCouponPersistence.class)
978            protected ShoppingCouponPersistence shoppingCouponPersistence;
979            @BeanReference(type = ShoppingItemPersistence.class)
980            protected ShoppingItemPersistence shoppingItemPersistence;
981            @BeanReference(type = ShoppingItemFieldPersistence.class)
982            protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
983            @BeanReference(type = ShoppingItemPricePersistence.class)
984            protected ShoppingItemPricePersistence shoppingItemPricePersistence;
985            @BeanReference(type = ShoppingOrderPersistence.class)
986            protected ShoppingOrderPersistence shoppingOrderPersistence;
987            @BeanReference(type = ShoppingOrderItemPersistence.class)
988            protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
989            @BeanReference(type = ResourcePersistence.class)
990            protected ResourcePersistence resourcePersistence;
991            @BeanReference(type = UserPersistence.class)
992            protected UserPersistence userPersistence;
993            private static final String _SQL_SELECT_SHOPPINGITEMFIELD = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField";
994            private static final String _SQL_SELECT_SHOPPINGITEMFIELD_WHERE = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField WHERE ";
995            private static final String _SQL_COUNT_SHOPPINGITEMFIELD = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField";
996            private static final String _SQL_COUNT_SHOPPINGITEMFIELD_WHERE = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField WHERE ";
997            private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemField.itemId = ?";
998            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemField.";
999            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemField exists with the primary key ";
1000            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemField exists with the key {";
1001            private static Log _log = LogFactoryUtil.getLog(ShoppingItemFieldPersistenceImpl.class);
1002    }