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