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