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