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