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