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