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