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            public ShoppingCategoryPersistenceImpl() {
1864                    setModelClass(ShoppingCategory.class);
1865            }
1866    
1867            /**
1868             * Caches the shopping category in the entity cache if it is enabled.
1869             *
1870             * @param shoppingCategory the shopping category
1871             */
1872            @Override
1873            public void cacheResult(ShoppingCategory shoppingCategory) {
1874                    EntityCacheUtil.putResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
1875                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey(),
1876                            shoppingCategory);
1877    
1878                    shoppingCategory.resetOriginalValues();
1879            }
1880    
1881            /**
1882             * Caches the shopping categories in the entity cache if it is enabled.
1883             *
1884             * @param shoppingCategories the shopping categories
1885             */
1886            @Override
1887            public void cacheResult(List<ShoppingCategory> shoppingCategories) {
1888                    for (ShoppingCategory shoppingCategory : shoppingCategories) {
1889                            if (EntityCacheUtil.getResult(
1890                                                    ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
1891                                                    ShoppingCategoryImpl.class,
1892                                                    shoppingCategory.getPrimaryKey()) == null) {
1893                                    cacheResult(shoppingCategory);
1894                            }
1895                            else {
1896                                    shoppingCategory.resetOriginalValues();
1897                            }
1898                    }
1899            }
1900    
1901            /**
1902             * Clears the cache for all shopping categories.
1903             *
1904             * <p>
1905             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1906             * </p>
1907             */
1908            @Override
1909            public void clearCache() {
1910                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1911                            CacheRegistryUtil.clear(ShoppingCategoryImpl.class.getName());
1912                    }
1913    
1914                    EntityCacheUtil.clearCache(ShoppingCategoryImpl.class.getName());
1915    
1916                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1917                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1918                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1919            }
1920    
1921            /**
1922             * Clears the cache for the shopping category.
1923             *
1924             * <p>
1925             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1926             * </p>
1927             */
1928            @Override
1929            public void clearCache(ShoppingCategory shoppingCategory) {
1930                    EntityCacheUtil.removeResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
1931                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey());
1932    
1933                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1934                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1935            }
1936    
1937            @Override
1938            public void clearCache(List<ShoppingCategory> shoppingCategories) {
1939                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1940                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1941    
1942                    for (ShoppingCategory shoppingCategory : shoppingCategories) {
1943                            EntityCacheUtil.removeResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
1944                                    ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey());
1945                    }
1946            }
1947    
1948            /**
1949             * Creates a new shopping category with the primary key. Does not add the shopping category to the database.
1950             *
1951             * @param categoryId the primary key for the new shopping category
1952             * @return the new shopping category
1953             */
1954            @Override
1955            public ShoppingCategory create(long categoryId) {
1956                    ShoppingCategory shoppingCategory = new ShoppingCategoryImpl();
1957    
1958                    shoppingCategory.setNew(true);
1959                    shoppingCategory.setPrimaryKey(categoryId);
1960    
1961                    return shoppingCategory;
1962            }
1963    
1964            /**
1965             * Removes the shopping category with the primary key from the database. Also notifies the appropriate model listeners.
1966             *
1967             * @param categoryId the primary key of the shopping category
1968             * @return the shopping category that was removed
1969             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
1970             * @throws SystemException if a system exception occurred
1971             */
1972            @Override
1973            public ShoppingCategory remove(long categoryId)
1974                    throws NoSuchCategoryException, SystemException {
1975                    return remove((Serializable)categoryId);
1976            }
1977    
1978            /**
1979             * Removes the shopping category with the primary key from the database. Also notifies the appropriate model listeners.
1980             *
1981             * @param primaryKey the primary key of the shopping category
1982             * @return the shopping category that was removed
1983             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
1984             * @throws SystemException if a system exception occurred
1985             */
1986            @Override
1987            public ShoppingCategory remove(Serializable primaryKey)
1988                    throws NoSuchCategoryException, SystemException {
1989                    Session session = null;
1990    
1991                    try {
1992                            session = openSession();
1993    
1994                            ShoppingCategory shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
1995                                            primaryKey);
1996    
1997                            if (shoppingCategory == null) {
1998                                    if (_log.isWarnEnabled()) {
1999                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2000                                    }
2001    
2002                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2003                                            primaryKey);
2004                            }
2005    
2006                            return remove(shoppingCategory);
2007                    }
2008                    catch (NoSuchCategoryException nsee) {
2009                            throw nsee;
2010                    }
2011                    catch (Exception e) {
2012                            throw processException(e);
2013                    }
2014                    finally {
2015                            closeSession(session);
2016                    }
2017            }
2018    
2019            @Override
2020            protected ShoppingCategory removeImpl(ShoppingCategory shoppingCategory)
2021                    throws SystemException {
2022                    shoppingCategory = toUnwrappedModel(shoppingCategory);
2023    
2024                    Session session = null;
2025    
2026                    try {
2027                            session = openSession();
2028    
2029                            if (!session.contains(shoppingCategory)) {
2030                                    shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
2031                                                    shoppingCategory.getPrimaryKeyObj());
2032                            }
2033    
2034                            if (shoppingCategory != null) {
2035                                    session.delete(shoppingCategory);
2036                            }
2037                    }
2038                    catch (Exception e) {
2039                            throw processException(e);
2040                    }
2041                    finally {
2042                            closeSession(session);
2043                    }
2044    
2045                    if (shoppingCategory != null) {
2046                            clearCache(shoppingCategory);
2047                    }
2048    
2049                    return shoppingCategory;
2050            }
2051    
2052            @Override
2053            public ShoppingCategory updateImpl(
2054                    com.liferay.portlet.shopping.model.ShoppingCategory shoppingCategory)
2055                    throws SystemException {
2056                    shoppingCategory = toUnwrappedModel(shoppingCategory);
2057    
2058                    boolean isNew = shoppingCategory.isNew();
2059    
2060                    ShoppingCategoryModelImpl shoppingCategoryModelImpl = (ShoppingCategoryModelImpl)shoppingCategory;
2061    
2062                    Session session = null;
2063    
2064                    try {
2065                            session = openSession();
2066    
2067                            if (shoppingCategory.isNew()) {
2068                                    session.save(shoppingCategory);
2069    
2070                                    shoppingCategory.setNew(false);
2071                            }
2072                            else {
2073                                    session.merge(shoppingCategory);
2074                            }
2075                    }
2076                    catch (Exception e) {
2077                            throw processException(e);
2078                    }
2079                    finally {
2080                            closeSession(session);
2081                    }
2082    
2083                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2084    
2085                    if (isNew || !ShoppingCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
2086                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2087                    }
2088    
2089                    else {
2090                            if ((shoppingCategoryModelImpl.getColumnBitmask() &
2091                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2092                                    Object[] args = new Object[] {
2093                                                    shoppingCategoryModelImpl.getOriginalGroupId()
2094                                            };
2095    
2096                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2097                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2098                                            args);
2099    
2100                                    args = new Object[] { shoppingCategoryModelImpl.getGroupId() };
2101    
2102                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2103                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2104                                            args);
2105                            }
2106    
2107                            if ((shoppingCategoryModelImpl.getColumnBitmask() &
2108                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
2109                                    Object[] args = new Object[] {
2110                                                    shoppingCategoryModelImpl.getOriginalGroupId(),
2111                                                    shoppingCategoryModelImpl.getOriginalParentCategoryId()
2112                                            };
2113    
2114                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
2115                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
2116                                            args);
2117    
2118                                    args = new Object[] {
2119                                                    shoppingCategoryModelImpl.getGroupId(),
2120                                                    shoppingCategoryModelImpl.getParentCategoryId()
2121                                            };
2122    
2123                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
2124                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
2125                                            args);
2126                            }
2127                    }
2128    
2129                    EntityCacheUtil.putResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
2130                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey(),
2131                            shoppingCategory);
2132    
2133                    return shoppingCategory;
2134            }
2135    
2136            protected ShoppingCategory toUnwrappedModel(
2137                    ShoppingCategory shoppingCategory) {
2138                    if (shoppingCategory instanceof ShoppingCategoryImpl) {
2139                            return shoppingCategory;
2140                    }
2141    
2142                    ShoppingCategoryImpl shoppingCategoryImpl = new ShoppingCategoryImpl();
2143    
2144                    shoppingCategoryImpl.setNew(shoppingCategory.isNew());
2145                    shoppingCategoryImpl.setPrimaryKey(shoppingCategory.getPrimaryKey());
2146    
2147                    shoppingCategoryImpl.setCategoryId(shoppingCategory.getCategoryId());
2148                    shoppingCategoryImpl.setGroupId(shoppingCategory.getGroupId());
2149                    shoppingCategoryImpl.setCompanyId(shoppingCategory.getCompanyId());
2150                    shoppingCategoryImpl.setUserId(shoppingCategory.getUserId());
2151                    shoppingCategoryImpl.setUserName(shoppingCategory.getUserName());
2152                    shoppingCategoryImpl.setCreateDate(shoppingCategory.getCreateDate());
2153                    shoppingCategoryImpl.setModifiedDate(shoppingCategory.getModifiedDate());
2154                    shoppingCategoryImpl.setParentCategoryId(shoppingCategory.getParentCategoryId());
2155                    shoppingCategoryImpl.setName(shoppingCategory.getName());
2156                    shoppingCategoryImpl.setDescription(shoppingCategory.getDescription());
2157    
2158                    return shoppingCategoryImpl;
2159            }
2160    
2161            /**
2162             * Returns the shopping category with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2163             *
2164             * @param primaryKey the primary key of the shopping category
2165             * @return the shopping category
2166             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
2167             * @throws SystemException if a system exception occurred
2168             */
2169            @Override
2170            public ShoppingCategory findByPrimaryKey(Serializable primaryKey)
2171                    throws NoSuchCategoryException, SystemException {
2172                    ShoppingCategory shoppingCategory = fetchByPrimaryKey(primaryKey);
2173    
2174                    if (shoppingCategory == null) {
2175                            if (_log.isWarnEnabled()) {
2176                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2177                            }
2178    
2179                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2180                                    primaryKey);
2181                    }
2182    
2183                    return shoppingCategory;
2184            }
2185    
2186            /**
2187             * Returns the shopping category with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchCategoryException} if it could not be found.
2188             *
2189             * @param categoryId the primary key of the shopping category
2190             * @return the shopping category
2191             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
2192             * @throws SystemException if a system exception occurred
2193             */
2194            @Override
2195            public ShoppingCategory findByPrimaryKey(long categoryId)
2196                    throws NoSuchCategoryException, SystemException {
2197                    return findByPrimaryKey((Serializable)categoryId);
2198            }
2199    
2200            /**
2201             * Returns the shopping category with the primary key or returns <code>null</code> if it could not be found.
2202             *
2203             * @param primaryKey the primary key of the shopping category
2204             * @return the shopping category, or <code>null</code> if a shopping category with the primary key could not be found
2205             * @throws SystemException if a system exception occurred
2206             */
2207            @Override
2208            public ShoppingCategory fetchByPrimaryKey(Serializable primaryKey)
2209                    throws SystemException {
2210                    ShoppingCategory shoppingCategory = (ShoppingCategory)EntityCacheUtil.getResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
2211                                    ShoppingCategoryImpl.class, primaryKey);
2212    
2213                    if (shoppingCategory == _nullShoppingCategory) {
2214                            return null;
2215                    }
2216    
2217                    if (shoppingCategory == null) {
2218                            Session session = null;
2219    
2220                            try {
2221                                    session = openSession();
2222    
2223                                    shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
2224                                                    primaryKey);
2225    
2226                                    if (shoppingCategory != null) {
2227                                            cacheResult(shoppingCategory);
2228                                    }
2229                                    else {
2230                                            EntityCacheUtil.putResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
2231                                                    ShoppingCategoryImpl.class, primaryKey,
2232                                                    _nullShoppingCategory);
2233                                    }
2234                            }
2235                            catch (Exception e) {
2236                                    EntityCacheUtil.removeResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
2237                                            ShoppingCategoryImpl.class, primaryKey);
2238    
2239                                    throw processException(e);
2240                            }
2241                            finally {
2242                                    closeSession(session);
2243                            }
2244                    }
2245    
2246                    return shoppingCategory;
2247            }
2248    
2249            /**
2250             * Returns the shopping category with the primary key or returns <code>null</code> if it could not be found.
2251             *
2252             * @param categoryId the primary key of the shopping category
2253             * @return the shopping category, or <code>null</code> if a shopping category with the primary key could not be found
2254             * @throws SystemException if a system exception occurred
2255             */
2256            @Override
2257            public ShoppingCategory fetchByPrimaryKey(long categoryId)
2258                    throws SystemException {
2259                    return fetchByPrimaryKey((Serializable)categoryId);
2260            }
2261    
2262            /**
2263             * Returns all the shopping categories.
2264             *
2265             * @return the shopping categories
2266             * @throws SystemException if a system exception occurred
2267             */
2268            @Override
2269            public List<ShoppingCategory> findAll() throws SystemException {
2270                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2271            }
2272    
2273            /**
2274             * Returns a range of all the shopping categories.
2275             *
2276             * <p>
2277             * 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.
2278             * </p>
2279             *
2280             * @param start the lower bound of the range of shopping categories
2281             * @param end the upper bound of the range of shopping categories (not inclusive)
2282             * @return the range of shopping categories
2283             * @throws SystemException if a system exception occurred
2284             */
2285            @Override
2286            public List<ShoppingCategory> findAll(int start, int end)
2287                    throws SystemException {
2288                    return findAll(start, end, null);
2289            }
2290    
2291            /**
2292             * Returns an ordered range of all the shopping categories.
2293             *
2294             * <p>
2295             * 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.
2296             * </p>
2297             *
2298             * @param start the lower bound of the range of shopping categories
2299             * @param end the upper bound of the range of shopping categories (not inclusive)
2300             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2301             * @return the ordered range of shopping categories
2302             * @throws SystemException if a system exception occurred
2303             */
2304            @Override
2305            public List<ShoppingCategory> findAll(int start, int end,
2306                    OrderByComparator orderByComparator) throws SystemException {
2307                    boolean pagination = true;
2308                    FinderPath finderPath = null;
2309                    Object[] finderArgs = null;
2310    
2311                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2312                                    (orderByComparator == null)) {
2313                            pagination = false;
2314                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2315                            finderArgs = FINDER_ARGS_EMPTY;
2316                    }
2317                    else {
2318                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2319                            finderArgs = new Object[] { start, end, orderByComparator };
2320                    }
2321    
2322                    List<ShoppingCategory> list = (List<ShoppingCategory>)FinderCacheUtil.getResult(finderPath,
2323                                    finderArgs, this);
2324    
2325                    if (list == null) {
2326                            StringBundler query = null;
2327                            String sql = null;
2328    
2329                            if (orderByComparator != null) {
2330                                    query = new StringBundler(2 +
2331                                                    (orderByComparator.getOrderByFields().length * 3));
2332    
2333                                    query.append(_SQL_SELECT_SHOPPINGCATEGORY);
2334    
2335                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2336                                            orderByComparator);
2337    
2338                                    sql = query.toString();
2339                            }
2340                            else {
2341                                    sql = _SQL_SELECT_SHOPPINGCATEGORY;
2342    
2343                                    if (pagination) {
2344                                            sql = sql.concat(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
2345                                    }
2346                            }
2347    
2348                            Session session = null;
2349    
2350                            try {
2351                                    session = openSession();
2352    
2353                                    Query q = session.createQuery(sql);
2354    
2355                                    if (!pagination) {
2356                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
2357                                                            getDialect(), start, end, false);
2358    
2359                                            Collections.sort(list);
2360    
2361                                            list = new UnmodifiableList<ShoppingCategory>(list);
2362                                    }
2363                                    else {
2364                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
2365                                                            getDialect(), start, end);
2366                                    }
2367    
2368                                    cacheResult(list);
2369    
2370                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2371                            }
2372                            catch (Exception e) {
2373                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2374    
2375                                    throw processException(e);
2376                            }
2377                            finally {
2378                                    closeSession(session);
2379                            }
2380                    }
2381    
2382                    return list;
2383            }
2384    
2385            /**
2386             * Removes all the shopping categories from the database.
2387             *
2388             * @throws SystemException if a system exception occurred
2389             */
2390            @Override
2391            public void removeAll() throws SystemException {
2392                    for (ShoppingCategory shoppingCategory : findAll()) {
2393                            remove(shoppingCategory);
2394                    }
2395            }
2396    
2397            /**
2398             * Returns the number of shopping categories.
2399             *
2400             * @return the number of shopping categories
2401             * @throws SystemException if a system exception occurred
2402             */
2403            @Override
2404            public int countAll() throws SystemException {
2405                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2406                                    FINDER_ARGS_EMPTY, this);
2407    
2408                    if (count == null) {
2409                            Session session = null;
2410    
2411                            try {
2412                                    session = openSession();
2413    
2414                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGCATEGORY);
2415    
2416                                    count = (Long)q.uniqueResult();
2417    
2418                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2419                                            FINDER_ARGS_EMPTY, count);
2420                            }
2421                            catch (Exception e) {
2422                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2423                                            FINDER_ARGS_EMPTY);
2424    
2425                                    throw processException(e);
2426                            }
2427                            finally {
2428                                    closeSession(session);
2429                            }
2430                    }
2431    
2432                    return count.intValue();
2433            }
2434    
2435            /**
2436             * Initializes the shopping category persistence.
2437             */
2438            public void afterPropertiesSet() {
2439                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2440                                            com.liferay.portal.util.PropsUtil.get(
2441                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingCategory")));
2442    
2443                    if (listenerClassNames.length > 0) {
2444                            try {
2445                                    List<ModelListener<ShoppingCategory>> listenersList = new ArrayList<ModelListener<ShoppingCategory>>();
2446    
2447                                    for (String listenerClassName : listenerClassNames) {
2448                                            listenersList.add((ModelListener<ShoppingCategory>)InstanceFactory.newInstance(
2449                                                            getClassLoader(), listenerClassName));
2450                                    }
2451    
2452                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2453                            }
2454                            catch (Exception e) {
2455                                    _log.error(e);
2456                            }
2457                    }
2458            }
2459    
2460            public void destroy() {
2461                    EntityCacheUtil.removeCache(ShoppingCategoryImpl.class.getName());
2462                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2463                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2464                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2465            }
2466    
2467            private static final String _SQL_SELECT_SHOPPINGCATEGORY = "SELECT shoppingCategory FROM ShoppingCategory shoppingCategory";
2468            private static final String _SQL_SELECT_SHOPPINGCATEGORY_WHERE = "SELECT shoppingCategory FROM ShoppingCategory shoppingCategory WHERE ";
2469            private static final String _SQL_COUNT_SHOPPINGCATEGORY = "SELECT COUNT(shoppingCategory) FROM ShoppingCategory shoppingCategory";
2470            private static final String _SQL_COUNT_SHOPPINGCATEGORY_WHERE = "SELECT COUNT(shoppingCategory) FROM ShoppingCategory shoppingCategory WHERE ";
2471            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "shoppingCategory.categoryId";
2472            private static final String _FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE = "SELECT DISTINCT {shoppingCategory.*} FROM ShoppingCategory shoppingCategory WHERE ";
2473            private static final String _FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
2474                    "SELECT {ShoppingCategory.*} FROM (SELECT DISTINCT shoppingCategory.categoryId FROM ShoppingCategory shoppingCategory WHERE ";
2475            private static final String _FILTER_SQL_SELECT_SHOPPINGCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
2476                    ") TEMP_TABLE INNER JOIN ShoppingCategory ON TEMP_TABLE.categoryId = ShoppingCategory.categoryId";
2477            private static final String _FILTER_SQL_COUNT_SHOPPINGCATEGORY_WHERE = "SELECT COUNT(DISTINCT shoppingCategory.categoryId) AS COUNT_VALUE FROM ShoppingCategory shoppingCategory WHERE ";
2478            private static final String _FILTER_ENTITY_ALIAS = "shoppingCategory";
2479            private static final String _FILTER_ENTITY_TABLE = "ShoppingCategory";
2480            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingCategory.";
2481            private static final String _ORDER_BY_ENTITY_TABLE = "ShoppingCategory.";
2482            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingCategory exists with the primary key ";
2483            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingCategory exists with the key {";
2484            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2485            private static Log _log = LogFactoryUtil.getLog(ShoppingCategoryPersistenceImpl.class);
2486            private static ShoppingCategory _nullShoppingCategory = new ShoppingCategoryImpl() {
2487                            @Override
2488                            public Object clone() {
2489                                    return this;
2490                            }
2491    
2492                            @Override
2493                            public CacheModel<ShoppingCategory> toCacheModel() {
2494                                    return _nullShoppingCategoryCacheModel;
2495                            }
2496                    };
2497    
2498            private static CacheModel<ShoppingCategory> _nullShoppingCategoryCacheModel = new CacheModel<ShoppingCategory>() {
2499                            @Override
2500                            public ShoppingCategory toEntityModel() {
2501                                    return _nullShoppingCategory;
2502                            }
2503                    };
2504    }