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            public ShoppingOrderPersistenceImpl() {
2502                    setModelClass(ShoppingOrder.class);
2503            }
2504    
2505            /**
2506             * Caches the shopping order in the entity cache if it is enabled.
2507             *
2508             * @param shoppingOrder the shopping order
2509             */
2510            @Override
2511            public void cacheResult(ShoppingOrder shoppingOrder) {
2512                    EntityCacheUtil.putResult(ShoppingOrderModelImpl.ENTITY_CACHE_ENABLED,
2513                            ShoppingOrderImpl.class, shoppingOrder.getPrimaryKey(),
2514                            shoppingOrder);
2515    
2516                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NUMBER,
2517                            new Object[] { shoppingOrder.getNumber() }, shoppingOrder);
2518    
2519                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PPTXNID,
2520                            new Object[] { shoppingOrder.getPpTxnId() }, shoppingOrder);
2521    
2522                    shoppingOrder.resetOriginalValues();
2523            }
2524    
2525            /**
2526             * Caches the shopping orders in the entity cache if it is enabled.
2527             *
2528             * @param shoppingOrders the shopping orders
2529             */
2530            @Override
2531            public void cacheResult(List<ShoppingOrder> shoppingOrders) {
2532                    for (ShoppingOrder shoppingOrder : shoppingOrders) {
2533                            if (EntityCacheUtil.getResult(
2534                                                    ShoppingOrderModelImpl.ENTITY_CACHE_ENABLED,
2535                                                    ShoppingOrderImpl.class, shoppingOrder.getPrimaryKey()) == null) {
2536                                    cacheResult(shoppingOrder);
2537                            }
2538                            else {
2539                                    shoppingOrder.resetOriginalValues();
2540                            }
2541                    }
2542            }
2543    
2544            /**
2545             * Clears the cache for all shopping orders.
2546             *
2547             * <p>
2548             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2549             * </p>
2550             */
2551            @Override
2552            public void clearCache() {
2553                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2554                            CacheRegistryUtil.clear(ShoppingOrderImpl.class.getName());
2555                    }
2556    
2557                    EntityCacheUtil.clearCache(ShoppingOrderImpl.class.getName());
2558    
2559                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2560                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2561                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2562            }
2563    
2564            /**
2565             * Clears the cache for the shopping order.
2566             *
2567             * <p>
2568             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2569             * </p>
2570             */
2571            @Override
2572            public void clearCache(ShoppingOrder shoppingOrder) {
2573                    EntityCacheUtil.removeResult(ShoppingOrderModelImpl.ENTITY_CACHE_ENABLED,
2574                            ShoppingOrderImpl.class, shoppingOrder.getPrimaryKey());
2575    
2576                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2577                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2578    
2579                    clearUniqueFindersCache(shoppingOrder);
2580            }
2581    
2582            @Override
2583            public void clearCache(List<ShoppingOrder> shoppingOrders) {
2584                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2585                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2586    
2587                    for (ShoppingOrder shoppingOrder : shoppingOrders) {
2588                            EntityCacheUtil.removeResult(ShoppingOrderModelImpl.ENTITY_CACHE_ENABLED,
2589                                    ShoppingOrderImpl.class, shoppingOrder.getPrimaryKey());
2590    
2591                            clearUniqueFindersCache(shoppingOrder);
2592                    }
2593            }
2594    
2595            protected void cacheUniqueFindersCache(ShoppingOrder shoppingOrder) {
2596                    if (shoppingOrder.isNew()) {
2597                            Object[] args = new Object[] { shoppingOrder.getNumber() };
2598    
2599                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NUMBER, args,
2600                                    Long.valueOf(1));
2601                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NUMBER, args,
2602                                    shoppingOrder);
2603    
2604                            args = new Object[] { shoppingOrder.getPpTxnId() };
2605    
2606                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PPTXNID, args,
2607                                    Long.valueOf(1));
2608                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PPTXNID, args,
2609                                    shoppingOrder);
2610                    }
2611                    else {
2612                            ShoppingOrderModelImpl shoppingOrderModelImpl = (ShoppingOrderModelImpl)shoppingOrder;
2613    
2614                            if ((shoppingOrderModelImpl.getColumnBitmask() &
2615                                            FINDER_PATH_FETCH_BY_NUMBER.getColumnBitmask()) != 0) {
2616                                    Object[] args = new Object[] { shoppingOrder.getNumber() };
2617    
2618                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NUMBER, args,
2619                                            Long.valueOf(1));
2620                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NUMBER, args,
2621                                            shoppingOrder);
2622                            }
2623    
2624                            if ((shoppingOrderModelImpl.getColumnBitmask() &
2625                                            FINDER_PATH_FETCH_BY_PPTXNID.getColumnBitmask()) != 0) {
2626                                    Object[] args = new Object[] { shoppingOrder.getPpTxnId() };
2627    
2628                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PPTXNID, args,
2629                                            Long.valueOf(1));
2630                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PPTXNID, args,
2631                                            shoppingOrder);
2632                            }
2633                    }
2634            }
2635    
2636            protected void clearUniqueFindersCache(ShoppingOrder shoppingOrder) {
2637                    ShoppingOrderModelImpl shoppingOrderModelImpl = (ShoppingOrderModelImpl)shoppingOrder;
2638    
2639                    Object[] args = new Object[] { shoppingOrder.getNumber() };
2640    
2641                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NUMBER, args);
2642                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NUMBER, args);
2643    
2644                    if ((shoppingOrderModelImpl.getColumnBitmask() &
2645                                    FINDER_PATH_FETCH_BY_NUMBER.getColumnBitmask()) != 0) {
2646                            args = new Object[] { shoppingOrderModelImpl.getOriginalNumber() };
2647    
2648                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NUMBER, args);
2649                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NUMBER, args);
2650                    }
2651    
2652                    args = new Object[] { shoppingOrder.getPpTxnId() };
2653    
2654                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PPTXNID, args);
2655                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_PPTXNID, args);
2656    
2657                    if ((shoppingOrderModelImpl.getColumnBitmask() &
2658                                    FINDER_PATH_FETCH_BY_PPTXNID.getColumnBitmask()) != 0) {
2659                            args = new Object[] { shoppingOrderModelImpl.getOriginalPpTxnId() };
2660    
2661                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PPTXNID, args);
2662                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_PPTXNID, args);
2663                    }
2664            }
2665    
2666            /**
2667             * Creates a new shopping order with the primary key. Does not add the shopping order to the database.
2668             *
2669             * @param orderId the primary key for the new shopping order
2670             * @return the new shopping order
2671             */
2672            @Override
2673            public ShoppingOrder create(long orderId) {
2674                    ShoppingOrder shoppingOrder = new ShoppingOrderImpl();
2675    
2676                    shoppingOrder.setNew(true);
2677                    shoppingOrder.setPrimaryKey(orderId);
2678    
2679                    return shoppingOrder;
2680            }
2681    
2682            /**
2683             * Removes the shopping order with the primary key from the database. Also notifies the appropriate model listeners.
2684             *
2685             * @param orderId the primary key of the shopping order
2686             * @return the shopping order that was removed
2687             * @throws com.liferay.portlet.shopping.NoSuchOrderException if a shopping order with the primary key could not be found
2688             * @throws SystemException if a system exception occurred
2689             */
2690            @Override
2691            public ShoppingOrder remove(long orderId)
2692                    throws NoSuchOrderException, SystemException {
2693                    return remove((Serializable)orderId);
2694            }
2695    
2696            /**
2697             * Removes the shopping order with the primary key from the database. Also notifies the appropriate model listeners.
2698             *
2699             * @param primaryKey the primary key of the shopping order
2700             * @return the shopping order that was removed
2701             * @throws com.liferay.portlet.shopping.NoSuchOrderException if a shopping order with the primary key could not be found
2702             * @throws SystemException if a system exception occurred
2703             */
2704            @Override
2705            public ShoppingOrder remove(Serializable primaryKey)
2706                    throws NoSuchOrderException, SystemException {
2707                    Session session = null;
2708    
2709                    try {
2710                            session = openSession();
2711    
2712                            ShoppingOrder shoppingOrder = (ShoppingOrder)session.get(ShoppingOrderImpl.class,
2713                                            primaryKey);
2714    
2715                            if (shoppingOrder == null) {
2716                                    if (_log.isWarnEnabled()) {
2717                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2718                                    }
2719    
2720                                    throw new NoSuchOrderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2721                                            primaryKey);
2722                            }
2723    
2724                            return remove(shoppingOrder);
2725                    }
2726                    catch (NoSuchOrderException nsee) {
2727                            throw nsee;
2728                    }
2729                    catch (Exception e) {
2730                            throw processException(e);
2731                    }
2732                    finally {
2733                            closeSession(session);
2734                    }
2735            }
2736    
2737            @Override
2738            protected ShoppingOrder removeImpl(ShoppingOrder shoppingOrder)
2739                    throws SystemException {
2740                    shoppingOrder = toUnwrappedModel(shoppingOrder);
2741    
2742                    Session session = null;
2743    
2744                    try {
2745                            session = openSession();
2746    
2747                            if (!session.contains(shoppingOrder)) {
2748                                    shoppingOrder = (ShoppingOrder)session.get(ShoppingOrderImpl.class,
2749                                                    shoppingOrder.getPrimaryKeyObj());
2750                            }
2751    
2752                            if (shoppingOrder != null) {
2753                                    session.delete(shoppingOrder);
2754                            }
2755                    }
2756                    catch (Exception e) {
2757                            throw processException(e);
2758                    }
2759                    finally {
2760                            closeSession(session);
2761                    }
2762    
2763                    if (shoppingOrder != null) {
2764                            clearCache(shoppingOrder);
2765                    }
2766    
2767                    return shoppingOrder;
2768            }
2769    
2770            @Override
2771            public ShoppingOrder updateImpl(
2772                    com.liferay.portlet.shopping.model.ShoppingOrder shoppingOrder)
2773                    throws SystemException {
2774                    shoppingOrder = toUnwrappedModel(shoppingOrder);
2775    
2776                    boolean isNew = shoppingOrder.isNew();
2777    
2778                    ShoppingOrderModelImpl shoppingOrderModelImpl = (ShoppingOrderModelImpl)shoppingOrder;
2779    
2780                    Session session = null;
2781    
2782                    try {
2783                            session = openSession();
2784    
2785                            if (shoppingOrder.isNew()) {
2786                                    session.save(shoppingOrder);
2787    
2788                                    shoppingOrder.setNew(false);
2789                            }
2790                            else {
2791                                    session.merge(shoppingOrder);
2792                            }
2793                    }
2794                    catch (Exception e) {
2795                            throw processException(e);
2796                    }
2797                    finally {
2798                            closeSession(session);
2799                    }
2800    
2801                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2802    
2803                    if (isNew || !ShoppingOrderModelImpl.COLUMN_BITMASK_ENABLED) {
2804                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2805                    }
2806    
2807                    else {
2808                            if ((shoppingOrderModelImpl.getColumnBitmask() &
2809                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2810                                    Object[] args = new Object[] {
2811                                                    shoppingOrderModelImpl.getOriginalGroupId()
2812                                            };
2813    
2814                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2815                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2816                                            args);
2817    
2818                                    args = new Object[] { shoppingOrderModelImpl.getGroupId() };
2819    
2820                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2821                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2822                                            args);
2823                            }
2824    
2825                            if ((shoppingOrderModelImpl.getColumnBitmask() &
2826                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_PPPS.getColumnBitmask()) != 0) {
2827                                    Object[] args = new Object[] {
2828                                                    shoppingOrderModelImpl.getOriginalGroupId(),
2829                                                    shoppingOrderModelImpl.getOriginalUserId(),
2830                                                    shoppingOrderModelImpl.getOriginalPpPaymentStatus()
2831                                            };
2832    
2833                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_PPPS, args);
2834                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_PPPS,
2835                                            args);
2836    
2837                                    args = new Object[] {
2838                                                    shoppingOrderModelImpl.getGroupId(),
2839                                                    shoppingOrderModelImpl.getUserId(),
2840                                                    shoppingOrderModelImpl.getPpPaymentStatus()
2841                                            };
2842    
2843                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_PPPS, args);
2844                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_PPPS,
2845                                            args);
2846                            }
2847                    }
2848    
2849                    EntityCacheUtil.putResult(ShoppingOrderModelImpl.ENTITY_CACHE_ENABLED,
2850                            ShoppingOrderImpl.class, shoppingOrder.getPrimaryKey(),
2851                            shoppingOrder);
2852    
2853                    clearUniqueFindersCache(shoppingOrder);
2854                    cacheUniqueFindersCache(shoppingOrder);
2855    
2856                    return shoppingOrder;
2857            }
2858    
2859            protected ShoppingOrder toUnwrappedModel(ShoppingOrder shoppingOrder) {
2860                    if (shoppingOrder instanceof ShoppingOrderImpl) {
2861                            return shoppingOrder;
2862                    }
2863    
2864                    ShoppingOrderImpl shoppingOrderImpl = new ShoppingOrderImpl();
2865    
2866                    shoppingOrderImpl.setNew(shoppingOrder.isNew());
2867                    shoppingOrderImpl.setPrimaryKey(shoppingOrder.getPrimaryKey());
2868    
2869                    shoppingOrderImpl.setOrderId(shoppingOrder.getOrderId());
2870                    shoppingOrderImpl.setGroupId(shoppingOrder.getGroupId());
2871                    shoppingOrderImpl.setCompanyId(shoppingOrder.getCompanyId());
2872                    shoppingOrderImpl.setUserId(shoppingOrder.getUserId());
2873                    shoppingOrderImpl.setUserName(shoppingOrder.getUserName());
2874                    shoppingOrderImpl.setCreateDate(shoppingOrder.getCreateDate());
2875                    shoppingOrderImpl.setModifiedDate(shoppingOrder.getModifiedDate());
2876                    shoppingOrderImpl.setNumber(shoppingOrder.getNumber());
2877                    shoppingOrderImpl.setTax(shoppingOrder.getTax());
2878                    shoppingOrderImpl.setShipping(shoppingOrder.getShipping());
2879                    shoppingOrderImpl.setAltShipping(shoppingOrder.getAltShipping());
2880                    shoppingOrderImpl.setRequiresShipping(shoppingOrder.isRequiresShipping());
2881                    shoppingOrderImpl.setInsure(shoppingOrder.isInsure());
2882                    shoppingOrderImpl.setInsurance(shoppingOrder.getInsurance());
2883                    shoppingOrderImpl.setCouponCodes(shoppingOrder.getCouponCodes());
2884                    shoppingOrderImpl.setCouponDiscount(shoppingOrder.getCouponDiscount());
2885                    shoppingOrderImpl.setBillingFirstName(shoppingOrder.getBillingFirstName());
2886                    shoppingOrderImpl.setBillingLastName(shoppingOrder.getBillingLastName());
2887                    shoppingOrderImpl.setBillingEmailAddress(shoppingOrder.getBillingEmailAddress());
2888                    shoppingOrderImpl.setBillingCompany(shoppingOrder.getBillingCompany());
2889                    shoppingOrderImpl.setBillingStreet(shoppingOrder.getBillingStreet());
2890                    shoppingOrderImpl.setBillingCity(shoppingOrder.getBillingCity());
2891                    shoppingOrderImpl.setBillingState(shoppingOrder.getBillingState());
2892                    shoppingOrderImpl.setBillingZip(shoppingOrder.getBillingZip());
2893                    shoppingOrderImpl.setBillingCountry(shoppingOrder.getBillingCountry());
2894                    shoppingOrderImpl.setBillingPhone(shoppingOrder.getBillingPhone());
2895                    shoppingOrderImpl.setShipToBilling(shoppingOrder.isShipToBilling());
2896                    shoppingOrderImpl.setShippingFirstName(shoppingOrder.getShippingFirstName());
2897                    shoppingOrderImpl.setShippingLastName(shoppingOrder.getShippingLastName());
2898                    shoppingOrderImpl.setShippingEmailAddress(shoppingOrder.getShippingEmailAddress());
2899                    shoppingOrderImpl.setShippingCompany(shoppingOrder.getShippingCompany());
2900                    shoppingOrderImpl.setShippingStreet(shoppingOrder.getShippingStreet());
2901                    shoppingOrderImpl.setShippingCity(shoppingOrder.getShippingCity());
2902                    shoppingOrderImpl.setShippingState(shoppingOrder.getShippingState());
2903                    shoppingOrderImpl.setShippingZip(shoppingOrder.getShippingZip());
2904                    shoppingOrderImpl.setShippingCountry(shoppingOrder.getShippingCountry());
2905                    shoppingOrderImpl.setShippingPhone(shoppingOrder.getShippingPhone());
2906                    shoppingOrderImpl.setCcName(shoppingOrder.getCcName());
2907                    shoppingOrderImpl.setCcType(shoppingOrder.getCcType());
2908                    shoppingOrderImpl.setCcNumber(shoppingOrder.getCcNumber());
2909                    shoppingOrderImpl.setCcExpMonth(shoppingOrder.getCcExpMonth());
2910                    shoppingOrderImpl.setCcExpYear(shoppingOrder.getCcExpYear());
2911                    shoppingOrderImpl.setCcVerNumber(shoppingOrder.getCcVerNumber());
2912                    shoppingOrderImpl.setComments(shoppingOrder.getComments());
2913                    shoppingOrderImpl.setPpTxnId(shoppingOrder.getPpTxnId());
2914                    shoppingOrderImpl.setPpPaymentStatus(shoppingOrder.getPpPaymentStatus());
2915                    shoppingOrderImpl.setPpPaymentGross(shoppingOrder.getPpPaymentGross());
2916                    shoppingOrderImpl.setPpReceiverEmail(shoppingOrder.getPpReceiverEmail());
2917                    shoppingOrderImpl.setPpPayerEmail(shoppingOrder.getPpPayerEmail());
2918                    shoppingOrderImpl.setSendOrderEmail(shoppingOrder.isSendOrderEmail());
2919                    shoppingOrderImpl.setSendShippingEmail(shoppingOrder.isSendShippingEmail());
2920    
2921                    return shoppingOrderImpl;
2922            }
2923    
2924            /**
2925             * Returns the shopping order with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2926             *
2927             * @param primaryKey the primary key of the shopping order
2928             * @return the shopping order
2929             * @throws com.liferay.portlet.shopping.NoSuchOrderException if a shopping order with the primary key could not be found
2930             * @throws SystemException if a system exception occurred
2931             */
2932            @Override
2933            public ShoppingOrder findByPrimaryKey(Serializable primaryKey)
2934                    throws NoSuchOrderException, SystemException {
2935                    ShoppingOrder shoppingOrder = fetchByPrimaryKey(primaryKey);
2936    
2937                    if (shoppingOrder == null) {
2938                            if (_log.isWarnEnabled()) {
2939                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2940                            }
2941    
2942                            throw new NoSuchOrderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2943                                    primaryKey);
2944                    }
2945    
2946                    return shoppingOrder;
2947            }
2948    
2949            /**
2950             * Returns the shopping order with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchOrderException} if it could not be found.
2951             *
2952             * @param orderId the primary key of the shopping order
2953             * @return the shopping order
2954             * @throws com.liferay.portlet.shopping.NoSuchOrderException if a shopping order with the primary key could not be found
2955             * @throws SystemException if a system exception occurred
2956             */
2957            @Override
2958            public ShoppingOrder findByPrimaryKey(long orderId)
2959                    throws NoSuchOrderException, SystemException {
2960                    return findByPrimaryKey((Serializable)orderId);
2961            }
2962    
2963            /**
2964             * Returns the shopping order with the primary key or returns <code>null</code> if it could not be found.
2965             *
2966             * @param primaryKey the primary key of the shopping order
2967             * @return the shopping order, or <code>null</code> if a shopping order with the primary key could not be found
2968             * @throws SystemException if a system exception occurred
2969             */
2970            @Override
2971            public ShoppingOrder fetchByPrimaryKey(Serializable primaryKey)
2972                    throws SystemException {
2973                    ShoppingOrder shoppingOrder = (ShoppingOrder)EntityCacheUtil.getResult(ShoppingOrderModelImpl.ENTITY_CACHE_ENABLED,
2974                                    ShoppingOrderImpl.class, primaryKey);
2975    
2976                    if (shoppingOrder == _nullShoppingOrder) {
2977                            return null;
2978                    }
2979    
2980                    if (shoppingOrder == null) {
2981                            Session session = null;
2982    
2983                            try {
2984                                    session = openSession();
2985    
2986                                    shoppingOrder = (ShoppingOrder)session.get(ShoppingOrderImpl.class,
2987                                                    primaryKey);
2988    
2989                                    if (shoppingOrder != null) {
2990                                            cacheResult(shoppingOrder);
2991                                    }
2992                                    else {
2993                                            EntityCacheUtil.putResult(ShoppingOrderModelImpl.ENTITY_CACHE_ENABLED,
2994                                                    ShoppingOrderImpl.class, primaryKey, _nullShoppingOrder);
2995                                    }
2996                            }
2997                            catch (Exception e) {
2998                                    EntityCacheUtil.removeResult(ShoppingOrderModelImpl.ENTITY_CACHE_ENABLED,
2999                                            ShoppingOrderImpl.class, primaryKey);
3000    
3001                                    throw processException(e);
3002                            }
3003                            finally {
3004                                    closeSession(session);
3005                            }
3006                    }
3007    
3008                    return shoppingOrder;
3009            }
3010    
3011            /**
3012             * Returns the shopping order with the primary key or returns <code>null</code> if it could not be found.
3013             *
3014             * @param orderId the primary key of the shopping order
3015             * @return the shopping order, or <code>null</code> if a shopping order with the primary key could not be found
3016             * @throws SystemException if a system exception occurred
3017             */
3018            @Override
3019            public ShoppingOrder fetchByPrimaryKey(long orderId)
3020                    throws SystemException {
3021                    return fetchByPrimaryKey((Serializable)orderId);
3022            }
3023    
3024            /**
3025             * Returns all the shopping orders.
3026             *
3027             * @return the shopping orders
3028             * @throws SystemException if a system exception occurred
3029             */
3030            @Override
3031            public List<ShoppingOrder> findAll() throws SystemException {
3032                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3033            }
3034    
3035            /**
3036             * Returns a range of all the shopping orders.
3037             *
3038             * <p>
3039             * 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.
3040             * </p>
3041             *
3042             * @param start the lower bound of the range of shopping orders
3043             * @param end the upper bound of the range of shopping orders (not inclusive)
3044             * @return the range of shopping orders
3045             * @throws SystemException if a system exception occurred
3046             */
3047            @Override
3048            public List<ShoppingOrder> findAll(int start, int end)
3049                    throws SystemException {
3050                    return findAll(start, end, null);
3051            }
3052    
3053            /**
3054             * Returns an ordered range of all the shopping orders.
3055             *
3056             * <p>
3057             * 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.
3058             * </p>
3059             *
3060             * @param start the lower bound of the range of shopping orders
3061             * @param end the upper bound of the range of shopping orders (not inclusive)
3062             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3063             * @return the ordered range of shopping orders
3064             * @throws SystemException if a system exception occurred
3065             */
3066            @Override
3067            public List<ShoppingOrder> findAll(int start, int end,
3068                    OrderByComparator orderByComparator) throws SystemException {
3069                    boolean pagination = true;
3070                    FinderPath finderPath = null;
3071                    Object[] finderArgs = null;
3072    
3073                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3074                                    (orderByComparator == null)) {
3075                            pagination = false;
3076                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3077                            finderArgs = FINDER_ARGS_EMPTY;
3078                    }
3079                    else {
3080                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3081                            finderArgs = new Object[] { start, end, orderByComparator };
3082                    }
3083    
3084                    List<ShoppingOrder> list = (List<ShoppingOrder>)FinderCacheUtil.getResult(finderPath,
3085                                    finderArgs, this);
3086    
3087                    if (list == null) {
3088                            StringBundler query = null;
3089                            String sql = null;
3090    
3091                            if (orderByComparator != null) {
3092                                    query = new StringBundler(2 +
3093                                                    (orderByComparator.getOrderByFields().length * 3));
3094    
3095                                    query.append(_SQL_SELECT_SHOPPINGORDER);
3096    
3097                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3098                                            orderByComparator);
3099    
3100                                    sql = query.toString();
3101                            }
3102                            else {
3103                                    sql = _SQL_SELECT_SHOPPINGORDER;
3104    
3105                                    if (pagination) {
3106                                            sql = sql.concat(ShoppingOrderModelImpl.ORDER_BY_JPQL);
3107                                    }
3108                            }
3109    
3110                            Session session = null;
3111    
3112                            try {
3113                                    session = openSession();
3114    
3115                                    Query q = session.createQuery(sql);
3116    
3117                                    if (!pagination) {
3118                                            list = (List<ShoppingOrder>)QueryUtil.list(q, getDialect(),
3119                                                            start, end, false);
3120    
3121                                            Collections.sort(list);
3122    
3123                                            list = new UnmodifiableList<ShoppingOrder>(list);
3124                                    }
3125                                    else {
3126                                            list = (List<ShoppingOrder>)QueryUtil.list(q, getDialect(),
3127                                                            start, end);
3128                                    }
3129    
3130                                    cacheResult(list);
3131    
3132                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3133                            }
3134                            catch (Exception e) {
3135                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3136    
3137                                    throw processException(e);
3138                            }
3139                            finally {
3140                                    closeSession(session);
3141                            }
3142                    }
3143    
3144                    return list;
3145            }
3146    
3147            /**
3148             * Removes all the shopping orders from the database.
3149             *
3150             * @throws SystemException if a system exception occurred
3151             */
3152            @Override
3153            public void removeAll() throws SystemException {
3154                    for (ShoppingOrder shoppingOrder : findAll()) {
3155                            remove(shoppingOrder);
3156                    }
3157            }
3158    
3159            /**
3160             * Returns the number of shopping orders.
3161             *
3162             * @return the number of shopping orders
3163             * @throws SystemException if a system exception occurred
3164             */
3165            @Override
3166            public int countAll() throws SystemException {
3167                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3168                                    FINDER_ARGS_EMPTY, this);
3169    
3170                    if (count == null) {
3171                            Session session = null;
3172    
3173                            try {
3174                                    session = openSession();
3175    
3176                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGORDER);
3177    
3178                                    count = (Long)q.uniqueResult();
3179    
3180                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3181                                            FINDER_ARGS_EMPTY, count);
3182                            }
3183                            catch (Exception e) {
3184                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3185                                            FINDER_ARGS_EMPTY);
3186    
3187                                    throw processException(e);
3188                            }
3189                            finally {
3190                                    closeSession(session);
3191                            }
3192                    }
3193    
3194                    return count.intValue();
3195            }
3196    
3197            @Override
3198            protected Set<String> getBadColumnNames() {
3199                    return _badColumnNames;
3200            }
3201    
3202            /**
3203             * Initializes the shopping order persistence.
3204             */
3205            public void afterPropertiesSet() {
3206                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3207                                            com.liferay.portal.util.PropsUtil.get(
3208                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingOrder")));
3209    
3210                    if (listenerClassNames.length > 0) {
3211                            try {
3212                                    List<ModelListener<ShoppingOrder>> listenersList = new ArrayList<ModelListener<ShoppingOrder>>();
3213    
3214                                    for (String listenerClassName : listenerClassNames) {
3215                                            listenersList.add((ModelListener<ShoppingOrder>)InstanceFactory.newInstance(
3216                                                            getClassLoader(), listenerClassName));
3217                                    }
3218    
3219                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3220                            }
3221                            catch (Exception e) {
3222                                    _log.error(e);
3223                            }
3224                    }
3225            }
3226    
3227            public void destroy() {
3228                    EntityCacheUtil.removeCache(ShoppingOrderImpl.class.getName());
3229                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3230                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3231                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3232            }
3233    
3234            private static final String _SQL_SELECT_SHOPPINGORDER = "SELECT shoppingOrder FROM ShoppingOrder shoppingOrder";
3235            private static final String _SQL_SELECT_SHOPPINGORDER_WHERE = "SELECT shoppingOrder FROM ShoppingOrder shoppingOrder WHERE ";
3236            private static final String _SQL_COUNT_SHOPPINGORDER = "SELECT COUNT(shoppingOrder) FROM ShoppingOrder shoppingOrder";
3237            private static final String _SQL_COUNT_SHOPPINGORDER_WHERE = "SELECT COUNT(shoppingOrder) FROM ShoppingOrder shoppingOrder WHERE ";
3238            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "shoppingOrder.orderId";
3239            private static final String _FILTER_SQL_SELECT_SHOPPINGORDER_WHERE = "SELECT DISTINCT {shoppingOrder.*} FROM ShoppingOrder shoppingOrder WHERE ";
3240            private static final String _FILTER_SQL_SELECT_SHOPPINGORDER_NO_INLINE_DISTINCT_WHERE_1 =
3241                    "SELECT {ShoppingOrder.*} FROM (SELECT DISTINCT shoppingOrder.orderId FROM ShoppingOrder shoppingOrder WHERE ";
3242            private static final String _FILTER_SQL_SELECT_SHOPPINGORDER_NO_INLINE_DISTINCT_WHERE_2 =
3243                    ") TEMP_TABLE INNER JOIN ShoppingOrder ON TEMP_TABLE.orderId = ShoppingOrder.orderId";
3244            private static final String _FILTER_SQL_COUNT_SHOPPINGORDER_WHERE = "SELECT COUNT(DISTINCT shoppingOrder.orderId) AS COUNT_VALUE FROM ShoppingOrder shoppingOrder WHERE ";
3245            private static final String _FILTER_ENTITY_ALIAS = "shoppingOrder";
3246            private static final String _FILTER_ENTITY_TABLE = "ShoppingOrder";
3247            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingOrder.";
3248            private static final String _ORDER_BY_ENTITY_TABLE = "ShoppingOrder.";
3249            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingOrder exists with the primary key ";
3250            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingOrder exists with the key {";
3251            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3252            private static Log _log = LogFactoryUtil.getLog(ShoppingOrderPersistenceImpl.class);
3253            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3254                                    "number"
3255                            });
3256            private static ShoppingOrder _nullShoppingOrder = new ShoppingOrderImpl() {
3257                            @Override
3258                            public Object clone() {
3259                                    return this;
3260                            }
3261    
3262                            @Override
3263                            public CacheModel<ShoppingOrder> toCacheModel() {
3264                                    return _nullShoppingOrderCacheModel;
3265                            }
3266                    };
3267    
3268            private static CacheModel<ShoppingOrder> _nullShoppingOrderCacheModel = new CacheModel<ShoppingOrder>() {
3269                            @Override
3270                            public ShoppingOrder toEntityModel() {
3271                                    return _nullShoppingOrder;
3272                            }
3273                    };
3274    }