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