001    /**
002     * Copyright (c) 2000-2010 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.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
039    import com.liferay.portal.service.persistence.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.ResourcePersistence;
041    import com.liferay.portal.service.persistence.UserPersistence;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.shopping.NoSuchCategoryException;
045    import com.liferay.portlet.shopping.model.ShoppingCategory;
046    import com.liferay.portlet.shopping.model.impl.ShoppingCategoryImpl;
047    import com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence for the shopping category service.
057     *
058     * <p>
059     * Never modify this class directly. Modify <code>service.xml</code> and rerun ServiceBuilder to regnerate this class.
060     * </p>
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see ShoppingCategoryPersistence
068     * @see ShoppingCategoryUtil
069     * @generated
070     */
071    public class ShoppingCategoryPersistenceImpl extends BasePersistenceImpl<ShoppingCategory>
072            implements ShoppingCategoryPersistence {
073            public static final String FINDER_CLASS_NAME_ENTITY = ShoppingCategoryImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075                    ".List";
076            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
077                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
078                            FINDER_CLASS_NAME_LIST, "findByGroupId",
079                            new String[] {
080                                    Long.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
086                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
087                            FINDER_CLASS_NAME_LIST, "countByGroupId",
088                            new String[] { Long.class.getName() });
089            public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
090                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
091                            FINDER_CLASS_NAME_LIST, "findByG_P",
092                            new String[] {
093                                    Long.class.getName(), Long.class.getName(),
094                                    
095                            "java.lang.Integer", "java.lang.Integer",
096                                    "com.liferay.portal.kernel.util.OrderByComparator"
097                            });
098            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
099                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
100                            FINDER_CLASS_NAME_LIST, "countByG_P",
101                            new String[] { Long.class.getName(), Long.class.getName() });
102            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
103                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
104                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
105            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
106                            ShoppingCategoryModelImpl.FINDER_CACHE_ENABLED,
107                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
108    
109            /**
110             * Caches the shopping category in the entity cache if it is enabled.
111             *
112             * @param shoppingCategory the shopping category to cache
113             */
114            public void cacheResult(ShoppingCategory shoppingCategory) {
115                    EntityCacheUtil.putResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
116                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey(),
117                            shoppingCategory);
118            }
119    
120            /**
121             * Caches the shopping categories in the entity cache if it is enabled.
122             *
123             * @param shoppingCategories the shopping categories to cache
124             */
125            public void cacheResult(List<ShoppingCategory> shoppingCategories) {
126                    for (ShoppingCategory shoppingCategory : shoppingCategories) {
127                            if (EntityCacheUtil.getResult(
128                                                    ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
129                                                    ShoppingCategoryImpl.class,
130                                                    shoppingCategory.getPrimaryKey(), this) == null) {
131                                    cacheResult(shoppingCategory);
132                            }
133                    }
134            }
135    
136            /**
137             * Clears the cache for all shopping categories.
138             *
139             * <p>
140             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
141             * </p>
142             */
143            public void clearCache() {
144                    CacheRegistryUtil.clear(ShoppingCategoryImpl.class.getName());
145                    EntityCacheUtil.clearCache(ShoppingCategoryImpl.class.getName());
146                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
147                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
148            }
149    
150            /**
151             * Clears the cache for the shopping category.
152             *
153             * <p>
154             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
155             * </p>
156             */
157            public void clearCache(ShoppingCategory shoppingCategory) {
158                    EntityCacheUtil.removeResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
159                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey());
160            }
161    
162            /**
163             * Creates a new shopping category with the primary key.
164             *
165             * @param categoryId the primary key for the new shopping category
166             * @return the new shopping category
167             */
168            public ShoppingCategory create(long categoryId) {
169                    ShoppingCategory shoppingCategory = new ShoppingCategoryImpl();
170    
171                    shoppingCategory.setNew(true);
172                    shoppingCategory.setPrimaryKey(categoryId);
173    
174                    return shoppingCategory;
175            }
176    
177            /**
178             * Removes the shopping category with the primary key from the database. Also notifies the appropriate model listeners.
179             *
180             * @param primaryKey the primary key of the shopping category to remove
181             * @return the shopping category that was removed
182             * @throws com.liferay.portal.NoSuchModelException if a shopping category with the primary key could not be found
183             * @throws SystemException if a system exception occurred
184             */
185            public ShoppingCategory remove(Serializable primaryKey)
186                    throws NoSuchModelException, SystemException {
187                    return remove(((Long)primaryKey).longValue());
188            }
189    
190            /**
191             * Removes the shopping category with the primary key from the database. Also notifies the appropriate model listeners.
192             *
193             * @param categoryId the primary key of the shopping category to remove
194             * @return the shopping category that was removed
195             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
196             * @throws SystemException if a system exception occurred
197             */
198            public ShoppingCategory remove(long categoryId)
199                    throws NoSuchCategoryException, SystemException {
200                    Session session = null;
201    
202                    try {
203                            session = openSession();
204    
205                            ShoppingCategory shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
206                                            new Long(categoryId));
207    
208                            if (shoppingCategory == null) {
209                                    if (_log.isWarnEnabled()) {
210                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
211                                    }
212    
213                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
214                                            categoryId);
215                            }
216    
217                            return remove(shoppingCategory);
218                    }
219                    catch (NoSuchCategoryException nsee) {
220                            throw nsee;
221                    }
222                    catch (Exception e) {
223                            throw processException(e);
224                    }
225                    finally {
226                            closeSession(session);
227                    }
228            }
229    
230            protected ShoppingCategory removeImpl(ShoppingCategory shoppingCategory)
231                    throws SystemException {
232                    shoppingCategory = toUnwrappedModel(shoppingCategory);
233    
234                    Session session = null;
235    
236                    try {
237                            session = openSession();
238    
239                            if (shoppingCategory.isCachedModel() ||
240                                            BatchSessionUtil.isEnabled()) {
241                                    Object staleObject = session.get(ShoppingCategoryImpl.class,
242                                                    shoppingCategory.getPrimaryKeyObj());
243    
244                                    if (staleObject != null) {
245                                            session.evict(staleObject);
246                                    }
247                            }
248    
249                            session.delete(shoppingCategory);
250    
251                            session.flush();
252                    }
253                    catch (Exception e) {
254                            throw processException(e);
255                    }
256                    finally {
257                            closeSession(session);
258                    }
259    
260                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
261    
262                    EntityCacheUtil.removeResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
263                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey());
264    
265                    return shoppingCategory;
266            }
267    
268            public ShoppingCategory updateImpl(
269                    com.liferay.portlet.shopping.model.ShoppingCategory shoppingCategory,
270                    boolean merge) throws SystemException {
271                    shoppingCategory = toUnwrappedModel(shoppingCategory);
272    
273                    Session session = null;
274    
275                    try {
276                            session = openSession();
277    
278                            BatchSessionUtil.update(session, shoppingCategory, merge);
279    
280                            shoppingCategory.setNew(false);
281                    }
282                    catch (Exception e) {
283                            throw processException(e);
284                    }
285                    finally {
286                            closeSession(session);
287                    }
288    
289                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
290    
291                    EntityCacheUtil.putResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
292                            ShoppingCategoryImpl.class, shoppingCategory.getPrimaryKey(),
293                            shoppingCategory);
294    
295                    return shoppingCategory;
296            }
297    
298            protected ShoppingCategory toUnwrappedModel(
299                    ShoppingCategory shoppingCategory) {
300                    if (shoppingCategory instanceof ShoppingCategoryImpl) {
301                            return shoppingCategory;
302                    }
303    
304                    ShoppingCategoryImpl shoppingCategoryImpl = new ShoppingCategoryImpl();
305    
306                    shoppingCategoryImpl.setNew(shoppingCategory.isNew());
307                    shoppingCategoryImpl.setPrimaryKey(shoppingCategory.getPrimaryKey());
308    
309                    shoppingCategoryImpl.setCategoryId(shoppingCategory.getCategoryId());
310                    shoppingCategoryImpl.setGroupId(shoppingCategory.getGroupId());
311                    shoppingCategoryImpl.setCompanyId(shoppingCategory.getCompanyId());
312                    shoppingCategoryImpl.setUserId(shoppingCategory.getUserId());
313                    shoppingCategoryImpl.setUserName(shoppingCategory.getUserName());
314                    shoppingCategoryImpl.setCreateDate(shoppingCategory.getCreateDate());
315                    shoppingCategoryImpl.setModifiedDate(shoppingCategory.getModifiedDate());
316                    shoppingCategoryImpl.setParentCategoryId(shoppingCategory.getParentCategoryId());
317                    shoppingCategoryImpl.setName(shoppingCategory.getName());
318                    shoppingCategoryImpl.setDescription(shoppingCategory.getDescription());
319    
320                    return shoppingCategoryImpl;
321            }
322    
323            /**
324             * Finds the shopping category with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
325             *
326             * @param primaryKey the primary key of the shopping category to find
327             * @return the shopping category
328             * @throws com.liferay.portal.NoSuchModelException if a shopping category with the primary key could not be found
329             * @throws SystemException if a system exception occurred
330             */
331            public ShoppingCategory findByPrimaryKey(Serializable primaryKey)
332                    throws NoSuchModelException, SystemException {
333                    return findByPrimaryKey(((Long)primaryKey).longValue());
334            }
335    
336            /**
337             * Finds the shopping category with the primary key or throws a {@link com.liferay.portlet.shopping.NoSuchCategoryException} if it could not be found.
338             *
339             * @param categoryId the primary key of the shopping category to find
340             * @return the shopping category
341             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
342             * @throws SystemException if a system exception occurred
343             */
344            public ShoppingCategory findByPrimaryKey(long categoryId)
345                    throws NoSuchCategoryException, SystemException {
346                    ShoppingCategory shoppingCategory = fetchByPrimaryKey(categoryId);
347    
348                    if (shoppingCategory == null) {
349                            if (_log.isWarnEnabled()) {
350                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
351                            }
352    
353                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
354                                    categoryId);
355                    }
356    
357                    return shoppingCategory;
358            }
359    
360            /**
361             * Finds the shopping category with the primary key or returns <code>null</code> if it could not be found.
362             *
363             * @param primaryKey the primary key of the shopping category to find
364             * @return the shopping category, or <code>null</code> if a shopping category with the primary key could not be found
365             * @throws SystemException if a system exception occurred
366             */
367            public ShoppingCategory fetchByPrimaryKey(Serializable primaryKey)
368                    throws SystemException {
369                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
370            }
371    
372            /**
373             * Finds the shopping category with the primary key or returns <code>null</code> if it could not be found.
374             *
375             * @param categoryId the primary key of the shopping category to find
376             * @return the shopping category, or <code>null</code> if a shopping category with the primary key could not be found
377             * @throws SystemException if a system exception occurred
378             */
379            public ShoppingCategory fetchByPrimaryKey(long categoryId)
380                    throws SystemException {
381                    ShoppingCategory shoppingCategory = (ShoppingCategory)EntityCacheUtil.getResult(ShoppingCategoryModelImpl.ENTITY_CACHE_ENABLED,
382                                    ShoppingCategoryImpl.class, categoryId, this);
383    
384                    if (shoppingCategory == null) {
385                            Session session = null;
386    
387                            try {
388                                    session = openSession();
389    
390                                    shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
391                                                    new Long(categoryId));
392                            }
393                            catch (Exception e) {
394                                    throw processException(e);
395                            }
396                            finally {
397                                    if (shoppingCategory != null) {
398                                            cacheResult(shoppingCategory);
399                                    }
400    
401                                    closeSession(session);
402                            }
403                    }
404    
405                    return shoppingCategory;
406            }
407    
408            /**
409             * Finds all the shopping categories where groupId = &#63;.
410             *
411             * @param groupId the group id to search with
412             * @return the matching shopping categories
413             * @throws SystemException if a system exception occurred
414             */
415            public List<ShoppingCategory> findByGroupId(long groupId)
416                    throws SystemException {
417                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
418            }
419    
420            /**
421             * Finds a range of all the shopping categories where groupId = &#63;.
422             *
423             * <p>
424             * 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.
425             * </p>
426             *
427             * @param groupId the group id to search with
428             * @param start the lower bound of the range of shopping categories to return
429             * @param end the upper bound of the range of shopping categories to return (not inclusive)
430             * @return the range of matching shopping categories
431             * @throws SystemException if a system exception occurred
432             */
433            public List<ShoppingCategory> findByGroupId(long groupId, int start, int end)
434                    throws SystemException {
435                    return findByGroupId(groupId, start, end, null);
436            }
437    
438            /**
439             * Finds an ordered range of all the shopping categories where groupId = &#63;.
440             *
441             * <p>
442             * 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.
443             * </p>
444             *
445             * @param groupId the group id to search with
446             * @param start the lower bound of the range of shopping categories to return
447             * @param end the upper bound of the range of shopping categories to return (not inclusive)
448             * @param orderByComparator the comparator to order the results by
449             * @return the ordered range of matching shopping categories
450             * @throws SystemException if a system exception occurred
451             */
452            public List<ShoppingCategory> findByGroupId(long groupId, int start,
453                    int end, OrderByComparator orderByComparator) throws SystemException {
454                    Object[] finderArgs = new Object[] {
455                                    groupId,
456                                    
457                                    String.valueOf(start), String.valueOf(end),
458                                    String.valueOf(orderByComparator)
459                            };
460    
461                    List<ShoppingCategory> list = (List<ShoppingCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
462                                    finderArgs, this);
463    
464                    if (list == null) {
465                            Session session = null;
466    
467                            try {
468                                    session = openSession();
469    
470                                    StringBundler query = null;
471    
472                                    if (orderByComparator != null) {
473                                            query = new StringBundler(3 +
474                                                            (orderByComparator.getOrderByFields().length * 3));
475                                    }
476                                    else {
477                                            query = new StringBundler(3);
478                                    }
479    
480                                    query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
481    
482                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
483    
484                                    if (orderByComparator != null) {
485                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
486                                                    orderByComparator);
487                                    }
488    
489                                    else {
490                                            query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
491                                    }
492    
493                                    String sql = query.toString();
494    
495                                    Query q = session.createQuery(sql);
496    
497                                    QueryPos qPos = QueryPos.getInstance(q);
498    
499                                    qPos.add(groupId);
500    
501                                    list = (List<ShoppingCategory>)QueryUtil.list(q, getDialect(),
502                                                    start, end);
503                            }
504                            catch (Exception e) {
505                                    throw processException(e);
506                            }
507                            finally {
508                                    if (list == null) {
509                                            list = new ArrayList<ShoppingCategory>();
510                                    }
511    
512                                    cacheResult(list);
513    
514                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
515                                            finderArgs, list);
516    
517                                    closeSession(session);
518                            }
519                    }
520    
521                    return list;
522            }
523    
524            /**
525             * Finds the first shopping category in the ordered set where groupId = &#63;.
526             *
527             * <p>
528             * 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.
529             * </p>
530             *
531             * @param groupId the group id to search with
532             * @param orderByComparator the comparator to order the set by
533             * @return the first matching shopping category
534             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
535             * @throws SystemException if a system exception occurred
536             */
537            public ShoppingCategory findByGroupId_First(long groupId,
538                    OrderByComparator orderByComparator)
539                    throws NoSuchCategoryException, SystemException {
540                    List<ShoppingCategory> list = findByGroupId(groupId, 0, 1,
541                                    orderByComparator);
542    
543                    if (list.isEmpty()) {
544                            StringBundler msg = new StringBundler(4);
545    
546                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
547    
548                            msg.append("groupId=");
549                            msg.append(groupId);
550    
551                            msg.append(StringPool.CLOSE_CURLY_BRACE);
552    
553                            throw new NoSuchCategoryException(msg.toString());
554                    }
555                    else {
556                            return list.get(0);
557                    }
558            }
559    
560            /**
561             * Finds the last shopping category in the ordered set where groupId = &#63;.
562             *
563             * <p>
564             * 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.
565             * </p>
566             *
567             * @param groupId the group id to search with
568             * @param orderByComparator the comparator to order the set by
569             * @return the last matching shopping category
570             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
571             * @throws SystemException if a system exception occurred
572             */
573            public ShoppingCategory findByGroupId_Last(long groupId,
574                    OrderByComparator orderByComparator)
575                    throws NoSuchCategoryException, SystemException {
576                    int count = countByGroupId(groupId);
577    
578                    List<ShoppingCategory> list = findByGroupId(groupId, count - 1, count,
579                                    orderByComparator);
580    
581                    if (list.isEmpty()) {
582                            StringBundler msg = new StringBundler(4);
583    
584                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
585    
586                            msg.append("groupId=");
587                            msg.append(groupId);
588    
589                            msg.append(StringPool.CLOSE_CURLY_BRACE);
590    
591                            throw new NoSuchCategoryException(msg.toString());
592                    }
593                    else {
594                            return list.get(0);
595                    }
596            }
597    
598            /**
599             * Finds the shopping categories before and after the current shopping category in the ordered set where groupId = &#63;.
600             *
601             * <p>
602             * 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.
603             * </p>
604             *
605             * @param categoryId the primary key of the current shopping category
606             * @param groupId the group id to search with
607             * @param orderByComparator the comparator to order the set by
608             * @return the previous, current, and next shopping category
609             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
610             * @throws SystemException if a system exception occurred
611             */
612            public ShoppingCategory[] findByGroupId_PrevAndNext(long categoryId,
613                    long groupId, OrderByComparator orderByComparator)
614                    throws NoSuchCategoryException, SystemException {
615                    ShoppingCategory shoppingCategory = findByPrimaryKey(categoryId);
616    
617                    Session session = null;
618    
619                    try {
620                            session = openSession();
621    
622                            ShoppingCategory[] array = new ShoppingCategoryImpl[3];
623    
624                            array[0] = getByGroupId_PrevAndNext(session, shoppingCategory,
625                                            groupId, orderByComparator, true);
626    
627                            array[1] = shoppingCategory;
628    
629                            array[2] = getByGroupId_PrevAndNext(session, shoppingCategory,
630                                            groupId, orderByComparator, false);
631    
632                            return array;
633                    }
634                    catch (Exception e) {
635                            throw processException(e);
636                    }
637                    finally {
638                            closeSession(session);
639                    }
640            }
641    
642            protected ShoppingCategory getByGroupId_PrevAndNext(Session session,
643                    ShoppingCategory shoppingCategory, long groupId,
644                    OrderByComparator orderByComparator, boolean previous) {
645                    StringBundler query = null;
646    
647                    if (orderByComparator != null) {
648                            query = new StringBundler(6 +
649                                            (orderByComparator.getOrderByFields().length * 6));
650                    }
651                    else {
652                            query = new StringBundler(3);
653                    }
654    
655                    query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
656    
657                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
658    
659                    if (orderByComparator != null) {
660                            String[] orderByFields = orderByComparator.getOrderByFields();
661    
662                            if (orderByFields.length > 0) {
663                                    query.append(WHERE_AND);
664                            }
665    
666                            for (int i = 0; i < orderByFields.length; i++) {
667                                    query.append(_ORDER_BY_ENTITY_ALIAS);
668                                    query.append(orderByFields[i]);
669    
670                                    if ((i + 1) < orderByFields.length) {
671                                            if (orderByComparator.isAscending() ^ previous) {
672                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
673                                            }
674                                            else {
675                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
676                                            }
677                                    }
678                                    else {
679                                            if (orderByComparator.isAscending() ^ previous) {
680                                                    query.append(WHERE_GREATER_THAN);
681                                            }
682                                            else {
683                                                    query.append(WHERE_LESSER_THAN);
684                                            }
685                                    }
686                            }
687    
688                            query.append(ORDER_BY_CLAUSE);
689    
690                            for (int i = 0; i < orderByFields.length; i++) {
691                                    query.append(_ORDER_BY_ENTITY_ALIAS);
692                                    query.append(orderByFields[i]);
693    
694                                    if ((i + 1) < orderByFields.length) {
695                                            if (orderByComparator.isAscending() ^ previous) {
696                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
697                                            }
698                                            else {
699                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
700                                            }
701                                    }
702                                    else {
703                                            if (orderByComparator.isAscending() ^ previous) {
704                                                    query.append(ORDER_BY_ASC);
705                                            }
706                                            else {
707                                                    query.append(ORDER_BY_DESC);
708                                            }
709                                    }
710                            }
711                    }
712    
713                    else {
714                            query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
715                    }
716    
717                    String sql = query.toString();
718    
719                    Query q = session.createQuery(sql);
720    
721                    q.setFirstResult(0);
722                    q.setMaxResults(2);
723    
724                    QueryPos qPos = QueryPos.getInstance(q);
725    
726                    qPos.add(groupId);
727    
728                    if (orderByComparator != null) {
729                            Object[] values = orderByComparator.getOrderByValues(shoppingCategory);
730    
731                            for (Object value : values) {
732                                    qPos.add(value);
733                            }
734                    }
735    
736                    List<ShoppingCategory> list = q.list();
737    
738                    if (list.size() == 2) {
739                            return list.get(1);
740                    }
741                    else {
742                            return null;
743                    }
744            }
745    
746            /**
747             * Filters by the user's permissions and finds all the shopping categories where groupId = &#63;.
748             *
749             * @param groupId the group id to search with
750             * @return the matching shopping categories that the user has permission to view
751             * @throws SystemException if a system exception occurred
752             */
753            public List<ShoppingCategory> filterFindByGroupId(long groupId)
754                    throws SystemException {
755                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
756                            QueryUtil.ALL_POS, null);
757            }
758    
759            /**
760             * Filters by the user's permissions and finds a range of all the shopping categories where groupId = &#63;.
761             *
762             * <p>
763             * 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.
764             * </p>
765             *
766             * @param groupId the group id to search with
767             * @param start the lower bound of the range of shopping categories to return
768             * @param end the upper bound of the range of shopping categories to return (not inclusive)
769             * @return the range of matching shopping categories that the user has permission to view
770             * @throws SystemException if a system exception occurred
771             */
772            public List<ShoppingCategory> filterFindByGroupId(long groupId, int start,
773                    int end) throws SystemException {
774                    return filterFindByGroupId(groupId, start, end, null);
775            }
776    
777            /**
778             * Filters by the user's permissions and finds an ordered range of all the shopping categories where groupId = &#63;.
779             *
780             * <p>
781             * 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.
782             * </p>
783             *
784             * @param groupId the group id to search with
785             * @param start the lower bound of the range of shopping categories to return
786             * @param end the upper bound of the range of shopping categories to return (not inclusive)
787             * @param orderByComparator the comparator to order the results by
788             * @return the ordered range of matching shopping categories that the user has permission to view
789             * @throws SystemException if a system exception occurred
790             */
791            public List<ShoppingCategory> filterFindByGroupId(long groupId, int start,
792                    int end, OrderByComparator orderByComparator) throws SystemException {
793                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
794                            return findByGroupId(groupId, start, end, orderByComparator);
795                    }
796    
797                    Session session = null;
798    
799                    try {
800                            session = openSession();
801    
802                            StringBundler query = null;
803    
804                            if (orderByComparator != null) {
805                                    query = new StringBundler(3 +
806                                                    (orderByComparator.getOrderByFields().length * 3));
807                            }
808                            else {
809                                    query = new StringBundler(3);
810                            }
811    
812                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
813    
814                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
815    
816                            if (orderByComparator != null) {
817                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
818                                            orderByComparator);
819                            }
820    
821                            else {
822                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
823                            }
824    
825                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
826                                            ShoppingCategory.class.getName(), _FILTER_COLUMN_PK,
827                                            _FILTER_COLUMN_USERID, groupId);
828    
829                            SQLQuery q = session.createSQLQuery(sql);
830    
831                            q.addEntity(_FILTER_ENTITY_ALIAS, ShoppingCategoryImpl.class);
832    
833                            QueryPos qPos = QueryPos.getInstance(q);
834    
835                            qPos.add(groupId);
836    
837                            return (List<ShoppingCategory>)QueryUtil.list(q, getDialect(),
838                                    start, end);
839                    }
840                    catch (Exception e) {
841                            throw processException(e);
842                    }
843                    finally {
844                            closeSession(session);
845                    }
846            }
847    
848            /**
849             * Finds all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
850             *
851             * @param groupId the group id to search with
852             * @param parentCategoryId the parent category id to search with
853             * @return the matching shopping categories
854             * @throws SystemException if a system exception occurred
855             */
856            public List<ShoppingCategory> findByG_P(long groupId, long parentCategoryId)
857                    throws SystemException {
858                    return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
859                            QueryUtil.ALL_POS, null);
860            }
861    
862            /**
863             * Finds a range of all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
864             *
865             * <p>
866             * 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.
867             * </p>
868             *
869             * @param groupId the group id to search with
870             * @param parentCategoryId the parent category id to search with
871             * @param start the lower bound of the range of shopping categories to return
872             * @param end the upper bound of the range of shopping categories to return (not inclusive)
873             * @return the range of matching shopping categories
874             * @throws SystemException if a system exception occurred
875             */
876            public List<ShoppingCategory> findByG_P(long groupId,
877                    long parentCategoryId, int start, int end) throws SystemException {
878                    return findByG_P(groupId, parentCategoryId, start, end, null);
879            }
880    
881            /**
882             * Finds an ordered range of all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
883             *
884             * <p>
885             * 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.
886             * </p>
887             *
888             * @param groupId the group id to search with
889             * @param parentCategoryId the parent category id to search with
890             * @param start the lower bound of the range of shopping categories to return
891             * @param end the upper bound of the range of shopping categories to return (not inclusive)
892             * @param orderByComparator the comparator to order the results by
893             * @return the ordered range of matching shopping categories
894             * @throws SystemException if a system exception occurred
895             */
896            public List<ShoppingCategory> findByG_P(long groupId,
897                    long parentCategoryId, int start, int end,
898                    OrderByComparator orderByComparator) throws SystemException {
899                    Object[] finderArgs = new Object[] {
900                                    groupId, parentCategoryId,
901                                    
902                                    String.valueOf(start), String.valueOf(end),
903                                    String.valueOf(orderByComparator)
904                            };
905    
906                    List<ShoppingCategory> list = (List<ShoppingCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
907                                    finderArgs, this);
908    
909                    if (list == null) {
910                            Session session = null;
911    
912                            try {
913                                    session = openSession();
914    
915                                    StringBundler query = null;
916    
917                                    if (orderByComparator != null) {
918                                            query = new StringBundler(4 +
919                                                            (orderByComparator.getOrderByFields().length * 3));
920                                    }
921                                    else {
922                                            query = new StringBundler(4);
923                                    }
924    
925                                    query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
926    
927                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
928    
929                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
930    
931                                    if (orderByComparator != null) {
932                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
933                                                    orderByComparator);
934                                    }
935    
936                                    else {
937                                            query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
938                                    }
939    
940                                    String sql = query.toString();
941    
942                                    Query q = session.createQuery(sql);
943    
944                                    QueryPos qPos = QueryPos.getInstance(q);
945    
946                                    qPos.add(groupId);
947    
948                                    qPos.add(parentCategoryId);
949    
950                                    list = (List<ShoppingCategory>)QueryUtil.list(q, getDialect(),
951                                                    start, end);
952                            }
953                            catch (Exception e) {
954                                    throw processException(e);
955                            }
956                            finally {
957                                    if (list == null) {
958                                            list = new ArrayList<ShoppingCategory>();
959                                    }
960    
961                                    cacheResult(list);
962    
963                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
964                                            list);
965    
966                                    closeSession(session);
967                            }
968                    }
969    
970                    return list;
971            }
972    
973            /**
974             * Finds the first shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
975             *
976             * <p>
977             * 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.
978             * </p>
979             *
980             * @param groupId the group id to search with
981             * @param parentCategoryId the parent category id to search with
982             * @param orderByComparator the comparator to order the set by
983             * @return the first matching shopping category
984             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
985             * @throws SystemException if a system exception occurred
986             */
987            public ShoppingCategory findByG_P_First(long groupId,
988                    long parentCategoryId, OrderByComparator orderByComparator)
989                    throws NoSuchCategoryException, SystemException {
990                    List<ShoppingCategory> list = findByG_P(groupId, parentCategoryId, 0,
991                                    1, orderByComparator);
992    
993                    if (list.isEmpty()) {
994                            StringBundler msg = new StringBundler(6);
995    
996                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
997    
998                            msg.append("groupId=");
999                            msg.append(groupId);
1000    
1001                            msg.append(", parentCategoryId=");
1002                            msg.append(parentCategoryId);
1003    
1004                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1005    
1006                            throw new NoSuchCategoryException(msg.toString());
1007                    }
1008                    else {
1009                            return list.get(0);
1010                    }
1011            }
1012    
1013            /**
1014             * Finds the last shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1015             *
1016             * <p>
1017             * 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.
1018             * </p>
1019             *
1020             * @param groupId the group id to search with
1021             * @param parentCategoryId the parent category id to search with
1022             * @param orderByComparator the comparator to order the set by
1023             * @return the last matching shopping category
1024             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a matching shopping category could not be found
1025             * @throws SystemException if a system exception occurred
1026             */
1027            public ShoppingCategory findByG_P_Last(long groupId, long parentCategoryId,
1028                    OrderByComparator orderByComparator)
1029                    throws NoSuchCategoryException, SystemException {
1030                    int count = countByG_P(groupId, parentCategoryId);
1031    
1032                    List<ShoppingCategory> list = findByG_P(groupId, parentCategoryId,
1033                                    count - 1, count, orderByComparator);
1034    
1035                    if (list.isEmpty()) {
1036                            StringBundler msg = new StringBundler(6);
1037    
1038                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1039    
1040                            msg.append("groupId=");
1041                            msg.append(groupId);
1042    
1043                            msg.append(", parentCategoryId=");
1044                            msg.append(parentCategoryId);
1045    
1046                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1047    
1048                            throw new NoSuchCategoryException(msg.toString());
1049                    }
1050                    else {
1051                            return list.get(0);
1052                    }
1053            }
1054    
1055            /**
1056             * Finds the shopping categories before and after the current shopping category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1057             *
1058             * <p>
1059             * 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.
1060             * </p>
1061             *
1062             * @param categoryId the primary key of the current shopping category
1063             * @param groupId the group id to search with
1064             * @param parentCategoryId the parent category id to search with
1065             * @param orderByComparator the comparator to order the set by
1066             * @return the previous, current, and next shopping category
1067             * @throws com.liferay.portlet.shopping.NoSuchCategoryException if a shopping category with the primary key could not be found
1068             * @throws SystemException if a system exception occurred
1069             */
1070            public ShoppingCategory[] findByG_P_PrevAndNext(long categoryId,
1071                    long groupId, long parentCategoryId, OrderByComparator orderByComparator)
1072                    throws NoSuchCategoryException, SystemException {
1073                    ShoppingCategory shoppingCategory = findByPrimaryKey(categoryId);
1074    
1075                    Session session = null;
1076    
1077                    try {
1078                            session = openSession();
1079    
1080                            ShoppingCategory[] array = new ShoppingCategoryImpl[3];
1081    
1082                            array[0] = getByG_P_PrevAndNext(session, shoppingCategory, groupId,
1083                                            parentCategoryId, orderByComparator, true);
1084    
1085                            array[1] = shoppingCategory;
1086    
1087                            array[2] = getByG_P_PrevAndNext(session, shoppingCategory, groupId,
1088                                            parentCategoryId, orderByComparator, false);
1089    
1090                            return array;
1091                    }
1092                    catch (Exception e) {
1093                            throw processException(e);
1094                    }
1095                    finally {
1096                            closeSession(session);
1097                    }
1098            }
1099    
1100            protected ShoppingCategory getByG_P_PrevAndNext(Session session,
1101                    ShoppingCategory shoppingCategory, long groupId, long parentCategoryId,
1102                    OrderByComparator orderByComparator, boolean previous) {
1103                    StringBundler query = null;
1104    
1105                    if (orderByComparator != null) {
1106                            query = new StringBundler(6 +
1107                                            (orderByComparator.getOrderByFields().length * 6));
1108                    }
1109                    else {
1110                            query = new StringBundler(3);
1111                    }
1112    
1113                    query.append(_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
1114    
1115                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1116    
1117                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1118    
1119                    if (orderByComparator != null) {
1120                            String[] orderByFields = orderByComparator.getOrderByFields();
1121    
1122                            if (orderByFields.length > 0) {
1123                                    query.append(WHERE_AND);
1124                            }
1125    
1126                            for (int i = 0; i < orderByFields.length; i++) {
1127                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1128                                    query.append(orderByFields[i]);
1129    
1130                                    if ((i + 1) < orderByFields.length) {
1131                                            if (orderByComparator.isAscending() ^ previous) {
1132                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1133                                            }
1134                                            else {
1135                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1136                                            }
1137                                    }
1138                                    else {
1139                                            if (orderByComparator.isAscending() ^ previous) {
1140                                                    query.append(WHERE_GREATER_THAN);
1141                                            }
1142                                            else {
1143                                                    query.append(WHERE_LESSER_THAN);
1144                                            }
1145                                    }
1146                            }
1147    
1148                            query.append(ORDER_BY_CLAUSE);
1149    
1150                            for (int i = 0; i < orderByFields.length; i++) {
1151                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1152                                    query.append(orderByFields[i]);
1153    
1154                                    if ((i + 1) < orderByFields.length) {
1155                                            if (orderByComparator.isAscending() ^ previous) {
1156                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1157                                            }
1158                                            else {
1159                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1160                                            }
1161                                    }
1162                                    else {
1163                                            if (orderByComparator.isAscending() ^ previous) {
1164                                                    query.append(ORDER_BY_ASC);
1165                                            }
1166                                            else {
1167                                                    query.append(ORDER_BY_DESC);
1168                                            }
1169                                    }
1170                            }
1171                    }
1172    
1173                    else {
1174                            query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
1175                    }
1176    
1177                    String sql = query.toString();
1178    
1179                    Query q = session.createQuery(sql);
1180    
1181                    q.setFirstResult(0);
1182                    q.setMaxResults(2);
1183    
1184                    QueryPos qPos = QueryPos.getInstance(q);
1185    
1186                    qPos.add(groupId);
1187    
1188                    qPos.add(parentCategoryId);
1189    
1190                    if (orderByComparator != null) {
1191                            Object[] values = orderByComparator.getOrderByValues(shoppingCategory);
1192    
1193                            for (Object value : values) {
1194                                    qPos.add(value);
1195                            }
1196                    }
1197    
1198                    List<ShoppingCategory> list = q.list();
1199    
1200                    if (list.size() == 2) {
1201                            return list.get(1);
1202                    }
1203                    else {
1204                            return null;
1205                    }
1206            }
1207    
1208            /**
1209             * Filters by the user's permissions and finds all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1210             *
1211             * @param groupId the group id to search with
1212             * @param parentCategoryId the parent category id to search with
1213             * @return the matching shopping categories that the user has permission to view
1214             * @throws SystemException if a system exception occurred
1215             */
1216            public List<ShoppingCategory> filterFindByG_P(long groupId,
1217                    long parentCategoryId) throws SystemException {
1218                    return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
1219                            QueryUtil.ALL_POS, null);
1220            }
1221    
1222            /**
1223             * Filters by the user's permissions and finds a range of all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1224             *
1225             * <p>
1226             * 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.
1227             * </p>
1228             *
1229             * @param groupId the group id to search with
1230             * @param parentCategoryId the parent category id to search with
1231             * @param start the lower bound of the range of shopping categories to return
1232             * @param end the upper bound of the range of shopping categories to return (not inclusive)
1233             * @return the range of matching shopping categories that the user has permission to view
1234             * @throws SystemException if a system exception occurred
1235             */
1236            public List<ShoppingCategory> filterFindByG_P(long groupId,
1237                    long parentCategoryId, int start, int end) throws SystemException {
1238                    return filterFindByG_P(groupId, parentCategoryId, start, end, null);
1239            }
1240    
1241            /**
1242             * Filters by the user's permissions and finds an ordered range of all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1243             *
1244             * <p>
1245             * 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.
1246             * </p>
1247             *
1248             * @param groupId the group id to search with
1249             * @param parentCategoryId the parent category id to search with
1250             * @param start the lower bound of the range of shopping categories to return
1251             * @param end the upper bound of the range of shopping categories to return (not inclusive)
1252             * @param orderByComparator the comparator to order the results by
1253             * @return the ordered range of matching shopping categories that the user has permission to view
1254             * @throws SystemException if a system exception occurred
1255             */
1256            public List<ShoppingCategory> filterFindByG_P(long groupId,
1257                    long parentCategoryId, int start, int end,
1258                    OrderByComparator orderByComparator) throws SystemException {
1259                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1260                            return findByG_P(groupId, parentCategoryId, start, end,
1261                                    orderByComparator);
1262                    }
1263    
1264                    Session session = null;
1265    
1266                    try {
1267                            session = openSession();
1268    
1269                            StringBundler query = null;
1270    
1271                            if (orderByComparator != null) {
1272                                    query = new StringBundler(4 +
1273                                                    (orderByComparator.getOrderByFields().length * 3));
1274                            }
1275                            else {
1276                                    query = new StringBundler(4);
1277                            }
1278    
1279                            query.append(_FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE);
1280    
1281                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1282    
1283                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1284    
1285                            if (orderByComparator != null) {
1286                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1287                                            orderByComparator);
1288                            }
1289    
1290                            else {
1291                                    query.append(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
1292                            }
1293    
1294                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1295                                            ShoppingCategory.class.getName(), _FILTER_COLUMN_PK,
1296                                            _FILTER_COLUMN_USERID, groupId);
1297    
1298                            SQLQuery q = session.createSQLQuery(sql);
1299    
1300                            q.addEntity(_FILTER_ENTITY_ALIAS, ShoppingCategoryImpl.class);
1301    
1302                            QueryPos qPos = QueryPos.getInstance(q);
1303    
1304                            qPos.add(groupId);
1305    
1306                            qPos.add(parentCategoryId);
1307    
1308                            return (List<ShoppingCategory>)QueryUtil.list(q, getDialect(),
1309                                    start, end);
1310                    }
1311                    catch (Exception e) {
1312                            throw processException(e);
1313                    }
1314                    finally {
1315                            closeSession(session);
1316                    }
1317            }
1318    
1319            /**
1320             * Finds all the shopping categories.
1321             *
1322             * @return the shopping categories
1323             * @throws SystemException if a system exception occurred
1324             */
1325            public List<ShoppingCategory> findAll() throws SystemException {
1326                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1327            }
1328    
1329            /**
1330             * Finds a range of all the shopping categories.
1331             *
1332             * <p>
1333             * 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.
1334             * </p>
1335             *
1336             * @param start the lower bound of the range of shopping categories to return
1337             * @param end the upper bound of the range of shopping categories to return (not inclusive)
1338             * @return the range of shopping categories
1339             * @throws SystemException if a system exception occurred
1340             */
1341            public List<ShoppingCategory> findAll(int start, int end)
1342                    throws SystemException {
1343                    return findAll(start, end, null);
1344            }
1345    
1346            /**
1347             * Finds an ordered range of all the shopping categories.
1348             *
1349             * <p>
1350             * 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.
1351             * </p>
1352             *
1353             * @param start the lower bound of the range of shopping categories to return
1354             * @param end the upper bound of the range of shopping categories to return (not inclusive)
1355             * @param orderByComparator the comparator to order the results by
1356             * @return the ordered range of shopping categories
1357             * @throws SystemException if a system exception occurred
1358             */
1359            public List<ShoppingCategory> findAll(int start, int end,
1360                    OrderByComparator orderByComparator) throws SystemException {
1361                    Object[] finderArgs = new Object[] {
1362                                    String.valueOf(start), String.valueOf(end),
1363                                    String.valueOf(orderByComparator)
1364                            };
1365    
1366                    List<ShoppingCategory> list = (List<ShoppingCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1367                                    finderArgs, this);
1368    
1369                    if (list == null) {
1370                            Session session = null;
1371    
1372                            try {
1373                                    session = openSession();
1374    
1375                                    StringBundler query = null;
1376                                    String sql = null;
1377    
1378                                    if (orderByComparator != null) {
1379                                            query = new StringBundler(2 +
1380                                                            (orderByComparator.getOrderByFields().length * 3));
1381    
1382                                            query.append(_SQL_SELECT_SHOPPINGCATEGORY);
1383    
1384                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1385                                                    orderByComparator);
1386    
1387                                            sql = query.toString();
1388                                    }
1389                                    else {
1390                                            sql = _SQL_SELECT_SHOPPINGCATEGORY.concat(ShoppingCategoryModelImpl.ORDER_BY_JPQL);
1391                                    }
1392    
1393                                    Query q = session.createQuery(sql);
1394    
1395                                    if (orderByComparator == null) {
1396                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
1397                                                            getDialect(), start, end, false);
1398    
1399                                            Collections.sort(list);
1400                                    }
1401                                    else {
1402                                            list = (List<ShoppingCategory>)QueryUtil.list(q,
1403                                                            getDialect(), start, end);
1404                                    }
1405                            }
1406                            catch (Exception e) {
1407                                    throw processException(e);
1408                            }
1409                            finally {
1410                                    if (list == null) {
1411                                            list = new ArrayList<ShoppingCategory>();
1412                                    }
1413    
1414                                    cacheResult(list);
1415    
1416                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1417    
1418                                    closeSession(session);
1419                            }
1420                    }
1421    
1422                    return list;
1423            }
1424    
1425            /**
1426             * Removes all the shopping categories where groupId = &#63; from the database.
1427             *
1428             * @param groupId the group id to search with
1429             * @throws SystemException if a system exception occurred
1430             */
1431            public void removeByGroupId(long groupId) throws SystemException {
1432                    for (ShoppingCategory shoppingCategory : findByGroupId(groupId)) {
1433                            remove(shoppingCategory);
1434                    }
1435            }
1436    
1437            /**
1438             * Removes all the shopping categories where groupId = &#63; and parentCategoryId = &#63; from the database.
1439             *
1440             * @param groupId the group id to search with
1441             * @param parentCategoryId the parent category id to search with
1442             * @throws SystemException if a system exception occurred
1443             */
1444            public void removeByG_P(long groupId, long parentCategoryId)
1445                    throws SystemException {
1446                    for (ShoppingCategory shoppingCategory : findByG_P(groupId,
1447                                    parentCategoryId)) {
1448                            remove(shoppingCategory);
1449                    }
1450            }
1451    
1452            /**
1453             * Removes all the shopping categories from the database.
1454             *
1455             * @throws SystemException if a system exception occurred
1456             */
1457            public void removeAll() throws SystemException {
1458                    for (ShoppingCategory shoppingCategory : findAll()) {
1459                            remove(shoppingCategory);
1460                    }
1461            }
1462    
1463            /**
1464             * Counts all the shopping categories where groupId = &#63;.
1465             *
1466             * @param groupId the group id to search with
1467             * @return the number of matching shopping categories
1468             * @throws SystemException if a system exception occurred
1469             */
1470            public int countByGroupId(long groupId) throws SystemException {
1471                    Object[] finderArgs = new Object[] { groupId };
1472    
1473                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1474                                    finderArgs, this);
1475    
1476                    if (count == null) {
1477                            Session session = null;
1478    
1479                            try {
1480                                    session = openSession();
1481    
1482                                    StringBundler query = new StringBundler(2);
1483    
1484                                    query.append(_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
1485    
1486                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1487    
1488                                    String sql = query.toString();
1489    
1490                                    Query q = session.createQuery(sql);
1491    
1492                                    QueryPos qPos = QueryPos.getInstance(q);
1493    
1494                                    qPos.add(groupId);
1495    
1496                                    count = (Long)q.uniqueResult();
1497                            }
1498                            catch (Exception e) {
1499                                    throw processException(e);
1500                            }
1501                            finally {
1502                                    if (count == null) {
1503                                            count = Long.valueOf(0);
1504                                    }
1505    
1506                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1507                                            finderArgs, count);
1508    
1509                                    closeSession(session);
1510                            }
1511                    }
1512    
1513                    return count.intValue();
1514            }
1515    
1516            /**
1517             * Filters by the user's permissions and counts all the shopping categories where groupId = &#63;.
1518             *
1519             * @param groupId the group id to search with
1520             * @return the number of matching shopping categories that the user has permission to view
1521             * @throws SystemException if a system exception occurred
1522             */
1523            public int filterCountByGroupId(long groupId) throws SystemException {
1524                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1525                            return countByGroupId(groupId);
1526                    }
1527    
1528                    Session session = null;
1529    
1530                    try {
1531                            session = openSession();
1532    
1533                            StringBundler query = new StringBundler(2);
1534    
1535                            query.append(_FILTER_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
1536    
1537                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1538    
1539                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1540                                            ShoppingCategory.class.getName(), _FILTER_COLUMN_PK,
1541                                            _FILTER_COLUMN_USERID, groupId);
1542    
1543                            SQLQuery q = session.createSQLQuery(sql);
1544    
1545                            q.addScalar(COUNT_COLUMN_NAME,
1546                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1547    
1548                            QueryPos qPos = QueryPos.getInstance(q);
1549    
1550                            qPos.add(groupId);
1551    
1552                            Long count = (Long)q.uniqueResult();
1553    
1554                            return count.intValue();
1555                    }
1556                    catch (Exception e) {
1557                            throw processException(e);
1558                    }
1559                    finally {
1560                            closeSession(session);
1561                    }
1562            }
1563    
1564            /**
1565             * Counts all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1566             *
1567             * @param groupId the group id to search with
1568             * @param parentCategoryId the parent category id to search with
1569             * @return the number of matching shopping categories
1570             * @throws SystemException if a system exception occurred
1571             */
1572            public int countByG_P(long groupId, long parentCategoryId)
1573                    throws SystemException {
1574                    Object[] finderArgs = new Object[] { groupId, parentCategoryId };
1575    
1576                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
1577                                    finderArgs, this);
1578    
1579                    if (count == null) {
1580                            Session session = null;
1581    
1582                            try {
1583                                    session = openSession();
1584    
1585                                    StringBundler query = new StringBundler(3);
1586    
1587                                    query.append(_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
1588    
1589                                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1590    
1591                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1592    
1593                                    String sql = query.toString();
1594    
1595                                    Query q = session.createQuery(sql);
1596    
1597                                    QueryPos qPos = QueryPos.getInstance(q);
1598    
1599                                    qPos.add(groupId);
1600    
1601                                    qPos.add(parentCategoryId);
1602    
1603                                    count = (Long)q.uniqueResult();
1604                            }
1605                            catch (Exception e) {
1606                                    throw processException(e);
1607                            }
1608                            finally {
1609                                    if (count == null) {
1610                                            count = Long.valueOf(0);
1611                                    }
1612    
1613                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
1614                                            count);
1615    
1616                                    closeSession(session);
1617                            }
1618                    }
1619    
1620                    return count.intValue();
1621            }
1622    
1623            /**
1624             * Filters by the user's permissions and counts all the shopping categories where groupId = &#63; and parentCategoryId = &#63;.
1625             *
1626             * @param groupId the group id to search with
1627             * @param parentCategoryId the parent category id to search with
1628             * @return the number of matching shopping categories that the user has permission to view
1629             * @throws SystemException if a system exception occurred
1630             */
1631            public int filterCountByG_P(long groupId, long parentCategoryId)
1632                    throws SystemException {
1633                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1634                            return countByG_P(groupId, parentCategoryId);
1635                    }
1636    
1637                    Session session = null;
1638    
1639                    try {
1640                            session = openSession();
1641    
1642                            StringBundler query = new StringBundler(3);
1643    
1644                            query.append(_FILTER_SQL_COUNT_SHOPPINGCATEGORY_WHERE);
1645    
1646                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1647    
1648                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1649    
1650                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1651                                            ShoppingCategory.class.getName(), _FILTER_COLUMN_PK,
1652                                            _FILTER_COLUMN_USERID, groupId);
1653    
1654                            SQLQuery q = session.createSQLQuery(sql);
1655    
1656                            q.addScalar(COUNT_COLUMN_NAME,
1657                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1658    
1659                            QueryPos qPos = QueryPos.getInstance(q);
1660    
1661                            qPos.add(groupId);
1662    
1663                            qPos.add(parentCategoryId);
1664    
1665                            Long count = (Long)q.uniqueResult();
1666    
1667                            return count.intValue();
1668                    }
1669                    catch (Exception e) {
1670                            throw processException(e);
1671                    }
1672                    finally {
1673                            closeSession(session);
1674                    }
1675            }
1676    
1677            /**
1678             * Counts all the shopping categories.
1679             *
1680             * @return the number of shopping categories
1681             * @throws SystemException if a system exception occurred
1682             */
1683            public int countAll() throws SystemException {
1684                    Object[] finderArgs = new Object[0];
1685    
1686                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1687                                    finderArgs, this);
1688    
1689                    if (count == null) {
1690                            Session session = null;
1691    
1692                            try {
1693                                    session = openSession();
1694    
1695                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGCATEGORY);
1696    
1697                                    count = (Long)q.uniqueResult();
1698                            }
1699                            catch (Exception e) {
1700                                    throw processException(e);
1701                            }
1702                            finally {
1703                                    if (count == null) {
1704                                            count = Long.valueOf(0);
1705                                    }
1706    
1707                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1708                                            count);
1709    
1710                                    closeSession(session);
1711                            }
1712                    }
1713    
1714                    return count.intValue();
1715            }
1716    
1717            /**
1718             * Initializes the shopping category persistence.
1719             */
1720            public void afterPropertiesSet() {
1721                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1722                                            com.liferay.portal.util.PropsUtil.get(
1723                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingCategory")));
1724    
1725                    if (listenerClassNames.length > 0) {
1726                            try {
1727                                    List<ModelListener<ShoppingCategory>> listenersList = new ArrayList<ModelListener<ShoppingCategory>>();
1728    
1729                                    for (String listenerClassName : listenerClassNames) {
1730                                            listenersList.add((ModelListener<ShoppingCategory>)InstanceFactory.newInstance(
1731                                                            listenerClassName));
1732                                    }
1733    
1734                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1735                            }
1736                            catch (Exception e) {
1737                                    _log.error(e);
1738                            }
1739                    }
1740            }
1741    
1742            @BeanReference(type = ShoppingCartPersistence.class)
1743            protected ShoppingCartPersistence shoppingCartPersistence;
1744            @BeanReference(type = ShoppingCategoryPersistence.class)
1745            protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1746            @BeanReference(type = ShoppingCouponPersistence.class)
1747            protected ShoppingCouponPersistence shoppingCouponPersistence;
1748            @BeanReference(type = ShoppingItemPersistence.class)
1749            protected ShoppingItemPersistence shoppingItemPersistence;
1750            @BeanReference(type = ShoppingItemFieldPersistence.class)
1751            protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1752            @BeanReference(type = ShoppingItemPricePersistence.class)
1753            protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1754            @BeanReference(type = ShoppingOrderPersistence.class)
1755            protected ShoppingOrderPersistence shoppingOrderPersistence;
1756            @BeanReference(type = ShoppingOrderItemPersistence.class)
1757            protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1758            @BeanReference(type = ResourcePersistence.class)
1759            protected ResourcePersistence resourcePersistence;
1760            @BeanReference(type = UserPersistence.class)
1761            protected UserPersistence userPersistence;
1762            private static final String _SQL_SELECT_SHOPPINGCATEGORY = "SELECT shoppingCategory FROM ShoppingCategory shoppingCategory";
1763            private static final String _SQL_SELECT_SHOPPINGCATEGORY_WHERE = "SELECT shoppingCategory FROM ShoppingCategory shoppingCategory WHERE ";
1764            private static final String _SQL_COUNT_SHOPPINGCATEGORY = "SELECT COUNT(shoppingCategory) FROM ShoppingCategory shoppingCategory";
1765            private static final String _SQL_COUNT_SHOPPINGCATEGORY_WHERE = "SELECT COUNT(shoppingCategory) FROM ShoppingCategory shoppingCategory WHERE ";
1766            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "shoppingCategory.groupId = ?";
1767            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "shoppingCategory.groupId = ? AND ";
1768            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "shoppingCategory.parentCategoryId = ?";
1769            private static final String _FILTER_SQL_SELECT_SHOPPINGCATEGORY_WHERE = "SELECT DISTINCT {shoppingCategory.*} FROM ShoppingCategory shoppingCategory WHERE ";
1770            private static final String _FILTER_SQL_COUNT_SHOPPINGCATEGORY_WHERE = "SELECT COUNT(DISTINCT shoppingCategory.categoryId) AS COUNT_VALUE FROM ShoppingCategory shoppingCategory WHERE ";
1771            private static final String _FILTER_COLUMN_PK = "shoppingCategory.categoryId";
1772            private static final String _FILTER_COLUMN_USERID = "shoppingCategory.userId";
1773            private static final String _FILTER_ENTITY_ALIAS = "shoppingCategory";
1774            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingCategory.";
1775            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingCategory exists with the primary key ";
1776            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingCategory exists with the key {";
1777            private static Log _log = LogFactoryUtil.getLog(ShoppingCategoryPersistenceImpl.class);
1778    }