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