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