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