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            public ShoppingItemPersistenceImpl() {
1918                    setModelClass(ShoppingItem.class);
1919            }
1920    
1921            /**
1922             * Caches the shopping item in the entity cache if it is enabled.
1923             *
1924             * @param shoppingItem the shopping item
1925             */
1926            @Override
1927            public void cacheResult(ShoppingItem shoppingItem) {
1928                    EntityCacheUtil.putResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
1929                            ShoppingItemImpl.class, shoppingItem.getPrimaryKey(), shoppingItem);
1930    
1931                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
1932                            new Object[] { shoppingItem.getSmallImageId() }, shoppingItem);
1933    
1934                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
1935                            new Object[] { shoppingItem.getMediumImageId() }, shoppingItem);
1936    
1937                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
1938                            new Object[] { shoppingItem.getLargeImageId() }, shoppingItem);
1939    
1940                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S,
1941                            new Object[] { shoppingItem.getCompanyId(), shoppingItem.getSku() },
1942                            shoppingItem);
1943    
1944                    shoppingItem.resetOriginalValues();
1945            }
1946    
1947            /**
1948             * Caches the shopping items in the entity cache if it is enabled.
1949             *
1950             * @param shoppingItems the shopping items
1951             */
1952            @Override
1953            public void cacheResult(List<ShoppingItem> shoppingItems) {
1954                    for (ShoppingItem shoppingItem : shoppingItems) {
1955                            if (EntityCacheUtil.getResult(
1956                                                    ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
1957                                                    ShoppingItemImpl.class, shoppingItem.getPrimaryKey()) == null) {
1958                                    cacheResult(shoppingItem);
1959                            }
1960                            else {
1961                                    shoppingItem.resetOriginalValues();
1962                            }
1963                    }
1964            }
1965    
1966            /**
1967             * Clears the cache for all shopping items.
1968             *
1969             * <p>
1970             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1971             * </p>
1972             */
1973            @Override
1974            public void clearCache() {
1975                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1976                            CacheRegistryUtil.clear(ShoppingItemImpl.class.getName());
1977                    }
1978    
1979                    EntityCacheUtil.clearCache(ShoppingItemImpl.class.getName());
1980    
1981                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1982                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1983                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1984            }
1985    
1986            /**
1987             * Clears the cache for the shopping item.
1988             *
1989             * <p>
1990             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1991             * </p>
1992             */
1993            @Override
1994            public void clearCache(ShoppingItem shoppingItem) {
1995                    EntityCacheUtil.removeResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
1996                            ShoppingItemImpl.class, shoppingItem.getPrimaryKey());
1997    
1998                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1999                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2000    
2001                    clearUniqueFindersCache(shoppingItem);
2002            }
2003    
2004            @Override
2005            public void clearCache(List<ShoppingItem> shoppingItems) {
2006                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2007                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2008    
2009                    for (ShoppingItem shoppingItem : shoppingItems) {
2010                            EntityCacheUtil.removeResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
2011                                    ShoppingItemImpl.class, shoppingItem.getPrimaryKey());
2012    
2013                            clearUniqueFindersCache(shoppingItem);
2014                    }
2015            }
2016    
2017            protected void cacheUniqueFindersCache(ShoppingItem shoppingItem) {
2018                    if (shoppingItem.isNew()) {
2019                            Object[] args = new Object[] { shoppingItem.getSmallImageId() };
2020    
2021                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args,
2022                                    Long.valueOf(1));
2023                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args,
2024                                    shoppingItem);
2025    
2026                            args = new Object[] { shoppingItem.getMediumImageId() };
2027    
2028                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MEDIUMIMAGEID, args,
2029                                    Long.valueOf(1));
2030                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID, args,
2031                                    shoppingItem);
2032    
2033                            args = new Object[] { shoppingItem.getLargeImageId() };
2034    
2035                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID, args,
2036                                    Long.valueOf(1));
2037                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID, args,
2038                                    shoppingItem);
2039    
2040                            args = new Object[] {
2041                                            shoppingItem.getCompanyId(), shoppingItem.getSku()
2042                                    };
2043    
2044                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, args,
2045                                    Long.valueOf(1));
2046                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S, args,
2047                                    shoppingItem);
2048                    }
2049                    else {
2050                            ShoppingItemModelImpl shoppingItemModelImpl = (ShoppingItemModelImpl)shoppingItem;
2051    
2052                            if ((shoppingItemModelImpl.getColumnBitmask() &
2053                                            FINDER_PATH_FETCH_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
2054                                    Object[] args = new Object[] { shoppingItem.getSmallImageId() };
2055    
2056                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
2057                                            args, Long.valueOf(1));
2058                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID,
2059                                            args, shoppingItem);
2060                            }
2061    
2062                            if ((shoppingItemModelImpl.getColumnBitmask() &
2063                                            FINDER_PATH_FETCH_BY_MEDIUMIMAGEID.getColumnBitmask()) != 0) {
2064                                    Object[] args = new Object[] { shoppingItem.getMediumImageId() };
2065    
2066                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MEDIUMIMAGEID,
2067                                            args, Long.valueOf(1));
2068                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
2069                                            args, shoppingItem);
2070                            }
2071    
2072                            if ((shoppingItemModelImpl.getColumnBitmask() &
2073                                            FINDER_PATH_FETCH_BY_LARGEIMAGEID.getColumnBitmask()) != 0) {
2074                                    Object[] args = new Object[] { shoppingItem.getLargeImageId() };
2075    
2076                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID,
2077                                            args, Long.valueOf(1));
2078                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID,
2079                                            args, shoppingItem);
2080                            }
2081    
2082                            if ((shoppingItemModelImpl.getColumnBitmask() &
2083                                            FINDER_PATH_FETCH_BY_C_S.getColumnBitmask()) != 0) {
2084                                    Object[] args = new Object[] {
2085                                                    shoppingItem.getCompanyId(), shoppingItem.getSku()
2086                                            };
2087    
2088                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, args,
2089                                            Long.valueOf(1));
2090                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_S, args,
2091                                            shoppingItem);
2092                            }
2093                    }
2094            }
2095    
2096            protected void clearUniqueFindersCache(ShoppingItem shoppingItem) {
2097                    ShoppingItemModelImpl shoppingItemModelImpl = (ShoppingItemModelImpl)shoppingItem;
2098    
2099                    Object[] args = new Object[] { shoppingItem.getSmallImageId() };
2100    
2101                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args);
2102                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args);
2103    
2104                    if ((shoppingItemModelImpl.getColumnBitmask() &
2105                                    FINDER_PATH_FETCH_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
2106                            args = new Object[] { shoppingItemModelImpl.getOriginalSmallImageId() };
2107    
2108                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID, args);
2109                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_SMALLIMAGEID, args);
2110                    }
2111    
2112                    args = new Object[] { shoppingItem.getMediumImageId() };
2113    
2114                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MEDIUMIMAGEID, args);
2115                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID, args);
2116    
2117                    if ((shoppingItemModelImpl.getColumnBitmask() &
2118                                    FINDER_PATH_FETCH_BY_MEDIUMIMAGEID.getColumnBitmask()) != 0) {
2119                            args = new Object[] { shoppingItemModelImpl.getOriginalMediumImageId() };
2120    
2121                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MEDIUMIMAGEID,
2122                                    args);
2123                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MEDIUMIMAGEID,
2124                                    args);
2125                    }
2126    
2127                    args = new Object[] { shoppingItem.getLargeImageId() };
2128    
2129                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID, args);
2130                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID, args);
2131    
2132                    if ((shoppingItemModelImpl.getColumnBitmask() &
2133                                    FINDER_PATH_FETCH_BY_LARGEIMAGEID.getColumnBitmask()) != 0) {
2134                            args = new Object[] { shoppingItemModelImpl.getOriginalLargeImageId() };
2135    
2136                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LARGEIMAGEID, args);
2137                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LARGEIMAGEID, args);
2138                    }
2139    
2140                    args = new Object[] { shoppingItem.getCompanyId(), shoppingItem.getSku() };
2141    
2142                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
2143                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_S, args);
2144    
2145                    if ((shoppingItemModelImpl.getColumnBitmask() &
2146                                    FINDER_PATH_FETCH_BY_C_S.getColumnBitmask()) != 0) {
2147                            args = new Object[] {
2148                                            shoppingItemModelImpl.getOriginalCompanyId(),
2149                                            shoppingItemModelImpl.getOriginalSku()
2150                                    };
2151    
2152                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
2153                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_S, args);
2154                    }
2155            }
2156    
2157            /**
2158             * Creates a new shopping item with the primary key. Does not add the shopping item to the database.
2159             *
2160             * @param itemId the primary key for the new shopping item
2161             * @return the new shopping item
2162             */
2163            @Override
2164            public ShoppingItem create(long itemId) {
2165                    ShoppingItem shoppingItem = new ShoppingItemImpl();
2166    
2167                    shoppingItem.setNew(true);
2168                    shoppingItem.setPrimaryKey(itemId);
2169    
2170                    return shoppingItem;
2171            }
2172    
2173            /**
2174             * Removes the shopping item with the primary key from the database. Also notifies the appropriate model listeners.
2175             *
2176             * @param itemId the primary key of the shopping item
2177             * @return the shopping item that was removed
2178             * @throws com.liferay.portlet.shopping.NoSuchItemException if a shopping item with the primary key could not be found
2179             * @throws SystemException if a system exception occurred
2180             */
2181            @Override
2182            public ShoppingItem remove(long itemId)
2183                    throws NoSuchItemException, SystemException {
2184                    return remove((Serializable)itemId);
2185            }
2186    
2187            /**
2188             * Removes the shopping item with the primary key from the database. Also notifies the appropriate model listeners.
2189             *
2190             * @param primaryKey the primary key of the shopping item
2191             * @return the shopping item that was removed
2192             * @throws com.liferay.portlet.shopping.NoSuchItemException if a shopping item with the primary key could not be found
2193             * @throws SystemException if a system exception occurred
2194             */
2195            @Override
2196            public ShoppingItem remove(Serializable primaryKey)
2197                    throws NoSuchItemException, SystemException {
2198                    Session session = null;
2199    
2200                    try {
2201                            session = openSession();
2202    
2203                            ShoppingItem shoppingItem = (ShoppingItem)session.get(ShoppingItemImpl.class,
2204                                            primaryKey);
2205    
2206                            if (shoppingItem == null) {
2207                                    if (_log.isWarnEnabled()) {
2208                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2209                                    }
2210    
2211                                    throw new NoSuchItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2212                                            primaryKey);
2213                            }
2214    
2215                            return remove(shoppingItem);
2216                    }
2217                    catch (NoSuchItemException nsee) {
2218                            throw nsee;
2219                    }
2220                    catch (Exception e) {
2221                            throw processException(e);
2222                    }
2223                    finally {
2224                            closeSession(session);
2225                    }
2226            }
2227    
2228            @Override
2229            protected ShoppingItem removeImpl(ShoppingItem shoppingItem)
2230                    throws SystemException {
2231                    shoppingItem = toUnwrappedModel(shoppingItem);
2232    
2233                    Session session = null;
2234    
2235                    try {
2236                            session = openSession();
2237    
2238                            if (!session.contains(shoppingItem)) {
2239                                    shoppingItem = (ShoppingItem)session.get(ShoppingItemImpl.class,
2240                                                    shoppingItem.getPrimaryKeyObj());
2241                            }
2242    
2243                            if (shoppingItem != null) {
2244                                    session.delete(shoppingItem);
2245                            }
2246                    }
2247                    catch (Exception e) {
2248                            throw processException(e);
2249                    }
2250                    finally {
2251                            closeSession(session);
2252                    }
2253    
2254                    if (shoppingItem != null) {
2255                            clearCache(shoppingItem);
2256                    }
2257    
2258                    return shoppingItem;
2259            }
2260    
2261            @Override
2262            public ShoppingItem updateImpl(
2263                    com.liferay.portlet.shopping.model.ShoppingItem shoppingItem)
2264                    throws SystemException {
2265                    shoppingItem = toUnwrappedModel(shoppingItem);
2266    
2267                    boolean isNew = shoppingItem.isNew();
2268    
2269                    ShoppingItemModelImpl shoppingItemModelImpl = (ShoppingItemModelImpl)shoppingItem;
2270    
2271                    Session session = null;
2272    
2273                    try {
2274                            session = openSession();
2275    
2276                            if (shoppingItem.isNew()) {
2277                                    session.save(shoppingItem);
2278    
2279                                    shoppingItem.setNew(false);
2280                            }
2281                            else {
2282                                    session.merge(shoppingItem);
2283                            }
2284                    }
2285                    catch (Exception e) {
2286                            throw processException(e);
2287                    }
2288                    finally {
2289                            closeSession(session);
2290                    }
2291    
2292                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2293    
2294                    if (isNew || !ShoppingItemModelImpl.COLUMN_BITMASK_ENABLED) {
2295                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2296                    }
2297    
2298                    else {
2299                            if ((shoppingItemModelImpl.getColumnBitmask() &
2300                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
2301                                    Object[] args = new Object[] {
2302                                                    shoppingItemModelImpl.getOriginalGroupId(),
2303                                                    shoppingItemModelImpl.getOriginalCategoryId()
2304                                            };
2305    
2306                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2307                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
2308                                            args);
2309    
2310                                    args = new Object[] {
2311                                                    shoppingItemModelImpl.getGroupId(),
2312                                                    shoppingItemModelImpl.getCategoryId()
2313                                            };
2314    
2315                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2316                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
2317                                            args);
2318                            }
2319                    }
2320    
2321                    EntityCacheUtil.putResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
2322                            ShoppingItemImpl.class, shoppingItem.getPrimaryKey(), shoppingItem);
2323    
2324                    clearUniqueFindersCache(shoppingItem);
2325                    cacheUniqueFindersCache(shoppingItem);
2326    
2327                    return shoppingItem;
2328            }
2329    
2330            protected ShoppingItem toUnwrappedModel(ShoppingItem shoppingItem) {
2331                    if (shoppingItem instanceof ShoppingItemImpl) {
2332                            return shoppingItem;
2333                    }
2334    
2335                    ShoppingItemImpl shoppingItemImpl = new ShoppingItemImpl();
2336    
2337                    shoppingItemImpl.setNew(shoppingItem.isNew());
2338                    shoppingItemImpl.setPrimaryKey(shoppingItem.getPrimaryKey());
2339    
2340                    shoppingItemImpl.setItemId(shoppingItem.getItemId());
2341                    shoppingItemImpl.setGroupId(shoppingItem.getGroupId());
2342                    shoppingItemImpl.setCompanyId(shoppingItem.getCompanyId());
2343                    shoppingItemImpl.setUserId(shoppingItem.getUserId());
2344                    shoppingItemImpl.setUserName(shoppingItem.getUserName());
2345                    shoppingItemImpl.setCreateDate(shoppingItem.getCreateDate());
2346                    shoppingItemImpl.setModifiedDate(shoppingItem.getModifiedDate());
2347                    shoppingItemImpl.setCategoryId(shoppingItem.getCategoryId());
2348                    shoppingItemImpl.setSku(shoppingItem.getSku());
2349                    shoppingItemImpl.setName(shoppingItem.getName());
2350                    shoppingItemImpl.setDescription(shoppingItem.getDescription());
2351                    shoppingItemImpl.setProperties(shoppingItem.getProperties());
2352                    shoppingItemImpl.setFields(shoppingItem.isFields());
2353                    shoppingItemImpl.setFieldsQuantities(shoppingItem.getFieldsQuantities());
2354                    shoppingItemImpl.setMinQuantity(shoppingItem.getMinQuantity());
2355                    shoppingItemImpl.setMaxQuantity(shoppingItem.getMaxQuantity());
2356                    shoppingItemImpl.setPrice(shoppingItem.getPrice());
2357                    shoppingItemImpl.setDiscount(shoppingItem.getDiscount());
2358                    shoppingItemImpl.setTaxable(shoppingItem.isTaxable());
2359                    shoppingItemImpl.setShipping(shoppingItem.getShipping());
2360                    shoppingItemImpl.setUseShippingFormula(shoppingItem.isUseShippingFormula());
2361                    shoppingItemImpl.setRequiresShipping(shoppingItem.isRequiresShipping());
2362                    shoppingItemImpl.setStockQuantity(shoppingItem.getStockQuantity());
2363                    shoppingItemImpl.setFeatured(shoppingItem.isFeatured());
2364                    shoppingItemImpl.setSale(shoppingItem.isSale());
2365                    shoppingItemImpl.setSmallImage(shoppingItem.isSmallImage());
2366                    shoppingItemImpl.setSmallImageId(shoppingItem.getSmallImageId());
2367                    shoppingItemImpl.setSmallImageURL(shoppingItem.getSmallImageURL());
2368                    shoppingItemImpl.setMediumImage(shoppingItem.isMediumImage());
2369                    shoppingItemImpl.setMediumImageId(shoppingItem.getMediumImageId());
2370                    shoppingItemImpl.setMediumImageURL(shoppingItem.getMediumImageURL());
2371                    shoppingItemImpl.setLargeImage(shoppingItem.isLargeImage());
2372                    shoppingItemImpl.setLargeImageId(shoppingItem.getLargeImageId());
2373                    shoppingItemImpl.setLargeImageURL(shoppingItem.getLargeImageURL());
2374    
2375                    return shoppingItemImpl;
2376            }
2377    
2378            /**
2379             * Returns the shopping item with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2380             *
2381             * @param primaryKey the primary key of the shopping item
2382             * @return the shopping item
2383             * @throws com.liferay.portlet.shopping.NoSuchItemException if a shopping item with the primary key could not be found
2384             * @throws SystemException if a system exception occurred
2385             */
2386            @Override
2387            public ShoppingItem findByPrimaryKey(Serializable primaryKey)
2388                    throws NoSuchItemException, SystemException {
2389                    ShoppingItem shoppingItem = fetchByPrimaryKey(primaryKey);
2390    
2391                    if (shoppingItem == null) {
2392                            if (_log.isWarnEnabled()) {
2393                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2394                            }
2395    
2396                            throw new NoSuchItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2397                                    primaryKey);
2398                    }
2399    
2400                    return shoppingItem;
2401            }
2402    
2403            /**
2404             * Returns the shopping item with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchItemException} if it could not be found.
2405             *
2406             * @param itemId the primary key of the shopping item
2407             * @return the shopping item
2408             * @throws com.liferay.portlet.shopping.NoSuchItemException if a shopping item with the primary key could not be found
2409             * @throws SystemException if a system exception occurred
2410             */
2411            @Override
2412            public ShoppingItem findByPrimaryKey(long itemId)
2413                    throws NoSuchItemException, SystemException {
2414                    return findByPrimaryKey((Serializable)itemId);
2415            }
2416    
2417            /**
2418             * Returns the shopping item with the primary key or returns <code>null</code> if it could not be found.
2419             *
2420             * @param primaryKey the primary key of the shopping item
2421             * @return the shopping item, or <code>null</code> if a shopping item with the primary key could not be found
2422             * @throws SystemException if a system exception occurred
2423             */
2424            @Override
2425            public ShoppingItem fetchByPrimaryKey(Serializable primaryKey)
2426                    throws SystemException {
2427                    ShoppingItem shoppingItem = (ShoppingItem)EntityCacheUtil.getResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
2428                                    ShoppingItemImpl.class, primaryKey);
2429    
2430                    if (shoppingItem == _nullShoppingItem) {
2431                            return null;
2432                    }
2433    
2434                    if (shoppingItem == null) {
2435                            Session session = null;
2436    
2437                            try {
2438                                    session = openSession();
2439    
2440                                    shoppingItem = (ShoppingItem)session.get(ShoppingItemImpl.class,
2441                                                    primaryKey);
2442    
2443                                    if (shoppingItem != null) {
2444                                            cacheResult(shoppingItem);
2445                                    }
2446                                    else {
2447                                            EntityCacheUtil.putResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
2448                                                    ShoppingItemImpl.class, primaryKey, _nullShoppingItem);
2449                                    }
2450                            }
2451                            catch (Exception e) {
2452                                    EntityCacheUtil.removeResult(ShoppingItemModelImpl.ENTITY_CACHE_ENABLED,
2453                                            ShoppingItemImpl.class, primaryKey);
2454    
2455                                    throw processException(e);
2456                            }
2457                            finally {
2458                                    closeSession(session);
2459                            }
2460                    }
2461    
2462                    return shoppingItem;
2463            }
2464    
2465            /**
2466             * Returns the shopping item with the primary key or returns <code>null</code> if it could not be found.
2467             *
2468             * @param itemId the primary key of the shopping item
2469             * @return the shopping item, or <code>null</code> if a shopping item with the primary key could not be found
2470             * @throws SystemException if a system exception occurred
2471             */
2472            @Override
2473            public ShoppingItem fetchByPrimaryKey(long itemId)
2474                    throws SystemException {
2475                    return fetchByPrimaryKey((Serializable)itemId);
2476            }
2477    
2478            /**
2479             * Returns all the shopping items.
2480             *
2481             * @return the shopping items
2482             * @throws SystemException if a system exception occurred
2483             */
2484            @Override
2485            public List<ShoppingItem> findAll() throws SystemException {
2486                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2487            }
2488    
2489            /**
2490             * Returns a range of all the shopping items.
2491             *
2492             * <p>
2493             * 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.
2494             * </p>
2495             *
2496             * @param start the lower bound of the range of shopping items
2497             * @param end the upper bound of the range of shopping items (not inclusive)
2498             * @return the range of shopping items
2499             * @throws SystemException if a system exception occurred
2500             */
2501            @Override
2502            public List<ShoppingItem> findAll(int start, int end)
2503                    throws SystemException {
2504                    return findAll(start, end, null);
2505            }
2506    
2507            /**
2508             * Returns an ordered range of all the shopping items.
2509             *
2510             * <p>
2511             * 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.
2512             * </p>
2513             *
2514             * @param start the lower bound of the range of shopping items
2515             * @param end the upper bound of the range of shopping items (not inclusive)
2516             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2517             * @return the ordered range of shopping items
2518             * @throws SystemException if a system exception occurred
2519             */
2520            @Override
2521            public List<ShoppingItem> findAll(int start, int end,
2522                    OrderByComparator orderByComparator) throws SystemException {
2523                    boolean pagination = true;
2524                    FinderPath finderPath = null;
2525                    Object[] finderArgs = null;
2526    
2527                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2528                                    (orderByComparator == null)) {
2529                            pagination = false;
2530                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2531                            finderArgs = FINDER_ARGS_EMPTY;
2532                    }
2533                    else {
2534                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2535                            finderArgs = new Object[] { start, end, orderByComparator };
2536                    }
2537    
2538                    List<ShoppingItem> list = (List<ShoppingItem>)FinderCacheUtil.getResult(finderPath,
2539                                    finderArgs, this);
2540    
2541                    if (list == null) {
2542                            StringBundler query = null;
2543                            String sql = null;
2544    
2545                            if (orderByComparator != null) {
2546                                    query = new StringBundler(2 +
2547                                                    (orderByComparator.getOrderByFields().length * 3));
2548    
2549                                    query.append(_SQL_SELECT_SHOPPINGITEM);
2550    
2551                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2552                                            orderByComparator);
2553    
2554                                    sql = query.toString();
2555                            }
2556                            else {
2557                                    sql = _SQL_SELECT_SHOPPINGITEM;
2558    
2559                                    if (pagination) {
2560                                            sql = sql.concat(ShoppingItemModelImpl.ORDER_BY_JPQL);
2561                                    }
2562                            }
2563    
2564                            Session session = null;
2565    
2566                            try {
2567                                    session = openSession();
2568    
2569                                    Query q = session.createQuery(sql);
2570    
2571                                    if (!pagination) {
2572                                            list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
2573                                                            start, end, false);
2574    
2575                                            Collections.sort(list);
2576    
2577                                            list = new UnmodifiableList<ShoppingItem>(list);
2578                                    }
2579                                    else {
2580                                            list = (List<ShoppingItem>)QueryUtil.list(q, getDialect(),
2581                                                            start, end);
2582                                    }
2583    
2584                                    cacheResult(list);
2585    
2586                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2587                            }
2588                            catch (Exception e) {
2589                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2590    
2591                                    throw processException(e);
2592                            }
2593                            finally {
2594                                    closeSession(session);
2595                            }
2596                    }
2597    
2598                    return list;
2599            }
2600    
2601            /**
2602             * Removes all the shopping items from the database.
2603             *
2604             * @throws SystemException if a system exception occurred
2605             */
2606            @Override
2607            public void removeAll() throws SystemException {
2608                    for (ShoppingItem shoppingItem : findAll()) {
2609                            remove(shoppingItem);
2610                    }
2611            }
2612    
2613            /**
2614             * Returns the number of shopping items.
2615             *
2616             * @return the number of shopping items
2617             * @throws SystemException if a system exception occurred
2618             */
2619            @Override
2620            public int countAll() throws SystemException {
2621                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2622                                    FINDER_ARGS_EMPTY, this);
2623    
2624                    if (count == null) {
2625                            Session session = null;
2626    
2627                            try {
2628                                    session = openSession();
2629    
2630                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEM);
2631    
2632                                    count = (Long)q.uniqueResult();
2633    
2634                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2635                                            FINDER_ARGS_EMPTY, count);
2636                            }
2637                            catch (Exception e) {
2638                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2639                                            FINDER_ARGS_EMPTY);
2640    
2641                                    throw processException(e);
2642                            }
2643                            finally {
2644                                    closeSession(session);
2645                            }
2646                    }
2647    
2648                    return count.intValue();
2649            }
2650    
2651            @Override
2652            protected Set<String> getBadColumnNames() {
2653                    return _badColumnNames;
2654            }
2655    
2656            /**
2657             * Initializes the shopping item persistence.
2658             */
2659            public void afterPropertiesSet() {
2660                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2661                                            com.liferay.portal.util.PropsUtil.get(
2662                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItem")));
2663    
2664                    if (listenerClassNames.length > 0) {
2665                            try {
2666                                    List<ModelListener<ShoppingItem>> listenersList = new ArrayList<ModelListener<ShoppingItem>>();
2667    
2668                                    for (String listenerClassName : listenerClassNames) {
2669                                            listenersList.add((ModelListener<ShoppingItem>)InstanceFactory.newInstance(
2670                                                            getClassLoader(), listenerClassName));
2671                                    }
2672    
2673                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2674                            }
2675                            catch (Exception e) {
2676                                    _log.error(e);
2677                            }
2678                    }
2679            }
2680    
2681            public void destroy() {
2682                    EntityCacheUtil.removeCache(ShoppingItemImpl.class.getName());
2683                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2684                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2685                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2686            }
2687    
2688            private static final String _SQL_SELECT_SHOPPINGITEM = "SELECT shoppingItem FROM ShoppingItem shoppingItem";
2689            private static final String _SQL_SELECT_SHOPPINGITEM_WHERE = "SELECT shoppingItem FROM ShoppingItem shoppingItem WHERE ";
2690            private static final String _SQL_COUNT_SHOPPINGITEM = "SELECT COUNT(shoppingItem) FROM ShoppingItem shoppingItem";
2691            private static final String _SQL_COUNT_SHOPPINGITEM_WHERE = "SELECT COUNT(shoppingItem) FROM ShoppingItem shoppingItem WHERE ";
2692            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "shoppingItem.itemId";
2693            private static final String _FILTER_SQL_SELECT_SHOPPINGITEM_WHERE = "SELECT DISTINCT {shoppingItem.*} FROM ShoppingItem shoppingItem WHERE ";
2694            private static final String _FILTER_SQL_SELECT_SHOPPINGITEM_NO_INLINE_DISTINCT_WHERE_1 =
2695                    "SELECT {ShoppingItem.*} FROM (SELECT DISTINCT shoppingItem.itemId FROM ShoppingItem shoppingItem WHERE ";
2696            private static final String _FILTER_SQL_SELECT_SHOPPINGITEM_NO_INLINE_DISTINCT_WHERE_2 =
2697                    ") TEMP_TABLE INNER JOIN ShoppingItem ON TEMP_TABLE.itemId = ShoppingItem.itemId";
2698            private static final String _FILTER_SQL_COUNT_SHOPPINGITEM_WHERE = "SELECT COUNT(DISTINCT shoppingItem.itemId) AS COUNT_VALUE FROM ShoppingItem shoppingItem WHERE ";
2699            private static final String _FILTER_ENTITY_ALIAS = "shoppingItem";
2700            private static final String _FILTER_ENTITY_TABLE = "ShoppingItem";
2701            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItem.";
2702            private static final String _ORDER_BY_ENTITY_TABLE = "ShoppingItem.";
2703            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItem exists with the primary key ";
2704            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItem exists with the key {";
2705            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2706            private static Log _log = LogFactoryUtil.getLog(ShoppingItemPersistenceImpl.class);
2707            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2708                                    "fields", "featured", "sale"
2709                            });
2710            private static ShoppingItem _nullShoppingItem = new ShoppingItemImpl() {
2711                            @Override
2712                            public Object clone() {
2713                                    return this;
2714                            }
2715    
2716                            @Override
2717                            public CacheModel<ShoppingItem> toCacheModel() {
2718                                    return _nullShoppingItemCacheModel;
2719                            }
2720                    };
2721    
2722            private static CacheModel<ShoppingItem> _nullShoppingItemCacheModel = new CacheModel<ShoppingItem>() {
2723                            @Override
2724                            public ShoppingItem toEntityModel() {
2725                                    return _nullShoppingItem;
2726                            }
2727                    };
2728    }