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