001    /**
002     * Copyright (c) 2000-2012 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.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
022    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
023    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025    import com.liferay.portal.kernel.dao.orm.FinderPath;
026    import com.liferay.portal.kernel.dao.orm.Query;
027    import com.liferay.portal.kernel.dao.orm.QueryPos;
028    import com.liferay.portal.kernel.dao.orm.QueryUtil;
029    import com.liferay.portal.kernel.dao.orm.SQLQuery;
030    import com.liferay.portal.kernel.dao.orm.Session;
031    import com.liferay.portal.kernel.exception.SystemException;
032    import com.liferay.portal.kernel.log.Log;
033    import com.liferay.portal.kernel.log.LogFactoryUtil;
034    import com.liferay.portal.kernel.util.GetterUtil;
035    import com.liferay.portal.kernel.util.InstanceFactory;
036    import com.liferay.portal.kernel.util.OrderByComparator;
037    import com.liferay.portal.kernel.util.StringBundler;
038    import com.liferay.portal.kernel.util.StringPool;
039    import com.liferay.portal.kernel.util.StringUtil;
040    import com.liferay.portal.kernel.util.UnmodifiableList;
041    import com.liferay.portal.kernel.util.Validator;
042    import com.liferay.portal.model.CacheModel;
043    import com.liferay.portal.model.ModelListener;
044    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
045    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046    
047    import com.liferay.portlet.shopping.NoSuchItemException;
048    import com.liferay.portlet.shopping.model.ShoppingItem;
049    import com.liferay.portlet.shopping.model.impl.ShoppingItemImpl;
050    import com.liferay.portlet.shopping.model.impl.ShoppingItemModelImpl;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    
058    /**
059     * The persistence implementation for the shopping item service.
060     *
061     * <p>
062     * Caching information and settings can be found in <code>portal.properties</code>
063     * </p>
064     *
065     * @author Brian Wing Shun Chan
066     * @see ShoppingItemPersistence
067     * @see ShoppingItemUtil
068     * @generated
069     */
070    public class ShoppingItemPersistenceImpl extends BasePersistenceImpl<ShoppingItem>
071            implements ShoppingItemPersistence {
072            /*
073             * NOTE FOR DEVELOPERS:
074             *
075             * Never modify or reference this class directly. Always use {@link ShoppingItemUtil} to access the shopping item persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
076             */
077            public static final String FINDER_CLASS_NAME_ENTITY = ShoppingItemImpl.class.getName();
078            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List1";
080            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List2";
082            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
083                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, ShoppingItemImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
086                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, ShoppingItemImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
089                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091            public static final FinderPath FINDER_PATH_FETCH_BY_SMALLIMAGEID = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
092                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, ShoppingItemImpl.class,
093                            FINDER_CLASS_NAME_ENTITY, "fetchBySmallImageId",
094                            new String[] { Long.class.getName() },
095                            ShoppingItemModelImpl.SMALLIMAGEID_COLUMN_BITMASK);
096            public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
097                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySmallImageId",
099                            new String[] { Long.class.getName() });
100    
101            /**
102             * Returns the shopping item where smallImageId = &#63; or throws a {@link com.liferay.portlet.shopping.NoSuchItemException} if it could not be found.
103             *
104             * @param smallImageId the small image ID
105             * @return the matching shopping item
106             * @throws com.liferay.portlet.shopping.NoSuchItemException if a matching shopping item could not be found
107             * @throws SystemException if a system exception occurred
108             */
109            public ShoppingItem findBySmallImageId(long smallImageId)
110                    throws NoSuchItemException, SystemException {
111                    ShoppingItem shoppingItem = fetchBySmallImageId(smallImageId);
112    
113                    if (shoppingItem == null) {
114                            StringBundler msg = new StringBundler(4);
115    
116                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
117    
118                            msg.append("smallImageId=");
119                            msg.append(smallImageId);
120    
121                            msg.append(StringPool.CLOSE_CURLY_BRACE);
122    
123                            if (_log.isWarnEnabled()) {
124                                    _log.warn(msg.toString());
125                            }
126    
127                            throw new NoSuchItemException(msg.toString());
128                    }
129    
130                    return shoppingItem;
131            }
132    
133            /**
134             * Returns the shopping item where smallImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
135             *
136             * @param smallImageId the small image ID
137             * @return the matching shopping item, or <code>null</code> if a matching shopping item could not be found
138             * @throws SystemException if a system exception occurred
139             */
140            public ShoppingItem fetchBySmallImageId(long smallImageId)
141                    throws SystemException {
142                    return fetchBySmallImageId(smallImageId, true);
143            }
144    
145            /**
146             * Returns the shopping item where smallImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
147             *
148             * @param smallImageId the small image ID
149             * @param retrieveFromCache whether to use the finder cache
150             * @return the matching shopping item, or <code>null</code> if a matching shopping item could not be found
151             * @throws SystemException if a system exception occurred
152             */
153            public ShoppingItem fetchBySmallImageId(long smallImageId,
154                    boolean retrieveFromCache) throws SystemException {
155                    Object[] finderArgs = new Object[] { smallImageId };
156    
157                    Object result = null;
158    
159                    if (retrieveFromCache) {
160                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
161                                            finderArgs, this);
162                    }
163    
164                    if (result instanceof ShoppingItem) {
165                            ShoppingItem shoppingItem = (ShoppingItem)result;
166    
167                            if ((smallImageId != shoppingItem.getSmallImageId())) {
168                                    result = null;
169                            }
170                    }
171    
172                    if (result == null) {
173                            StringBundler query = new StringBundler(3);
174    
175                            query.append(_SQL_SELECT_SHOPPINGITEM_WHERE);
176    
177                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
178    
179                            String sql = query.toString();
180    
181                            Session session = null;
182    
183                            try {
184                                    session = openSession();
185    
186                                    Query q = session.createQuery(sql);
187    
188                                    QueryPos qPos = QueryPos.getInstance(q);
189    
190                                    qPos.add(smallImageId);
191    
192                                    List<ShoppingItem> list = q.list();
193    
194                                    if (list.isEmpty()) {
195                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
196                                                    finderArgs, list);
197                                    }
198                                    else {
199                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
200                                                    _log.warn(
201                                                            "ShoppingItemPersistenceImpl.fetchBySmallImageId(long, boolean) with parameters (" +
202                                                            StringUtil.merge(finderArgs) +
203                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
204                                            }
205    
206                                            ShoppingItem shoppingItem = list.get(0);
207    
208                                            result = shoppingItem;
209    
210                                            cacheResult(shoppingItem);
211    
212                                            if ((shoppingItem.getSmallImageId() != smallImageId)) {
213                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
214                                                            finderArgs, shoppingItem);
215                                            }
216                                    }
217                            }
218                            catch (Exception e) {
219                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
220                                            finderArgs);
221    
222                                    throw processException(e);
223                            }
224                            finally {
225                                    closeSession(session);
226                            }
227                    }
228    
229                    if (result instanceof List<?>) {
230                            return null;
231                    }
232                    else {
233                            return (ShoppingItem)result;
234                    }
235            }
236    
237            /**
238             * Removes the shopping item where smallImageId = &#63; from the database.
239             *
240             * @param smallImageId the small image ID
241             * @return the shopping item that was removed
242             * @throws SystemException if a system exception occurred
243             */
244            public ShoppingItem removeBySmallImageId(long smallImageId)
245                    throws NoSuchItemException, SystemException {
246                    ShoppingItem shoppingItem = findBySmallImageId(smallImageId);
247    
248                    return remove(shoppingItem);
249            }
250    
251            /**
252             * Returns the number of shopping items where smallImageId = &#63;.
253             *
254             * @param smallImageId the small image ID
255             * @return the number of matching shopping items
256             * @throws SystemException if a system exception occurred
257             */
258            public int countBySmallImageId(long smallImageId) throws SystemException {
259                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SMALLIMAGEID;
260    
261                    Object[] finderArgs = new Object[] { smallImageId };
262    
263                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
264                                    this);
265    
266                    if (count == null) {
267                            StringBundler query = new StringBundler(2);
268    
269                            query.append(_SQL_COUNT_SHOPPINGITEM_WHERE);
270    
271                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
272    
273                            String sql = query.toString();
274    
275                            Session session = null;
276    
277                            try {
278                                    session = openSession();
279    
280                                    Query q = session.createQuery(sql);
281    
282                                    QueryPos qPos = QueryPos.getInstance(q);
283    
284                                    qPos.add(smallImageId);
285    
286                                    count = (Long)q.uniqueResult();
287    
288                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
289                            }
290                            catch (Exception e) {
291                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
292    
293                                    throw processException(e);
294                            }
295                            finally {
296                                    closeSession(session);
297                            }
298                    }
299    
300                    return count.intValue();
301            }
302    
303            private static final String _FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2 = "shoppingItem.smallImageId = ?";
304            public static final FinderPath FINDER_PATH_FETCH_BY_MEDIUMIMAGEID = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
305                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, ShoppingItemImpl.class,
306                            FINDER_CLASS_NAME_ENTITY, "fetchByMediumImageId",
307                            new String[] { Long.class.getName() },
308                            ShoppingItemModelImpl.MEDIUMIMAGEID_COLUMN_BITMASK);
309            public static final FinderPath FINDER_PATH_COUNT_BY_MEDIUMIMAGEID = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
310                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
311                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByMediumImageId",
312                            new String[] { Long.class.getName() });
313    
314            /**
315             * Returns the shopping item where mediumImageId = &#63; or throws a {@link com.liferay.portlet.shopping.NoSuchItemException} if it could not be found.
316             *
317             * @param mediumImageId the medium image ID
318             * @return the matching shopping item
319             * @throws com.liferay.portlet.shopping.NoSuchItemException if a matching shopping item could not be found
320             * @throws SystemException if a system exception occurred
321             */
322            public ShoppingItem findByMediumImageId(long mediumImageId)
323                    throws NoSuchItemException, SystemException {
324                    ShoppingItem shoppingItem = fetchByMediumImageId(mediumImageId);
325    
326                    if (shoppingItem == null) {
327                            StringBundler msg = new StringBundler(4);
328    
329                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
330    
331                            msg.append("mediumImageId=");
332                            msg.append(mediumImageId);
333    
334                            msg.append(StringPool.CLOSE_CURLY_BRACE);
335    
336                            if (_log.isWarnEnabled()) {
337                                    _log.warn(msg.toString());
338                            }
339    
340                            throw new NoSuchItemException(msg.toString());
341                    }
342    
343                    return shoppingItem;
344            }
345    
346            /**
347             * Returns the shopping item where mediumImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
348             *
349             * @param mediumImageId the medium image ID
350             * @return the matching shopping item, or <code>null</code> if a matching shopping item could not be found
351             * @throws SystemException if a system exception occurred
352             */
353            public ShoppingItem fetchByMediumImageId(long mediumImageId)
354                    throws SystemException {
355                    return fetchByMediumImageId(mediumImageId, true);
356            }
357    
358            /**
359             * Returns the shopping item where mediumImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
360             *
361             * @param mediumImageId the medium image ID
362             * @param retrieveFromCache whether to use the finder cache
363             * @return the matching shopping item, or <code>null</code> if a matching shopping item could not be found
364             * @throws SystemException if a system exception occurred
365             */
366            public ShoppingItem fetchByMediumImageId(long mediumImageId,
367                    boolean retrieveFromCache) throws SystemException {
368                    Object[] finderArgs = new Object[] { mediumImageId };
369    
370                    Object result = null;
371    
372                    if (retrieveFromCache) {
373                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
374                                            finderArgs, this);
375                    }
376    
377                    if (result instanceof ShoppingItem) {
378                            ShoppingItem shoppingItem = (ShoppingItem)result;
379    
380                            if ((mediumImageId != shoppingItem.getMediumImageId())) {
381                                    result = null;
382                            }
383                    }
384    
385                    if (result == null) {
386                            StringBundler query = new StringBundler(3);
387    
388                            query.append(_SQL_SELECT_SHOPPINGITEM_WHERE);
389    
390                            query.append(_FINDER_COLUMN_MEDIUMIMAGEID_MEDIUMIMAGEID_2);
391    
392                            String sql = query.toString();
393    
394                            Session session = null;
395    
396                            try {
397                                    session = openSession();
398    
399                                    Query q = session.createQuery(sql);
400    
401                                    QueryPos qPos = QueryPos.getInstance(q);
402    
403                                    qPos.add(mediumImageId);
404    
405                                    List<ShoppingItem> list = q.list();
406    
407                                    if (list.isEmpty()) {
408                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
409                                                    finderArgs, list);
410                                    }
411                                    else {
412                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
413                                                    _log.warn(
414                                                            "ShoppingItemPersistenceImpl.fetchByMediumImageId(long, boolean) with parameters (" +
415                                                            StringUtil.merge(finderArgs) +
416                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
417                                            }
418    
419                                            ShoppingItem shoppingItem = list.get(0);
420    
421                                            result = shoppingItem;
422    
423                                            cacheResult(shoppingItem);
424    
425                                            if ((shoppingItem.getMediumImageId() != mediumImageId)) {
426                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
427                                                            finderArgs, shoppingItem);
428                                            }
429                                    }
430                            }
431                            catch (Exception e) {
432                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
433                                            finderArgs);
434    
435                                    throw processException(e);
436                            }
437                            finally {
438                                    closeSession(session);
439                            }
440                    }
441    
442                    if (result instanceof List<?>) {
443                            return null;
444                    }
445                    else {
446                            return (ShoppingItem)result;
447                    }
448            }
449    
450            /**
451             * Removes the shopping item where mediumImageId = &#63; from the database.
452             *
453             * @param mediumImageId the medium image ID
454             * @return the shopping item that was removed
455             * @throws SystemException if a system exception occurred
456             */
457            public ShoppingItem removeByMediumImageId(long mediumImageId)
458                    throws NoSuchItemException, SystemException {
459                    ShoppingItem shoppingItem = findByMediumImageId(mediumImageId);
460    
461                    return remove(shoppingItem);
462            }
463    
464            /**
465             * Returns the number of shopping items where mediumImageId = &#63;.
466             *
467             * @param mediumImageId the medium image ID
468             * @return the number of matching shopping items
469             * @throws SystemException if a system exception occurred
470             */
471            public int countByMediumImageId(long mediumImageId)
472                    throws SystemException {
473                    FinderPath finderPath = FINDER_PATH_COUNT_BY_MEDIUMIMAGEID;
474    
475                    Object[] finderArgs = new Object[] { mediumImageId };
476    
477                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
478                                    this);
479    
480                    if (count == null) {
481                            StringBundler query = new StringBundler(2);
482    
483                            query.append(_SQL_COUNT_SHOPPINGITEM_WHERE);
484    
485                            query.append(_FINDER_COLUMN_MEDIUMIMAGEID_MEDIUMIMAGEID_2);
486    
487                            String sql = query.toString();
488    
489                            Session session = null;
490    
491                            try {
492                                    session = openSession();
493    
494                                    Query q = session.createQuery(sql);
495    
496                                    QueryPos qPos = QueryPos.getInstance(q);
497    
498                                    qPos.add(mediumImageId);
499    
500                                    count = (Long)q.uniqueResult();
501    
502                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
503                            }
504                            catch (Exception e) {
505                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
506    
507                                    throw processException(e);
508                            }
509                            finally {
510                                    closeSession(session);
511                            }
512                    }
513    
514                    return count.intValue();
515            }
516    
517            private static final String _FINDER_COLUMN_MEDIUMIMAGEID_MEDIUMIMAGEID_2 = "shoppingItem.mediumImageId = ?";
518            public static final FinderPath FINDER_PATH_FETCH_BY_LARGEIMAGEID = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
519                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, ShoppingItemImpl.class,
520                            FINDER_CLASS_NAME_ENTITY, "fetchByLargeImageId",
521                            new String[] { Long.class.getName() },
522                            ShoppingItemModelImpl.LARGEIMAGEID_COLUMN_BITMASK);
523            public static final FinderPath FINDER_PATH_COUNT_BY_LARGEIMAGEID = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
524                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
525                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLargeImageId",
526                            new String[] { Long.class.getName() });
527    
528            /**
529             * Returns the shopping item where largeImageId = &#63; or throws a {@link com.liferay.portlet.shopping.NoSuchItemException} if it could not be found.
530             *
531             * @param largeImageId the large image ID
532             * @return the matching shopping item
533             * @throws com.liferay.portlet.shopping.NoSuchItemException if a matching shopping item could not be found
534             * @throws SystemException if a system exception occurred
535             */
536            public ShoppingItem findByLargeImageId(long largeImageId)
537                    throws NoSuchItemException, SystemException {
538                    ShoppingItem shoppingItem = fetchByLargeImageId(largeImageId);
539    
540                    if (shoppingItem == null) {
541                            StringBundler msg = new StringBundler(4);
542    
543                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
544    
545                            msg.append("largeImageId=");
546                            msg.append(largeImageId);
547    
548                            msg.append(StringPool.CLOSE_CURLY_BRACE);
549    
550                            if (_log.isWarnEnabled()) {
551                                    _log.warn(msg.toString());
552                            }
553    
554                            throw new NoSuchItemException(msg.toString());
555                    }
556    
557                    return shoppingItem;
558            }
559    
560            /**
561             * Returns the shopping item where largeImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
562             *
563             * @param largeImageId the large image ID
564             * @return the matching shopping item, or <code>null</code> if a matching shopping item could not be found
565             * @throws SystemException if a system exception occurred
566             */
567            public ShoppingItem fetchByLargeImageId(long largeImageId)
568                    throws SystemException {
569                    return fetchByLargeImageId(largeImageId, true);
570            }
571    
572            /**
573             * Returns the shopping item where largeImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
574             *
575             * @param largeImageId the large image ID
576             * @param retrieveFromCache whether to use the finder cache
577             * @return the matching shopping item, or <code>null</code> if a matching shopping item could not be found
578             * @throws SystemException if a system exception occurred
579             */
580            public ShoppingItem fetchByLargeImageId(long largeImageId,
581                    boolean retrieveFromCache) throws SystemException {
582                    Object[] finderArgs = new Object[] { largeImageId };
583    
584                    Object result = null;
585    
586                    if (retrieveFromCache) {
587                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
588                                            finderArgs, this);
589                    }
590    
591                    if (result instanceof ShoppingItem) {
592                            ShoppingItem shoppingItem = (ShoppingItem)result;
593    
594                            if ((largeImageId != shoppingItem.getLargeImageId())) {
595                                    result = null;
596                            }
597                    }
598    
599                    if (result == null) {
600                            StringBundler query = new StringBundler(3);
601    
602                            query.append(_SQL_SELECT_SHOPPINGITEM_WHERE);
603    
604                            query.append(_FINDER_COLUMN_LARGEIMAGEID_LARGEIMAGEID_2);
605    
606                            String sql = query.toString();
607    
608                            Session session = null;
609    
610                            try {
611                                    session = openSession();
612    
613                                    Query q = session.createQuery(sql);
614    
615                                    QueryPos qPos = QueryPos.getInstance(q);
616    
617                                    qPos.add(largeImageId);
618    
619                                    List<ShoppingItem> list = q.list();
620    
621                                    if (list.isEmpty()) {
622                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
623                                                    finderArgs, list);
624                                    }
625                                    else {
626                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
627                                                    _log.warn(
628                                                            "ShoppingItemPersistenceImpl.fetchByLargeImageId(long, boolean) with parameters (" +
629                                                            StringUtil.merge(finderArgs) +
630                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
631                                            }
632    
633                                            ShoppingItem shoppingItem = list.get(0);
634    
635                                            result = shoppingItem;
636    
637                                            cacheResult(shoppingItem);
638    
639                                            if ((shoppingItem.getLargeImageId() != largeImageId)) {
640                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
641                                                            finderArgs, shoppingItem);
642                                            }
643                                    }
644                            }
645                            catch (Exception e) {
646                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
647                                            finderArgs);
648    
649                                    throw processException(e);
650                            }
651                            finally {
652                                    closeSession(session);
653                            }
654                    }
655    
656                    if (result instanceof List<?>) {
657                            return null;
658                    }
659                    else {
660                            return (ShoppingItem)result;
661                    }
662            }
663    
664            /**
665             * Removes the shopping item where largeImageId = &#63; from the database.
666             *
667             * @param largeImageId the large image ID
668             * @return the shopping item that was removed
669             * @throws SystemException if a system exception occurred
670             */
671            public ShoppingItem removeByLargeImageId(long largeImageId)
672                    throws NoSuchItemException, SystemException {
673                    ShoppingItem shoppingItem = findByLargeImageId(largeImageId);
674    
675                    return remove(shoppingItem);
676            }
677    
678            /**
679             * Returns the number of shopping items where largeImageId = &#63;.
680             *
681             * @param largeImageId the large image ID
682             * @return the number of matching shopping items
683             * @throws SystemException if a system exception occurred
684             */
685            public int countByLargeImageId(long largeImageId) throws SystemException {
686                    FinderPath finderPath = FINDER_PATH_COUNT_BY_LARGEIMAGEID;
687    
688                    Object[] finderArgs = new Object[] { largeImageId };
689    
690                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
691                                    this);
692    
693                    if (count == null) {
694                            StringBundler query = new StringBundler(2);
695    
696                            query.append(_SQL_COUNT_SHOPPINGITEM_WHERE);
697    
698                            query.append(_FINDER_COLUMN_LARGEIMAGEID_LARGEIMAGEID_2);
699    
700                            String sql = query.toString();
701    
702                            Session session = null;
703    
704                            try {
705                                    session = openSession();
706    
707                                    Query q = session.createQuery(sql);
708    
709                                    QueryPos qPos = QueryPos.getInstance(q);
710    
711                                    qPos.add(largeImageId);
712    
713                                    count = (Long)q.uniqueResult();
714    
715                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
716                            }
717                            catch (Exception e) {
718                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
719    
720                                    throw processException(e);
721                            }
722                            finally {
723                                    closeSession(session);
724                            }
725                    }
726    
727                    return count.intValue();
728            }
729    
730            private static final String _FINDER_COLUMN_LARGEIMAGEID_LARGEIMAGEID_2 = "shoppingItem.largeImageId = ?";
731            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
732                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, ShoppingItemImpl.class,
733                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
734                            new String[] {
735                                    Long.class.getName(), Long.class.getName(),
736                                    
737                            Integer.class.getName(), Integer.class.getName(),
738                                    OrderByComparator.class.getName()
739                            });
740            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
741                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, ShoppingItemImpl.class,
742                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
743                            new String[] { Long.class.getName(), Long.class.getName() },
744                            ShoppingItemModelImpl.GROUPID_COLUMN_BITMASK |
745                            ShoppingItemModelImpl.CATEGORYID_COLUMN_BITMASK);
746            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
747                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
748                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
749                            new String[] { Long.class.getName(), Long.class.getName() });
750    
751            /**
752             * Returns all the shopping items where groupId = &#63; and categoryId = &#63;.
753             *
754             * @param groupId the group ID
755             * @param categoryId the category ID
756             * @return the matching shopping items
757             * @throws SystemException if a system exception occurred
758             */
759            public List<ShoppingItem> findByG_C(long groupId, long categoryId)
760                    throws SystemException {
761                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
762                            QueryUtil.ALL_POS, null);
763            }
764    
765            /**
766             * Returns a range of all the shopping items where groupId = &#63; and categoryId = &#63;.
767             *
768             * <p>
769             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingItemModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
770             * </p>
771             *
772             * @param groupId the group ID
773             * @param categoryId the category ID
774             * @param start the lower bound of the range of shopping items
775             * @param end the upper bound of the range of shopping items (not inclusive)
776             * @return the range of matching shopping items
777             * @throws SystemException if a system exception occurred
778             */
779            public List<ShoppingItem> findByG_C(long groupId, long categoryId,
780                    int start, int end) throws SystemException {
781                    return findByG_C(groupId, categoryId, start, end, null);
782            }
783    
784            /**
785             * Returns an ordered range of all the shopping items where groupId = &#63; and categoryId = &#63;.
786             *
787             * <p>
788             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingItemModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
789             * </p>
790             *
791             * @param groupId the group ID
792             * @param categoryId the category ID
793             * @param start the lower bound of the range of shopping items
794             * @param end the upper bound of the range of shopping items (not inclusive)
795             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
796             * @return the ordered range of matching shopping items
797             * @throws SystemException if a system exception occurred
798             */
799            public List<ShoppingItem> findByG_C(long groupId, long categoryId,
800                    int start, int end, OrderByComparator orderByComparator)
801                    throws SystemException {
802                    boolean pagination = true;
803                    FinderPath finderPath = null;
804                    Object[] finderArgs = null;
805    
806                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
807                                    (orderByComparator == null)) {
808                            pagination = false;
809                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
810                            finderArgs = new Object[] { groupId, categoryId };
811                    }
812                    else {
813                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
814                            finderArgs = new Object[] {
815                                            groupId, categoryId,
816                                            
817                                            start, end, orderByComparator
818                                    };
819                    }
820    
821                    List<ShoppingItem> list = (List<ShoppingItem>)FinderCacheUtil.getResult(finderPath,
822                                    finderArgs, this);
823    
824                    if ((list != null) && !list.isEmpty()) {
825                            for (ShoppingItem shoppingItem : list) {
826                                    if ((groupId != shoppingItem.getGroupId()) ||
827                                                    (categoryId != shoppingItem.getCategoryId())) {
828                                            list = null;
829    
830                                            break;
831                                    }
832                            }
833                    }
834    
835                    if (list == null) {
836                            StringBundler query = null;
837    
838                            if (orderByComparator != null) {
839                                    query = new StringBundler(4 +
840                                                    (orderByComparator.getOrderByFields().length * 3));
841                            }
842                            else {
843                                    query = new StringBundler(4);
844                            }
845    
846                            query.append(_SQL_SELECT_SHOPPINGITEM_WHERE);
847    
848                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
849    
850                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
851    
852                            if (orderByComparator != null) {
853                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
854                                            orderByComparator);
855                            }
856                            else
857                             if (pagination) {
858                                    query.append(ShoppingItemModelImpl.ORDER_BY_JPQL);
859                            }
860    
861                            String sql = query.toString();
862    
863                            Session session = null;
864    
865                            try {
866                                    session = openSession();
867    
868                                    Query q = session.createQuery(sql);
869    
870                                    QueryPos qPos = QueryPos.getInstance(q);
871    
872                                    qPos.add(groupId);
873    
874                                    qPos.add(categoryId);
875    
876                                    if (!pagination) {
877                                            list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
878                                                            start, end, false);
879    
880                                            Collections.sort(list);
881    
882                                            list = new UnmodifiableList<ShoppingItem>(list);
883                                    }
884                                    else {
885                                            list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
886                                                            start, end);
887                                    }
888    
889                                    cacheResult(list);
890    
891                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
892                            }
893                            catch (Exception e) {
894                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
895    
896                                    throw processException(e);
897                            }
898                            finally {
899                                    closeSession(session);
900                            }
901                    }
902    
903                    return list;
904            }
905    
906            /**
907             * Returns the first shopping item in the ordered set where groupId = &#63; and categoryId = &#63;.
908             *
909             * @param groupId the group ID
910             * @param categoryId the category ID
911             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
912             * @return the first matching shopping item
913             * @throws com.liferay.portlet.shopping.NoSuchItemException if a matching shopping item could not be found
914             * @throws SystemException if a system exception occurred
915             */
916            public ShoppingItem findByG_C_First(long groupId, long categoryId,
917                    OrderByComparator orderByComparator)
918                    throws NoSuchItemException, SystemException {
919                    ShoppingItem shoppingItem = fetchByG_C_First(groupId, categoryId,
920                                    orderByComparator);
921    
922                    if (shoppingItem != null) {
923                            return shoppingItem;
924                    }
925    
926                    StringBundler msg = new StringBundler(6);
927    
928                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
929    
930                    msg.append("groupId=");
931                    msg.append(groupId);
932    
933                    msg.append(", categoryId=");
934                    msg.append(categoryId);
935    
936                    msg.append(StringPool.CLOSE_CURLY_BRACE);
937    
938                    throw new NoSuchItemException(msg.toString());
939            }
940    
941            /**
942             * Returns the first shopping item in the ordered set where groupId = &#63; and categoryId = &#63;.
943             *
944             * @param groupId the group ID
945             * @param categoryId the category ID
946             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
947             * @return the first matching shopping item, or <code>null</code> if a matching shopping item could not be found
948             * @throws SystemException if a system exception occurred
949             */
950            public ShoppingItem fetchByG_C_First(long groupId, long categoryId,
951                    OrderByComparator orderByComparator) throws SystemException {
952                    List<ShoppingItem> list = findByG_C(groupId, categoryId, 0, 1,
953                                    orderByComparator);
954    
955                    if (!list.isEmpty()) {
956                            return list.get(0);
957                    }
958    
959                    return null;
960            }
961    
962            /**
963             * Returns the last shopping item in the ordered set where groupId = &#63; and categoryId = &#63;.
964             *
965             * @param groupId the group ID
966             * @param categoryId the category ID
967             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
968             * @return the last matching shopping item
969             * @throws com.liferay.portlet.shopping.NoSuchItemException if a matching shopping item could not be found
970             * @throws SystemException if a system exception occurred
971             */
972            public ShoppingItem findByG_C_Last(long groupId, long categoryId,
973                    OrderByComparator orderByComparator)
974                    throws NoSuchItemException, SystemException {
975                    ShoppingItem shoppingItem = fetchByG_C_Last(groupId, categoryId,
976                                    orderByComparator);
977    
978                    if (shoppingItem != null) {
979                            return shoppingItem;
980                    }
981    
982                    StringBundler msg = new StringBundler(6);
983    
984                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
985    
986                    msg.append("groupId=");
987                    msg.append(groupId);
988    
989                    msg.append(", categoryId=");
990                    msg.append(categoryId);
991    
992                    msg.append(StringPool.CLOSE_CURLY_BRACE);
993    
994                    throw new NoSuchItemException(msg.toString());
995            }
996    
997            /**
998             * Returns the last shopping item in the ordered set where groupId = &#63; and categoryId = &#63;.
999             *
1000             * @param groupId the group ID
1001             * @param categoryId the category ID
1002             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1003             * @return the last matching shopping item, or <code>null</code> if a matching shopping item could not be found
1004             * @throws SystemException if a system exception occurred
1005             */
1006            public ShoppingItem fetchByG_C_Last(long groupId, long categoryId,
1007                    OrderByComparator orderByComparator) throws SystemException {
1008                    int count = countByG_C(groupId, categoryId);
1009    
1010                    List<ShoppingItem> list = findByG_C(groupId, categoryId, count - 1,
1011                                    count, orderByComparator);
1012    
1013                    if (!list.isEmpty()) {
1014                            return list.get(0);
1015                    }
1016    
1017                    return null;
1018            }
1019    
1020            /**
1021             * Returns the shopping items before and after the current shopping item in the ordered set where groupId = &#63; and categoryId = &#63;.
1022             *
1023             * @param itemId the primary key of the current shopping item
1024             * @param groupId the group ID
1025             * @param categoryId the category ID
1026             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1027             * @return the previous, current, and next shopping item
1028             * @throws com.liferay.portlet.shopping.NoSuchItemException if a shopping item with the primary key could not be found
1029             * @throws SystemException if a system exception occurred
1030             */
1031            public ShoppingItem[] findByG_C_PrevAndNext(long itemId, long groupId,
1032                    long categoryId, OrderByComparator orderByComparator)
1033                    throws NoSuchItemException, SystemException {
1034                    ShoppingItem shoppingItem = findByPrimaryKey(itemId);
1035    
1036                    Session session = null;
1037    
1038                    try {
1039                            session = openSession();
1040    
1041                            ShoppingItem[] array = new ShoppingItemImpl[3];
1042    
1043                            array[0] = getByG_C_PrevAndNext(session, shoppingItem, groupId,
1044                                            categoryId, orderByComparator, true);
1045    
1046                            array[1] = shoppingItem;
1047    
1048                            array[2] = getByG_C_PrevAndNext(session, shoppingItem, groupId,
1049                                            categoryId, orderByComparator, false);
1050    
1051                            return array;
1052                    }
1053                    catch (Exception e) {
1054                            throw processException(e);
1055                    }
1056                    finally {
1057                            closeSession(session);
1058                    }
1059            }
1060    
1061            protected ShoppingItem getByG_C_PrevAndNext(Session session,
1062                    ShoppingItem shoppingItem, long groupId, long categoryId,
1063                    OrderByComparator orderByComparator, boolean previous) {
1064                    StringBundler query = null;
1065    
1066                    if (orderByComparator != null) {
1067                            query = new StringBundler(6 +
1068                                            (orderByComparator.getOrderByFields().length * 6));
1069                    }
1070                    else {
1071                            query = new StringBundler(3);
1072                    }
1073    
1074                    query.append(_SQL_SELECT_SHOPPINGITEM_WHERE);
1075    
1076                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1077    
1078                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1079    
1080                    if (orderByComparator != null) {
1081                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1082    
1083                            if (orderByConditionFields.length > 0) {
1084                                    query.append(WHERE_AND);
1085                            }
1086    
1087                            for (int i = 0; i < orderByConditionFields.length; i++) {
1088                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1089                                    query.append(orderByConditionFields[i]);
1090    
1091                                    if ((i + 1) < orderByConditionFields.length) {
1092                                            if (orderByComparator.isAscending() ^ previous) {
1093                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1094                                            }
1095                                            else {
1096                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1097                                            }
1098                                    }
1099                                    else {
1100                                            if (orderByComparator.isAscending() ^ previous) {
1101                                                    query.append(WHERE_GREATER_THAN);
1102                                            }
1103                                            else {
1104                                                    query.append(WHERE_LESSER_THAN);
1105                                            }
1106                                    }
1107                            }
1108    
1109                            query.append(ORDER_BY_CLAUSE);
1110    
1111                            String[] orderByFields = orderByComparator.getOrderByFields();
1112    
1113                            for (int i = 0; i < orderByFields.length; i++) {
1114                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1115                                    query.append(orderByFields[i]);
1116    
1117                                    if ((i + 1) < orderByFields.length) {
1118                                            if (orderByComparator.isAscending() ^ previous) {
1119                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1120                                            }
1121                                            else {
1122                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1123                                            }
1124                                    }
1125                                    else {
1126                                            if (orderByComparator.isAscending() ^ previous) {
1127                                                    query.append(ORDER_BY_ASC);
1128                                            }
1129                                            else {
1130                                                    query.append(ORDER_BY_DESC);
1131                                            }
1132                                    }
1133                            }
1134                    }
1135                    else {
1136                            query.append(ShoppingItemModelImpl.ORDER_BY_JPQL);
1137                    }
1138    
1139                    String sql = query.toString();
1140    
1141                    Query q = session.createQuery(sql);
1142    
1143                    q.setFirstResult(0);
1144                    q.setMaxResults(2);
1145    
1146                    QueryPos qPos = QueryPos.getInstance(q);
1147    
1148                    qPos.add(groupId);
1149    
1150                    qPos.add(categoryId);
1151    
1152                    if (orderByComparator != null) {
1153                            Object[] values = orderByComparator.getOrderByConditionValues(shoppingItem);
1154    
1155                            for (Object value : values) {
1156                                    qPos.add(value);
1157                            }
1158                    }
1159    
1160                    List<ShoppingItem> list = q.list();
1161    
1162                    if (list.size() == 2) {
1163                            return list.get(1);
1164                    }
1165                    else {
1166                            return null;
1167                    }
1168            }
1169    
1170            /**
1171             * Returns all the shopping items that the user has permission to view where groupId = &#63; and categoryId = &#63;.
1172             *
1173             * @param groupId the group ID
1174             * @param categoryId the category ID
1175             * @return the matching shopping items that the user has permission to view
1176             * @throws SystemException if a system exception occurred
1177             */
1178            public List<ShoppingItem> filterFindByG_C(long groupId, long categoryId)
1179                    throws SystemException {
1180                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
1181                            QueryUtil.ALL_POS, null);
1182            }
1183    
1184            /**
1185             * Returns a range of all the shopping items that the user has permission to view where groupId = &#63; and categoryId = &#63;.
1186             *
1187             * <p>
1188             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingItemModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1189             * </p>
1190             *
1191             * @param groupId the group ID
1192             * @param categoryId the category ID
1193             * @param start the lower bound of the range of shopping items
1194             * @param end the upper bound of the range of shopping items (not inclusive)
1195             * @return the range of matching shopping items that the user has permission to view
1196             * @throws SystemException if a system exception occurred
1197             */
1198            public List<ShoppingItem> filterFindByG_C(long groupId, long categoryId,
1199                    int start, int end) throws SystemException {
1200                    return filterFindByG_C(groupId, categoryId, start, end, null);
1201            }
1202    
1203            /**
1204             * Returns an ordered range of all the shopping items that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
1205             *
1206             * <p>
1207             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingItemModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1208             * </p>
1209             *
1210             * @param groupId the group ID
1211             * @param categoryId the category ID
1212             * @param start the lower bound of the range of shopping items
1213             * @param end the upper bound of the range of shopping items (not inclusive)
1214             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1215             * @return the ordered range of matching shopping items that the user has permission to view
1216             * @throws SystemException if a system exception occurred
1217             */
1218            public List<ShoppingItem> filterFindByG_C(long groupId, long categoryId,
1219                    int start, int end, OrderByComparator orderByComparator)
1220                    throws SystemException {
1221                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1222                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
1223                    }
1224    
1225                    StringBundler query = null;
1226    
1227                    if (orderByComparator != null) {
1228                            query = new StringBundler(4 +
1229                                            (orderByComparator.getOrderByFields().length * 3));
1230                    }
1231                    else {
1232                            query = new StringBundler(4);
1233                    }
1234    
1235                    if (getDB().isSupportsInlineDistinct()) {
1236                            query.append(_FILTER_SQL_SELECT_SHOPPINGITEM_WHERE);
1237                    }
1238                    else {
1239                            query.append(_FILTER_SQL_SELECT_SHOPPINGITEM_NO_INLINE_DISTINCT_WHERE_1);
1240                    }
1241    
1242                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1243    
1244                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1245    
1246                    if (!getDB().isSupportsInlineDistinct()) {
1247                            query.append(_FILTER_SQL_SELECT_SHOPPINGITEM_NO_INLINE_DISTINCT_WHERE_2);
1248                    }
1249    
1250                    if (orderByComparator != null) {
1251                            if (getDB().isSupportsInlineDistinct()) {
1252                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1253                                            orderByComparator);
1254                            }
1255                            else {
1256                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1257                                            orderByComparator);
1258                            }
1259                    }
1260                    else {
1261                            if (getDB().isSupportsInlineDistinct()) {
1262                                    query.append(ShoppingItemModelImpl.ORDER_BY_JPQL);
1263                            }
1264                            else {
1265                                    query.append(ShoppingItemModelImpl.ORDER_BY_SQL);
1266                            }
1267                    }
1268    
1269                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1270                                    ShoppingItem.class.getName(),
1271                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1272    
1273                    Session session = null;
1274    
1275                    try {
1276                            session = openSession();
1277    
1278                            SQLQuery q = session.createSQLQuery(sql);
1279    
1280                            if (getDB().isSupportsInlineDistinct()) {
1281                                    q.addEntity(_FILTER_ENTITY_ALIAS, ShoppingItemImpl.class);
1282                            }
1283                            else {
1284                                    q.addEntity(_FILTER_ENTITY_TABLE, ShoppingItemImpl.class);
1285                            }
1286    
1287                            QueryPos qPos = QueryPos.getInstance(q);
1288    
1289                            qPos.add(groupId);
1290    
1291                            qPos.add(categoryId);
1292    
1293                            return (List<ShoppingItem>)QueryUtil.list(q, getDialect(), start,
1294                                    end);
1295                    }
1296                    catch (Exception e) {
1297                            throw processException(e);
1298                    }
1299                    finally {
1300                            closeSession(session);
1301                    }
1302            }
1303    
1304            /**
1305             * Returns the shopping items before and after the current shopping item in the ordered set of shopping items that the user has permission to view where groupId = &#63; and categoryId = &#63;.
1306             *
1307             * @param itemId the primary key of the current shopping item
1308             * @param groupId the group ID
1309             * @param categoryId the category ID
1310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1311             * @return the previous, current, and next shopping item
1312             * @throws com.liferay.portlet.shopping.NoSuchItemException if a shopping item with the primary key could not be found
1313             * @throws SystemException if a system exception occurred
1314             */
1315            public ShoppingItem[] filterFindByG_C_PrevAndNext(long itemId,
1316                    long groupId, long categoryId, OrderByComparator orderByComparator)
1317                    throws NoSuchItemException, SystemException {
1318                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1319                            return findByG_C_PrevAndNext(itemId, groupId, categoryId,
1320                                    orderByComparator);
1321                    }
1322    
1323                    ShoppingItem shoppingItem = findByPrimaryKey(itemId);
1324    
1325                    Session session = null;
1326    
1327                    try {
1328                            session = openSession();
1329    
1330                            ShoppingItem[] array = new ShoppingItemImpl[3];
1331    
1332                            array[0] = filterGetByG_C_PrevAndNext(session, shoppingItem,
1333                                            groupId, categoryId, orderByComparator, true);
1334    
1335                            array[1] = shoppingItem;
1336    
1337                            array[2] = filterGetByG_C_PrevAndNext(session, shoppingItem,
1338                                            groupId, categoryId, orderByComparator, false);
1339    
1340                            return array;
1341                    }
1342                    catch (Exception e) {
1343                            throw processException(e);
1344                    }
1345                    finally {
1346                            closeSession(session);
1347                    }
1348            }
1349    
1350            protected ShoppingItem filterGetByG_C_PrevAndNext(Session session,
1351                    ShoppingItem shoppingItem, long groupId, long categoryId,
1352                    OrderByComparator orderByComparator, boolean previous) {
1353                    StringBundler query = null;
1354    
1355                    if (orderByComparator != null) {
1356                            query = new StringBundler(6 +
1357                                            (orderByComparator.getOrderByFields().length * 6));
1358                    }
1359                    else {
1360                            query = new StringBundler(3);
1361                    }
1362    
1363                    if (getDB().isSupportsInlineDistinct()) {
1364                            query.append(_FILTER_SQL_SELECT_SHOPPINGITEM_WHERE);
1365                    }
1366                    else {
1367                            query.append(_FILTER_SQL_SELECT_SHOPPINGITEM_NO_INLINE_DISTINCT_WHERE_1);
1368                    }
1369    
1370                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1371    
1372                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1373    
1374                    if (!getDB().isSupportsInlineDistinct()) {
1375                            query.append(_FILTER_SQL_SELECT_SHOPPINGITEM_NO_INLINE_DISTINCT_WHERE_2);
1376                    }
1377    
1378                    if (orderByComparator != null) {
1379                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1380    
1381                            if (orderByConditionFields.length > 0) {
1382                                    query.append(WHERE_AND);
1383                            }
1384    
1385                            for (int i = 0; i < orderByConditionFields.length; i++) {
1386                                    if (getDB().isSupportsInlineDistinct()) {
1387                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1388                                    }
1389                                    else {
1390                                            query.append(_ORDER_BY_ENTITY_TABLE);
1391                                    }
1392    
1393                                    query.append(orderByConditionFields[i]);
1394    
1395                                    if ((i + 1) < orderByConditionFields.length) {
1396                                            if (orderByComparator.isAscending() ^ previous) {
1397                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1398                                            }
1399                                            else {
1400                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1401                                            }
1402                                    }
1403                                    else {
1404                                            if (orderByComparator.isAscending() ^ previous) {
1405                                                    query.append(WHERE_GREATER_THAN);
1406                                            }
1407                                            else {
1408                                                    query.append(WHERE_LESSER_THAN);
1409                                            }
1410                                    }
1411                            }
1412    
1413                            query.append(ORDER_BY_CLAUSE);
1414    
1415                            String[] orderByFields = orderByComparator.getOrderByFields();
1416    
1417                            for (int i = 0; i < orderByFields.length; i++) {
1418                                    if (getDB().isSupportsInlineDistinct()) {
1419                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1420                                    }
1421                                    else {
1422                                            query.append(_ORDER_BY_ENTITY_TABLE);
1423                                    }
1424    
1425                                    query.append(orderByFields[i]);
1426    
1427                                    if ((i + 1) < orderByFields.length) {
1428                                            if (orderByComparator.isAscending() ^ previous) {
1429                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1430                                            }
1431                                            else {
1432                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1433                                            }
1434                                    }
1435                                    else {
1436                                            if (orderByComparator.isAscending() ^ previous) {
1437                                                    query.append(ORDER_BY_ASC);
1438                                            }
1439                                            else {
1440                                                    query.append(ORDER_BY_DESC);
1441                                            }
1442                                    }
1443                            }
1444                    }
1445                    else {
1446                            if (getDB().isSupportsInlineDistinct()) {
1447                                    query.append(ShoppingItemModelImpl.ORDER_BY_JPQL);
1448                            }
1449                            else {
1450                                    query.append(ShoppingItemModelImpl.ORDER_BY_SQL);
1451                            }
1452                    }
1453    
1454                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1455                                    ShoppingItem.class.getName(),
1456                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1457    
1458                    SQLQuery q = session.createSQLQuery(sql);
1459    
1460                    q.setFirstResult(0);
1461                    q.setMaxResults(2);
1462    
1463                    if (getDB().isSupportsInlineDistinct()) {
1464                            q.addEntity(_FILTER_ENTITY_ALIAS, ShoppingItemImpl.class);
1465                    }
1466                    else {
1467                            q.addEntity(_FILTER_ENTITY_TABLE, ShoppingItemImpl.class);
1468                    }
1469    
1470                    QueryPos qPos = QueryPos.getInstance(q);
1471    
1472                    qPos.add(groupId);
1473    
1474                    qPos.add(categoryId);
1475    
1476                    if (orderByComparator != null) {
1477                            Object[] values = orderByComparator.getOrderByConditionValues(shoppingItem);
1478    
1479                            for (Object value : values) {
1480                                    qPos.add(value);
1481                            }
1482                    }
1483    
1484                    List<ShoppingItem> list = q.list();
1485    
1486                    if (list.size() == 2) {
1487                            return list.get(1);
1488                    }
1489                    else {
1490                            return null;
1491                    }
1492            }
1493    
1494            /**
1495             * Removes all the shopping items where groupId = &#63; and categoryId = &#63; from the database.
1496             *
1497             * @param groupId the group ID
1498             * @param categoryId the category ID
1499             * @throws SystemException if a system exception occurred
1500             */
1501            public void removeByG_C(long groupId, long categoryId)
1502                    throws SystemException {
1503                    for (ShoppingItem shoppingItem : findByG_C(groupId, categoryId,
1504                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1505                            remove(shoppingItem);
1506                    }
1507            }
1508    
1509            /**
1510             * Returns the number of shopping items where groupId = &#63; and categoryId = &#63;.
1511             *
1512             * @param groupId the group ID
1513             * @param categoryId the category ID
1514             * @return the number of matching shopping items
1515             * @throws SystemException if a system exception occurred
1516             */
1517            public int countByG_C(long groupId, long categoryId)
1518                    throws SystemException {
1519                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
1520    
1521                    Object[] finderArgs = new Object[] { groupId, categoryId };
1522    
1523                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1524                                    this);
1525    
1526                    if (count == null) {
1527                            StringBundler query = new StringBundler(3);
1528    
1529                            query.append(_SQL_COUNT_SHOPPINGITEM_WHERE);
1530    
1531                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1532    
1533                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1534    
1535                            String sql = query.toString();
1536    
1537                            Session session = null;
1538    
1539                            try {
1540                                    session = openSession();
1541    
1542                                    Query q = session.createQuery(sql);
1543    
1544                                    QueryPos qPos = QueryPos.getInstance(q);
1545    
1546                                    qPos.add(groupId);
1547    
1548                                    qPos.add(categoryId);
1549    
1550                                    count = (Long)q.uniqueResult();
1551    
1552                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1553                            }
1554                            catch (Exception e) {
1555                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1556    
1557                                    throw processException(e);
1558                            }
1559                            finally {
1560                                    closeSession(session);
1561                            }
1562                    }
1563    
1564                    return count.intValue();
1565            }
1566    
1567            /**
1568             * Returns the number of shopping items that the user has permission to view where groupId = &#63; and categoryId = &#63;.
1569             *
1570             * @param groupId the group ID
1571             * @param categoryId the category ID
1572             * @return the number of matching shopping items that the user has permission to view
1573             * @throws SystemException if a system exception occurred
1574             */
1575            public int filterCountByG_C(long groupId, long categoryId)
1576                    throws SystemException {
1577                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1578                            return countByG_C(groupId, categoryId);
1579                    }
1580    
1581                    StringBundler query = new StringBundler(3);
1582    
1583                    query.append(_FILTER_SQL_COUNT_SHOPPINGITEM_WHERE);
1584    
1585                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1586    
1587                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1588    
1589                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1590                                    ShoppingItem.class.getName(),
1591                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1592    
1593                    Session session = null;
1594    
1595                    try {
1596                            session = openSession();
1597    
1598                            SQLQuery q = session.createSQLQuery(sql);
1599    
1600                            q.addScalar(COUNT_COLUMN_NAME,
1601                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1602    
1603                            QueryPos qPos = QueryPos.getInstance(q);
1604    
1605                            qPos.add(groupId);
1606    
1607                            qPos.add(categoryId);
1608    
1609                            Long count = (Long)q.uniqueResult();
1610    
1611                            return count.intValue();
1612                    }
1613                    catch (Exception e) {
1614                            throw processException(e);
1615                    }
1616                    finally {
1617                            closeSession(session);
1618                    }
1619            }
1620    
1621            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "shoppingItem.groupId = ? AND ";
1622            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "shoppingItem.categoryId = ?";
1623            public static final FinderPath FINDER_PATH_FETCH_BY_C_S = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
1624                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, ShoppingItemImpl.class,
1625                            FINDER_CLASS_NAME_ENTITY, "fetchByC_S",
1626                            new String[] { Long.class.getName(), String.class.getName() },
1627                            ShoppingItemModelImpl.COMPANYID_COLUMN_BITMASK |
1628                            ShoppingItemModelImpl.SKU_COLUMN_BITMASK);
1629            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
1630                            ShoppingItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
1631                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
1632                            new String[] { Long.class.getName(), String.class.getName() });
1633    
1634            /**
1635             * Returns the shopping item where companyId = &#63; and sku = &#63; or throws a {@link com.liferay.portlet.shopping.NoSuchItemException} if it could not be found.
1636             *
1637             * @param companyId the company ID
1638             * @param sku the sku
1639             * @return the matching shopping item
1640             * @throws com.liferay.portlet.shopping.NoSuchItemException if a matching shopping item could not be found
1641             * @throws SystemException if a system exception occurred
1642             */
1643            public ShoppingItem findByC_S(long companyId, String sku)
1644                    throws NoSuchItemException, SystemException {
1645                    ShoppingItem shoppingItem = fetchByC_S(companyId, sku);
1646    
1647                    if (shoppingItem == null) {
1648                            StringBundler msg = new StringBundler(6);
1649    
1650                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1651    
1652                            msg.append("companyId=");
1653                            msg.append(companyId);
1654    
1655                            msg.append(", sku=");
1656                            msg.append(sku);
1657    
1658                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1659    
1660                            if (_log.isWarnEnabled()) {
1661                                    _log.warn(msg.toString());
1662                            }
1663    
1664                            throw new NoSuchItemException(msg.toString());
1665                    }
1666    
1667                    return shoppingItem;
1668            }
1669    
1670            /**
1671             * Returns the shopping item where companyId = &#63; and sku = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1672             *
1673             * @param companyId the company ID
1674             * @param sku the sku
1675             * @return the matching shopping item, or <code>null</code> if a matching shopping item could not be found
1676             * @throws SystemException if a system exception occurred
1677             */
1678            public ShoppingItem fetchByC_S(long companyId, String sku)
1679                    throws SystemException {
1680                    return fetchByC_S(companyId, sku, true);
1681            }
1682    
1683            /**
1684             * Returns the shopping item where companyId = &#63; and sku = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1685             *
1686             * @param companyId the company ID
1687             * @param sku the sku
1688             * @param retrieveFromCache whether to use the finder cache
1689             * @return the matching shopping item, or <code>null</code> if a matching shopping item could not be found
1690             * @throws SystemException if a system exception occurred
1691             */
1692            public ShoppingItem fetchByC_S(long companyId, String sku,
1693                    boolean retrieveFromCache) throws SystemException {
1694                    Object[] finderArgs = new Object[] { companyId, sku };
1695    
1696                    Object result = null;
1697    
1698                    if (retrieveFromCache) {
1699                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_S,
1700                                            finderArgs, this);
1701                    }
1702    
1703                    if (result instanceof ShoppingItem) {
1704                            ShoppingItem shoppingItem = (ShoppingItem)result;
1705    
1706                            if ((companyId != shoppingItem.getCompanyId()) ||
1707                                            !Validator.equals(sku, shoppingItem.getSku())) {
1708                                    result = null;
1709                            }
1710                    }
1711    
1712                    if (result == null) {
1713                            StringBundler query = new StringBundler(4);
1714    
1715                            query.append(_SQL_SELECT_SHOPPINGITEM_WHERE);
1716    
1717                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
1718    
1719                            if (sku == null) {
1720                                    query.append(_FINDER_COLUMN_C_S_SKU_1);
1721                            }
1722                            else {
1723                                    if (sku.equals(StringPool.BLANK)) {
1724                                            query.append(_FINDER_COLUMN_C_S_SKU_3);
1725                                    }
1726                                    else {
1727                                            query.append(_FINDER_COLUMN_C_S_SKU_2);
1728                                    }
1729                            }
1730    
1731                            String sql = query.toString();
1732    
1733                            Session session = null;
1734    
1735                            try {
1736                                    session = openSession();
1737    
1738                                    Query q = session.createQuery(sql);
1739    
1740                                    QueryPos qPos = QueryPos.getInstance(q);
1741    
1742                                    qPos.add(companyId);
1743    
1744                                    if (sku != null) {
1745                                            qPos.add(sku);
1746                                    }
1747    
1748                                    List<ShoppingItem> list = q.list();
1749    
1750                                    if (list.isEmpty()) {
1751                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S,
1752                                                    finderArgs, list);
1753                                    }
1754                                    else {
1755                                            ShoppingItem shoppingItem = list.get(0);
1756    
1757                                            result = shoppingItem;
1758    
1759                                            cacheResult(shoppingItem);
1760    
1761                                            if ((shoppingItem.getCompanyId() != companyId) ||
1762                                                            (shoppingItem.getSku() == null) ||
1763                                                            !shoppingItem.getSku().equals(sku)) {
1764                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S,
1765                                                            finderArgs, shoppingItem);
1766                                            }
1767                                    }
1768                            }
1769                            catch (Exception e) {
1770                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_S,
1771                                            finderArgs);
1772    
1773                                    throw processException(e);
1774                            }
1775                            finally {
1776                                    closeSession(session);
1777                            }
1778                    }
1779    
1780                    if (result instanceof List<?>) {
1781                            return null;
1782                    }
1783                    else {
1784                            return (ShoppingItem)result;
1785                    }
1786            }
1787    
1788            /**
1789             * Removes the shopping item where companyId = &#63; and sku = &#63; from the database.
1790             *
1791             * @param companyId the company ID
1792             * @param sku the sku
1793             * @return the shopping item that was removed
1794             * @throws SystemException if a system exception occurred
1795             */
1796            public ShoppingItem removeByC_S(long companyId, String sku)
1797                    throws NoSuchItemException, SystemException {
1798                    ShoppingItem shoppingItem = findByC_S(companyId, sku);
1799    
1800                    return remove(shoppingItem);
1801            }
1802    
1803            /**
1804             * Returns the number of shopping items where companyId = &#63; and sku = &#63;.
1805             *
1806             * @param companyId the company ID
1807             * @param sku the sku
1808             * @return the number of matching shopping items
1809             * @throws SystemException if a system exception occurred
1810             */
1811            public int countByC_S(long companyId, String sku) throws SystemException {
1812                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
1813    
1814                    Object[] finderArgs = new Object[] { companyId, sku };
1815    
1816                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1817                                    this);
1818    
1819                    if (count == null) {
1820                            StringBundler query = new StringBundler(3);
1821    
1822                            query.append(_SQL_COUNT_SHOPPINGITEM_WHERE);
1823    
1824                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
1825    
1826                            if (sku == null) {
1827                                    query.append(_FINDER_COLUMN_C_S_SKU_1);
1828                            }
1829                            else {
1830                                    if (sku.equals(StringPool.BLANK)) {
1831                                            query.append(_FINDER_COLUMN_C_S_SKU_3);
1832                                    }
1833                                    else {
1834                                            query.append(_FINDER_COLUMN_C_S_SKU_2);
1835                                    }
1836                            }
1837    
1838                            String sql = query.toString();
1839    
1840                            Session session = null;
1841    
1842                            try {
1843                                    session = openSession();
1844    
1845                                    Query q = session.createQuery(sql);
1846    
1847                                    QueryPos qPos = QueryPos.getInstance(q);
1848    
1849                                    qPos.add(companyId);
1850    
1851                                    if (sku != null) {
1852                                            qPos.add(sku);
1853                                    }
1854    
1855                                    count = (Long)q.uniqueResult();
1856    
1857                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1858                            }
1859                            catch (Exception e) {
1860                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1861    
1862                                    throw processException(e);
1863                            }
1864                            finally {
1865                                    closeSession(session);
1866                            }
1867                    }
1868    
1869                    return count.intValue();
1870            }
1871    
1872            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "shoppingItem.companyId = ? AND ";
1873            private static final String _FINDER_COLUMN_C_S_SKU_1 = "shoppingItem.sku IS NULL";
1874            private static final String _FINDER_COLUMN_C_S_SKU_2 = "shoppingItem.sku = ?";
1875            private static final String _FINDER_COLUMN_C_S_SKU_3 = "(shoppingItem.sku IS NULL OR shoppingItem.sku = ?)";
1876    
1877            /**
1878             * Caches the shopping item in the entity cache if it is enabled.
1879             *
1880             * @param shoppingItem the shopping item
1881             */
1882            public void cacheResult(ShoppingItem shoppingItem) {
1883                    EntityCacheUtil.putResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
1884                            ShoppingItemImpl.class, shoppingItem.getPrimaryKey(), shoppingItem);
1885    
1886                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1887                            new Object[] { Long.valueOf(shoppingItem.getSmallImageId()) },
1888                            shoppingItem);
1889    
1890                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
1891                            new Object[] { Long.valueOf(shoppingItem.getMediumImageId()) },
1892                            shoppingItem);
1893    
1894                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1895                            new Object[] { Long.valueOf(shoppingItem.getLargeImageId()) },
1896                            shoppingItem);
1897    
1898                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S,
1899                            new Object[] {
1900                                    Long.valueOf(shoppingItem.getCompanyId()),
1901                                    
1902                            shoppingItem.getSku()
1903                            }, shoppingItem);
1904    
1905                    shoppingItem.resetOriginalValues();
1906            }
1907    
1908            /**
1909             * Caches the shopping items in the entity cache if it is enabled.
1910             *
1911             * @param shoppingItems the shopping items
1912             */
1913            public void cacheResult(List<ShoppingItem> shoppingItems) {
1914                    for (ShoppingItem shoppingItem : shoppingItems) {
1915                            if (EntityCacheUtil.getResult(
1916                                                    ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
1917                                                    ShoppingItemImpl.class, shoppingItem.getPrimaryKey()) == null) {
1918                                    cacheResult(shoppingItem);
1919                            }
1920                            else {
1921                                    shoppingItem.resetOriginalValues();
1922                            }
1923                    }
1924            }
1925    
1926            /**
1927             * Clears the cache for all shopping items.
1928             *
1929             * <p>
1930             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1931             * </p>
1932             */
1933            @Override
1934            public void clearCache() {
1935                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1936                            CacheRegistryUtil.clear(ShoppingItemImpl.class.getName());
1937                    }
1938    
1939                    EntityCacheUtil.clearCache(ShoppingItemImpl.class.getName());
1940    
1941                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1942                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1943                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1944            }
1945    
1946            /**
1947             * Clears the cache for the shopping item.
1948             *
1949             * <p>
1950             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1951             * </p>
1952             */
1953            @Override
1954            public void clearCache(ShoppingItem shoppingItem) {
1955                    EntityCacheUtil.removeResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
1956                            ShoppingItemImpl.class, shoppingItem.getPrimaryKey());
1957    
1958                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1959                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1960    
1961                    clearUniqueFindersCache(shoppingItem);
1962            }
1963    
1964            @Override
1965            public void clearCache(List<ShoppingItem> shoppingItems) {
1966                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1967                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1968    
1969                    for (ShoppingItem shoppingItem : shoppingItems) {
1970                            EntityCacheUtil.removeResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
1971                                    ShoppingItemImpl.class, shoppingItem.getPrimaryKey());
1972    
1973                            clearUniqueFindersCache(shoppingItem);
1974                    }
1975            }
1976    
1977            protected void cacheUniqueFindersCache(ShoppingItem shoppingItem) {
1978                    if (shoppingItem.isNew()) {
1979                            Object[] args = new Object[] {
1980                                            Long.valueOf(shoppingItem.getSmallImageId())
1981                                    };
1982    
1983                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args,
1984                                    Long.valueOf(1));
1985                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args,
1986                                    shoppingItem);
1987    
1988                            args = new Object[] { Long.valueOf(shoppingItem.getMediumImageId()) };
1989    
1990                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MEDIUMIMAGEID, args,
1991                                    Long.valueOf(1));
1992                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID, args,
1993                                    shoppingItem);
1994    
1995                            args = new Object[] { Long.valueOf(shoppingItem.getLargeImageId()) };
1996    
1997                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID, args,
1998                                    Long.valueOf(1));
1999                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID, args,
2000                                    shoppingItem);
2001    
2002                            args = new Object[] {
2003                                            Long.valueOf(shoppingItem.getCompanyId()),
2004                                            
2005                                            shoppingItem.getSku()
2006                                    };
2007    
2008                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, args,
2009                                    Long.valueOf(1));
2010                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S, args,
2011                                    shoppingItem);
2012                    }
2013                    else {
2014                            ShoppingItemModelImpl shoppingItemModelImpl = (ShoppingItemModelImpl)shoppingItem;
2015    
2016                            if ((shoppingItemModelImpl.getColumnBitmask() &
2017                                            FINDER_PATH_FETCH_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
2018                                    Object[] args = new Object[] {
2019                                                    Long.valueOf(shoppingItem.getSmallImageId())
2020                                            };
2021    
2022                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
2023                                            args, Long.valueOf(1));
2024                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
2025                                            args, shoppingItem);
2026                            }
2027    
2028                            if ((shoppingItemModelImpl.getColumnBitmask() &
2029                                            FINDER_PATH_FETCH_BY_MEDIUMIMAGEID.getColumnBitmask()) != 0) {
2030                                    Object[] args = new Object[] {
2031                                                    Long.valueOf(shoppingItem.getMediumImageId())
2032                                            };
2033    
2034                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MEDIUMIMAGEID,
2035                                            args, Long.valueOf(1));
2036                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
2037                                            args, shoppingItem);
2038                            }
2039    
2040                            if ((shoppingItemModelImpl.getColumnBitmask() &
2041                                            FINDER_PATH_FETCH_BY_LARGEIMAGEID.getColumnBitmask()) != 0) {
2042                                    Object[] args = new Object[] {
2043                                                    Long.valueOf(shoppingItem.getLargeImageId())
2044                                            };
2045    
2046                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID,
2047                                            args, Long.valueOf(1));
2048                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
2049                                            args, shoppingItem);
2050                            }
2051    
2052                            if ((shoppingItemModelImpl.getColumnBitmask() &
2053                                            FINDER_PATH_FETCH_BY_C_S.getColumnBitmask()) != 0) {
2054                                    Object[] args = new Object[] {
2055                                                    Long.valueOf(shoppingItem.getCompanyId()),
2056                                                    
2057                                                    shoppingItem.getSku()
2058                                            };
2059    
2060                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, args,
2061                                            Long.valueOf(1));
2062                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S, args,
2063                                            shoppingItem);
2064                            }
2065                    }
2066            }
2067    
2068            protected void clearUniqueFindersCache(ShoppingItem shoppingItem) {
2069                    ShoppingItemModelImpl shoppingItemModelImpl = (ShoppingItemModelImpl)shoppingItem;
2070    
2071                    Object[] args = new Object[] {
2072                                    Long.valueOf(shoppingItem.getSmallImageId())
2073                            };
2074    
2075                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args);
2076                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args);
2077    
2078                    if ((shoppingItemModelImpl.getColumnBitmask() &
2079                                    FINDER_PATH_FETCH_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
2080                            args = new Object[] {
2081                                            Long.valueOf(shoppingItemModelImpl.getOriginalSmallImageId())
2082                                    };
2083    
2084                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args);
2085                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args);
2086                    }
2087    
2088                    args = new Object[] { Long.valueOf(shoppingItem.getMediumImageId()) };
2089    
2090                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MEDIUMIMAGEID, args);
2091                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID, args);
2092    
2093                    if ((shoppingItemModelImpl.getColumnBitmask() &
2094                                    FINDER_PATH_FETCH_BY_MEDIUMIMAGEID.getColumnBitmask()) != 0) {
2095                            args = new Object[] {
2096                                            Long.valueOf(shoppingItemModelImpl.getOriginalMediumImageId())
2097                                    };
2098    
2099                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MEDIUMIMAGEID,
2100                                    args);
2101                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
2102                                    args);
2103                    }
2104    
2105                    args = new Object[] { Long.valueOf(shoppingItem.getLargeImageId()) };
2106    
2107                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID, args);
2108                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID, args);
2109    
2110                    if ((shoppingItemModelImpl.getColumnBitmask() &
2111                                    FINDER_PATH_FETCH_BY_LARGEIMAGEID.getColumnBitmask()) != 0) {
2112                            args = new Object[] {
2113                                            Long.valueOf(shoppingItemModelImpl.getOriginalLargeImageId())
2114                                    };
2115    
2116                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID, args);
2117                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID, args);
2118                    }
2119    
2120                    args = new Object[] {
2121                                    Long.valueOf(shoppingItem.getCompanyId()),
2122                                    
2123                                    shoppingItem.getSku()
2124                            };
2125    
2126                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
2127                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_S, args);
2128    
2129                    if ((shoppingItemModelImpl.getColumnBitmask() &
2130                                    FINDER_PATH_FETCH_BY_C_S.getColumnBitmask()) != 0) {
2131                            args = new Object[] {
2132                                            Long.valueOf(shoppingItemModelImpl.getOriginalCompanyId()),
2133                                            
2134                                            shoppingItemModelImpl.getOriginalSku()
2135                                    };
2136    
2137                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
2138                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_S, args);
2139                    }
2140            }
2141    
2142            /**
2143             * Creates a new shopping item with the primary key. Does not add the shopping item to the database.
2144             *
2145             * @param itemId the primary key for the new shopping item
2146             * @return the new shopping item
2147             */
2148            public ShoppingItem create(long itemId) {
2149                    ShoppingItem shoppingItem = new ShoppingItemImpl();
2150    
2151                    shoppingItem.setNew(true);
2152                    shoppingItem.setPrimaryKey(itemId);
2153    
2154                    return shoppingItem;
2155            }
2156    
2157            /**
2158             * Removes the shopping item with the primary key from the database. Also notifies the appropriate model listeners.
2159             *
2160             * @param itemId the primary key of the shopping item
2161             * @return the shopping item that was removed
2162             * @throws com.liferay.portlet.shopping.NoSuchItemException if a shopping item with the primary key could not be found
2163             * @throws SystemException if a system exception occurred
2164             */
2165            public ShoppingItem remove(long itemId)
2166                    throws NoSuchItemException, SystemException {
2167                    return remove(Long.valueOf(itemId));
2168            }
2169    
2170            /**
2171             * Removes the shopping item with the primary key from the database. Also notifies the appropriate model listeners.
2172             *
2173             * @param primaryKey the primary key of the shopping item
2174             * @return the shopping item that was removed
2175             * @throws com.liferay.portlet.shopping.NoSuchItemException if a shopping item with the primary key could not be found
2176             * @throws SystemException if a system exception occurred
2177             */
2178            @Override
2179            public ShoppingItem remove(Serializable primaryKey)
2180                    throws NoSuchItemException, SystemException {
2181                    Session session = null;
2182    
2183                    try {
2184                            session = openSession();
2185    
2186                            ShoppingItem shoppingItem = (ShoppingItem)session.get(ShoppingItemImpl.class,
2187                                            primaryKey);
2188    
2189                            if (shoppingItem == null) {
2190                                    if (_log.isWarnEnabled()) {
2191                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2192                                    }
2193    
2194                                    throw new NoSuchItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2195                                            primaryKey);
2196                            }
2197    
2198                            return remove(shoppingItem);
2199                    }
2200                    catch (NoSuchItemException nsee) {
2201                            throw nsee;
2202                    }
2203                    catch (Exception e) {
2204                            throw processException(e);
2205                    }
2206                    finally {
2207                            closeSession(session);
2208                    }
2209            }
2210    
2211            @Override
2212            protected ShoppingItem removeImpl(ShoppingItem shoppingItem)
2213                    throws SystemException {
2214                    shoppingItem = toUnwrappedModel(shoppingItem);
2215    
2216                    Session session = null;
2217    
2218                    try {
2219                            session = openSession();
2220    
2221                            if (!session.contains(shoppingItem)) {
2222                                    shoppingItem = (ShoppingItem)session.get(ShoppingItemImpl.class,
2223                                                    shoppingItem.getPrimaryKeyObj());
2224                            }
2225    
2226                            if (shoppingItem != null) {
2227                                    session.delete(shoppingItem);
2228                            }
2229                    }
2230                    catch (Exception e) {
2231                            throw processException(e);
2232                    }
2233                    finally {
2234                            closeSession(session);
2235                    }
2236    
2237                    if (shoppingItem != null) {
2238                            clearCache(shoppingItem);
2239                    }
2240    
2241                    return shoppingItem;
2242            }
2243    
2244            @Override
2245            public ShoppingItem updateImpl(
2246                    com.liferay.portlet.shopping.model.ShoppingItem shoppingItem)
2247                    throws SystemException {
2248                    shoppingItem = toUnwrappedModel(shoppingItem);
2249    
2250                    boolean isNew = shoppingItem.isNew();
2251    
2252                    ShoppingItemModelImpl shoppingItemModelImpl = (ShoppingItemModelImpl)shoppingItem;
2253    
2254                    Session session = null;
2255    
2256                    try {
2257                            session = openSession();
2258    
2259                            if (shoppingItem.isNew()) {
2260                                    session.save(shoppingItem);
2261    
2262                                    shoppingItem.setNew(false);
2263                            }
2264                            else {
2265                                    session.merge(shoppingItem);
2266                            }
2267                    }
2268                    catch (Exception e) {
2269                            throw processException(e);
2270                    }
2271                    finally {
2272                            closeSession(session);
2273                    }
2274    
2275                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2276    
2277                    if (isNew || !ShoppingItemModelImpl.COLUMN_BITMASK_ENABLED) {
2278                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2279                    }
2280    
2281                    else {
2282                            if ((shoppingItemModelImpl.getColumnBitmask() &
2283                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
2284                                    Object[] args = new Object[] {
2285                                                    Long.valueOf(shoppingItemModelImpl.getOriginalGroupId()),
2286                                                    Long.valueOf(shoppingItemModelImpl.getOriginalCategoryId())
2287                                            };
2288    
2289                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2290                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
2291                                            args);
2292    
2293                                    args = new Object[] {
2294                                                    Long.valueOf(shoppingItemModelImpl.getGroupId()),
2295                                                    Long.valueOf(shoppingItemModelImpl.getCategoryId())
2296                                            };
2297    
2298                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2299                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
2300                                            args);
2301                            }
2302                    }
2303    
2304                    EntityCacheUtil.putResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
2305                            ShoppingItemImpl.class, shoppingItem.getPrimaryKey(), shoppingItem);
2306    
2307                    clearUniqueFindersCache(shoppingItem);
2308                    cacheUniqueFindersCache(shoppingItem);
2309    
2310                    return shoppingItem;
2311            }
2312    
2313            protected ShoppingItem toUnwrappedModel(ShoppingItem shoppingItem) {
2314                    if (shoppingItem instanceof ShoppingItemImpl) {
2315                            return shoppingItem;
2316                    }
2317    
2318                    ShoppingItemImpl shoppingItemImpl = new ShoppingItemImpl();
2319    
2320                    shoppingItemImpl.setNew(shoppingItem.isNew());
2321                    shoppingItemImpl.setPrimaryKey(shoppingItem.getPrimaryKey());
2322    
2323                    shoppingItemImpl.setItemId(shoppingItem.getItemId());
2324                    shoppingItemImpl.setGroupId(shoppingItem.getGroupId());
2325                    shoppingItemImpl.setCompanyId(shoppingItem.getCompanyId());
2326                    shoppingItemImpl.setUserId(shoppingItem.getUserId());
2327                    shoppingItemImpl.setUserName(shoppingItem.getUserName());
2328                    shoppingItemImpl.setCreateDate(shoppingItem.getCreateDate());
2329                    shoppingItemImpl.setModifiedDate(shoppingItem.getModifiedDate());
2330                    shoppingItemImpl.setCategoryId(shoppingItem.getCategoryId());
2331                    shoppingItemImpl.setSku(shoppingItem.getSku());
2332                    shoppingItemImpl.setName(shoppingItem.getName());
2333                    shoppingItemImpl.setDescription(shoppingItem.getDescription());
2334                    shoppingItemImpl.setProperties(shoppingItem.getProperties());
2335                    shoppingItemImpl.setFields(shoppingItem.isFields());
2336                    shoppingItemImpl.setFieldsQuantities(shoppingItem.getFieldsQuantities());
2337                    shoppingItemImpl.setMinQuantity(shoppingItem.getMinQuantity());
2338                    shoppingItemImpl.setMaxQuantity(shoppingItem.getMaxQuantity());
2339                    shoppingItemImpl.setPrice(shoppingItem.getPrice());
2340                    shoppingItemImpl.setDiscount(shoppingItem.getDiscount());
2341                    shoppingItemImpl.setTaxable(shoppingItem.isTaxable());
2342                    shoppingItemImpl.setShipping(shoppingItem.getShipping());
2343                    shoppingItemImpl.setUseShippingFormula(shoppingItem.isUseShippingFormula());
2344                    shoppingItemImpl.setRequiresShipping(shoppingItem.isRequiresShipping());
2345                    shoppingItemImpl.setStockQuantity(shoppingItem.getStockQuantity());
2346                    shoppingItemImpl.setFeatured(shoppingItem.isFeatured());
2347                    shoppingItemImpl.setSale(shoppingItem.isSale());
2348                    shoppingItemImpl.setSmallImage(shoppingItem.isSmallImage());
2349                    shoppingItemImpl.setSmallImageId(shoppingItem.getSmallImageId());
2350                    shoppingItemImpl.setSmallImageURL(shoppingItem.getSmallImageURL());
2351                    shoppingItemImpl.setMediumImage(shoppingItem.isMediumImage());
2352                    shoppingItemImpl.setMediumImageId(shoppingItem.getMediumImageId());
2353                    shoppingItemImpl.setMediumImageURL(shoppingItem.getMediumImageURL());
2354                    shoppingItemImpl.setLargeImage(shoppingItem.isLargeImage());
2355                    shoppingItemImpl.setLargeImageId(shoppingItem.getLargeImageId());
2356                    shoppingItemImpl.setLargeImageURL(shoppingItem.getLargeImageURL());
2357    
2358                    return shoppingItemImpl;
2359            }
2360    
2361            /**
2362             * Returns the shopping item with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2363             *
2364             * @param primaryKey the primary key of the shopping item
2365             * @return the shopping item
2366             * @throws com.liferay.portal.NoSuchModelException if a shopping item with the primary key could not be found
2367             * @throws SystemException if a system exception occurred
2368             */
2369            @Override
2370            public ShoppingItem findByPrimaryKey(Serializable primaryKey)
2371                    throws NoSuchModelException, SystemException {
2372                    return findByPrimaryKey(((Long)primaryKey).longValue());
2373            }
2374    
2375            /**
2376             * Returns the shopping item with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchItemException} if it could not be found.
2377             *
2378             * @param itemId the primary key of the shopping item
2379             * @return the shopping item
2380             * @throws com.liferay.portlet.shopping.NoSuchItemException if a shopping item with the primary key could not be found
2381             * @throws SystemException if a system exception occurred
2382             */
2383            public ShoppingItem findByPrimaryKey(long itemId)
2384                    throws NoSuchItemException, SystemException {
2385                    ShoppingItem shoppingItem = fetchByPrimaryKey(itemId);
2386    
2387                    if (shoppingItem == null) {
2388                            if (_log.isWarnEnabled()) {
2389                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemId);
2390                            }
2391    
2392                            throw new NoSuchItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2393                                    itemId);
2394                    }
2395    
2396                    return shoppingItem;
2397            }
2398    
2399            /**
2400             * Returns the shopping item with the primary key or returns <code>null</code> if it could not be found.
2401             *
2402             * @param primaryKey the primary key of the shopping item
2403             * @return the shopping item, or <code>null</code> if a shopping item with the primary key could not be found
2404             * @throws SystemException if a system exception occurred
2405             */
2406            @Override
2407            public ShoppingItem fetchByPrimaryKey(Serializable primaryKey)
2408                    throws SystemException {
2409                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
2410            }
2411    
2412            /**
2413             * Returns the shopping item with the primary key or returns <code>null</code> if it could not be found.
2414             *
2415             * @param itemId the primary key of the shopping item
2416             * @return the shopping item, or <code>null</code> if a shopping item with the primary key could not be found
2417             * @throws SystemException if a system exception occurred
2418             */
2419            public ShoppingItem fetchByPrimaryKey(long itemId)
2420                    throws SystemException {
2421                    ShoppingItem shoppingItem = (ShoppingItem)EntityCacheUtil.getResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
2422                                    ShoppingItemImpl.class, itemId);
2423    
2424                    if (shoppingItem == _nullShoppingItem) {
2425                            return null;
2426                    }
2427    
2428                    if (shoppingItem == null) {
2429                            Session session = null;
2430    
2431                            try {
2432                                    session = openSession();
2433    
2434                                    shoppingItem = (ShoppingItem)session.get(ShoppingItemImpl.class,
2435                                                    Long.valueOf(itemId));
2436    
2437                                    if (shoppingItem != null) {
2438                                            cacheResult(shoppingItem);
2439                                    }
2440                                    else {
2441                                            EntityCacheUtil.putResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
2442                                                    ShoppingItemImpl.class, itemId, _nullShoppingItem);
2443                                    }
2444                            }
2445                            catch (Exception e) {
2446                                    EntityCacheUtil.removeResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
2447                                            ShoppingItemImpl.class, itemId);
2448    
2449                                    throw processException(e);
2450                            }
2451                            finally {
2452                                    closeSession(session);
2453                            }
2454                    }
2455    
2456                    return shoppingItem;
2457            }
2458    
2459            /**
2460             * Returns all the shopping items.
2461             *
2462             * @return the shopping items
2463             * @throws SystemException if a system exception occurred
2464             */
2465            public List<ShoppingItem> findAll() throws SystemException {
2466                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2467            }
2468    
2469            /**
2470             * Returns a range of all the shopping items.
2471             *
2472             * <p>
2473             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingItemModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2474             * </p>
2475             *
2476             * @param start the lower bound of the range of shopping items
2477             * @param end the upper bound of the range of shopping items (not inclusive)
2478             * @return the range of shopping items
2479             * @throws SystemException if a system exception occurred
2480             */
2481            public List<ShoppingItem> findAll(int start, int end)
2482                    throws SystemException {
2483                    return findAll(start, end, null);
2484            }
2485    
2486            /**
2487             * Returns an ordered range of all the shopping items.
2488             *
2489             * <p>
2490             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingItemModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2491             * </p>
2492             *
2493             * @param start the lower bound of the range of shopping items
2494             * @param end the upper bound of the range of shopping items (not inclusive)
2495             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2496             * @return the ordered range of shopping items
2497             * @throws SystemException if a system exception occurred
2498             */
2499            public List<ShoppingItem> findAll(int start, int end,
2500                    OrderByComparator orderByComparator) throws SystemException {
2501                    boolean pagination = true;
2502                    FinderPath finderPath = null;
2503                    Object[] finderArgs = null;
2504    
2505                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2506                                    (orderByComparator == null)) {
2507                            pagination = false;
2508                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2509                            finderArgs = FINDER_ARGS_EMPTY;
2510                    }
2511                    else {
2512                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2513                            finderArgs = new Object[] { start, end, orderByComparator };
2514                    }
2515    
2516                    List<ShoppingItem> list = (List<ShoppingItem>)FinderCacheUtil.getResult(finderPath,
2517                                    finderArgs, this);
2518    
2519                    if (list == null) {
2520                            StringBundler query = null;
2521                            String sql = null;
2522    
2523                            if (orderByComparator != null) {
2524                                    query = new StringBundler(2 +
2525                                                    (orderByComparator.getOrderByFields().length * 3));
2526    
2527                                    query.append(_SQL_SELECT_SHOPPINGITEM);
2528    
2529                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2530                                            orderByComparator);
2531    
2532                                    sql = query.toString();
2533                            }
2534                            else {
2535                                    sql = _SQL_SELECT_SHOPPINGITEM;
2536    
2537                                    if (pagination) {
2538                                            sql = sql.concat(ShoppingItemModelImpl.ORDER_BY_JPQL);
2539                                    }
2540                            }
2541    
2542                            Session session = null;
2543    
2544                            try {
2545                                    session = openSession();
2546    
2547                                    Query q = session.createQuery(sql);
2548    
2549                                    if (!pagination) {
2550                                            list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
2551                                                            start, end, false);
2552    
2553                                            Collections.sort(list);
2554    
2555                                            list = new UnmodifiableList<ShoppingItem>(list);
2556                                    }
2557                                    else {
2558                                            list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
2559                                                            start, end);
2560                                    }
2561    
2562                                    cacheResult(list);
2563    
2564                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2565                            }
2566                            catch (Exception e) {
2567                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2568    
2569                                    throw processException(e);
2570                            }
2571                            finally {
2572                                    closeSession(session);
2573                            }
2574                    }
2575    
2576                    return list;
2577            }
2578    
2579            /**
2580             * Removes all the shopping items from the database.
2581             *
2582             * @throws SystemException if a system exception occurred
2583             */
2584            public void removeAll() throws SystemException {
2585                    for (ShoppingItem shoppingItem : findAll()) {
2586                            remove(shoppingItem);
2587                    }
2588            }
2589    
2590            /**
2591             * Returns the number of shopping items.
2592             *
2593             * @return the number of shopping items
2594             * @throws SystemException if a system exception occurred
2595             */
2596            public int countAll() throws SystemException {
2597                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2598                                    FINDER_ARGS_EMPTY, this);
2599    
2600                    if (count == null) {
2601                            Session session = null;
2602    
2603                            try {
2604                                    session = openSession();
2605    
2606                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEM);
2607    
2608                                    count = (Long)q.uniqueResult();
2609    
2610                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2611                                            FINDER_ARGS_EMPTY, count);
2612                            }
2613                            catch (Exception e) {
2614                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2615                                            FINDER_ARGS_EMPTY);
2616    
2617                                    throw processException(e);
2618                            }
2619                            finally {
2620                                    closeSession(session);
2621                            }
2622                    }
2623    
2624                    return count.intValue();
2625            }
2626    
2627            /**
2628             * Returns all the shopping item prices associated with the shopping item.
2629             *
2630             * @param pk the primary key of the shopping item
2631             * @return the shopping item prices associated with the shopping item
2632             * @throws SystemException if a system exception occurred
2633             */
2634            public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
2635                    long pk) throws SystemException {
2636                    return getShoppingItemPrices(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2637            }
2638    
2639            /**
2640             * Returns a range of all the shopping item prices associated with the shopping item.
2641             *
2642             * <p>
2643             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingItemModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2644             * </p>
2645             *
2646             * @param pk the primary key of the shopping item
2647             * @param start the lower bound of the range of shopping items
2648             * @param end the upper bound of the range of shopping items (not inclusive)
2649             * @return the range of shopping item prices associated with the shopping item
2650             * @throws SystemException if a system exception occurred
2651             */
2652            public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
2653                    long pk, int start, int end) throws SystemException {
2654                    return getShoppingItemPrices(pk, start, end, null);
2655            }
2656    
2657            public static final FinderPath FINDER_PATH_GET_SHOPPINGITEMPRICES = new FinderPath(com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
2658                            com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
2659                            com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl.class,
2660                            com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2661                            "getShoppingItemPrices",
2662                            new String[] {
2663                                    Long.class.getName(), Integer.class.getName(),
2664                                    Integer.class.getName(), OrderByComparator.class.getName()
2665                            });
2666    
2667            static {
2668                    FINDER_PATH_GET_SHOPPINGITEMPRICES.setCacheKeyGeneratorCacheName(null);
2669            }
2670    
2671            /**
2672             * Returns an ordered range of all the shopping item prices associated with the shopping item.
2673             *
2674             * <p>
2675             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingItemModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2676             * </p>
2677             *
2678             * @param pk the primary key of the shopping item
2679             * @param start the lower bound of the range of shopping items
2680             * @param end the upper bound of the range of shopping items (not inclusive)
2681             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2682             * @return the ordered range of shopping item prices associated with the shopping item
2683             * @throws SystemException if a system exception occurred
2684             */
2685            public List<com.liferay.portlet.shopping.model.ShoppingItemPrice> getShoppingItemPrices(
2686                    long pk, int start, int end, OrderByComparator orderByComparator)
2687                    throws SystemException {
2688                    boolean pagination = true;
2689                    Object[] finderArgs = null;
2690    
2691                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2692                                    (orderByComparator == null)) {
2693                            pagination = false;
2694                            finderArgs = new Object[] { pk };
2695                    }
2696                    else {
2697                            finderArgs = new Object[] { pk, start, end, orderByComparator };
2698                    }
2699    
2700                    List<com.liferay.portlet.shopping.model.ShoppingItemPrice> list = (List<com.liferay.portlet.shopping.model.ShoppingItemPrice>)FinderCacheUtil.getResult(FINDER_PATH_GET_SHOPPINGITEMPRICES,
2701                                    finderArgs, this);
2702    
2703                    if (list == null) {
2704                            Session session = null;
2705    
2706                            try {
2707                                    session = openSession();
2708    
2709                                    String sql = null;
2710    
2711                                    if (orderByComparator != null) {
2712                                            sql = _SQL_GETSHOPPINGITEMPRICES.concat(ORDER_BY_CLAUSE)
2713                                                                                                            .concat(orderByComparator.getOrderBy());
2714                                    }
2715                                    else {
2716                                            sql = _SQL_GETSHOPPINGITEMPRICES;
2717    
2718                                            if (pagination) {
2719                                                    sql = sql.concat(com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.ORDER_BY_SQL);
2720                                            }
2721                                    }
2722    
2723                                    SQLQuery q = session.createSQLQuery(sql);
2724    
2725                                    q.addEntity("ShoppingItemPrice",
2726                                            com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl.class);
2727    
2728                                    QueryPos qPos = QueryPos.getInstance(q);
2729    
2730                                    qPos.add(pk);
2731    
2732                                    if (!pagination) {
2733                                            list = (List<com.liferay.portlet.shopping.model.ShoppingItemPrice>)QueryUtil.list(q,
2734                                                            getDialect(), start, end, false);
2735    
2736                                            Collections.sort(list);
2737    
2738                                            list = new UnmodifiableList<com.liferay.portlet.shopping.model.ShoppingItemPrice>(list);
2739                                    }
2740                                    else {
2741                                            list = (List<com.liferay.portlet.shopping.model.ShoppingItemPrice>)QueryUtil.list(q,
2742                                                            getDialect(), start, end);
2743                                    }
2744    
2745                                    shoppingItemPricePersistence.cacheResult(list);
2746    
2747                                    FinderCacheUtil.putResult(FINDER_PATH_GET_SHOPPINGITEMPRICES,
2748                                            finderArgs, list);
2749                            }
2750                            catch (Exception e) {
2751                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_SHOPPINGITEMPRICES,
2752                                            finderArgs);
2753    
2754                                    throw processException(e);
2755                            }
2756                            finally {
2757                                    closeSession(session);
2758                            }
2759                    }
2760    
2761                    return list;
2762            }
2763    
2764            public static final FinderPath FINDER_PATH_GET_SHOPPINGITEMPRICES_SIZE = new FinderPath(com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
2765                            com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
2766                            com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl.class,
2767                            com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2768                            "getShoppingItemPricesSize", new String[] { Long.class.getName() });
2769    
2770            static {
2771                    FINDER_PATH_GET_SHOPPINGITEMPRICES_SIZE.setCacheKeyGeneratorCacheName(null);
2772            }
2773    
2774            /**
2775             * Returns the number of shopping item prices associated with the shopping item.
2776             *
2777             * @param pk the primary key of the shopping item
2778             * @return the number of shopping item prices associated with the shopping item
2779             * @throws SystemException if a system exception occurred
2780             */
2781            public int getShoppingItemPricesSize(long pk) throws SystemException {
2782                    Object[] finderArgs = new Object[] { pk };
2783    
2784                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_SHOPPINGITEMPRICES_SIZE,
2785                                    finderArgs, this);
2786    
2787                    if (count == null) {
2788                            Session session = null;
2789    
2790                            try {
2791                                    session = openSession();
2792    
2793                                    SQLQuery q = session.createSQLQuery(_SQL_GETSHOPPINGITEMPRICESSIZE);
2794    
2795                                    q.addScalar(COUNT_COLUMN_NAME,
2796                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
2797    
2798                                    QueryPos qPos = QueryPos.getInstance(q);
2799    
2800                                    qPos.add(pk);
2801    
2802                                    count = (Long)q.uniqueResult();
2803    
2804                                    FinderCacheUtil.putResult(FINDER_PATH_GET_SHOPPINGITEMPRICES_SIZE,
2805                                            finderArgs, count);
2806                            }
2807                            catch (Exception e) {
2808                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_SHOPPINGITEMPRICES_SIZE,
2809                                            finderArgs);
2810    
2811                                    throw processException(e);
2812                            }
2813                            finally {
2814                                    closeSession(session);
2815                            }
2816                    }
2817    
2818                    return count.intValue();
2819            }
2820    
2821            public static final FinderPath FINDER_PATH_CONTAINS_SHOPPINGITEMPRICE = new FinderPath(com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
2822                            com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
2823                            com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl.class,
2824                            com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2825                            "containsShoppingItemPrice",
2826                            new String[] { Long.class.getName(), Long.class.getName() });
2827    
2828            /**
2829             * Returns <code>true</code> if the shopping item price is associated with the shopping item.
2830             *
2831             * @param pk the primary key of the shopping item
2832             * @param shoppingItemPricePK the primary key of the shopping item price
2833             * @return <code>true</code> if the shopping item price is associated with the shopping item; <code>false</code> otherwise
2834             * @throws SystemException if a system exception occurred
2835             */
2836            public boolean containsShoppingItemPrice(long pk, long shoppingItemPricePK)
2837                    throws SystemException {
2838                    Object[] finderArgs = new Object[] { pk, shoppingItemPricePK };
2839    
2840                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_SHOPPINGITEMPRICE,
2841                                    finderArgs, this);
2842    
2843                    if (value == null) {
2844                            try {
2845                                    value = Boolean.valueOf(containsShoppingItemPrice.contains(pk,
2846                                                            shoppingItemPricePK));
2847    
2848                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_SHOPPINGITEMPRICE,
2849                                            finderArgs, value);
2850                            }
2851                            catch (Exception e) {
2852                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_SHOPPINGITEMPRICE,
2853                                            finderArgs);
2854    
2855                                    throw processException(e);
2856                            }
2857                    }
2858    
2859                    return value.booleanValue();
2860            }
2861    
2862            /**
2863             * Returns <code>true</code> if the shopping item has any shopping item prices associated with it.
2864             *
2865             * @param pk the primary key of the shopping item to check for associations with shopping item prices
2866             * @return <code>true</code> if the shopping item has any shopping item prices associated with it; <code>false</code> otherwise
2867             * @throws SystemException if a system exception occurred
2868             */
2869            public boolean containsShoppingItemPrices(long pk)
2870                    throws SystemException {
2871                    if (getShoppingItemPricesSize(pk) > 0) {
2872                            return true;
2873                    }
2874                    else {
2875                            return false;
2876                    }
2877            }
2878    
2879            /**
2880             * Initializes the shopping item persistence.
2881             */
2882            public void afterPropertiesSet() {
2883                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2884                                            com.liferay.portal.util.PropsUtil.get(
2885                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItem")));
2886    
2887                    if (listenerClassNames.length > 0) {
2888                            try {
2889                                    List<ModelListener<ShoppingItem>> listenersList = new ArrayList<ModelListener<ShoppingItem>>();
2890    
2891                                    for (String listenerClassName : listenerClassNames) {
2892                                            listenersList.add((ModelListener<ShoppingItem>)InstanceFactory.newInstance(
2893                                                            listenerClassName));
2894                                    }
2895    
2896                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2897                            }
2898                            catch (Exception e) {
2899                                    _log.error(e);
2900                            }
2901                    }
2902    
2903                    containsShoppingItemPrice = new ContainsShoppingItemPrice();
2904            }
2905    
2906            public void destroy() {
2907                    EntityCacheUtil.removeCache(ShoppingItemImpl.class.getName());
2908                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2909                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2910                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2911            }
2912    
2913            @BeanReference(type = ShoppingItemPricePersistence.class)
2914            protected ShoppingItemPricePersistence shoppingItemPricePersistence;
2915            protected ContainsShoppingItemPrice containsShoppingItemPrice;
2916    
2917            protected class ContainsShoppingItemPrice {
2918                    protected ContainsShoppingItemPrice() {
2919                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2920                                            _SQL_CONTAINSSHOPPINGITEMPRICE,
2921                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2922                                            RowMapper.COUNT);
2923                    }
2924    
2925                    protected boolean contains(long itemId, long itemPriceId) {
2926                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2927                                                    new Long(itemId), new Long(itemPriceId)
2928                                            });
2929    
2930                            if (results.size() > 0) {
2931                                    Integer count = results.get(0);
2932    
2933                                    if (count.intValue() > 0) {
2934                                            return true;
2935                                    }
2936                            }
2937    
2938                            return false;
2939                    }
2940    
2941                    private MappingSqlQuery<Integer> _mappingSqlQuery;
2942            }
2943    
2944            private static final String _SQL_SELECT_SHOPPINGITEM = "SELECT shoppingItem FROM ShoppingItem shoppingItem";
2945            private static final String _SQL_SELECT_SHOPPINGITEM_WHERE = "SELECT shoppingItem FROM ShoppingItem shoppingItem WHERE ";
2946            private static final String _SQL_COUNT_SHOPPINGITEM = "SELECT COUNT(shoppingItem) FROM ShoppingItem shoppingItem";
2947            private static final String _SQL_COUNT_SHOPPINGITEM_WHERE = "SELECT COUNT(shoppingItem) FROM ShoppingItem shoppingItem WHERE ";
2948            private static final String _SQL_GETSHOPPINGITEMPRICES = "SELECT {ShoppingItemPrice.*} FROM ShoppingItemPrice INNER JOIN ShoppingItem ON (ShoppingItem.itemId = ShoppingItemPrice.itemId) WHERE (ShoppingItem.itemId = ?)";
2949            private static final String _SQL_GETSHOPPINGITEMPRICESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM ShoppingItemPrice WHERE itemId = ?";
2950            private static final String _SQL_CONTAINSSHOPPINGITEMPRICE = "SELECT COUNT(*) AS COUNT_VALUE FROM ShoppingItemPrice WHERE itemId = ? AND itemPriceId = ?";
2951            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "shoppingItem.itemId";
2952            private static final String _FILTER_SQL_SELECT_SHOPPINGITEM_WHERE = "SELECT DISTINCT {shoppingItem.*} FROM ShoppingItem shoppingItem WHERE ";
2953            private static final String _FILTER_SQL_SELECT_SHOPPINGITEM_NO_INLINE_DISTINCT_WHERE_1 =
2954                    "SELECT {ShoppingItem.*} FROM (SELECT DISTINCT shoppingItem.itemId FROM ShoppingItem shoppingItem WHERE ";
2955            private static final String _FILTER_SQL_SELECT_SHOPPINGITEM_NO_INLINE_DISTINCT_WHERE_2 =
2956                    ") TEMP_TABLE INNER JOIN ShoppingItem ON TEMP_TABLE.itemId = ShoppingItem.itemId";
2957            private static final String _FILTER_SQL_COUNT_SHOPPINGITEM_WHERE = "SELECT COUNT(DISTINCT shoppingItem.itemId) AS COUNT_VALUE FROM ShoppingItem shoppingItem WHERE ";
2958            private static final String _FILTER_ENTITY_ALIAS = "shoppingItem";
2959            private static final String _FILTER_ENTITY_TABLE = "ShoppingItem";
2960            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItem.";
2961            private static final String _ORDER_BY_ENTITY_TABLE = "ShoppingItem.";
2962            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItem exists with the primary key ";
2963            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItem exists with the key {";
2964            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2965            private static Log _log = LogFactoryUtil.getLog(ShoppingItemPersistenceImpl.class);
2966            private static ShoppingItem _nullShoppingItem = new ShoppingItemImpl() {
2967                            @Override
2968                            public Object clone() {
2969                                    return this;
2970                            }
2971    
2972                            @Override
2973                            public CacheModel<ShoppingItem> toCacheModel() {
2974                                    return _nullShoppingItemCacheModel;
2975                            }
2976                    };
2977    
2978            private static CacheModel<ShoppingItem> _nullShoppingItemCacheModel = new CacheModel<ShoppingItem>() {
2979                            public ShoppingItem toEntityModel() {
2980                                    return _nullShoppingItem;
2981                            }
2982                    };
2983    }