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