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