001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.shopping.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstanceFactory;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.StringUtil;
034    import com.liferay.portal.kernel.util.UnmodifiableList;
035    import com.liferay.portal.model.CacheModel;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038    
039    import com.liferay.portlet.shopping.NoSuchCartException;
040    import com.liferay.portlet.shopping.model.ShoppingCart;
041    import com.liferay.portlet.shopping.model.impl.ShoppingCartImpl;
042    import com.liferay.portlet.shopping.model.impl.ShoppingCartModelImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the shopping cart service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see ShoppingCartPersistence
059     * @see ShoppingCartUtil
060     * @generated
061     */
062    public class ShoppingCartPersistenceImpl extends BasePersistenceImpl<ShoppingCart>
063            implements ShoppingCartPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * 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.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = ShoppingCartImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
075                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, ShoppingCartImpl.class,
076                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
078                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, ShoppingCartImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
081                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, Long.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
084                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, ShoppingCartImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
086                            new String[] {
087                                    Long.class.getName(),
088                                    
089                            Integer.class.getName(), Integer.class.getName(),
090                                    OrderByComparator.class.getName()
091                            });
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
093                    new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
094                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, ShoppingCartImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
096                            new String[] { Long.class.getName() },
097                            ShoppingCartModelImpl.GROUPID_COLUMN_BITMASK);
098            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
099                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, Long.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
101                            new String[] { Long.class.getName() });
102    
103            /**
104             * Returns all the shopping carts where groupId = &#63;.
105             *
106             * @param groupId the group ID
107             * @return the matching shopping carts
108             * @throws SystemException if a system exception occurred
109             */
110            @Override
111            public List<ShoppingCart> findByGroupId(long groupId)
112                    throws SystemException {
113                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
114            }
115    
116            /**
117             * Returns a range of all the shopping carts where groupId = &#63;.
118             *
119             * <p>
120             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCartModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
121             * </p>
122             *
123             * @param groupId the group ID
124             * @param start the lower bound of the range of shopping carts
125             * @param end the upper bound of the range of shopping carts (not inclusive)
126             * @return the range of matching shopping carts
127             * @throws SystemException if a system exception occurred
128             */
129            @Override
130            public List<ShoppingCart> findByGroupId(long groupId, int start, int end)
131                    throws SystemException {
132                    return findByGroupId(groupId, start, end, null);
133            }
134    
135            /**
136             * Returns an ordered range of all the shopping carts where groupId = &#63;.
137             *
138             * <p>
139             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCartModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
140             * </p>
141             *
142             * @param groupId the group ID
143             * @param start the lower bound of the range of shopping carts
144             * @param end the upper bound of the range of shopping carts (not inclusive)
145             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
146             * @return the ordered range of matching shopping carts
147             * @throws SystemException if a system exception occurred
148             */
149            @Override
150            public List<ShoppingCart> findByGroupId(long groupId, int start, int end,
151                    OrderByComparator orderByComparator) throws SystemException {
152                    boolean pagination = true;
153                    FinderPath finderPath = null;
154                    Object[] finderArgs = null;
155    
156                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
157                                    (orderByComparator == null)) {
158                            pagination = false;
159                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
160                            finderArgs = new Object[] { groupId };
161                    }
162                    else {
163                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
164                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
165                    }
166    
167                    List<ShoppingCart> list = (List<ShoppingCart>)FinderCacheUtil.getResult(finderPath,
168                                    finderArgs, this);
169    
170                    if ((list != null) && !list.isEmpty()) {
171                            for (ShoppingCart shoppingCart : list) {
172                                    if ((groupId != shoppingCart.getGroupId())) {
173                                            list = null;
174    
175                                            break;
176                                    }
177                            }
178                    }
179    
180                    if (list == null) {
181                            StringBundler query = null;
182    
183                            if (orderByComparator != null) {
184                                    query = new StringBundler(3 +
185                                                    (orderByComparator.getOrderByFields().length * 3));
186                            }
187                            else {
188                                    query = new StringBundler(3);
189                            }
190    
191                            query.append(_SQL_SELECT_SHOPPINGCART_WHERE);
192    
193                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
194    
195                            if (orderByComparator != null) {
196                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
197                                            orderByComparator);
198                            }
199                            else
200                             if (pagination) {
201                                    query.append(ShoppingCartModelImpl.ORDER_BY_JPQL);
202                            }
203    
204                            String sql = query.toString();
205    
206                            Session session = null;
207    
208                            try {
209                                    session = openSession();
210    
211                                    Query q = session.createQuery(sql);
212    
213                                    QueryPos qPos = QueryPos.getInstance(q);
214    
215                                    qPos.add(groupId);
216    
217                                    if (!pagination) {
218                                            list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
219                                                            start, end, false);
220    
221                                            Collections.sort(list);
222    
223                                            list = new UnmodifiableList<ShoppingCart>(list);
224                                    }
225                                    else {
226                                            list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
227                                                            start, end);
228                                    }
229    
230                                    cacheResult(list);
231    
232                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
233                            }
234                            catch (Exception e) {
235                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
236    
237                                    throw processException(e);
238                            }
239                            finally {
240                                    closeSession(session);
241                            }
242                    }
243    
244                    return list;
245            }
246    
247            /**
248             * Returns the first shopping cart in the ordered set where groupId = &#63;.
249             *
250             * @param groupId the group ID
251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
252             * @return the first matching shopping cart
253             * @throws com.liferay.portlet.shopping.NoSuchCartException if a matching shopping cart could not be found
254             * @throws SystemException if a system exception occurred
255             */
256            @Override
257            public ShoppingCart findByGroupId_First(long groupId,
258                    OrderByComparator orderByComparator)
259                    throws NoSuchCartException, SystemException {
260                    ShoppingCart shoppingCart = fetchByGroupId_First(groupId,
261                                    orderByComparator);
262    
263                    if (shoppingCart != null) {
264                            return shoppingCart;
265                    }
266    
267                    StringBundler msg = new StringBundler(4);
268    
269                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
270    
271                    msg.append("groupId=");
272                    msg.append(groupId);
273    
274                    msg.append(StringPool.CLOSE_CURLY_BRACE);
275    
276                    throw new NoSuchCartException(msg.toString());
277            }
278    
279            /**
280             * Returns the first shopping cart in the ordered set where groupId = &#63;.
281             *
282             * @param groupId the group ID
283             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
284             * @return the first matching shopping cart, or <code>null</code> if a matching shopping cart could not be found
285             * @throws SystemException if a system exception occurred
286             */
287            @Override
288            public ShoppingCart fetchByGroupId_First(long groupId,
289                    OrderByComparator orderByComparator) throws SystemException {
290                    List<ShoppingCart> list = findByGroupId(groupId, 0, 1, orderByComparator);
291    
292                    if (!list.isEmpty()) {
293                            return list.get(0);
294                    }
295    
296                    return null;
297            }
298    
299            /**
300             * Returns the last shopping cart in the ordered set where groupId = &#63;.
301             *
302             * @param groupId the group ID
303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
304             * @return the last matching shopping cart
305             * @throws com.liferay.portlet.shopping.NoSuchCartException if a matching shopping cart could not be found
306             * @throws SystemException if a system exception occurred
307             */
308            @Override
309            public ShoppingCart findByGroupId_Last(long groupId,
310                    OrderByComparator orderByComparator)
311                    throws NoSuchCartException, SystemException {
312                    ShoppingCart shoppingCart = fetchByGroupId_Last(groupId,
313                                    orderByComparator);
314    
315                    if (shoppingCart != null) {
316                            return shoppingCart;
317                    }
318    
319                    StringBundler msg = new StringBundler(4);
320    
321                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
322    
323                    msg.append("groupId=");
324                    msg.append(groupId);
325    
326                    msg.append(StringPool.CLOSE_CURLY_BRACE);
327    
328                    throw new NoSuchCartException(msg.toString());
329            }
330    
331            /**
332             * Returns the last shopping cart in the ordered set where groupId = &#63;.
333             *
334             * @param groupId the group ID
335             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
336             * @return the last matching shopping cart, or <code>null</code> if a matching shopping cart could not be found
337             * @throws SystemException if a system exception occurred
338             */
339            @Override
340            public ShoppingCart fetchByGroupId_Last(long groupId,
341                    OrderByComparator orderByComparator) throws SystemException {
342                    int count = countByGroupId(groupId);
343    
344                    if (count == 0) {
345                            return null;
346                    }
347    
348                    List<ShoppingCart> list = findByGroupId(groupId, count - 1, count,
349                                    orderByComparator);
350    
351                    if (!list.isEmpty()) {
352                            return list.get(0);
353                    }
354    
355                    return null;
356            }
357    
358            /**
359             * Returns the shopping carts before and after the current shopping cart in the ordered set where groupId = &#63;.
360             *
361             * @param cartId the primary key of the current shopping cart
362             * @param groupId the group ID
363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
364             * @return the previous, current, and next shopping cart
365             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
366             * @throws SystemException if a system exception occurred
367             */
368            @Override
369            public ShoppingCart[] findByGroupId_PrevAndNext(long cartId, long groupId,
370                    OrderByComparator orderByComparator)
371                    throws NoSuchCartException, SystemException {
372                    ShoppingCart shoppingCart = findByPrimaryKey(cartId);
373    
374                    Session session = null;
375    
376                    try {
377                            session = openSession();
378    
379                            ShoppingCart[] array = new ShoppingCartImpl[3];
380    
381                            array[0] = getByGroupId_PrevAndNext(session, shoppingCart, groupId,
382                                            orderByComparator, true);
383    
384                            array[1] = shoppingCart;
385    
386                            array[2] = getByGroupId_PrevAndNext(session, shoppingCart, groupId,
387                                            orderByComparator, false);
388    
389                            return array;
390                    }
391                    catch (Exception e) {
392                            throw processException(e);
393                    }
394                    finally {
395                            closeSession(session);
396                    }
397            }
398    
399            protected ShoppingCart getByGroupId_PrevAndNext(Session session,
400                    ShoppingCart shoppingCart, long groupId,
401                    OrderByComparator orderByComparator, boolean previous) {
402                    StringBundler query = null;
403    
404                    if (orderByComparator != null) {
405                            query = new StringBundler(6 +
406                                            (orderByComparator.getOrderByFields().length * 6));
407                    }
408                    else {
409                            query = new StringBundler(3);
410                    }
411    
412                    query.append(_SQL_SELECT_SHOPPINGCART_WHERE);
413    
414                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
415    
416                    if (orderByComparator != null) {
417                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
418    
419                            if (orderByConditionFields.length > 0) {
420                                    query.append(WHERE_AND);
421                            }
422    
423                            for (int i = 0; i < orderByConditionFields.length; i++) {
424                                    query.append(_ORDER_BY_ENTITY_ALIAS);
425                                    query.append(orderByConditionFields[i]);
426    
427                                    if ((i + 1) < orderByConditionFields.length) {
428                                            if (orderByComparator.isAscending() ^ previous) {
429                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
430                                            }
431                                            else {
432                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
433                                            }
434                                    }
435                                    else {
436                                            if (orderByComparator.isAscending() ^ previous) {
437                                                    query.append(WHERE_GREATER_THAN);
438                                            }
439                                            else {
440                                                    query.append(WHERE_LESSER_THAN);
441                                            }
442                                    }
443                            }
444    
445                            query.append(ORDER_BY_CLAUSE);
446    
447                            String[] orderByFields = orderByComparator.getOrderByFields();
448    
449                            for (int i = 0; i < orderByFields.length; i++) {
450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
451                                    query.append(orderByFields[i]);
452    
453                                    if ((i + 1) < orderByFields.length) {
454                                            if (orderByComparator.isAscending() ^ previous) {
455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
456                                            }
457                                            else {
458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
459                                            }
460                                    }
461                                    else {
462                                            if (orderByComparator.isAscending() ^ previous) {
463                                                    query.append(ORDER_BY_ASC);
464                                            }
465                                            else {
466                                                    query.append(ORDER_BY_DESC);
467                                            }
468                                    }
469                            }
470                    }
471                    else {
472                            query.append(ShoppingCartModelImpl.ORDER_BY_JPQL);
473                    }
474    
475                    String sql = query.toString();
476    
477                    Query q = session.createQuery(sql);
478    
479                    q.setFirstResult(0);
480                    q.setMaxResults(2);
481    
482                    QueryPos qPos = QueryPos.getInstance(q);
483    
484                    qPos.add(groupId);
485    
486                    if (orderByComparator != null) {
487                            Object[] values = orderByComparator.getOrderByConditionValues(shoppingCart);
488    
489                            for (Object value : values) {
490                                    qPos.add(value);
491                            }
492                    }
493    
494                    List<ShoppingCart> list = q.list();
495    
496                    if (list.size() == 2) {
497                            return list.get(1);
498                    }
499                    else {
500                            return null;
501                    }
502            }
503    
504            /**
505             * Removes all the shopping carts where groupId = &#63; from the database.
506             *
507             * @param groupId the group ID
508             * @throws SystemException if a system exception occurred
509             */
510            @Override
511            public void removeByGroupId(long groupId) throws SystemException {
512                    for (ShoppingCart shoppingCart : findByGroupId(groupId,
513                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
514                            remove(shoppingCart);
515                    }
516            }
517    
518            /**
519             * Returns the number of shopping carts where groupId = &#63;.
520             *
521             * @param groupId the group ID
522             * @return the number of matching shopping carts
523             * @throws SystemException if a system exception occurred
524             */
525            @Override
526            public int countByGroupId(long groupId) throws SystemException {
527                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
528    
529                    Object[] finderArgs = new Object[] { groupId };
530    
531                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
532                                    this);
533    
534                    if (count == null) {
535                            StringBundler query = new StringBundler(2);
536    
537                            query.append(_SQL_COUNT_SHOPPINGCART_WHERE);
538    
539                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
540    
541                            String sql = query.toString();
542    
543                            Session session = null;
544    
545                            try {
546                                    session = openSession();
547    
548                                    Query q = session.createQuery(sql);
549    
550                                    QueryPos qPos = QueryPos.getInstance(q);
551    
552                                    qPos.add(groupId);
553    
554                                    count = (Long)q.uniqueResult();
555    
556                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
557                            }
558                            catch (Exception e) {
559                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
560    
561                                    throw processException(e);
562                            }
563                            finally {
564                                    closeSession(session);
565                            }
566                    }
567    
568                    return count.intValue();
569            }
570    
571            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "shoppingCart.groupId = ?";
572            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
573                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, ShoppingCartImpl.class,
574                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
575                            new String[] {
576                                    Long.class.getName(),
577                                    
578                            Integer.class.getName(), Integer.class.getName(),
579                                    OrderByComparator.class.getName()
580                            });
581            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
582                    new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
583                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, ShoppingCartImpl.class,
584                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
585                            new String[] { Long.class.getName() },
586                            ShoppingCartModelImpl.USERID_COLUMN_BITMASK);
587            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
588                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, Long.class,
589                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
590                            new String[] { Long.class.getName() });
591    
592            /**
593             * Returns all the shopping carts where userId = &#63;.
594             *
595             * @param userId the user ID
596             * @return the matching shopping carts
597             * @throws SystemException if a system exception occurred
598             */
599            @Override
600            public List<ShoppingCart> findByUserId(long userId)
601                    throws SystemException {
602                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
603            }
604    
605            /**
606             * Returns a range of all the shopping carts where userId = &#63;.
607             *
608             * <p>
609             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCartModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
610             * </p>
611             *
612             * @param userId the user ID
613             * @param start the lower bound of the range of shopping carts
614             * @param end the upper bound of the range of shopping carts (not inclusive)
615             * @return the range of matching shopping carts
616             * @throws SystemException if a system exception occurred
617             */
618            @Override
619            public List<ShoppingCart> findByUserId(long userId, int start, int end)
620                    throws SystemException {
621                    return findByUserId(userId, start, end, null);
622            }
623    
624            /**
625             * Returns an ordered range of all the shopping carts where userId = &#63;.
626             *
627             * <p>
628             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCartModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
629             * </p>
630             *
631             * @param userId the user ID
632             * @param start the lower bound of the range of shopping carts
633             * @param end the upper bound of the range of shopping carts (not inclusive)
634             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
635             * @return the ordered range of matching shopping carts
636             * @throws SystemException if a system exception occurred
637             */
638            @Override
639            public List<ShoppingCart> findByUserId(long userId, int start, int end,
640                    OrderByComparator orderByComparator) throws SystemException {
641                    boolean pagination = true;
642                    FinderPath finderPath = null;
643                    Object[] finderArgs = null;
644    
645                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
646                                    (orderByComparator == null)) {
647                            pagination = false;
648                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
649                            finderArgs = new Object[] { userId };
650                    }
651                    else {
652                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
653                            finderArgs = new Object[] { userId, start, end, orderByComparator };
654                    }
655    
656                    List<ShoppingCart> list = (List<ShoppingCart>)FinderCacheUtil.getResult(finderPath,
657                                    finderArgs, this);
658    
659                    if ((list != null) && !list.isEmpty()) {
660                            for (ShoppingCart shoppingCart : list) {
661                                    if ((userId != shoppingCart.getUserId())) {
662                                            list = null;
663    
664                                            break;
665                                    }
666                            }
667                    }
668    
669                    if (list == null) {
670                            StringBundler query = null;
671    
672                            if (orderByComparator != null) {
673                                    query = new StringBundler(3 +
674                                                    (orderByComparator.getOrderByFields().length * 3));
675                            }
676                            else {
677                                    query = new StringBundler(3);
678                            }
679    
680                            query.append(_SQL_SELECT_SHOPPINGCART_WHERE);
681    
682                            query.append(_FINDER_COLUMN_USERID_USERID_2);
683    
684                            if (orderByComparator != null) {
685                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
686                                            orderByComparator);
687                            }
688                            else
689                             if (pagination) {
690                                    query.append(ShoppingCartModelImpl.ORDER_BY_JPQL);
691                            }
692    
693                            String sql = query.toString();
694    
695                            Session session = null;
696    
697                            try {
698                                    session = openSession();
699    
700                                    Query q = session.createQuery(sql);
701    
702                                    QueryPos qPos = QueryPos.getInstance(q);
703    
704                                    qPos.add(userId);
705    
706                                    if (!pagination) {
707                                            list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
708                                                            start, end, false);
709    
710                                            Collections.sort(list);
711    
712                                            list = new UnmodifiableList<ShoppingCart>(list);
713                                    }
714                                    else {
715                                            list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
716                                                            start, end);
717                                    }
718    
719                                    cacheResult(list);
720    
721                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
722                            }
723                            catch (Exception e) {
724                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
725    
726                                    throw processException(e);
727                            }
728                            finally {
729                                    closeSession(session);
730                            }
731                    }
732    
733                    return list;
734            }
735    
736            /**
737             * Returns the first shopping cart in the ordered set where userId = &#63;.
738             *
739             * @param userId the user ID
740             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
741             * @return the first matching shopping cart
742             * @throws com.liferay.portlet.shopping.NoSuchCartException if a matching shopping cart could not be found
743             * @throws SystemException if a system exception occurred
744             */
745            @Override
746            public ShoppingCart findByUserId_First(long userId,
747                    OrderByComparator orderByComparator)
748                    throws NoSuchCartException, SystemException {
749                    ShoppingCart shoppingCart = fetchByUserId_First(userId,
750                                    orderByComparator);
751    
752                    if (shoppingCart != null) {
753                            return shoppingCart;
754                    }
755    
756                    StringBundler msg = new StringBundler(4);
757    
758                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
759    
760                    msg.append("userId=");
761                    msg.append(userId);
762    
763                    msg.append(StringPool.CLOSE_CURLY_BRACE);
764    
765                    throw new NoSuchCartException(msg.toString());
766            }
767    
768            /**
769             * Returns the first shopping cart in the ordered set where userId = &#63;.
770             *
771             * @param userId the user ID
772             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
773             * @return the first matching shopping cart, or <code>null</code> if a matching shopping cart could not be found
774             * @throws SystemException if a system exception occurred
775             */
776            @Override
777            public ShoppingCart fetchByUserId_First(long userId,
778                    OrderByComparator orderByComparator) throws SystemException {
779                    List<ShoppingCart> list = findByUserId(userId, 0, 1, orderByComparator);
780    
781                    if (!list.isEmpty()) {
782                            return list.get(0);
783                    }
784    
785                    return null;
786            }
787    
788            /**
789             * Returns the last shopping cart in the ordered set where userId = &#63;.
790             *
791             * @param userId the user ID
792             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
793             * @return the last matching shopping cart
794             * @throws com.liferay.portlet.shopping.NoSuchCartException if a matching shopping cart could not be found
795             * @throws SystemException if a system exception occurred
796             */
797            @Override
798            public ShoppingCart findByUserId_Last(long userId,
799                    OrderByComparator orderByComparator)
800                    throws NoSuchCartException, SystemException {
801                    ShoppingCart shoppingCart = fetchByUserId_Last(userId, orderByComparator);
802    
803                    if (shoppingCart != null) {
804                            return shoppingCart;
805                    }
806    
807                    StringBundler msg = new StringBundler(4);
808    
809                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
810    
811                    msg.append("userId=");
812                    msg.append(userId);
813    
814                    msg.append(StringPool.CLOSE_CURLY_BRACE);
815    
816                    throw new NoSuchCartException(msg.toString());
817            }
818    
819            /**
820             * Returns the last shopping cart in the ordered set where userId = &#63;.
821             *
822             * @param userId the user ID
823             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
824             * @return the last matching shopping cart, or <code>null</code> if a matching shopping cart could not be found
825             * @throws SystemException if a system exception occurred
826             */
827            @Override
828            public ShoppingCart fetchByUserId_Last(long userId,
829                    OrderByComparator orderByComparator) throws SystemException {
830                    int count = countByUserId(userId);
831    
832                    if (count == 0) {
833                            return null;
834                    }
835    
836                    List<ShoppingCart> list = findByUserId(userId, count - 1, count,
837                                    orderByComparator);
838    
839                    if (!list.isEmpty()) {
840                            return list.get(0);
841                    }
842    
843                    return null;
844            }
845    
846            /**
847             * Returns the shopping carts before and after the current shopping cart in the ordered set where userId = &#63;.
848             *
849             * @param cartId the primary key of the current shopping cart
850             * @param userId the user ID
851             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
852             * @return the previous, current, and next shopping cart
853             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
854             * @throws SystemException if a system exception occurred
855             */
856            @Override
857            public ShoppingCart[] findByUserId_PrevAndNext(long cartId, long userId,
858                    OrderByComparator orderByComparator)
859                    throws NoSuchCartException, SystemException {
860                    ShoppingCart shoppingCart = findByPrimaryKey(cartId);
861    
862                    Session session = null;
863    
864                    try {
865                            session = openSession();
866    
867                            ShoppingCart[] array = new ShoppingCartImpl[3];
868    
869                            array[0] = getByUserId_PrevAndNext(session, shoppingCart, userId,
870                                            orderByComparator, true);
871    
872                            array[1] = shoppingCart;
873    
874                            array[2] = getByUserId_PrevAndNext(session, shoppingCart, userId,
875                                            orderByComparator, false);
876    
877                            return array;
878                    }
879                    catch (Exception e) {
880                            throw processException(e);
881                    }
882                    finally {
883                            closeSession(session);
884                    }
885            }
886    
887            protected ShoppingCart getByUserId_PrevAndNext(Session session,
888                    ShoppingCart shoppingCart, long userId,
889                    OrderByComparator orderByComparator, boolean previous) {
890                    StringBundler query = null;
891    
892                    if (orderByComparator != null) {
893                            query = new StringBundler(6 +
894                                            (orderByComparator.getOrderByFields().length * 6));
895                    }
896                    else {
897                            query = new StringBundler(3);
898                    }
899    
900                    query.append(_SQL_SELECT_SHOPPINGCART_WHERE);
901    
902                    query.append(_FINDER_COLUMN_USERID_USERID_2);
903    
904                    if (orderByComparator != null) {
905                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
906    
907                            if (orderByConditionFields.length > 0) {
908                                    query.append(WHERE_AND);
909                            }
910    
911                            for (int i = 0; i < orderByConditionFields.length; i++) {
912                                    query.append(_ORDER_BY_ENTITY_ALIAS);
913                                    query.append(orderByConditionFields[i]);
914    
915                                    if ((i + 1) < orderByConditionFields.length) {
916                                            if (orderByComparator.isAscending() ^ previous) {
917                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
918                                            }
919                                            else {
920                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
921                                            }
922                                    }
923                                    else {
924                                            if (orderByComparator.isAscending() ^ previous) {
925                                                    query.append(WHERE_GREATER_THAN);
926                                            }
927                                            else {
928                                                    query.append(WHERE_LESSER_THAN);
929                                            }
930                                    }
931                            }
932    
933                            query.append(ORDER_BY_CLAUSE);
934    
935                            String[] orderByFields = orderByComparator.getOrderByFields();
936    
937                            for (int i = 0; i < orderByFields.length; i++) {
938                                    query.append(_ORDER_BY_ENTITY_ALIAS);
939                                    query.append(orderByFields[i]);
940    
941                                    if ((i + 1) < orderByFields.length) {
942                                            if (orderByComparator.isAscending() ^ previous) {
943                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
944                                            }
945                                            else {
946                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
947                                            }
948                                    }
949                                    else {
950                                            if (orderByComparator.isAscending() ^ previous) {
951                                                    query.append(ORDER_BY_ASC);
952                                            }
953                                            else {
954                                                    query.append(ORDER_BY_DESC);
955                                            }
956                                    }
957                            }
958                    }
959                    else {
960                            query.append(ShoppingCartModelImpl.ORDER_BY_JPQL);
961                    }
962    
963                    String sql = query.toString();
964    
965                    Query q = session.createQuery(sql);
966    
967                    q.setFirstResult(0);
968                    q.setMaxResults(2);
969    
970                    QueryPos qPos = QueryPos.getInstance(q);
971    
972                    qPos.add(userId);
973    
974                    if (orderByComparator != null) {
975                            Object[] values = orderByComparator.getOrderByConditionValues(shoppingCart);
976    
977                            for (Object value : values) {
978                                    qPos.add(value);
979                            }
980                    }
981    
982                    List<ShoppingCart> list = q.list();
983    
984                    if (list.size() == 2) {
985                            return list.get(1);
986                    }
987                    else {
988                            return null;
989                    }
990            }
991    
992            /**
993             * Removes all the shopping carts where userId = &#63; from the database.
994             *
995             * @param userId the user ID
996             * @throws SystemException if a system exception occurred
997             */
998            @Override
999            public void removeByUserId(long userId) throws SystemException {
1000                    for (ShoppingCart shoppingCart : findByUserId(userId,
1001                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1002                            remove(shoppingCart);
1003                    }
1004            }
1005    
1006            /**
1007             * Returns the number of shopping carts where userId = &#63;.
1008             *
1009             * @param userId the user ID
1010             * @return the number of matching shopping carts
1011             * @throws SystemException if a system exception occurred
1012             */
1013            @Override
1014            public int countByUserId(long userId) throws SystemException {
1015                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1016    
1017                    Object[] finderArgs = new Object[] { userId };
1018    
1019                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1020                                    this);
1021    
1022                    if (count == null) {
1023                            StringBundler query = new StringBundler(2);
1024    
1025                            query.append(_SQL_COUNT_SHOPPINGCART_WHERE);
1026    
1027                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1028    
1029                            String sql = query.toString();
1030    
1031                            Session session = null;
1032    
1033                            try {
1034                                    session = openSession();
1035    
1036                                    Query q = session.createQuery(sql);
1037    
1038                                    QueryPos qPos = QueryPos.getInstance(q);
1039    
1040                                    qPos.add(userId);
1041    
1042                                    count = (Long)q.uniqueResult();
1043    
1044                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1045                            }
1046                            catch (Exception e) {
1047                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1048    
1049                                    throw processException(e);
1050                            }
1051                            finally {
1052                                    closeSession(session);
1053                            }
1054                    }
1055    
1056                    return count.intValue();
1057            }
1058    
1059            private static final String _FINDER_COLUMN_USERID_USERID_2 = "shoppingCart.userId = ?";
1060            public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1061                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, ShoppingCartImpl.class,
1062                            FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
1063                            new String[] { Long.class.getName(), Long.class.getName() },
1064                            ShoppingCartModelImpl.GROUPID_COLUMN_BITMASK |
1065                            ShoppingCartModelImpl.USERID_COLUMN_BITMASK);
1066            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1067                            ShoppingCartModelImpl.FINDER_CACHE_ENABLED, Long.class,
1068                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
1069                            new String[] { Long.class.getName(), Long.class.getName() });
1070    
1071            /**
1072             * Returns the shopping cart where groupId = &#63; and userId = &#63; or throws a {@link com.liferay.portlet.shopping.NoSuchCartException} if it could not be found.
1073             *
1074             * @param groupId the group ID
1075             * @param userId the user ID
1076             * @return the matching shopping cart
1077             * @throws com.liferay.portlet.shopping.NoSuchCartException if a matching shopping cart could not be found
1078             * @throws SystemException if a system exception occurred
1079             */
1080            @Override
1081            public ShoppingCart findByG_U(long groupId, long userId)
1082                    throws NoSuchCartException, SystemException {
1083                    ShoppingCart shoppingCart = fetchByG_U(groupId, userId);
1084    
1085                    if (shoppingCart == null) {
1086                            StringBundler msg = new StringBundler(6);
1087    
1088                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1089    
1090                            msg.append("groupId=");
1091                            msg.append(groupId);
1092    
1093                            msg.append(", userId=");
1094                            msg.append(userId);
1095    
1096                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1097    
1098                            if (_log.isWarnEnabled()) {
1099                                    _log.warn(msg.toString());
1100                            }
1101    
1102                            throw new NoSuchCartException(msg.toString());
1103                    }
1104    
1105                    return shoppingCart;
1106            }
1107    
1108            /**
1109             * Returns the shopping cart where groupId = &#63; and userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1110             *
1111             * @param groupId the group ID
1112             * @param userId the user ID
1113             * @return the matching shopping cart, or <code>null</code> if a matching shopping cart could not be found
1114             * @throws SystemException if a system exception occurred
1115             */
1116            @Override
1117            public ShoppingCart fetchByG_U(long groupId, long userId)
1118                    throws SystemException {
1119                    return fetchByG_U(groupId, userId, true);
1120            }
1121    
1122            /**
1123             * Returns 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.
1124             *
1125             * @param groupId the group ID
1126             * @param userId the user ID
1127             * @param retrieveFromCache whether to use the finder cache
1128             * @return the matching shopping cart, or <code>null</code> if a matching shopping cart could not be found
1129             * @throws SystemException if a system exception occurred
1130             */
1131            @Override
1132            public ShoppingCart fetchByG_U(long groupId, long userId,
1133                    boolean retrieveFromCache) throws SystemException {
1134                    Object[] finderArgs = new Object[] { groupId, userId };
1135    
1136                    Object result = null;
1137    
1138                    if (retrieveFromCache) {
1139                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1140                                            finderArgs, this);
1141                    }
1142    
1143                    if (result instanceof ShoppingCart) {
1144                            ShoppingCart shoppingCart = (ShoppingCart)result;
1145    
1146                            if ((groupId != shoppingCart.getGroupId()) ||
1147                                            (userId != shoppingCart.getUserId())) {
1148                                    result = null;
1149                            }
1150                    }
1151    
1152                    if (result == null) {
1153                            StringBundler query = new StringBundler(4);
1154    
1155                            query.append(_SQL_SELECT_SHOPPINGCART_WHERE);
1156    
1157                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1158    
1159                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1160    
1161                            String sql = query.toString();
1162    
1163                            Session session = null;
1164    
1165                            try {
1166                                    session = openSession();
1167    
1168                                    Query q = session.createQuery(sql);
1169    
1170                                    QueryPos qPos = QueryPos.getInstance(q);
1171    
1172                                    qPos.add(groupId);
1173    
1174                                    qPos.add(userId);
1175    
1176                                    List<ShoppingCart> list = q.list();
1177    
1178                                    if (list.isEmpty()) {
1179                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1180                                                    finderArgs, list);
1181                                    }
1182                                    else {
1183                                            ShoppingCart shoppingCart = list.get(0);
1184    
1185                                            result = shoppingCart;
1186    
1187                                            cacheResult(shoppingCart);
1188    
1189                                            if ((shoppingCart.getGroupId() != groupId) ||
1190                                                            (shoppingCart.getUserId() != userId)) {
1191                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1192                                                            finderArgs, shoppingCart);
1193                                            }
1194                                    }
1195                            }
1196                            catch (Exception e) {
1197                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
1198                                            finderArgs);
1199    
1200                                    throw processException(e);
1201                            }
1202                            finally {
1203                                    closeSession(session);
1204                            }
1205                    }
1206    
1207                    if (result instanceof List<?>) {
1208                            return null;
1209                    }
1210                    else {
1211                            return (ShoppingCart)result;
1212                    }
1213            }
1214    
1215            /**
1216             * Removes the shopping cart where groupId = &#63; and userId = &#63; from the database.
1217             *
1218             * @param groupId the group ID
1219             * @param userId the user ID
1220             * @return the shopping cart that was removed
1221             * @throws SystemException if a system exception occurred
1222             */
1223            @Override
1224            public ShoppingCart removeByG_U(long groupId, long userId)
1225                    throws NoSuchCartException, SystemException {
1226                    ShoppingCart shoppingCart = findByG_U(groupId, userId);
1227    
1228                    return remove(shoppingCart);
1229            }
1230    
1231            /**
1232             * Returns the number of shopping carts where groupId = &#63; and userId = &#63;.
1233             *
1234             * @param groupId the group ID
1235             * @param userId the user ID
1236             * @return the number of matching shopping carts
1237             * @throws SystemException if a system exception occurred
1238             */
1239            @Override
1240            public int countByG_U(long groupId, long userId) throws SystemException {
1241                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
1242    
1243                    Object[] finderArgs = new Object[] { groupId, userId };
1244    
1245                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1246                                    this);
1247    
1248                    if (count == null) {
1249                            StringBundler query = new StringBundler(3);
1250    
1251                            query.append(_SQL_COUNT_SHOPPINGCART_WHERE);
1252    
1253                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1254    
1255                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1256    
1257                            String sql = query.toString();
1258    
1259                            Session session = null;
1260    
1261                            try {
1262                                    session = openSession();
1263    
1264                                    Query q = session.createQuery(sql);
1265    
1266                                    QueryPos qPos = QueryPos.getInstance(q);
1267    
1268                                    qPos.add(groupId);
1269    
1270                                    qPos.add(userId);
1271    
1272                                    count = (Long)q.uniqueResult();
1273    
1274                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1275                            }
1276                            catch (Exception e) {
1277                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1278    
1279                                    throw processException(e);
1280                            }
1281                            finally {
1282                                    closeSession(session);
1283                            }
1284                    }
1285    
1286                    return count.intValue();
1287            }
1288    
1289            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "shoppingCart.groupId = ? AND ";
1290            private static final String _FINDER_COLUMN_G_U_USERID_2 = "shoppingCart.userId = ?";
1291    
1292            /**
1293             * Caches the shopping cart in the entity cache if it is enabled.
1294             *
1295             * @param shoppingCart the shopping cart
1296             */
1297            @Override
1298            public void cacheResult(ShoppingCart shoppingCart) {
1299                    EntityCacheUtil.putResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1300                            ShoppingCartImpl.class, shoppingCart.getPrimaryKey(), shoppingCart);
1301    
1302                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1303                            new Object[] { shoppingCart.getGroupId(), shoppingCart.getUserId() },
1304                            shoppingCart);
1305    
1306                    shoppingCart.resetOriginalValues();
1307            }
1308    
1309            /**
1310             * Caches the shopping carts in the entity cache if it is enabled.
1311             *
1312             * @param shoppingCarts the shopping carts
1313             */
1314            @Override
1315            public void cacheResult(List<ShoppingCart> shoppingCarts) {
1316                    for (ShoppingCart shoppingCart : shoppingCarts) {
1317                            if (EntityCacheUtil.getResult(
1318                                                    ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1319                                                    ShoppingCartImpl.class, shoppingCart.getPrimaryKey()) == null) {
1320                                    cacheResult(shoppingCart);
1321                            }
1322                            else {
1323                                    shoppingCart.resetOriginalValues();
1324                            }
1325                    }
1326            }
1327    
1328            /**
1329             * Clears the cache for all shopping carts.
1330             *
1331             * <p>
1332             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1333             * </p>
1334             */
1335            @Override
1336            public void clearCache() {
1337                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1338                            CacheRegistryUtil.clear(ShoppingCartImpl.class.getName());
1339                    }
1340    
1341                    EntityCacheUtil.clearCache(ShoppingCartImpl.class.getName());
1342    
1343                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1344                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1345                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1346            }
1347    
1348            /**
1349             * Clears the cache for the shopping cart.
1350             *
1351             * <p>
1352             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1353             * </p>
1354             */
1355            @Override
1356            public void clearCache(ShoppingCart shoppingCart) {
1357                    EntityCacheUtil.removeResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1358                            ShoppingCartImpl.class, shoppingCart.getPrimaryKey());
1359    
1360                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1361                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1362    
1363                    clearUniqueFindersCache(shoppingCart);
1364            }
1365    
1366            @Override
1367            public void clearCache(List<ShoppingCart> shoppingCarts) {
1368                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1369                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1370    
1371                    for (ShoppingCart shoppingCart : shoppingCarts) {
1372                            EntityCacheUtil.removeResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1373                                    ShoppingCartImpl.class, shoppingCart.getPrimaryKey());
1374    
1375                            clearUniqueFindersCache(shoppingCart);
1376                    }
1377            }
1378    
1379            protected void cacheUniqueFindersCache(ShoppingCart shoppingCart) {
1380                    if (shoppingCart.isNew()) {
1381                            Object[] args = new Object[] {
1382                                            shoppingCart.getGroupId(), shoppingCart.getUserId()
1383                                    };
1384    
1385                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, args,
1386                                    Long.valueOf(1));
1387                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U, args,
1388                                    shoppingCart);
1389                    }
1390                    else {
1391                            ShoppingCartModelImpl shoppingCartModelImpl = (ShoppingCartModelImpl)shoppingCart;
1392    
1393                            if ((shoppingCartModelImpl.getColumnBitmask() &
1394                                            FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
1395                                    Object[] args = new Object[] {
1396                                                    shoppingCart.getGroupId(), shoppingCart.getUserId()
1397                                            };
1398    
1399                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, args,
1400                                            Long.valueOf(1));
1401                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U, args,
1402                                            shoppingCart);
1403                            }
1404                    }
1405            }
1406    
1407            protected void clearUniqueFindersCache(ShoppingCart shoppingCart) {
1408                    ShoppingCartModelImpl shoppingCartModelImpl = (ShoppingCartModelImpl)shoppingCart;
1409    
1410                    Object[] args = new Object[] {
1411                                    shoppingCart.getGroupId(), shoppingCart.getUserId()
1412                            };
1413    
1414                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1415                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
1416    
1417                    if ((shoppingCartModelImpl.getColumnBitmask() &
1418                                    FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
1419                            args = new Object[] {
1420                                            shoppingCartModelImpl.getOriginalGroupId(),
1421                                            shoppingCartModelImpl.getOriginalUserId()
1422                                    };
1423    
1424                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1425                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
1426                    }
1427            }
1428    
1429            /**
1430             * Creates a new shopping cart with the primary key. Does not add the shopping cart to the database.
1431             *
1432             * @param cartId the primary key for the new shopping cart
1433             * @return the new shopping cart
1434             */
1435            @Override
1436            public ShoppingCart create(long cartId) {
1437                    ShoppingCart shoppingCart = new ShoppingCartImpl();
1438    
1439                    shoppingCart.setNew(true);
1440                    shoppingCart.setPrimaryKey(cartId);
1441    
1442                    return shoppingCart;
1443            }
1444    
1445            /**
1446             * Removes the shopping cart with the primary key from the database. Also notifies the appropriate model listeners.
1447             *
1448             * @param cartId the primary key of the shopping cart
1449             * @return the shopping cart that was removed
1450             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
1451             * @throws SystemException if a system exception occurred
1452             */
1453            @Override
1454            public ShoppingCart remove(long cartId)
1455                    throws NoSuchCartException, SystemException {
1456                    return remove((Serializable)cartId);
1457            }
1458    
1459            /**
1460             * Removes the shopping cart with the primary key from the database. Also notifies the appropriate model listeners.
1461             *
1462             * @param primaryKey the primary key of the shopping cart
1463             * @return the shopping cart that was removed
1464             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
1465             * @throws SystemException if a system exception occurred
1466             */
1467            @Override
1468            public ShoppingCart remove(Serializable primaryKey)
1469                    throws NoSuchCartException, SystemException {
1470                    Session session = null;
1471    
1472                    try {
1473                            session = openSession();
1474    
1475                            ShoppingCart shoppingCart = (ShoppingCart)session.get(ShoppingCartImpl.class,
1476                                            primaryKey);
1477    
1478                            if (shoppingCart == null) {
1479                                    if (_log.isWarnEnabled()) {
1480                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1481                                    }
1482    
1483                                    throw new NoSuchCartException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1484                                            primaryKey);
1485                            }
1486    
1487                            return remove(shoppingCart);
1488                    }
1489                    catch (NoSuchCartException nsee) {
1490                            throw nsee;
1491                    }
1492                    catch (Exception e) {
1493                            throw processException(e);
1494                    }
1495                    finally {
1496                            closeSession(session);
1497                    }
1498            }
1499    
1500            @Override
1501            protected ShoppingCart removeImpl(ShoppingCart shoppingCart)
1502                    throws SystemException {
1503                    shoppingCart = toUnwrappedModel(shoppingCart);
1504    
1505                    Session session = null;
1506    
1507                    try {
1508                            session = openSession();
1509    
1510                            if (!session.contains(shoppingCart)) {
1511                                    shoppingCart = (ShoppingCart)session.get(ShoppingCartImpl.class,
1512                                                    shoppingCart.getPrimaryKeyObj());
1513                            }
1514    
1515                            if (shoppingCart != null) {
1516                                    session.delete(shoppingCart);
1517                            }
1518                    }
1519                    catch (Exception e) {
1520                            throw processException(e);
1521                    }
1522                    finally {
1523                            closeSession(session);
1524                    }
1525    
1526                    if (shoppingCart != null) {
1527                            clearCache(shoppingCart);
1528                    }
1529    
1530                    return shoppingCart;
1531            }
1532    
1533            @Override
1534            public ShoppingCart updateImpl(
1535                    com.liferay.portlet.shopping.model.ShoppingCart shoppingCart)
1536                    throws SystemException {
1537                    shoppingCart = toUnwrappedModel(shoppingCart);
1538    
1539                    boolean isNew = shoppingCart.isNew();
1540    
1541                    ShoppingCartModelImpl shoppingCartModelImpl = (ShoppingCartModelImpl)shoppingCart;
1542    
1543                    Session session = null;
1544    
1545                    try {
1546                            session = openSession();
1547    
1548                            if (shoppingCart.isNew()) {
1549                                    session.save(shoppingCart);
1550    
1551                                    shoppingCart.setNew(false);
1552                            }
1553                            else {
1554                                    session.merge(shoppingCart);
1555                            }
1556                    }
1557                    catch (Exception e) {
1558                            throw processException(e);
1559                    }
1560                    finally {
1561                            closeSession(session);
1562                    }
1563    
1564                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1565    
1566                    if (isNew || !ShoppingCartModelImpl.COLUMN_BITMASK_ENABLED) {
1567                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1568                    }
1569    
1570                    else {
1571                            if ((shoppingCartModelImpl.getColumnBitmask() &
1572                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1573                                    Object[] args = new Object[] {
1574                                                    shoppingCartModelImpl.getOriginalGroupId()
1575                                            };
1576    
1577                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1578                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1579                                            args);
1580    
1581                                    args = new Object[] { shoppingCartModelImpl.getGroupId() };
1582    
1583                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1584                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1585                                            args);
1586                            }
1587    
1588                            if ((shoppingCartModelImpl.getColumnBitmask() &
1589                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1590                                    Object[] args = new Object[] {
1591                                                    shoppingCartModelImpl.getOriginalUserId()
1592                                            };
1593    
1594                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1595                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1596                                            args);
1597    
1598                                    args = new Object[] { shoppingCartModelImpl.getUserId() };
1599    
1600                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1601                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1602                                            args);
1603                            }
1604                    }
1605    
1606                    EntityCacheUtil.putResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1607                            ShoppingCartImpl.class, shoppingCart.getPrimaryKey(), shoppingCart);
1608    
1609                    clearUniqueFindersCache(shoppingCart);
1610                    cacheUniqueFindersCache(shoppingCart);
1611    
1612                    return shoppingCart;
1613            }
1614    
1615            protected ShoppingCart toUnwrappedModel(ShoppingCart shoppingCart) {
1616                    if (shoppingCart instanceof ShoppingCartImpl) {
1617                            return shoppingCart;
1618                    }
1619    
1620                    ShoppingCartImpl shoppingCartImpl = new ShoppingCartImpl();
1621    
1622                    shoppingCartImpl.setNew(shoppingCart.isNew());
1623                    shoppingCartImpl.setPrimaryKey(shoppingCart.getPrimaryKey());
1624    
1625                    shoppingCartImpl.setCartId(shoppingCart.getCartId());
1626                    shoppingCartImpl.setGroupId(shoppingCart.getGroupId());
1627                    shoppingCartImpl.setCompanyId(shoppingCart.getCompanyId());
1628                    shoppingCartImpl.setUserId(shoppingCart.getUserId());
1629                    shoppingCartImpl.setUserName(shoppingCart.getUserName());
1630                    shoppingCartImpl.setCreateDate(shoppingCart.getCreateDate());
1631                    shoppingCartImpl.setModifiedDate(shoppingCart.getModifiedDate());
1632                    shoppingCartImpl.setItemIds(shoppingCart.getItemIds());
1633                    shoppingCartImpl.setCouponCodes(shoppingCart.getCouponCodes());
1634                    shoppingCartImpl.setAltShipping(shoppingCart.getAltShipping());
1635                    shoppingCartImpl.setInsure(shoppingCart.isInsure());
1636    
1637                    return shoppingCartImpl;
1638            }
1639    
1640            /**
1641             * Returns the shopping cart with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1642             *
1643             * @param primaryKey the primary key of the shopping cart
1644             * @return the shopping cart
1645             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
1646             * @throws SystemException if a system exception occurred
1647             */
1648            @Override
1649            public ShoppingCart findByPrimaryKey(Serializable primaryKey)
1650                    throws NoSuchCartException, SystemException {
1651                    ShoppingCart shoppingCart = fetchByPrimaryKey(primaryKey);
1652    
1653                    if (shoppingCart == null) {
1654                            if (_log.isWarnEnabled()) {
1655                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1656                            }
1657    
1658                            throw new NoSuchCartException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1659                                    primaryKey);
1660                    }
1661    
1662                    return shoppingCart;
1663            }
1664    
1665            /**
1666             * Returns the shopping cart with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchCartException} if it could not be found.
1667             *
1668             * @param cartId the primary key of the shopping cart
1669             * @return the shopping cart
1670             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
1671             * @throws SystemException if a system exception occurred
1672             */
1673            @Override
1674            public ShoppingCart findByPrimaryKey(long cartId)
1675                    throws NoSuchCartException, SystemException {
1676                    return findByPrimaryKey((Serializable)cartId);
1677            }
1678    
1679            /**
1680             * Returns the shopping cart with the primary key or returns <code>null</code> if it could not be found.
1681             *
1682             * @param primaryKey the primary key of the shopping cart
1683             * @return the shopping cart, or <code>null</code> if a shopping cart with the primary key could not be found
1684             * @throws SystemException if a system exception occurred
1685             */
1686            @Override
1687            public ShoppingCart fetchByPrimaryKey(Serializable primaryKey)
1688                    throws SystemException {
1689                    ShoppingCart shoppingCart = (ShoppingCart)EntityCacheUtil.getResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1690                                    ShoppingCartImpl.class, primaryKey);
1691    
1692                    if (shoppingCart == _nullShoppingCart) {
1693                            return null;
1694                    }
1695    
1696                    if (shoppingCart == null) {
1697                            Session session = null;
1698    
1699                            try {
1700                                    session = openSession();
1701    
1702                                    shoppingCart = (ShoppingCart)session.get(ShoppingCartImpl.class,
1703                                                    primaryKey);
1704    
1705                                    if (shoppingCart != null) {
1706                                            cacheResult(shoppingCart);
1707                                    }
1708                                    else {
1709                                            EntityCacheUtil.putResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1710                                                    ShoppingCartImpl.class, primaryKey, _nullShoppingCart);
1711                                    }
1712                            }
1713                            catch (Exception e) {
1714                                    EntityCacheUtil.removeResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1715                                            ShoppingCartImpl.class, primaryKey);
1716    
1717                                    throw processException(e);
1718                            }
1719                            finally {
1720                                    closeSession(session);
1721                            }
1722                    }
1723    
1724                    return shoppingCart;
1725            }
1726    
1727            /**
1728             * Returns the shopping cart with the primary key or returns <code>null</code> if it could not be found.
1729             *
1730             * @param cartId the primary key of the shopping cart
1731             * @return the shopping cart, or <code>null</code> if a shopping cart with the primary key could not be found
1732             * @throws SystemException if a system exception occurred
1733             */
1734            @Override
1735            public ShoppingCart fetchByPrimaryKey(long cartId)
1736                    throws SystemException {
1737                    return fetchByPrimaryKey((Serializable)cartId);
1738            }
1739    
1740            /**
1741             * Returns all the shopping carts.
1742             *
1743             * @return the shopping carts
1744             * @throws SystemException if a system exception occurred
1745             */
1746            @Override
1747            public List<ShoppingCart> findAll() throws SystemException {
1748                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1749            }
1750    
1751            /**
1752             * Returns a range of all the shopping carts.
1753             *
1754             * <p>
1755             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCartModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1756             * </p>
1757             *
1758             * @param start the lower bound of the range of shopping carts
1759             * @param end the upper bound of the range of shopping carts (not inclusive)
1760             * @return the range of shopping carts
1761             * @throws SystemException if a system exception occurred
1762             */
1763            @Override
1764            public List<ShoppingCart> findAll(int start, int end)
1765                    throws SystemException {
1766                    return findAll(start, end, null);
1767            }
1768    
1769            /**
1770             * Returns an ordered range of all the shopping carts.
1771             *
1772             * <p>
1773             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCartModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1774             * </p>
1775             *
1776             * @param start the lower bound of the range of shopping carts
1777             * @param end the upper bound of the range of shopping carts (not inclusive)
1778             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1779             * @return the ordered range of shopping carts
1780             * @throws SystemException if a system exception occurred
1781             */
1782            @Override
1783            public List<ShoppingCart> findAll(int start, int end,
1784                    OrderByComparator orderByComparator) throws SystemException {
1785                    boolean pagination = true;
1786                    FinderPath finderPath = null;
1787                    Object[] finderArgs = null;
1788    
1789                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1790                                    (orderByComparator == null)) {
1791                            pagination = false;
1792                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1793                            finderArgs = FINDER_ARGS_EMPTY;
1794                    }
1795                    else {
1796                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1797                            finderArgs = new Object[] { start, end, orderByComparator };
1798                    }
1799    
1800                    List<ShoppingCart> list = (List<ShoppingCart>)FinderCacheUtil.getResult(finderPath,
1801                                    finderArgs, this);
1802    
1803                    if (list == null) {
1804                            StringBundler query = null;
1805                            String sql = null;
1806    
1807                            if (orderByComparator != null) {
1808                                    query = new StringBundler(2 +
1809                                                    (orderByComparator.getOrderByFields().length * 3));
1810    
1811                                    query.append(_SQL_SELECT_SHOPPINGCART);
1812    
1813                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1814                                            orderByComparator);
1815    
1816                                    sql = query.toString();
1817                            }
1818                            else {
1819                                    sql = _SQL_SELECT_SHOPPINGCART;
1820    
1821                                    if (pagination) {
1822                                            sql = sql.concat(ShoppingCartModelImpl.ORDER_BY_JPQL);
1823                                    }
1824                            }
1825    
1826                            Session session = null;
1827    
1828                            try {
1829                                    session = openSession();
1830    
1831                                    Query q = session.createQuery(sql);
1832    
1833                                    if (!pagination) {
1834                                            list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
1835                                                            start, end, false);
1836    
1837                                            Collections.sort(list);
1838    
1839                                            list = new UnmodifiableList<ShoppingCart>(list);
1840                                    }
1841                                    else {
1842                                            list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
1843                                                            start, end);
1844                                    }
1845    
1846                                    cacheResult(list);
1847    
1848                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1849                            }
1850                            catch (Exception e) {
1851                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1852    
1853                                    throw processException(e);
1854                            }
1855                            finally {
1856                                    closeSession(session);
1857                            }
1858                    }
1859    
1860                    return list;
1861            }
1862    
1863            /**
1864             * Removes all the shopping carts from the database.
1865             *
1866             * @throws SystemException if a system exception occurred
1867             */
1868            @Override
1869            public void removeAll() throws SystemException {
1870                    for (ShoppingCart shoppingCart : findAll()) {
1871                            remove(shoppingCart);
1872                    }
1873            }
1874    
1875            /**
1876             * Returns the number of shopping carts.
1877             *
1878             * @return the number of shopping carts
1879             * @throws SystemException if a system exception occurred
1880             */
1881            @Override
1882            public int countAll() throws SystemException {
1883                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1884                                    FINDER_ARGS_EMPTY, this);
1885    
1886                    if (count == null) {
1887                            Session session = null;
1888    
1889                            try {
1890                                    session = openSession();
1891    
1892                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGCART);
1893    
1894                                    count = (Long)q.uniqueResult();
1895    
1896                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1897                                            FINDER_ARGS_EMPTY, count);
1898                            }
1899                            catch (Exception e) {
1900                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1901                                            FINDER_ARGS_EMPTY);
1902    
1903                                    throw processException(e);
1904                            }
1905                            finally {
1906                                    closeSession(session);
1907                            }
1908                    }
1909    
1910                    return count.intValue();
1911            }
1912    
1913            /**
1914             * Initializes the shopping cart persistence.
1915             */
1916            public void afterPropertiesSet() {
1917                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1918                                            com.liferay.portal.util.PropsUtil.get(
1919                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingCart")));
1920    
1921                    if (listenerClassNames.length > 0) {
1922                            try {
1923                                    List<ModelListener<ShoppingCart>> listenersList = new ArrayList<ModelListener<ShoppingCart>>();
1924    
1925                                    for (String listenerClassName : listenerClassNames) {
1926                                            listenersList.add((ModelListener<ShoppingCart>)InstanceFactory.newInstance(
1927                                                            getClassLoader(), listenerClassName));
1928                                    }
1929    
1930                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1931                            }
1932                            catch (Exception e) {
1933                                    _log.error(e);
1934                            }
1935                    }
1936            }
1937    
1938            public void destroy() {
1939                    EntityCacheUtil.removeCache(ShoppingCartImpl.class.getName());
1940                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1941                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1942                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1943            }
1944    
1945            private static final String _SQL_SELECT_SHOPPINGCART = "SELECT shoppingCart FROM ShoppingCart shoppingCart";
1946            private static final String _SQL_SELECT_SHOPPINGCART_WHERE = "SELECT shoppingCart FROM ShoppingCart shoppingCart WHERE ";
1947            private static final String _SQL_COUNT_SHOPPINGCART = "SELECT COUNT(shoppingCart) FROM ShoppingCart shoppingCart";
1948            private static final String _SQL_COUNT_SHOPPINGCART_WHERE = "SELECT COUNT(shoppingCart) FROM ShoppingCart shoppingCart WHERE ";
1949            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingCart.";
1950            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingCart exists with the primary key ";
1951            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingCart exists with the key {";
1952            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1953            private static Log _log = LogFactoryUtil.getLog(ShoppingCartPersistenceImpl.class);
1954            private static ShoppingCart _nullShoppingCart = new ShoppingCartImpl() {
1955                            @Override
1956                            public Object clone() {
1957                                    return this;
1958                            }
1959    
1960                            @Override
1961                            public CacheModel<ShoppingCart> toCacheModel() {
1962                                    return _nullShoppingCartCacheModel;
1963                            }
1964                    };
1965    
1966            private static CacheModel<ShoppingCart> _nullShoppingCartCacheModel = new CacheModel<ShoppingCart>() {
1967                            @Override
1968                            public ShoppingCart toEntityModel() {
1969                                    return _nullShoppingCart;
1970                            }
1971                    };
1972    }