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