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