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