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