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