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