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