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