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