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