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