001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.shopping.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.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.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
039    import com.liferay.portal.service.persistence.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.ResourcePersistence;
041    import com.liferay.portal.service.persistence.UserPersistence;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.shopping.NoSuchCategoryException;
045    import com.liferay.portlet.shopping.model.ShoppingCategory;
046    import com.liferay.portlet.shopping.model.impl.ShoppingCategoryImpl;
047    import com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence implementation for the shopping category service.
057     *
058     * <p>
059     * Never modify or reference this class directly. Always use {@link ShoppingCategoryUtil} to access the shopping category persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
060     * </p>
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see ShoppingCategoryPersistence
068     * @see ShoppingCategoryUtil
069     * @generated
070     */
071    public class ShoppingCategoryPersistenceImpl extends BasePersistenceImpl<ShoppingCategory>
072            implements ShoppingCategoryPersistence {
073            public static final String FINDER_CLASS_NAME_ENTITY = ShoppingCategoryImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075                    ".List";
076            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
077                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
078                            FINDER_CLASS_NAME_LIST, "findByGroupId",
079                            new String[] {
080                                    Long.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
086                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
087                            FINDER_CLASS_NAME_LIST, "countByGroupId",
088                            new String[] { Long.class.getName() });
089            public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
090                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
091                            FINDER_CLASS_NAME_LIST, "findByG_P",
092                            new String[] {
093                                    Long.class.getName(), Long.class.getName(),
094                                    
095                            "java.lang.Integer", "java.lang.Integer",
096                                    "com.liferay.portal.kernel.util.OrderByComparator"
097                            });
098            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
099                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
100                            FINDER_CLASS_NAME_LIST, "countByG_P",
101                            new String[] { Long.class.getName(), Long.class.getName() });
102            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
103                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
104                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
105            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
106                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
107                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
108    
109            /**
110             * Caches the shopping category in the entity cache if it is enabled.
111             *
112             * @param shoppingCategory the shopping category to cache
113             */
114            public void cacheResult(ShoppingCategory shoppingCategory) {
115                    EntityCacheUtil.putResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
116                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey(),
117                            shoppingCategory);
118            }
119    
120            /**
121             * Caches the shopping categories in the entity cache if it is enabled.
122             *
123             * @param shoppingCategories the shopping categories to cache
124             */
125            public void cacheResult(List<ShoppingCategory> shoppingCategories) {
126                    for (ShoppingCategory shoppingCategory : shoppingCategories) {
127                            if (EntityCacheUtil.getResult(
128                                                    ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
129                                                    ShoppingCategoryImpl.class,
130                                                    shoppingCategory.getPrimaryKey(), this) == null) {
131                                    cacheResult(shoppingCategory);
132                            }
133                    }
134            }
135    
136            /**
137             * Clears the cache for all shopping categories.
138             *
139             * <p>
140             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
141             * </p>
142             */
143            public void clearCache() {
144                    CacheRegistryUtil.clear(ShoppingCategoryImpl.class.getName());
145                    EntityCacheUtil.clearCache(ShoppingCategoryImpl.class.getName());
146                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
147                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
148            }
149    
150            /**
151             * Clears the cache for the shopping category.
152             *
153             * <p>
154             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
155             * </p>
156             */
157            public void clearCache(ShoppingCategory shoppingCategory) {
158                    EntityCacheUtil.removeResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
159                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey());
160            }
161    
162            /**
163             * Creates a new shopping category with the primary key. Does not add the shopping category to the database.
164             *
165             * @param categoryId the primary key for the new shopping category
166             * @return the new shopping category
167             */
168            public ShoppingCategory create(long categoryId) {
169                    ShoppingCategory shoppingCategory = new ShoppingCategoryImpl();
170    
171                    shoppingCategory.setNew(true);
172                    shoppingCategory.setPrimaryKey(categoryId);
173    
174                    return shoppingCategory;
175            }
176    
177            /**
178             * Removes the shopping category with the primary key from the database. Also notifies the appropriate model listeners.
179             *
180             * @param primaryKey the primary key of the shopping category to remove
181             * @return the shopping category that was removed
182             * @throws com.liferay.portal.NoSuchModelException if a shopping category with the primary key could not be found
183             * @throws SystemException if a system exception occurred
184             */
185            public ShoppingCategory remove(Serializable primaryKey)
186                    throws NoSuchModelException, SystemException {
187                    return remove(((Long)primaryKey).longValue());
188            }
189    
190            /**
191             * Removes the shopping category with the primary key from the database. Also notifies the appropriate model listeners.
192             *
193             * @param categoryId the primary key of the shopping category to remove
194             * @return the shopping category that was removed
195             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
196             * @throws SystemException if a system exception occurred
197             */
198            public ShoppingCategory remove(long categoryId)
199                    throws NoSuchCategoryException, SystemException {
200                    Session session = null;
201    
202                    try {
203                            session = openSession();
204    
205                            ShoppingCategory shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
206                                            new Long(categoryId));
207    
208                            if (shoppingCategory == null) {
209                                    if (_log.isWarnEnabled()) {
210                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
211                                    }
212    
213                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
214                                            categoryId);
215                            }
216    
217                            return remove(shoppingCategory);
218                    }
219                    catch (NoSuchCategoryException nsee) {
220                            throw nsee;
221                    }
222                    catch (Exception e) {
223                            throw processException(e);
224                    }
225                    finally {
226                            closeSession(session);
227                    }
228            }
229    
230            protected ShoppingCategory removeImpl(ShoppingCategory shoppingCategory)
231                    throws SystemException {
232                    shoppingCategory = toUnwrappedModel(shoppingCategory);
233    
234                    Session session = null;
235    
236                    try {
237                            session = openSession();
238    
239                            BatchSessionUtil.delete(session, shoppingCategory);
240                    }
241                    catch (Exception e) {
242                            throw processException(e);
243                    }
244                    finally {
245                            closeSession(session);
246                    }
247    
248                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
249    
250                    EntityCacheUtil.removeResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
251                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey());
252    
253                    return shoppingCategory;
254            }
255    
256            public ShoppingCategory updateImpl(
257                    com.liferay.portlet.shopping.model.ShoppingCategory shoppingCategory,
258                    boolean merge) throws SystemException {
259                    shoppingCategory = toUnwrappedModel(shoppingCategory);
260    
261                    Session session = null;
262    
263                    try {
264                            session = openSession();
265    
266                            BatchSessionUtil.update(session, shoppingCategory, merge);
267    
268                            shoppingCategory.setNew(false);
269                    }
270                    catch (Exception e) {
271                            throw processException(e);
272                    }
273                    finally {
274                            closeSession(session);
275                    }
276    
277                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
278    
279                    EntityCacheUtil.putResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
280                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey(),
281                            shoppingCategory);
282    
283                    return shoppingCategory;
284            }
285    
286            protected ShoppingCategory toUnwrappedModel(
287                    ShoppingCategory shoppingCategory) {
288                    if (shoppingCategory instanceof ShoppingCategoryImpl) {
289                            return shoppingCategory;
290                    }
291    
292                    ShoppingCategoryImpl shoppingCategoryImpl = new ShoppingCategoryImpl();
293    
294                    shoppingCategoryImpl.setNew(shoppingCategory.isNew());
295                    shoppingCategoryImpl.setPrimaryKey(shoppingCategory.getPrimaryKey());
296    
297                    shoppingCategoryImpl.setCategoryId(shoppingCategory.getCategoryId());
298                    shoppingCategoryImpl.setGroupId(shoppingCategory.getGroupId());
299                    shoppingCategoryImpl.setCompanyId(shoppingCategory.getCompanyId());
300                    shoppingCategoryImpl.setUserId(shoppingCategory.getUserId());
301                    shoppingCategoryImpl.setUserName(shoppingCategory.getUserName());
302                    shoppingCategoryImpl.setCreateDate(shoppingCategory.getCreateDate());
303                    shoppingCategoryImpl.setModifiedDate(shoppingCategory.getModifiedDate());
304                    shoppingCategoryImpl.setParentCategoryId(shoppingCategory.getParentCategoryId());
305                    shoppingCategoryImpl.setName(shoppingCategory.getName());
306                    shoppingCategoryImpl.setDescription(shoppingCategory.getDescription());
307    
308                    return shoppingCategoryImpl;
309            }
310    
311            /**
312             * Finds the shopping category with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
313             *
314             * @param primaryKey the primary key of the shopping category to find
315             * @return the shopping category
316             * @throws com.liferay.portal.NoSuchModelException if a shopping category with the primary key could not be found
317             * @throws SystemException if a system exception occurred
318             */
319            public ShoppingCategory findByPrimaryKey(Serializable primaryKey)
320                    throws NoSuchModelException, SystemException {
321                    return findByPrimaryKey(((Long)primaryKey).longValue());
322            }
323    
324            /**
325             * Finds the shopping category with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchCategoryException} if it could not be found.
326             *
327             * @param categoryId the primary key of the shopping category to find
328             * @return the shopping category
329             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
330             * @throws SystemException if a system exception occurred
331             */
332            public ShoppingCategory findByPrimaryKey(long categoryId)
333                    throws NoSuchCategoryException, SystemException {
334                    ShoppingCategory shoppingCategory = fetchByPrimaryKey(categoryId);
335    
336                    if (shoppingCategory == null) {
337                            if (_log.isWarnEnabled()) {
338                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
339                            }
340    
341                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
342                                    categoryId);
343                    }
344    
345                    return shoppingCategory;
346            }
347    
348            /**
349             * Finds the shopping category with the primary key or returns <code>null</code> if it could not be found.
350             *
351             * @param primaryKey the primary key of the shopping category to find
352             * @return the shopping category, or <code>null</code> if a shopping category with the primary key could not be found
353             * @throws SystemException if a system exception occurred
354             */
355            public ShoppingCategory fetchByPrimaryKey(Serializable primaryKey)
356                    throws SystemException {
357                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
358            }
359    
360            /**
361             * Finds the shopping category with the primary key or returns <code>null</code> if it could not be found.
362             *
363             * @param categoryId the primary key of the shopping category to find
364             * @return the shopping category, or <code>null</code> if a shopping category with the primary key could not be found
365             * @throws SystemException if a system exception occurred
366             */
367            public ShoppingCategory fetchByPrimaryKey(long categoryId)
368                    throws SystemException {
369                    ShoppingCategory shoppingCategory = (ShoppingCategory)EntityCacheUtil.getResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
370                                    ShoppingCategoryImpl.class, categoryId, this);
371    
372                    if (shoppingCategory == null) {
373                            Session session = null;
374    
375                            try {
376                                    session = openSession();
377    
378                                    shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
379                                                    new Long(categoryId));
380                            }
381                            catch (Exception e) {
382                                    throw processException(e);
383                            }
384                            finally {
385                                    if (shoppingCategory != null) {
386                                            cacheResult(shoppingCategory);
387                                    }
388    
389                                    closeSession(session);
390                            }
391                    }
392    
393                    return shoppingCategory;
394            }
395    
396            /**
397             * Finds all the shopping categories where groupId = &#63;.
398             *
399             * @param groupId the group id to search with
400             * @return the matching shopping categories
401             * @throws SystemException if a system exception occurred
402             */
403            public List<ShoppingCategory> findByGroupId(long groupId)
404                    throws SystemException {
405                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
406            }
407    
408            /**
409             * Finds a range of all the shopping categories where groupId = &#63;.
410             *
411             * <p>
412             * 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.
413             * </p>
414             *
415             * @param groupId the group id to search with
416             * @param start the lower bound of the range of shopping categories to return
417             * @param end the upper bound of the range of shopping categories to return (not inclusive)
418             * @return the range of matching shopping categories
419             * @throws SystemException if a system exception occurred
420             */
421            public List<ShoppingCategory> findByGroupId(long groupId, int start, int end)
422                    throws SystemException {
423                    return findByGroupId(groupId, start, end, null);
424            }
425    
426            /**
427             * Finds an ordered range of all the shopping categories where groupId = &#63;.
428             *
429             * <p>
430             * 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.
431             * </p>
432             *
433             * @param groupId the group id to search with
434             * @param start the lower bound of the range of shopping categories to return
435             * @param end the upper bound of the range of shopping categories to return (not inclusive)
436             * @param orderByComparator the comparator to order the results by
437             * @return the ordered range of matching shopping categories
438             * @throws SystemException if a system exception occurred
439             */
440            public List<ShoppingCategory> findByGroupId(long groupId, int start,
441                    int end, OrderByComparator orderByComparator) throws SystemException {
442                    Object[] finderArgs = new Object[] {
443                                    groupId,
444                                    
445                                    String.valueOf(start), String.valueOf(end),
446                                    String.valueOf(orderByComparator)
447                            };
448    
449                    List<ShoppingCategory> list = (List<ShoppingCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
450                                    finderArgs, this);
451    
452                    if (list == null) {
453                            Session session = null;
454    
455                            try {
456                                    session = openSession();
457    
458                                    StringBundler query = null;
459    
460                                    if (orderByComparator != null) {
461                                            query = new StringBundler(3 +
462                                                            (orderByComparator.getOrderByFields().length * 3));
463                                    }
464                                    else {
465                                            query = new StringBundler(3);
466                                    }
467    
468                                    query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
469    
470                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
471    
472                                    if (orderByComparator != null) {
473                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
474                                                    orderByComparator);
475                                    }
476    
477                                    else {
478                                            query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
479                                    }
480    
481                                    String sql = query.toString();
482    
483                                    Query q = session.createQuery(sql);
484    
485                                    QueryPos qPos = QueryPos.getInstance(q);
486    
487                                    qPos.add(groupId);
488    
489                                    list = (List<ShoppingCategory>)QueryUtil.list(q, getDialect(),
490                                                    start, end);
491                            }
492                            catch (Exception e) {
493                                    throw processException(e);
494                            }
495                            finally {
496                                    if (list == null) {
497                                            list = new ArrayList<ShoppingCategory>();
498                                    }
499    
500                                    cacheResult(list);
501    
502                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
503                                            finderArgs, list);
504    
505                                    closeSession(session);
506                            }
507                    }
508    
509                    return list;
510            }
511    
512            /**
513             * Finds the first shopping category in the ordered set where groupId = &#63;.
514             *
515             * <p>
516             * 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.
517             * </p>
518             *
519             * @param groupId the group id to search with
520             * @param orderByComparator the comparator to order the set by
521             * @return the first matching shopping category
522             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
523             * @throws SystemException if a system exception occurred
524             */
525            public ShoppingCategory findByGroupId_First(long groupId,
526                    OrderByComparator orderByComparator)
527                    throws NoSuchCategoryException, SystemException {
528                    List<ShoppingCategory> list = findByGroupId(groupId, 0, 1,
529                                    orderByComparator);
530    
531                    if (list.isEmpty()) {
532                            StringBundler msg = new StringBundler(4);
533    
534                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
535    
536                            msg.append("groupId=");
537                            msg.append(groupId);
538    
539                            msg.append(StringPool.CLOSE_CURLY_BRACE);
540    
541                            throw new NoSuchCategoryException(msg.toString());
542                    }
543                    else {
544                            return list.get(0);
545                    }
546            }
547    
548            /**
549             * Finds the last shopping category in the ordered set where groupId = &#63;.
550             *
551             * <p>
552             * 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.
553             * </p>
554             *
555             * @param groupId the group id to search with
556             * @param orderByComparator the comparator to order the set by
557             * @return the last matching shopping category
558             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
559             * @throws SystemException if a system exception occurred
560             */
561            public ShoppingCategory findByGroupId_Last(long groupId,
562                    OrderByComparator orderByComparator)
563                    throws NoSuchCategoryException, SystemException {
564                    int count = countByGroupId(groupId);
565    
566                    List<ShoppingCategory> list = findByGroupId(groupId, count - 1, count,
567                                    orderByComparator);
568    
569                    if (list.isEmpty()) {
570                            StringBundler msg = new StringBundler(4);
571    
572                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
573    
574                            msg.append("groupId=");
575                            msg.append(groupId);
576    
577                            msg.append(StringPool.CLOSE_CURLY_BRACE);
578    
579                            throw new NoSuchCategoryException(msg.toString());
580                    }
581                    else {
582                            return list.get(0);
583                    }
584            }
585    
586            /**
587             * Finds the shopping categories before and after the current shopping category in the ordered set where groupId = &#63;.
588             *
589             * <p>
590             * 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.
591             * </p>
592             *
593             * @param categoryId the primary key of the current shopping category
594             * @param groupId the group id to search with
595             * @param orderByComparator the comparator to order the set by
596             * @return the previous, current, and next shopping category
597             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
598             * @throws SystemException if a system exception occurred
599             */
600            public ShoppingCategory[] findByGroupId_PrevAndNext(long categoryId,
601                    long groupId, OrderByComparator orderByComparator)
602                    throws NoSuchCategoryException, SystemException {
603                    ShoppingCategory shoppingCategory = findByPrimaryKey(categoryId);
604    
605                    Session session = null;
606    
607                    try {
608                            session = openSession();
609    
610                            ShoppingCategory[] array = new ShoppingCategoryImpl[3];
611    
612                            array[0] = getByGroupId_PrevAndNext(session, shoppingCategory,
613                                            groupId, orderByComparator, true);
614    
615                            array[1] = shoppingCategory;
616    
617                            array[2] = getByGroupId_PrevAndNext(session, shoppingCategory,
618                                            groupId, orderByComparator, false);
619    
620                            return array;
621                    }
622                    catch (Exception e) {
623                            throw processException(e);
624                    }
625                    finally {
626                            closeSession(session);
627                    }
628            }
629    
630            protected ShoppingCategory getByGroupId_PrevAndNext(Session session,
631                    ShoppingCategory shoppingCategory, long groupId,
632                    OrderByComparator orderByComparator, boolean previous) {
633                    StringBundler query = null;
634    
635                    if (orderByComparator != null) {
636                            query = new StringBundler(6 +
637                                            (orderByComparator.getOrderByFields().length * 6));
638                    }
639                    else {
640                            query = new StringBundler(3);
641                    }
642    
643                    query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
644    
645                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
646    
647                    if (orderByComparator != null) {
648                            String[] orderByFields = orderByComparator.getOrderByFields();
649    
650                            if (orderByFields.length > 0) {
651                                    query.append(WHERE_AND);
652                            }
653    
654                            for (int i = 0; i < orderByFields.length; i++) {
655                                    query.append(_ORDER_BY_ENTITY_ALIAS);
656                                    query.append(orderByFields[i]);
657    
658                                    if ((i + 1) < orderByFields.length) {
659                                            if (orderByComparator.isAscending() ^ previous) {
660                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
661                                            }
662                                            else {
663                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
664                                            }
665                                    }
666                                    else {
667                                            if (orderByComparator.isAscending() ^ previous) {
668                                                    query.append(WHERE_GREATER_THAN);
669                                            }
670                                            else {
671                                                    query.append(WHERE_LESSER_THAN);
672                                            }
673                                    }
674                            }
675    
676                            query.append(ORDER_BY_CLAUSE);
677    
678                            for (int i = 0; i < orderByFields.length; i++) {
679                                    query.append(_ORDER_BY_ENTITY_ALIAS);
680                                    query.append(orderByFields[i]);
681    
682                                    if ((i + 1) < orderByFields.length) {
683                                            if (orderByComparator.isAscending() ^ previous) {
684                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
685                                            }
686                                            else {
687                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
688                                            }
689                                    }
690                                    else {
691                                            if (orderByComparator.isAscending() ^ previous) {
692                                                    query.append(ORDER_BY_ASC);
693                                            }
694                                            else {
695                                                    query.append(ORDER_BY_DESC);
696                                            }
697                                    }
698                            }
699                    }
700    
701                    else {
702                            query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
703                    }
704    
705                    String sql = query.toString();
706    
707                    Query q = session.createQuery(sql);
708    
709                    q.setFirstResult(0);
710                    q.setMaxResults(2);
711    
712                    QueryPos qPos = QueryPos.getInstance(q);
713    
714                    qPos.add(groupId);
715    
716                    if (orderByComparator != null) {
717                            Object[] values = orderByComparator.getOrderByValues(shoppingCategory);
718    
719                            for (Object value : values) {
720                                    qPos.add(value);
721                            }
722                    }
723    
724                    List<ShoppingCategory> list = q.list();
725    
726                    if (list.size() == 2) {
727                            return list.get(1);
728                    }
729                    else {
730                            return null;
731                    }
732            }
733    
734            /**
735             * Filters by the user's permissions and finds all the shopping categories where groupId = &#63;.
736             *
737             * @param groupId the group id to search with
738             * @return the matching shopping categories that the user has permission to view
739             * @throws SystemException if a system exception occurred
740             */
741            public List<ShoppingCategory> filterFindByGroupId(long groupId)
742                    throws SystemException {
743                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
744                            QueryUtil.ALL_POS, null);
745            }
746    
747            /**
748             * Filters by the user's permissions and finds a range of all the shopping categories where groupId = &#63;.
749             *
750             * <p>
751             * 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.
752             * </p>
753             *
754             * @param groupId the group id to search with
755             * @param start the lower bound of the range of shopping categories to return
756             * @param end the upper bound of the range of shopping categories to return (not inclusive)
757             * @return the range of matching shopping categories that the user has permission to view
758             * @throws SystemException if a system exception occurred
759             */
760            public List<ShoppingCategory> filterFindByGroupId(long groupId, int start,
761                    int end) throws SystemException {
762                    return filterFindByGroupId(groupId, start, end, null);
763            }
764    
765            /**
766             * Filters by the user's permissions and finds an ordered range of all the shopping categories where groupId = &#63;.
767             *
768             * <p>
769             * 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.
770             * </p>
771             *
772             * @param groupId the group id to search with
773             * @param start the lower bound of the range of shopping categories to return
774             * @param end the upper bound of the range of shopping categories to return (not inclusive)
775             * @param orderByComparator the comparator to order the results by
776             * @return the ordered range of matching shopping categories that the user has permission to view
777             * @throws SystemException if a system exception occurred
778             */
779            public List<ShoppingCategory> filterFindByGroupId(long groupId, int start,
780                    int end, OrderByComparator orderByComparator) throws SystemException {
781                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
782                            return findByGroupId(groupId, start, end, orderByComparator);
783                    }
784    
785                    Session session = null;
786    
787                    try {
788                            session = openSession();
789    
790                            StringBundler query = null;
791    
792                            if (orderByComparator != null) {
793                                    query = new StringBundler(3 +
794                                                    (orderByComparator.getOrderByFields().length * 3));
795                            }
796                            else {
797                                    query = new StringBundler(3);
798                            }
799    
800                            if (getDB().isSupportsInlineDistinct()) {
801                                    query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
802                            }
803                            else {
804                                    query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE);
805                            }
806    
807                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
808    
809                            if (orderByComparator != null) {
810                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
811                                            orderByComparator);
812                            }
813    
814                            else {
815                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
816                            }
817    
818                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
819                                            ShoppingCategory.class.getName(), _FILTER_COLUMN_PK,
820                                            _FILTER_COLUMN_USERID, groupId);
821    
822                            SQLQuery q = session.createSQLQuery(sql);
823    
824                            q.addEntity(_FILTER_ENTITY_ALIAS, ShoppingCategoryImpl.class);
825    
826                            QueryPos qPos = QueryPos.getInstance(q);
827    
828                            qPos.add(groupId);
829    
830                            return (List<ShoppingCategory>)QueryUtil.list(q, getDialect(),
831                                    start, end);
832                    }
833                    catch (Exception e) {
834                            throw processException(e);
835                    }
836                    finally {
837                            closeSession(session);
838                    }
839            }
840    
841            /**
842             * Finds all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
843             *
844             * @param groupId the group id to search with
845             * @param parentCategoryId the parent category id to search with
846             * @return the matching shopping categories
847             * @throws SystemException if a system exception occurred
848             */
849            public List<ShoppingCategory> findByG_P(long groupId, long parentCategoryId)
850                    throws SystemException {
851                    return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
852                            QueryUtil.ALL_POS, null);
853            }
854    
855            /**
856             * Finds a range of all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
857             *
858             * <p>
859             * 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.
860             * </p>
861             *
862             * @param groupId the group id to search with
863             * @param parentCategoryId the parent category id to search with
864             * @param start the lower bound of the range of shopping categories to return
865             * @param end the upper bound of the range of shopping categories to return (not inclusive)
866             * @return the range of matching shopping categories
867             * @throws SystemException if a system exception occurred
868             */
869            public List<ShoppingCategory> findByG_P(long groupId,
870                    long parentCategoryId, int start, int end) throws SystemException {
871                    return findByG_P(groupId, parentCategoryId, start, end, null);
872            }
873    
874            /**
875             * Finds an ordered range of all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
876             *
877             * <p>
878             * 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.
879             * </p>
880             *
881             * @param groupId the group id to search with
882             * @param parentCategoryId the parent category id to search with
883             * @param start the lower bound of the range of shopping categories to return
884             * @param end the upper bound of the range of shopping categories to return (not inclusive)
885             * @param orderByComparator the comparator to order the results by
886             * @return the ordered range of matching shopping categories
887             * @throws SystemException if a system exception occurred
888             */
889            public List<ShoppingCategory> findByG_P(long groupId,
890                    long parentCategoryId, int start, int end,
891                    OrderByComparator orderByComparator) throws SystemException {
892                    Object[] finderArgs = new Object[] {
893                                    groupId, parentCategoryId,
894                                    
895                                    String.valueOf(start), String.valueOf(end),
896                                    String.valueOf(orderByComparator)
897                            };
898    
899                    List<ShoppingCategory> list = (List<ShoppingCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
900                                    finderArgs, this);
901    
902                    if (list == null) {
903                            Session session = null;
904    
905                            try {
906                                    session = openSession();
907    
908                                    StringBundler query = null;
909    
910                                    if (orderByComparator != null) {
911                                            query = new StringBundler(4 +
912                                                            (orderByComparator.getOrderByFields().length * 3));
913                                    }
914                                    else {
915                                            query = new StringBundler(4);
916                                    }
917    
918                                    query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
919    
920                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
921    
922                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
923    
924                                    if (orderByComparator != null) {
925                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
926                                                    orderByComparator);
927                                    }
928    
929                                    else {
930                                            query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
931                                    }
932    
933                                    String sql = query.toString();
934    
935                                    Query q = session.createQuery(sql);
936    
937                                    QueryPos qPos = QueryPos.getInstance(q);
938    
939                                    qPos.add(groupId);
940    
941                                    qPos.add(parentCategoryId);
942    
943                                    list = (List<ShoppingCategory>)QueryUtil.list(q, getDialect(),
944                                                    start, end);
945                            }
946                            catch (Exception e) {
947                                    throw processException(e);
948                            }
949                            finally {
950                                    if (list == null) {
951                                            list = new ArrayList<ShoppingCategory>();
952                                    }
953    
954                                    cacheResult(list);
955    
956                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
957                                            list);
958    
959                                    closeSession(session);
960                            }
961                    }
962    
963                    return list;
964            }
965    
966            /**
967             * Finds the first shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
968             *
969             * <p>
970             * 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.
971             * </p>
972             *
973             * @param groupId the group id to search with
974             * @param parentCategoryId the parent category id to search with
975             * @param orderByComparator the comparator to order the set by
976             * @return the first matching shopping category
977             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
978             * @throws SystemException if a system exception occurred
979             */
980            public ShoppingCategory findByG_P_First(long groupId,
981                    long parentCategoryId, OrderByComparator orderByComparator)
982                    throws NoSuchCategoryException, SystemException {
983                    List<ShoppingCategory> list = findByG_P(groupId, parentCategoryId, 0,
984                                    1, orderByComparator);
985    
986                    if (list.isEmpty()) {
987                            StringBundler msg = new StringBundler(6);
988    
989                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
990    
991                            msg.append("groupId=");
992                            msg.append(groupId);
993    
994                            msg.append(", parentCategoryId=");
995                            msg.append(parentCategoryId);
996    
997                            msg.append(StringPool.CLOSE_CURLY_BRACE);
998    
999                            throw new NoSuchCategoryException(msg.toString());
1000                    }
1001                    else {
1002                            return list.get(0);
1003                    }
1004            }
1005    
1006            /**
1007             * Finds the last shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1008             *
1009             * <p>
1010             * 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.
1011             * </p>
1012             *
1013             * @param groupId the group id to search with
1014             * @param parentCategoryId the parent category id to search with
1015             * @param orderByComparator the comparator to order the set by
1016             * @return the last matching shopping category
1017             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
1018             * @throws SystemException if a system exception occurred
1019             */
1020            public ShoppingCategory findByG_P_Last(long groupId, long parentCategoryId,
1021                    OrderByComparator orderByComparator)
1022                    throws NoSuchCategoryException, SystemException {
1023                    int count = countByG_P(groupId, parentCategoryId);
1024    
1025                    List<ShoppingCategory> list = findByG_P(groupId, parentCategoryId,
1026                                    count - 1, count, orderByComparator);
1027    
1028                    if (list.isEmpty()) {
1029                            StringBundler msg = new StringBundler(6);
1030    
1031                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1032    
1033                            msg.append("groupId=");
1034                            msg.append(groupId);
1035    
1036                            msg.append(", parentCategoryId=");
1037                            msg.append(parentCategoryId);
1038    
1039                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1040    
1041                            throw new NoSuchCategoryException(msg.toString());
1042                    }
1043                    else {
1044                            return list.get(0);
1045                    }
1046            }
1047    
1048            /**
1049             * Finds the shopping categories before and after the current shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1050             *
1051             * <p>
1052             * 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.
1053             * </p>
1054             *
1055             * @param categoryId the primary key of the current shopping category
1056             * @param groupId the group id to search with
1057             * @param parentCategoryId the parent category id to search with
1058             * @param orderByComparator the comparator to order the set by
1059             * @return the previous, current, and next shopping category
1060             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
1061             * @throws SystemException if a system exception occurred
1062             */
1063            public ShoppingCategory[] findByG_P_PrevAndNext(long categoryId,
1064                    long groupId, long parentCategoryId, OrderByComparator orderByComparator)
1065                    throws NoSuchCategoryException, SystemException {
1066                    ShoppingCategory shoppingCategory = findByPrimaryKey(categoryId);
1067    
1068                    Session session = null;
1069    
1070                    try {
1071                            session = openSession();
1072    
1073                            ShoppingCategory[] array = new ShoppingCategoryImpl[3];
1074    
1075                            array[0] = getByG_P_PrevAndNext(session, shoppingCategory, groupId,
1076                                            parentCategoryId, orderByComparator, true);
1077    
1078                            array[1] = shoppingCategory;
1079    
1080                            array[2] = getByG_P_PrevAndNext(session, shoppingCategory, groupId,
1081                                            parentCategoryId, orderByComparator, false);
1082    
1083                            return array;
1084                    }
1085                    catch (Exception e) {
1086                            throw processException(e);
1087                    }
1088                    finally {
1089                            closeSession(session);
1090                    }
1091            }
1092    
1093            protected ShoppingCategory getByG_P_PrevAndNext(Session session,
1094                    ShoppingCategory shoppingCategory, long groupId, long parentCategoryId,
1095                    OrderByComparator orderByComparator, boolean previous) {
1096                    StringBundler query = null;
1097    
1098                    if (orderByComparator != null) {
1099                            query = new StringBundler(6 +
1100                                            (orderByComparator.getOrderByFields().length * 6));
1101                    }
1102                    else {
1103                            query = new StringBundler(3);
1104                    }
1105    
1106                    query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
1107    
1108                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1109    
1110                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1111    
1112                    if (orderByComparator != null) {
1113                            String[] orderByFields = orderByComparator.getOrderByFields();
1114    
1115                            if (orderByFields.length > 0) {
1116                                    query.append(WHERE_AND);
1117                            }
1118    
1119                            for (int i = 0; i < orderByFields.length; i++) {
1120                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1121                                    query.append(orderByFields[i]);
1122    
1123                                    if ((i + 1) < orderByFields.length) {
1124                                            if (orderByComparator.isAscending() ^ previous) {
1125                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1126                                            }
1127                                            else {
1128                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1129                                            }
1130                                    }
1131                                    else {
1132                                            if (orderByComparator.isAscending() ^ previous) {
1133                                                    query.append(WHERE_GREATER_THAN);
1134                                            }
1135                                            else {
1136                                                    query.append(WHERE_LESSER_THAN);
1137                                            }
1138                                    }
1139                            }
1140    
1141                            query.append(ORDER_BY_CLAUSE);
1142    
1143                            for (int i = 0; i < orderByFields.length; i++) {
1144                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1145                                    query.append(orderByFields[i]);
1146    
1147                                    if ((i + 1) < orderByFields.length) {
1148                                            if (orderByComparator.isAscending() ^ previous) {
1149                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1150                                            }
1151                                            else {
1152                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1153                                            }
1154                                    }
1155                                    else {
1156                                            if (orderByComparator.isAscending() ^ previous) {
1157                                                    query.append(ORDER_BY_ASC);
1158                                            }
1159                                            else {
1160                                                    query.append(ORDER_BY_DESC);
1161                                            }
1162                                    }
1163                            }
1164                    }
1165    
1166                    else {
1167                            query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
1168                    }
1169    
1170                    String sql = query.toString();
1171    
1172                    Query q = session.createQuery(sql);
1173    
1174                    q.setFirstResult(0);
1175                    q.setMaxResults(2);
1176    
1177                    QueryPos qPos = QueryPos.getInstance(q);
1178    
1179                    qPos.add(groupId);
1180    
1181                    qPos.add(parentCategoryId);
1182    
1183                    if (orderByComparator != null) {
1184                            Object[] values = orderByComparator.getOrderByValues(shoppingCategory);
1185    
1186                            for (Object value : values) {
1187                                    qPos.add(value);
1188                            }
1189                    }
1190    
1191                    List<ShoppingCategory> list = q.list();
1192    
1193                    if (list.size() == 2) {
1194                            return list.get(1);
1195                    }
1196                    else {
1197                            return null;
1198                    }
1199            }
1200    
1201            /**
1202             * Filters by the user's permissions and finds all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1203             *
1204             * @param groupId the group id to search with
1205             * @param parentCategoryId the parent category id to search with
1206             * @return the matching shopping categories that the user has permission to view
1207             * @throws SystemException if a system exception occurred
1208             */
1209            public List<ShoppingCategory> filterFindByG_P(long groupId,
1210                    long parentCategoryId) throws SystemException {
1211                    return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
1212                            QueryUtil.ALL_POS, null);
1213            }
1214    
1215            /**
1216             * Filters by the user's permissions and finds a range of all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1217             *
1218             * <p>
1219             * 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.
1220             * </p>
1221             *
1222             * @param groupId the group id to search with
1223             * @param parentCategoryId the parent category id to search with
1224             * @param start the lower bound of the range of shopping categories to return
1225             * @param end the upper bound of the range of shopping categories to return (not inclusive)
1226             * @return the range of matching shopping categories that the user has permission to view
1227             * @throws SystemException if a system exception occurred
1228             */
1229            public List<ShoppingCategory> filterFindByG_P(long groupId,
1230                    long parentCategoryId, int start, int end) throws SystemException {
1231                    return filterFindByG_P(groupId, parentCategoryId, start, end, null);
1232            }
1233    
1234            /**
1235             * Filters by the user's permissions and finds an ordered range of all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1236             *
1237             * <p>
1238             * 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.
1239             * </p>
1240             *
1241             * @param groupId the group id to search with
1242             * @param parentCategoryId the parent category id to search with
1243             * @param start the lower bound of the range of shopping categories to return
1244             * @param end the upper bound of the range of shopping categories to return (not inclusive)
1245             * @param orderByComparator the comparator to order the results by
1246             * @return the ordered range of matching shopping categories that the user has permission to view
1247             * @throws SystemException if a system exception occurred
1248             */
1249            public List<ShoppingCategory> filterFindByG_P(long groupId,
1250                    long parentCategoryId, int start, int end,
1251                    OrderByComparator orderByComparator) throws SystemException {
1252                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1253                            return findByG_P(groupId, parentCategoryId, start, end,
1254                                    orderByComparator);
1255                    }
1256    
1257                    Session session = null;
1258    
1259                    try {
1260                            session = openSession();
1261    
1262                            StringBundler query = null;
1263    
1264                            if (orderByComparator != null) {
1265                                    query = new StringBundler(4 +
1266                                                    (orderByComparator.getOrderByFields().length * 3));
1267                            }
1268                            else {
1269                                    query = new StringBundler(4);
1270                            }
1271    
1272                            if (getDB().isSupportsInlineDistinct()) {
1273                                    query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
1274                            }
1275                            else {
1276                                    query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE);
1277                            }
1278    
1279                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1280    
1281                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1282    
1283                            if (orderByComparator != null) {
1284                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1285                                            orderByComparator);
1286                            }
1287    
1288                            else {
1289                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
1290                            }
1291    
1292                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1293                                            ShoppingCategory.class.getName(), _FILTER_COLUMN_PK,
1294                                            _FILTER_COLUMN_USERID, groupId);
1295    
1296                            SQLQuery q = session.createSQLQuery(sql);
1297    
1298                            q.addEntity(_FILTER_ENTITY_ALIAS, ShoppingCategoryImpl.class);
1299    
1300                            QueryPos qPos = QueryPos.getInstance(q);
1301    
1302                            qPos.add(groupId);
1303    
1304                            qPos.add(parentCategoryId);
1305    
1306                            return (List<ShoppingCategory>)QueryUtil.list(q, getDialect(),
1307                                    start, end);
1308                    }
1309                    catch (Exception e) {
1310                            throw processException(e);
1311                    }
1312                    finally {
1313                            closeSession(session);
1314                    }
1315            }
1316    
1317            /**
1318             * Finds all the shopping categories.
1319             *
1320             * @return the shopping categories
1321             * @throws SystemException if a system exception occurred
1322             */
1323            public List<ShoppingCategory> findAll() throws SystemException {
1324                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1325            }
1326    
1327            /**
1328             * Finds a range of all the shopping categories.
1329             *
1330             * <p>
1331             * 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.
1332             * </p>
1333             *
1334             * @param start the lower bound of the range of shopping categories to return
1335             * @param end the upper bound of the range of shopping categories to return (not inclusive)
1336             * @return the range of shopping categories
1337             * @throws SystemException if a system exception occurred
1338             */
1339            public List<ShoppingCategory> findAll(int start, int end)
1340                    throws SystemException {
1341                    return findAll(start, end, null);
1342            }
1343    
1344            /**
1345             * Finds an ordered range of all the shopping categories.
1346             *
1347             * <p>
1348             * 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.
1349             * </p>
1350             *
1351             * @param start the lower bound of the range of shopping categories to return
1352             * @param end the upper bound of the range of shopping categories to return (not inclusive)
1353             * @param orderByComparator the comparator to order the results by
1354             * @return the ordered range of shopping categories
1355             * @throws SystemException if a system exception occurred
1356             */
1357            public List<ShoppingCategory> findAll(int start, int end,
1358                    OrderByComparator orderByComparator) throws SystemException {
1359                    Object[] finderArgs = new Object[] {
1360                                    String.valueOf(start), String.valueOf(end),
1361                                    String.valueOf(orderByComparator)
1362                            };
1363    
1364                    List<ShoppingCategory> list = (List<ShoppingCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1365                                    finderArgs, this);
1366    
1367                    if (list == null) {
1368                            Session session = null;
1369    
1370                            try {
1371                                    session = openSession();
1372    
1373                                    StringBundler query = null;
1374                                    String sql = null;
1375    
1376                                    if (orderByComparator != null) {
1377                                            query = new StringBundler(2 +
1378                                                            (orderByComparator.getOrderByFields().length * 3));
1379    
1380                                            query.append(_SQL_SELECT_SHOPPINGCATEGORY);
1381    
1382                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1383                                                    orderByComparator);
1384    
1385                                            sql = query.toString();
1386                                    }
1387                                    else {
1388                                            sql = _SQL_SELECT_SHOPPINGCATEGORY.concat(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
1389                                    }
1390    
1391                                    Query q = session.createQuery(sql);
1392    
1393                                    if (orderByComparator == null) {
1394                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
1395                                                            getDialect(), start, end, false);
1396    
1397                                            Collections.sort(list);
1398                                    }
1399                                    else {
1400                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
1401                                                            getDialect(), start, end);
1402                                    }
1403                            }
1404                            catch (Exception e) {
1405                                    throw processException(e);
1406                            }
1407                            finally {
1408                                    if (list == null) {
1409                                            list = new ArrayList<ShoppingCategory>();
1410                                    }
1411    
1412                                    cacheResult(list);
1413    
1414                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1415    
1416                                    closeSession(session);
1417                            }
1418                    }
1419    
1420                    return list;
1421            }
1422    
1423            /**
1424             * Removes all the shopping categories where groupId = &#63; from the database.
1425             *
1426             * @param groupId the group id to search with
1427             * @throws SystemException if a system exception occurred
1428             */
1429            public void removeByGroupId(long groupId) throws SystemException {
1430                    for (ShoppingCategory shoppingCategory : findByGroupId(groupId)) {
1431                            remove(shoppingCategory);
1432                    }
1433            }
1434    
1435            /**
1436             * Removes all the shopping categories where groupId = &#63; and parentCategoryId = &#63; from the database.
1437             *
1438             * @param groupId the group id to search with
1439             * @param parentCategoryId the parent category id to search with
1440             * @throws SystemException if a system exception occurred
1441             */
1442            public void removeByG_P(long groupId, long parentCategoryId)
1443                    throws SystemException {
1444                    for (ShoppingCategory shoppingCategory : findByG_P(groupId,
1445                                    parentCategoryId)) {
1446                            remove(shoppingCategory);
1447                    }
1448            }
1449    
1450            /**
1451             * Removes all the shopping categories from the database.
1452             *
1453             * @throws SystemException if a system exception occurred
1454             */
1455            public void removeAll() throws SystemException {
1456                    for (ShoppingCategory shoppingCategory : findAll()) {
1457                            remove(shoppingCategory);
1458                    }
1459            }
1460    
1461            /**
1462             * Counts all the shopping categories where groupId = &#63;.
1463             *
1464             * @param groupId the group id to search with
1465             * @return the number of matching shopping categories
1466             * @throws SystemException if a system exception occurred
1467             */
1468            public int countByGroupId(long groupId) throws SystemException {
1469                    Object[] finderArgs = new Object[] { groupId };
1470    
1471                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1472                                    finderArgs, this);
1473    
1474                    if (count == null) {
1475                            Session session = null;
1476    
1477                            try {
1478                                    session = openSession();
1479    
1480                                    StringBundler query = new StringBundler(2);
1481    
1482                                    query.append(_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
1483    
1484                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1485    
1486                                    String sql = query.toString();
1487    
1488                                    Query q = session.createQuery(sql);
1489    
1490                                    QueryPos qPos = QueryPos.getInstance(q);
1491    
1492                                    qPos.add(groupId);
1493    
1494                                    count = (Long)q.uniqueResult();
1495                            }
1496                            catch (Exception e) {
1497                                    throw processException(e);
1498                            }
1499                            finally {
1500                                    if (count == null) {
1501                                            count = Long.valueOf(0);
1502                                    }
1503    
1504                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1505                                            finderArgs, count);
1506    
1507                                    closeSession(session);
1508                            }
1509                    }
1510    
1511                    return count.intValue();
1512            }
1513    
1514            /**
1515             * Filters by the user's permissions and counts all the shopping categories where groupId = &#63;.
1516             *
1517             * @param groupId the group id to search with
1518             * @return the number of matching shopping categories that the user has permission to view
1519             * @throws SystemException if a system exception occurred
1520             */
1521            public int filterCountByGroupId(long groupId) throws SystemException {
1522                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1523                            return countByGroupId(groupId);
1524                    }
1525    
1526                    Session session = null;
1527    
1528                    try {
1529                            session = openSession();
1530    
1531                            StringBundler query = new StringBundler(2);
1532    
1533                            query.append(_FILTER_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
1534    
1535                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1536    
1537                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1538                                            ShoppingCategory.class.getName(), _FILTER_COLUMN_PK,
1539                                            _FILTER_COLUMN_USERID, groupId);
1540    
1541                            SQLQuery q = session.createSQLQuery(sql);
1542    
1543                            q.addScalar(COUNT_COLUMN_NAME,
1544                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1545    
1546                            QueryPos qPos = QueryPos.getInstance(q);
1547    
1548                            qPos.add(groupId);
1549    
1550                            Long count = (Long)q.uniqueResult();
1551    
1552                            return count.intValue();
1553                    }
1554                    catch (Exception e) {
1555                            throw processException(e);
1556                    }
1557                    finally {
1558                            closeSession(session);
1559                    }
1560            }
1561    
1562            /**
1563             * Counts all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1564             *
1565             * @param groupId the group id to search with
1566             * @param parentCategoryId the parent category id to search with
1567             * @return the number of matching shopping categories
1568             * @throws SystemException if a system exception occurred
1569             */
1570            public int countByG_P(long groupId, long parentCategoryId)
1571                    throws SystemException {
1572                    Object[] finderArgs = new Object[] { groupId, parentCategoryId };
1573    
1574                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
1575                                    finderArgs, this);
1576    
1577                    if (count == null) {
1578                            Session session = null;
1579    
1580                            try {
1581                                    session = openSession();
1582    
1583                                    StringBundler query = new StringBundler(3);
1584    
1585                                    query.append(_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
1586    
1587                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1588    
1589                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1590    
1591                                    String sql = query.toString();
1592    
1593                                    Query q = session.createQuery(sql);
1594    
1595                                    QueryPos qPos = QueryPos.getInstance(q);
1596    
1597                                    qPos.add(groupId);
1598    
1599                                    qPos.add(parentCategoryId);
1600    
1601                                    count = (Long)q.uniqueResult();
1602                            }
1603                            catch (Exception e) {
1604                                    throw processException(e);
1605                            }
1606                            finally {
1607                                    if (count == null) {
1608                                            count = Long.valueOf(0);
1609                                    }
1610    
1611                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
1612                                            count);
1613    
1614                                    closeSession(session);
1615                            }
1616                    }
1617    
1618                    return count.intValue();
1619            }
1620    
1621            /**
1622             * Filters by the user's permissions and counts all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1623             *
1624             * @param groupId the group id to search with
1625             * @param parentCategoryId the parent category id to search with
1626             * @return the number of matching shopping categories that the user has permission to view
1627             * @throws SystemException if a system exception occurred
1628             */
1629            public int filterCountByG_P(long groupId, long parentCategoryId)
1630                    throws SystemException {
1631                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1632                            return countByG_P(groupId, parentCategoryId);
1633                    }
1634    
1635                    Session session = null;
1636    
1637                    try {
1638                            session = openSession();
1639    
1640                            StringBundler query = new StringBundler(3);
1641    
1642                            query.append(_FILTER_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
1643    
1644                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1645    
1646                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1647    
1648                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1649                                            ShoppingCategory.class.getName(), _FILTER_COLUMN_PK,
1650                                            _FILTER_COLUMN_USERID, groupId);
1651    
1652                            SQLQuery q = session.createSQLQuery(sql);
1653    
1654                            q.addScalar(COUNT_COLUMN_NAME,
1655                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1656    
1657                            QueryPos qPos = QueryPos.getInstance(q);
1658    
1659                            qPos.add(groupId);
1660    
1661                            qPos.add(parentCategoryId);
1662    
1663                            Long count = (Long)q.uniqueResult();
1664    
1665                            return count.intValue();
1666                    }
1667                    catch (Exception e) {
1668                            throw processException(e);
1669                    }
1670                    finally {
1671                            closeSession(session);
1672                    }
1673            }
1674    
1675            /**
1676             * Counts all the shopping categories.
1677             *
1678             * @return the number of shopping categories
1679             * @throws SystemException if a system exception occurred
1680             */
1681            public int countAll() throws SystemException {
1682                    Object[] finderArgs = new Object[0];
1683    
1684                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1685                                    finderArgs, this);
1686    
1687                    if (count == null) {
1688                            Session session = null;
1689    
1690                            try {
1691                                    session = openSession();
1692    
1693                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGCATEGORY);
1694    
1695                                    count = (Long)q.uniqueResult();
1696                            }
1697                            catch (Exception e) {
1698                                    throw processException(e);
1699                            }
1700                            finally {
1701                                    if (count == null) {
1702                                            count = Long.valueOf(0);
1703                                    }
1704    
1705                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1706                                            count);
1707    
1708                                    closeSession(session);
1709                            }
1710                    }
1711    
1712                    return count.intValue();
1713            }
1714    
1715            /**
1716             * Initializes the shopping category persistence.
1717             */
1718            public void afterPropertiesSet() {
1719                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1720                                            com.liferay.portal.util.PropsUtil.get(
1721                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingCategory")));
1722    
1723                    if (listenerClassNames.length > 0) {
1724                            try {
1725                                    List<ModelListener<ShoppingCategory>> listenersList = new ArrayList<ModelListener<ShoppingCategory>>();
1726    
1727                                    for (String listenerClassName : listenerClassNames) {
1728                                            listenersList.add((ModelListener<ShoppingCategory>)InstanceFactory.newInstance(
1729                                                            listenerClassName));
1730                                    }
1731    
1732                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1733                            }
1734                            catch (Exception e) {
1735                                    _log.error(e);
1736                            }
1737                    }
1738            }
1739    
1740            public void destroy() {
1741                    EntityCacheUtil.removeCache(ShoppingCategoryImpl.class.getName());
1742                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1743                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1744            }
1745    
1746            @BeanReference(type = ShoppingCartPersistence.class)
1747            protected ShoppingCartPersistence shoppingCartPersistence;
1748            @BeanReference(type = ShoppingCategoryPersistence.class)
1749            protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1750            @BeanReference(type = ShoppingCouponPersistence.class)
1751            protected ShoppingCouponPersistence shoppingCouponPersistence;
1752            @BeanReference(type = ShoppingItemPersistence.class)
1753            protected ShoppingItemPersistence shoppingItemPersistence;
1754            @BeanReference(type = ShoppingItemFieldPersistence.class)
1755            protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1756            @BeanReference(type = ShoppingItemPricePersistence.class)
1757            protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1758            @BeanReference(type = ShoppingOrderPersistence.class)
1759            protected ShoppingOrderPersistence shoppingOrderPersistence;
1760            @BeanReference(type = ShoppingOrderItemPersistence.class)
1761            protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1762            @BeanReference(type = ResourcePersistence.class)
1763            protected ResourcePersistence resourcePersistence;
1764            @BeanReference(type = UserPersistence.class)
1765            protected UserPersistence userPersistence;
1766            private static final String _SQL_SELECT_SHOPPINGCATEGORY = "SELECT shoppingCategory FROM ShoppingCategory shoppingCategory";
1767            private static final String _SQL_SELECT_SHOPPINGCATEGORY_WHERE = "SELECT shoppingCategory FROM ShoppingCategory shoppingCategory WHERE ";
1768            private static final String _SQL_COUNT_SHOPPINGCATEGORY = "SELECT COUNT(shoppingCategory) FROM ShoppingCategory shoppingCategory";
1769            private static final String _SQL_COUNT_SHOPPINGCATEGORY_WHERE = "SELECT COUNT(shoppingCategory) FROM ShoppingCategory shoppingCategory WHERE ";
1770            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "shoppingCategory.groupId = ?";
1771            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "shoppingCategory.groupId = ? AND ";
1772            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "shoppingCategory.parentCategoryId = ?";
1773            private static final String _FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE = "SELECT DISTINCT {shoppingCategory.*} FROM ShoppingCategory shoppingCategory WHERE ";
1774            private static final String _FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE =
1775                    "SELECT {shoppingCategory.*} FROM (SELECT DISTINCT categoryId FROM ShoppingCategory) shoppingCategory2 INNER JOIN ShoppingCategory shoppingCategory ON (shoppingCategory2.categoryId = shoppingCategory.categoryId) WHERE ";
1776            private static final String _FILTER_SQL_COUNT_SHOPPINGCATEGORY_WHERE = "SELECT COUNT(DISTINCT shoppingCategory.categoryId) AS COUNT_VALUE FROM ShoppingCategory shoppingCategory WHERE ";
1777            private static final String _FILTER_COLUMN_PK = "shoppingCategory.categoryId";
1778            private static final String _FILTER_COLUMN_USERID = "shoppingCategory.userId";
1779            private static final String _FILTER_ENTITY_ALIAS = "shoppingCategory";
1780            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingCategory.";
1781            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingCategory exists with the primary key ";
1782            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingCategory exists with the key {";
1783            private static Log _log = LogFactoryUtil.getLog(ShoppingCategoryPersistenceImpl.class);
1784    }