001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.shopping.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
039    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040    
041    import com.liferay.portlet.shopping.NoSuchCategoryException;
042    import com.liferay.portlet.shopping.model.ShoppingCategory;
043    import com.liferay.portlet.shopping.model.impl.ShoppingCategoryImpl;
044    import com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.List;
051    
052    /**
053     * The persistence implementation for the shopping category service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see ShoppingCategoryPersistence
061     * @see ShoppingCategoryUtil
062     * @generated
063     */
064    public class ShoppingCategoryPersistenceImpl extends BasePersistenceImpl<ShoppingCategory>
065            implements ShoppingCategoryPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * 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.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = ShoppingCategoryImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
077                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
078                            ShoppingCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
079                            "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
081                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
082                            ShoppingCategoryImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
085                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
088                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
089                            ShoppingCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090                            "findByGroupId",
091                            new String[] {
092                                    Long.class.getName(),
093                                    
094                            Integer.class.getName(), Integer.class.getName(),
095                                    OrderByComparator.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
098                    new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
099                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
100                            ShoppingCategoryImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
102                            new String[] { Long.class.getName() },
103                            ShoppingCategoryModelImpl.GROUPID_COLUMN_BITMASK |
104                            ShoppingCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
105                            ShoppingCategoryModelImpl.NAME_COLUMN_BITMASK);
106            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
107                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
109                            new String[] { Long.class.getName() });
110    
111            /**
112             * Returns all the shopping categories where groupId = &#63;.
113             *
114             * @param groupId the group ID
115             * @return the matching shopping categories
116             * @throws SystemException if a system exception occurred
117             */
118            @Override
119            public List<ShoppingCategory> findByGroupId(long groupId)
120                    throws SystemException {
121                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the shopping categories where groupId = &#63;.
126             *
127             * <p>
128             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
129             * </p>
130             *
131             * @param groupId the group ID
132             * @param start the lower bound of the range of shopping categories
133             * @param end the upper bound of the range of shopping categories (not inclusive)
134             * @return the range of matching shopping categories
135             * @throws SystemException if a system exception occurred
136             */
137            @Override
138            public List<ShoppingCategory> findByGroupId(long groupId, int start, int end)
139                    throws SystemException {
140                    return findByGroupId(groupId, start, end, null);
141            }
142    
143            /**
144             * Returns an ordered range of all the shopping categories where groupId = &#63;.
145             *
146             * <p>
147             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
148             * </p>
149             *
150             * @param groupId the group ID
151             * @param start the lower bound of the range of shopping categories
152             * @param end the upper bound of the range of shopping categories (not inclusive)
153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
154             * @return the ordered range of matching shopping categories
155             * @throws SystemException if a system exception occurred
156             */
157            @Override
158            public List<ShoppingCategory> findByGroupId(long groupId, int start,
159                    int end, OrderByComparator orderByComparator) throws SystemException {
160                    boolean pagination = true;
161                    FinderPath finderPath = null;
162                    Object[] finderArgs = null;
163    
164                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165                                    (orderByComparator == null)) {
166                            pagination = false;
167                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
168                            finderArgs = new Object[] { groupId };
169                    }
170                    else {
171                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
172                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
173                    }
174    
175                    List<ShoppingCategory> list = (List<ShoppingCategory>)FinderCacheUtil.getResult(finderPath,
176                                    finderArgs, this);
177    
178                    if ((list != null) && !list.isEmpty()) {
179                            for (ShoppingCategory shoppingCategory : list) {
180                                    if ((groupId != shoppingCategory.getGroupId())) {
181                                            list = null;
182    
183                                            break;
184                                    }
185                            }
186                    }
187    
188                    if (list == null) {
189                            StringBundler query = null;
190    
191                            if (orderByComparator != null) {
192                                    query = new StringBundler(3 +
193                                                    (orderByComparator.getOrderByFields().length * 3));
194                            }
195                            else {
196                                    query = new StringBundler(3);
197                            }
198    
199                            query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
200    
201                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
202    
203                            if (orderByComparator != null) {
204                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
205                                            orderByComparator);
206                            }
207                            else
208                             if (pagination) {
209                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
210                            }
211    
212                            String sql = query.toString();
213    
214                            Session session = null;
215    
216                            try {
217                                    session = openSession();
218    
219                                    Query q = session.createQuery(sql);
220    
221                                    QueryPos qPos = QueryPos.getInstance(q);
222    
223                                    qPos.add(groupId);
224    
225                                    if (!pagination) {
226                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
227                                                            getDialect(), start, end, false);
228    
229                                            Collections.sort(list);
230    
231                                            list = new UnmodifiableList<ShoppingCategory>(list);
232                                    }
233                                    else {
234                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
235                                                            getDialect(), start, end);
236                                    }
237    
238                                    cacheResult(list);
239    
240                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
241                            }
242                            catch (Exception e) {
243                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
244    
245                                    throw processException(e);
246                            }
247                            finally {
248                                    closeSession(session);
249                            }
250                    }
251    
252                    return list;
253            }
254    
255            /**
256             * Returns the first shopping category in the ordered set where groupId = &#63;.
257             *
258             * @param groupId the group ID
259             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
260             * @return the first matching shopping category
261             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
262             * @throws SystemException if a system exception occurred
263             */
264            @Override
265            public ShoppingCategory findByGroupId_First(long groupId,
266                    OrderByComparator orderByComparator)
267                    throws NoSuchCategoryException, SystemException {
268                    ShoppingCategory shoppingCategory = fetchByGroupId_First(groupId,
269                                    orderByComparator);
270    
271                    if (shoppingCategory != null) {
272                            return shoppingCategory;
273                    }
274    
275                    StringBundler msg = new StringBundler(4);
276    
277                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
278    
279                    msg.append("groupId=");
280                    msg.append(groupId);
281    
282                    msg.append(StringPool.CLOSE_CURLY_BRACE);
283    
284                    throw new NoSuchCategoryException(msg.toString());
285            }
286    
287            /**
288             * Returns the first shopping category in the ordered set where groupId = &#63;.
289             *
290             * @param groupId the group ID
291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
292             * @return the first matching shopping category, or <code>null</code> if a matching shopping category could not be found
293             * @throws SystemException if a system exception occurred
294             */
295            @Override
296            public ShoppingCategory fetchByGroupId_First(long groupId,
297                    OrderByComparator orderByComparator) throws SystemException {
298                    List<ShoppingCategory> list = findByGroupId(groupId, 0, 1,
299                                    orderByComparator);
300    
301                    if (!list.isEmpty()) {
302                            return list.get(0);
303                    }
304    
305                    return null;
306            }
307    
308            /**
309             * Returns the last shopping category in the ordered set where groupId = &#63;.
310             *
311             * @param groupId the group ID
312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
313             * @return the last matching shopping category
314             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
315             * @throws SystemException if a system exception occurred
316             */
317            @Override
318            public ShoppingCategory findByGroupId_Last(long groupId,
319                    OrderByComparator orderByComparator)
320                    throws NoSuchCategoryException, SystemException {
321                    ShoppingCategory shoppingCategory = fetchByGroupId_Last(groupId,
322                                    orderByComparator);
323    
324                    if (shoppingCategory != null) {
325                            return shoppingCategory;
326                    }
327    
328                    StringBundler msg = new StringBundler(4);
329    
330                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
331    
332                    msg.append("groupId=");
333                    msg.append(groupId);
334    
335                    msg.append(StringPool.CLOSE_CURLY_BRACE);
336    
337                    throw new NoSuchCategoryException(msg.toString());
338            }
339    
340            /**
341             * Returns the last shopping category in the ordered set where groupId = &#63;.
342             *
343             * @param groupId the group ID
344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
345             * @return the last matching shopping category, or <code>null</code> if a matching shopping category could not be found
346             * @throws SystemException if a system exception occurred
347             */
348            @Override
349            public ShoppingCategory fetchByGroupId_Last(long groupId,
350                    OrderByComparator orderByComparator) throws SystemException {
351                    int count = countByGroupId(groupId);
352    
353                    if (count == 0) {
354                            return null;
355                    }
356    
357                    List<ShoppingCategory> list = findByGroupId(groupId, count - 1, count,
358                                    orderByComparator);
359    
360                    if (!list.isEmpty()) {
361                            return list.get(0);
362                    }
363    
364                    return null;
365            }
366    
367            /**
368             * Returns the shopping categories before and after the current shopping category in the ordered set where groupId = &#63;.
369             *
370             * @param categoryId the primary key of the current shopping category
371             * @param groupId the group ID
372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
373             * @return the previous, current, and next shopping category
374             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
375             * @throws SystemException if a system exception occurred
376             */
377            @Override
378            public ShoppingCategory[] findByGroupId_PrevAndNext(long categoryId,
379                    long groupId, OrderByComparator orderByComparator)
380                    throws NoSuchCategoryException, SystemException {
381                    ShoppingCategory shoppingCategory = findByPrimaryKey(categoryId);
382    
383                    Session session = null;
384    
385                    try {
386                            session = openSession();
387    
388                            ShoppingCategory[] array = new ShoppingCategoryImpl[3];
389    
390                            array[0] = getByGroupId_PrevAndNext(session, shoppingCategory,
391                                            groupId, orderByComparator, true);
392    
393                            array[1] = shoppingCategory;
394    
395                            array[2] = getByGroupId_PrevAndNext(session, shoppingCategory,
396                                            groupId, orderByComparator, false);
397    
398                            return array;
399                    }
400                    catch (Exception e) {
401                            throw processException(e);
402                    }
403                    finally {
404                            closeSession(session);
405                    }
406            }
407    
408            protected ShoppingCategory getByGroupId_PrevAndNext(Session session,
409                    ShoppingCategory shoppingCategory, long groupId,
410                    OrderByComparator orderByComparator, boolean previous) {
411                    StringBundler query = null;
412    
413                    if (orderByComparator != null) {
414                            query = new StringBundler(6 +
415                                            (orderByComparator.getOrderByFields().length * 6));
416                    }
417                    else {
418                            query = new StringBundler(3);
419                    }
420    
421                    query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
422    
423                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
424    
425                    if (orderByComparator != null) {
426                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
427    
428                            if (orderByConditionFields.length > 0) {
429                                    query.append(WHERE_AND);
430                            }
431    
432                            for (int i = 0; i < orderByConditionFields.length; i++) {
433                                    query.append(_ORDER_BY_ENTITY_ALIAS);
434                                    query.append(orderByConditionFields[i]);
435    
436                                    if ((i + 1) < orderByConditionFields.length) {
437                                            if (orderByComparator.isAscending() ^ previous) {
438                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
439                                            }
440                                            else {
441                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
442                                            }
443                                    }
444                                    else {
445                                            if (orderByComparator.isAscending() ^ previous) {
446                                                    query.append(WHERE_GREATER_THAN);
447                                            }
448                                            else {
449                                                    query.append(WHERE_LESSER_THAN);
450                                            }
451                                    }
452                            }
453    
454                            query.append(ORDER_BY_CLAUSE);
455    
456                            String[] orderByFields = orderByComparator.getOrderByFields();
457    
458                            for (int i = 0; i < orderByFields.length; i++) {
459                                    query.append(_ORDER_BY_ENTITY_ALIAS);
460                                    query.append(orderByFields[i]);
461    
462                                    if ((i + 1) < orderByFields.length) {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
465                                            }
466                                            else {
467                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
468                                            }
469                                    }
470                                    else {
471                                            if (orderByComparator.isAscending() ^ previous) {
472                                                    query.append(ORDER_BY_ASC);
473                                            }
474                                            else {
475                                                    query.append(ORDER_BY_DESC);
476                                            }
477                                    }
478                            }
479                    }
480                    else {
481                            query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
482                    }
483    
484                    String sql = query.toString();
485    
486                    Query q = session.createQuery(sql);
487    
488                    q.setFirstResult(0);
489                    q.setMaxResults(2);
490    
491                    QueryPos qPos = QueryPos.getInstance(q);
492    
493                    qPos.add(groupId);
494    
495                    if (orderByComparator != null) {
496                            Object[] values = orderByComparator.getOrderByConditionValues(shoppingCategory);
497    
498                            for (Object value : values) {
499                                    qPos.add(value);
500                            }
501                    }
502    
503                    List<ShoppingCategory> list = q.list();
504    
505                    if (list.size() == 2) {
506                            return list.get(1);
507                    }
508                    else {
509                            return null;
510                    }
511            }
512    
513            /**
514             * Returns all the shopping categories that the user has permission to view where groupId = &#63;.
515             *
516             * @param groupId the group ID
517             * @return the matching shopping categories that the user has permission to view
518             * @throws SystemException if a system exception occurred
519             */
520            @Override
521            public List<ShoppingCategory> filterFindByGroupId(long groupId)
522                    throws SystemException {
523                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
524                            QueryUtil.ALL_POS, null);
525            }
526    
527            /**
528             * Returns a range of all the shopping categories that the user has permission to view where groupId = &#63;.
529             *
530             * <p>
531             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
532             * </p>
533             *
534             * @param groupId the group ID
535             * @param start the lower bound of the range of shopping categories
536             * @param end the upper bound of the range of shopping categories (not inclusive)
537             * @return the range of matching shopping categories that the user has permission to view
538             * @throws SystemException if a system exception occurred
539             */
540            @Override
541            public List<ShoppingCategory> filterFindByGroupId(long groupId, int start,
542                    int end) throws SystemException {
543                    return filterFindByGroupId(groupId, start, end, null);
544            }
545    
546            /**
547             * Returns an ordered range of all the shopping categories that the user has permissions to view where groupId = &#63;.
548             *
549             * <p>
550             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
551             * </p>
552             *
553             * @param groupId the group ID
554             * @param start the lower bound of the range of shopping categories
555             * @param end the upper bound of the range of shopping categories (not inclusive)
556             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
557             * @return the ordered range of matching shopping categories that the user has permission to view
558             * @throws SystemException if a system exception occurred
559             */
560            @Override
561            public List<ShoppingCategory> filterFindByGroupId(long groupId, int start,
562                    int end, OrderByComparator orderByComparator) throws SystemException {
563                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
564                            return findByGroupId(groupId, start, end, orderByComparator);
565                    }
566    
567                    StringBundler query = null;
568    
569                    if (orderByComparator != null) {
570                            query = new StringBundler(3 +
571                                            (orderByComparator.getOrderByFields().length * 3));
572                    }
573                    else {
574                            query = new StringBundler(3);
575                    }
576    
577                    if (getDB().isSupportsInlineDistinct()) {
578                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
579                    }
580                    else {
581                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
582                    }
583    
584                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
585    
586                    if (!getDB().isSupportsInlineDistinct()) {
587                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
588                    }
589    
590                    if (orderByComparator != null) {
591                            if (getDB().isSupportsInlineDistinct()) {
592                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
593                                            orderByComparator, true);
594                            }
595                            else {
596                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
597                                            orderByComparator, true);
598                            }
599                    }
600                    else {
601                            if (getDB().isSupportsInlineDistinct()) {
602                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
603                            }
604                            else {
605                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_SQL);
606                            }
607                    }
608    
609                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
610                                    ShoppingCategory.class.getName(),
611                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
612    
613                    Session session = null;
614    
615                    try {
616                            session = openSession();
617    
618                            SQLQuery q = session.createSQLQuery(sql);
619    
620                            if (getDB().isSupportsInlineDistinct()) {
621                                    q.addEntity(_FILTER_ENTITY_ALIAS, ShoppingCategoryImpl.class);
622                            }
623                            else {
624                                    q.addEntity(_FILTER_ENTITY_TABLE, ShoppingCategoryImpl.class);
625                            }
626    
627                            QueryPos qPos = QueryPos.getInstance(q);
628    
629                            qPos.add(groupId);
630    
631                            return (List<ShoppingCategory>)QueryUtil.list(q, getDialect(),
632                                    start, end);
633                    }
634                    catch (Exception e) {
635                            throw processException(e);
636                    }
637                    finally {
638                            closeSession(session);
639                    }
640            }
641    
642            /**
643             * Returns the shopping categories before and after the current shopping category in the ordered set of shopping categories that the user has permission to view where groupId = &#63;.
644             *
645             * @param categoryId the primary key of the current shopping category
646             * @param groupId the group ID
647             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
648             * @return the previous, current, and next shopping category
649             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
650             * @throws SystemException if a system exception occurred
651             */
652            @Override
653            public ShoppingCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
654                    long groupId, OrderByComparator orderByComparator)
655                    throws NoSuchCategoryException, SystemException {
656                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
657                            return findByGroupId_PrevAndNext(categoryId, groupId,
658                                    orderByComparator);
659                    }
660    
661                    ShoppingCategory shoppingCategory = findByPrimaryKey(categoryId);
662    
663                    Session session = null;
664    
665                    try {
666                            session = openSession();
667    
668                            ShoppingCategory[] array = new ShoppingCategoryImpl[3];
669    
670                            array[0] = filterGetByGroupId_PrevAndNext(session,
671                                            shoppingCategory, groupId, orderByComparator, true);
672    
673                            array[1] = shoppingCategory;
674    
675                            array[2] = filterGetByGroupId_PrevAndNext(session,
676                                            shoppingCategory, groupId, orderByComparator, false);
677    
678                            return array;
679                    }
680                    catch (Exception e) {
681                            throw processException(e);
682                    }
683                    finally {
684                            closeSession(session);
685                    }
686            }
687    
688            protected ShoppingCategory filterGetByGroupId_PrevAndNext(Session session,
689                    ShoppingCategory shoppingCategory, long groupId,
690                    OrderByComparator orderByComparator, boolean previous) {
691                    StringBundler query = null;
692    
693                    if (orderByComparator != null) {
694                            query = new StringBundler(6 +
695                                            (orderByComparator.getOrderByFields().length * 6));
696                    }
697                    else {
698                            query = new StringBundler(3);
699                    }
700    
701                    if (getDB().isSupportsInlineDistinct()) {
702                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
703                    }
704                    else {
705                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
706                    }
707    
708                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
709    
710                    if (!getDB().isSupportsInlineDistinct()) {
711                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
712                    }
713    
714                    if (orderByComparator != null) {
715                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
716    
717                            if (orderByConditionFields.length > 0) {
718                                    query.append(WHERE_AND);
719                            }
720    
721                            for (int i = 0; i < orderByConditionFields.length; i++) {
722                                    if (getDB().isSupportsInlineDistinct()) {
723                                            query.append(_ORDER_BY_ENTITY_ALIAS);
724                                    }
725                                    else {
726                                            query.append(_ORDER_BY_ENTITY_TABLE);
727                                    }
728    
729                                    query.append(orderByConditionFields[i]);
730    
731                                    if ((i + 1) < orderByConditionFields.length) {
732                                            if (orderByComparator.isAscending() ^ previous) {
733                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
734                                            }
735                                            else {
736                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
737                                            }
738                                    }
739                                    else {
740                                            if (orderByComparator.isAscending() ^ previous) {
741                                                    query.append(WHERE_GREATER_THAN);
742                                            }
743                                            else {
744                                                    query.append(WHERE_LESSER_THAN);
745                                            }
746                                    }
747                            }
748    
749                            query.append(ORDER_BY_CLAUSE);
750    
751                            String[] orderByFields = orderByComparator.getOrderByFields();
752    
753                            for (int i = 0; i < orderByFields.length; i++) {
754                                    if (getDB().isSupportsInlineDistinct()) {
755                                            query.append(_ORDER_BY_ENTITY_ALIAS);
756                                    }
757                                    else {
758                                            query.append(_ORDER_BY_ENTITY_TABLE);
759                                    }
760    
761                                    query.append(orderByFields[i]);
762    
763                                    if ((i + 1) < orderByFields.length) {
764                                            if (orderByComparator.isAscending() ^ previous) {
765                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
766                                            }
767                                            else {
768                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
769                                            }
770                                    }
771                                    else {
772                                            if (orderByComparator.isAscending() ^ previous) {
773                                                    query.append(ORDER_BY_ASC);
774                                            }
775                                            else {
776                                                    query.append(ORDER_BY_DESC);
777                                            }
778                                    }
779                            }
780                    }
781                    else {
782                            if (getDB().isSupportsInlineDistinct()) {
783                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
784                            }
785                            else {
786                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_SQL);
787                            }
788                    }
789    
790                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
791                                    ShoppingCategory.class.getName(),
792                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
793    
794                    SQLQuery q = session.createSQLQuery(sql);
795    
796                    q.setFirstResult(0);
797                    q.setMaxResults(2);
798    
799                    if (getDB().isSupportsInlineDistinct()) {
800                            q.addEntity(_FILTER_ENTITY_ALIAS, ShoppingCategoryImpl.class);
801                    }
802                    else {
803                            q.addEntity(_FILTER_ENTITY_TABLE, ShoppingCategoryImpl.class);
804                    }
805    
806                    QueryPos qPos = QueryPos.getInstance(q);
807    
808                    qPos.add(groupId);
809    
810                    if (orderByComparator != null) {
811                            Object[] values = orderByComparator.getOrderByConditionValues(shoppingCategory);
812    
813                            for (Object value : values) {
814                                    qPos.add(value);
815                            }
816                    }
817    
818                    List<ShoppingCategory> list = q.list();
819    
820                    if (list.size() == 2) {
821                            return list.get(1);
822                    }
823                    else {
824                            return null;
825                    }
826            }
827    
828            /**
829             * Removes all the shopping categories where groupId = &#63; from the database.
830             *
831             * @param groupId the group ID
832             * @throws SystemException if a system exception occurred
833             */
834            @Override
835            public void removeByGroupId(long groupId) throws SystemException {
836                    for (ShoppingCategory shoppingCategory : findByGroupId(groupId,
837                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
838                            remove(shoppingCategory);
839                    }
840            }
841    
842            /**
843             * Returns the number of shopping categories where groupId = &#63;.
844             *
845             * @param groupId the group ID
846             * @return the number of matching shopping categories
847             * @throws SystemException if a system exception occurred
848             */
849            @Override
850            public int countByGroupId(long groupId) throws SystemException {
851                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
852    
853                    Object[] finderArgs = new Object[] { groupId };
854    
855                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
856                                    this);
857    
858                    if (count == null) {
859                            StringBundler query = new StringBundler(2);
860    
861                            query.append(_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
862    
863                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
864    
865                            String sql = query.toString();
866    
867                            Session session = null;
868    
869                            try {
870                                    session = openSession();
871    
872                                    Query q = session.createQuery(sql);
873    
874                                    QueryPos qPos = QueryPos.getInstance(q);
875    
876                                    qPos.add(groupId);
877    
878                                    count = (Long)q.uniqueResult();
879    
880                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
881                            }
882                            catch (Exception e) {
883                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
884    
885                                    throw processException(e);
886                            }
887                            finally {
888                                    closeSession(session);
889                            }
890                    }
891    
892                    return count.intValue();
893            }
894    
895            /**
896             * Returns the number of shopping categories that the user has permission to view where groupId = &#63;.
897             *
898             * @param groupId the group ID
899             * @return the number of matching shopping categories that the user has permission to view
900             * @throws SystemException if a system exception occurred
901             */
902            @Override
903            public int filterCountByGroupId(long groupId) throws SystemException {
904                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
905                            return countByGroupId(groupId);
906                    }
907    
908                    StringBundler query = new StringBundler(2);
909    
910                    query.append(_FILTER_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
911    
912                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
913    
914                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
915                                    ShoppingCategory.class.getName(),
916                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
917    
918                    Session session = null;
919    
920                    try {
921                            session = openSession();
922    
923                            SQLQuery q = session.createSQLQuery(sql);
924    
925                            q.addScalar(COUNT_COLUMN_NAME,
926                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
927    
928                            QueryPos qPos = QueryPos.getInstance(q);
929    
930                            qPos.add(groupId);
931    
932                            Long count = (Long)q.uniqueResult();
933    
934                            return count.intValue();
935                    }
936                    catch (Exception e) {
937                            throw processException(e);
938                    }
939                    finally {
940                            closeSession(session);
941                    }
942            }
943    
944            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "shoppingCategory.groupId = ?";
945            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
946                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
947                            ShoppingCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
948                            "findByG_P",
949                            new String[] {
950                                    Long.class.getName(), Long.class.getName(),
951                                    
952                            Integer.class.getName(), Integer.class.getName(),
953                                    OrderByComparator.class.getName()
954                            });
955            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
956                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
957                            ShoppingCategoryImpl.class,
958                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
959                            new String[] { Long.class.getName(), Long.class.getName() },
960                            ShoppingCategoryModelImpl.GROUPID_COLUMN_BITMASK |
961                            ShoppingCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
962                            ShoppingCategoryModelImpl.NAME_COLUMN_BITMASK);
963            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
964                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
965                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
966                            new String[] { Long.class.getName(), Long.class.getName() });
967    
968            /**
969             * Returns all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
970             *
971             * @param groupId the group ID
972             * @param parentCategoryId the parent category ID
973             * @return the matching shopping categories
974             * @throws SystemException if a system exception occurred
975             */
976            @Override
977            public List<ShoppingCategory> findByG_P(long groupId, long parentCategoryId)
978                    throws SystemException {
979                    return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
980                            QueryUtil.ALL_POS, null);
981            }
982    
983            /**
984             * Returns a range of all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
985             *
986             * <p>
987             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
988             * </p>
989             *
990             * @param groupId the group ID
991             * @param parentCategoryId the parent category ID
992             * @param start the lower bound of the range of shopping categories
993             * @param end the upper bound of the range of shopping categories (not inclusive)
994             * @return the range of matching shopping categories
995             * @throws SystemException if a system exception occurred
996             */
997            @Override
998            public List<ShoppingCategory> findByG_P(long groupId,
999                    long parentCategoryId, int start, int end) throws SystemException {
1000                    return findByG_P(groupId, parentCategoryId, start, end, null);
1001            }
1002    
1003            /**
1004             * Returns an ordered range of all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1005             *
1006             * <p>
1007             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1008             * </p>
1009             *
1010             * @param groupId the group ID
1011             * @param parentCategoryId the parent category ID
1012             * @param start the lower bound of the range of shopping categories
1013             * @param end the upper bound of the range of shopping categories (not inclusive)
1014             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1015             * @return the ordered range of matching shopping categories
1016             * @throws SystemException if a system exception occurred
1017             */
1018            @Override
1019            public List<ShoppingCategory> findByG_P(long groupId,
1020                    long parentCategoryId, int start, int end,
1021                    OrderByComparator orderByComparator) throws SystemException {
1022                    boolean pagination = true;
1023                    FinderPath finderPath = null;
1024                    Object[] finderArgs = null;
1025    
1026                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1027                                    (orderByComparator == null)) {
1028                            pagination = false;
1029                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
1030                            finderArgs = new Object[] { groupId, parentCategoryId };
1031                    }
1032                    else {
1033                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
1034                            finderArgs = new Object[] {
1035                                            groupId, parentCategoryId,
1036                                            
1037                                            start, end, orderByComparator
1038                                    };
1039                    }
1040    
1041                    List<ShoppingCategory> list = (List<ShoppingCategory>)FinderCacheUtil.getResult(finderPath,
1042                                    finderArgs, this);
1043    
1044                    if ((list != null) && !list.isEmpty()) {
1045                            for (ShoppingCategory shoppingCategory : list) {
1046                                    if ((groupId != shoppingCategory.getGroupId()) ||
1047                                                    (parentCategoryId != shoppingCategory.getParentCategoryId())) {
1048                                            list = null;
1049    
1050                                            break;
1051                                    }
1052                            }
1053                    }
1054    
1055                    if (list == null) {
1056                            StringBundler query = null;
1057    
1058                            if (orderByComparator != null) {
1059                                    query = new StringBundler(4 +
1060                                                    (orderByComparator.getOrderByFields().length * 3));
1061                            }
1062                            else {
1063                                    query = new StringBundler(4);
1064                            }
1065    
1066                            query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
1067    
1068                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1069    
1070                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1071    
1072                            if (orderByComparator != null) {
1073                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1074                                            orderByComparator);
1075                            }
1076                            else
1077                             if (pagination) {
1078                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
1079                            }
1080    
1081                            String sql = query.toString();
1082    
1083                            Session session = null;
1084    
1085                            try {
1086                                    session = openSession();
1087    
1088                                    Query q = session.createQuery(sql);
1089    
1090                                    QueryPos qPos = QueryPos.getInstance(q);
1091    
1092                                    qPos.add(groupId);
1093    
1094                                    qPos.add(parentCategoryId);
1095    
1096                                    if (!pagination) {
1097                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
1098                                                            getDialect(), start, end, false);
1099    
1100                                            Collections.sort(list);
1101    
1102                                            list = new UnmodifiableList<ShoppingCategory>(list);
1103                                    }
1104                                    else {
1105                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
1106                                                            getDialect(), start, end);
1107                                    }
1108    
1109                                    cacheResult(list);
1110    
1111                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1112                            }
1113                            catch (Exception e) {
1114                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1115    
1116                                    throw processException(e);
1117                            }
1118                            finally {
1119                                    closeSession(session);
1120                            }
1121                    }
1122    
1123                    return list;
1124            }
1125    
1126            /**
1127             * Returns the first shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1128             *
1129             * @param groupId the group ID
1130             * @param parentCategoryId the parent category ID
1131             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1132             * @return the first matching shopping category
1133             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
1134             * @throws SystemException if a system exception occurred
1135             */
1136            @Override
1137            public ShoppingCategory findByG_P_First(long groupId,
1138                    long parentCategoryId, OrderByComparator orderByComparator)
1139                    throws NoSuchCategoryException, SystemException {
1140                    ShoppingCategory shoppingCategory = fetchByG_P_First(groupId,
1141                                    parentCategoryId, orderByComparator);
1142    
1143                    if (shoppingCategory != null) {
1144                            return shoppingCategory;
1145                    }
1146    
1147                    StringBundler msg = new StringBundler(6);
1148    
1149                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1150    
1151                    msg.append("groupId=");
1152                    msg.append(groupId);
1153    
1154                    msg.append(", parentCategoryId=");
1155                    msg.append(parentCategoryId);
1156    
1157                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1158    
1159                    throw new NoSuchCategoryException(msg.toString());
1160            }
1161    
1162            /**
1163             * Returns the first shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1164             *
1165             * @param groupId the group ID
1166             * @param parentCategoryId the parent category ID
1167             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1168             * @return the first matching shopping category, or <code>null</code> if a matching shopping category could not be found
1169             * @throws SystemException if a system exception occurred
1170             */
1171            @Override
1172            public ShoppingCategory fetchByG_P_First(long groupId,
1173                    long parentCategoryId, OrderByComparator orderByComparator)
1174                    throws SystemException {
1175                    List<ShoppingCategory> list = findByG_P(groupId, parentCategoryId, 0,
1176                                    1, orderByComparator);
1177    
1178                    if (!list.isEmpty()) {
1179                            return list.get(0);
1180                    }
1181    
1182                    return null;
1183            }
1184    
1185            /**
1186             * Returns the last shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1187             *
1188             * @param groupId the group ID
1189             * @param parentCategoryId the parent category ID
1190             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1191             * @return the last matching shopping category
1192             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
1193             * @throws SystemException if a system exception occurred
1194             */
1195            @Override
1196            public ShoppingCategory findByG_P_Last(long groupId, long parentCategoryId,
1197                    OrderByComparator orderByComparator)
1198                    throws NoSuchCategoryException, SystemException {
1199                    ShoppingCategory shoppingCategory = fetchByG_P_Last(groupId,
1200                                    parentCategoryId, orderByComparator);
1201    
1202                    if (shoppingCategory != null) {
1203                            return shoppingCategory;
1204                    }
1205    
1206                    StringBundler msg = new StringBundler(6);
1207    
1208                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1209    
1210                    msg.append("groupId=");
1211                    msg.append(groupId);
1212    
1213                    msg.append(", parentCategoryId=");
1214                    msg.append(parentCategoryId);
1215    
1216                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1217    
1218                    throw new NoSuchCategoryException(msg.toString());
1219            }
1220    
1221            /**
1222             * Returns the last shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1223             *
1224             * @param groupId the group ID
1225             * @param parentCategoryId the parent category ID
1226             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1227             * @return the last matching shopping category, or <code>null</code> if a matching shopping category could not be found
1228             * @throws SystemException if a system exception occurred
1229             */
1230            @Override
1231            public ShoppingCategory fetchByG_P_Last(long groupId,
1232                    long parentCategoryId, OrderByComparator orderByComparator)
1233                    throws SystemException {
1234                    int count = countByG_P(groupId, parentCategoryId);
1235    
1236                    if (count == 0) {
1237                            return null;
1238                    }
1239    
1240                    List<ShoppingCategory> list = findByG_P(groupId, parentCategoryId,
1241                                    count - 1, count, orderByComparator);
1242    
1243                    if (!list.isEmpty()) {
1244                            return list.get(0);
1245                    }
1246    
1247                    return null;
1248            }
1249    
1250            /**
1251             * Returns the shopping categories before and after the current shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1252             *
1253             * @param categoryId the primary key of the current shopping category
1254             * @param groupId the group ID
1255             * @param parentCategoryId the parent category ID
1256             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1257             * @return the previous, current, and next shopping category
1258             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
1259             * @throws SystemException if a system exception occurred
1260             */
1261            @Override
1262            public ShoppingCategory[] findByG_P_PrevAndNext(long categoryId,
1263                    long groupId, long parentCategoryId, OrderByComparator orderByComparator)
1264                    throws NoSuchCategoryException, SystemException {
1265                    ShoppingCategory shoppingCategory = findByPrimaryKey(categoryId);
1266    
1267                    Session session = null;
1268    
1269                    try {
1270                            session = openSession();
1271    
1272                            ShoppingCategory[] array = new ShoppingCategoryImpl[3];
1273    
1274                            array[0] = getByG_P_PrevAndNext(session, shoppingCategory, groupId,
1275                                            parentCategoryId, orderByComparator, true);
1276    
1277                            array[1] = shoppingCategory;
1278    
1279                            array[2] = getByG_P_PrevAndNext(session, shoppingCategory, groupId,
1280                                            parentCategoryId, orderByComparator, false);
1281    
1282                            return array;
1283                    }
1284                    catch (Exception e) {
1285                            throw processException(e);
1286                    }
1287                    finally {
1288                            closeSession(session);
1289                    }
1290            }
1291    
1292            protected ShoppingCategory getByG_P_PrevAndNext(Session session,
1293                    ShoppingCategory shoppingCategory, long groupId, long parentCategoryId,
1294                    OrderByComparator orderByComparator, boolean previous) {
1295                    StringBundler query = null;
1296    
1297                    if (orderByComparator != null) {
1298                            query = new StringBundler(6 +
1299                                            (orderByComparator.getOrderByFields().length * 6));
1300                    }
1301                    else {
1302                            query = new StringBundler(3);
1303                    }
1304    
1305                    query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
1306    
1307                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1308    
1309                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1310    
1311                    if (orderByComparator != null) {
1312                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1313    
1314                            if (orderByConditionFields.length > 0) {
1315                                    query.append(WHERE_AND);
1316                            }
1317    
1318                            for (int i = 0; i < orderByConditionFields.length; i++) {
1319                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1320                                    query.append(orderByConditionFields[i]);
1321    
1322                                    if ((i + 1) < orderByConditionFields.length) {
1323                                            if (orderByComparator.isAscending() ^ previous) {
1324                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1325                                            }
1326                                            else {
1327                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1328                                            }
1329                                    }
1330                                    else {
1331                                            if (orderByComparator.isAscending() ^ previous) {
1332                                                    query.append(WHERE_GREATER_THAN);
1333                                            }
1334                                            else {
1335                                                    query.append(WHERE_LESSER_THAN);
1336                                            }
1337                                    }
1338                            }
1339    
1340                            query.append(ORDER_BY_CLAUSE);
1341    
1342                            String[] orderByFields = orderByComparator.getOrderByFields();
1343    
1344                            for (int i = 0; i < orderByFields.length; i++) {
1345                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1346                                    query.append(orderByFields[i]);
1347    
1348                                    if ((i + 1) < orderByFields.length) {
1349                                            if (orderByComparator.isAscending() ^ previous) {
1350                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1351                                            }
1352                                            else {
1353                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1354                                            }
1355                                    }
1356                                    else {
1357                                            if (orderByComparator.isAscending() ^ previous) {
1358                                                    query.append(ORDER_BY_ASC);
1359                                            }
1360                                            else {
1361                                                    query.append(ORDER_BY_DESC);
1362                                            }
1363                                    }
1364                            }
1365                    }
1366                    else {
1367                            query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
1368                    }
1369    
1370                    String sql = query.toString();
1371    
1372                    Query q = session.createQuery(sql);
1373    
1374                    q.setFirstResult(0);
1375                    q.setMaxResults(2);
1376    
1377                    QueryPos qPos = QueryPos.getInstance(q);
1378    
1379                    qPos.add(groupId);
1380    
1381                    qPos.add(parentCategoryId);
1382    
1383                    if (orderByComparator != null) {
1384                            Object[] values = orderByComparator.getOrderByConditionValues(shoppingCategory);
1385    
1386                            for (Object value : values) {
1387                                    qPos.add(value);
1388                            }
1389                    }
1390    
1391                    List<ShoppingCategory> list = q.list();
1392    
1393                    if (list.size() == 2) {
1394                            return list.get(1);
1395                    }
1396                    else {
1397                            return null;
1398                    }
1399            }
1400    
1401            /**
1402             * Returns all the shopping categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
1403             *
1404             * @param groupId the group ID
1405             * @param parentCategoryId the parent category ID
1406             * @return the matching shopping categories that the user has permission to view
1407             * @throws SystemException if a system exception occurred
1408             */
1409            @Override
1410            public List<ShoppingCategory> filterFindByG_P(long groupId,
1411                    long parentCategoryId) throws SystemException {
1412                    return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
1413                            QueryUtil.ALL_POS, null);
1414            }
1415    
1416            /**
1417             * Returns a range of all the shopping categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
1418             *
1419             * <p>
1420             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1421             * </p>
1422             *
1423             * @param groupId the group ID
1424             * @param parentCategoryId the parent category ID
1425             * @param start the lower bound of the range of shopping categories
1426             * @param end the upper bound of the range of shopping categories (not inclusive)
1427             * @return the range of matching shopping categories that the user has permission to view
1428             * @throws SystemException if a system exception occurred
1429             */
1430            @Override
1431            public List<ShoppingCategory> filterFindByG_P(long groupId,
1432                    long parentCategoryId, int start, int end) throws SystemException {
1433                    return filterFindByG_P(groupId, parentCategoryId, start, end, null);
1434            }
1435    
1436            /**
1437             * Returns an ordered range of all the shopping categories that the user has permissions to view where groupId = &#63; and parentCategoryId = &#63;.
1438             *
1439             * <p>
1440             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1441             * </p>
1442             *
1443             * @param groupId the group ID
1444             * @param parentCategoryId the parent category ID
1445             * @param start the lower bound of the range of shopping categories
1446             * @param end the upper bound of the range of shopping categories (not inclusive)
1447             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1448             * @return the ordered range of matching shopping categories that the user has permission to view
1449             * @throws SystemException if a system exception occurred
1450             */
1451            @Override
1452            public List<ShoppingCategory> filterFindByG_P(long groupId,
1453                    long parentCategoryId, int start, int end,
1454                    OrderByComparator orderByComparator) throws SystemException {
1455                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1456                            return findByG_P(groupId, parentCategoryId, start, end,
1457                                    orderByComparator);
1458                    }
1459    
1460                    StringBundler query = null;
1461    
1462                    if (orderByComparator != null) {
1463                            query = new StringBundler(4 +
1464                                            (orderByComparator.getOrderByFields().length * 3));
1465                    }
1466                    else {
1467                            query = new StringBundler(4);
1468                    }
1469    
1470                    if (getDB().isSupportsInlineDistinct()) {
1471                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
1472                    }
1473                    else {
1474                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1475                    }
1476    
1477                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1478    
1479                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1480    
1481                    if (!getDB().isSupportsInlineDistinct()) {
1482                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1483                    }
1484    
1485                    if (orderByComparator != null) {
1486                            if (getDB().isSupportsInlineDistinct()) {
1487                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1488                                            orderByComparator, true);
1489                            }
1490                            else {
1491                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1492                                            orderByComparator, true);
1493                            }
1494                    }
1495                    else {
1496                            if (getDB().isSupportsInlineDistinct()) {
1497                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
1498                            }
1499                            else {
1500                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_SQL);
1501                            }
1502                    }
1503    
1504                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1505                                    ShoppingCategory.class.getName(),
1506                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1507    
1508                    Session session = null;
1509    
1510                    try {
1511                            session = openSession();
1512    
1513                            SQLQuery q = session.createSQLQuery(sql);
1514    
1515                            if (getDB().isSupportsInlineDistinct()) {
1516                                    q.addEntity(_FILTER_ENTITY_ALIAS, ShoppingCategoryImpl.class);
1517                            }
1518                            else {
1519                                    q.addEntity(_FILTER_ENTITY_TABLE, ShoppingCategoryImpl.class);
1520                            }
1521    
1522                            QueryPos qPos = QueryPos.getInstance(q);
1523    
1524                            qPos.add(groupId);
1525    
1526                            qPos.add(parentCategoryId);
1527    
1528                            return (List<ShoppingCategory>)QueryUtil.list(q, getDialect(),
1529                                    start, end);
1530                    }
1531                    catch (Exception e) {
1532                            throw processException(e);
1533                    }
1534                    finally {
1535                            closeSession(session);
1536                    }
1537            }
1538    
1539            /**
1540             * Returns the shopping categories before and after the current shopping category in the ordered set of shopping categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
1541             *
1542             * @param categoryId the primary key of the current shopping category
1543             * @param groupId the group ID
1544             * @param parentCategoryId the parent category ID
1545             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1546             * @return the previous, current, and next shopping category
1547             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
1548             * @throws SystemException if a system exception occurred
1549             */
1550            @Override
1551            public ShoppingCategory[] filterFindByG_P_PrevAndNext(long categoryId,
1552                    long groupId, long parentCategoryId, OrderByComparator orderByComparator)
1553                    throws NoSuchCategoryException, SystemException {
1554                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1555                            return findByG_P_PrevAndNext(categoryId, groupId, parentCategoryId,
1556                                    orderByComparator);
1557                    }
1558    
1559                    ShoppingCategory shoppingCategory = findByPrimaryKey(categoryId);
1560    
1561                    Session session = null;
1562    
1563                    try {
1564                            session = openSession();
1565    
1566                            ShoppingCategory[] array = new ShoppingCategoryImpl[3];
1567    
1568                            array[0] = filterGetByG_P_PrevAndNext(session, shoppingCategory,
1569                                            groupId, parentCategoryId, orderByComparator, true);
1570    
1571                            array[1] = shoppingCategory;
1572    
1573                            array[2] = filterGetByG_P_PrevAndNext(session, shoppingCategory,
1574                                            groupId, parentCategoryId, orderByComparator, false);
1575    
1576                            return array;
1577                    }
1578                    catch (Exception e) {
1579                            throw processException(e);
1580                    }
1581                    finally {
1582                            closeSession(session);
1583                    }
1584            }
1585    
1586            protected ShoppingCategory filterGetByG_P_PrevAndNext(Session session,
1587                    ShoppingCategory shoppingCategory, long groupId, long parentCategoryId,
1588                    OrderByComparator orderByComparator, boolean previous) {
1589                    StringBundler query = null;
1590    
1591                    if (orderByComparator != null) {
1592                            query = new StringBundler(6 +
1593                                            (orderByComparator.getOrderByFields().length * 6));
1594                    }
1595                    else {
1596                            query = new StringBundler(3);
1597                    }
1598    
1599                    if (getDB().isSupportsInlineDistinct()) {
1600                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
1601                    }
1602                    else {
1603                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1604                    }
1605    
1606                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1607    
1608                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1609    
1610                    if (!getDB().isSupportsInlineDistinct()) {
1611                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1612                    }
1613    
1614                    if (orderByComparator != null) {
1615                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1616    
1617                            if (orderByConditionFields.length > 0) {
1618                                    query.append(WHERE_AND);
1619                            }
1620    
1621                            for (int i = 0; i < orderByConditionFields.length; i++) {
1622                                    if (getDB().isSupportsInlineDistinct()) {
1623                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1624                                    }
1625                                    else {
1626                                            query.append(_ORDER_BY_ENTITY_TABLE);
1627                                    }
1628    
1629                                    query.append(orderByConditionFields[i]);
1630    
1631                                    if ((i + 1) < orderByConditionFields.length) {
1632                                            if (orderByComparator.isAscending() ^ previous) {
1633                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1634                                            }
1635                                            else {
1636                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1637                                            }
1638                                    }
1639                                    else {
1640                                            if (orderByComparator.isAscending() ^ previous) {
1641                                                    query.append(WHERE_GREATER_THAN);
1642                                            }
1643                                            else {
1644                                                    query.append(WHERE_LESSER_THAN);
1645                                            }
1646                                    }
1647                            }
1648    
1649                            query.append(ORDER_BY_CLAUSE);
1650    
1651                            String[] orderByFields = orderByComparator.getOrderByFields();
1652    
1653                            for (int i = 0; i < orderByFields.length; i++) {
1654                                    if (getDB().isSupportsInlineDistinct()) {
1655                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1656                                    }
1657                                    else {
1658                                            query.append(_ORDER_BY_ENTITY_TABLE);
1659                                    }
1660    
1661                                    query.append(orderByFields[i]);
1662    
1663                                    if ((i + 1) < orderByFields.length) {
1664                                            if (orderByComparator.isAscending() ^ previous) {
1665                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1666                                            }
1667                                            else {
1668                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1669                                            }
1670                                    }
1671                                    else {
1672                                            if (orderByComparator.isAscending() ^ previous) {
1673                                                    query.append(ORDER_BY_ASC);
1674                                            }
1675                                            else {
1676                                                    query.append(ORDER_BY_DESC);
1677                                            }
1678                                    }
1679                            }
1680                    }
1681                    else {
1682                            if (getDB().isSupportsInlineDistinct()) {
1683                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
1684                            }
1685                            else {
1686                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_SQL);
1687                            }
1688                    }
1689    
1690                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1691                                    ShoppingCategory.class.getName(),
1692                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1693    
1694                    SQLQuery q = session.createSQLQuery(sql);
1695    
1696                    q.setFirstResult(0);
1697                    q.setMaxResults(2);
1698    
1699                    if (getDB().isSupportsInlineDistinct()) {
1700                            q.addEntity(_FILTER_ENTITY_ALIAS, ShoppingCategoryImpl.class);
1701                    }
1702                    else {
1703                            q.addEntity(_FILTER_ENTITY_TABLE, ShoppingCategoryImpl.class);
1704                    }
1705    
1706                    QueryPos qPos = QueryPos.getInstance(q);
1707    
1708                    qPos.add(groupId);
1709    
1710                    qPos.add(parentCategoryId);
1711    
1712                    if (orderByComparator != null) {
1713                            Object[] values = orderByComparator.getOrderByConditionValues(shoppingCategory);
1714    
1715                            for (Object value : values) {
1716                                    qPos.add(value);
1717                            }
1718                    }
1719    
1720                    List<ShoppingCategory> list = q.list();
1721    
1722                    if (list.size() == 2) {
1723                            return list.get(1);
1724                    }
1725                    else {
1726                            return null;
1727                    }
1728            }
1729    
1730            /**
1731             * Removes all the shopping categories where groupId = &#63; and parentCategoryId = &#63; from the database.
1732             *
1733             * @param groupId the group ID
1734             * @param parentCategoryId the parent category ID
1735             * @throws SystemException if a system exception occurred
1736             */
1737            @Override
1738            public void removeByG_P(long groupId, long parentCategoryId)
1739                    throws SystemException {
1740                    for (ShoppingCategory shoppingCategory : findByG_P(groupId,
1741                                    parentCategoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1742                            remove(shoppingCategory);
1743                    }
1744            }
1745    
1746            /**
1747             * Returns the number of shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1748             *
1749             * @param groupId the group ID
1750             * @param parentCategoryId the parent category ID
1751             * @return the number of matching shopping categories
1752             * @throws SystemException if a system exception occurred
1753             */
1754            @Override
1755            public int countByG_P(long groupId, long parentCategoryId)
1756                    throws SystemException {
1757                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
1758    
1759                    Object[] finderArgs = new Object[] { groupId, parentCategoryId };
1760    
1761                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1762                                    this);
1763    
1764                    if (count == null) {
1765                            StringBundler query = new StringBundler(3);
1766    
1767                            query.append(_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
1768    
1769                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1770    
1771                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1772    
1773                            String sql = query.toString();
1774    
1775                            Session session = null;
1776    
1777                            try {
1778                                    session = openSession();
1779    
1780                                    Query q = session.createQuery(sql);
1781    
1782                                    QueryPos qPos = QueryPos.getInstance(q);
1783    
1784                                    qPos.add(groupId);
1785    
1786                                    qPos.add(parentCategoryId);
1787    
1788                                    count = (Long)q.uniqueResult();
1789    
1790                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1791                            }
1792                            catch (Exception e) {
1793                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1794    
1795                                    throw processException(e);
1796                            }
1797                            finally {
1798                                    closeSession(session);
1799                            }
1800                    }
1801    
1802                    return count.intValue();
1803            }
1804    
1805            /**
1806             * Returns the number of shopping categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
1807             *
1808             * @param groupId the group ID
1809             * @param parentCategoryId the parent category ID
1810             * @return the number of matching shopping categories that the user has permission to view
1811             * @throws SystemException if a system exception occurred
1812             */
1813            @Override
1814            public int filterCountByG_P(long groupId, long parentCategoryId)
1815                    throws SystemException {
1816                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1817                            return countByG_P(groupId, parentCategoryId);
1818                    }
1819    
1820                    StringBundler query = new StringBundler(3);
1821    
1822                    query.append(_FILTER_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
1823    
1824                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1825    
1826                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1827    
1828                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1829                                    ShoppingCategory.class.getName(),
1830                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1831    
1832                    Session session = null;
1833    
1834                    try {
1835                            session = openSession();
1836    
1837                            SQLQuery q = session.createSQLQuery(sql);
1838    
1839                            q.addScalar(COUNT_COLUMN_NAME,
1840                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1841    
1842                            QueryPos qPos = QueryPos.getInstance(q);
1843    
1844                            qPos.add(groupId);
1845    
1846                            qPos.add(parentCategoryId);
1847    
1848                            Long count = (Long)q.uniqueResult();
1849    
1850                            return count.intValue();
1851                    }
1852                    catch (Exception e) {
1853                            throw processException(e);
1854                    }
1855                    finally {
1856                            closeSession(session);
1857                    }
1858            }
1859    
1860            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "shoppingCategory.groupId = ? AND ";
1861            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "shoppingCategory.parentCategoryId = ?";
1862    
1863            /**
1864             * Caches the shopping category in the entity cache if it is enabled.
1865             *
1866             * @param shoppingCategory the shopping category
1867             */
1868            @Override
1869            public void cacheResult(ShoppingCategory shoppingCategory) {
1870                    EntityCacheUtil.putResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
1871                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey(),
1872                            shoppingCategory);
1873    
1874                    shoppingCategory.resetOriginalValues();
1875            }
1876    
1877            /**
1878             * Caches the shopping categories in the entity cache if it is enabled.
1879             *
1880             * @param shoppingCategories the shopping categories
1881             */
1882            @Override
1883            public void cacheResult(List<ShoppingCategory> shoppingCategories) {
1884                    for (ShoppingCategory shoppingCategory : shoppingCategories) {
1885                            if (EntityCacheUtil.getResult(
1886                                                    ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
1887                                                    ShoppingCategoryImpl.class,
1888                                                    shoppingCategory.getPrimaryKey()) == null) {
1889                                    cacheResult(shoppingCategory);
1890                            }
1891                            else {
1892                                    shoppingCategory.resetOriginalValues();
1893                            }
1894                    }
1895            }
1896    
1897            /**
1898             * Clears the cache for all shopping categories.
1899             *
1900             * <p>
1901             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1902             * </p>
1903             */
1904            @Override
1905            public void clearCache() {
1906                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1907                            CacheRegistryUtil.clear(ShoppingCategoryImpl.class.getName());
1908                    }
1909    
1910                    EntityCacheUtil.clearCache(ShoppingCategoryImpl.class.getName());
1911    
1912                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1913                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1914                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1915            }
1916    
1917            /**
1918             * Clears the cache for the shopping category.
1919             *
1920             * <p>
1921             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1922             * </p>
1923             */
1924            @Override
1925            public void clearCache(ShoppingCategory shoppingCategory) {
1926                    EntityCacheUtil.removeResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
1927                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey());
1928    
1929                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1930                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1931            }
1932    
1933            @Override
1934            public void clearCache(List<ShoppingCategory> shoppingCategories) {
1935                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1936                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1937    
1938                    for (ShoppingCategory shoppingCategory : shoppingCategories) {
1939                            EntityCacheUtil.removeResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
1940                                    ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey());
1941                    }
1942            }
1943    
1944            /**
1945             * Creates a new shopping category with the primary key. Does not add the shopping category to the database.
1946             *
1947             * @param categoryId the primary key for the new shopping category
1948             * @return the new shopping category
1949             */
1950            @Override
1951            public ShoppingCategory create(long categoryId) {
1952                    ShoppingCategory shoppingCategory = new ShoppingCategoryImpl();
1953    
1954                    shoppingCategory.setNew(true);
1955                    shoppingCategory.setPrimaryKey(categoryId);
1956    
1957                    return shoppingCategory;
1958            }
1959    
1960            /**
1961             * Removes the shopping category with the primary key from the database. Also notifies the appropriate model listeners.
1962             *
1963             * @param categoryId the primary key of the shopping category
1964             * @return the shopping category that was removed
1965             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
1966             * @throws SystemException if a system exception occurred
1967             */
1968            @Override
1969            public ShoppingCategory remove(long categoryId)
1970                    throws NoSuchCategoryException, SystemException {
1971                    return remove((Serializable)categoryId);
1972            }
1973    
1974            /**
1975             * Removes the shopping category with the primary key from the database. Also notifies the appropriate model listeners.
1976             *
1977             * @param primaryKey the primary key of the shopping category
1978             * @return the shopping category that was removed
1979             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
1980             * @throws SystemException if a system exception occurred
1981             */
1982            @Override
1983            public ShoppingCategory remove(Serializable primaryKey)
1984                    throws NoSuchCategoryException, SystemException {
1985                    Session session = null;
1986    
1987                    try {
1988                            session = openSession();
1989    
1990                            ShoppingCategory shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
1991                                            primaryKey);
1992    
1993                            if (shoppingCategory == null) {
1994                                    if (_log.isWarnEnabled()) {
1995                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1996                                    }
1997    
1998                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1999                                            primaryKey);
2000                            }
2001    
2002                            return remove(shoppingCategory);
2003                    }
2004                    catch (NoSuchCategoryException nsee) {
2005                            throw nsee;
2006                    }
2007                    catch (Exception e) {
2008                            throw processException(e);
2009                    }
2010                    finally {
2011                            closeSession(session);
2012                    }
2013            }
2014    
2015            @Override
2016            protected ShoppingCategory removeImpl(ShoppingCategory shoppingCategory)
2017                    throws SystemException {
2018                    shoppingCategory = toUnwrappedModel(shoppingCategory);
2019    
2020                    Session session = null;
2021    
2022                    try {
2023                            session = openSession();
2024    
2025                            if (!session.contains(shoppingCategory)) {
2026                                    shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
2027                                                    shoppingCategory.getPrimaryKeyObj());
2028                            }
2029    
2030                            if (shoppingCategory != null) {
2031                                    session.delete(shoppingCategory);
2032                            }
2033                    }
2034                    catch (Exception e) {
2035                            throw processException(e);
2036                    }
2037                    finally {
2038                            closeSession(session);
2039                    }
2040    
2041                    if (shoppingCategory != null) {
2042                            clearCache(shoppingCategory);
2043                    }
2044    
2045                    return shoppingCategory;
2046            }
2047    
2048            @Override
2049            public ShoppingCategory updateImpl(
2050                    com.liferay.portlet.shopping.model.ShoppingCategory shoppingCategory)
2051                    throws SystemException {
2052                    shoppingCategory = toUnwrappedModel(shoppingCategory);
2053    
2054                    boolean isNew = shoppingCategory.isNew();
2055    
2056                    ShoppingCategoryModelImpl shoppingCategoryModelImpl = (ShoppingCategoryModelImpl)shoppingCategory;
2057    
2058                    Session session = null;
2059    
2060                    try {
2061                            session = openSession();
2062    
2063                            if (shoppingCategory.isNew()) {
2064                                    session.save(shoppingCategory);
2065    
2066                                    shoppingCategory.setNew(false);
2067                            }
2068                            else {
2069                                    session.merge(shoppingCategory);
2070                            }
2071                    }
2072                    catch (Exception e) {
2073                            throw processException(e);
2074                    }
2075                    finally {
2076                            closeSession(session);
2077                    }
2078    
2079                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2080    
2081                    if (isNew || !ShoppingCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
2082                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2083                    }
2084    
2085                    else {
2086                            if ((shoppingCategoryModelImpl.getColumnBitmask() &
2087                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2088                                    Object[] args = new Object[] {
2089                                                    shoppingCategoryModelImpl.getOriginalGroupId()
2090                                            };
2091    
2092                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2093                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2094                                            args);
2095    
2096                                    args = new Object[] { shoppingCategoryModelImpl.getGroupId() };
2097    
2098                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2099                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2100                                            args);
2101                            }
2102    
2103                            if ((shoppingCategoryModelImpl.getColumnBitmask() &
2104                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
2105                                    Object[] args = new Object[] {
2106                                                    shoppingCategoryModelImpl.getOriginalGroupId(),
2107                                                    shoppingCategoryModelImpl.getOriginalParentCategoryId()
2108                                            };
2109    
2110                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
2111                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
2112                                            args);
2113    
2114                                    args = new Object[] {
2115                                                    shoppingCategoryModelImpl.getGroupId(),
2116                                                    shoppingCategoryModelImpl.getParentCategoryId()
2117                                            };
2118    
2119                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
2120                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
2121                                            args);
2122                            }
2123                    }
2124    
2125                    EntityCacheUtil.putResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
2126                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey(),
2127                            shoppingCategory);
2128    
2129                    return shoppingCategory;
2130            }
2131    
2132            protected ShoppingCategory toUnwrappedModel(
2133                    ShoppingCategory shoppingCategory) {
2134                    if (shoppingCategory instanceof ShoppingCategoryImpl) {
2135                            return shoppingCategory;
2136                    }
2137    
2138                    ShoppingCategoryImpl shoppingCategoryImpl = new ShoppingCategoryImpl();
2139    
2140                    shoppingCategoryImpl.setNew(shoppingCategory.isNew());
2141                    shoppingCategoryImpl.setPrimaryKey(shoppingCategory.getPrimaryKey());
2142    
2143                    shoppingCategoryImpl.setCategoryId(shoppingCategory.getCategoryId());
2144                    shoppingCategoryImpl.setGroupId(shoppingCategory.getGroupId());
2145                    shoppingCategoryImpl.setCompanyId(shoppingCategory.getCompanyId());
2146                    shoppingCategoryImpl.setUserId(shoppingCategory.getUserId());
2147                    shoppingCategoryImpl.setUserName(shoppingCategory.getUserName());
2148                    shoppingCategoryImpl.setCreateDate(shoppingCategory.getCreateDate());
2149                    shoppingCategoryImpl.setModifiedDate(shoppingCategory.getModifiedDate());
2150                    shoppingCategoryImpl.setParentCategoryId(shoppingCategory.getParentCategoryId());
2151                    shoppingCategoryImpl.setName(shoppingCategory.getName());
2152                    shoppingCategoryImpl.setDescription(shoppingCategory.getDescription());
2153    
2154                    return shoppingCategoryImpl;
2155            }
2156    
2157            /**
2158             * Returns the shopping category with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2159             *
2160             * @param primaryKey the primary key of the shopping category
2161             * @return the shopping category
2162             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
2163             * @throws SystemException if a system exception occurred
2164             */
2165            @Override
2166            public ShoppingCategory findByPrimaryKey(Serializable primaryKey)
2167                    throws NoSuchCategoryException, SystemException {
2168                    ShoppingCategory shoppingCategory = fetchByPrimaryKey(primaryKey);
2169    
2170                    if (shoppingCategory == null) {
2171                            if (_log.isWarnEnabled()) {
2172                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2173                            }
2174    
2175                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2176                                    primaryKey);
2177                    }
2178    
2179                    return shoppingCategory;
2180            }
2181    
2182            /**
2183             * Returns the shopping category with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchCategoryException} if it could not be found.
2184             *
2185             * @param categoryId the primary key of the shopping category
2186             * @return the shopping category
2187             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
2188             * @throws SystemException if a system exception occurred
2189             */
2190            @Override
2191            public ShoppingCategory findByPrimaryKey(long categoryId)
2192                    throws NoSuchCategoryException, SystemException {
2193                    return findByPrimaryKey((Serializable)categoryId);
2194            }
2195    
2196            /**
2197             * Returns the shopping category with the primary key or returns <code>null</code> if it could not be found.
2198             *
2199             * @param primaryKey the primary key of the shopping category
2200             * @return the shopping category, or <code>null</code> if a shopping category with the primary key could not be found
2201             * @throws SystemException if a system exception occurred
2202             */
2203            @Override
2204            public ShoppingCategory fetchByPrimaryKey(Serializable primaryKey)
2205                    throws SystemException {
2206                    ShoppingCategory shoppingCategory = (ShoppingCategory)EntityCacheUtil.getResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
2207                                    ShoppingCategoryImpl.class, primaryKey);
2208    
2209                    if (shoppingCategory == _nullShoppingCategory) {
2210                            return null;
2211                    }
2212    
2213                    if (shoppingCategory == null) {
2214                            Session session = null;
2215    
2216                            try {
2217                                    session = openSession();
2218    
2219                                    shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
2220                                                    primaryKey);
2221    
2222                                    if (shoppingCategory != null) {
2223                                            cacheResult(shoppingCategory);
2224                                    }
2225                                    else {
2226                                            EntityCacheUtil.putResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
2227                                                    ShoppingCategoryImpl.class, primaryKey,
2228                                                    _nullShoppingCategory);
2229                                    }
2230                            }
2231                            catch (Exception e) {
2232                                    EntityCacheUtil.removeResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
2233                                            ShoppingCategoryImpl.class, primaryKey);
2234    
2235                                    throw processException(e);
2236                            }
2237                            finally {
2238                                    closeSession(session);
2239                            }
2240                    }
2241    
2242                    return shoppingCategory;
2243            }
2244    
2245            /**
2246             * Returns the shopping category with the primary key or returns <code>null</code> if it could not be found.
2247             *
2248             * @param categoryId the primary key of the shopping category
2249             * @return the shopping category, or <code>null</code> if a shopping category with the primary key could not be found
2250             * @throws SystemException if a system exception occurred
2251             */
2252            @Override
2253            public ShoppingCategory fetchByPrimaryKey(long categoryId)
2254                    throws SystemException {
2255                    return fetchByPrimaryKey((Serializable)categoryId);
2256            }
2257    
2258            /**
2259             * Returns all the shopping categories.
2260             *
2261             * @return the shopping categories
2262             * @throws SystemException if a system exception occurred
2263             */
2264            @Override
2265            public List<ShoppingCategory> findAll() throws SystemException {
2266                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2267            }
2268    
2269            /**
2270             * Returns a range of all the shopping categories.
2271             *
2272             * <p>
2273             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2274             * </p>
2275             *
2276             * @param start the lower bound of the range of shopping categories
2277             * @param end the upper bound of the range of shopping categories (not inclusive)
2278             * @return the range of shopping categories
2279             * @throws SystemException if a system exception occurred
2280             */
2281            @Override
2282            public List<ShoppingCategory> findAll(int start, int end)
2283                    throws SystemException {
2284                    return findAll(start, end, null);
2285            }
2286    
2287            /**
2288             * Returns an ordered range of all the shopping categories.
2289             *
2290             * <p>
2291             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2292             * </p>
2293             *
2294             * @param start the lower bound of the range of shopping categories
2295             * @param end the upper bound of the range of shopping categories (not inclusive)
2296             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2297             * @return the ordered range of shopping categories
2298             * @throws SystemException if a system exception occurred
2299             */
2300            @Override
2301            public List<ShoppingCategory> findAll(int start, int end,
2302                    OrderByComparator orderByComparator) throws SystemException {
2303                    boolean pagination = true;
2304                    FinderPath finderPath = null;
2305                    Object[] finderArgs = null;
2306    
2307                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2308                                    (orderByComparator == null)) {
2309                            pagination = false;
2310                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2311                            finderArgs = FINDER_ARGS_EMPTY;
2312                    }
2313                    else {
2314                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2315                            finderArgs = new Object[] { start, end, orderByComparator };
2316                    }
2317    
2318                    List<ShoppingCategory> list = (List<ShoppingCategory>)FinderCacheUtil.getResult(finderPath,
2319                                    finderArgs, this);
2320    
2321                    if (list == null) {
2322                            StringBundler query = null;
2323                            String sql = null;
2324    
2325                            if (orderByComparator != null) {
2326                                    query = new StringBundler(2 +
2327                                                    (orderByComparator.getOrderByFields().length * 3));
2328    
2329                                    query.append(_SQL_SELECT_SHOPPINGCATEGORY);
2330    
2331                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2332                                            orderByComparator);
2333    
2334                                    sql = query.toString();
2335                            }
2336                            else {
2337                                    sql = _SQL_SELECT_SHOPPINGCATEGORY;
2338    
2339                                    if (pagination) {
2340                                            sql = sql.concat(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
2341                                    }
2342                            }
2343    
2344                            Session session = null;
2345    
2346                            try {
2347                                    session = openSession();
2348    
2349                                    Query q = session.createQuery(sql);
2350    
2351                                    if (!pagination) {
2352                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
2353                                                            getDialect(), start, end, false);
2354    
2355                                            Collections.sort(list);
2356    
2357                                            list = new UnmodifiableList<ShoppingCategory>(list);
2358                                    }
2359                                    else {
2360                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
2361                                                            getDialect(), start, end);
2362                                    }
2363    
2364                                    cacheResult(list);
2365    
2366                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2367                            }
2368                            catch (Exception e) {
2369                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2370    
2371                                    throw processException(e);
2372                            }
2373                            finally {
2374                                    closeSession(session);
2375                            }
2376                    }
2377    
2378                    return list;
2379            }
2380    
2381            /**
2382             * Removes all the shopping categories from the database.
2383             *
2384             * @throws SystemException if a system exception occurred
2385             */
2386            @Override
2387            public void removeAll() throws SystemException {
2388                    for (ShoppingCategory shoppingCategory : findAll()) {
2389                            remove(shoppingCategory);
2390                    }
2391            }
2392    
2393            /**
2394             * Returns the number of shopping categories.
2395             *
2396             * @return the number of shopping categories
2397             * @throws SystemException if a system exception occurred
2398             */
2399            @Override
2400            public int countAll() throws SystemException {
2401                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2402                                    FINDER_ARGS_EMPTY, this);
2403    
2404                    if (count == null) {
2405                            Session session = null;
2406    
2407                            try {
2408                                    session = openSession();
2409    
2410                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGCATEGORY);
2411    
2412                                    count = (Long)q.uniqueResult();
2413    
2414                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2415                                            FINDER_ARGS_EMPTY, count);
2416                            }
2417                            catch (Exception e) {
2418                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2419                                            FINDER_ARGS_EMPTY);
2420    
2421                                    throw processException(e);
2422                            }
2423                            finally {
2424                                    closeSession(session);
2425                            }
2426                    }
2427    
2428                    return count.intValue();
2429            }
2430    
2431            /**
2432             * Initializes the shopping category persistence.
2433             */
2434            public void afterPropertiesSet() {
2435                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2436                                            com.liferay.portal.util.PropsUtil.get(
2437                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingCategory")));
2438    
2439                    if (listenerClassNames.length > 0) {
2440                            try {
2441                                    List<ModelListener<ShoppingCategory>> listenersList = new ArrayList<ModelListener<ShoppingCategory>>();
2442    
2443                                    for (String listenerClassName : listenerClassNames) {
2444                                            listenersList.add((ModelListener<ShoppingCategory>)InstanceFactory.newInstance(
2445                                                            getClassLoader(), listenerClassName));
2446                                    }
2447    
2448                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2449                            }
2450                            catch (Exception e) {
2451                                    _log.error(e);
2452                            }
2453                    }
2454            }
2455    
2456            public void destroy() {
2457                    EntityCacheUtil.removeCache(ShoppingCategoryImpl.class.getName());
2458                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2459                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2460                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2461            }
2462    
2463            private static final String _SQL_SELECT_SHOPPINGCATEGORY = "SELECT shoppingCategory FROM ShoppingCategory shoppingCategory";
2464            private static final String _SQL_SELECT_SHOPPINGCATEGORY_WHERE = "SELECT shoppingCategory FROM ShoppingCategory shoppingCategory WHERE ";
2465            private static final String _SQL_COUNT_SHOPPINGCATEGORY = "SELECT COUNT(shoppingCategory) FROM ShoppingCategory shoppingCategory";
2466            private static final String _SQL_COUNT_SHOPPINGCATEGORY_WHERE = "SELECT COUNT(shoppingCategory) FROM ShoppingCategory shoppingCategory WHERE ";
2467            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "shoppingCategory.categoryId";
2468            private static final String _FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE = "SELECT DISTINCT {shoppingCategory.*} FROM ShoppingCategory shoppingCategory WHERE ";
2469            private static final String _FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
2470                    "SELECT {ShoppingCategory.*} FROM (SELECT DISTINCT shoppingCategory.categoryId FROM ShoppingCategory shoppingCategory WHERE ";
2471            private static final String _FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
2472                    ") TEMP_TABLE INNER JOIN ShoppingCategory ON TEMP_TABLE.categoryId = ShoppingCategory.categoryId";
2473            private static final String _FILTER_SQL_COUNT_SHOPPINGCATEGORY_WHERE = "SELECT COUNT(DISTINCT shoppingCategory.categoryId) AS COUNT_VALUE FROM ShoppingCategory shoppingCategory WHERE ";
2474            private static final String _FILTER_ENTITY_ALIAS = "shoppingCategory";
2475            private static final String _FILTER_ENTITY_TABLE = "ShoppingCategory";
2476            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingCategory.";
2477            private static final String _ORDER_BY_ENTITY_TABLE = "ShoppingCategory.";
2478            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingCategory exists with the primary key ";
2479            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingCategory exists with the key {";
2480            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2481            private static Log _log = LogFactoryUtil.getLog(ShoppingCategoryPersistenceImpl.class);
2482            private static ShoppingCategory _nullShoppingCategory = new ShoppingCategoryImpl() {
2483                            @Override
2484                            public Object clone() {
2485                                    return this;
2486                            }
2487    
2488                            @Override
2489                            public CacheModel<ShoppingCategory> toCacheModel() {
2490                                    return _nullShoppingCategoryCacheModel;
2491                            }
2492                    };
2493    
2494            private static CacheModel<ShoppingCategory> _nullShoppingCategoryCacheModel = new CacheModel<ShoppingCategory>() {
2495                            @Override
2496                            public ShoppingCategory toEntityModel() {
2497                                    return _nullShoppingCategory;
2498                            }
2499                    };
2500    }