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