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