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