001    /**
002     * Copyright (c) 2000-2010 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.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.ResourcePersistence;
039    import com.liferay.portal.service.persistence.UserPersistence;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.shopping.NoSuchCartException;
043    import com.liferay.portlet.shopping.model.ShoppingCart;
044    import com.liferay.portlet.shopping.model.impl.ShoppingCartImpl;
045    import com.liferay.portlet.shopping.model.impl.ShoppingCartModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    
053    /**
054     * The persistence implementation for the shopping cart service.
055     *
056     * <p>
057     * Never modify or reference this class directly. Always use {@link ShoppingCartUtil} to access the shopping cart persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
058     * </p>
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see ShoppingCartPersistence
066     * @see ShoppingCartUtil
067     * @generated
068     */
069    public class ShoppingCartPersistenceImpl extends BasePersistenceImpl<ShoppingCart>
070            implements ShoppingCartPersistence {
071            public static final String FINDER_CLASS_NAME_ENTITY = ShoppingCartImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073                    ".List";
074            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
075                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
076                            "findByGroupId",
077                            new String[] {
078                                    Long.class.getName(),
079                                    
080                            "java.lang.Integer", "java.lang.Integer",
081                                    "com.liferay.portal.kernel.util.OrderByComparator"
082                            });
083            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
084                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
085                            "countByGroupId", new String[] { Long.class.getName() });
086            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
087                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
088                            "findByUserId",
089                            new String[] {
090                                    Long.class.getName(),
091                                    
092                            "java.lang.Integer", "java.lang.Integer",
093                                    "com.liferay.portal.kernel.util.OrderByComparator"
094                            });
095            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
096                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097                            "countByUserId", new String[] { Long.class.getName() });
098            public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
099                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED,
100                            FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
101                            new String[] { Long.class.getName(), Long.class.getName() });
102            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
103                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104                            "countByG_U",
105                            new String[] { Long.class.getName(), Long.class.getName() });
106            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
107                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108                            "findAll", new String[0]);
109            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
110                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111                            "countAll", new String[0]);
112    
113            /**
114             * Caches the shopping cart in the entity cache if it is enabled.
115             *
116             * @param shoppingCart the shopping cart to cache
117             */
118            public void cacheResult(ShoppingCart shoppingCart) {
119                    EntityCacheUtil.putResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
120                            ShoppingCartImpl.class, shoppingCart.getPrimaryKey(), shoppingCart);
121    
122                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
123                            new Object[] {
124                                    new Long(shoppingCart.getGroupId()),
125                                    new Long(shoppingCart.getUserId())
126                            }, shoppingCart);
127            }
128    
129            /**
130             * Caches the shopping carts in the entity cache if it is enabled.
131             *
132             * @param shoppingCarts the shopping carts to cache
133             */
134            public void cacheResult(List<ShoppingCart> shoppingCarts) {
135                    for (ShoppingCart shoppingCart : shoppingCarts) {
136                            if (EntityCacheUtil.getResult(
137                                                    ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
138                                                    ShoppingCartImpl.class, shoppingCart.getPrimaryKey(),
139                                                    this) == null) {
140                                    cacheResult(shoppingCart);
141                            }
142                    }
143            }
144    
145            /**
146             * Clears the cache for all shopping carts.
147             *
148             * <p>
149             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
150             * </p>
151             */
152            public void clearCache() {
153                    CacheRegistryUtil.clear(ShoppingCartImpl.class.getName());
154                    EntityCacheUtil.clearCache(ShoppingCartImpl.class.getName());
155                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
156                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
157            }
158    
159            /**
160             * Clears the cache for the shopping cart.
161             *
162             * <p>
163             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
164             * </p>
165             */
166            public void clearCache(ShoppingCart shoppingCart) {
167                    EntityCacheUtil.removeResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
168                            ShoppingCartImpl.class, shoppingCart.getPrimaryKey());
169    
170                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
171                            new Object[] {
172                                    new Long(shoppingCart.getGroupId()),
173                                    new Long(shoppingCart.getUserId())
174                            });
175            }
176    
177            /**
178             * Creates a new shopping cart with the primary key. Does not add the shopping cart to the database.
179             *
180             * @param cartId the primary key for the new shopping cart
181             * @return the new shopping cart
182             */
183            public ShoppingCart create(long cartId) {
184                    ShoppingCart shoppingCart = new ShoppingCartImpl();
185    
186                    shoppingCart.setNew(true);
187                    shoppingCart.setPrimaryKey(cartId);
188    
189                    return shoppingCart;
190            }
191    
192            /**
193             * Removes the shopping cart with the primary key from the database. Also notifies the appropriate model listeners.
194             *
195             * @param primaryKey the primary key of the shopping cart to remove
196             * @return the shopping cart that was removed
197             * @throws com.liferay.portal.NoSuchModelException if a shopping cart with the primary key could not be found
198             * @throws SystemException if a system exception occurred
199             */
200            public ShoppingCart remove(Serializable primaryKey)
201                    throws NoSuchModelException, SystemException {
202                    return remove(((Long)primaryKey).longValue());
203            }
204    
205            /**
206             * Removes the shopping cart with the primary key from the database. Also notifies the appropriate model listeners.
207             *
208             * @param cartId the primary key of the shopping cart to remove
209             * @return the shopping cart that was removed
210             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
211             * @throws SystemException if a system exception occurred
212             */
213            public ShoppingCart remove(long cartId)
214                    throws NoSuchCartException, SystemException {
215                    Session session = null;
216    
217                    try {
218                            session = openSession();
219    
220                            ShoppingCart shoppingCart = (ShoppingCart)session.get(ShoppingCartImpl.class,
221                                            new Long(cartId));
222    
223                            if (shoppingCart == null) {
224                                    if (_log.isWarnEnabled()) {
225                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + cartId);
226                                    }
227    
228                                    throw new NoSuchCartException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
229                                            cartId);
230                            }
231    
232                            return remove(shoppingCart);
233                    }
234                    catch (NoSuchCartException nsee) {
235                            throw nsee;
236                    }
237                    catch (Exception e) {
238                            throw processException(e);
239                    }
240                    finally {
241                            closeSession(session);
242                    }
243            }
244    
245            protected ShoppingCart removeImpl(ShoppingCart shoppingCart)
246                    throws SystemException {
247                    shoppingCart = toUnwrappedModel(shoppingCart);
248    
249                    Session session = null;
250    
251                    try {
252                            session = openSession();
253    
254                            BatchSessionUtil.delete(session, shoppingCart);
255                    }
256                    catch (Exception e) {
257                            throw processException(e);
258                    }
259                    finally {
260                            closeSession(session);
261                    }
262    
263                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
264    
265                    ShoppingCartModelImpl shoppingCartModelImpl = (ShoppingCartModelImpl)shoppingCart;
266    
267                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
268                            new Object[] {
269                                    new Long(shoppingCartModelImpl.getOriginalGroupId()),
270                                    new Long(shoppingCartModelImpl.getOriginalUserId())
271                            });
272    
273                    EntityCacheUtil.removeResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
274                            ShoppingCartImpl.class, shoppingCart.getPrimaryKey());
275    
276                    return shoppingCart;
277            }
278    
279            public ShoppingCart updateImpl(
280                    com.liferay.portlet.shopping.model.ShoppingCart shoppingCart,
281                    boolean merge) throws SystemException {
282                    shoppingCart = toUnwrappedModel(shoppingCart);
283    
284                    boolean isNew = shoppingCart.isNew();
285    
286                    ShoppingCartModelImpl shoppingCartModelImpl = (ShoppingCartModelImpl)shoppingCart;
287    
288                    Session session = null;
289    
290                    try {
291                            session = openSession();
292    
293                            BatchSessionUtil.update(session, shoppingCart, merge);
294    
295                            shoppingCart.setNew(false);
296                    }
297                    catch (Exception e) {
298                            throw processException(e);
299                    }
300                    finally {
301                            closeSession(session);
302                    }
303    
304                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
305    
306                    EntityCacheUtil.putResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
307                            ShoppingCartImpl.class, shoppingCart.getPrimaryKey(), shoppingCart);
308    
309                    if (!isNew &&
310                                    ((shoppingCart.getGroupId() != shoppingCartModelImpl.getOriginalGroupId()) ||
311                                    (shoppingCart.getUserId() != shoppingCartModelImpl.getOriginalUserId()))) {
312                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
313                                    new Object[] {
314                                            new Long(shoppingCartModelImpl.getOriginalGroupId()),
315                                            new Long(shoppingCartModelImpl.getOriginalUserId())
316                                    });
317                    }
318    
319                    if (isNew ||
320                                    ((shoppingCart.getGroupId() != shoppingCartModelImpl.getOriginalGroupId()) ||
321                                    (shoppingCart.getUserId() != shoppingCartModelImpl.getOriginalUserId()))) {
322                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
323                                    new Object[] {
324                                            new Long(shoppingCart.getGroupId()),
325                                            new Long(shoppingCart.getUserId())
326                                    }, shoppingCart);
327                    }
328    
329                    return shoppingCart;
330            }
331    
332            protected ShoppingCart toUnwrappedModel(ShoppingCart shoppingCart) {
333                    if (shoppingCart instanceof ShoppingCartImpl) {
334                            return shoppingCart;
335                    }
336    
337                    ShoppingCartImpl shoppingCartImpl = new ShoppingCartImpl();
338    
339                    shoppingCartImpl.setNew(shoppingCart.isNew());
340                    shoppingCartImpl.setPrimaryKey(shoppingCart.getPrimaryKey());
341    
342                    shoppingCartImpl.setCartId(shoppingCart.getCartId());
343                    shoppingCartImpl.setGroupId(shoppingCart.getGroupId());
344                    shoppingCartImpl.setCompanyId(shoppingCart.getCompanyId());
345                    shoppingCartImpl.setUserId(shoppingCart.getUserId());
346                    shoppingCartImpl.setUserName(shoppingCart.getUserName());
347                    shoppingCartImpl.setCreateDate(shoppingCart.getCreateDate());
348                    shoppingCartImpl.setModifiedDate(shoppingCart.getModifiedDate());
349                    shoppingCartImpl.setItemIds(shoppingCart.getItemIds());
350                    shoppingCartImpl.setCouponCodes(shoppingCart.getCouponCodes());
351                    shoppingCartImpl.setAltShipping(shoppingCart.getAltShipping());
352                    shoppingCartImpl.setInsure(shoppingCart.isInsure());
353    
354                    return shoppingCartImpl;
355            }
356    
357            /**
358             * Finds the shopping cart with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
359             *
360             * @param primaryKey the primary key of the shopping cart to find
361             * @return the shopping cart
362             * @throws com.liferay.portal.NoSuchModelException if a shopping cart with the primary key could not be found
363             * @throws SystemException if a system exception occurred
364             */
365            public ShoppingCart findByPrimaryKey(Serializable primaryKey)
366                    throws NoSuchModelException, SystemException {
367                    return findByPrimaryKey(((Long)primaryKey).longValue());
368            }
369    
370            /**
371             * Finds the shopping cart with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchCartException} if it could not be found.
372             *
373             * @param cartId the primary key of the shopping cart to find
374             * @return the shopping cart
375             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
376             * @throws SystemException if a system exception occurred
377             */
378            public ShoppingCart findByPrimaryKey(long cartId)
379                    throws NoSuchCartException, SystemException {
380                    ShoppingCart shoppingCart = fetchByPrimaryKey(cartId);
381    
382                    if (shoppingCart == null) {
383                            if (_log.isWarnEnabled()) {
384                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + cartId);
385                            }
386    
387                            throw new NoSuchCartException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
388                                    cartId);
389                    }
390    
391                    return shoppingCart;
392            }
393    
394            /**
395             * Finds the shopping cart with the primary key or returns <code>null</code> if it could not be found.
396             *
397             * @param primaryKey the primary key of the shopping cart to find
398             * @return the shopping cart, or <code>null</code> if a shopping cart with the primary key could not be found
399             * @throws SystemException if a system exception occurred
400             */
401            public ShoppingCart fetchByPrimaryKey(Serializable primaryKey)
402                    throws SystemException {
403                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
404            }
405    
406            /**
407             * Finds the shopping cart with the primary key or returns <code>null</code> if it could not be found.
408             *
409             * @param cartId the primary key of the shopping cart to find
410             * @return the shopping cart, or <code>null</code> if a shopping cart with the primary key could not be found
411             * @throws SystemException if a system exception occurred
412             */
413            public ShoppingCart fetchByPrimaryKey(long cartId)
414                    throws SystemException {
415                    ShoppingCart shoppingCart = (ShoppingCart)EntityCacheUtil.getResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
416                                    ShoppingCartImpl.class, cartId, this);
417    
418                    if (shoppingCart == null) {
419                            Session session = null;
420    
421                            try {
422                                    session = openSession();
423    
424                                    shoppingCart = (ShoppingCart)session.get(ShoppingCartImpl.class,
425                                                    new Long(cartId));
426                            }
427                            catch (Exception e) {
428                                    throw processException(e);
429                            }
430                            finally {
431                                    if (shoppingCart != null) {
432                                            cacheResult(shoppingCart);
433                                    }
434    
435                                    closeSession(session);
436                            }
437                    }
438    
439                    return shoppingCart;
440            }
441    
442            /**
443             * Finds all the shopping carts where groupId = &#63;.
444             *
445             * @param groupId the group id to search with
446             * @return the matching shopping carts
447             * @throws SystemException if a system exception occurred
448             */
449            public List<ShoppingCart> findByGroupId(long groupId)
450                    throws SystemException {
451                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
452            }
453    
454            /**
455             * Finds a range of all the shopping carts where groupId = &#63;.
456             *
457             * <p>
458             * 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.
459             * </p>
460             *
461             * @param groupId the group id to search with
462             * @param start the lower bound of the range of shopping carts to return
463             * @param end the upper bound of the range of shopping carts to return (not inclusive)
464             * @return the range of matching shopping carts
465             * @throws SystemException if a system exception occurred
466             */
467            public List<ShoppingCart> findByGroupId(long groupId, int start, int end)
468                    throws SystemException {
469                    return findByGroupId(groupId, start, end, null);
470            }
471    
472            /**
473             * Finds an ordered range of all the shopping carts where groupId = &#63;.
474             *
475             * <p>
476             * 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.
477             * </p>
478             *
479             * @param groupId the group id to search with
480             * @param start the lower bound of the range of shopping carts to return
481             * @param end the upper bound of the range of shopping carts to return (not inclusive)
482             * @param orderByComparator the comparator to order the results by
483             * @return the ordered range of matching shopping carts
484             * @throws SystemException if a system exception occurred
485             */
486            public List<ShoppingCart> findByGroupId(long groupId, int start, int end,
487                    OrderByComparator orderByComparator) throws SystemException {
488                    Object[] finderArgs = new Object[] {
489                                    groupId,
490                                    
491                                    String.valueOf(start), String.valueOf(end),
492                                    String.valueOf(orderByComparator)
493                            };
494    
495                    List<ShoppingCart> list = (List<ShoppingCart>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
496                                    finderArgs, this);
497    
498                    if (list == null) {
499                            Session session = null;
500    
501                            try {
502                                    session = openSession();
503    
504                                    StringBundler query = null;
505    
506                                    if (orderByComparator != null) {
507                                            query = new StringBundler(3 +
508                                                            (orderByComparator.getOrderByFields().length * 3));
509                                    }
510                                    else {
511                                            query = new StringBundler(2);
512                                    }
513    
514                                    query.append(_SQL_SELECT_SHOPPINGCART_WHERE);
515    
516                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
517    
518                                    if (orderByComparator != null) {
519                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
520                                                    orderByComparator);
521                                    }
522    
523                                    String sql = query.toString();
524    
525                                    Query q = session.createQuery(sql);
526    
527                                    QueryPos qPos = QueryPos.getInstance(q);
528    
529                                    qPos.add(groupId);
530    
531                                    list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
532                                                    start, end);
533                            }
534                            catch (Exception e) {
535                                    throw processException(e);
536                            }
537                            finally {
538                                    if (list == null) {
539                                            list = new ArrayList<ShoppingCart>();
540                                    }
541    
542                                    cacheResult(list);
543    
544                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
545                                            finderArgs, list);
546    
547                                    closeSession(session);
548                            }
549                    }
550    
551                    return list;
552            }
553    
554            /**
555             * Finds the first shopping cart in the ordered set where groupId = &#63;.
556             *
557             * <p>
558             * 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.
559             * </p>
560             *
561             * @param groupId the group id to search with
562             * @param orderByComparator the comparator to order the set by
563             * @return the first matching shopping cart
564             * @throws com.liferay.portlet.shopping.NoSuchCartException if a matching shopping cart could not be found
565             * @throws SystemException if a system exception occurred
566             */
567            public ShoppingCart findByGroupId_First(long groupId,
568                    OrderByComparator orderByComparator)
569                    throws NoSuchCartException, SystemException {
570                    List<ShoppingCart> list = findByGroupId(groupId, 0, 1, orderByComparator);
571    
572                    if (list.isEmpty()) {
573                            StringBundler msg = new StringBundler(4);
574    
575                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
576    
577                            msg.append("groupId=");
578                            msg.append(groupId);
579    
580                            msg.append(StringPool.CLOSE_CURLY_BRACE);
581    
582                            throw new NoSuchCartException(msg.toString());
583                    }
584                    else {
585                            return list.get(0);
586                    }
587            }
588    
589            /**
590             * Finds the last shopping cart in the ordered set where groupId = &#63;.
591             *
592             * <p>
593             * 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.
594             * </p>
595             *
596             * @param groupId the group id to search with
597             * @param orderByComparator the comparator to order the set by
598             * @return the last matching shopping cart
599             * @throws com.liferay.portlet.shopping.NoSuchCartException if a matching shopping cart could not be found
600             * @throws SystemException if a system exception occurred
601             */
602            public ShoppingCart findByGroupId_Last(long groupId,
603                    OrderByComparator orderByComparator)
604                    throws NoSuchCartException, SystemException {
605                    int count = countByGroupId(groupId);
606    
607                    List<ShoppingCart> list = findByGroupId(groupId, count - 1, count,
608                                    orderByComparator);
609    
610                    if (list.isEmpty()) {
611                            StringBundler msg = new StringBundler(4);
612    
613                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
614    
615                            msg.append("groupId=");
616                            msg.append(groupId);
617    
618                            msg.append(StringPool.CLOSE_CURLY_BRACE);
619    
620                            throw new NoSuchCartException(msg.toString());
621                    }
622                    else {
623                            return list.get(0);
624                    }
625            }
626    
627            /**
628             * Finds the shopping carts before and after the current shopping cart in the ordered set where groupId = &#63;.
629             *
630             * <p>
631             * 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.
632             * </p>
633             *
634             * @param cartId the primary key of the current shopping cart
635             * @param groupId the group id to search with
636             * @param orderByComparator the comparator to order the set by
637             * @return the previous, current, and next shopping cart
638             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
639             * @throws SystemException if a system exception occurred
640             */
641            public ShoppingCart[] findByGroupId_PrevAndNext(long cartId, long groupId,
642                    OrderByComparator orderByComparator)
643                    throws NoSuchCartException, SystemException {
644                    ShoppingCart shoppingCart = findByPrimaryKey(cartId);
645    
646                    Session session = null;
647    
648                    try {
649                            session = openSession();
650    
651                            ShoppingCart[] array = new ShoppingCartImpl[3];
652    
653                            array[0] = getByGroupId_PrevAndNext(session, shoppingCart, groupId,
654                                            orderByComparator, true);
655    
656                            array[1] = shoppingCart;
657    
658                            array[2] = getByGroupId_PrevAndNext(session, shoppingCart, groupId,
659                                            orderByComparator, false);
660    
661                            return array;
662                    }
663                    catch (Exception e) {
664                            throw processException(e);
665                    }
666                    finally {
667                            closeSession(session);
668                    }
669            }
670    
671            protected ShoppingCart getByGroupId_PrevAndNext(Session session,
672                    ShoppingCart shoppingCart, long groupId,
673                    OrderByComparator orderByComparator, boolean previous) {
674                    StringBundler query = null;
675    
676                    if (orderByComparator != null) {
677                            query = new StringBundler(6 +
678                                            (orderByComparator.getOrderByFields().length * 6));
679                    }
680                    else {
681                            query = new StringBundler(3);
682                    }
683    
684                    query.append(_SQL_SELECT_SHOPPINGCART_WHERE);
685    
686                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
687    
688                    if (orderByComparator != null) {
689                            String[] orderByFields = orderByComparator.getOrderByFields();
690    
691                            if (orderByFields.length > 0) {
692                                    query.append(WHERE_AND);
693                            }
694    
695                            for (int i = 0; i < orderByFields.length; i++) {
696                                    query.append(_ORDER_BY_ENTITY_ALIAS);
697                                    query.append(orderByFields[i]);
698    
699                                    if ((i + 1) < orderByFields.length) {
700                                            if (orderByComparator.isAscending() ^ previous) {
701                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
702                                            }
703                                            else {
704                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
705                                            }
706                                    }
707                                    else {
708                                            if (orderByComparator.isAscending() ^ previous) {
709                                                    query.append(WHERE_GREATER_THAN);
710                                            }
711                                            else {
712                                                    query.append(WHERE_LESSER_THAN);
713                                            }
714                                    }
715                            }
716    
717                            query.append(ORDER_BY_CLAUSE);
718    
719                            for (int i = 0; i < orderByFields.length; i++) {
720                                    query.append(_ORDER_BY_ENTITY_ALIAS);
721                                    query.append(orderByFields[i]);
722    
723                                    if ((i + 1) < orderByFields.length) {
724                                            if (orderByComparator.isAscending() ^ previous) {
725                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
726                                            }
727                                            else {
728                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
729                                            }
730                                    }
731                                    else {
732                                            if (orderByComparator.isAscending() ^ previous) {
733                                                    query.append(ORDER_BY_ASC);
734                                            }
735                                            else {
736                                                    query.append(ORDER_BY_DESC);
737                                            }
738                                    }
739                            }
740                    }
741    
742                    String sql = query.toString();
743    
744                    Query q = session.createQuery(sql);
745    
746                    q.setFirstResult(0);
747                    q.setMaxResults(2);
748    
749                    QueryPos qPos = QueryPos.getInstance(q);
750    
751                    qPos.add(groupId);
752    
753                    if (orderByComparator != null) {
754                            Object[] values = orderByComparator.getOrderByValues(shoppingCart);
755    
756                            for (Object value : values) {
757                                    qPos.add(value);
758                            }
759                    }
760    
761                    List<ShoppingCart> list = q.list();
762    
763                    if (list.size() == 2) {
764                            return list.get(1);
765                    }
766                    else {
767                            return null;
768                    }
769            }
770    
771            /**
772             * Finds all the shopping carts where userId = &#63;.
773             *
774             * @param userId the user id to search with
775             * @return the matching shopping carts
776             * @throws SystemException if a system exception occurred
777             */
778            public List<ShoppingCart> findByUserId(long userId)
779                    throws SystemException {
780                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
781            }
782    
783            /**
784             * Finds a range of all the shopping carts where userId = &#63;.
785             *
786             * <p>
787             * 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.
788             * </p>
789             *
790             * @param userId the user id to search with
791             * @param start the lower bound of the range of shopping carts to return
792             * @param end the upper bound of the range of shopping carts to return (not inclusive)
793             * @return the range of matching shopping carts
794             * @throws SystemException if a system exception occurred
795             */
796            public List<ShoppingCart> findByUserId(long userId, int start, int end)
797                    throws SystemException {
798                    return findByUserId(userId, start, end, null);
799            }
800    
801            /**
802             * Finds an ordered range of all the shopping carts where userId = &#63;.
803             *
804             * <p>
805             * 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.
806             * </p>
807             *
808             * @param userId the user id to search with
809             * @param start the lower bound of the range of shopping carts to return
810             * @param end the upper bound of the range of shopping carts to return (not inclusive)
811             * @param orderByComparator the comparator to order the results by
812             * @return the ordered range of matching shopping carts
813             * @throws SystemException if a system exception occurred
814             */
815            public List<ShoppingCart> findByUserId(long userId, int start, int end,
816                    OrderByComparator orderByComparator) throws SystemException {
817                    Object[] finderArgs = new Object[] {
818                                    userId,
819                                    
820                                    String.valueOf(start), String.valueOf(end),
821                                    String.valueOf(orderByComparator)
822                            };
823    
824                    List<ShoppingCart> list = (List<ShoppingCart>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
825                                    finderArgs, this);
826    
827                    if (list == null) {
828                            Session session = null;
829    
830                            try {
831                                    session = openSession();
832    
833                                    StringBundler query = null;
834    
835                                    if (orderByComparator != null) {
836                                            query = new StringBundler(3 +
837                                                            (orderByComparator.getOrderByFields().length * 3));
838                                    }
839                                    else {
840                                            query = new StringBundler(2);
841                                    }
842    
843                                    query.append(_SQL_SELECT_SHOPPINGCART_WHERE);
844    
845                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
846    
847                                    if (orderByComparator != null) {
848                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
849                                                    orderByComparator);
850                                    }
851    
852                                    String sql = query.toString();
853    
854                                    Query q = session.createQuery(sql);
855    
856                                    QueryPos qPos = QueryPos.getInstance(q);
857    
858                                    qPos.add(userId);
859    
860                                    list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
861                                                    start, end);
862                            }
863                            catch (Exception e) {
864                                    throw processException(e);
865                            }
866                            finally {
867                                    if (list == null) {
868                                            list = new ArrayList<ShoppingCart>();
869                                    }
870    
871                                    cacheResult(list);
872    
873                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
874                                            finderArgs, list);
875    
876                                    closeSession(session);
877                            }
878                    }
879    
880                    return list;
881            }
882    
883            /**
884             * Finds the first shopping cart in the ordered set where userId = &#63;.
885             *
886             * <p>
887             * 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.
888             * </p>
889             *
890             * @param userId the user id to search with
891             * @param orderByComparator the comparator to order the set by
892             * @return the first matching shopping cart
893             * @throws com.liferay.portlet.shopping.NoSuchCartException if a matching shopping cart could not be found
894             * @throws SystemException if a system exception occurred
895             */
896            public ShoppingCart findByUserId_First(long userId,
897                    OrderByComparator orderByComparator)
898                    throws NoSuchCartException, SystemException {
899                    List<ShoppingCart> list = findByUserId(userId, 0, 1, orderByComparator);
900    
901                    if (list.isEmpty()) {
902                            StringBundler msg = new StringBundler(4);
903    
904                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
905    
906                            msg.append("userId=");
907                            msg.append(userId);
908    
909                            msg.append(StringPool.CLOSE_CURLY_BRACE);
910    
911                            throw new NoSuchCartException(msg.toString());
912                    }
913                    else {
914                            return list.get(0);
915                    }
916            }
917    
918            /**
919             * Finds the last shopping cart in the ordered set where userId = &#63;.
920             *
921             * <p>
922             * 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.
923             * </p>
924             *
925             * @param userId the user id to search with
926             * @param orderByComparator the comparator to order the set by
927             * @return the last matching shopping cart
928             * @throws com.liferay.portlet.shopping.NoSuchCartException if a matching shopping cart could not be found
929             * @throws SystemException if a system exception occurred
930             */
931            public ShoppingCart findByUserId_Last(long userId,
932                    OrderByComparator orderByComparator)
933                    throws NoSuchCartException, SystemException {
934                    int count = countByUserId(userId);
935    
936                    List<ShoppingCart> list = findByUserId(userId, count - 1, count,
937                                    orderByComparator);
938    
939                    if (list.isEmpty()) {
940                            StringBundler msg = new StringBundler(4);
941    
942                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
943    
944                            msg.append("userId=");
945                            msg.append(userId);
946    
947                            msg.append(StringPool.CLOSE_CURLY_BRACE);
948    
949                            throw new NoSuchCartException(msg.toString());
950                    }
951                    else {
952                            return list.get(0);
953                    }
954            }
955    
956            /**
957             * Finds the shopping carts before and after the current shopping cart in the ordered set where userId = &#63;.
958             *
959             * <p>
960             * 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.
961             * </p>
962             *
963             * @param cartId the primary key of the current shopping cart
964             * @param userId the user id to search with
965             * @param orderByComparator the comparator to order the set by
966             * @return the previous, current, and next shopping cart
967             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
968             * @throws SystemException if a system exception occurred
969             */
970            public ShoppingCart[] findByUserId_PrevAndNext(long cartId, long userId,
971                    OrderByComparator orderByComparator)
972                    throws NoSuchCartException, SystemException {
973                    ShoppingCart shoppingCart = findByPrimaryKey(cartId);
974    
975                    Session session = null;
976    
977                    try {
978                            session = openSession();
979    
980                            ShoppingCart[] array = new ShoppingCartImpl[3];
981    
982                            array[0] = getByUserId_PrevAndNext(session, shoppingCart, userId,
983                                            orderByComparator, true);
984    
985                            array[1] = shoppingCart;
986    
987                            array[2] = getByUserId_PrevAndNext(session, shoppingCart, userId,
988                                            orderByComparator, false);
989    
990                            return array;
991                    }
992                    catch (Exception e) {
993                            throw processException(e);
994                    }
995                    finally {
996                            closeSession(session);
997                    }
998            }
999    
1000            protected ShoppingCart getByUserId_PrevAndNext(Session session,
1001                    ShoppingCart shoppingCart, long userId,
1002                    OrderByComparator orderByComparator, boolean previous) {
1003                    StringBundler query = null;
1004    
1005                    if (orderByComparator != null) {
1006                            query = new StringBundler(6 +
1007                                            (orderByComparator.getOrderByFields().length * 6));
1008                    }
1009                    else {
1010                            query = new StringBundler(3);
1011                    }
1012    
1013                    query.append(_SQL_SELECT_SHOPPINGCART_WHERE);
1014    
1015                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1016    
1017                    if (orderByComparator != null) {
1018                            String[] orderByFields = orderByComparator.getOrderByFields();
1019    
1020                            if (orderByFields.length > 0) {
1021                                    query.append(WHERE_AND);
1022                            }
1023    
1024                            for (int i = 0; i < orderByFields.length; i++) {
1025                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1026                                    query.append(orderByFields[i]);
1027    
1028                                    if ((i + 1) < orderByFields.length) {
1029                                            if (orderByComparator.isAscending() ^ previous) {
1030                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1031                                            }
1032                                            else {
1033                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1034                                            }
1035                                    }
1036                                    else {
1037                                            if (orderByComparator.isAscending() ^ previous) {
1038                                                    query.append(WHERE_GREATER_THAN);
1039                                            }
1040                                            else {
1041                                                    query.append(WHERE_LESSER_THAN);
1042                                            }
1043                                    }
1044                            }
1045    
1046                            query.append(ORDER_BY_CLAUSE);
1047    
1048                            for (int i = 0; i < orderByFields.length; i++) {
1049                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1050                                    query.append(orderByFields[i]);
1051    
1052                                    if ((i + 1) < orderByFields.length) {
1053                                            if (orderByComparator.isAscending() ^ previous) {
1054                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1055                                            }
1056                                            else {
1057                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1058                                            }
1059                                    }
1060                                    else {
1061                                            if (orderByComparator.isAscending() ^ previous) {
1062                                                    query.append(ORDER_BY_ASC);
1063                                            }
1064                                            else {
1065                                                    query.append(ORDER_BY_DESC);
1066                                            }
1067                                    }
1068                            }
1069                    }
1070    
1071                    String sql = query.toString();
1072    
1073                    Query q = session.createQuery(sql);
1074    
1075                    q.setFirstResult(0);
1076                    q.setMaxResults(2);
1077    
1078                    QueryPos qPos = QueryPos.getInstance(q);
1079    
1080                    qPos.add(userId);
1081    
1082                    if (orderByComparator != null) {
1083                            Object[] values = orderByComparator.getOrderByValues(shoppingCart);
1084    
1085                            for (Object value : values) {
1086                                    qPos.add(value);
1087                            }
1088                    }
1089    
1090                    List<ShoppingCart> list = q.list();
1091    
1092                    if (list.size() == 2) {
1093                            return list.get(1);
1094                    }
1095                    else {
1096                            return null;
1097                    }
1098            }
1099    
1100            /**
1101             * Finds the shopping cart where groupId = &#63; and userId = &#63; or throws a {@link com.liferay.portlet.shopping.NoSuchCartException} if it could not be found.
1102             *
1103             * @param groupId the group id to search with
1104             * @param userId the user id to search with
1105             * @return the matching shopping cart
1106             * @throws com.liferay.portlet.shopping.NoSuchCartException if a matching shopping cart could not be found
1107             * @throws SystemException if a system exception occurred
1108             */
1109            public ShoppingCart findByG_U(long groupId, long userId)
1110                    throws NoSuchCartException, SystemException {
1111                    ShoppingCart shoppingCart = fetchByG_U(groupId, userId);
1112    
1113                    if (shoppingCart == null) {
1114                            StringBundler msg = new StringBundler(6);
1115    
1116                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1117    
1118                            msg.append("groupId=");
1119                            msg.append(groupId);
1120    
1121                            msg.append(", userId=");
1122                            msg.append(userId);
1123    
1124                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1125    
1126                            if (_log.isWarnEnabled()) {
1127                                    _log.warn(msg.toString());
1128                            }
1129    
1130                            throw new NoSuchCartException(msg.toString());
1131                    }
1132    
1133                    return shoppingCart;
1134            }
1135    
1136            /**
1137             * Finds the shopping cart where groupId = &#63; and userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1138             *
1139             * @param groupId the group id to search with
1140             * @param userId the user id to search with
1141             * @return the matching shopping cart, or <code>null</code> if a matching shopping cart could not be found
1142             * @throws SystemException if a system exception occurred
1143             */
1144            public ShoppingCart fetchByG_U(long groupId, long userId)
1145                    throws SystemException {
1146                    return fetchByG_U(groupId, userId, true);
1147            }
1148    
1149            /**
1150             * Finds the shopping cart where groupId = &#63; and userId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1151             *
1152             * @param groupId the group id to search with
1153             * @param userId the user id to search with
1154             * @return the matching shopping cart, or <code>null</code> if a matching shopping cart could not be found
1155             * @throws SystemException if a system exception occurred
1156             */
1157            public ShoppingCart fetchByG_U(long groupId, long userId,
1158                    boolean retrieveFromCache) throws SystemException {
1159                    Object[] finderArgs = new Object[] { groupId, userId };
1160    
1161                    Object result = null;
1162    
1163                    if (retrieveFromCache) {
1164                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1165                                            finderArgs, this);
1166                    }
1167    
1168                    if (result == null) {
1169                            Session session = null;
1170    
1171                            try {
1172                                    session = openSession();
1173    
1174                                    StringBundler query = new StringBundler(3);
1175    
1176                                    query.append(_SQL_SELECT_SHOPPINGCART_WHERE);
1177    
1178                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1179    
1180                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1181    
1182                                    String sql = query.toString();
1183    
1184                                    Query q = session.createQuery(sql);
1185    
1186                                    QueryPos qPos = QueryPos.getInstance(q);
1187    
1188                                    qPos.add(groupId);
1189    
1190                                    qPos.add(userId);
1191    
1192                                    List<ShoppingCart> list = q.list();
1193    
1194                                    result = list;
1195    
1196                                    ShoppingCart shoppingCart = null;
1197    
1198                                    if (list.isEmpty()) {
1199                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1200                                                    finderArgs, list);
1201                                    }
1202                                    else {
1203                                            shoppingCart = list.get(0);
1204    
1205                                            cacheResult(shoppingCart);
1206    
1207                                            if ((shoppingCart.getGroupId() != groupId) ||
1208                                                            (shoppingCart.getUserId() != userId)) {
1209                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1210                                                            finderArgs, shoppingCart);
1211                                            }
1212                                    }
1213    
1214                                    return shoppingCart;
1215                            }
1216                            catch (Exception e) {
1217                                    throw processException(e);
1218                            }
1219                            finally {
1220                                    if (result == null) {
1221                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1222                                                    finderArgs, new ArrayList<ShoppingCart>());
1223                                    }
1224    
1225                                    closeSession(session);
1226                            }
1227                    }
1228                    else {
1229                            if (result instanceof List<?>) {
1230                                    return null;
1231                            }
1232                            else {
1233                                    return (ShoppingCart)result;
1234                            }
1235                    }
1236            }
1237    
1238            /**
1239             * Finds all the shopping carts.
1240             *
1241             * @return the shopping carts
1242             * @throws SystemException if a system exception occurred
1243             */
1244            public List<ShoppingCart> findAll() throws SystemException {
1245                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1246            }
1247    
1248            /**
1249             * Finds a range of all the shopping carts.
1250             *
1251             * <p>
1252             * 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.
1253             * </p>
1254             *
1255             * @param start the lower bound of the range of shopping carts to return
1256             * @param end the upper bound of the range of shopping carts to return (not inclusive)
1257             * @return the range of shopping carts
1258             * @throws SystemException if a system exception occurred
1259             */
1260            public List<ShoppingCart> findAll(int start, int end)
1261                    throws SystemException {
1262                    return findAll(start, end, null);
1263            }
1264    
1265            /**
1266             * Finds an ordered range of all the shopping carts.
1267             *
1268             * <p>
1269             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1270             * </p>
1271             *
1272             * @param start the lower bound of the range of shopping carts to return
1273             * @param end the upper bound of the range of shopping carts to return (not inclusive)
1274             * @param orderByComparator the comparator to order the results by
1275             * @return the ordered range of shopping carts
1276             * @throws SystemException if a system exception occurred
1277             */
1278            public List<ShoppingCart> findAll(int start, int end,
1279                    OrderByComparator orderByComparator) throws SystemException {
1280                    Object[] finderArgs = new Object[] {
1281                                    String.valueOf(start), String.valueOf(end),
1282                                    String.valueOf(orderByComparator)
1283                            };
1284    
1285                    List<ShoppingCart> list = (List<ShoppingCart>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1286                                    finderArgs, this);
1287    
1288                    if (list == null) {
1289                            Session session = null;
1290    
1291                            try {
1292                                    session = openSession();
1293    
1294                                    StringBundler query = null;
1295                                    String sql = null;
1296    
1297                                    if (orderByComparator != null) {
1298                                            query = new StringBundler(2 +
1299                                                            (orderByComparator.getOrderByFields().length * 3));
1300    
1301                                            query.append(_SQL_SELECT_SHOPPINGCART);
1302    
1303                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1304                                                    orderByComparator);
1305    
1306                                            sql = query.toString();
1307                                    }
1308                                    else {
1309                                            sql = _SQL_SELECT_SHOPPINGCART;
1310                                    }
1311    
1312                                    Query q = session.createQuery(sql);
1313    
1314                                    if (orderByComparator == null) {
1315                                            list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
1316                                                            start, end, false);
1317    
1318                                            Collections.sort(list);
1319                                    }
1320                                    else {
1321                                            list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
1322                                                            start, end);
1323                                    }
1324                            }
1325                            catch (Exception e) {
1326                                    throw processException(e);
1327                            }
1328                            finally {
1329                                    if (list == null) {
1330                                            list = new ArrayList<ShoppingCart>();
1331                                    }
1332    
1333                                    cacheResult(list);
1334    
1335                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1336    
1337                                    closeSession(session);
1338                            }
1339                    }
1340    
1341                    return list;
1342            }
1343    
1344            /**
1345             * Removes all the shopping carts where groupId = &#63; from the database.
1346             *
1347             * @param groupId the group id to search with
1348             * @throws SystemException if a system exception occurred
1349             */
1350            public void removeByGroupId(long groupId) throws SystemException {
1351                    for (ShoppingCart shoppingCart : findByGroupId(groupId)) {
1352                            remove(shoppingCart);
1353                    }
1354            }
1355    
1356            /**
1357             * Removes all the shopping carts where userId = &#63; from the database.
1358             *
1359             * @param userId the user id to search with
1360             * @throws SystemException if a system exception occurred
1361             */
1362            public void removeByUserId(long userId) throws SystemException {
1363                    for (ShoppingCart shoppingCart : findByUserId(userId)) {
1364                            remove(shoppingCart);
1365                    }
1366            }
1367    
1368            /**
1369             * Removes the shopping cart where groupId = &#63; and userId = &#63; from the database.
1370             *
1371             * @param groupId the group id to search with
1372             * @param userId the user id to search with
1373             * @throws SystemException if a system exception occurred
1374             */
1375            public void removeByG_U(long groupId, long userId)
1376                    throws NoSuchCartException, SystemException {
1377                    ShoppingCart shoppingCart = findByG_U(groupId, userId);
1378    
1379                    remove(shoppingCart);
1380            }
1381    
1382            /**
1383             * Removes all the shopping carts from the database.
1384             *
1385             * @throws SystemException if a system exception occurred
1386             */
1387            public void removeAll() throws SystemException {
1388                    for (ShoppingCart shoppingCart : findAll()) {
1389                            remove(shoppingCart);
1390                    }
1391            }
1392    
1393            /**
1394             * Counts all the shopping carts where groupId = &#63;.
1395             *
1396             * @param groupId the group id to search with
1397             * @return the number of matching shopping carts
1398             * @throws SystemException if a system exception occurred
1399             */
1400            public int countByGroupId(long groupId) throws SystemException {
1401                    Object[] finderArgs = new Object[] { groupId };
1402    
1403                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1404                                    finderArgs, this);
1405    
1406                    if (count == null) {
1407                            Session session = null;
1408    
1409                            try {
1410                                    session = openSession();
1411    
1412                                    StringBundler query = new StringBundler(2);
1413    
1414                                    query.append(_SQL_COUNT_SHOPPINGCART_WHERE);
1415    
1416                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1417    
1418                                    String sql = query.toString();
1419    
1420                                    Query q = session.createQuery(sql);
1421    
1422                                    QueryPos qPos = QueryPos.getInstance(q);
1423    
1424                                    qPos.add(groupId);
1425    
1426                                    count = (Long)q.uniqueResult();
1427                            }
1428                            catch (Exception e) {
1429                                    throw processException(e);
1430                            }
1431                            finally {
1432                                    if (count == null) {
1433                                            count = Long.valueOf(0);
1434                                    }
1435    
1436                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1437                                            finderArgs, count);
1438    
1439                                    closeSession(session);
1440                            }
1441                    }
1442    
1443                    return count.intValue();
1444            }
1445    
1446            /**
1447             * Counts all the shopping carts where userId = &#63;.
1448             *
1449             * @param userId the user id to search with
1450             * @return the number of matching shopping carts
1451             * @throws SystemException if a system exception occurred
1452             */
1453            public int countByUserId(long userId) throws SystemException {
1454                    Object[] finderArgs = new Object[] { userId };
1455    
1456                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1457                                    finderArgs, this);
1458    
1459                    if (count == null) {
1460                            Session session = null;
1461    
1462                            try {
1463                                    session = openSession();
1464    
1465                                    StringBundler query = new StringBundler(2);
1466    
1467                                    query.append(_SQL_COUNT_SHOPPINGCART_WHERE);
1468    
1469                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1470    
1471                                    String sql = query.toString();
1472    
1473                                    Query q = session.createQuery(sql);
1474    
1475                                    QueryPos qPos = QueryPos.getInstance(q);
1476    
1477                                    qPos.add(userId);
1478    
1479                                    count = (Long)q.uniqueResult();
1480                            }
1481                            catch (Exception e) {
1482                                    throw processException(e);
1483                            }
1484                            finally {
1485                                    if (count == null) {
1486                                            count = Long.valueOf(0);
1487                                    }
1488    
1489                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1490                                            finderArgs, count);
1491    
1492                                    closeSession(session);
1493                            }
1494                    }
1495    
1496                    return count.intValue();
1497            }
1498    
1499            /**
1500             * Counts all the shopping carts where groupId = &#63; and userId = &#63;.
1501             *
1502             * @param groupId the group id to search with
1503             * @param userId the user id to search with
1504             * @return the number of matching shopping carts
1505             * @throws SystemException if a system exception occurred
1506             */
1507            public int countByG_U(long groupId, long userId) throws SystemException {
1508                    Object[] finderArgs = new Object[] { groupId, userId };
1509    
1510                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1511                                    finderArgs, this);
1512    
1513                    if (count == null) {
1514                            Session session = null;
1515    
1516                            try {
1517                                    session = openSession();
1518    
1519                                    StringBundler query = new StringBundler(3);
1520    
1521                                    query.append(_SQL_COUNT_SHOPPINGCART_WHERE);
1522    
1523                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1524    
1525                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1526    
1527                                    String sql = query.toString();
1528    
1529                                    Query q = session.createQuery(sql);
1530    
1531                                    QueryPos qPos = QueryPos.getInstance(q);
1532    
1533                                    qPos.add(groupId);
1534    
1535                                    qPos.add(userId);
1536    
1537                                    count = (Long)q.uniqueResult();
1538                            }
1539                            catch (Exception e) {
1540                                    throw processException(e);
1541                            }
1542                            finally {
1543                                    if (count == null) {
1544                                            count = Long.valueOf(0);
1545                                    }
1546    
1547                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1548                                            count);
1549    
1550                                    closeSession(session);
1551                            }
1552                    }
1553    
1554                    return count.intValue();
1555            }
1556    
1557            /**
1558             * Counts all the shopping carts.
1559             *
1560             * @return the number of shopping carts
1561             * @throws SystemException if a system exception occurred
1562             */
1563            public int countAll() throws SystemException {
1564                    Object[] finderArgs = new Object[0];
1565    
1566                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1567                                    finderArgs, this);
1568    
1569                    if (count == null) {
1570                            Session session = null;
1571    
1572                            try {
1573                                    session = openSession();
1574    
1575                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGCART);
1576    
1577                                    count = (Long)q.uniqueResult();
1578                            }
1579                            catch (Exception e) {
1580                                    throw processException(e);
1581                            }
1582                            finally {
1583                                    if (count == null) {
1584                                            count = Long.valueOf(0);
1585                                    }
1586    
1587                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1588                                            count);
1589    
1590                                    closeSession(session);
1591                            }
1592                    }
1593    
1594                    return count.intValue();
1595            }
1596    
1597            /**
1598             * Initializes the shopping cart persistence.
1599             */
1600            public void afterPropertiesSet() {
1601                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1602                                            com.liferay.portal.util.PropsUtil.get(
1603                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingCart")));
1604    
1605                    if (listenerClassNames.length > 0) {
1606                            try {
1607                                    List<ModelListener<ShoppingCart>> listenersList = new ArrayList<ModelListener<ShoppingCart>>();
1608    
1609                                    for (String listenerClassName : listenerClassNames) {
1610                                            listenersList.add((ModelListener<ShoppingCart>)InstanceFactory.newInstance(
1611                                                            listenerClassName));
1612                                    }
1613    
1614                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1615                            }
1616                            catch (Exception e) {
1617                                    _log.error(e);
1618                            }
1619                    }
1620            }
1621    
1622            public void destroy() {
1623                    EntityCacheUtil.removeCache(ShoppingCartImpl.class.getName());
1624                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1625                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1626            }
1627    
1628            @BeanReference(type = ShoppingCartPersistence.class)
1629            protected ShoppingCartPersistence shoppingCartPersistence;
1630            @BeanReference(type = ShoppingCategoryPersistence.class)
1631            protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1632            @BeanReference(type = ShoppingCouponPersistence.class)
1633            protected ShoppingCouponPersistence shoppingCouponPersistence;
1634            @BeanReference(type = ShoppingItemPersistence.class)
1635            protected ShoppingItemPersistence shoppingItemPersistence;
1636            @BeanReference(type = ShoppingItemFieldPersistence.class)
1637            protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1638            @BeanReference(type = ShoppingItemPricePersistence.class)
1639            protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1640            @BeanReference(type = ShoppingOrderPersistence.class)
1641            protected ShoppingOrderPersistence shoppingOrderPersistence;
1642            @BeanReference(type = ShoppingOrderItemPersistence.class)
1643            protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1644            @BeanReference(type = ResourcePersistence.class)
1645            protected ResourcePersistence resourcePersistence;
1646            @BeanReference(type = UserPersistence.class)
1647            protected UserPersistence userPersistence;
1648            private static final String _SQL_SELECT_SHOPPINGCART = "SELECT shoppingCart FROM ShoppingCart shoppingCart";
1649            private static final String _SQL_SELECT_SHOPPINGCART_WHERE = "SELECT shoppingCart FROM ShoppingCart shoppingCart WHERE ";
1650            private static final String _SQL_COUNT_SHOPPINGCART = "SELECT COUNT(shoppingCart) FROM ShoppingCart shoppingCart";
1651            private static final String _SQL_COUNT_SHOPPINGCART_WHERE = "SELECT COUNT(shoppingCart) FROM ShoppingCart shoppingCart WHERE ";
1652            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "shoppingCart.groupId = ?";
1653            private static final String _FINDER_COLUMN_USERID_USERID_2 = "shoppingCart.userId = ?";
1654            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "shoppingCart.groupId = ? AND ";
1655            private static final String _FINDER_COLUMN_G_U_USERID_2 = "shoppingCart.userId = ?";
1656            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingCart.";
1657            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingCart exists with the primary key ";
1658            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingCart exists with the key {";
1659            private static Log _log = LogFactoryUtil.getLog(ShoppingCartPersistenceImpl.class);
1660    }