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