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