001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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                            BatchSessionUtil.delete(session, shoppingItemField);
225                    }
226                    catch (Exception e) {
227                            throw processException(e);
228                    }
229                    finally {
230                            closeSession(session);
231                    }
232    
233                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
234    
235                    EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
236                            ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
237    
238                    return shoppingItemField;
239            }
240    
241            public ShoppingItemField updateImpl(
242                    com.liferay.portlet.shopping.model.ShoppingItemField shoppingItemField,
243                    boolean merge) throws SystemException {
244                    shoppingItemField = toUnwrappedModel(shoppingItemField);
245    
246                    Session session = null;
247    
248                    try {
249                            session = openSession();
250    
251                            BatchSessionUtil.update(session, shoppingItemField, merge);
252    
253                            shoppingItemField.setNew(false);
254                    }
255                    catch (Exception e) {
256                            throw processException(e);
257                    }
258                    finally {
259                            closeSession(session);
260                    }
261    
262                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
263    
264                    EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
265                            ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
266                            shoppingItemField);
267    
268                    return shoppingItemField;
269            }
270    
271            protected ShoppingItemField toUnwrappedModel(
272                    ShoppingItemField shoppingItemField) {
273                    if (shoppingItemField instanceof ShoppingItemFieldImpl) {
274                            return shoppingItemField;
275                    }
276    
277                    ShoppingItemFieldImpl shoppingItemFieldImpl = new ShoppingItemFieldImpl();
278    
279                    shoppingItemFieldImpl.setNew(shoppingItemField.isNew());
280                    shoppingItemFieldImpl.setPrimaryKey(shoppingItemField.getPrimaryKey());
281    
282                    shoppingItemFieldImpl.setItemFieldId(shoppingItemField.getItemFieldId());
283                    shoppingItemFieldImpl.setItemId(shoppingItemField.getItemId());
284                    shoppingItemFieldImpl.setName(shoppingItemField.getName());
285                    shoppingItemFieldImpl.setValues(shoppingItemField.getValues());
286                    shoppingItemFieldImpl.setDescription(shoppingItemField.getDescription());
287    
288                    return shoppingItemFieldImpl;
289            }
290    
291            /**
292             * Finds the shopping item field with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
293             *
294             * @param primaryKey the primary key of the shopping item field to find
295             * @return the shopping item field
296             * @throws com.liferay.portal.NoSuchModelException if a shopping item field with the primary key could not be found
297             * @throws SystemException if a system exception occurred
298             */
299            public ShoppingItemField findByPrimaryKey(Serializable primaryKey)
300                    throws NoSuchModelException, SystemException {
301                    return findByPrimaryKey(((Long)primaryKey).longValue());
302            }
303    
304            /**
305             * Finds the shopping item field with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchItemFieldException} if it could not be found.
306             *
307             * @param itemFieldId the primary key of the shopping item field to find
308             * @return the shopping item field
309             * @throws com.liferay.portlet.shopping.NoSuchItemFieldException if a shopping item field with the primary key could not be found
310             * @throws SystemException if a system exception occurred
311             */
312            public ShoppingItemField findByPrimaryKey(long itemFieldId)
313                    throws NoSuchItemFieldException, SystemException {
314                    ShoppingItemField shoppingItemField = fetchByPrimaryKey(itemFieldId);
315    
316                    if (shoppingItemField == null) {
317                            if (_log.isWarnEnabled()) {
318                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
319                            }
320    
321                            throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
322                                    itemFieldId);
323                    }
324    
325                    return shoppingItemField;
326            }
327    
328            /**
329             * Finds the shopping item field with the primary key or returns <code>null</code> if it could not be found.
330             *
331             * @param primaryKey the primary key of the shopping item field to find
332             * @return the shopping item field, or <code>null</code> if a shopping item field with the primary key could not be found
333             * @throws SystemException if a system exception occurred
334             */
335            public ShoppingItemField fetchByPrimaryKey(Serializable primaryKey)
336                    throws SystemException {
337                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
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 itemFieldId 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(long itemFieldId)
348                    throws SystemException {
349                    ShoppingItemField shoppingItemField = (ShoppingItemField)EntityCacheUtil.getResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
350                                    ShoppingItemFieldImpl.class, itemFieldId, this);
351    
352                    if (shoppingItemField == null) {
353                            Session session = null;
354    
355                            try {
356                                    session = openSession();
357    
358                                    shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
359                                                    new Long(itemFieldId));
360                            }
361                            catch (Exception e) {
362                                    throw processException(e);
363                            }
364                            finally {
365                                    if (shoppingItemField != null) {
366                                            cacheResult(shoppingItemField);
367                                    }
368    
369                                    closeSession(session);
370                            }
371                    }
372    
373                    return shoppingItemField;
374            }
375    
376            /**
377             * Finds all the shopping item fields where itemId = &#63;.
378             *
379             * @param itemId the item id to search with
380             * @return the matching shopping item fields
381             * @throws SystemException if a system exception occurred
382             */
383            public List<ShoppingItemField> findByItemId(long itemId)
384                    throws SystemException {
385                    return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
386            }
387    
388            /**
389             * Finds a range of all the shopping item fields where itemId = &#63;.
390             *
391             * <p>
392             * 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.
393             * </p>
394             *
395             * @param itemId the item id to search with
396             * @param start the lower bound of the range of shopping item fields to return
397             * @param end the upper bound of the range of shopping item fields to return (not inclusive)
398             * @return the range of matching shopping item fields
399             * @throws SystemException if a system exception occurred
400             */
401            public List<ShoppingItemField> findByItemId(long itemId, int start, int end)
402                    throws SystemException {
403                    return findByItemId(itemId, start, end, null);
404            }
405    
406            /**
407             * Finds an ordered range of all the shopping item fields where itemId = &#63;.
408             *
409             * <p>
410             * 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.
411             * </p>
412             *
413             * @param itemId the item id to search with
414             * @param start the lower bound of the range of shopping item fields to return
415             * @param end the upper bound of the range of shopping item fields to return (not inclusive)
416             * @param orderByComparator the comparator to order the results by
417             * @return the ordered range of matching shopping item fields
418             * @throws SystemException if a system exception occurred
419             */
420            public List<ShoppingItemField> findByItemId(long itemId, int start,
421                    int end, OrderByComparator orderByComparator) throws SystemException {
422                    Object[] finderArgs = new Object[] {
423                                    itemId,
424                                    
425                                    String.valueOf(start), String.valueOf(end),
426                                    String.valueOf(orderByComparator)
427                            };
428    
429                    List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ITEMID,
430                                    finderArgs, this);
431    
432                    if (list == null) {
433                            Session session = null;
434    
435                            try {
436                                    session = openSession();
437    
438                                    StringBundler query = null;
439    
440                                    if (orderByComparator != null) {
441                                            query = new StringBundler(3 +
442                                                            (orderByComparator.getOrderByFields().length * 3));
443                                    }
444                                    else {
445                                            query = new StringBundler(3);
446                                    }
447    
448                                    query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
449    
450                                    query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
451    
452                                    if (orderByComparator != null) {
453                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
454                                                    orderByComparator);
455                                    }
456    
457                                    else {
458                                            query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
459                                    }
460    
461                                    String sql = query.toString();
462    
463                                    Query q = session.createQuery(sql);
464    
465                                    QueryPos qPos = QueryPos.getInstance(q);
466    
467                                    qPos.add(itemId);
468    
469                                    list = (List<ShoppingItemField>)QueryUtil.list(q, getDialect(),
470                                                    start, end);
471                            }
472                            catch (Exception e) {
473                                    throw processException(e);
474                            }
475                            finally {
476                                    if (list == null) {
477                                            list = new ArrayList<ShoppingItemField>();
478                                    }
479    
480                                    cacheResult(list);
481    
482                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ITEMID,
483                                            finderArgs, list);
484    
485                                    closeSession(session);
486                            }
487                    }
488    
489                    return list;
490            }
491    
492            /**
493             * Finds the first shopping item field in the ordered set where itemId = &#63;.
494             *
495             * <p>
496             * 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.
497             * </p>
498             *
499             * @param itemId the item id to search with
500             * @param orderByComparator the comparator to order the set by
501             * @return the first matching shopping item field
502             * @throws com.liferay.portlet.shopping.NoSuchItemFieldException if a matching shopping item field could not be found
503             * @throws SystemException if a system exception occurred
504             */
505            public ShoppingItemField findByItemId_First(long itemId,
506                    OrderByComparator orderByComparator)
507                    throws NoSuchItemFieldException, SystemException {
508                    List<ShoppingItemField> list = findByItemId(itemId, 0, 1,
509                                    orderByComparator);
510    
511                    if (list.isEmpty()) {
512                            StringBundler msg = new StringBundler(4);
513    
514                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
515    
516                            msg.append("itemId=");
517                            msg.append(itemId);
518    
519                            msg.append(StringPool.CLOSE_CURLY_BRACE);
520    
521                            throw new NoSuchItemFieldException(msg.toString());
522                    }
523                    else {
524                            return list.get(0);
525                    }
526            }
527    
528            /**
529             * Finds the last shopping item field in the ordered set where itemId = &#63;.
530             *
531             * <p>
532             * 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.
533             * </p>
534             *
535             * @param itemId the item id to search with
536             * @param orderByComparator the comparator to order the set by
537             * @return the last matching shopping item field
538             * @throws com.liferay.portlet.shopping.NoSuchItemFieldException if a matching shopping item field could not be found
539             * @throws SystemException if a system exception occurred
540             */
541            public ShoppingItemField findByItemId_Last(long itemId,
542                    OrderByComparator orderByComparator)
543                    throws NoSuchItemFieldException, SystemException {
544                    int count = countByItemId(itemId);
545    
546                    List<ShoppingItemField> list = findByItemId(itemId, count - 1, count,
547                                    orderByComparator);
548    
549                    if (list.isEmpty()) {
550                            StringBundler msg = new StringBundler(4);
551    
552                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
553    
554                            msg.append("itemId=");
555                            msg.append(itemId);
556    
557                            msg.append(StringPool.CLOSE_CURLY_BRACE);
558    
559                            throw new NoSuchItemFieldException(msg.toString());
560                    }
561                    else {
562                            return list.get(0);
563                    }
564            }
565    
566            /**
567             * Finds the shopping item fields before and after the current shopping item field in the ordered set where itemId = &#63;.
568             *
569             * <p>
570             * 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.
571             * </p>
572             *
573             * @param itemFieldId the primary key of the current shopping item field
574             * @param itemId the item id to search with
575             * @param orderByComparator the comparator to order the set by
576             * @return the previous, current, and next shopping item field
577             * @throws com.liferay.portlet.shopping.NoSuchItemFieldException if a shopping item field with the primary key could not be found
578             * @throws SystemException if a system exception occurred
579             */
580            public ShoppingItemField[] findByItemId_PrevAndNext(long itemFieldId,
581                    long itemId, OrderByComparator orderByComparator)
582                    throws NoSuchItemFieldException, SystemException {
583                    ShoppingItemField shoppingItemField = findByPrimaryKey(itemFieldId);
584    
585                    Session session = null;
586    
587                    try {
588                            session = openSession();
589    
590                            ShoppingItemField[] array = new ShoppingItemFieldImpl[3];
591    
592                            array[0] = getByItemId_PrevAndNext(session, shoppingItemField,
593                                            itemId, orderByComparator, true);
594    
595                            array[1] = shoppingItemField;
596    
597                            array[2] = getByItemId_PrevAndNext(session, shoppingItemField,
598                                            itemId, orderByComparator, false);
599    
600                            return array;
601                    }
602                    catch (Exception e) {
603                            throw processException(e);
604                    }
605                    finally {
606                            closeSession(session);
607                    }
608            }
609    
610            protected ShoppingItemField getByItemId_PrevAndNext(Session session,
611                    ShoppingItemField shoppingItemField, long itemId,
612                    OrderByComparator orderByComparator, boolean previous) {
613                    StringBundler query = null;
614    
615                    if (orderByComparator != null) {
616                            query = new StringBundler(6 +
617                                            (orderByComparator.getOrderByFields().length * 6));
618                    }
619                    else {
620                            query = new StringBundler(3);
621                    }
622    
623                    query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
624    
625                    query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
626    
627                    if (orderByComparator != null) {
628                            String[] orderByFields = orderByComparator.getOrderByFields();
629    
630                            if (orderByFields.length > 0) {
631                                    query.append(WHERE_AND);
632                            }
633    
634                            for (int i = 0; i < orderByFields.length; i++) {
635                                    query.append(_ORDER_BY_ENTITY_ALIAS);
636                                    query.append(orderByFields[i]);
637    
638                                    if ((i + 1) < orderByFields.length) {
639                                            if (orderByComparator.isAscending() ^ previous) {
640                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
641                                            }
642                                            else {
643                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
644                                            }
645                                    }
646                                    else {
647                                            if (orderByComparator.isAscending() ^ previous) {
648                                                    query.append(WHERE_GREATER_THAN);
649                                            }
650                                            else {
651                                                    query.append(WHERE_LESSER_THAN);
652                                            }
653                                    }
654                            }
655    
656                            query.append(ORDER_BY_CLAUSE);
657    
658                            for (int i = 0; i < orderByFields.length; i++) {
659                                    query.append(_ORDER_BY_ENTITY_ALIAS);
660                                    query.append(orderByFields[i]);
661    
662                                    if ((i + 1) < orderByFields.length) {
663                                            if (orderByComparator.isAscending() ^ previous) {
664                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
665                                            }
666                                            else {
667                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
668                                            }
669                                    }
670                                    else {
671                                            if (orderByComparator.isAscending() ^ previous) {
672                                                    query.append(ORDER_BY_ASC);
673                                            }
674                                            else {
675                                                    query.append(ORDER_BY_DESC);
676                                            }
677                                    }
678                            }
679                    }
680    
681                    else {
682                            query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
683                    }
684    
685                    String sql = query.toString();
686    
687                    Query q = session.createQuery(sql);
688    
689                    q.setFirstResult(0);
690                    q.setMaxResults(2);
691    
692                    QueryPos qPos = QueryPos.getInstance(q);
693    
694                    qPos.add(itemId);
695    
696                    if (orderByComparator != null) {
697                            Object[] values = orderByComparator.getOrderByValues(shoppingItemField);
698    
699                            for (Object value : values) {
700                                    qPos.add(value);
701                            }
702                    }
703    
704                    List<ShoppingItemField> list = q.list();
705    
706                    if (list.size() == 2) {
707                            return list.get(1);
708                    }
709                    else {
710                            return null;
711                    }
712            }
713    
714            /**
715             * Finds all the shopping item fields.
716             *
717             * @return the shopping item fields
718             * @throws SystemException if a system exception occurred
719             */
720            public List<ShoppingItemField> findAll() throws SystemException {
721                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
722            }
723    
724            /**
725             * Finds a range of all the shopping item fields.
726             *
727             * <p>
728             * 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.
729             * </p>
730             *
731             * @param start the lower bound of the range of shopping item fields to return
732             * @param end the upper bound of the range of shopping item fields to return (not inclusive)
733             * @return the range of shopping item fields
734             * @throws SystemException if a system exception occurred
735             */
736            public List<ShoppingItemField> findAll(int start, int end)
737                    throws SystemException {
738                    return findAll(start, end, null);
739            }
740    
741            /**
742             * Finds an ordered range of all the shopping item fields.
743             *
744             * <p>
745             * 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.
746             * </p>
747             *
748             * @param start the lower bound of the range of shopping item fields to return
749             * @param end the upper bound of the range of shopping item fields to return (not inclusive)
750             * @param orderByComparator the comparator to order the results by
751             * @return the ordered range of shopping item fields
752             * @throws SystemException if a system exception occurred
753             */
754            public List<ShoppingItemField> findAll(int start, int end,
755                    OrderByComparator orderByComparator) throws SystemException {
756                    Object[] finderArgs = new Object[] {
757                                    String.valueOf(start), String.valueOf(end),
758                                    String.valueOf(orderByComparator)
759                            };
760    
761                    List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
762                                    finderArgs, this);
763    
764                    if (list == null) {
765                            Session session = null;
766    
767                            try {
768                                    session = openSession();
769    
770                                    StringBundler query = null;
771                                    String sql = null;
772    
773                                    if (orderByComparator != null) {
774                                            query = new StringBundler(2 +
775                                                            (orderByComparator.getOrderByFields().length * 3));
776    
777                                            query.append(_SQL_SELECT_SHOPPINGITEMFIELD);
778    
779                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
780                                                    orderByComparator);
781    
782                                            sql = query.toString();
783                                    }
784                                    else {
785                                            sql = _SQL_SELECT_SHOPPINGITEMFIELD.concat(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
786                                    }
787    
788                                    Query q = session.createQuery(sql);
789    
790                                    if (orderByComparator == null) {
791                                            list = (List<ShoppingItemField>)QueryUtil.list(q,
792                                                            getDialect(), start, end, false);
793    
794                                            Collections.sort(list);
795                                    }
796                                    else {
797                                            list = (List<ShoppingItemField>)QueryUtil.list(q,
798                                                            getDialect(), start, end);
799                                    }
800                            }
801                            catch (Exception e) {
802                                    throw processException(e);
803                            }
804                            finally {
805                                    if (list == null) {
806                                            list = new ArrayList<ShoppingItemField>();
807                                    }
808    
809                                    cacheResult(list);
810    
811                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
812    
813                                    closeSession(session);
814                            }
815                    }
816    
817                    return list;
818            }
819    
820            /**
821             * Removes all the shopping item fields where itemId = &#63; from the database.
822             *
823             * @param itemId the item id to search with
824             * @throws SystemException if a system exception occurred
825             */
826            public void removeByItemId(long itemId) throws SystemException {
827                    for (ShoppingItemField shoppingItemField : findByItemId(itemId)) {
828                            remove(shoppingItemField);
829                    }
830            }
831    
832            /**
833             * Removes all the shopping item fields from the database.
834             *
835             * @throws SystemException if a system exception occurred
836             */
837            public void removeAll() throws SystemException {
838                    for (ShoppingItemField shoppingItemField : findAll()) {
839                            remove(shoppingItemField);
840                    }
841            }
842    
843            /**
844             * Counts all the shopping item fields where itemId = &#63;.
845             *
846             * @param itemId the item id to search with
847             * @return the number of matching shopping item fields
848             * @throws SystemException if a system exception occurred
849             */
850            public int countByItemId(long itemId) throws SystemException {
851                    Object[] finderArgs = new Object[] { itemId };
852    
853                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
854                                    finderArgs, this);
855    
856                    if (count == null) {
857                            Session session = null;
858    
859                            try {
860                                    session = openSession();
861    
862                                    StringBundler query = new StringBundler(2);
863    
864                                    query.append(_SQL_COUNT_SHOPPINGITEMFIELD_WHERE);
865    
866                                    query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
867    
868                                    String sql = query.toString();
869    
870                                    Query q = session.createQuery(sql);
871    
872                                    QueryPos qPos = QueryPos.getInstance(q);
873    
874                                    qPos.add(itemId);
875    
876                                    count = (Long)q.uniqueResult();
877                            }
878                            catch (Exception e) {
879                                    throw processException(e);
880                            }
881                            finally {
882                                    if (count == null) {
883                                            count = Long.valueOf(0);
884                                    }
885    
886                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
887                                            finderArgs, count);
888    
889                                    closeSession(session);
890                            }
891                    }
892    
893                    return count.intValue();
894            }
895    
896            /**
897             * Counts all the shopping item fields.
898             *
899             * @return the number of shopping item fields
900             * @throws SystemException if a system exception occurred
901             */
902            public int countAll() throws SystemException {
903                    Object[] finderArgs = new Object[0];
904    
905                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
906                                    finderArgs, this);
907    
908                    if (count == null) {
909                            Session session = null;
910    
911                            try {
912                                    session = openSession();
913    
914                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMFIELD);
915    
916                                    count = (Long)q.uniqueResult();
917                            }
918                            catch (Exception e) {
919                                    throw processException(e);
920                            }
921                            finally {
922                                    if (count == null) {
923                                            count = Long.valueOf(0);
924                                    }
925    
926                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
927                                            count);
928    
929                                    closeSession(session);
930                            }
931                    }
932    
933                    return count.intValue();
934            }
935    
936            /**
937             * Initializes the shopping item field persistence.
938             */
939            public void afterPropertiesSet() {
940                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
941                                            com.liferay.portal.util.PropsUtil.get(
942                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemField")));
943    
944                    if (listenerClassNames.length > 0) {
945                            try {
946                                    List<ModelListener<ShoppingItemField>> listenersList = new ArrayList<ModelListener<ShoppingItemField>>();
947    
948                                    for (String listenerClassName : listenerClassNames) {
949                                            listenersList.add((ModelListener<ShoppingItemField>)InstanceFactory.newInstance(
950                                                            listenerClassName));
951                                    }
952    
953                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
954                            }
955                            catch (Exception e) {
956                                    _log.error(e);
957                            }
958                    }
959            }
960    
961            public void destroy() {
962                    EntityCacheUtil.removeCache(ShoppingItemFieldImpl.class.getName());
963                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
964                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
965            }
966    
967            @BeanReference(type = ShoppingCartPersistence.class)
968            protected ShoppingCartPersistence shoppingCartPersistence;
969            @BeanReference(type = ShoppingCategoryPersistence.class)
970            protected ShoppingCategoryPersistence shoppingCategoryPersistence;
971            @BeanReference(type = ShoppingCouponPersistence.class)
972            protected ShoppingCouponPersistence shoppingCouponPersistence;
973            @BeanReference(type = ShoppingItemPersistence.class)
974            protected ShoppingItemPersistence shoppingItemPersistence;
975            @BeanReference(type = ShoppingItemFieldPersistence.class)
976            protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
977            @BeanReference(type = ShoppingItemPricePersistence.class)
978            protected ShoppingItemPricePersistence shoppingItemPricePersistence;
979            @BeanReference(type = ShoppingOrderPersistence.class)
980            protected ShoppingOrderPersistence shoppingOrderPersistence;
981            @BeanReference(type = ShoppingOrderItemPersistence.class)
982            protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
983            @BeanReference(type = ResourcePersistence.class)
984            protected ResourcePersistence resourcePersistence;
985            @BeanReference(type = UserPersistence.class)
986            protected UserPersistence userPersistence;
987            private static final String _SQL_SELECT_SHOPPINGITEMFIELD = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField";
988            private static final String _SQL_SELECT_SHOPPINGITEMFIELD_WHERE = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField WHERE ";
989            private static final String _SQL_COUNT_SHOPPINGITEMFIELD = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField";
990            private static final String _SQL_COUNT_SHOPPINGITEMFIELD_WHERE = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField WHERE ";
991            private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemField.itemId = ?";
992            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemField.";
993            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemField exists with the primary key ";
994            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemField exists with the key {";
995            private static Log _log = LogFactoryUtil.getLog(ShoppingItemFieldPersistenceImpl.class);
996    }