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