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            public ShoppingCartPersistenceImpl() {
1293                    setModelClass(ShoppingCart.class);
1294            }
1295    
1296            /**
1297             * Caches the shopping cart in the entity cache if it is enabled.
1298             *
1299             * @param shoppingCart the shopping cart
1300             */
1301            @Override
1302            public void cacheResult(ShoppingCart shoppingCart) {
1303                    EntityCacheUtil.putResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1304                            ShoppingCartImpl.class, shoppingCart.getPrimaryKey(), shoppingCart);
1305    
1306                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1307                            new Object[] { shoppingCart.getGroupId(), shoppingCart.getUserId() },
1308                            shoppingCart);
1309    
1310                    shoppingCart.resetOriginalValues();
1311            }
1312    
1313            /**
1314             * Caches the shopping carts in the entity cache if it is enabled.
1315             *
1316             * @param shoppingCarts the shopping carts
1317             */
1318            @Override
1319            public void cacheResult(List<ShoppingCart> shoppingCarts) {
1320                    for (ShoppingCart shoppingCart : shoppingCarts) {
1321                            if (EntityCacheUtil.getResult(
1322                                                    ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1323                                                    ShoppingCartImpl.class, shoppingCart.getPrimaryKey()) == null) {
1324                                    cacheResult(shoppingCart);
1325                            }
1326                            else {
1327                                    shoppingCart.resetOriginalValues();
1328                            }
1329                    }
1330            }
1331    
1332            /**
1333             * Clears the cache for all shopping carts.
1334             *
1335             * <p>
1336             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1337             * </p>
1338             */
1339            @Override
1340            public void clearCache() {
1341                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1342                            CacheRegistryUtil.clear(ShoppingCartImpl.class.getName());
1343                    }
1344    
1345                    EntityCacheUtil.clearCache(ShoppingCartImpl.class.getName());
1346    
1347                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1348                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1349                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1350            }
1351    
1352            /**
1353             * Clears the cache for the shopping cart.
1354             *
1355             * <p>
1356             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1357             * </p>
1358             */
1359            @Override
1360            public void clearCache(ShoppingCart shoppingCart) {
1361                    EntityCacheUtil.removeResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1362                            ShoppingCartImpl.class, shoppingCart.getPrimaryKey());
1363    
1364                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1365                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1366    
1367                    clearUniqueFindersCache(shoppingCart);
1368            }
1369    
1370            @Override
1371            public void clearCache(List<ShoppingCart> shoppingCarts) {
1372                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1373                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1374    
1375                    for (ShoppingCart shoppingCart : shoppingCarts) {
1376                            EntityCacheUtil.removeResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1377                                    ShoppingCartImpl.class, shoppingCart.getPrimaryKey());
1378    
1379                            clearUniqueFindersCache(shoppingCart);
1380                    }
1381            }
1382    
1383            protected void cacheUniqueFindersCache(ShoppingCart shoppingCart) {
1384                    if (shoppingCart.isNew()) {
1385                            Object[] args = new Object[] {
1386                                            shoppingCart.getGroupId(), shoppingCart.getUserId()
1387                                    };
1388    
1389                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, args,
1390                                    Long.valueOf(1));
1391                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U, args,
1392                                    shoppingCart);
1393                    }
1394                    else {
1395                            ShoppingCartModelImpl shoppingCartModelImpl = (ShoppingCartModelImpl)shoppingCart;
1396    
1397                            if ((shoppingCartModelImpl.getColumnBitmask() &
1398                                            FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
1399                                    Object[] args = new Object[] {
1400                                                    shoppingCart.getGroupId(), shoppingCart.getUserId()
1401                                            };
1402    
1403                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, args,
1404                                            Long.valueOf(1));
1405                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U, args,
1406                                            shoppingCart);
1407                            }
1408                    }
1409            }
1410    
1411            protected void clearUniqueFindersCache(ShoppingCart shoppingCart) {
1412                    ShoppingCartModelImpl shoppingCartModelImpl = (ShoppingCartModelImpl)shoppingCart;
1413    
1414                    Object[] args = new Object[] {
1415                                    shoppingCart.getGroupId(), shoppingCart.getUserId()
1416                            };
1417    
1418                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1419                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
1420    
1421                    if ((shoppingCartModelImpl.getColumnBitmask() &
1422                                    FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
1423                            args = new Object[] {
1424                                            shoppingCartModelImpl.getOriginalGroupId(),
1425                                            shoppingCartModelImpl.getOriginalUserId()
1426                                    };
1427    
1428                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1429                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
1430                    }
1431            }
1432    
1433            /**
1434             * Creates a new shopping cart with the primary key. Does not add the shopping cart to the database.
1435             *
1436             * @param cartId the primary key for the new shopping cart
1437             * @return the new shopping cart
1438             */
1439            @Override
1440            public ShoppingCart create(long cartId) {
1441                    ShoppingCart shoppingCart = new ShoppingCartImpl();
1442    
1443                    shoppingCart.setNew(true);
1444                    shoppingCart.setPrimaryKey(cartId);
1445    
1446                    return shoppingCart;
1447            }
1448    
1449            /**
1450             * Removes the shopping cart with the primary key from the database. Also notifies the appropriate model listeners.
1451             *
1452             * @param cartId the primary key of the shopping cart
1453             * @return the shopping cart that was removed
1454             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
1455             * @throws SystemException if a system exception occurred
1456             */
1457            @Override
1458            public ShoppingCart remove(long cartId)
1459                    throws NoSuchCartException, SystemException {
1460                    return remove((Serializable)cartId);
1461            }
1462    
1463            /**
1464             * Removes the shopping cart with the primary key from the database. Also notifies the appropriate model listeners.
1465             *
1466             * @param primaryKey the primary key of the shopping cart
1467             * @return the shopping cart that was removed
1468             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
1469             * @throws SystemException if a system exception occurred
1470             */
1471            @Override
1472            public ShoppingCart remove(Serializable primaryKey)
1473                    throws NoSuchCartException, SystemException {
1474                    Session session = null;
1475    
1476                    try {
1477                            session = openSession();
1478    
1479                            ShoppingCart shoppingCart = (ShoppingCart)session.get(ShoppingCartImpl.class,
1480                                            primaryKey);
1481    
1482                            if (shoppingCart == null) {
1483                                    if (_log.isWarnEnabled()) {
1484                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1485                                    }
1486    
1487                                    throw new NoSuchCartException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1488                                            primaryKey);
1489                            }
1490    
1491                            return remove(shoppingCart);
1492                    }
1493                    catch (NoSuchCartException nsee) {
1494                            throw nsee;
1495                    }
1496                    catch (Exception e) {
1497                            throw processException(e);
1498                    }
1499                    finally {
1500                            closeSession(session);
1501                    }
1502            }
1503    
1504            @Override
1505            protected ShoppingCart removeImpl(ShoppingCart shoppingCart)
1506                    throws SystemException {
1507                    shoppingCart = toUnwrappedModel(shoppingCart);
1508    
1509                    Session session = null;
1510    
1511                    try {
1512                            session = openSession();
1513    
1514                            if (!session.contains(shoppingCart)) {
1515                                    shoppingCart = (ShoppingCart)session.get(ShoppingCartImpl.class,
1516                                                    shoppingCart.getPrimaryKeyObj());
1517                            }
1518    
1519                            if (shoppingCart != null) {
1520                                    session.delete(shoppingCart);
1521                            }
1522                    }
1523                    catch (Exception e) {
1524                            throw processException(e);
1525                    }
1526                    finally {
1527                            closeSession(session);
1528                    }
1529    
1530                    if (shoppingCart != null) {
1531                            clearCache(shoppingCart);
1532                    }
1533    
1534                    return shoppingCart;
1535            }
1536    
1537            @Override
1538            public ShoppingCart updateImpl(
1539                    com.liferay.portlet.shopping.model.ShoppingCart shoppingCart)
1540                    throws SystemException {
1541                    shoppingCart = toUnwrappedModel(shoppingCart);
1542    
1543                    boolean isNew = shoppingCart.isNew();
1544    
1545                    ShoppingCartModelImpl shoppingCartModelImpl = (ShoppingCartModelImpl)shoppingCart;
1546    
1547                    Session session = null;
1548    
1549                    try {
1550                            session = openSession();
1551    
1552                            if (shoppingCart.isNew()) {
1553                                    session.save(shoppingCart);
1554    
1555                                    shoppingCart.setNew(false);
1556                            }
1557                            else {
1558                                    session.merge(shoppingCart);
1559                            }
1560                    }
1561                    catch (Exception e) {
1562                            throw processException(e);
1563                    }
1564                    finally {
1565                            closeSession(session);
1566                    }
1567    
1568                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1569    
1570                    if (isNew || !ShoppingCartModelImpl.COLUMN_BITMASK_ENABLED) {
1571                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1572                    }
1573    
1574                    else {
1575                            if ((shoppingCartModelImpl.getColumnBitmask() &
1576                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1577                                    Object[] args = new Object[] {
1578                                                    shoppingCartModelImpl.getOriginalGroupId()
1579                                            };
1580    
1581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1582                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1583                                            args);
1584    
1585                                    args = new Object[] { shoppingCartModelImpl.getGroupId() };
1586    
1587                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1588                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1589                                            args);
1590                            }
1591    
1592                            if ((shoppingCartModelImpl.getColumnBitmask() &
1593                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1594                                    Object[] args = new Object[] {
1595                                                    shoppingCartModelImpl.getOriginalUserId()
1596                                            };
1597    
1598                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1599                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1600                                            args);
1601    
1602                                    args = new Object[] { shoppingCartModelImpl.getUserId() };
1603    
1604                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1605                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1606                                            args);
1607                            }
1608                    }
1609    
1610                    EntityCacheUtil.putResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1611                            ShoppingCartImpl.class, shoppingCart.getPrimaryKey(), shoppingCart);
1612    
1613                    clearUniqueFindersCache(shoppingCart);
1614                    cacheUniqueFindersCache(shoppingCart);
1615    
1616                    return shoppingCart;
1617            }
1618    
1619            protected ShoppingCart toUnwrappedModel(ShoppingCart shoppingCart) {
1620                    if (shoppingCart instanceof ShoppingCartImpl) {
1621                            return shoppingCart;
1622                    }
1623    
1624                    ShoppingCartImpl shoppingCartImpl = new ShoppingCartImpl();
1625    
1626                    shoppingCartImpl.setNew(shoppingCart.isNew());
1627                    shoppingCartImpl.setPrimaryKey(shoppingCart.getPrimaryKey());
1628    
1629                    shoppingCartImpl.setCartId(shoppingCart.getCartId());
1630                    shoppingCartImpl.setGroupId(shoppingCart.getGroupId());
1631                    shoppingCartImpl.setCompanyId(shoppingCart.getCompanyId());
1632                    shoppingCartImpl.setUserId(shoppingCart.getUserId());
1633                    shoppingCartImpl.setUserName(shoppingCart.getUserName());
1634                    shoppingCartImpl.setCreateDate(shoppingCart.getCreateDate());
1635                    shoppingCartImpl.setModifiedDate(shoppingCart.getModifiedDate());
1636                    shoppingCartImpl.setItemIds(shoppingCart.getItemIds());
1637                    shoppingCartImpl.setCouponCodes(shoppingCart.getCouponCodes());
1638                    shoppingCartImpl.setAltShipping(shoppingCart.getAltShipping());
1639                    shoppingCartImpl.setInsure(shoppingCart.isInsure());
1640    
1641                    return shoppingCartImpl;
1642            }
1643    
1644            /**
1645             * Returns the shopping cart with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1646             *
1647             * @param primaryKey the primary key of the shopping cart
1648             * @return the shopping cart
1649             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
1650             * @throws SystemException if a system exception occurred
1651             */
1652            @Override
1653            public ShoppingCart findByPrimaryKey(Serializable primaryKey)
1654                    throws NoSuchCartException, SystemException {
1655                    ShoppingCart shoppingCart = fetchByPrimaryKey(primaryKey);
1656    
1657                    if (shoppingCart == null) {
1658                            if (_log.isWarnEnabled()) {
1659                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1660                            }
1661    
1662                            throw new NoSuchCartException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1663                                    primaryKey);
1664                    }
1665    
1666                    return shoppingCart;
1667            }
1668    
1669            /**
1670             * Returns the shopping cart with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchCartException} if it could not be found.
1671             *
1672             * @param cartId the primary key of the shopping cart
1673             * @return the shopping cart
1674             * @throws com.liferay.portlet.shopping.NoSuchCartException if a shopping cart with the primary key could not be found
1675             * @throws SystemException if a system exception occurred
1676             */
1677            @Override
1678            public ShoppingCart findByPrimaryKey(long cartId)
1679                    throws NoSuchCartException, SystemException {
1680                    return findByPrimaryKey((Serializable)cartId);
1681            }
1682    
1683            /**
1684             * Returns the shopping cart with the primary key or returns <code>null</code> if it could not be found.
1685             *
1686             * @param primaryKey the primary key of the shopping cart
1687             * @return the shopping cart, or <code>null</code> if a shopping cart with the primary key could not be found
1688             * @throws SystemException if a system exception occurred
1689             */
1690            @Override
1691            public ShoppingCart fetchByPrimaryKey(Serializable primaryKey)
1692                    throws SystemException {
1693                    ShoppingCart shoppingCart = (ShoppingCart)EntityCacheUtil.getResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1694                                    ShoppingCartImpl.class, primaryKey);
1695    
1696                    if (shoppingCart == _nullShoppingCart) {
1697                            return null;
1698                    }
1699    
1700                    if (shoppingCart == null) {
1701                            Session session = null;
1702    
1703                            try {
1704                                    session = openSession();
1705    
1706                                    shoppingCart = (ShoppingCart)session.get(ShoppingCartImpl.class,
1707                                                    primaryKey);
1708    
1709                                    if (shoppingCart != null) {
1710                                            cacheResult(shoppingCart);
1711                                    }
1712                                    else {
1713                                            EntityCacheUtil.putResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1714                                                    ShoppingCartImpl.class, primaryKey, _nullShoppingCart);
1715                                    }
1716                            }
1717                            catch (Exception e) {
1718                                    EntityCacheUtil.removeResult(ShoppingCartModelImpl.ENTITY_CACHE_ENABLED,
1719                                            ShoppingCartImpl.class, primaryKey);
1720    
1721                                    throw processException(e);
1722                            }
1723                            finally {
1724                                    closeSession(session);
1725                            }
1726                    }
1727    
1728                    return shoppingCart;
1729            }
1730    
1731            /**
1732             * Returns the shopping cart with the primary key or returns <code>null</code> if it could not be found.
1733             *
1734             * @param cartId the primary key of the shopping cart
1735             * @return the shopping cart, or <code>null</code> if a shopping cart with the primary key could not be found
1736             * @throws SystemException if a system exception occurred
1737             */
1738            @Override
1739            public ShoppingCart fetchByPrimaryKey(long cartId)
1740                    throws SystemException {
1741                    return fetchByPrimaryKey((Serializable)cartId);
1742            }
1743    
1744            /**
1745             * Returns all the shopping carts.
1746             *
1747             * @return the shopping carts
1748             * @throws SystemException if a system exception occurred
1749             */
1750            @Override
1751            public List<ShoppingCart> findAll() throws SystemException {
1752                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1753            }
1754    
1755            /**
1756             * Returns a range of all the shopping carts.
1757             *
1758             * <p>
1759             * 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.
1760             * </p>
1761             *
1762             * @param start the lower bound of the range of shopping carts
1763             * @param end the upper bound of the range of shopping carts (not inclusive)
1764             * @return the range of shopping carts
1765             * @throws SystemException if a system exception occurred
1766             */
1767            @Override
1768            public List<ShoppingCart> findAll(int start, int end)
1769                    throws SystemException {
1770                    return findAll(start, end, null);
1771            }
1772    
1773            /**
1774             * Returns an ordered range of all the shopping carts.
1775             *
1776             * <p>
1777             * 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.
1778             * </p>
1779             *
1780             * @param start the lower bound of the range of shopping carts
1781             * @param end the upper bound of the range of shopping carts (not inclusive)
1782             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1783             * @return the ordered range of shopping carts
1784             * @throws SystemException if a system exception occurred
1785             */
1786            @Override
1787            public List<ShoppingCart> findAll(int start, int end,
1788                    OrderByComparator orderByComparator) throws SystemException {
1789                    boolean pagination = true;
1790                    FinderPath finderPath = null;
1791                    Object[] finderArgs = null;
1792    
1793                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1794                                    (orderByComparator == null)) {
1795                            pagination = false;
1796                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1797                            finderArgs = FINDER_ARGS_EMPTY;
1798                    }
1799                    else {
1800                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1801                            finderArgs = new Object[] { start, end, orderByComparator };
1802                    }
1803    
1804                    List<ShoppingCart> list = (List<ShoppingCart>)FinderCacheUtil.getResult(finderPath,
1805                                    finderArgs, this);
1806    
1807                    if (list == null) {
1808                            StringBundler query = null;
1809                            String sql = null;
1810    
1811                            if (orderByComparator != null) {
1812                                    query = new StringBundler(2 +
1813                                                    (orderByComparator.getOrderByFields().length * 3));
1814    
1815                                    query.append(_SQL_SELECT_SHOPPINGCART);
1816    
1817                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1818                                            orderByComparator);
1819    
1820                                    sql = query.toString();
1821                            }
1822                            else {
1823                                    sql = _SQL_SELECT_SHOPPINGCART;
1824    
1825                                    if (pagination) {
1826                                            sql = sql.concat(ShoppingCartModelImpl.ORDER_BY_JPQL);
1827                                    }
1828                            }
1829    
1830                            Session session = null;
1831    
1832                            try {
1833                                    session = openSession();
1834    
1835                                    Query q = session.createQuery(sql);
1836    
1837                                    if (!pagination) {
1838                                            list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
1839                                                            start, end, false);
1840    
1841                                            Collections.sort(list);
1842    
1843                                            list = new UnmodifiableList<ShoppingCart>(list);
1844                                    }
1845                                    else {
1846                                            list = (List<ShoppingCart>)QueryUtil.list(q, getDialect(),
1847                                                            start, end);
1848                                    }
1849    
1850                                    cacheResult(list);
1851    
1852                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1853                            }
1854                            catch (Exception e) {
1855                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1856    
1857                                    throw processException(e);
1858                            }
1859                            finally {
1860                                    closeSession(session);
1861                            }
1862                    }
1863    
1864                    return list;
1865            }
1866    
1867            /**
1868             * Removes all the shopping carts from the database.
1869             *
1870             * @throws SystemException if a system exception occurred
1871             */
1872            @Override
1873            public void removeAll() throws SystemException {
1874                    for (ShoppingCart shoppingCart : findAll()) {
1875                            remove(shoppingCart);
1876                    }
1877            }
1878    
1879            /**
1880             * Returns the number of shopping carts.
1881             *
1882             * @return the number of shopping carts
1883             * @throws SystemException if a system exception occurred
1884             */
1885            @Override
1886            public int countAll() throws SystemException {
1887                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1888                                    FINDER_ARGS_EMPTY, this);
1889    
1890                    if (count == null) {
1891                            Session session = null;
1892    
1893                            try {
1894                                    session = openSession();
1895    
1896                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGCART);
1897    
1898                                    count = (Long)q.uniqueResult();
1899    
1900                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1901                                            FINDER_ARGS_EMPTY, count);
1902                            }
1903                            catch (Exception e) {
1904                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1905                                            FINDER_ARGS_EMPTY);
1906    
1907                                    throw processException(e);
1908                            }
1909                            finally {
1910                                    closeSession(session);
1911                            }
1912                    }
1913    
1914                    return count.intValue();
1915            }
1916    
1917            /**
1918             * Initializes the shopping cart persistence.
1919             */
1920            public void afterPropertiesSet() {
1921                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1922                                            com.liferay.portal.util.PropsUtil.get(
1923                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingCart")));
1924    
1925                    if (listenerClassNames.length > 0) {
1926                            try {
1927                                    List<ModelListener<ShoppingCart>> listenersList = new ArrayList<ModelListener<ShoppingCart>>();
1928    
1929                                    for (String listenerClassName : listenerClassNames) {
1930                                            listenersList.add((ModelListener<ShoppingCart>)InstanceFactory.newInstance(
1931                                                            getClassLoader(), listenerClassName));
1932                                    }
1933    
1934                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1935                            }
1936                            catch (Exception e) {
1937                                    _log.error(e);
1938                            }
1939                    }
1940            }
1941    
1942            public void destroy() {
1943                    EntityCacheUtil.removeCache(ShoppingCartImpl.class.getName());
1944                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1945                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1946                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1947            }
1948    
1949            private static final String _SQL_SELECT_SHOPPINGCART = "SELECT shoppingCart FROM ShoppingCart shoppingCart";
1950            private static final String _SQL_SELECT_SHOPPINGCART_WHERE = "SELECT shoppingCart FROM ShoppingCart shoppingCart WHERE ";
1951            private static final String _SQL_COUNT_SHOPPINGCART = "SELECT COUNT(shoppingCart) FROM ShoppingCart shoppingCart";
1952            private static final String _SQL_COUNT_SHOPPINGCART_WHERE = "SELECT COUNT(shoppingCart) FROM ShoppingCart shoppingCart WHERE ";
1953            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingCart.";
1954            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingCart exists with the primary key ";
1955            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingCart exists with the key {";
1956            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1957            private static Log _log = LogFactoryUtil.getLog(ShoppingCartPersistenceImpl.class);
1958            private static ShoppingCart _nullShoppingCart = new ShoppingCartImpl() {
1959                            @Override
1960                            public Object clone() {
1961                                    return this;
1962                            }
1963    
1964                            @Override
1965                            public CacheModel<ShoppingCart> toCacheModel() {
1966                                    return _nullShoppingCartCacheModel;
1967                            }
1968                    };
1969    
1970            private static CacheModel<ShoppingCart> _nullShoppingCartCacheModel = new CacheModel<ShoppingCart>() {
1971                            @Override
1972                            public ShoppingCart toEntityModel() {
1973                                    return _nullShoppingCart;
1974                            }
1975                    };
1976    }