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