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