001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.shopping.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.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.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.ResourcePersistence;
039    import com.liferay.portal.service.persistence.UserPersistence;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.shopping.NoSuchOrderItemException;
043    import com.liferay.portlet.shopping.model.ShoppingOrderItem;
044    import com.liferay.portlet.shopping.model.impl.ShoppingOrderItemImpl;
045    import com.liferay.portlet.shopping.model.impl.ShoppingOrderItemModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    
053    /**
054     * The persistence implementation for the shopping order item service.
055     *
056     * <p>
057     * Never modify or reference this class directly. Always use {@link ShoppingOrderItemUtil} to access the shopping order item persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
058     * </p>
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see ShoppingOrderItemPersistence
066     * @see ShoppingOrderItemUtil
067     * @generated
068     */
069    public class ShoppingOrderItemPersistenceImpl extends BasePersistenceImpl<ShoppingOrderItem>
070            implements ShoppingOrderItemPersistence {
071            public static final String FINDER_CLASS_NAME_ENTITY = ShoppingOrderItemImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073                    ".List";
074            public static final FinderPath FINDER_PATH_FIND_BY_ORDERID = new FinderPath(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
075                            ShoppingOrderItemModelImpl.FINDER_CACHE_ENABLED,
076                            FINDER_CLASS_NAME_LIST, "findByOrderId",
077                            new String[] {
078                                    Long.class.getName(),
079                                    
080                            "java.lang.Integer", "java.lang.Integer",
081                                    "com.liferay.portal.kernel.util.OrderByComparator"
082                            });
083            public static final FinderPath FINDER_PATH_COUNT_BY_ORDERID = new FinderPath(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
084                            ShoppingOrderItemModelImpl.FINDER_CACHE_ENABLED,
085                            FINDER_CLASS_NAME_LIST, "countByOrderId",
086                            new String[] { Long.class.getName() });
087            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
088                            ShoppingOrderItemModelImpl.FINDER_CACHE_ENABLED,
089                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
091                            ShoppingOrderItemModelImpl.FINDER_CACHE_ENABLED,
092                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
093    
094            /**
095             * Caches the shopping order item in the entity cache if it is enabled.
096             *
097             * @param shoppingOrderItem the shopping order item to cache
098             */
099            public void cacheResult(ShoppingOrderItem shoppingOrderItem) {
100                    EntityCacheUtil.putResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
101                            ShoppingOrderItemImpl.class, shoppingOrderItem.getPrimaryKey(),
102                            shoppingOrderItem);
103            }
104    
105            /**
106             * Caches the shopping order items in the entity cache if it is enabled.
107             *
108             * @param shoppingOrderItems the shopping order items to cache
109             */
110            public void cacheResult(List<ShoppingOrderItem> shoppingOrderItems) {
111                    for (ShoppingOrderItem shoppingOrderItem : shoppingOrderItems) {
112                            if (EntityCacheUtil.getResult(
113                                                    ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
114                                                    ShoppingOrderItemImpl.class,
115                                                    shoppingOrderItem.getPrimaryKey(), this) == null) {
116                                    cacheResult(shoppingOrderItem);
117                            }
118                    }
119            }
120    
121            /**
122             * Clears the cache for all shopping order items.
123             *
124             * <p>
125             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
126             * </p>
127             */
128            public void clearCache() {
129                    CacheRegistryUtil.clear(ShoppingOrderItemImpl.class.getName());
130                    EntityCacheUtil.clearCache(ShoppingOrderItemImpl.class.getName());
131                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
132                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
133            }
134    
135            /**
136             * Clears the cache for the shopping order item.
137             *
138             * <p>
139             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
140             * </p>
141             */
142            public void clearCache(ShoppingOrderItem shoppingOrderItem) {
143                    EntityCacheUtil.removeResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
144                            ShoppingOrderItemImpl.class, shoppingOrderItem.getPrimaryKey());
145            }
146    
147            /**
148             * Creates a new shopping order item with the primary key. Does not add the shopping order item to the database.
149             *
150             * @param orderItemId the primary key for the new shopping order item
151             * @return the new shopping order item
152             */
153            public ShoppingOrderItem create(long orderItemId) {
154                    ShoppingOrderItem shoppingOrderItem = new ShoppingOrderItemImpl();
155    
156                    shoppingOrderItem.setNew(true);
157                    shoppingOrderItem.setPrimaryKey(orderItemId);
158    
159                    return shoppingOrderItem;
160            }
161    
162            /**
163             * Removes the shopping order item with the primary key from the database. Also notifies the appropriate model listeners.
164             *
165             * @param primaryKey the primary key of the shopping order item to remove
166             * @return the shopping order item that was removed
167             * @throws com.liferay.portal.NoSuchModelException if a shopping order item with the primary key could not be found
168             * @throws SystemException if a system exception occurred
169             */
170            public ShoppingOrderItem remove(Serializable primaryKey)
171                    throws NoSuchModelException, SystemException {
172                    return remove(((Long)primaryKey).longValue());
173            }
174    
175            /**
176             * Removes the shopping order item with the primary key from the database. Also notifies the appropriate model listeners.
177             *
178             * @param orderItemId the primary key of the shopping order item to remove
179             * @return the shopping order item that was removed
180             * @throws com.liferay.portlet.shopping.NoSuchOrderItemException if a shopping order item with the primary key could not be found
181             * @throws SystemException if a system exception occurred
182             */
183            public ShoppingOrderItem remove(long orderItemId)
184                    throws NoSuchOrderItemException, SystemException {
185                    Session session = null;
186    
187                    try {
188                            session = openSession();
189    
190                            ShoppingOrderItem shoppingOrderItem = (ShoppingOrderItem)session.get(ShoppingOrderItemImpl.class,
191                                            new Long(orderItemId));
192    
193                            if (shoppingOrderItem == null) {
194                                    if (_log.isWarnEnabled()) {
195                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orderItemId);
196                                    }
197    
198                                    throw new NoSuchOrderItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
199                                            orderItemId);
200                            }
201    
202                            return remove(shoppingOrderItem);
203                    }
204                    catch (NoSuchOrderItemException nsee) {
205                            throw nsee;
206                    }
207                    catch (Exception e) {
208                            throw processException(e);
209                    }
210                    finally {
211                            closeSession(session);
212                    }
213            }
214    
215            protected ShoppingOrderItem removeImpl(ShoppingOrderItem shoppingOrderItem)
216                    throws SystemException {
217                    shoppingOrderItem = toUnwrappedModel(shoppingOrderItem);
218    
219                    Session session = null;
220    
221                    try {
222                            session = openSession();
223    
224                            if (shoppingOrderItem.isCachedModel() ||
225                                            BatchSessionUtil.isEnabled()) {
226                                    Object staleObject = session.get(ShoppingOrderItemImpl.class,
227                                                    shoppingOrderItem.getPrimaryKeyObj());
228    
229                                    if (staleObject != null) {
230                                            session.evict(staleObject);
231                                    }
232                            }
233    
234                            session.delete(shoppingOrderItem);
235    
236                            session.flush();
237                    }
238                    catch (Exception e) {
239                            throw processException(e);
240                    }
241                    finally {
242                            closeSession(session);
243                    }
244    
245                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
246    
247                    EntityCacheUtil.removeResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
248                            ShoppingOrderItemImpl.class, shoppingOrderItem.getPrimaryKey());
249    
250                    return shoppingOrderItem;
251            }
252    
253            public ShoppingOrderItem updateImpl(
254                    com.liferay.portlet.shopping.model.ShoppingOrderItem shoppingOrderItem,
255                    boolean merge) throws SystemException {
256                    shoppingOrderItem = toUnwrappedModel(shoppingOrderItem);
257    
258                    Session session = null;
259    
260                    try {
261                            session = openSession();
262    
263                            BatchSessionUtil.update(session, shoppingOrderItem, merge);
264    
265                            shoppingOrderItem.setNew(false);
266                    }
267                    catch (Exception e) {
268                            throw processException(e);
269                    }
270                    finally {
271                            closeSession(session);
272                    }
273    
274                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
275    
276                    EntityCacheUtil.putResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
277                            ShoppingOrderItemImpl.class, shoppingOrderItem.getPrimaryKey(),
278                            shoppingOrderItem);
279    
280                    return shoppingOrderItem;
281            }
282    
283            protected ShoppingOrderItem toUnwrappedModel(
284                    ShoppingOrderItem shoppingOrderItem) {
285                    if (shoppingOrderItem instanceof ShoppingOrderItemImpl) {
286                            return shoppingOrderItem;
287                    }
288    
289                    ShoppingOrderItemImpl shoppingOrderItemImpl = new ShoppingOrderItemImpl();
290    
291                    shoppingOrderItemImpl.setNew(shoppingOrderItem.isNew());
292                    shoppingOrderItemImpl.setPrimaryKey(shoppingOrderItem.getPrimaryKey());
293    
294                    shoppingOrderItemImpl.setOrderItemId(shoppingOrderItem.getOrderItemId());
295                    shoppingOrderItemImpl.setOrderId(shoppingOrderItem.getOrderId());
296                    shoppingOrderItemImpl.setItemId(shoppingOrderItem.getItemId());
297                    shoppingOrderItemImpl.setSku(shoppingOrderItem.getSku());
298                    shoppingOrderItemImpl.setName(shoppingOrderItem.getName());
299                    shoppingOrderItemImpl.setDescription(shoppingOrderItem.getDescription());
300                    shoppingOrderItemImpl.setProperties(shoppingOrderItem.getProperties());
301                    shoppingOrderItemImpl.setPrice(shoppingOrderItem.getPrice());
302                    shoppingOrderItemImpl.setQuantity(shoppingOrderItem.getQuantity());
303                    shoppingOrderItemImpl.setShippedDate(shoppingOrderItem.getShippedDate());
304    
305                    return shoppingOrderItemImpl;
306            }
307    
308            /**
309             * Finds the shopping order item with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
310             *
311             * @param primaryKey the primary key of the shopping order item to find
312             * @return the shopping order item
313             * @throws com.liferay.portal.NoSuchModelException if a shopping order item with the primary key could not be found
314             * @throws SystemException if a system exception occurred
315             */
316            public ShoppingOrderItem findByPrimaryKey(Serializable primaryKey)
317                    throws NoSuchModelException, SystemException {
318                    return findByPrimaryKey(((Long)primaryKey).longValue());
319            }
320    
321            /**
322             * Finds the shopping order item with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchOrderItemException} if it could not be found.
323             *
324             * @param orderItemId the primary key of the shopping order item to find
325             * @return the shopping order item
326             * @throws com.liferay.portlet.shopping.NoSuchOrderItemException if a shopping order item with the primary key could not be found
327             * @throws SystemException if a system exception occurred
328             */
329            public ShoppingOrderItem findByPrimaryKey(long orderItemId)
330                    throws NoSuchOrderItemException, SystemException {
331                    ShoppingOrderItem shoppingOrderItem = fetchByPrimaryKey(orderItemId);
332    
333                    if (shoppingOrderItem == null) {
334                            if (_log.isWarnEnabled()) {
335                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orderItemId);
336                            }
337    
338                            throw new NoSuchOrderItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
339                                    orderItemId);
340                    }
341    
342                    return shoppingOrderItem;
343            }
344    
345            /**
346             * Finds the shopping order item with the primary key or returns <code>null</code> if it could not be found.
347             *
348             * @param primaryKey the primary key of the shopping order item to find
349             * @return the shopping order item, or <code>null</code> if a shopping order item with the primary key could not be found
350             * @throws SystemException if a system exception occurred
351             */
352            public ShoppingOrderItem fetchByPrimaryKey(Serializable primaryKey)
353                    throws SystemException {
354                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
355            }
356    
357            /**
358             * Finds the shopping order item with the primary key or returns <code>null</code> if it could not be found.
359             *
360             * @param orderItemId the primary key of the shopping order item to find
361             * @return the shopping order item, or <code>null</code> if a shopping order item with the primary key could not be found
362             * @throws SystemException if a system exception occurred
363             */
364            public ShoppingOrderItem fetchByPrimaryKey(long orderItemId)
365                    throws SystemException {
366                    ShoppingOrderItem shoppingOrderItem = (ShoppingOrderItem)EntityCacheUtil.getResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
367                                    ShoppingOrderItemImpl.class, orderItemId, this);
368    
369                    if (shoppingOrderItem == null) {
370                            Session session = null;
371    
372                            try {
373                                    session = openSession();
374    
375                                    shoppingOrderItem = (ShoppingOrderItem)session.get(ShoppingOrderItemImpl.class,
376                                                    new Long(orderItemId));
377                            }
378                            catch (Exception e) {
379                                    throw processException(e);
380                            }
381                            finally {
382                                    if (shoppingOrderItem != null) {
383                                            cacheResult(shoppingOrderItem);
384                                    }
385    
386                                    closeSession(session);
387                            }
388                    }
389    
390                    return shoppingOrderItem;
391            }
392    
393            /**
394             * Finds all the shopping order items where orderId = &#63;.
395             *
396             * @param orderId the order id to search with
397             * @return the matching shopping order items
398             * @throws SystemException if a system exception occurred
399             */
400            public List<ShoppingOrderItem> findByOrderId(long orderId)
401                    throws SystemException {
402                    return findByOrderId(orderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
403            }
404    
405            /**
406             * Finds a range of all the shopping order items where orderId = &#63;.
407             *
408             * <p>
409             * 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.
410             * </p>
411             *
412             * @param orderId the order id to search with
413             * @param start the lower bound of the range of shopping order items to return
414             * @param end the upper bound of the range of shopping order items to return (not inclusive)
415             * @return the range of matching shopping order items
416             * @throws SystemException if a system exception occurred
417             */
418            public List<ShoppingOrderItem> findByOrderId(long orderId, int start,
419                    int end) throws SystemException {
420                    return findByOrderId(orderId, start, end, null);
421            }
422    
423            /**
424             * Finds an ordered range of all the shopping order items where orderId = &#63;.
425             *
426             * <p>
427             * 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.
428             * </p>
429             *
430             * @param orderId the order id to search with
431             * @param start the lower bound of the range of shopping order items to return
432             * @param end the upper bound of the range of shopping order items to return (not inclusive)
433             * @param orderByComparator the comparator to order the results by
434             * @return the ordered range of matching shopping order items
435             * @throws SystemException if a system exception occurred
436             */
437            public List<ShoppingOrderItem> findByOrderId(long orderId, int start,
438                    int end, OrderByComparator orderByComparator) throws SystemException {
439                    Object[] finderArgs = new Object[] {
440                                    orderId,
441                                    
442                                    String.valueOf(start), String.valueOf(end),
443                                    String.valueOf(orderByComparator)
444                            };
445    
446                    List<ShoppingOrderItem> list = (List<ShoppingOrderItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ORDERID,
447                                    finderArgs, this);
448    
449                    if (list == null) {
450                            Session session = null;
451    
452                            try {
453                                    session = openSession();
454    
455                                    StringBundler query = null;
456    
457                                    if (orderByComparator != null) {
458                                            query = new StringBundler(3 +
459                                                            (orderByComparator.getOrderByFields().length * 3));
460                                    }
461                                    else {
462                                            query = new StringBundler(3);
463                                    }
464    
465                                    query.append(_SQL_SELECT_SHOPPINGORDERITEM_WHERE);
466    
467                                    query.append(_FINDER_COLUMN_ORDERID_ORDERID_2);
468    
469                                    if (orderByComparator != null) {
470                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
471                                                    orderByComparator);
472                                    }
473    
474                                    else {
475                                            query.append(ShoppingOrderItemModelImpl.ORDER_BY_JPQL);
476                                    }
477    
478                                    String sql = query.toString();
479    
480                                    Query q = session.createQuery(sql);
481    
482                                    QueryPos qPos = QueryPos.getInstance(q);
483    
484                                    qPos.add(orderId);
485    
486                                    list = (List<ShoppingOrderItem>)QueryUtil.list(q, getDialect(),
487                                                    start, end);
488                            }
489                            catch (Exception e) {
490                                    throw processException(e);
491                            }
492                            finally {
493                                    if (list == null) {
494                                            list = new ArrayList<ShoppingOrderItem>();
495                                    }
496    
497                                    cacheResult(list);
498    
499                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ORDERID,
500                                            finderArgs, list);
501    
502                                    closeSession(session);
503                            }
504                    }
505    
506                    return list;
507            }
508    
509            /**
510             * Finds the first shopping order item in the ordered set where orderId = &#63;.
511             *
512             * <p>
513             * 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.
514             * </p>
515             *
516             * @param orderId the order id to search with
517             * @param orderByComparator the comparator to order the set by
518             * @return the first matching shopping order item
519             * @throws com.liferay.portlet.shopping.NoSuchOrderItemException if a matching shopping order item could not be found
520             * @throws SystemException if a system exception occurred
521             */
522            public ShoppingOrderItem findByOrderId_First(long orderId,
523                    OrderByComparator orderByComparator)
524                    throws NoSuchOrderItemException, SystemException {
525                    List<ShoppingOrderItem> list = findByOrderId(orderId, 0, 1,
526                                    orderByComparator);
527    
528                    if (list.isEmpty()) {
529                            StringBundler msg = new StringBundler(4);
530    
531                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
532    
533                            msg.append("orderId=");
534                            msg.append(orderId);
535    
536                            msg.append(StringPool.CLOSE_CURLY_BRACE);
537    
538                            throw new NoSuchOrderItemException(msg.toString());
539                    }
540                    else {
541                            return list.get(0);
542                    }
543            }
544    
545            /**
546             * Finds the last shopping order item in the ordered set where orderId = &#63;.
547             *
548             * <p>
549             * 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.
550             * </p>
551             *
552             * @param orderId the order id to search with
553             * @param orderByComparator the comparator to order the set by
554             * @return the last matching shopping order item
555             * @throws com.liferay.portlet.shopping.NoSuchOrderItemException if a matching shopping order item could not be found
556             * @throws SystemException if a system exception occurred
557             */
558            public ShoppingOrderItem findByOrderId_Last(long orderId,
559                    OrderByComparator orderByComparator)
560                    throws NoSuchOrderItemException, SystemException {
561                    int count = countByOrderId(orderId);
562    
563                    List<ShoppingOrderItem> list = findByOrderId(orderId, count - 1, count,
564                                    orderByComparator);
565    
566                    if (list.isEmpty()) {
567                            StringBundler msg = new StringBundler(4);
568    
569                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
570    
571                            msg.append("orderId=");
572                            msg.append(orderId);
573    
574                            msg.append(StringPool.CLOSE_CURLY_BRACE);
575    
576                            throw new NoSuchOrderItemException(msg.toString());
577                    }
578                    else {
579                            return list.get(0);
580                    }
581            }
582    
583            /**
584             * Finds the shopping order items before and after the current shopping order item in the ordered set where orderId = &#63;.
585             *
586             * <p>
587             * 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.
588             * </p>
589             *
590             * @param orderItemId the primary key of the current shopping order item
591             * @param orderId the order id to search with
592             * @param orderByComparator the comparator to order the set by
593             * @return the previous, current, and next shopping order item
594             * @throws com.liferay.portlet.shopping.NoSuchOrderItemException if a shopping order item with the primary key could not be found
595             * @throws SystemException if a system exception occurred
596             */
597            public ShoppingOrderItem[] findByOrderId_PrevAndNext(long orderItemId,
598                    long orderId, OrderByComparator orderByComparator)
599                    throws NoSuchOrderItemException, SystemException {
600                    ShoppingOrderItem shoppingOrderItem = findByPrimaryKey(orderItemId);
601    
602                    Session session = null;
603    
604                    try {
605                            session = openSession();
606    
607                            ShoppingOrderItem[] array = new ShoppingOrderItemImpl[3];
608    
609                            array[0] = getByOrderId_PrevAndNext(session, shoppingOrderItem,
610                                            orderId, orderByComparator, true);
611    
612                            array[1] = shoppingOrderItem;
613    
614                            array[2] = getByOrderId_PrevAndNext(session, shoppingOrderItem,
615                                            orderId, orderByComparator, false);
616    
617                            return array;
618                    }
619                    catch (Exception e) {
620                            throw processException(e);
621                    }
622                    finally {
623                            closeSession(session);
624                    }
625            }
626    
627            protected ShoppingOrderItem getByOrderId_PrevAndNext(Session session,
628                    ShoppingOrderItem shoppingOrderItem, long orderId,
629                    OrderByComparator orderByComparator, boolean previous) {
630                    StringBundler query = null;
631    
632                    if (orderByComparator != null) {
633                            query = new StringBundler(6 +
634                                            (orderByComparator.getOrderByFields().length * 6));
635                    }
636                    else {
637                            query = new StringBundler(3);
638                    }
639    
640                    query.append(_SQL_SELECT_SHOPPINGORDERITEM_WHERE);
641    
642                    query.append(_FINDER_COLUMN_ORDERID_ORDERID_2);
643    
644                    if (orderByComparator != null) {
645                            String[] orderByFields = orderByComparator.getOrderByFields();
646    
647                            if (orderByFields.length > 0) {
648                                    query.append(WHERE_AND);
649                            }
650    
651                            for (int i = 0; i < orderByFields.length; i++) {
652                                    query.append(_ORDER_BY_ENTITY_ALIAS);
653                                    query.append(orderByFields[i]);
654    
655                                    if ((i + 1) < orderByFields.length) {
656                                            if (orderByComparator.isAscending() ^ previous) {
657                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
658                                            }
659                                            else {
660                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
661                                            }
662                                    }
663                                    else {
664                                            if (orderByComparator.isAscending() ^ previous) {
665                                                    query.append(WHERE_GREATER_THAN);
666                                            }
667                                            else {
668                                                    query.append(WHERE_LESSER_THAN);
669                                            }
670                                    }
671                            }
672    
673                            query.append(ORDER_BY_CLAUSE);
674    
675                            for (int i = 0; i < orderByFields.length; i++) {
676                                    query.append(_ORDER_BY_ENTITY_ALIAS);
677                                    query.append(orderByFields[i]);
678    
679                                    if ((i + 1) < orderByFields.length) {
680                                            if (orderByComparator.isAscending() ^ previous) {
681                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
682                                            }
683                                            else {
684                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
685                                            }
686                                    }
687                                    else {
688                                            if (orderByComparator.isAscending() ^ previous) {
689                                                    query.append(ORDER_BY_ASC);
690                                            }
691                                            else {
692                                                    query.append(ORDER_BY_DESC);
693                                            }
694                                    }
695                            }
696                    }
697    
698                    else {
699                            query.append(ShoppingOrderItemModelImpl.ORDER_BY_JPQL);
700                    }
701    
702                    String sql = query.toString();
703    
704                    Query q = session.createQuery(sql);
705    
706                    q.setFirstResult(0);
707                    q.setMaxResults(2);
708    
709                    QueryPos qPos = QueryPos.getInstance(q);
710    
711                    qPos.add(orderId);
712    
713                    if (orderByComparator != null) {
714                            Object[] values = orderByComparator.getOrderByValues(shoppingOrderItem);
715    
716                            for (Object value : values) {
717                                    qPos.add(value);
718                            }
719                    }
720    
721                    List<ShoppingOrderItem> list = q.list();
722    
723                    if (list.size() == 2) {
724                            return list.get(1);
725                    }
726                    else {
727                            return null;
728                    }
729            }
730    
731            /**
732             * Finds all the shopping order items.
733             *
734             * @return the shopping order items
735             * @throws SystemException if a system exception occurred
736             */
737            public List<ShoppingOrderItem> findAll() throws SystemException {
738                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
739            }
740    
741            /**
742             * Finds a range of all the shopping order items.
743             *
744             * <p>
745             * 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.
746             * </p>
747             *
748             * @param start the lower bound of the range of shopping order items to return
749             * @param end the upper bound of the range of shopping order items to return (not inclusive)
750             * @return the range of shopping order items
751             * @throws SystemException if a system exception occurred
752             */
753            public List<ShoppingOrderItem> findAll(int start, int end)
754                    throws SystemException {
755                    return findAll(start, end, null);
756            }
757    
758            /**
759             * Finds an ordered range of all the shopping order items.
760             *
761             * <p>
762             * 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.
763             * </p>
764             *
765             * @param start the lower bound of the range of shopping order items to return
766             * @param end the upper bound of the range of shopping order items to return (not inclusive)
767             * @param orderByComparator the comparator to order the results by
768             * @return the ordered range of shopping order items
769             * @throws SystemException if a system exception occurred
770             */
771            public List<ShoppingOrderItem> findAll(int start, int end,
772                    OrderByComparator orderByComparator) throws SystemException {
773                    Object[] finderArgs = new Object[] {
774                                    String.valueOf(start), String.valueOf(end),
775                                    String.valueOf(orderByComparator)
776                            };
777    
778                    List<ShoppingOrderItem> list = (List<ShoppingOrderItem>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
779                                    finderArgs, this);
780    
781                    if (list == null) {
782                            Session session = null;
783    
784                            try {
785                                    session = openSession();
786    
787                                    StringBundler query = null;
788                                    String sql = null;
789    
790                                    if (orderByComparator != null) {
791                                            query = new StringBundler(2 +
792                                                            (orderByComparator.getOrderByFields().length * 3));
793    
794                                            query.append(_SQL_SELECT_SHOPPINGORDERITEM);
795    
796                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
797                                                    orderByComparator);
798    
799                                            sql = query.toString();
800                                    }
801                                    else {
802                                            sql = _SQL_SELECT_SHOPPINGORDERITEM.concat(ShoppingOrderItemModelImpl.ORDER_BY_JPQL);
803                                    }
804    
805                                    Query q = session.createQuery(sql);
806    
807                                    if (orderByComparator == null) {
808                                            list = (List<ShoppingOrderItem>)QueryUtil.list(q,
809                                                            getDialect(), start, end, false);
810    
811                                            Collections.sort(list);
812                                    }
813                                    else {
814                                            list = (List<ShoppingOrderItem>)QueryUtil.list(q,
815                                                            getDialect(), start, end);
816                                    }
817                            }
818                            catch (Exception e) {
819                                    throw processException(e);
820                            }
821                            finally {
822                                    if (list == null) {
823                                            list = new ArrayList<ShoppingOrderItem>();
824                                    }
825    
826                                    cacheResult(list);
827    
828                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
829    
830                                    closeSession(session);
831                            }
832                    }
833    
834                    return list;
835            }
836    
837            /**
838             * Removes all the shopping order items where orderId = &#63; from the database.
839             *
840             * @param orderId the order id to search with
841             * @throws SystemException if a system exception occurred
842             */
843            public void removeByOrderId(long orderId) throws SystemException {
844                    for (ShoppingOrderItem shoppingOrderItem : findByOrderId(orderId)) {
845                            remove(shoppingOrderItem);
846                    }
847            }
848    
849            /**
850             * Removes all the shopping order items from the database.
851             *
852             * @throws SystemException if a system exception occurred
853             */
854            public void removeAll() throws SystemException {
855                    for (ShoppingOrderItem shoppingOrderItem : findAll()) {
856                            remove(shoppingOrderItem);
857                    }
858            }
859    
860            /**
861             * Counts all the shopping order items where orderId = &#63;.
862             *
863             * @param orderId the order id to search with
864             * @return the number of matching shopping order items
865             * @throws SystemException if a system exception occurred
866             */
867            public int countByOrderId(long orderId) throws SystemException {
868                    Object[] finderArgs = new Object[] { orderId };
869    
870                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ORDERID,
871                                    finderArgs, this);
872    
873                    if (count == null) {
874                            Session session = null;
875    
876                            try {
877                                    session = openSession();
878    
879                                    StringBundler query = new StringBundler(2);
880    
881                                    query.append(_SQL_COUNT_SHOPPINGORDERITEM_WHERE);
882    
883                                    query.append(_FINDER_COLUMN_ORDERID_ORDERID_2);
884    
885                                    String sql = query.toString();
886    
887                                    Query q = session.createQuery(sql);
888    
889                                    QueryPos qPos = QueryPos.getInstance(q);
890    
891                                    qPos.add(orderId);
892    
893                                    count = (Long)q.uniqueResult();
894                            }
895                            catch (Exception e) {
896                                    throw processException(e);
897                            }
898                            finally {
899                                    if (count == null) {
900                                            count = Long.valueOf(0);
901                                    }
902    
903                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ORDERID,
904                                            finderArgs, count);
905    
906                                    closeSession(session);
907                            }
908                    }
909    
910                    return count.intValue();
911            }
912    
913            /**
914             * Counts all the shopping order items.
915             *
916             * @return the number of shopping order items
917             * @throws SystemException if a system exception occurred
918             */
919            public int countAll() throws SystemException {
920                    Object[] finderArgs = new Object[0];
921    
922                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
923                                    finderArgs, this);
924    
925                    if (count == null) {
926                            Session session = null;
927    
928                            try {
929                                    session = openSession();
930    
931                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGORDERITEM);
932    
933                                    count = (Long)q.uniqueResult();
934                            }
935                            catch (Exception e) {
936                                    throw processException(e);
937                            }
938                            finally {
939                                    if (count == null) {
940                                            count = Long.valueOf(0);
941                                    }
942    
943                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
944                                            count);
945    
946                                    closeSession(session);
947                            }
948                    }
949    
950                    return count.intValue();
951            }
952    
953            /**
954             * Initializes the shopping order item persistence.
955             */
956            public void afterPropertiesSet() {
957                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
958                                            com.liferay.portal.util.PropsUtil.get(
959                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingOrderItem")));
960    
961                    if (listenerClassNames.length > 0) {
962                            try {
963                                    List<ModelListener<ShoppingOrderItem>> listenersList = new ArrayList<ModelListener<ShoppingOrderItem>>();
964    
965                                    for (String listenerClassName : listenerClassNames) {
966                                            listenersList.add((ModelListener<ShoppingOrderItem>)InstanceFactory.newInstance(
967                                                            listenerClassName));
968                                    }
969    
970                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
971                            }
972                            catch (Exception e) {
973                                    _log.error(e);
974                            }
975                    }
976            }
977    
978            @BeanReference(type = ShoppingCartPersistence.class)
979            protected ShoppingCartPersistence shoppingCartPersistence;
980            @BeanReference(type = ShoppingCategoryPersistence.class)
981            protected ShoppingCategoryPersistence shoppingCategoryPersistence;
982            @BeanReference(type = ShoppingCouponPersistence.class)
983            protected ShoppingCouponPersistence shoppingCouponPersistence;
984            @BeanReference(type = ShoppingItemPersistence.class)
985            protected ShoppingItemPersistence shoppingItemPersistence;
986            @BeanReference(type = ShoppingItemFieldPersistence.class)
987            protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
988            @BeanReference(type = ShoppingItemPricePersistence.class)
989            protected ShoppingItemPricePersistence shoppingItemPricePersistence;
990            @BeanReference(type = ShoppingOrderPersistence.class)
991            protected ShoppingOrderPersistence shoppingOrderPersistence;
992            @BeanReference(type = ShoppingOrderItemPersistence.class)
993            protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
994            @BeanReference(type = ResourcePersistence.class)
995            protected ResourcePersistence resourcePersistence;
996            @BeanReference(type = UserPersistence.class)
997            protected UserPersistence userPersistence;
998            private static final String _SQL_SELECT_SHOPPINGORDERITEM = "SELECT shoppingOrderItem FROM ShoppingOrderItem shoppingOrderItem";
999            private static final String _SQL_SELECT_SHOPPINGORDERITEM_WHERE = "SELECT shoppingOrderItem FROM ShoppingOrderItem shoppingOrderItem WHERE ";
1000            private static final String _SQL_COUNT_SHOPPINGORDERITEM = "SELECT COUNT(shoppingOrderItem) FROM ShoppingOrderItem shoppingOrderItem";
1001            private static final String _SQL_COUNT_SHOPPINGORDERITEM_WHERE = "SELECT COUNT(shoppingOrderItem) FROM ShoppingOrderItem shoppingOrderItem WHERE ";
1002            private static final String _FINDER_COLUMN_ORDERID_ORDERID_2 = "shoppingOrderItem.orderId = ?";
1003            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingOrderItem.";
1004            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingOrderItem exists with the primary key ";
1005            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingOrderItem exists with the key {";
1006            private static Log _log = LogFactoryUtil.getLog(ShoppingOrderItemPersistenceImpl.class);
1007    }