001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.asset.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
021    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
022    import com.liferay.portal.kernel.dao.orm.EntityCache;
023    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderCache;
025    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
026    import com.liferay.portal.kernel.dao.orm.FinderPath;
027    import com.liferay.portal.kernel.dao.orm.Query;
028    import com.liferay.portal.kernel.dao.orm.QueryPos;
029    import com.liferay.portal.kernel.dao.orm.QueryUtil;
030    import com.liferay.portal.kernel.dao.orm.SQLQuery;
031    import com.liferay.portal.kernel.dao.orm.Session;
032    import com.liferay.portal.kernel.exception.SystemException;
033    import com.liferay.portal.kernel.log.Log;
034    import com.liferay.portal.kernel.log.LogFactoryUtil;
035    import com.liferay.portal.kernel.util.ArrayUtil;
036    import com.liferay.portal.kernel.util.CharPool;
037    import com.liferay.portal.kernel.util.OrderByComparator;
038    import com.liferay.portal.kernel.util.SetUtil;
039    import com.liferay.portal.kernel.util.StringBundler;
040    import com.liferay.portal.kernel.util.StringPool;
041    import com.liferay.portal.kernel.util.StringUtil;
042    import com.liferay.portal.kernel.util.Validator;
043    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
044    import com.liferay.portal.model.CacheModel;
045    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
046    import com.liferay.portal.service.ServiceContext;
047    import com.liferay.portal.service.ServiceContextThreadLocal;
048    import com.liferay.portal.service.persistence.CompanyProvider;
049    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
050    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
051    import com.liferay.portal.service.persistence.impl.NestedSetsTreeManager;
052    import com.liferay.portal.service.persistence.impl.PersistenceNestedSetsTreeManager;
053    import com.liferay.portal.service.persistence.impl.TableMapper;
054    import com.liferay.portal.service.persistence.impl.TableMapperFactory;
055    
056    import com.liferay.portlet.asset.exception.NoSuchCategoryException;
057    import com.liferay.portlet.asset.model.AssetCategory;
058    import com.liferay.portlet.asset.model.impl.AssetCategoryImpl;
059    import com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl;
060    import com.liferay.portlet.asset.service.persistence.AssetCategoryPersistence;
061    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
062    
063    import java.io.Serializable;
064    
065    import java.util.Arrays;
066    import java.util.Collections;
067    import java.util.Date;
068    import java.util.HashMap;
069    import java.util.HashSet;
070    import java.util.Iterator;
071    import java.util.List;
072    import java.util.Map;
073    import java.util.Set;
074    
075    /**
076     * The persistence implementation for the asset category service.
077     *
078     * <p>
079     * Caching information and settings can be found in <code>portal.properties</code>
080     * </p>
081     *
082     * @author Brian Wing Shun Chan
083     * @see AssetCategoryPersistence
084     * @see com.liferay.portlet.asset.service.persistence.AssetCategoryUtil
085     * @generated
086     */
087    @ProviderType
088    public class AssetCategoryPersistenceImpl extends BasePersistenceImpl<AssetCategory>
089            implements AssetCategoryPersistence {
090            /*
091             * NOTE FOR DEVELOPERS:
092             *
093             * Never modify or reference this class directly. Always use {@link AssetCategoryUtil} to access the asset category persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
094             */
095            public static final String FINDER_CLASS_NAME_ENTITY = AssetCategoryImpl.class.getName();
096            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
097                    ".List1";
098            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
099                    ".List2";
100            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
101                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
102                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
103                            "findAll", new String[0]);
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
105                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
106                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
107                            "findAll", new String[0]);
108            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
109                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
111            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_ANCESTORS = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
112                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countAncestors",
114                            new String[] {
115                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
116                            });
117            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_DESCENDANTS =
118                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
119                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
120                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countDescendants",
121                            new String[] {
122                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
123                            });
124            public static final FinderPath FINDER_PATH_WITH_PAGINATION_GET_ANCESTORS = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
125                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
126                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
127                            "getAncestors",
128                            new String[] {
129                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
130                            });
131            public static final FinderPath FINDER_PATH_WITH_PAGINATION_GET_DESCENDANTS = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
132                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
133                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
134                            "getDescendants",
135                            new String[] {
136                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
137                            });
138            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
139                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
140                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
141                            "findByUuid",
142                            new String[] {
143                                    String.class.getName(),
144                                    
145                            Integer.class.getName(), Integer.class.getName(),
146                                    OrderByComparator.class.getName()
147                            });
148            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
149                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
150                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
151                            "findByUuid", new String[] { String.class.getName() },
152                            AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
153                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
154            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
155                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
156                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
157                            new String[] { String.class.getName() });
158    
159            /**
160             * Returns all the asset categories where uuid = &#63;.
161             *
162             * @param uuid the uuid
163             * @return the matching asset categories
164             */
165            @Override
166            public List<AssetCategory> findByUuid(String uuid) {
167                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
168            }
169    
170            /**
171             * Returns a range of all the asset categories where uuid = &#63;.
172             *
173             * <p>
174             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
175             * </p>
176             *
177             * @param uuid the uuid
178             * @param start the lower bound of the range of asset categories
179             * @param end the upper bound of the range of asset categories (not inclusive)
180             * @return the range of matching asset categories
181             */
182            @Override
183            public List<AssetCategory> findByUuid(String uuid, int start, int end) {
184                    return findByUuid(uuid, start, end, null);
185            }
186    
187            /**
188             * Returns an ordered range of all the asset categories where uuid = &#63;.
189             *
190             * <p>
191             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
192             * </p>
193             *
194             * @param uuid the uuid
195             * @param start the lower bound of the range of asset categories
196             * @param end the upper bound of the range of asset categories (not inclusive)
197             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
198             * @return the ordered range of matching asset categories
199             */
200            @Override
201            public List<AssetCategory> findByUuid(String uuid, int start, int end,
202                    OrderByComparator<AssetCategory> orderByComparator) {
203                    return findByUuid(uuid, start, end, orderByComparator, true);
204            }
205    
206            /**
207             * Returns an ordered range of all the asset categories where uuid = &#63;.
208             *
209             * <p>
210             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
211             * </p>
212             *
213             * @param uuid the uuid
214             * @param start the lower bound of the range of asset categories
215             * @param end the upper bound of the range of asset categories (not inclusive)
216             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
217             * @param retrieveFromCache whether to retrieve from the finder cache
218             * @return the ordered range of matching asset categories
219             */
220            @Override
221            public List<AssetCategory> findByUuid(String uuid, int start, int end,
222                    OrderByComparator<AssetCategory> orderByComparator,
223                    boolean retrieveFromCache) {
224                    boolean pagination = true;
225                    FinderPath finderPath = null;
226                    Object[] finderArgs = null;
227    
228                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
229                                    (orderByComparator == null)) {
230                            pagination = false;
231                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
232                            finderArgs = new Object[] { uuid };
233                    }
234                    else {
235                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
236                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
237                    }
238    
239                    List<AssetCategory> list = null;
240    
241                    if (retrieveFromCache) {
242                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
243                                            finderArgs, this);
244    
245                            if ((list != null) && !list.isEmpty()) {
246                                    for (AssetCategory assetCategory : list) {
247                                            if (!Validator.equals(uuid, assetCategory.getUuid())) {
248                                                    list = null;
249    
250                                                    break;
251                                            }
252                                    }
253                            }
254                    }
255    
256                    if (list == null) {
257                            StringBundler query = null;
258    
259                            if (orderByComparator != null) {
260                                    query = new StringBundler(3 +
261                                                    (orderByComparator.getOrderByFields().length * 3));
262                            }
263                            else {
264                                    query = new StringBundler(3);
265                            }
266    
267                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
268    
269                            boolean bindUuid = false;
270    
271                            if (uuid == null) {
272                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
273                            }
274                            else if (uuid.equals(StringPool.BLANK)) {
275                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
276                            }
277                            else {
278                                    bindUuid = true;
279    
280                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
281                            }
282    
283                            if (orderByComparator != null) {
284                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
285                                            orderByComparator);
286                            }
287                            else
288                             if (pagination) {
289                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
290                            }
291    
292                            String sql = query.toString();
293    
294                            Session session = null;
295    
296                            try {
297                                    session = openSession();
298    
299                                    Query q = session.createQuery(sql);
300    
301                                    QueryPos qPos = QueryPos.getInstance(q);
302    
303                                    if (bindUuid) {
304                                            qPos.add(uuid);
305                                    }
306    
307                                    if (!pagination) {
308                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
309                                                            start, end, false);
310    
311                                            Collections.sort(list);
312    
313                                            list = Collections.unmodifiableList(list);
314                                    }
315                                    else {
316                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
317                                                            start, end);
318                                    }
319    
320                                    cacheResult(list);
321    
322                                    finderCache.putResult(finderPath, finderArgs, list);
323                            }
324                            catch (Exception e) {
325                                    finderCache.removeResult(finderPath, finderArgs);
326    
327                                    throw processException(e);
328                            }
329                            finally {
330                                    closeSession(session);
331                            }
332                    }
333    
334                    return list;
335            }
336    
337            /**
338             * Returns the first asset category in the ordered set where uuid = &#63;.
339             *
340             * @param uuid the uuid
341             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
342             * @return the first matching asset category
343             * @throws NoSuchCategoryException if a matching asset category could not be found
344             */
345            @Override
346            public AssetCategory findByUuid_First(String uuid,
347                    OrderByComparator<AssetCategory> orderByComparator)
348                    throws NoSuchCategoryException {
349                    AssetCategory assetCategory = fetchByUuid_First(uuid, orderByComparator);
350    
351                    if (assetCategory != null) {
352                            return assetCategory;
353                    }
354    
355                    StringBundler msg = new StringBundler(4);
356    
357                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
358    
359                    msg.append("uuid=");
360                    msg.append(uuid);
361    
362                    msg.append(StringPool.CLOSE_CURLY_BRACE);
363    
364                    throw new NoSuchCategoryException(msg.toString());
365            }
366    
367            /**
368             * Returns the first asset category in the ordered set where uuid = &#63;.
369             *
370             * @param uuid the uuid
371             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
372             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
373             */
374            @Override
375            public AssetCategory fetchByUuid_First(String uuid,
376                    OrderByComparator<AssetCategory> orderByComparator) {
377                    List<AssetCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
378    
379                    if (!list.isEmpty()) {
380                            return list.get(0);
381                    }
382    
383                    return null;
384            }
385    
386            /**
387             * Returns the last asset category in the ordered set where uuid = &#63;.
388             *
389             * @param uuid the uuid
390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
391             * @return the last matching asset category
392             * @throws NoSuchCategoryException if a matching asset category could not be found
393             */
394            @Override
395            public AssetCategory findByUuid_Last(String uuid,
396                    OrderByComparator<AssetCategory> orderByComparator)
397                    throws NoSuchCategoryException {
398                    AssetCategory assetCategory = fetchByUuid_Last(uuid, orderByComparator);
399    
400                    if (assetCategory != null) {
401                            return assetCategory;
402                    }
403    
404                    StringBundler msg = new StringBundler(4);
405    
406                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
407    
408                    msg.append("uuid=");
409                    msg.append(uuid);
410    
411                    msg.append(StringPool.CLOSE_CURLY_BRACE);
412    
413                    throw new NoSuchCategoryException(msg.toString());
414            }
415    
416            /**
417             * Returns the last asset category in the ordered set where uuid = &#63;.
418             *
419             * @param uuid the uuid
420             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
421             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
422             */
423            @Override
424            public AssetCategory fetchByUuid_Last(String uuid,
425                    OrderByComparator<AssetCategory> orderByComparator) {
426                    int count = countByUuid(uuid);
427    
428                    if (count == 0) {
429                            return null;
430                    }
431    
432                    List<AssetCategory> list = findByUuid(uuid, count - 1, count,
433                                    orderByComparator);
434    
435                    if (!list.isEmpty()) {
436                            return list.get(0);
437                    }
438    
439                    return null;
440            }
441    
442            /**
443             * Returns the asset categories before and after the current asset category in the ordered set where uuid = &#63;.
444             *
445             * @param categoryId the primary key of the current asset category
446             * @param uuid the uuid
447             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
448             * @return the previous, current, and next asset category
449             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
450             */
451            @Override
452            public AssetCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
453                    OrderByComparator<AssetCategory> orderByComparator)
454                    throws NoSuchCategoryException {
455                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
456    
457                    Session session = null;
458    
459                    try {
460                            session = openSession();
461    
462                            AssetCategory[] array = new AssetCategoryImpl[3];
463    
464                            array[0] = getByUuid_PrevAndNext(session, assetCategory, uuid,
465                                            orderByComparator, true);
466    
467                            array[1] = assetCategory;
468    
469                            array[2] = getByUuid_PrevAndNext(session, assetCategory, uuid,
470                                            orderByComparator, false);
471    
472                            return array;
473                    }
474                    catch (Exception e) {
475                            throw processException(e);
476                    }
477                    finally {
478                            closeSession(session);
479                    }
480            }
481    
482            protected AssetCategory getByUuid_PrevAndNext(Session session,
483                    AssetCategory assetCategory, String uuid,
484                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
485                    StringBundler query = null;
486    
487                    if (orderByComparator != null) {
488                            query = new StringBundler(6 +
489                                            (orderByComparator.getOrderByFields().length * 6));
490                    }
491                    else {
492                            query = new StringBundler(3);
493                    }
494    
495                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
496    
497                    boolean bindUuid = false;
498    
499                    if (uuid == null) {
500                            query.append(_FINDER_COLUMN_UUID_UUID_1);
501                    }
502                    else if (uuid.equals(StringPool.BLANK)) {
503                            query.append(_FINDER_COLUMN_UUID_UUID_3);
504                    }
505                    else {
506                            bindUuid = true;
507    
508                            query.append(_FINDER_COLUMN_UUID_UUID_2);
509                    }
510    
511                    if (orderByComparator != null) {
512                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
513    
514                            if (orderByConditionFields.length > 0) {
515                                    query.append(WHERE_AND);
516                            }
517    
518                            for (int i = 0; i < orderByConditionFields.length; i++) {
519                                    query.append(_ORDER_BY_ENTITY_ALIAS);
520                                    query.append(orderByConditionFields[i]);
521    
522                                    if ((i + 1) < orderByConditionFields.length) {
523                                            if (orderByComparator.isAscending() ^ previous) {
524                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
525                                            }
526                                            else {
527                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
528                                            }
529                                    }
530                                    else {
531                                            if (orderByComparator.isAscending() ^ previous) {
532                                                    query.append(WHERE_GREATER_THAN);
533                                            }
534                                            else {
535                                                    query.append(WHERE_LESSER_THAN);
536                                            }
537                                    }
538                            }
539    
540                            query.append(ORDER_BY_CLAUSE);
541    
542                            String[] orderByFields = orderByComparator.getOrderByFields();
543    
544                            for (int i = 0; i < orderByFields.length; i++) {
545                                    query.append(_ORDER_BY_ENTITY_ALIAS);
546                                    query.append(orderByFields[i]);
547    
548                                    if ((i + 1) < orderByFields.length) {
549                                            if (orderByComparator.isAscending() ^ previous) {
550                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
551                                            }
552                                            else {
553                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
554                                            }
555                                    }
556                                    else {
557                                            if (orderByComparator.isAscending() ^ previous) {
558                                                    query.append(ORDER_BY_ASC);
559                                            }
560                                            else {
561                                                    query.append(ORDER_BY_DESC);
562                                            }
563                                    }
564                            }
565                    }
566                    else {
567                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
568                    }
569    
570                    String sql = query.toString();
571    
572                    Query q = session.createQuery(sql);
573    
574                    q.setFirstResult(0);
575                    q.setMaxResults(2);
576    
577                    QueryPos qPos = QueryPos.getInstance(q);
578    
579                    if (bindUuid) {
580                            qPos.add(uuid);
581                    }
582    
583                    if (orderByComparator != null) {
584                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
585    
586                            for (Object value : values) {
587                                    qPos.add(value);
588                            }
589                    }
590    
591                    List<AssetCategory> list = q.list();
592    
593                    if (list.size() == 2) {
594                            return list.get(1);
595                    }
596                    else {
597                            return null;
598                    }
599            }
600    
601            /**
602             * Removes all the asset categories where uuid = &#63; from the database.
603             *
604             * @param uuid the uuid
605             */
606            @Override
607            public void removeByUuid(String uuid) {
608                    for (AssetCategory assetCategory : findByUuid(uuid, QueryUtil.ALL_POS,
609                                    QueryUtil.ALL_POS, null)) {
610                            remove(assetCategory);
611                    }
612            }
613    
614            /**
615             * Returns the number of asset categories where uuid = &#63;.
616             *
617             * @param uuid the uuid
618             * @return the number of matching asset categories
619             */
620            @Override
621            public int countByUuid(String uuid) {
622                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
623    
624                    Object[] finderArgs = new Object[] { uuid };
625    
626                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
627    
628                    if (count == null) {
629                            StringBundler query = new StringBundler(2);
630    
631                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
632    
633                            boolean bindUuid = false;
634    
635                            if (uuid == null) {
636                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
637                            }
638                            else if (uuid.equals(StringPool.BLANK)) {
639                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
640                            }
641                            else {
642                                    bindUuid = true;
643    
644                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
645                            }
646    
647                            String sql = query.toString();
648    
649                            Session session = null;
650    
651                            try {
652                                    session = openSession();
653    
654                                    Query q = session.createQuery(sql);
655    
656                                    QueryPos qPos = QueryPos.getInstance(q);
657    
658                                    if (bindUuid) {
659                                            qPos.add(uuid);
660                                    }
661    
662                                    count = (Long)q.uniqueResult();
663    
664                                    finderCache.putResult(finderPath, finderArgs, count);
665                            }
666                            catch (Exception e) {
667                                    finderCache.removeResult(finderPath, finderArgs);
668    
669                                    throw processException(e);
670                            }
671                            finally {
672                                    closeSession(session);
673                            }
674                    }
675    
676                    return count.intValue();
677            }
678    
679            private static final String _FINDER_COLUMN_UUID_UUID_1 = "assetCategory.uuid IS NULL";
680            private static final String _FINDER_COLUMN_UUID_UUID_2 = "assetCategory.uuid = ?";
681            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = '')";
682            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
683                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
684                            AssetCategoryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
685                            new String[] { String.class.getName(), Long.class.getName() },
686                            AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
687                            AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK);
688            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
689                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
690                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
691                            new String[] { String.class.getName(), Long.class.getName() });
692    
693            /**
694             * Returns the asset category where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchCategoryException} if it could not be found.
695             *
696             * @param uuid the uuid
697             * @param groupId the group ID
698             * @return the matching asset category
699             * @throws NoSuchCategoryException if a matching asset category could not be found
700             */
701            @Override
702            public AssetCategory findByUUID_G(String uuid, long groupId)
703                    throws NoSuchCategoryException {
704                    AssetCategory assetCategory = fetchByUUID_G(uuid, groupId);
705    
706                    if (assetCategory == null) {
707                            StringBundler msg = new StringBundler(6);
708    
709                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
710    
711                            msg.append("uuid=");
712                            msg.append(uuid);
713    
714                            msg.append(", groupId=");
715                            msg.append(groupId);
716    
717                            msg.append(StringPool.CLOSE_CURLY_BRACE);
718    
719                            if (_log.isWarnEnabled()) {
720                                    _log.warn(msg.toString());
721                            }
722    
723                            throw new NoSuchCategoryException(msg.toString());
724                    }
725    
726                    return assetCategory;
727            }
728    
729            /**
730             * Returns the asset category where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
731             *
732             * @param uuid the uuid
733             * @param groupId the group ID
734             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
735             */
736            @Override
737            public AssetCategory fetchByUUID_G(String uuid, long groupId) {
738                    return fetchByUUID_G(uuid, groupId, true);
739            }
740    
741            /**
742             * Returns the asset category where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
743             *
744             * @param uuid the uuid
745             * @param groupId the group ID
746             * @param retrieveFromCache whether to retrieve from the finder cache
747             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
748             */
749            @Override
750            public AssetCategory fetchByUUID_G(String uuid, long groupId,
751                    boolean retrieveFromCache) {
752                    Object[] finderArgs = new Object[] { uuid, groupId };
753    
754                    Object result = null;
755    
756                    if (retrieveFromCache) {
757                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
758                                            finderArgs, this);
759                    }
760    
761                    if (result instanceof AssetCategory) {
762                            AssetCategory assetCategory = (AssetCategory)result;
763    
764                            if (!Validator.equals(uuid, assetCategory.getUuid()) ||
765                                            (groupId != assetCategory.getGroupId())) {
766                                    result = null;
767                            }
768                    }
769    
770                    if (result == null) {
771                            StringBundler query = new StringBundler(4);
772    
773                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
774    
775                            boolean bindUuid = false;
776    
777                            if (uuid == null) {
778                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
779                            }
780                            else if (uuid.equals(StringPool.BLANK)) {
781                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
782                            }
783                            else {
784                                    bindUuid = true;
785    
786                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
787                            }
788    
789                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
790    
791                            String sql = query.toString();
792    
793                            Session session = null;
794    
795                            try {
796                                    session = openSession();
797    
798                                    Query q = session.createQuery(sql);
799    
800                                    QueryPos qPos = QueryPos.getInstance(q);
801    
802                                    if (bindUuid) {
803                                            qPos.add(uuid);
804                                    }
805    
806                                    qPos.add(groupId);
807    
808                                    List<AssetCategory> list = q.list();
809    
810                                    if (list.isEmpty()) {
811                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
812                                                    finderArgs, list);
813                                    }
814                                    else {
815                                            AssetCategory assetCategory = list.get(0);
816    
817                                            result = assetCategory;
818    
819                                            cacheResult(assetCategory);
820    
821                                            if ((assetCategory.getUuid() == null) ||
822                                                            !assetCategory.getUuid().equals(uuid) ||
823                                                            (assetCategory.getGroupId() != groupId)) {
824                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
825                                                            finderArgs, assetCategory);
826                                            }
827                                    }
828                            }
829                            catch (Exception e) {
830                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
831    
832                                    throw processException(e);
833                            }
834                            finally {
835                                    closeSession(session);
836                            }
837                    }
838    
839                    if (result instanceof List<?>) {
840                            return null;
841                    }
842                    else {
843                            return (AssetCategory)result;
844                    }
845            }
846    
847            /**
848             * Removes the asset category where uuid = &#63; and groupId = &#63; from the database.
849             *
850             * @param uuid the uuid
851             * @param groupId the group ID
852             * @return the asset category that was removed
853             */
854            @Override
855            public AssetCategory removeByUUID_G(String uuid, long groupId)
856                    throws NoSuchCategoryException {
857                    AssetCategory assetCategory = findByUUID_G(uuid, groupId);
858    
859                    return remove(assetCategory);
860            }
861    
862            /**
863             * Returns the number of asset categories where uuid = &#63; and groupId = &#63;.
864             *
865             * @param uuid the uuid
866             * @param groupId the group ID
867             * @return the number of matching asset categories
868             */
869            @Override
870            public int countByUUID_G(String uuid, long groupId) {
871                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
872    
873                    Object[] finderArgs = new Object[] { uuid, groupId };
874    
875                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
876    
877                    if (count == null) {
878                            StringBundler query = new StringBundler(3);
879    
880                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
881    
882                            boolean bindUuid = false;
883    
884                            if (uuid == null) {
885                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
886                            }
887                            else if (uuid.equals(StringPool.BLANK)) {
888                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
889                            }
890                            else {
891                                    bindUuid = true;
892    
893                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
894                            }
895    
896                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
897    
898                            String sql = query.toString();
899    
900                            Session session = null;
901    
902                            try {
903                                    session = openSession();
904    
905                                    Query q = session.createQuery(sql);
906    
907                                    QueryPos qPos = QueryPos.getInstance(q);
908    
909                                    if (bindUuid) {
910                                            qPos.add(uuid);
911                                    }
912    
913                                    qPos.add(groupId);
914    
915                                    count = (Long)q.uniqueResult();
916    
917                                    finderCache.putResult(finderPath, finderArgs, count);
918                            }
919                            catch (Exception e) {
920                                    finderCache.removeResult(finderPath, finderArgs);
921    
922                                    throw processException(e);
923                            }
924                            finally {
925                                    closeSession(session);
926                            }
927                    }
928    
929                    return count.intValue();
930            }
931    
932            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "assetCategory.uuid IS NULL AND ";
933            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "assetCategory.uuid = ? AND ";
934            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = '') AND ";
935            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "assetCategory.groupId = ?";
936            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
937                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
938                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
939                            "findByUuid_C",
940                            new String[] {
941                                    String.class.getName(), Long.class.getName(),
942                                    
943                            Integer.class.getName(), Integer.class.getName(),
944                                    OrderByComparator.class.getName()
945                            });
946            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
947                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
948                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
949                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
950                            "findByUuid_C",
951                            new String[] { String.class.getName(), Long.class.getName() },
952                            AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
953                            AssetCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
954                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
955            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
956                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
957                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
958                            new String[] { String.class.getName(), Long.class.getName() });
959    
960            /**
961             * Returns all the asset categories where uuid = &#63; and companyId = &#63;.
962             *
963             * @param uuid the uuid
964             * @param companyId the company ID
965             * @return the matching asset categories
966             */
967            @Override
968            public List<AssetCategory> findByUuid_C(String uuid, long companyId) {
969                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
970                            QueryUtil.ALL_POS, null);
971            }
972    
973            /**
974             * Returns a range of all the asset categories where uuid = &#63; and companyId = &#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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
978             * </p>
979             *
980             * @param uuid the uuid
981             * @param companyId the company ID
982             * @param start the lower bound of the range of asset categories
983             * @param end the upper bound of the range of asset categories (not inclusive)
984             * @return the range of matching asset categories
985             */
986            @Override
987            public List<AssetCategory> findByUuid_C(String uuid, long companyId,
988                    int start, int end) {
989                    return findByUuid_C(uuid, companyId, start, end, null);
990            }
991    
992            /**
993             * Returns an ordered range of all the asset categories where uuid = &#63; and companyId = &#63;.
994             *
995             * <p>
996             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
997             * </p>
998             *
999             * @param uuid the uuid
1000             * @param companyId the company ID
1001             * @param start the lower bound of the range of asset categories
1002             * @param end the upper bound of the range of asset categories (not inclusive)
1003             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1004             * @return the ordered range of matching asset categories
1005             */
1006            @Override
1007            public List<AssetCategory> findByUuid_C(String uuid, long companyId,
1008                    int start, int end, OrderByComparator<AssetCategory> orderByComparator) {
1009                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
1010            }
1011    
1012            /**
1013             * Returns an ordered range of all the asset categories where uuid = &#63; and companyId = &#63;.
1014             *
1015             * <p>
1016             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1017             * </p>
1018             *
1019             * @param uuid the uuid
1020             * @param companyId the company ID
1021             * @param start the lower bound of the range of asset categories
1022             * @param end the upper bound of the range of asset categories (not inclusive)
1023             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1024             * @param retrieveFromCache whether to retrieve from the finder cache
1025             * @return the ordered range of matching asset categories
1026             */
1027            @Override
1028            public List<AssetCategory> findByUuid_C(String uuid, long companyId,
1029                    int start, int end, OrderByComparator<AssetCategory> orderByComparator,
1030                    boolean retrieveFromCache) {
1031                    boolean pagination = true;
1032                    FinderPath finderPath = null;
1033                    Object[] finderArgs = null;
1034    
1035                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1036                                    (orderByComparator == null)) {
1037                            pagination = false;
1038                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1039                            finderArgs = new Object[] { uuid, companyId };
1040                    }
1041                    else {
1042                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1043                            finderArgs = new Object[] {
1044                                            uuid, companyId,
1045                                            
1046                                            start, end, orderByComparator
1047                                    };
1048                    }
1049    
1050                    List<AssetCategory> list = null;
1051    
1052                    if (retrieveFromCache) {
1053                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
1054                                            finderArgs, this);
1055    
1056                            if ((list != null) && !list.isEmpty()) {
1057                                    for (AssetCategory assetCategory : list) {
1058                                            if (!Validator.equals(uuid, assetCategory.getUuid()) ||
1059                                                            (companyId != assetCategory.getCompanyId())) {
1060                                                    list = null;
1061    
1062                                                    break;
1063                                            }
1064                                    }
1065                            }
1066                    }
1067    
1068                    if (list == null) {
1069                            StringBundler query = null;
1070    
1071                            if (orderByComparator != null) {
1072                                    query = new StringBundler(4 +
1073                                                    (orderByComparator.getOrderByFields().length * 3));
1074                            }
1075                            else {
1076                                    query = new StringBundler(4);
1077                            }
1078    
1079                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1080    
1081                            boolean bindUuid = false;
1082    
1083                            if (uuid == null) {
1084                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1085                            }
1086                            else if (uuid.equals(StringPool.BLANK)) {
1087                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1088                            }
1089                            else {
1090                                    bindUuid = true;
1091    
1092                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1093                            }
1094    
1095                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1096    
1097                            if (orderByComparator != null) {
1098                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1099                                            orderByComparator);
1100                            }
1101                            else
1102                             if (pagination) {
1103                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1104                            }
1105    
1106                            String sql = query.toString();
1107    
1108                            Session session = null;
1109    
1110                            try {
1111                                    session = openSession();
1112    
1113                                    Query q = session.createQuery(sql);
1114    
1115                                    QueryPos qPos = QueryPos.getInstance(q);
1116    
1117                                    if (bindUuid) {
1118                                            qPos.add(uuid);
1119                                    }
1120    
1121                                    qPos.add(companyId);
1122    
1123                                    if (!pagination) {
1124                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1125                                                            start, end, false);
1126    
1127                                            Collections.sort(list);
1128    
1129                                            list = Collections.unmodifiableList(list);
1130                                    }
1131                                    else {
1132                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1133                                                            start, end);
1134                                    }
1135    
1136                                    cacheResult(list);
1137    
1138                                    finderCache.putResult(finderPath, finderArgs, list);
1139                            }
1140                            catch (Exception e) {
1141                                    finderCache.removeResult(finderPath, finderArgs);
1142    
1143                                    throw processException(e);
1144                            }
1145                            finally {
1146                                    closeSession(session);
1147                            }
1148                    }
1149    
1150                    return list;
1151            }
1152    
1153            /**
1154             * Returns the first asset category in the ordered set where uuid = &#63; and companyId = &#63;.
1155             *
1156             * @param uuid the uuid
1157             * @param companyId the company ID
1158             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1159             * @return the first matching asset category
1160             * @throws NoSuchCategoryException if a matching asset category could not be found
1161             */
1162            @Override
1163            public AssetCategory findByUuid_C_First(String uuid, long companyId,
1164                    OrderByComparator<AssetCategory> orderByComparator)
1165                    throws NoSuchCategoryException {
1166                    AssetCategory assetCategory = fetchByUuid_C_First(uuid, companyId,
1167                                    orderByComparator);
1168    
1169                    if (assetCategory != null) {
1170                            return assetCategory;
1171                    }
1172    
1173                    StringBundler msg = new StringBundler(6);
1174    
1175                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1176    
1177                    msg.append("uuid=");
1178                    msg.append(uuid);
1179    
1180                    msg.append(", companyId=");
1181                    msg.append(companyId);
1182    
1183                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1184    
1185                    throw new NoSuchCategoryException(msg.toString());
1186            }
1187    
1188            /**
1189             * Returns the first asset category in the ordered set where uuid = &#63; and companyId = &#63;.
1190             *
1191             * @param uuid the uuid
1192             * @param companyId the company ID
1193             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1194             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
1195             */
1196            @Override
1197            public AssetCategory fetchByUuid_C_First(String uuid, long companyId,
1198                    OrderByComparator<AssetCategory> orderByComparator) {
1199                    List<AssetCategory> list = findByUuid_C(uuid, companyId, 0, 1,
1200                                    orderByComparator);
1201    
1202                    if (!list.isEmpty()) {
1203                            return list.get(0);
1204                    }
1205    
1206                    return null;
1207            }
1208    
1209            /**
1210             * Returns the last asset category in the ordered set where uuid = &#63; and companyId = &#63;.
1211             *
1212             * @param uuid the uuid
1213             * @param companyId the company ID
1214             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1215             * @return the last matching asset category
1216             * @throws NoSuchCategoryException if a matching asset category could not be found
1217             */
1218            @Override
1219            public AssetCategory findByUuid_C_Last(String uuid, long companyId,
1220                    OrderByComparator<AssetCategory> orderByComparator)
1221                    throws NoSuchCategoryException {
1222                    AssetCategory assetCategory = fetchByUuid_C_Last(uuid, companyId,
1223                                    orderByComparator);
1224    
1225                    if (assetCategory != null) {
1226                            return assetCategory;
1227                    }
1228    
1229                    StringBundler msg = new StringBundler(6);
1230    
1231                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1232    
1233                    msg.append("uuid=");
1234                    msg.append(uuid);
1235    
1236                    msg.append(", companyId=");
1237                    msg.append(companyId);
1238    
1239                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1240    
1241                    throw new NoSuchCategoryException(msg.toString());
1242            }
1243    
1244            /**
1245             * Returns the last asset category in the ordered set where uuid = &#63; and companyId = &#63;.
1246             *
1247             * @param uuid the uuid
1248             * @param companyId the company ID
1249             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1250             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
1251             */
1252            @Override
1253            public AssetCategory fetchByUuid_C_Last(String uuid, long companyId,
1254                    OrderByComparator<AssetCategory> orderByComparator) {
1255                    int count = countByUuid_C(uuid, companyId);
1256    
1257                    if (count == 0) {
1258                            return null;
1259                    }
1260    
1261                    List<AssetCategory> list = findByUuid_C(uuid, companyId, count - 1,
1262                                    count, orderByComparator);
1263    
1264                    if (!list.isEmpty()) {
1265                            return list.get(0);
1266                    }
1267    
1268                    return null;
1269            }
1270    
1271            /**
1272             * Returns the asset categories before and after the current asset category in the ordered set where uuid = &#63; and companyId = &#63;.
1273             *
1274             * @param categoryId the primary key of the current asset category
1275             * @param uuid the uuid
1276             * @param companyId the company ID
1277             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1278             * @return the previous, current, and next asset category
1279             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
1280             */
1281            @Override
1282            public AssetCategory[] findByUuid_C_PrevAndNext(long categoryId,
1283                    String uuid, long companyId,
1284                    OrderByComparator<AssetCategory> orderByComparator)
1285                    throws NoSuchCategoryException {
1286                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
1287    
1288                    Session session = null;
1289    
1290                    try {
1291                            session = openSession();
1292    
1293                            AssetCategory[] array = new AssetCategoryImpl[3];
1294    
1295                            array[0] = getByUuid_C_PrevAndNext(session, assetCategory, uuid,
1296                                            companyId, orderByComparator, true);
1297    
1298                            array[1] = assetCategory;
1299    
1300                            array[2] = getByUuid_C_PrevAndNext(session, assetCategory, uuid,
1301                                            companyId, orderByComparator, false);
1302    
1303                            return array;
1304                    }
1305                    catch (Exception e) {
1306                            throw processException(e);
1307                    }
1308                    finally {
1309                            closeSession(session);
1310                    }
1311            }
1312    
1313            protected AssetCategory getByUuid_C_PrevAndNext(Session session,
1314                    AssetCategory assetCategory, String uuid, long companyId,
1315                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
1316                    StringBundler query = null;
1317    
1318                    if (orderByComparator != null) {
1319                            query = new StringBundler(6 +
1320                                            (orderByComparator.getOrderByFields().length * 6));
1321                    }
1322                    else {
1323                            query = new StringBundler(3);
1324                    }
1325    
1326                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1327    
1328                    boolean bindUuid = false;
1329    
1330                    if (uuid == null) {
1331                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1332                    }
1333                    else if (uuid.equals(StringPool.BLANK)) {
1334                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1335                    }
1336                    else {
1337                            bindUuid = true;
1338    
1339                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1340                    }
1341    
1342                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1343    
1344                    if (orderByComparator != null) {
1345                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1346    
1347                            if (orderByConditionFields.length > 0) {
1348                                    query.append(WHERE_AND);
1349                            }
1350    
1351                            for (int i = 0; i < orderByConditionFields.length; i++) {
1352                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1353                                    query.append(orderByConditionFields[i]);
1354    
1355                                    if ((i + 1) < orderByConditionFields.length) {
1356                                            if (orderByComparator.isAscending() ^ previous) {
1357                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1358                                            }
1359                                            else {
1360                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1361                                            }
1362                                    }
1363                                    else {
1364                                            if (orderByComparator.isAscending() ^ previous) {
1365                                                    query.append(WHERE_GREATER_THAN);
1366                                            }
1367                                            else {
1368                                                    query.append(WHERE_LESSER_THAN);
1369                                            }
1370                                    }
1371                            }
1372    
1373                            query.append(ORDER_BY_CLAUSE);
1374    
1375                            String[] orderByFields = orderByComparator.getOrderByFields();
1376    
1377                            for (int i = 0; i < orderByFields.length; i++) {
1378                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1379                                    query.append(orderByFields[i]);
1380    
1381                                    if ((i + 1) < orderByFields.length) {
1382                                            if (orderByComparator.isAscending() ^ previous) {
1383                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1384                                            }
1385                                            else {
1386                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1387                                            }
1388                                    }
1389                                    else {
1390                                            if (orderByComparator.isAscending() ^ previous) {
1391                                                    query.append(ORDER_BY_ASC);
1392                                            }
1393                                            else {
1394                                                    query.append(ORDER_BY_DESC);
1395                                            }
1396                                    }
1397                            }
1398                    }
1399                    else {
1400                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1401                    }
1402    
1403                    String sql = query.toString();
1404    
1405                    Query q = session.createQuery(sql);
1406    
1407                    q.setFirstResult(0);
1408                    q.setMaxResults(2);
1409    
1410                    QueryPos qPos = QueryPos.getInstance(q);
1411    
1412                    if (bindUuid) {
1413                            qPos.add(uuid);
1414                    }
1415    
1416                    qPos.add(companyId);
1417    
1418                    if (orderByComparator != null) {
1419                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
1420    
1421                            for (Object value : values) {
1422                                    qPos.add(value);
1423                            }
1424                    }
1425    
1426                    List<AssetCategory> list = q.list();
1427    
1428                    if (list.size() == 2) {
1429                            return list.get(1);
1430                    }
1431                    else {
1432                            return null;
1433                    }
1434            }
1435    
1436            /**
1437             * Removes all the asset categories where uuid = &#63; and companyId = &#63; from the database.
1438             *
1439             * @param uuid the uuid
1440             * @param companyId the company ID
1441             */
1442            @Override
1443            public void removeByUuid_C(String uuid, long companyId) {
1444                    for (AssetCategory assetCategory : findByUuid_C(uuid, companyId,
1445                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1446                            remove(assetCategory);
1447                    }
1448            }
1449    
1450            /**
1451             * Returns the number of asset categories where uuid = &#63; and companyId = &#63;.
1452             *
1453             * @param uuid the uuid
1454             * @param companyId the company ID
1455             * @return the number of matching asset categories
1456             */
1457            @Override
1458            public int countByUuid_C(String uuid, long companyId) {
1459                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1460    
1461                    Object[] finderArgs = new Object[] { uuid, companyId };
1462    
1463                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1464    
1465                    if (count == null) {
1466                            StringBundler query = new StringBundler(3);
1467    
1468                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
1469    
1470                            boolean bindUuid = false;
1471    
1472                            if (uuid == null) {
1473                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1474                            }
1475                            else if (uuid.equals(StringPool.BLANK)) {
1476                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1477                            }
1478                            else {
1479                                    bindUuid = true;
1480    
1481                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1482                            }
1483    
1484                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1485    
1486                            String sql = query.toString();
1487    
1488                            Session session = null;
1489    
1490                            try {
1491                                    session = openSession();
1492    
1493                                    Query q = session.createQuery(sql);
1494    
1495                                    QueryPos qPos = QueryPos.getInstance(q);
1496    
1497                                    if (bindUuid) {
1498                                            qPos.add(uuid);
1499                                    }
1500    
1501                                    qPos.add(companyId);
1502    
1503                                    count = (Long)q.uniqueResult();
1504    
1505                                    finderCache.putResult(finderPath, finderArgs, count);
1506                            }
1507                            catch (Exception e) {
1508                                    finderCache.removeResult(finderPath, finderArgs);
1509    
1510                                    throw processException(e);
1511                            }
1512                            finally {
1513                                    closeSession(session);
1514                            }
1515                    }
1516    
1517                    return count.intValue();
1518            }
1519    
1520            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "assetCategory.uuid IS NULL AND ";
1521            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "assetCategory.uuid = ? AND ";
1522            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = '') AND ";
1523            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "assetCategory.companyId = ?";
1524            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1525                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
1526                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1527                            "findByGroupId",
1528                            new String[] {
1529                                    Long.class.getName(),
1530                                    
1531                            Integer.class.getName(), Integer.class.getName(),
1532                                    OrderByComparator.class.getName()
1533                            });
1534            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1535                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1536                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
1537                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1538                            "findByGroupId", new String[] { Long.class.getName() },
1539                            AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
1540                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
1541            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1542                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1543                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1544                            new String[] { Long.class.getName() });
1545    
1546            /**
1547             * Returns all the asset categories where groupId = &#63;.
1548             *
1549             * @param groupId the group ID
1550             * @return the matching asset categories
1551             */
1552            @Override
1553            public List<AssetCategory> findByGroupId(long groupId) {
1554                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1555            }
1556    
1557            /**
1558             * Returns a range of all the asset categories where groupId = &#63;.
1559             *
1560             * <p>
1561             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1562             * </p>
1563             *
1564             * @param groupId the group ID
1565             * @param start the lower bound of the range of asset categories
1566             * @param end the upper bound of the range of asset categories (not inclusive)
1567             * @return the range of matching asset categories
1568             */
1569            @Override
1570            public List<AssetCategory> findByGroupId(long groupId, int start, int end) {
1571                    return findByGroupId(groupId, start, end, null);
1572            }
1573    
1574            /**
1575             * Returns an ordered range of all the asset categories where groupId = &#63;.
1576             *
1577             * <p>
1578             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1579             * </p>
1580             *
1581             * @param groupId the group ID
1582             * @param start the lower bound of the range of asset categories
1583             * @param end the upper bound of the range of asset categories (not inclusive)
1584             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1585             * @return the ordered range of matching asset categories
1586             */
1587            @Override
1588            public List<AssetCategory> findByGroupId(long groupId, int start, int end,
1589                    OrderByComparator<AssetCategory> orderByComparator) {
1590                    return findByGroupId(groupId, start, end, orderByComparator, true);
1591            }
1592    
1593            /**
1594             * Returns an ordered range of all the asset categories where groupId = &#63;.
1595             *
1596             * <p>
1597             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1598             * </p>
1599             *
1600             * @param groupId the group ID
1601             * @param start the lower bound of the range of asset categories
1602             * @param end the upper bound of the range of asset categories (not inclusive)
1603             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1604             * @param retrieveFromCache whether to retrieve from the finder cache
1605             * @return the ordered range of matching asset categories
1606             */
1607            @Override
1608            public List<AssetCategory> findByGroupId(long groupId, int start, int end,
1609                    OrderByComparator<AssetCategory> orderByComparator,
1610                    boolean retrieveFromCache) {
1611                    boolean pagination = true;
1612                    FinderPath finderPath = null;
1613                    Object[] finderArgs = null;
1614    
1615                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1616                                    (orderByComparator == null)) {
1617                            pagination = false;
1618                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1619                            finderArgs = new Object[] { groupId };
1620                    }
1621                    else {
1622                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1623                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1624                    }
1625    
1626                    List<AssetCategory> list = null;
1627    
1628                    if (retrieveFromCache) {
1629                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
1630                                            finderArgs, this);
1631    
1632                            if ((list != null) && !list.isEmpty()) {
1633                                    for (AssetCategory assetCategory : list) {
1634                                            if ((groupId != assetCategory.getGroupId())) {
1635                                                    list = null;
1636    
1637                                                    break;
1638                                            }
1639                                    }
1640                            }
1641                    }
1642    
1643                    if (list == null) {
1644                            StringBundler query = null;
1645    
1646                            if (orderByComparator != null) {
1647                                    query = new StringBundler(3 +
1648                                                    (orderByComparator.getOrderByFields().length * 3));
1649                            }
1650                            else {
1651                                    query = new StringBundler(3);
1652                            }
1653    
1654                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1655    
1656                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1657    
1658                            if (orderByComparator != null) {
1659                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1660                                            orderByComparator);
1661                            }
1662                            else
1663                             if (pagination) {
1664                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1665                            }
1666    
1667                            String sql = query.toString();
1668    
1669                            Session session = null;
1670    
1671                            try {
1672                                    session = openSession();
1673    
1674                                    Query q = session.createQuery(sql);
1675    
1676                                    QueryPos qPos = QueryPos.getInstance(q);
1677    
1678                                    qPos.add(groupId);
1679    
1680                                    if (!pagination) {
1681                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1682                                                            start, end, false);
1683    
1684                                            Collections.sort(list);
1685    
1686                                            list = Collections.unmodifiableList(list);
1687                                    }
1688                                    else {
1689                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1690                                                            start, end);
1691                                    }
1692    
1693                                    cacheResult(list);
1694    
1695                                    finderCache.putResult(finderPath, finderArgs, list);
1696                            }
1697                            catch (Exception e) {
1698                                    finderCache.removeResult(finderPath, finderArgs);
1699    
1700                                    throw processException(e);
1701                            }
1702                            finally {
1703                                    closeSession(session);
1704                            }
1705                    }
1706    
1707                    return list;
1708            }
1709    
1710            /**
1711             * Returns the first asset category in the ordered set where groupId = &#63;.
1712             *
1713             * @param groupId the group ID
1714             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1715             * @return the first matching asset category
1716             * @throws NoSuchCategoryException if a matching asset category could not be found
1717             */
1718            @Override
1719            public AssetCategory findByGroupId_First(long groupId,
1720                    OrderByComparator<AssetCategory> orderByComparator)
1721                    throws NoSuchCategoryException {
1722                    AssetCategory assetCategory = fetchByGroupId_First(groupId,
1723                                    orderByComparator);
1724    
1725                    if (assetCategory != null) {
1726                            return assetCategory;
1727                    }
1728    
1729                    StringBundler msg = new StringBundler(4);
1730    
1731                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1732    
1733                    msg.append("groupId=");
1734                    msg.append(groupId);
1735    
1736                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1737    
1738                    throw new NoSuchCategoryException(msg.toString());
1739            }
1740    
1741            /**
1742             * Returns the first asset category in the ordered set where groupId = &#63;.
1743             *
1744             * @param groupId the group ID
1745             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1746             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
1747             */
1748            @Override
1749            public AssetCategory fetchByGroupId_First(long groupId,
1750                    OrderByComparator<AssetCategory> orderByComparator) {
1751                    List<AssetCategory> list = findByGroupId(groupId, 0, 1,
1752                                    orderByComparator);
1753    
1754                    if (!list.isEmpty()) {
1755                            return list.get(0);
1756                    }
1757    
1758                    return null;
1759            }
1760    
1761            /**
1762             * Returns the last asset category in the ordered set where groupId = &#63;.
1763             *
1764             * @param groupId the group ID
1765             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1766             * @return the last matching asset category
1767             * @throws NoSuchCategoryException if a matching asset category could not be found
1768             */
1769            @Override
1770            public AssetCategory findByGroupId_Last(long groupId,
1771                    OrderByComparator<AssetCategory> orderByComparator)
1772                    throws NoSuchCategoryException {
1773                    AssetCategory assetCategory = fetchByGroupId_Last(groupId,
1774                                    orderByComparator);
1775    
1776                    if (assetCategory != null) {
1777                            return assetCategory;
1778                    }
1779    
1780                    StringBundler msg = new StringBundler(4);
1781    
1782                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1783    
1784                    msg.append("groupId=");
1785                    msg.append(groupId);
1786    
1787                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1788    
1789                    throw new NoSuchCategoryException(msg.toString());
1790            }
1791    
1792            /**
1793             * Returns the last asset category in the ordered set where groupId = &#63;.
1794             *
1795             * @param groupId the group ID
1796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1797             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
1798             */
1799            @Override
1800            public AssetCategory fetchByGroupId_Last(long groupId,
1801                    OrderByComparator<AssetCategory> orderByComparator) {
1802                    int count = countByGroupId(groupId);
1803    
1804                    if (count == 0) {
1805                            return null;
1806                    }
1807    
1808                    List<AssetCategory> list = findByGroupId(groupId, count - 1, count,
1809                                    orderByComparator);
1810    
1811                    if (!list.isEmpty()) {
1812                            return list.get(0);
1813                    }
1814    
1815                    return null;
1816            }
1817    
1818            /**
1819             * Returns the asset categories before and after the current asset category in the ordered set where groupId = &#63;.
1820             *
1821             * @param categoryId the primary key of the current asset category
1822             * @param groupId the group ID
1823             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1824             * @return the previous, current, and next asset category
1825             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
1826             */
1827            @Override
1828            public AssetCategory[] findByGroupId_PrevAndNext(long categoryId,
1829                    long groupId, OrderByComparator<AssetCategory> orderByComparator)
1830                    throws NoSuchCategoryException {
1831                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
1832    
1833                    Session session = null;
1834    
1835                    try {
1836                            session = openSession();
1837    
1838                            AssetCategory[] array = new AssetCategoryImpl[3];
1839    
1840                            array[0] = getByGroupId_PrevAndNext(session, assetCategory,
1841                                            groupId, orderByComparator, true);
1842    
1843                            array[1] = assetCategory;
1844    
1845                            array[2] = getByGroupId_PrevAndNext(session, assetCategory,
1846                                            groupId, orderByComparator, false);
1847    
1848                            return array;
1849                    }
1850                    catch (Exception e) {
1851                            throw processException(e);
1852                    }
1853                    finally {
1854                            closeSession(session);
1855                    }
1856            }
1857    
1858            protected AssetCategory getByGroupId_PrevAndNext(Session session,
1859                    AssetCategory assetCategory, long groupId,
1860                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
1861                    StringBundler query = null;
1862    
1863                    if (orderByComparator != null) {
1864                            query = new StringBundler(6 +
1865                                            (orderByComparator.getOrderByFields().length * 6));
1866                    }
1867                    else {
1868                            query = new StringBundler(3);
1869                    }
1870    
1871                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1872    
1873                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1874    
1875                    if (orderByComparator != null) {
1876                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1877    
1878                            if (orderByConditionFields.length > 0) {
1879                                    query.append(WHERE_AND);
1880                            }
1881    
1882                            for (int i = 0; i < orderByConditionFields.length; i++) {
1883                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1884                                    query.append(orderByConditionFields[i]);
1885    
1886                                    if ((i + 1) < orderByConditionFields.length) {
1887                                            if (orderByComparator.isAscending() ^ previous) {
1888                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1889                                            }
1890                                            else {
1891                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1892                                            }
1893                                    }
1894                                    else {
1895                                            if (orderByComparator.isAscending() ^ previous) {
1896                                                    query.append(WHERE_GREATER_THAN);
1897                                            }
1898                                            else {
1899                                                    query.append(WHERE_LESSER_THAN);
1900                                            }
1901                                    }
1902                            }
1903    
1904                            query.append(ORDER_BY_CLAUSE);
1905    
1906                            String[] orderByFields = orderByComparator.getOrderByFields();
1907    
1908                            for (int i = 0; i < orderByFields.length; i++) {
1909                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1910                                    query.append(orderByFields[i]);
1911    
1912                                    if ((i + 1) < orderByFields.length) {
1913                                            if (orderByComparator.isAscending() ^ previous) {
1914                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1915                                            }
1916                                            else {
1917                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1918                                            }
1919                                    }
1920                                    else {
1921                                            if (orderByComparator.isAscending() ^ previous) {
1922                                                    query.append(ORDER_BY_ASC);
1923                                            }
1924                                            else {
1925                                                    query.append(ORDER_BY_DESC);
1926                                            }
1927                                    }
1928                            }
1929                    }
1930                    else {
1931                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1932                    }
1933    
1934                    String sql = query.toString();
1935    
1936                    Query q = session.createQuery(sql);
1937    
1938                    q.setFirstResult(0);
1939                    q.setMaxResults(2);
1940    
1941                    QueryPos qPos = QueryPos.getInstance(q);
1942    
1943                    qPos.add(groupId);
1944    
1945                    if (orderByComparator != null) {
1946                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
1947    
1948                            for (Object value : values) {
1949                                    qPos.add(value);
1950                            }
1951                    }
1952    
1953                    List<AssetCategory> list = q.list();
1954    
1955                    if (list.size() == 2) {
1956                            return list.get(1);
1957                    }
1958                    else {
1959                            return null;
1960                    }
1961            }
1962    
1963            /**
1964             * Returns all the asset categories that the user has permission to view where groupId = &#63;.
1965             *
1966             * @param groupId the group ID
1967             * @return the matching asset categories that the user has permission to view
1968             */
1969            @Override
1970            public List<AssetCategory> filterFindByGroupId(long groupId) {
1971                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1972                            QueryUtil.ALL_POS, null);
1973            }
1974    
1975            /**
1976             * Returns a range of all the asset categories that the user has permission to view where groupId = &#63;.
1977             *
1978             * <p>
1979             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1980             * </p>
1981             *
1982             * @param groupId the group ID
1983             * @param start the lower bound of the range of asset categories
1984             * @param end the upper bound of the range of asset categories (not inclusive)
1985             * @return the range of matching asset categories that the user has permission to view
1986             */
1987            @Override
1988            public List<AssetCategory> filterFindByGroupId(long groupId, int start,
1989                    int end) {
1990                    return filterFindByGroupId(groupId, start, end, null);
1991            }
1992    
1993            /**
1994             * Returns an ordered range of all the asset categories that the user has permissions to view where groupId = &#63;.
1995             *
1996             * <p>
1997             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1998             * </p>
1999             *
2000             * @param groupId the group ID
2001             * @param start the lower bound of the range of asset categories
2002             * @param end the upper bound of the range of asset categories (not inclusive)
2003             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2004             * @return the ordered range of matching asset categories that the user has permission to view
2005             */
2006            @Override
2007            public List<AssetCategory> filterFindByGroupId(long groupId, int start,
2008                    int end, OrderByComparator<AssetCategory> orderByComparator) {
2009                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2010                            return findByGroupId(groupId, start, end, orderByComparator);
2011                    }
2012    
2013                    StringBundler query = null;
2014    
2015                    if (orderByComparator != null) {
2016                            query = new StringBundler(3 +
2017                                            (orderByComparator.getOrderByFields().length * 3));
2018                    }
2019                    else {
2020                            query = new StringBundler(3);
2021                    }
2022    
2023                    if (getDB().isSupportsInlineDistinct()) {
2024                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
2025                    }
2026                    else {
2027                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2028                    }
2029    
2030                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2031    
2032                    if (!getDB().isSupportsInlineDistinct()) {
2033                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2034                    }
2035    
2036                    if (orderByComparator != null) {
2037                            if (getDB().isSupportsInlineDistinct()) {
2038                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2039                                            orderByComparator, true);
2040                            }
2041                            else {
2042                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2043                                            orderByComparator, true);
2044                            }
2045                    }
2046                    else {
2047                            if (getDB().isSupportsInlineDistinct()) {
2048                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2049                            }
2050                            else {
2051                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
2052                            }
2053                    }
2054    
2055                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2056                                    AssetCategory.class.getName(),
2057                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2058    
2059                    Session session = null;
2060    
2061                    try {
2062                            session = openSession();
2063    
2064                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2065    
2066                            if (getDB().isSupportsInlineDistinct()) {
2067                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
2068                            }
2069                            else {
2070                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
2071                            }
2072    
2073                            QueryPos qPos = QueryPos.getInstance(q);
2074    
2075                            qPos.add(groupId);
2076    
2077                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
2078                                    end);
2079                    }
2080                    catch (Exception e) {
2081                            throw processException(e);
2082                    }
2083                    finally {
2084                            closeSession(session);
2085                    }
2086            }
2087    
2088            /**
2089             * Returns the asset categories before and after the current asset category in the ordered set of asset categories that the user has permission to view where groupId = &#63;.
2090             *
2091             * @param categoryId the primary key of the current asset category
2092             * @param groupId the group ID
2093             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2094             * @return the previous, current, and next asset category
2095             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
2096             */
2097            @Override
2098            public AssetCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
2099                    long groupId, OrderByComparator<AssetCategory> orderByComparator)
2100                    throws NoSuchCategoryException {
2101                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2102                            return findByGroupId_PrevAndNext(categoryId, groupId,
2103                                    orderByComparator);
2104                    }
2105    
2106                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
2107    
2108                    Session session = null;
2109    
2110                    try {
2111                            session = openSession();
2112    
2113                            AssetCategory[] array = new AssetCategoryImpl[3];
2114    
2115                            array[0] = filterGetByGroupId_PrevAndNext(session, assetCategory,
2116                                            groupId, orderByComparator, true);
2117    
2118                            array[1] = assetCategory;
2119    
2120                            array[2] = filterGetByGroupId_PrevAndNext(session, assetCategory,
2121                                            groupId, orderByComparator, false);
2122    
2123                            return array;
2124                    }
2125                    catch (Exception e) {
2126                            throw processException(e);
2127                    }
2128                    finally {
2129                            closeSession(session);
2130                    }
2131            }
2132    
2133            protected AssetCategory filterGetByGroupId_PrevAndNext(Session session,
2134                    AssetCategory assetCategory, long groupId,
2135                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
2136                    StringBundler query = null;
2137    
2138                    if (orderByComparator != null) {
2139                            query = new StringBundler(6 +
2140                                            (orderByComparator.getOrderByFields().length * 6));
2141                    }
2142                    else {
2143                            query = new StringBundler(3);
2144                    }
2145    
2146                    if (getDB().isSupportsInlineDistinct()) {
2147                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
2148                    }
2149                    else {
2150                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2151                    }
2152    
2153                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2154    
2155                    if (!getDB().isSupportsInlineDistinct()) {
2156                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2157                    }
2158    
2159                    if (orderByComparator != null) {
2160                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2161    
2162                            if (orderByConditionFields.length > 0) {
2163                                    query.append(WHERE_AND);
2164                            }
2165    
2166                            for (int i = 0; i < orderByConditionFields.length; i++) {
2167                                    if (getDB().isSupportsInlineDistinct()) {
2168                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2169                                    }
2170                                    else {
2171                                            query.append(_ORDER_BY_ENTITY_TABLE);
2172                                    }
2173    
2174                                    query.append(orderByConditionFields[i]);
2175    
2176                                    if ((i + 1) < orderByConditionFields.length) {
2177                                            if (orderByComparator.isAscending() ^ previous) {
2178                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2179                                            }
2180                                            else {
2181                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2182                                            }
2183                                    }
2184                                    else {
2185                                            if (orderByComparator.isAscending() ^ previous) {
2186                                                    query.append(WHERE_GREATER_THAN);
2187                                            }
2188                                            else {
2189                                                    query.append(WHERE_LESSER_THAN);
2190                                            }
2191                                    }
2192                            }
2193    
2194                            query.append(ORDER_BY_CLAUSE);
2195    
2196                            String[] orderByFields = orderByComparator.getOrderByFields();
2197    
2198                            for (int i = 0; i < orderByFields.length; i++) {
2199                                    if (getDB().isSupportsInlineDistinct()) {
2200                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2201                                    }
2202                                    else {
2203                                            query.append(_ORDER_BY_ENTITY_TABLE);
2204                                    }
2205    
2206                                    query.append(orderByFields[i]);
2207    
2208                                    if ((i + 1) < orderByFields.length) {
2209                                            if (orderByComparator.isAscending() ^ previous) {
2210                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2211                                            }
2212                                            else {
2213                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2214                                            }
2215                                    }
2216                                    else {
2217                                            if (orderByComparator.isAscending() ^ previous) {
2218                                                    query.append(ORDER_BY_ASC);
2219                                            }
2220                                            else {
2221                                                    query.append(ORDER_BY_DESC);
2222                                            }
2223                                    }
2224                            }
2225                    }
2226                    else {
2227                            if (getDB().isSupportsInlineDistinct()) {
2228                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2229                            }
2230                            else {
2231                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
2232                            }
2233                    }
2234    
2235                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2236                                    AssetCategory.class.getName(),
2237                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2238    
2239                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2240    
2241                    q.setFirstResult(0);
2242                    q.setMaxResults(2);
2243    
2244                    if (getDB().isSupportsInlineDistinct()) {
2245                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
2246                    }
2247                    else {
2248                            q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
2249                    }
2250    
2251                    QueryPos qPos = QueryPos.getInstance(q);
2252    
2253                    qPos.add(groupId);
2254    
2255                    if (orderByComparator != null) {
2256                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
2257    
2258                            for (Object value : values) {
2259                                    qPos.add(value);
2260                            }
2261                    }
2262    
2263                    List<AssetCategory> list = q.list();
2264    
2265                    if (list.size() == 2) {
2266                            return list.get(1);
2267                    }
2268                    else {
2269                            return null;
2270                    }
2271            }
2272    
2273            /**
2274             * Removes all the asset categories where groupId = &#63; from the database.
2275             *
2276             * @param groupId the group ID
2277             */
2278            @Override
2279            public void removeByGroupId(long groupId) {
2280                    for (AssetCategory assetCategory : findByGroupId(groupId,
2281                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2282                            remove(assetCategory);
2283                    }
2284            }
2285    
2286            /**
2287             * Returns the number of asset categories where groupId = &#63;.
2288             *
2289             * @param groupId the group ID
2290             * @return the number of matching asset categories
2291             */
2292            @Override
2293            public int countByGroupId(long groupId) {
2294                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2295    
2296                    Object[] finderArgs = new Object[] { groupId };
2297    
2298                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2299    
2300                    if (count == null) {
2301                            StringBundler query = new StringBundler(2);
2302    
2303                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
2304    
2305                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2306    
2307                            String sql = query.toString();
2308    
2309                            Session session = null;
2310    
2311                            try {
2312                                    session = openSession();
2313    
2314                                    Query q = session.createQuery(sql);
2315    
2316                                    QueryPos qPos = QueryPos.getInstance(q);
2317    
2318                                    qPos.add(groupId);
2319    
2320                                    count = (Long)q.uniqueResult();
2321    
2322                                    finderCache.putResult(finderPath, finderArgs, count);
2323                            }
2324                            catch (Exception e) {
2325                                    finderCache.removeResult(finderPath, finderArgs);
2326    
2327                                    throw processException(e);
2328                            }
2329                            finally {
2330                                    closeSession(session);
2331                            }
2332                    }
2333    
2334                    return count.intValue();
2335            }
2336    
2337            /**
2338             * Returns the number of asset categories that the user has permission to view where groupId = &#63;.
2339             *
2340             * @param groupId the group ID
2341             * @return the number of matching asset categories that the user has permission to view
2342             */
2343            @Override
2344            public int filterCountByGroupId(long groupId) {
2345                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2346                            return countByGroupId(groupId);
2347                    }
2348    
2349                    StringBundler query = new StringBundler(2);
2350    
2351                    query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
2352    
2353                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2354    
2355                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2356                                    AssetCategory.class.getName(),
2357                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2358    
2359                    Session session = null;
2360    
2361                    try {
2362                            session = openSession();
2363    
2364                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2365    
2366                            q.addScalar(COUNT_COLUMN_NAME,
2367                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2368    
2369                            QueryPos qPos = QueryPos.getInstance(q);
2370    
2371                            qPos.add(groupId);
2372    
2373                            Long count = (Long)q.uniqueResult();
2374    
2375                            return count.intValue();
2376                    }
2377                    catch (Exception e) {
2378                            throw processException(e);
2379                    }
2380                    finally {
2381                            closeSession(session);
2382                    }
2383            }
2384    
2385            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetCategory.groupId = ?";
2386            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTCATEGORYID =
2387                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2388                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2389                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2390                            "findByParentCategoryId",
2391                            new String[] {
2392                                    Long.class.getName(),
2393                                    
2394                            Integer.class.getName(), Integer.class.getName(),
2395                                    OrderByComparator.class.getName()
2396                            });
2397            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID =
2398                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2399                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2400                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2401                            "findByParentCategoryId", new String[] { Long.class.getName() },
2402                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2403                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
2404            public static final FinderPath FINDER_PATH_COUNT_BY_PARENTCATEGORYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2405                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2406                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2407                            "countByParentCategoryId", new String[] { Long.class.getName() });
2408    
2409            /**
2410             * Returns all the asset categories where parentCategoryId = &#63;.
2411             *
2412             * @param parentCategoryId the parent category ID
2413             * @return the matching asset categories
2414             */
2415            @Override
2416            public List<AssetCategory> findByParentCategoryId(long parentCategoryId) {
2417                    return findByParentCategoryId(parentCategoryId, QueryUtil.ALL_POS,
2418                            QueryUtil.ALL_POS, null);
2419            }
2420    
2421            /**
2422             * Returns a range of all the asset categories where parentCategoryId = &#63;.
2423             *
2424             * <p>
2425             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2426             * </p>
2427             *
2428             * @param parentCategoryId the parent category ID
2429             * @param start the lower bound of the range of asset categories
2430             * @param end the upper bound of the range of asset categories (not inclusive)
2431             * @return the range of matching asset categories
2432             */
2433            @Override
2434            public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
2435                    int start, int end) {
2436                    return findByParentCategoryId(parentCategoryId, start, end, null);
2437            }
2438    
2439            /**
2440             * Returns an ordered range of all the asset categories where parentCategoryId = &#63;.
2441             *
2442             * <p>
2443             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2444             * </p>
2445             *
2446             * @param parentCategoryId the parent category ID
2447             * @param start the lower bound of the range of asset categories
2448             * @param end the upper bound of the range of asset categories (not inclusive)
2449             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2450             * @return the ordered range of matching asset categories
2451             */
2452            @Override
2453            public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
2454                    int start, int end, OrderByComparator<AssetCategory> orderByComparator) {
2455                    return findByParentCategoryId(parentCategoryId, start, end,
2456                            orderByComparator, true);
2457            }
2458    
2459            /**
2460             * Returns an ordered range of all the asset categories where parentCategoryId = &#63;.
2461             *
2462             * <p>
2463             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2464             * </p>
2465             *
2466             * @param parentCategoryId the parent category ID
2467             * @param start the lower bound of the range of asset categories
2468             * @param end the upper bound of the range of asset categories (not inclusive)
2469             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2470             * @param retrieveFromCache whether to retrieve from the finder cache
2471             * @return the ordered range of matching asset categories
2472             */
2473            @Override
2474            public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
2475                    int start, int end, OrderByComparator<AssetCategory> orderByComparator,
2476                    boolean retrieveFromCache) {
2477                    boolean pagination = true;
2478                    FinderPath finderPath = null;
2479                    Object[] finderArgs = null;
2480    
2481                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2482                                    (orderByComparator == null)) {
2483                            pagination = false;
2484                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID;
2485                            finderArgs = new Object[] { parentCategoryId };
2486                    }
2487                    else {
2488                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTCATEGORYID;
2489                            finderArgs = new Object[] {
2490                                            parentCategoryId,
2491                                            
2492                                            start, end, orderByComparator
2493                                    };
2494                    }
2495    
2496                    List<AssetCategory> list = null;
2497    
2498                    if (retrieveFromCache) {
2499                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
2500                                            finderArgs, this);
2501    
2502                            if ((list != null) && !list.isEmpty()) {
2503                                    for (AssetCategory assetCategory : list) {
2504                                            if ((parentCategoryId != assetCategory.getParentCategoryId())) {
2505                                                    list = null;
2506    
2507                                                    break;
2508                                            }
2509                                    }
2510                            }
2511                    }
2512    
2513                    if (list == null) {
2514                            StringBundler query = null;
2515    
2516                            if (orderByComparator != null) {
2517                                    query = new StringBundler(3 +
2518                                                    (orderByComparator.getOrderByFields().length * 3));
2519                            }
2520                            else {
2521                                    query = new StringBundler(3);
2522                            }
2523    
2524                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2525    
2526                            query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2527    
2528                            if (orderByComparator != null) {
2529                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2530                                            orderByComparator);
2531                            }
2532                            else
2533                             if (pagination) {
2534                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2535                            }
2536    
2537                            String sql = query.toString();
2538    
2539                            Session session = null;
2540    
2541                            try {
2542                                    session = openSession();
2543    
2544                                    Query q = session.createQuery(sql);
2545    
2546                                    QueryPos qPos = QueryPos.getInstance(q);
2547    
2548                                    qPos.add(parentCategoryId);
2549    
2550                                    if (!pagination) {
2551                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2552                                                            start, end, false);
2553    
2554                                            Collections.sort(list);
2555    
2556                                            list = Collections.unmodifiableList(list);
2557                                    }
2558                                    else {
2559                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2560                                                            start, end);
2561                                    }
2562    
2563                                    cacheResult(list);
2564    
2565                                    finderCache.putResult(finderPath, finderArgs, list);
2566                            }
2567                            catch (Exception e) {
2568                                    finderCache.removeResult(finderPath, finderArgs);
2569    
2570                                    throw processException(e);
2571                            }
2572                            finally {
2573                                    closeSession(session);
2574                            }
2575                    }
2576    
2577                    return list;
2578            }
2579    
2580            /**
2581             * Returns the first asset category in the ordered set where parentCategoryId = &#63;.
2582             *
2583             * @param parentCategoryId the parent category ID
2584             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2585             * @return the first matching asset category
2586             * @throws NoSuchCategoryException if a matching asset category could not be found
2587             */
2588            @Override
2589            public AssetCategory findByParentCategoryId_First(long parentCategoryId,
2590                    OrderByComparator<AssetCategory> orderByComparator)
2591                    throws NoSuchCategoryException {
2592                    AssetCategory assetCategory = fetchByParentCategoryId_First(parentCategoryId,
2593                                    orderByComparator);
2594    
2595                    if (assetCategory != null) {
2596                            return assetCategory;
2597                    }
2598    
2599                    StringBundler msg = new StringBundler(4);
2600    
2601                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2602    
2603                    msg.append("parentCategoryId=");
2604                    msg.append(parentCategoryId);
2605    
2606                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2607    
2608                    throw new NoSuchCategoryException(msg.toString());
2609            }
2610    
2611            /**
2612             * Returns the first asset category in the ordered set where parentCategoryId = &#63;.
2613             *
2614             * @param parentCategoryId the parent category ID
2615             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2616             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
2617             */
2618            @Override
2619            public AssetCategory fetchByParentCategoryId_First(long parentCategoryId,
2620                    OrderByComparator<AssetCategory> orderByComparator) {
2621                    List<AssetCategory> list = findByParentCategoryId(parentCategoryId, 0,
2622                                    1, orderByComparator);
2623    
2624                    if (!list.isEmpty()) {
2625                            return list.get(0);
2626                    }
2627    
2628                    return null;
2629            }
2630    
2631            /**
2632             * Returns the last asset category in the ordered set where parentCategoryId = &#63;.
2633             *
2634             * @param parentCategoryId the parent category ID
2635             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2636             * @return the last matching asset category
2637             * @throws NoSuchCategoryException if a matching asset category could not be found
2638             */
2639            @Override
2640            public AssetCategory findByParentCategoryId_Last(long parentCategoryId,
2641                    OrderByComparator<AssetCategory> orderByComparator)
2642                    throws NoSuchCategoryException {
2643                    AssetCategory assetCategory = fetchByParentCategoryId_Last(parentCategoryId,
2644                                    orderByComparator);
2645    
2646                    if (assetCategory != null) {
2647                            return assetCategory;
2648                    }
2649    
2650                    StringBundler msg = new StringBundler(4);
2651    
2652                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2653    
2654                    msg.append("parentCategoryId=");
2655                    msg.append(parentCategoryId);
2656    
2657                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2658    
2659                    throw new NoSuchCategoryException(msg.toString());
2660            }
2661    
2662            /**
2663             * Returns the last asset category in the ordered set where parentCategoryId = &#63;.
2664             *
2665             * @param parentCategoryId the parent category ID
2666             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2667             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
2668             */
2669            @Override
2670            public AssetCategory fetchByParentCategoryId_Last(long parentCategoryId,
2671                    OrderByComparator<AssetCategory> orderByComparator) {
2672                    int count = countByParentCategoryId(parentCategoryId);
2673    
2674                    if (count == 0) {
2675                            return null;
2676                    }
2677    
2678                    List<AssetCategory> list = findByParentCategoryId(parentCategoryId,
2679                                    count - 1, count, orderByComparator);
2680    
2681                    if (!list.isEmpty()) {
2682                            return list.get(0);
2683                    }
2684    
2685                    return null;
2686            }
2687    
2688            /**
2689             * Returns the asset categories before and after the current asset category in the ordered set where parentCategoryId = &#63;.
2690             *
2691             * @param categoryId the primary key of the current asset category
2692             * @param parentCategoryId the parent category ID
2693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2694             * @return the previous, current, and next asset category
2695             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
2696             */
2697            @Override
2698            public AssetCategory[] findByParentCategoryId_PrevAndNext(long categoryId,
2699                    long parentCategoryId,
2700                    OrderByComparator<AssetCategory> orderByComparator)
2701                    throws NoSuchCategoryException {
2702                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
2703    
2704                    Session session = null;
2705    
2706                    try {
2707                            session = openSession();
2708    
2709                            AssetCategory[] array = new AssetCategoryImpl[3];
2710    
2711                            array[0] = getByParentCategoryId_PrevAndNext(session,
2712                                            assetCategory, parentCategoryId, orderByComparator, true);
2713    
2714                            array[1] = assetCategory;
2715    
2716                            array[2] = getByParentCategoryId_PrevAndNext(session,
2717                                            assetCategory, parentCategoryId, orderByComparator, false);
2718    
2719                            return array;
2720                    }
2721                    catch (Exception e) {
2722                            throw processException(e);
2723                    }
2724                    finally {
2725                            closeSession(session);
2726                    }
2727            }
2728    
2729            protected AssetCategory getByParentCategoryId_PrevAndNext(Session session,
2730                    AssetCategory assetCategory, long parentCategoryId,
2731                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
2732                    StringBundler query = null;
2733    
2734                    if (orderByComparator != null) {
2735                            query = new StringBundler(6 +
2736                                            (orderByComparator.getOrderByFields().length * 6));
2737                    }
2738                    else {
2739                            query = new StringBundler(3);
2740                    }
2741    
2742                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2743    
2744                    query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2745    
2746                    if (orderByComparator != null) {
2747                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2748    
2749                            if (orderByConditionFields.length > 0) {
2750                                    query.append(WHERE_AND);
2751                            }
2752    
2753                            for (int i = 0; i < orderByConditionFields.length; i++) {
2754                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2755                                    query.append(orderByConditionFields[i]);
2756    
2757                                    if ((i + 1) < orderByConditionFields.length) {
2758                                            if (orderByComparator.isAscending() ^ previous) {
2759                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2760                                            }
2761                                            else {
2762                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2763                                            }
2764                                    }
2765                                    else {
2766                                            if (orderByComparator.isAscending() ^ previous) {
2767                                                    query.append(WHERE_GREATER_THAN);
2768                                            }
2769                                            else {
2770                                                    query.append(WHERE_LESSER_THAN);
2771                                            }
2772                                    }
2773                            }
2774    
2775                            query.append(ORDER_BY_CLAUSE);
2776    
2777                            String[] orderByFields = orderByComparator.getOrderByFields();
2778    
2779                            for (int i = 0; i < orderByFields.length; i++) {
2780                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2781                                    query.append(orderByFields[i]);
2782    
2783                                    if ((i + 1) < orderByFields.length) {
2784                                            if (orderByComparator.isAscending() ^ previous) {
2785                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2786                                            }
2787                                            else {
2788                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2789                                            }
2790                                    }
2791                                    else {
2792                                            if (orderByComparator.isAscending() ^ previous) {
2793                                                    query.append(ORDER_BY_ASC);
2794                                            }
2795                                            else {
2796                                                    query.append(ORDER_BY_DESC);
2797                                            }
2798                                    }
2799                            }
2800                    }
2801                    else {
2802                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2803                    }
2804    
2805                    String sql = query.toString();
2806    
2807                    Query q = session.createQuery(sql);
2808    
2809                    q.setFirstResult(0);
2810                    q.setMaxResults(2);
2811    
2812                    QueryPos qPos = QueryPos.getInstance(q);
2813    
2814                    qPos.add(parentCategoryId);
2815    
2816                    if (orderByComparator != null) {
2817                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
2818    
2819                            for (Object value : values) {
2820                                    qPos.add(value);
2821                            }
2822                    }
2823    
2824                    List<AssetCategory> list = q.list();
2825    
2826                    if (list.size() == 2) {
2827                            return list.get(1);
2828                    }
2829                    else {
2830                            return null;
2831                    }
2832            }
2833    
2834            /**
2835             * Removes all the asset categories where parentCategoryId = &#63; from the database.
2836             *
2837             * @param parentCategoryId the parent category ID
2838             */
2839            @Override
2840            public void removeByParentCategoryId(long parentCategoryId) {
2841                    for (AssetCategory assetCategory : findByParentCategoryId(
2842                                    parentCategoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2843                            remove(assetCategory);
2844                    }
2845            }
2846    
2847            /**
2848             * Returns the number of asset categories where parentCategoryId = &#63;.
2849             *
2850             * @param parentCategoryId the parent category ID
2851             * @return the number of matching asset categories
2852             */
2853            @Override
2854            public int countByParentCategoryId(long parentCategoryId) {
2855                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PARENTCATEGORYID;
2856    
2857                    Object[] finderArgs = new Object[] { parentCategoryId };
2858    
2859                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2860    
2861                    if (count == null) {
2862                            StringBundler query = new StringBundler(2);
2863    
2864                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
2865    
2866                            query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2867    
2868                            String sql = query.toString();
2869    
2870                            Session session = null;
2871    
2872                            try {
2873                                    session = openSession();
2874    
2875                                    Query q = session.createQuery(sql);
2876    
2877                                    QueryPos qPos = QueryPos.getInstance(q);
2878    
2879                                    qPos.add(parentCategoryId);
2880    
2881                                    count = (Long)q.uniqueResult();
2882    
2883                                    finderCache.putResult(finderPath, finderArgs, count);
2884                            }
2885                            catch (Exception e) {
2886                                    finderCache.removeResult(finderPath, finderArgs);
2887    
2888                                    throw processException(e);
2889                            }
2890                            finally {
2891                                    closeSession(session);
2892                            }
2893                    }
2894    
2895                    return count.intValue();
2896            }
2897    
2898            private static final String _FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2 =
2899                    "assetCategory.parentCategoryId = ?";
2900            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_VOCABULARYID =
2901                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2902                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2903                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2904                            "findByVocabularyId",
2905                            new String[] {
2906                                    Long.class.getName(),
2907                                    
2908                            Integer.class.getName(), Integer.class.getName(),
2909                                    OrderByComparator.class.getName()
2910                            });
2911            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID =
2912                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2913                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2914                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2915                            "findByVocabularyId", new String[] { Long.class.getName() },
2916                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
2917                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
2918            public static final FinderPath FINDER_PATH_COUNT_BY_VOCABULARYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2919                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2920                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByVocabularyId",
2921                            new String[] { Long.class.getName() });
2922    
2923            /**
2924             * Returns all the asset categories where vocabularyId = &#63;.
2925             *
2926             * @param vocabularyId the vocabulary ID
2927             * @return the matching asset categories
2928             */
2929            @Override
2930            public List<AssetCategory> findByVocabularyId(long vocabularyId) {
2931                    return findByVocabularyId(vocabularyId, QueryUtil.ALL_POS,
2932                            QueryUtil.ALL_POS, null);
2933            }
2934    
2935            /**
2936             * Returns a range of all the asset categories where vocabularyId = &#63;.
2937             *
2938             * <p>
2939             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2940             * </p>
2941             *
2942             * @param vocabularyId the vocabulary ID
2943             * @param start the lower bound of the range of asset categories
2944             * @param end the upper bound of the range of asset categories (not inclusive)
2945             * @return the range of matching asset categories
2946             */
2947            @Override
2948            public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
2949                    int end) {
2950                    return findByVocabularyId(vocabularyId, start, end, null);
2951            }
2952    
2953            /**
2954             * Returns an ordered range of all the asset categories where vocabularyId = &#63;.
2955             *
2956             * <p>
2957             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2958             * </p>
2959             *
2960             * @param vocabularyId the vocabulary ID
2961             * @param start the lower bound of the range of asset categories
2962             * @param end the upper bound of the range of asset categories (not inclusive)
2963             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2964             * @return the ordered range of matching asset categories
2965             */
2966            @Override
2967            public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
2968                    int end, OrderByComparator<AssetCategory> orderByComparator) {
2969                    return findByVocabularyId(vocabularyId, start, end, orderByComparator,
2970                            true);
2971            }
2972    
2973            /**
2974             * Returns an ordered range of all the asset categories where vocabularyId = &#63;.
2975             *
2976             * <p>
2977             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2978             * </p>
2979             *
2980             * @param vocabularyId the vocabulary ID
2981             * @param start the lower bound of the range of asset categories
2982             * @param end the upper bound of the range of asset categories (not inclusive)
2983             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2984             * @param retrieveFromCache whether to retrieve from the finder cache
2985             * @return the ordered range of matching asset categories
2986             */
2987            @Override
2988            public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
2989                    int end, OrderByComparator<AssetCategory> orderByComparator,
2990                    boolean retrieveFromCache) {
2991                    boolean pagination = true;
2992                    FinderPath finderPath = null;
2993                    Object[] finderArgs = null;
2994    
2995                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2996                                    (orderByComparator == null)) {
2997                            pagination = false;
2998                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID;
2999                            finderArgs = new Object[] { vocabularyId };
3000                    }
3001                    else {
3002                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_VOCABULARYID;
3003                            finderArgs = new Object[] {
3004                                            vocabularyId,
3005                                            
3006                                            start, end, orderByComparator
3007                                    };
3008                    }
3009    
3010                    List<AssetCategory> list = null;
3011    
3012                    if (retrieveFromCache) {
3013                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
3014                                            finderArgs, this);
3015    
3016                            if ((list != null) && !list.isEmpty()) {
3017                                    for (AssetCategory assetCategory : list) {
3018                                            if ((vocabularyId != assetCategory.getVocabularyId())) {
3019                                                    list = null;
3020    
3021                                                    break;
3022                                            }
3023                                    }
3024                            }
3025                    }
3026    
3027                    if (list == null) {
3028                            StringBundler query = null;
3029    
3030                            if (orderByComparator != null) {
3031                                    query = new StringBundler(3 +
3032                                                    (orderByComparator.getOrderByFields().length * 3));
3033                            }
3034                            else {
3035                                    query = new StringBundler(3);
3036                            }
3037    
3038                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3039    
3040                            query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
3041    
3042                            if (orderByComparator != null) {
3043                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3044                                            orderByComparator);
3045                            }
3046                            else
3047                             if (pagination) {
3048                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3049                            }
3050    
3051                            String sql = query.toString();
3052    
3053                            Session session = null;
3054    
3055                            try {
3056                                    session = openSession();
3057    
3058                                    Query q = session.createQuery(sql);
3059    
3060                                    QueryPos qPos = QueryPos.getInstance(q);
3061    
3062                                    qPos.add(vocabularyId);
3063    
3064                                    if (!pagination) {
3065                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3066                                                            start, end, false);
3067    
3068                                            Collections.sort(list);
3069    
3070                                            list = Collections.unmodifiableList(list);
3071                                    }
3072                                    else {
3073                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3074                                                            start, end);
3075                                    }
3076    
3077                                    cacheResult(list);
3078    
3079                                    finderCache.putResult(finderPath, finderArgs, list);
3080                            }
3081                            catch (Exception e) {
3082                                    finderCache.removeResult(finderPath, finderArgs);
3083    
3084                                    throw processException(e);
3085                            }
3086                            finally {
3087                                    closeSession(session);
3088                            }
3089                    }
3090    
3091                    return list;
3092            }
3093    
3094            /**
3095             * Returns the first asset category in the ordered set where vocabularyId = &#63;.
3096             *
3097             * @param vocabularyId the vocabulary ID
3098             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3099             * @return the first matching asset category
3100             * @throws NoSuchCategoryException if a matching asset category could not be found
3101             */
3102            @Override
3103            public AssetCategory findByVocabularyId_First(long vocabularyId,
3104                    OrderByComparator<AssetCategory> orderByComparator)
3105                    throws NoSuchCategoryException {
3106                    AssetCategory assetCategory = fetchByVocabularyId_First(vocabularyId,
3107                                    orderByComparator);
3108    
3109                    if (assetCategory != null) {
3110                            return assetCategory;
3111                    }
3112    
3113                    StringBundler msg = new StringBundler(4);
3114    
3115                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3116    
3117                    msg.append("vocabularyId=");
3118                    msg.append(vocabularyId);
3119    
3120                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3121    
3122                    throw new NoSuchCategoryException(msg.toString());
3123            }
3124    
3125            /**
3126             * Returns the first asset category in the ordered set where vocabularyId = &#63;.
3127             *
3128             * @param vocabularyId the vocabulary ID
3129             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3130             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
3131             */
3132            @Override
3133            public AssetCategory fetchByVocabularyId_First(long vocabularyId,
3134                    OrderByComparator<AssetCategory> orderByComparator) {
3135                    List<AssetCategory> list = findByVocabularyId(vocabularyId, 0, 1,
3136                                    orderByComparator);
3137    
3138                    if (!list.isEmpty()) {
3139                            return list.get(0);
3140                    }
3141    
3142                    return null;
3143            }
3144    
3145            /**
3146             * Returns the last asset category in the ordered set where vocabularyId = &#63;.
3147             *
3148             * @param vocabularyId the vocabulary ID
3149             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3150             * @return the last matching asset category
3151             * @throws NoSuchCategoryException if a matching asset category could not be found
3152             */
3153            @Override
3154            public AssetCategory findByVocabularyId_Last(long vocabularyId,
3155                    OrderByComparator<AssetCategory> orderByComparator)
3156                    throws NoSuchCategoryException {
3157                    AssetCategory assetCategory = fetchByVocabularyId_Last(vocabularyId,
3158                                    orderByComparator);
3159    
3160                    if (assetCategory != null) {
3161                            return assetCategory;
3162                    }
3163    
3164                    StringBundler msg = new StringBundler(4);
3165    
3166                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3167    
3168                    msg.append("vocabularyId=");
3169                    msg.append(vocabularyId);
3170    
3171                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3172    
3173                    throw new NoSuchCategoryException(msg.toString());
3174            }
3175    
3176            /**
3177             * Returns the last asset category in the ordered set where vocabularyId = &#63;.
3178             *
3179             * @param vocabularyId the vocabulary ID
3180             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3181             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
3182             */
3183            @Override
3184            public AssetCategory fetchByVocabularyId_Last(long vocabularyId,
3185                    OrderByComparator<AssetCategory> orderByComparator) {
3186                    int count = countByVocabularyId(vocabularyId);
3187    
3188                    if (count == 0) {
3189                            return null;
3190                    }
3191    
3192                    List<AssetCategory> list = findByVocabularyId(vocabularyId, count - 1,
3193                                    count, orderByComparator);
3194    
3195                    if (!list.isEmpty()) {
3196                            return list.get(0);
3197                    }
3198    
3199                    return null;
3200            }
3201    
3202            /**
3203             * Returns the asset categories before and after the current asset category in the ordered set where vocabularyId = &#63;.
3204             *
3205             * @param categoryId the primary key of the current asset category
3206             * @param vocabularyId the vocabulary ID
3207             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3208             * @return the previous, current, and next asset category
3209             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
3210             */
3211            @Override
3212            public AssetCategory[] findByVocabularyId_PrevAndNext(long categoryId,
3213                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator)
3214                    throws NoSuchCategoryException {
3215                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
3216    
3217                    Session session = null;
3218    
3219                    try {
3220                            session = openSession();
3221    
3222                            AssetCategory[] array = new AssetCategoryImpl[3];
3223    
3224                            array[0] = getByVocabularyId_PrevAndNext(session, assetCategory,
3225                                            vocabularyId, orderByComparator, true);
3226    
3227                            array[1] = assetCategory;
3228    
3229                            array[2] = getByVocabularyId_PrevAndNext(session, assetCategory,
3230                                            vocabularyId, orderByComparator, false);
3231    
3232                            return array;
3233                    }
3234                    catch (Exception e) {
3235                            throw processException(e);
3236                    }
3237                    finally {
3238                            closeSession(session);
3239                    }
3240            }
3241    
3242            protected AssetCategory getByVocabularyId_PrevAndNext(Session session,
3243                    AssetCategory assetCategory, long vocabularyId,
3244                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
3245                    StringBundler query = null;
3246    
3247                    if (orderByComparator != null) {
3248                            query = new StringBundler(6 +
3249                                            (orderByComparator.getOrderByFields().length * 6));
3250                    }
3251                    else {
3252                            query = new StringBundler(3);
3253                    }
3254    
3255                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3256    
3257                    query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
3258    
3259                    if (orderByComparator != null) {
3260                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3261    
3262                            if (orderByConditionFields.length > 0) {
3263                                    query.append(WHERE_AND);
3264                            }
3265    
3266                            for (int i = 0; i < orderByConditionFields.length; i++) {
3267                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3268                                    query.append(orderByConditionFields[i]);
3269    
3270                                    if ((i + 1) < orderByConditionFields.length) {
3271                                            if (orderByComparator.isAscending() ^ previous) {
3272                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3273                                            }
3274                                            else {
3275                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3276                                            }
3277                                    }
3278                                    else {
3279                                            if (orderByComparator.isAscending() ^ previous) {
3280                                                    query.append(WHERE_GREATER_THAN);
3281                                            }
3282                                            else {
3283                                                    query.append(WHERE_LESSER_THAN);
3284                                            }
3285                                    }
3286                            }
3287    
3288                            query.append(ORDER_BY_CLAUSE);
3289    
3290                            String[] orderByFields = orderByComparator.getOrderByFields();
3291    
3292                            for (int i = 0; i < orderByFields.length; i++) {
3293                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3294                                    query.append(orderByFields[i]);
3295    
3296                                    if ((i + 1) < orderByFields.length) {
3297                                            if (orderByComparator.isAscending() ^ previous) {
3298                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3299                                            }
3300                                            else {
3301                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3302                                            }
3303                                    }
3304                                    else {
3305                                            if (orderByComparator.isAscending() ^ previous) {
3306                                                    query.append(ORDER_BY_ASC);
3307                                            }
3308                                            else {
3309                                                    query.append(ORDER_BY_DESC);
3310                                            }
3311                                    }
3312                            }
3313                    }
3314                    else {
3315                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3316                    }
3317    
3318                    String sql = query.toString();
3319    
3320                    Query q = session.createQuery(sql);
3321    
3322                    q.setFirstResult(0);
3323                    q.setMaxResults(2);
3324    
3325                    QueryPos qPos = QueryPos.getInstance(q);
3326    
3327                    qPos.add(vocabularyId);
3328    
3329                    if (orderByComparator != null) {
3330                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
3331    
3332                            for (Object value : values) {
3333                                    qPos.add(value);
3334                            }
3335                    }
3336    
3337                    List<AssetCategory> list = q.list();
3338    
3339                    if (list.size() == 2) {
3340                            return list.get(1);
3341                    }
3342                    else {
3343                            return null;
3344                    }
3345            }
3346    
3347            /**
3348             * Removes all the asset categories where vocabularyId = &#63; from the database.
3349             *
3350             * @param vocabularyId the vocabulary ID
3351             */
3352            @Override
3353            public void removeByVocabularyId(long vocabularyId) {
3354                    for (AssetCategory assetCategory : findByVocabularyId(vocabularyId,
3355                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3356                            remove(assetCategory);
3357                    }
3358            }
3359    
3360            /**
3361             * Returns the number of asset categories where vocabularyId = &#63;.
3362             *
3363             * @param vocabularyId the vocabulary ID
3364             * @return the number of matching asset categories
3365             */
3366            @Override
3367            public int countByVocabularyId(long vocabularyId) {
3368                    FinderPath finderPath = FINDER_PATH_COUNT_BY_VOCABULARYID;
3369    
3370                    Object[] finderArgs = new Object[] { vocabularyId };
3371    
3372                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3373    
3374                    if (count == null) {
3375                            StringBundler query = new StringBundler(2);
3376    
3377                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
3378    
3379                            query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
3380    
3381                            String sql = query.toString();
3382    
3383                            Session session = null;
3384    
3385                            try {
3386                                    session = openSession();
3387    
3388                                    Query q = session.createQuery(sql);
3389    
3390                                    QueryPos qPos = QueryPos.getInstance(q);
3391    
3392                                    qPos.add(vocabularyId);
3393    
3394                                    count = (Long)q.uniqueResult();
3395    
3396                                    finderCache.putResult(finderPath, finderArgs, count);
3397                            }
3398                            catch (Exception e) {
3399                                    finderCache.removeResult(finderPath, finderArgs);
3400    
3401                                    throw processException(e);
3402                            }
3403                            finally {
3404                                    closeSession(session);
3405                            }
3406                    }
3407    
3408                    return count.intValue();
3409            }
3410    
3411            private static final String _FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
3412            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3413                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
3414                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3415                            "findByG_V",
3416                            new String[] {
3417                                    Long.class.getName(), Long.class.getName(),
3418                                    
3419                            Integer.class.getName(), Integer.class.getName(),
3420                                    OrderByComparator.class.getName()
3421                            });
3422            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3423                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
3424                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3425                            "findByG_V",
3426                            new String[] { Long.class.getName(), Long.class.getName() },
3427                            AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
3428                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
3429                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
3430            public static final FinderPath FINDER_PATH_COUNT_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3431                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
3432                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_V",
3433                            new String[] { Long.class.getName(), Long.class.getName() });
3434            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3435                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
3436                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_V",
3437                            new String[] { Long.class.getName(), Long.class.getName() });
3438    
3439            /**
3440             * Returns all the asset categories where groupId = &#63; and vocabularyId = &#63;.
3441             *
3442             * @param groupId the group ID
3443             * @param vocabularyId the vocabulary ID
3444             * @return the matching asset categories
3445             */
3446            @Override
3447            public List<AssetCategory> findByG_V(long groupId, long vocabularyId) {
3448                    return findByG_V(groupId, vocabularyId, QueryUtil.ALL_POS,
3449                            QueryUtil.ALL_POS, null);
3450            }
3451    
3452            /**
3453             * Returns a range of all the asset categories where groupId = &#63; and vocabularyId = &#63;.
3454             *
3455             * <p>
3456             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3457             * </p>
3458             *
3459             * @param groupId the group ID
3460             * @param vocabularyId the vocabulary ID
3461             * @param start the lower bound of the range of asset categories
3462             * @param end the upper bound of the range of asset categories (not inclusive)
3463             * @return the range of matching asset categories
3464             */
3465            @Override
3466            public List<AssetCategory> findByG_V(long groupId, long vocabularyId,
3467                    int start, int end) {
3468                    return findByG_V(groupId, vocabularyId, start, end, null);
3469            }
3470    
3471            /**
3472             * Returns an ordered range of all the asset categories where groupId = &#63; and vocabularyId = &#63;.
3473             *
3474             * <p>
3475             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3476             * </p>
3477             *
3478             * @param groupId the group ID
3479             * @param vocabularyId the vocabulary ID
3480             * @param start the lower bound of the range of asset categories
3481             * @param end the upper bound of the range of asset categories (not inclusive)
3482             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3483             * @return the ordered range of matching asset categories
3484             */
3485            @Override
3486            public List<AssetCategory> findByG_V(long groupId, long vocabularyId,
3487                    int start, int end, OrderByComparator<AssetCategory> orderByComparator) {
3488                    return findByG_V(groupId, vocabularyId, start, end, orderByComparator,
3489                            true);
3490            }
3491    
3492            /**
3493             * Returns an ordered range of all the asset categories where groupId = &#63; and vocabularyId = &#63;.
3494             *
3495             * <p>
3496             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3497             * </p>
3498             *
3499             * @param groupId the group ID
3500             * @param vocabularyId the vocabulary ID
3501             * @param start the lower bound of the range of asset categories
3502             * @param end the upper bound of the range of asset categories (not inclusive)
3503             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3504             * @param retrieveFromCache whether to retrieve from the finder cache
3505             * @return the ordered range of matching asset categories
3506             */
3507            @Override
3508            public List<AssetCategory> findByG_V(long groupId, long vocabularyId,
3509                    int start, int end, OrderByComparator<AssetCategory> orderByComparator,
3510                    boolean retrieveFromCache) {
3511                    boolean pagination = true;
3512                    FinderPath finderPath = null;
3513                    Object[] finderArgs = null;
3514    
3515                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3516                                    (orderByComparator == null)) {
3517                            pagination = false;
3518                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V;
3519                            finderArgs = new Object[] { groupId, vocabularyId };
3520                    }
3521                    else {
3522                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V;
3523                            finderArgs = new Object[] {
3524                                            groupId, vocabularyId,
3525                                            
3526                                            start, end, orderByComparator
3527                                    };
3528                    }
3529    
3530                    List<AssetCategory> list = null;
3531    
3532                    if (retrieveFromCache) {
3533                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
3534                                            finderArgs, this);
3535    
3536                            if ((list != null) && !list.isEmpty()) {
3537                                    for (AssetCategory assetCategory : list) {
3538                                            if ((groupId != assetCategory.getGroupId()) ||
3539                                                            (vocabularyId != assetCategory.getVocabularyId())) {
3540                                                    list = null;
3541    
3542                                                    break;
3543                                            }
3544                                    }
3545                            }
3546                    }
3547    
3548                    if (list == null) {
3549                            StringBundler query = null;
3550    
3551                            if (orderByComparator != null) {
3552                                    query = new StringBundler(4 +
3553                                                    (orderByComparator.getOrderByFields().length * 3));
3554                            }
3555                            else {
3556                                    query = new StringBundler(4);
3557                            }
3558    
3559                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3560    
3561                            query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3562    
3563                            query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3564    
3565                            if (orderByComparator != null) {
3566                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3567                                            orderByComparator);
3568                            }
3569                            else
3570                             if (pagination) {
3571                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3572                            }
3573    
3574                            String sql = query.toString();
3575    
3576                            Session session = null;
3577    
3578                            try {
3579                                    session = openSession();
3580    
3581                                    Query q = session.createQuery(sql);
3582    
3583                                    QueryPos qPos = QueryPos.getInstance(q);
3584    
3585                                    qPos.add(groupId);
3586    
3587                                    qPos.add(vocabularyId);
3588    
3589                                    if (!pagination) {
3590                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3591                                                            start, end, false);
3592    
3593                                            Collections.sort(list);
3594    
3595                                            list = Collections.unmodifiableList(list);
3596                                    }
3597                                    else {
3598                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3599                                                            start, end);
3600                                    }
3601    
3602                                    cacheResult(list);
3603    
3604                                    finderCache.putResult(finderPath, finderArgs, list);
3605                            }
3606                            catch (Exception e) {
3607                                    finderCache.removeResult(finderPath, finderArgs);
3608    
3609                                    throw processException(e);
3610                            }
3611                            finally {
3612                                    closeSession(session);
3613                            }
3614                    }
3615    
3616                    return list;
3617            }
3618    
3619            /**
3620             * Returns the first asset category in the ordered set where groupId = &#63; and vocabularyId = &#63;.
3621             *
3622             * @param groupId the group ID
3623             * @param vocabularyId the vocabulary ID
3624             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3625             * @return the first matching asset category
3626             * @throws NoSuchCategoryException if a matching asset category could not be found
3627             */
3628            @Override
3629            public AssetCategory findByG_V_First(long groupId, long vocabularyId,
3630                    OrderByComparator<AssetCategory> orderByComparator)
3631                    throws NoSuchCategoryException {
3632                    AssetCategory assetCategory = fetchByG_V_First(groupId, vocabularyId,
3633                                    orderByComparator);
3634    
3635                    if (assetCategory != null) {
3636                            return assetCategory;
3637                    }
3638    
3639                    StringBundler msg = new StringBundler(6);
3640    
3641                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3642    
3643                    msg.append("groupId=");
3644                    msg.append(groupId);
3645    
3646                    msg.append(", vocabularyId=");
3647                    msg.append(vocabularyId);
3648    
3649                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3650    
3651                    throw new NoSuchCategoryException(msg.toString());
3652            }
3653    
3654            /**
3655             * Returns the first asset category in the ordered set where groupId = &#63; and vocabularyId = &#63;.
3656             *
3657             * @param groupId the group ID
3658             * @param vocabularyId the vocabulary ID
3659             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3660             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
3661             */
3662            @Override
3663            public AssetCategory fetchByG_V_First(long groupId, long vocabularyId,
3664                    OrderByComparator<AssetCategory> orderByComparator) {
3665                    List<AssetCategory> list = findByG_V(groupId, vocabularyId, 0, 1,
3666                                    orderByComparator);
3667    
3668                    if (!list.isEmpty()) {
3669                            return list.get(0);
3670                    }
3671    
3672                    return null;
3673            }
3674    
3675            /**
3676             * Returns the last asset category in the ordered set where groupId = &#63; and vocabularyId = &#63;.
3677             *
3678             * @param groupId the group ID
3679             * @param vocabularyId the vocabulary ID
3680             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3681             * @return the last matching asset category
3682             * @throws NoSuchCategoryException if a matching asset category could not be found
3683             */
3684            @Override
3685            public AssetCategory findByG_V_Last(long groupId, long vocabularyId,
3686                    OrderByComparator<AssetCategory> orderByComparator)
3687                    throws NoSuchCategoryException {
3688                    AssetCategory assetCategory = fetchByG_V_Last(groupId, vocabularyId,
3689                                    orderByComparator);
3690    
3691                    if (assetCategory != null) {
3692                            return assetCategory;
3693                    }
3694    
3695                    StringBundler msg = new StringBundler(6);
3696    
3697                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3698    
3699                    msg.append("groupId=");
3700                    msg.append(groupId);
3701    
3702                    msg.append(", vocabularyId=");
3703                    msg.append(vocabularyId);
3704    
3705                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3706    
3707                    throw new NoSuchCategoryException(msg.toString());
3708            }
3709    
3710            /**
3711             * Returns the last asset category in the ordered set where groupId = &#63; and vocabularyId = &#63;.
3712             *
3713             * @param groupId the group ID
3714             * @param vocabularyId the vocabulary ID
3715             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3716             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
3717             */
3718            @Override
3719            public AssetCategory fetchByG_V_Last(long groupId, long vocabularyId,
3720                    OrderByComparator<AssetCategory> orderByComparator) {
3721                    int count = countByG_V(groupId, vocabularyId);
3722    
3723                    if (count == 0) {
3724                            return null;
3725                    }
3726    
3727                    List<AssetCategory> list = findByG_V(groupId, vocabularyId, count - 1,
3728                                    count, orderByComparator);
3729    
3730                    if (!list.isEmpty()) {
3731                            return list.get(0);
3732                    }
3733    
3734                    return null;
3735            }
3736    
3737            /**
3738             * Returns the asset categories before and after the current asset category in the ordered set where groupId = &#63; and vocabularyId = &#63;.
3739             *
3740             * @param categoryId the primary key of the current asset category
3741             * @param groupId the group ID
3742             * @param vocabularyId the vocabulary ID
3743             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3744             * @return the previous, current, and next asset category
3745             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
3746             */
3747            @Override
3748            public AssetCategory[] findByG_V_PrevAndNext(long categoryId, long groupId,
3749                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator)
3750                    throws NoSuchCategoryException {
3751                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
3752    
3753                    Session session = null;
3754    
3755                    try {
3756                            session = openSession();
3757    
3758                            AssetCategory[] array = new AssetCategoryImpl[3];
3759    
3760                            array[0] = getByG_V_PrevAndNext(session, assetCategory, groupId,
3761                                            vocabularyId, orderByComparator, true);
3762    
3763                            array[1] = assetCategory;
3764    
3765                            array[2] = getByG_V_PrevAndNext(session, assetCategory, groupId,
3766                                            vocabularyId, orderByComparator, false);
3767    
3768                            return array;
3769                    }
3770                    catch (Exception e) {
3771                            throw processException(e);
3772                    }
3773                    finally {
3774                            closeSession(session);
3775                    }
3776            }
3777    
3778            protected AssetCategory getByG_V_PrevAndNext(Session session,
3779                    AssetCategory assetCategory, long groupId, long vocabularyId,
3780                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
3781                    StringBundler query = null;
3782    
3783                    if (orderByComparator != null) {
3784                            query = new StringBundler(6 +
3785                                            (orderByComparator.getOrderByFields().length * 6));
3786                    }
3787                    else {
3788                            query = new StringBundler(3);
3789                    }
3790    
3791                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3792    
3793                    query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3794    
3795                    query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3796    
3797                    if (orderByComparator != null) {
3798                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3799    
3800                            if (orderByConditionFields.length > 0) {
3801                                    query.append(WHERE_AND);
3802                            }
3803    
3804                            for (int i = 0; i < orderByConditionFields.length; i++) {
3805                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3806                                    query.append(orderByConditionFields[i]);
3807    
3808                                    if ((i + 1) < orderByConditionFields.length) {
3809                                            if (orderByComparator.isAscending() ^ previous) {
3810                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3811                                            }
3812                                            else {
3813                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3814                                            }
3815                                    }
3816                                    else {
3817                                            if (orderByComparator.isAscending() ^ previous) {
3818                                                    query.append(WHERE_GREATER_THAN);
3819                                            }
3820                                            else {
3821                                                    query.append(WHERE_LESSER_THAN);
3822                                            }
3823                                    }
3824                            }
3825    
3826                            query.append(ORDER_BY_CLAUSE);
3827    
3828                            String[] orderByFields = orderByComparator.getOrderByFields();
3829    
3830                            for (int i = 0; i < orderByFields.length; i++) {
3831                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3832                                    query.append(orderByFields[i]);
3833    
3834                                    if ((i + 1) < orderByFields.length) {
3835                                            if (orderByComparator.isAscending() ^ previous) {
3836                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3837                                            }
3838                                            else {
3839                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3840                                            }
3841                                    }
3842                                    else {
3843                                            if (orderByComparator.isAscending() ^ previous) {
3844                                                    query.append(ORDER_BY_ASC);
3845                                            }
3846                                            else {
3847                                                    query.append(ORDER_BY_DESC);
3848                                            }
3849                                    }
3850                            }
3851                    }
3852                    else {
3853                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3854                    }
3855    
3856                    String sql = query.toString();
3857    
3858                    Query q = session.createQuery(sql);
3859    
3860                    q.setFirstResult(0);
3861                    q.setMaxResults(2);
3862    
3863                    QueryPos qPos = QueryPos.getInstance(q);
3864    
3865                    qPos.add(groupId);
3866    
3867                    qPos.add(vocabularyId);
3868    
3869                    if (orderByComparator != null) {
3870                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
3871    
3872                            for (Object value : values) {
3873                                    qPos.add(value);
3874                            }
3875                    }
3876    
3877                    List<AssetCategory> list = q.list();
3878    
3879                    if (list.size() == 2) {
3880                            return list.get(1);
3881                    }
3882                    else {
3883                            return null;
3884                    }
3885            }
3886    
3887            /**
3888             * Returns all the asset categories that the user has permission to view where groupId = &#63; and vocabularyId = &#63;.
3889             *
3890             * @param groupId the group ID
3891             * @param vocabularyId the vocabulary ID
3892             * @return the matching asset categories that the user has permission to view
3893             */
3894            @Override
3895            public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId) {
3896                    return filterFindByG_V(groupId, vocabularyId, QueryUtil.ALL_POS,
3897                            QueryUtil.ALL_POS, null);
3898            }
3899    
3900            /**
3901             * Returns a range of all the asset categories that the user has permission to view where groupId = &#63; and vocabularyId = &#63;.
3902             *
3903             * <p>
3904             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3905             * </p>
3906             *
3907             * @param groupId the group ID
3908             * @param vocabularyId the vocabulary ID
3909             * @param start the lower bound of the range of asset categories
3910             * @param end the upper bound of the range of asset categories (not inclusive)
3911             * @return the range of matching asset categories that the user has permission to view
3912             */
3913            @Override
3914            public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId,
3915                    int start, int end) {
3916                    return filterFindByG_V(groupId, vocabularyId, start, end, null);
3917            }
3918    
3919            /**
3920             * Returns an ordered range of all the asset categories that the user has permissions to view where groupId = &#63; and vocabularyId = &#63;.
3921             *
3922             * <p>
3923             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3924             * </p>
3925             *
3926             * @param groupId the group ID
3927             * @param vocabularyId the vocabulary ID
3928             * @param start the lower bound of the range of asset categories
3929             * @param end the upper bound of the range of asset categories (not inclusive)
3930             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3931             * @return the ordered range of matching asset categories that the user has permission to view
3932             */
3933            @Override
3934            public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId,
3935                    int start, int end, OrderByComparator<AssetCategory> orderByComparator) {
3936                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3937                            return findByG_V(groupId, vocabularyId, start, end,
3938                                    orderByComparator);
3939                    }
3940    
3941                    StringBundler query = null;
3942    
3943                    if (orderByComparator != null) {
3944                            query = new StringBundler(4 +
3945                                            (orderByComparator.getOrderByFields().length * 3));
3946                    }
3947                    else {
3948                            query = new StringBundler(4);
3949                    }
3950    
3951                    if (getDB().isSupportsInlineDistinct()) {
3952                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
3953                    }
3954                    else {
3955                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3956                    }
3957    
3958                    query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3959    
3960                    query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3961    
3962                    if (!getDB().isSupportsInlineDistinct()) {
3963                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3964                    }
3965    
3966                    if (orderByComparator != null) {
3967                            if (getDB().isSupportsInlineDistinct()) {
3968                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3969                                            orderByComparator, true);
3970                            }
3971                            else {
3972                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3973                                            orderByComparator, true);
3974                            }
3975                    }
3976                    else {
3977                            if (getDB().isSupportsInlineDistinct()) {
3978                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3979                            }
3980                            else {
3981                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
3982                            }
3983                    }
3984    
3985                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3986                                    AssetCategory.class.getName(),
3987                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3988    
3989                    Session session = null;
3990    
3991                    try {
3992                            session = openSession();
3993    
3994                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3995    
3996                            if (getDB().isSupportsInlineDistinct()) {
3997                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
3998                            }
3999                            else {
4000                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
4001                            }
4002    
4003                            QueryPos qPos = QueryPos.getInstance(q);
4004    
4005                            qPos.add(groupId);
4006    
4007                            qPos.add(vocabularyId);
4008    
4009                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
4010                                    end);
4011                    }
4012                    catch (Exception e) {
4013                            throw processException(e);
4014                    }
4015                    finally {
4016                            closeSession(session);
4017                    }
4018            }
4019    
4020            /**
4021             * Returns the asset categories before and after the current asset category in the ordered set of asset categories that the user has permission to view where groupId = &#63; and vocabularyId = &#63;.
4022             *
4023             * @param categoryId the primary key of the current asset category
4024             * @param groupId the group ID
4025             * @param vocabularyId the vocabulary ID
4026             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4027             * @return the previous, current, and next asset category
4028             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
4029             */
4030            @Override
4031            public AssetCategory[] filterFindByG_V_PrevAndNext(long categoryId,
4032                    long groupId, long vocabularyId,
4033                    OrderByComparator<AssetCategory> orderByComparator)
4034                    throws NoSuchCategoryException {
4035                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4036                            return findByG_V_PrevAndNext(categoryId, groupId, vocabularyId,
4037                                    orderByComparator);
4038                    }
4039    
4040                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
4041    
4042                    Session session = null;
4043    
4044                    try {
4045                            session = openSession();
4046    
4047                            AssetCategory[] array = new AssetCategoryImpl[3];
4048    
4049                            array[0] = filterGetByG_V_PrevAndNext(session, assetCategory,
4050                                            groupId, vocabularyId, orderByComparator, true);
4051    
4052                            array[1] = assetCategory;
4053    
4054                            array[2] = filterGetByG_V_PrevAndNext(session, assetCategory,
4055                                            groupId, vocabularyId, orderByComparator, false);
4056    
4057                            return array;
4058                    }
4059                    catch (Exception e) {
4060                            throw processException(e);
4061                    }
4062                    finally {
4063                            closeSession(session);
4064                    }
4065            }
4066    
4067            protected AssetCategory filterGetByG_V_PrevAndNext(Session session,
4068                    AssetCategory assetCategory, long groupId, long vocabularyId,
4069                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
4070                    StringBundler query = null;
4071    
4072                    if (orderByComparator != null) {
4073                            query = new StringBundler(6 +
4074                                            (orderByComparator.getOrderByFields().length * 6));
4075                    }
4076                    else {
4077                            query = new StringBundler(3);
4078                    }
4079    
4080                    if (getDB().isSupportsInlineDistinct()) {
4081                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
4082                    }
4083                    else {
4084                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4085                    }
4086    
4087                    query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4088    
4089                    query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
4090    
4091                    if (!getDB().isSupportsInlineDistinct()) {
4092                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4093                    }
4094    
4095                    if (orderByComparator != null) {
4096                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4097    
4098                            if (orderByConditionFields.length > 0) {
4099                                    query.append(WHERE_AND);
4100                            }
4101    
4102                            for (int i = 0; i < orderByConditionFields.length; i++) {
4103                                    if (getDB().isSupportsInlineDistinct()) {
4104                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4105                                    }
4106                                    else {
4107                                            query.append(_ORDER_BY_ENTITY_TABLE);
4108                                    }
4109    
4110                                    query.append(orderByConditionFields[i]);
4111    
4112                                    if ((i + 1) < orderByConditionFields.length) {
4113                                            if (orderByComparator.isAscending() ^ previous) {
4114                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4115                                            }
4116                                            else {
4117                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4118                                            }
4119                                    }
4120                                    else {
4121                                            if (orderByComparator.isAscending() ^ previous) {
4122                                                    query.append(WHERE_GREATER_THAN);
4123                                            }
4124                                            else {
4125                                                    query.append(WHERE_LESSER_THAN);
4126                                            }
4127                                    }
4128                            }
4129    
4130                            query.append(ORDER_BY_CLAUSE);
4131    
4132                            String[] orderByFields = orderByComparator.getOrderByFields();
4133    
4134                            for (int i = 0; i < orderByFields.length; i++) {
4135                                    if (getDB().isSupportsInlineDistinct()) {
4136                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4137                                    }
4138                                    else {
4139                                            query.append(_ORDER_BY_ENTITY_TABLE);
4140                                    }
4141    
4142                                    query.append(orderByFields[i]);
4143    
4144                                    if ((i + 1) < orderByFields.length) {
4145                                            if (orderByComparator.isAscending() ^ previous) {
4146                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4147                                            }
4148                                            else {
4149                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4150                                            }
4151                                    }
4152                                    else {
4153                                            if (orderByComparator.isAscending() ^ previous) {
4154                                                    query.append(ORDER_BY_ASC);
4155                                            }
4156                                            else {
4157                                                    query.append(ORDER_BY_DESC);
4158                                            }
4159                                    }
4160                            }
4161                    }
4162                    else {
4163                            if (getDB().isSupportsInlineDistinct()) {
4164                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4165                            }
4166                            else {
4167                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
4168                            }
4169                    }
4170    
4171                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4172                                    AssetCategory.class.getName(),
4173                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4174    
4175                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
4176    
4177                    q.setFirstResult(0);
4178                    q.setMaxResults(2);
4179    
4180                    if (getDB().isSupportsInlineDistinct()) {
4181                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
4182                    }
4183                    else {
4184                            q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
4185                    }
4186    
4187                    QueryPos qPos = QueryPos.getInstance(q);
4188    
4189                    qPos.add(groupId);
4190    
4191                    qPos.add(vocabularyId);
4192    
4193                    if (orderByComparator != null) {
4194                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
4195    
4196                            for (Object value : values) {
4197                                    qPos.add(value);
4198                            }
4199                    }
4200    
4201                    List<AssetCategory> list = q.list();
4202    
4203                    if (list.size() == 2) {
4204                            return list.get(1);
4205                    }
4206                    else {
4207                            return null;
4208                    }
4209            }
4210    
4211            /**
4212             * Returns all the asset categories that the user has permission to view where groupId = &#63; and vocabularyId = any &#63;.
4213             *
4214             * @param groupId the group ID
4215             * @param vocabularyIds the vocabulary IDs
4216             * @return the matching asset categories that the user has permission to view
4217             */
4218            @Override
4219            public List<AssetCategory> filterFindByG_V(long groupId,
4220                    long[] vocabularyIds) {
4221                    return filterFindByG_V(groupId, vocabularyIds, QueryUtil.ALL_POS,
4222                            QueryUtil.ALL_POS, null);
4223            }
4224    
4225            /**
4226             * Returns a range of all the asset categories that the user has permission to view where groupId = &#63; and vocabularyId = any &#63;.
4227             *
4228             * <p>
4229             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4230             * </p>
4231             *
4232             * @param groupId the group ID
4233             * @param vocabularyIds the vocabulary IDs
4234             * @param start the lower bound of the range of asset categories
4235             * @param end the upper bound of the range of asset categories (not inclusive)
4236             * @return the range of matching asset categories that the user has permission to view
4237             */
4238            @Override
4239            public List<AssetCategory> filterFindByG_V(long groupId,
4240                    long[] vocabularyIds, int start, int end) {
4241                    return filterFindByG_V(groupId, vocabularyIds, start, end, null);
4242            }
4243    
4244            /**
4245             * Returns an ordered range of all the asset categories that the user has permission to view where groupId = &#63; and vocabularyId = any &#63;.
4246             *
4247             * <p>
4248             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4249             * </p>
4250             *
4251             * @param groupId the group ID
4252             * @param vocabularyIds the vocabulary IDs
4253             * @param start the lower bound of the range of asset categories
4254             * @param end the upper bound of the range of asset categories (not inclusive)
4255             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4256             * @return the ordered range of matching asset categories that the user has permission to view
4257             */
4258            @Override
4259            public List<AssetCategory> filterFindByG_V(long groupId,
4260                    long[] vocabularyIds, int start, int end,
4261                    OrderByComparator<AssetCategory> orderByComparator) {
4262                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4263                            return findByG_V(groupId, vocabularyIds, start, end,
4264                                    orderByComparator);
4265                    }
4266    
4267                    if (vocabularyIds == null) {
4268                            vocabularyIds = new long[0];
4269                    }
4270                    else if (vocabularyIds.length > 1) {
4271                            vocabularyIds = ArrayUtil.unique(vocabularyIds);
4272    
4273                            Arrays.sort(vocabularyIds);
4274                    }
4275    
4276                    StringBundler query = new StringBundler();
4277    
4278                    if (getDB().isSupportsInlineDistinct()) {
4279                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
4280                    }
4281                    else {
4282                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4283                    }
4284    
4285                    query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4286    
4287                    if (vocabularyIds.length > 0) {
4288                            query.append(StringPool.OPEN_PARENTHESIS);
4289    
4290                            query.append(_FINDER_COLUMN_G_V_VOCABULARYID_7);
4291    
4292                            query.append(StringUtil.merge(vocabularyIds));
4293    
4294                            query.append(StringPool.CLOSE_PARENTHESIS);
4295    
4296                            query.append(StringPool.CLOSE_PARENTHESIS);
4297                    }
4298    
4299                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
4300                            query.index() - 1);
4301    
4302                    if (!getDB().isSupportsInlineDistinct()) {
4303                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4304                    }
4305    
4306                    if (orderByComparator != null) {
4307                            if (getDB().isSupportsInlineDistinct()) {
4308                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4309                                            orderByComparator, true);
4310                            }
4311                            else {
4312                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4313                                            orderByComparator, true);
4314                            }
4315                    }
4316                    else {
4317                            if (getDB().isSupportsInlineDistinct()) {
4318                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4319                            }
4320                            else {
4321                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
4322                            }
4323                    }
4324    
4325                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4326                                    AssetCategory.class.getName(),
4327                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4328    
4329                    Session session = null;
4330    
4331                    try {
4332                            session = openSession();
4333    
4334                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4335    
4336                            if (getDB().isSupportsInlineDistinct()) {
4337                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
4338                            }
4339                            else {
4340                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
4341                            }
4342    
4343                            QueryPos qPos = QueryPos.getInstance(q);
4344    
4345                            qPos.add(groupId);
4346    
4347                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
4348                                    end);
4349                    }
4350                    catch (Exception e) {
4351                            throw processException(e);
4352                    }
4353                    finally {
4354                            closeSession(session);
4355                    }
4356            }
4357    
4358            /**
4359             * Returns all the asset categories where groupId = &#63; and vocabularyId = any &#63;.
4360             *
4361             * <p>
4362             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4363             * </p>
4364             *
4365             * @param groupId the group ID
4366             * @param vocabularyIds the vocabulary IDs
4367             * @return the matching asset categories
4368             */
4369            @Override
4370            public List<AssetCategory> findByG_V(long groupId, long[] vocabularyIds) {
4371                    return findByG_V(groupId, vocabularyIds, QueryUtil.ALL_POS,
4372                            QueryUtil.ALL_POS, null);
4373            }
4374    
4375            /**
4376             * Returns a range of all the asset categories where groupId = &#63; and vocabularyId = any &#63;.
4377             *
4378             * <p>
4379             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4380             * </p>
4381             *
4382             * @param groupId the group ID
4383             * @param vocabularyIds the vocabulary IDs
4384             * @param start the lower bound of the range of asset categories
4385             * @param end the upper bound of the range of asset categories (not inclusive)
4386             * @return the range of matching asset categories
4387             */
4388            @Override
4389            public List<AssetCategory> findByG_V(long groupId, long[] vocabularyIds,
4390                    int start, int end) {
4391                    return findByG_V(groupId, vocabularyIds, start, end, null);
4392            }
4393    
4394            /**
4395             * Returns an ordered range of all the asset categories where groupId = &#63; and vocabularyId = any &#63;.
4396             *
4397             * <p>
4398             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4399             * </p>
4400             *
4401             * @param groupId the group ID
4402             * @param vocabularyIds the vocabulary IDs
4403             * @param start the lower bound of the range of asset categories
4404             * @param end the upper bound of the range of asset categories (not inclusive)
4405             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4406             * @return the ordered range of matching asset categories
4407             */
4408            @Override
4409            public List<AssetCategory> findByG_V(long groupId, long[] vocabularyIds,
4410                    int start, int end, OrderByComparator<AssetCategory> orderByComparator) {
4411                    return findByG_V(groupId, vocabularyIds, start, end, orderByComparator,
4412                            true);
4413            }
4414    
4415            /**
4416             * Returns an ordered range of all the asset categories where groupId = &#63; and vocabularyId = &#63;, optionally using the finder cache.
4417             *
4418             * <p>
4419             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4420             * </p>
4421             *
4422             * @param groupId the group ID
4423             * @param vocabularyId the vocabulary ID
4424             * @param start the lower bound of the range of asset categories
4425             * @param end the upper bound of the range of asset categories (not inclusive)
4426             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4427             * @param retrieveFromCache whether to retrieve from the finder cache
4428             * @return the ordered range of matching asset categories
4429             */
4430            @Override
4431            public List<AssetCategory> findByG_V(long groupId, long[] vocabularyIds,
4432                    int start, int end, OrderByComparator<AssetCategory> orderByComparator,
4433                    boolean retrieveFromCache) {
4434                    if (vocabularyIds == null) {
4435                            vocabularyIds = new long[0];
4436                    }
4437                    else if (vocabularyIds.length > 1) {
4438                            vocabularyIds = ArrayUtil.unique(vocabularyIds);
4439    
4440                            Arrays.sort(vocabularyIds);
4441                    }
4442    
4443                    if (vocabularyIds.length == 1) {
4444                            return findByG_V(groupId, vocabularyIds[0], start, end,
4445                                    orderByComparator);
4446                    }
4447    
4448                    boolean pagination = true;
4449                    Object[] finderArgs = null;
4450    
4451                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4452                                    (orderByComparator == null)) {
4453                            pagination = false;
4454                            finderArgs = new Object[] { groupId, StringUtil.merge(vocabularyIds) };
4455                    }
4456                    else {
4457                            finderArgs = new Object[] {
4458                                            groupId, StringUtil.merge(vocabularyIds),
4459                                            
4460                                            start, end, orderByComparator
4461                                    };
4462                    }
4463    
4464                    List<AssetCategory> list = null;
4465    
4466                    if (retrieveFromCache) {
4467                            list = (List<AssetCategory>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V,
4468                                            finderArgs, this);
4469    
4470                            if ((list != null) && !list.isEmpty()) {
4471                                    for (AssetCategory assetCategory : list) {
4472                                            if ((groupId != assetCategory.getGroupId()) ||
4473                                                            !ArrayUtil.contains(vocabularyIds,
4474                                                                    assetCategory.getVocabularyId())) {
4475                                                    list = null;
4476    
4477                                                    break;
4478                                            }
4479                                    }
4480                            }
4481                    }
4482    
4483                    if (list == null) {
4484                            StringBundler query = new StringBundler();
4485    
4486                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
4487    
4488                            query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4489    
4490                            if (vocabularyIds.length > 0) {
4491                                    query.append(StringPool.OPEN_PARENTHESIS);
4492    
4493                                    query.append(_FINDER_COLUMN_G_V_VOCABULARYID_7);
4494    
4495                                    query.append(StringUtil.merge(vocabularyIds));
4496    
4497                                    query.append(StringPool.CLOSE_PARENTHESIS);
4498    
4499                                    query.append(StringPool.CLOSE_PARENTHESIS);
4500                            }
4501    
4502                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
4503                                                    1)), query.index() - 1);
4504    
4505                            if (orderByComparator != null) {
4506                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4507                                            orderByComparator);
4508                            }
4509                            else
4510                             if (pagination) {
4511                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4512                            }
4513    
4514                            String sql = query.toString();
4515    
4516                            Session session = null;
4517    
4518                            try {
4519                                    session = openSession();
4520    
4521                                    Query q = session.createQuery(sql);
4522    
4523                                    QueryPos qPos = QueryPos.getInstance(q);
4524    
4525                                    qPos.add(groupId);
4526    
4527                                    if (!pagination) {
4528                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4529                                                            start, end, false);
4530    
4531                                            Collections.sort(list);
4532    
4533                                            list = Collections.unmodifiableList(list);
4534                                    }
4535                                    else {
4536                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4537                                                            start, end);
4538                                    }
4539    
4540                                    cacheResult(list);
4541    
4542                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V,
4543                                            finderArgs, list);
4544                            }
4545                            catch (Exception e) {
4546                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V,
4547                                            finderArgs);
4548    
4549                                    throw processException(e);
4550                            }
4551                            finally {
4552                                    closeSession(session);
4553                            }
4554                    }
4555    
4556                    return list;
4557            }
4558    
4559            /**
4560             * Removes all the asset categories where groupId = &#63; and vocabularyId = &#63; from the database.
4561             *
4562             * @param groupId the group ID
4563             * @param vocabularyId the vocabulary ID
4564             */
4565            @Override
4566            public void removeByG_V(long groupId, long vocabularyId) {
4567                    for (AssetCategory assetCategory : findByG_V(groupId, vocabularyId,
4568                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4569                            remove(assetCategory);
4570                    }
4571            }
4572    
4573            /**
4574             * Returns the number of asset categories where groupId = &#63; and vocabularyId = &#63;.
4575             *
4576             * @param groupId the group ID
4577             * @param vocabularyId the vocabulary ID
4578             * @return the number of matching asset categories
4579             */
4580            @Override
4581            public int countByG_V(long groupId, long vocabularyId) {
4582                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_V;
4583    
4584                    Object[] finderArgs = new Object[] { groupId, vocabularyId };
4585    
4586                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4587    
4588                    if (count == null) {
4589                            StringBundler query = new StringBundler(3);
4590    
4591                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4592    
4593                            query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4594    
4595                            query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
4596    
4597                            String sql = query.toString();
4598    
4599                            Session session = null;
4600    
4601                            try {
4602                                    session = openSession();
4603    
4604                                    Query q = session.createQuery(sql);
4605    
4606                                    QueryPos qPos = QueryPos.getInstance(q);
4607    
4608                                    qPos.add(groupId);
4609    
4610                                    qPos.add(vocabularyId);
4611    
4612                                    count = (Long)q.uniqueResult();
4613    
4614                                    finderCache.putResult(finderPath, finderArgs, count);
4615                            }
4616                            catch (Exception e) {
4617                                    finderCache.removeResult(finderPath, finderArgs);
4618    
4619                                    throw processException(e);
4620                            }
4621                            finally {
4622                                    closeSession(session);
4623                            }
4624                    }
4625    
4626                    return count.intValue();
4627            }
4628    
4629            /**
4630             * Returns the number of asset categories where groupId = &#63; and vocabularyId = any &#63;.
4631             *
4632             * @param groupId the group ID
4633             * @param vocabularyIds the vocabulary IDs
4634             * @return the number of matching asset categories
4635             */
4636            @Override
4637            public int countByG_V(long groupId, long[] vocabularyIds) {
4638                    if (vocabularyIds == null) {
4639                            vocabularyIds = new long[0];
4640                    }
4641                    else if (vocabularyIds.length > 1) {
4642                            vocabularyIds = ArrayUtil.unique(vocabularyIds);
4643    
4644                            Arrays.sort(vocabularyIds);
4645                    }
4646    
4647                    Object[] finderArgs = new Object[] {
4648                                    groupId, StringUtil.merge(vocabularyIds)
4649                            };
4650    
4651                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V,
4652                                    finderArgs, this);
4653    
4654                    if (count == null) {
4655                            StringBundler query = new StringBundler();
4656    
4657                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4658    
4659                            query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4660    
4661                            if (vocabularyIds.length > 0) {
4662                                    query.append(StringPool.OPEN_PARENTHESIS);
4663    
4664                                    query.append(_FINDER_COLUMN_G_V_VOCABULARYID_7);
4665    
4666                                    query.append(StringUtil.merge(vocabularyIds));
4667    
4668                                    query.append(StringPool.CLOSE_PARENTHESIS);
4669    
4670                                    query.append(StringPool.CLOSE_PARENTHESIS);
4671                            }
4672    
4673                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
4674                                                    1)), query.index() - 1);
4675    
4676                            String sql = query.toString();
4677    
4678                            Session session = null;
4679    
4680                            try {
4681                                    session = openSession();
4682    
4683                                    Query q = session.createQuery(sql);
4684    
4685                                    QueryPos qPos = QueryPos.getInstance(q);
4686    
4687                                    qPos.add(groupId);
4688    
4689                                    count = (Long)q.uniqueResult();
4690    
4691                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V,
4692                                            finderArgs, count);
4693                            }
4694                            catch (Exception e) {
4695                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_V,
4696                                            finderArgs);
4697    
4698                                    throw processException(e);
4699                            }
4700                            finally {
4701                                    closeSession(session);
4702                            }
4703                    }
4704    
4705                    return count.intValue();
4706            }
4707    
4708            /**
4709             * Returns the number of asset categories that the user has permission to view where groupId = &#63; and vocabularyId = &#63;.
4710             *
4711             * @param groupId the group ID
4712             * @param vocabularyId the vocabulary ID
4713             * @return the number of matching asset categories that the user has permission to view
4714             */
4715            @Override
4716            public int filterCountByG_V(long groupId, long vocabularyId) {
4717                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4718                            return countByG_V(groupId, vocabularyId);
4719                    }
4720    
4721                    StringBundler query = new StringBundler(3);
4722    
4723                    query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
4724    
4725                    query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4726    
4727                    query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
4728    
4729                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4730                                    AssetCategory.class.getName(),
4731                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4732    
4733                    Session session = null;
4734    
4735                    try {
4736                            session = openSession();
4737    
4738                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4739    
4740                            q.addScalar(COUNT_COLUMN_NAME,
4741                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4742    
4743                            QueryPos qPos = QueryPos.getInstance(q);
4744    
4745                            qPos.add(groupId);
4746    
4747                            qPos.add(vocabularyId);
4748    
4749                            Long count = (Long)q.uniqueResult();
4750    
4751                            return count.intValue();
4752                    }
4753                    catch (Exception e) {
4754                            throw processException(e);
4755                    }
4756                    finally {
4757                            closeSession(session);
4758                    }
4759            }
4760    
4761            /**
4762             * Returns the number of asset categories that the user has permission to view where groupId = &#63; and vocabularyId = any &#63;.
4763             *
4764             * @param groupId the group ID
4765             * @param vocabularyIds the vocabulary IDs
4766             * @return the number of matching asset categories that the user has permission to view
4767             */
4768            @Override
4769            public int filterCountByG_V(long groupId, long[] vocabularyIds) {
4770                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4771                            return countByG_V(groupId, vocabularyIds);
4772                    }
4773    
4774                    if (vocabularyIds == null) {
4775                            vocabularyIds = new long[0];
4776                    }
4777                    else if (vocabularyIds.length > 1) {
4778                            vocabularyIds = ArrayUtil.unique(vocabularyIds);
4779    
4780                            Arrays.sort(vocabularyIds);
4781                    }
4782    
4783                    StringBundler query = new StringBundler();
4784    
4785                    query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
4786    
4787                    query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4788    
4789                    if (vocabularyIds.length > 0) {
4790                            query.append(StringPool.OPEN_PARENTHESIS);
4791    
4792                            query.append(_FINDER_COLUMN_G_V_VOCABULARYID_7);
4793    
4794                            query.append(StringUtil.merge(vocabularyIds));
4795    
4796                            query.append(StringPool.CLOSE_PARENTHESIS);
4797    
4798                            query.append(StringPool.CLOSE_PARENTHESIS);
4799                    }
4800    
4801                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
4802                            query.index() - 1);
4803    
4804                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4805                                    AssetCategory.class.getName(),
4806                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4807    
4808                    Session session = null;
4809    
4810                    try {
4811                            session = openSession();
4812    
4813                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4814    
4815                            q.addScalar(COUNT_COLUMN_NAME,
4816                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4817    
4818                            QueryPos qPos = QueryPos.getInstance(q);
4819    
4820                            qPos.add(groupId);
4821    
4822                            Long count = (Long)q.uniqueResult();
4823    
4824                            return count.intValue();
4825                    }
4826                    catch (Exception e) {
4827                            throw processException(e);
4828                    }
4829                    finally {
4830                            closeSession(session);
4831                    }
4832            }
4833    
4834            private static final String _FINDER_COLUMN_G_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
4835            private static final String _FINDER_COLUMN_G_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
4836            private static final String _FINDER_COLUMN_G_V_VOCABULARYID_7 = "assetCategory.vocabularyId IN (";
4837            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4838                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
4839                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4840                            "findByP_N",
4841                            new String[] {
4842                                    Long.class.getName(), String.class.getName(),
4843                                    
4844                            Integer.class.getName(), Integer.class.getName(),
4845                                    OrderByComparator.class.getName()
4846                            });
4847            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4848                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
4849                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4850                            "findByP_N",
4851                            new String[] { Long.class.getName(), String.class.getName() },
4852                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
4853                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
4854            public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4855                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
4856                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
4857                            new String[] { Long.class.getName(), String.class.getName() });
4858    
4859            /**
4860             * Returns all the asset categories where parentCategoryId = &#63; and name = &#63;.
4861             *
4862             * @param parentCategoryId the parent category ID
4863             * @param name the name
4864             * @return the matching asset categories
4865             */
4866            @Override
4867            public List<AssetCategory> findByP_N(long parentCategoryId, String name) {
4868                    return findByP_N(parentCategoryId, name, QueryUtil.ALL_POS,
4869                            QueryUtil.ALL_POS, null);
4870            }
4871    
4872            /**
4873             * Returns a range of all the asset categories where parentCategoryId = &#63; and name = &#63;.
4874             *
4875             * <p>
4876             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4877             * </p>
4878             *
4879             * @param parentCategoryId the parent category ID
4880             * @param name the name
4881             * @param start the lower bound of the range of asset categories
4882             * @param end the upper bound of the range of asset categories (not inclusive)
4883             * @return the range of matching asset categories
4884             */
4885            @Override
4886            public List<AssetCategory> findByP_N(long parentCategoryId, String name,
4887                    int start, int end) {
4888                    return findByP_N(parentCategoryId, name, start, end, null);
4889            }
4890    
4891            /**
4892             * Returns an ordered range of all the asset categories where parentCategoryId = &#63; and name = &#63;.
4893             *
4894             * <p>
4895             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4896             * </p>
4897             *
4898             * @param parentCategoryId the parent category ID
4899             * @param name the name
4900             * @param start the lower bound of the range of asset categories
4901             * @param end the upper bound of the range of asset categories (not inclusive)
4902             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4903             * @return the ordered range of matching asset categories
4904             */
4905            @Override
4906            public List<AssetCategory> findByP_N(long parentCategoryId, String name,
4907                    int start, int end, OrderByComparator<AssetCategory> orderByComparator) {
4908                    return findByP_N(parentCategoryId, name, start, end, orderByComparator,
4909                            true);
4910            }
4911    
4912            /**
4913             * Returns an ordered range of all the asset categories where parentCategoryId = &#63; and name = &#63;.
4914             *
4915             * <p>
4916             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4917             * </p>
4918             *
4919             * @param parentCategoryId the parent category ID
4920             * @param name the name
4921             * @param start the lower bound of the range of asset categories
4922             * @param end the upper bound of the range of asset categories (not inclusive)
4923             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4924             * @param retrieveFromCache whether to retrieve from the finder cache
4925             * @return the ordered range of matching asset categories
4926             */
4927            @Override
4928            public List<AssetCategory> findByP_N(long parentCategoryId, String name,
4929                    int start, int end, OrderByComparator<AssetCategory> orderByComparator,
4930                    boolean retrieveFromCache) {
4931                    boolean pagination = true;
4932                    FinderPath finderPath = null;
4933                    Object[] finderArgs = null;
4934    
4935                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4936                                    (orderByComparator == null)) {
4937                            pagination = false;
4938                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
4939                            finderArgs = new Object[] { parentCategoryId, name };
4940                    }
4941                    else {
4942                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
4943                            finderArgs = new Object[] {
4944                                            parentCategoryId, name,
4945                                            
4946                                            start, end, orderByComparator
4947                                    };
4948                    }
4949    
4950                    List<AssetCategory> list = null;
4951    
4952                    if (retrieveFromCache) {
4953                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
4954                                            finderArgs, this);
4955    
4956                            if ((list != null) && !list.isEmpty()) {
4957                                    for (AssetCategory assetCategory : list) {
4958                                            if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
4959                                                            !Validator.equals(name, assetCategory.getName())) {
4960                                                    list = null;
4961    
4962                                                    break;
4963                                            }
4964                                    }
4965                            }
4966                    }
4967    
4968                    if (list == null) {
4969                            StringBundler query = null;
4970    
4971                            if (orderByComparator != null) {
4972                                    query = new StringBundler(4 +
4973                                                    (orderByComparator.getOrderByFields().length * 3));
4974                            }
4975                            else {
4976                                    query = new StringBundler(4);
4977                            }
4978    
4979                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
4980    
4981                            query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
4982    
4983                            boolean bindName = false;
4984    
4985                            if (name == null) {
4986                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
4987                            }
4988                            else if (name.equals(StringPool.BLANK)) {
4989                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
4990                            }
4991                            else {
4992                                    bindName = true;
4993    
4994                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
4995                            }
4996    
4997                            if (orderByComparator != null) {
4998                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4999                                            orderByComparator);
5000                            }
5001                            else
5002                             if (pagination) {
5003                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5004                            }
5005    
5006                            String sql = query.toString();
5007    
5008                            Session session = null;
5009    
5010                            try {
5011                                    session = openSession();
5012    
5013                                    Query q = session.createQuery(sql);
5014    
5015                                    QueryPos qPos = QueryPos.getInstance(q);
5016    
5017                                    qPos.add(parentCategoryId);
5018    
5019                                    if (bindName) {
5020                                            qPos.add(name);
5021                                    }
5022    
5023                                    if (!pagination) {
5024                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
5025                                                            start, end, false);
5026    
5027                                            Collections.sort(list);
5028    
5029                                            list = Collections.unmodifiableList(list);
5030                                    }
5031                                    else {
5032                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
5033                                                            start, end);
5034                                    }
5035    
5036                                    cacheResult(list);
5037    
5038                                    finderCache.putResult(finderPath, finderArgs, list);
5039                            }
5040                            catch (Exception e) {
5041                                    finderCache.removeResult(finderPath, finderArgs);
5042    
5043                                    throw processException(e);
5044                            }
5045                            finally {
5046                                    closeSession(session);
5047                            }
5048                    }
5049    
5050                    return list;
5051            }
5052    
5053            /**
5054             * Returns the first asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
5055             *
5056             * @param parentCategoryId the parent category ID
5057             * @param name the name
5058             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5059             * @return the first matching asset category
5060             * @throws NoSuchCategoryException if a matching asset category could not be found
5061             */
5062            @Override
5063            public AssetCategory findByP_N_First(long parentCategoryId, String name,
5064                    OrderByComparator<AssetCategory> orderByComparator)
5065                    throws NoSuchCategoryException {
5066                    AssetCategory assetCategory = fetchByP_N_First(parentCategoryId, name,
5067                                    orderByComparator);
5068    
5069                    if (assetCategory != null) {
5070                            return assetCategory;
5071                    }
5072    
5073                    StringBundler msg = new StringBundler(6);
5074    
5075                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5076    
5077                    msg.append("parentCategoryId=");
5078                    msg.append(parentCategoryId);
5079    
5080                    msg.append(", name=");
5081                    msg.append(name);
5082    
5083                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5084    
5085                    throw new NoSuchCategoryException(msg.toString());
5086            }
5087    
5088            /**
5089             * Returns the first asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
5090             *
5091             * @param parentCategoryId the parent category ID
5092             * @param name the name
5093             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5094             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
5095             */
5096            @Override
5097            public AssetCategory fetchByP_N_First(long parentCategoryId, String name,
5098                    OrderByComparator<AssetCategory> orderByComparator) {
5099                    List<AssetCategory> list = findByP_N(parentCategoryId, name, 0, 1,
5100                                    orderByComparator);
5101    
5102                    if (!list.isEmpty()) {
5103                            return list.get(0);
5104                    }
5105    
5106                    return null;
5107            }
5108    
5109            /**
5110             * Returns the last asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
5111             *
5112             * @param parentCategoryId the parent category ID
5113             * @param name the name
5114             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5115             * @return the last matching asset category
5116             * @throws NoSuchCategoryException if a matching asset category could not be found
5117             */
5118            @Override
5119            public AssetCategory findByP_N_Last(long parentCategoryId, String name,
5120                    OrderByComparator<AssetCategory> orderByComparator)
5121                    throws NoSuchCategoryException {
5122                    AssetCategory assetCategory = fetchByP_N_Last(parentCategoryId, name,
5123                                    orderByComparator);
5124    
5125                    if (assetCategory != null) {
5126                            return assetCategory;
5127                    }
5128    
5129                    StringBundler msg = new StringBundler(6);
5130    
5131                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5132    
5133                    msg.append("parentCategoryId=");
5134                    msg.append(parentCategoryId);
5135    
5136                    msg.append(", name=");
5137                    msg.append(name);
5138    
5139                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5140    
5141                    throw new NoSuchCategoryException(msg.toString());
5142            }
5143    
5144            /**
5145             * Returns the last asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
5146             *
5147             * @param parentCategoryId the parent category ID
5148             * @param name the name
5149             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5150             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
5151             */
5152            @Override
5153            public AssetCategory fetchByP_N_Last(long parentCategoryId, String name,
5154                    OrderByComparator<AssetCategory> orderByComparator) {
5155                    int count = countByP_N(parentCategoryId, name);
5156    
5157                    if (count == 0) {
5158                            return null;
5159                    }
5160    
5161                    List<AssetCategory> list = findByP_N(parentCategoryId, name, count - 1,
5162                                    count, orderByComparator);
5163    
5164                    if (!list.isEmpty()) {
5165                            return list.get(0);
5166                    }
5167    
5168                    return null;
5169            }
5170    
5171            /**
5172             * Returns the asset categories before and after the current asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
5173             *
5174             * @param categoryId the primary key of the current asset category
5175             * @param parentCategoryId the parent category ID
5176             * @param name the name
5177             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5178             * @return the previous, current, and next asset category
5179             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
5180             */
5181            @Override
5182            public AssetCategory[] findByP_N_PrevAndNext(long categoryId,
5183                    long parentCategoryId, String name,
5184                    OrderByComparator<AssetCategory> orderByComparator)
5185                    throws NoSuchCategoryException {
5186                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
5187    
5188                    Session session = null;
5189    
5190                    try {
5191                            session = openSession();
5192    
5193                            AssetCategory[] array = new AssetCategoryImpl[3];
5194    
5195                            array[0] = getByP_N_PrevAndNext(session, assetCategory,
5196                                            parentCategoryId, name, orderByComparator, true);
5197    
5198                            array[1] = assetCategory;
5199    
5200                            array[2] = getByP_N_PrevAndNext(session, assetCategory,
5201                                            parentCategoryId, name, orderByComparator, false);
5202    
5203                            return array;
5204                    }
5205                    catch (Exception e) {
5206                            throw processException(e);
5207                    }
5208                    finally {
5209                            closeSession(session);
5210                    }
5211            }
5212    
5213            protected AssetCategory getByP_N_PrevAndNext(Session session,
5214                    AssetCategory assetCategory, long parentCategoryId, String name,
5215                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
5216                    StringBundler query = null;
5217    
5218                    if (orderByComparator != null) {
5219                            query = new StringBundler(6 +
5220                                            (orderByComparator.getOrderByFields().length * 6));
5221                    }
5222                    else {
5223                            query = new StringBundler(3);
5224                    }
5225    
5226                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5227    
5228                    query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
5229    
5230                    boolean bindName = false;
5231    
5232                    if (name == null) {
5233                            query.append(_FINDER_COLUMN_P_N_NAME_1);
5234                    }
5235                    else if (name.equals(StringPool.BLANK)) {
5236                            query.append(_FINDER_COLUMN_P_N_NAME_3);
5237                    }
5238                    else {
5239                            bindName = true;
5240    
5241                            query.append(_FINDER_COLUMN_P_N_NAME_2);
5242                    }
5243    
5244                    if (orderByComparator != null) {
5245                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5246    
5247                            if (orderByConditionFields.length > 0) {
5248                                    query.append(WHERE_AND);
5249                            }
5250    
5251                            for (int i = 0; i < orderByConditionFields.length; i++) {
5252                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5253                                    query.append(orderByConditionFields[i]);
5254    
5255                                    if ((i + 1) < orderByConditionFields.length) {
5256                                            if (orderByComparator.isAscending() ^ previous) {
5257                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5258                                            }
5259                                            else {
5260                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5261                                            }
5262                                    }
5263                                    else {
5264                                            if (orderByComparator.isAscending() ^ previous) {
5265                                                    query.append(WHERE_GREATER_THAN);
5266                                            }
5267                                            else {
5268                                                    query.append(WHERE_LESSER_THAN);
5269                                            }
5270                                    }
5271                            }
5272    
5273                            query.append(ORDER_BY_CLAUSE);
5274    
5275                            String[] orderByFields = orderByComparator.getOrderByFields();
5276    
5277                            for (int i = 0; i < orderByFields.length; i++) {
5278                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5279                                    query.append(orderByFields[i]);
5280    
5281                                    if ((i + 1) < orderByFields.length) {
5282                                            if (orderByComparator.isAscending() ^ previous) {
5283                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5284                                            }
5285                                            else {
5286                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5287                                            }
5288                                    }
5289                                    else {
5290                                            if (orderByComparator.isAscending() ^ previous) {
5291                                                    query.append(ORDER_BY_ASC);
5292                                            }
5293                                            else {
5294                                                    query.append(ORDER_BY_DESC);
5295                                            }
5296                                    }
5297                            }
5298                    }
5299                    else {
5300                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5301                    }
5302    
5303                    String sql = query.toString();
5304    
5305                    Query q = session.createQuery(sql);
5306    
5307                    q.setFirstResult(0);
5308                    q.setMaxResults(2);
5309    
5310                    QueryPos qPos = QueryPos.getInstance(q);
5311    
5312                    qPos.add(parentCategoryId);
5313    
5314                    if (bindName) {
5315                            qPos.add(name);
5316                    }
5317    
5318                    if (orderByComparator != null) {
5319                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
5320    
5321                            for (Object value : values) {
5322                                    qPos.add(value);
5323                            }
5324                    }
5325    
5326                    List<AssetCategory> list = q.list();
5327    
5328                    if (list.size() == 2) {
5329                            return list.get(1);
5330                    }
5331                    else {
5332                            return null;
5333                    }
5334            }
5335    
5336            /**
5337             * Removes all the asset categories where parentCategoryId = &#63; and name = &#63; from the database.
5338             *
5339             * @param parentCategoryId the parent category ID
5340             * @param name the name
5341             */
5342            @Override
5343            public void removeByP_N(long parentCategoryId, String name) {
5344                    for (AssetCategory assetCategory : findByP_N(parentCategoryId, name,
5345                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5346                            remove(assetCategory);
5347                    }
5348            }
5349    
5350            /**
5351             * Returns the number of asset categories where parentCategoryId = &#63; and name = &#63;.
5352             *
5353             * @param parentCategoryId the parent category ID
5354             * @param name the name
5355             * @return the number of matching asset categories
5356             */
5357            @Override
5358            public int countByP_N(long parentCategoryId, String name) {
5359                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N;
5360    
5361                    Object[] finderArgs = new Object[] { parentCategoryId, name };
5362    
5363                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5364    
5365                    if (count == null) {
5366                            StringBundler query = new StringBundler(3);
5367    
5368                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
5369    
5370                            query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
5371    
5372                            boolean bindName = false;
5373    
5374                            if (name == null) {
5375                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
5376                            }
5377                            else if (name.equals(StringPool.BLANK)) {
5378                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
5379                            }
5380                            else {
5381                                    bindName = true;
5382    
5383                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
5384                            }
5385    
5386                            String sql = query.toString();
5387    
5388                            Session session = null;
5389    
5390                            try {
5391                                    session = openSession();
5392    
5393                                    Query q = session.createQuery(sql);
5394    
5395                                    QueryPos qPos = QueryPos.getInstance(q);
5396    
5397                                    qPos.add(parentCategoryId);
5398    
5399                                    if (bindName) {
5400                                            qPos.add(name);
5401                                    }
5402    
5403                                    count = (Long)q.uniqueResult();
5404    
5405                                    finderCache.putResult(finderPath, finderArgs, count);
5406                            }
5407                            catch (Exception e) {
5408                                    finderCache.removeResult(finderPath, finderArgs);
5409    
5410                                    throw processException(e);
5411                            }
5412                            finally {
5413                                    closeSession(session);
5414                            }
5415                    }
5416    
5417                    return count.intValue();
5418            }
5419    
5420            private static final String _FINDER_COLUMN_P_N_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
5421            private static final String _FINDER_COLUMN_P_N_NAME_1 = "assetCategory.name IS NULL";
5422            private static final String _FINDER_COLUMN_P_N_NAME_2 = "assetCategory.name = ?";
5423            private static final String _FINDER_COLUMN_P_N_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '')";
5424            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5425                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5426                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5427                            "findByP_V",
5428                            new String[] {
5429                                    Long.class.getName(), Long.class.getName(),
5430                                    
5431                            Integer.class.getName(), Integer.class.getName(),
5432                                    OrderByComparator.class.getName()
5433                            });
5434            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5435                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5436                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
5437                            "findByP_V",
5438                            new String[] { Long.class.getName(), Long.class.getName() },
5439                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5440                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
5441                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
5442            public static final FinderPath FINDER_PATH_COUNT_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5443                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5444                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_V",
5445                            new String[] { Long.class.getName(), Long.class.getName() });
5446    
5447            /**
5448             * Returns all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
5449             *
5450             * @param parentCategoryId the parent category ID
5451             * @param vocabularyId the vocabulary ID
5452             * @return the matching asset categories
5453             */
5454            @Override
5455            public List<AssetCategory> findByP_V(long parentCategoryId,
5456                    long vocabularyId) {
5457                    return findByP_V(parentCategoryId, vocabularyId, QueryUtil.ALL_POS,
5458                            QueryUtil.ALL_POS, null);
5459            }
5460    
5461            /**
5462             * Returns a range of all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
5463             *
5464             * <p>
5465             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5466             * </p>
5467             *
5468             * @param parentCategoryId the parent category ID
5469             * @param vocabularyId the vocabulary ID
5470             * @param start the lower bound of the range of asset categories
5471             * @param end the upper bound of the range of asset categories (not inclusive)
5472             * @return the range of matching asset categories
5473             */
5474            @Override
5475            public List<AssetCategory> findByP_V(long parentCategoryId,
5476                    long vocabularyId, int start, int end) {
5477                    return findByP_V(parentCategoryId, vocabularyId, start, end, null);
5478            }
5479    
5480            /**
5481             * Returns an ordered range of all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
5482             *
5483             * <p>
5484             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5485             * </p>
5486             *
5487             * @param parentCategoryId the parent category ID
5488             * @param vocabularyId the vocabulary ID
5489             * @param start the lower bound of the range of asset categories
5490             * @param end the upper bound of the range of asset categories (not inclusive)
5491             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5492             * @return the ordered range of matching asset categories
5493             */
5494            @Override
5495            public List<AssetCategory> findByP_V(long parentCategoryId,
5496                    long vocabularyId, int start, int end,
5497                    OrderByComparator<AssetCategory> orderByComparator) {
5498                    return findByP_V(parentCategoryId, vocabularyId, start, end,
5499                            orderByComparator, true);
5500            }
5501    
5502            /**
5503             * Returns an ordered range of all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
5504             *
5505             * <p>
5506             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5507             * </p>
5508             *
5509             * @param parentCategoryId the parent category ID
5510             * @param vocabularyId the vocabulary ID
5511             * @param start the lower bound of the range of asset categories
5512             * @param end the upper bound of the range of asset categories (not inclusive)
5513             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5514             * @param retrieveFromCache whether to retrieve from the finder cache
5515             * @return the ordered range of matching asset categories
5516             */
5517            @Override
5518            public List<AssetCategory> findByP_V(long parentCategoryId,
5519                    long vocabularyId, int start, int end,
5520                    OrderByComparator<AssetCategory> orderByComparator,
5521                    boolean retrieveFromCache) {
5522                    boolean pagination = true;
5523                    FinderPath finderPath = null;
5524                    Object[] finderArgs = null;
5525    
5526                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5527                                    (orderByComparator == null)) {
5528                            pagination = false;
5529                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V;
5530                            finderArgs = new Object[] { parentCategoryId, vocabularyId };
5531                    }
5532                    else {
5533                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_V;
5534                            finderArgs = new Object[] {
5535                                            parentCategoryId, vocabularyId,
5536                                            
5537                                            start, end, orderByComparator
5538                                    };
5539                    }
5540    
5541                    List<AssetCategory> list = null;
5542    
5543                    if (retrieveFromCache) {
5544                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
5545                                            finderArgs, this);
5546    
5547                            if ((list != null) && !list.isEmpty()) {
5548                                    for (AssetCategory assetCategory : list) {
5549                                            if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
5550                                                            (vocabularyId != assetCategory.getVocabularyId())) {
5551                                                    list = null;
5552    
5553                                                    break;
5554                                            }
5555                                    }
5556                            }
5557                    }
5558    
5559                    if (list == null) {
5560                            StringBundler query = null;
5561    
5562                            if (orderByComparator != null) {
5563                                    query = new StringBundler(4 +
5564                                                    (orderByComparator.getOrderByFields().length * 3));
5565                            }
5566                            else {
5567                                    query = new StringBundler(4);
5568                            }
5569    
5570                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5571    
5572                            query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5573    
5574                            query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5575    
5576                            if (orderByComparator != null) {
5577                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5578                                            orderByComparator);
5579                            }
5580                            else
5581                             if (pagination) {
5582                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5583                            }
5584    
5585                            String sql = query.toString();
5586    
5587                            Session session = null;
5588    
5589                            try {
5590                                    session = openSession();
5591    
5592                                    Query q = session.createQuery(sql);
5593    
5594                                    QueryPos qPos = QueryPos.getInstance(q);
5595    
5596                                    qPos.add(parentCategoryId);
5597    
5598                                    qPos.add(vocabularyId);
5599    
5600                                    if (!pagination) {
5601                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
5602                                                            start, end, false);
5603    
5604                                            Collections.sort(list);
5605    
5606                                            list = Collections.unmodifiableList(list);
5607                                    }
5608                                    else {
5609                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
5610                                                            start, end);
5611                                    }
5612    
5613                                    cacheResult(list);
5614    
5615                                    finderCache.putResult(finderPath, finderArgs, list);
5616                            }
5617                            catch (Exception e) {
5618                                    finderCache.removeResult(finderPath, finderArgs);
5619    
5620                                    throw processException(e);
5621                            }
5622                            finally {
5623                                    closeSession(session);
5624                            }
5625                    }
5626    
5627                    return list;
5628            }
5629    
5630            /**
5631             * Returns the first asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
5632             *
5633             * @param parentCategoryId the parent category ID
5634             * @param vocabularyId the vocabulary ID
5635             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5636             * @return the first matching asset category
5637             * @throws NoSuchCategoryException if a matching asset category could not be found
5638             */
5639            @Override
5640            public AssetCategory findByP_V_First(long parentCategoryId,
5641                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator)
5642                    throws NoSuchCategoryException {
5643                    AssetCategory assetCategory = fetchByP_V_First(parentCategoryId,
5644                                    vocabularyId, orderByComparator);
5645    
5646                    if (assetCategory != null) {
5647                            return assetCategory;
5648                    }
5649    
5650                    StringBundler msg = new StringBundler(6);
5651    
5652                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5653    
5654                    msg.append("parentCategoryId=");
5655                    msg.append(parentCategoryId);
5656    
5657                    msg.append(", vocabularyId=");
5658                    msg.append(vocabularyId);
5659    
5660                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5661    
5662                    throw new NoSuchCategoryException(msg.toString());
5663            }
5664    
5665            /**
5666             * Returns the first asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
5667             *
5668             * @param parentCategoryId the parent category ID
5669             * @param vocabularyId the vocabulary ID
5670             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5671             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
5672             */
5673            @Override
5674            public AssetCategory fetchByP_V_First(long parentCategoryId,
5675                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator) {
5676                    List<AssetCategory> list = findByP_V(parentCategoryId, vocabularyId, 0,
5677                                    1, orderByComparator);
5678    
5679                    if (!list.isEmpty()) {
5680                            return list.get(0);
5681                    }
5682    
5683                    return null;
5684            }
5685    
5686            /**
5687             * Returns the last asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
5688             *
5689             * @param parentCategoryId the parent category ID
5690             * @param vocabularyId the vocabulary ID
5691             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5692             * @return the last matching asset category
5693             * @throws NoSuchCategoryException if a matching asset category could not be found
5694             */
5695            @Override
5696            public AssetCategory findByP_V_Last(long parentCategoryId,
5697                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator)
5698                    throws NoSuchCategoryException {
5699                    AssetCategory assetCategory = fetchByP_V_Last(parentCategoryId,
5700                                    vocabularyId, orderByComparator);
5701    
5702                    if (assetCategory != null) {
5703                            return assetCategory;
5704                    }
5705    
5706                    StringBundler msg = new StringBundler(6);
5707    
5708                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5709    
5710                    msg.append("parentCategoryId=");
5711                    msg.append(parentCategoryId);
5712    
5713                    msg.append(", vocabularyId=");
5714                    msg.append(vocabularyId);
5715    
5716                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5717    
5718                    throw new NoSuchCategoryException(msg.toString());
5719            }
5720    
5721            /**
5722             * Returns the last asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
5723             *
5724             * @param parentCategoryId the parent category ID
5725             * @param vocabularyId the vocabulary ID
5726             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5727             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
5728             */
5729            @Override
5730            public AssetCategory fetchByP_V_Last(long parentCategoryId,
5731                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator) {
5732                    int count = countByP_V(parentCategoryId, vocabularyId);
5733    
5734                    if (count == 0) {
5735                            return null;
5736                    }
5737    
5738                    List<AssetCategory> list = findByP_V(parentCategoryId, vocabularyId,
5739                                    count - 1, count, orderByComparator);
5740    
5741                    if (!list.isEmpty()) {
5742                            return list.get(0);
5743                    }
5744    
5745                    return null;
5746            }
5747    
5748            /**
5749             * Returns the asset categories before and after the current asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
5750             *
5751             * @param categoryId the primary key of the current asset category
5752             * @param parentCategoryId the parent category ID
5753             * @param vocabularyId the vocabulary ID
5754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5755             * @return the previous, current, and next asset category
5756             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
5757             */
5758            @Override
5759            public AssetCategory[] findByP_V_PrevAndNext(long categoryId,
5760                    long parentCategoryId, long vocabularyId,
5761                    OrderByComparator<AssetCategory> orderByComparator)
5762                    throws NoSuchCategoryException {
5763                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
5764    
5765                    Session session = null;
5766    
5767                    try {
5768                            session = openSession();
5769    
5770                            AssetCategory[] array = new AssetCategoryImpl[3];
5771    
5772                            array[0] = getByP_V_PrevAndNext(session, assetCategory,
5773                                            parentCategoryId, vocabularyId, orderByComparator, true);
5774    
5775                            array[1] = assetCategory;
5776    
5777                            array[2] = getByP_V_PrevAndNext(session, assetCategory,
5778                                            parentCategoryId, vocabularyId, orderByComparator, false);
5779    
5780                            return array;
5781                    }
5782                    catch (Exception e) {
5783                            throw processException(e);
5784                    }
5785                    finally {
5786                            closeSession(session);
5787                    }
5788            }
5789    
5790            protected AssetCategory getByP_V_PrevAndNext(Session session,
5791                    AssetCategory assetCategory, long parentCategoryId, long vocabularyId,
5792                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
5793                    StringBundler query = null;
5794    
5795                    if (orderByComparator != null) {
5796                            query = new StringBundler(6 +
5797                                            (orderByComparator.getOrderByFields().length * 6));
5798                    }
5799                    else {
5800                            query = new StringBundler(3);
5801                    }
5802    
5803                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5804    
5805                    query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5806    
5807                    query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5808    
5809                    if (orderByComparator != null) {
5810                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5811    
5812                            if (orderByConditionFields.length > 0) {
5813                                    query.append(WHERE_AND);
5814                            }
5815    
5816                            for (int i = 0; i < orderByConditionFields.length; i++) {
5817                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5818                                    query.append(orderByConditionFields[i]);
5819    
5820                                    if ((i + 1) < orderByConditionFields.length) {
5821                                            if (orderByComparator.isAscending() ^ previous) {
5822                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5823                                            }
5824                                            else {
5825                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5826                                            }
5827                                    }
5828                                    else {
5829                                            if (orderByComparator.isAscending() ^ previous) {
5830                                                    query.append(WHERE_GREATER_THAN);
5831                                            }
5832                                            else {
5833                                                    query.append(WHERE_LESSER_THAN);
5834                                            }
5835                                    }
5836                            }
5837    
5838                            query.append(ORDER_BY_CLAUSE);
5839    
5840                            String[] orderByFields = orderByComparator.getOrderByFields();
5841    
5842                            for (int i = 0; i < orderByFields.length; i++) {
5843                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5844                                    query.append(orderByFields[i]);
5845    
5846                                    if ((i + 1) < orderByFields.length) {
5847                                            if (orderByComparator.isAscending() ^ previous) {
5848                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5849                                            }
5850                                            else {
5851                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5852                                            }
5853                                    }
5854                                    else {
5855                                            if (orderByComparator.isAscending() ^ previous) {
5856                                                    query.append(ORDER_BY_ASC);
5857                                            }
5858                                            else {
5859                                                    query.append(ORDER_BY_DESC);
5860                                            }
5861                                    }
5862                            }
5863                    }
5864                    else {
5865                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5866                    }
5867    
5868                    String sql = query.toString();
5869    
5870                    Query q = session.createQuery(sql);
5871    
5872                    q.setFirstResult(0);
5873                    q.setMaxResults(2);
5874    
5875                    QueryPos qPos = QueryPos.getInstance(q);
5876    
5877                    qPos.add(parentCategoryId);
5878    
5879                    qPos.add(vocabularyId);
5880    
5881                    if (orderByComparator != null) {
5882                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
5883    
5884                            for (Object value : values) {
5885                                    qPos.add(value);
5886                            }
5887                    }
5888    
5889                    List<AssetCategory> list = q.list();
5890    
5891                    if (list.size() == 2) {
5892                            return list.get(1);
5893                    }
5894                    else {
5895                            return null;
5896                    }
5897            }
5898    
5899            /**
5900             * Removes all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63; from the database.
5901             *
5902             * @param parentCategoryId the parent category ID
5903             * @param vocabularyId the vocabulary ID
5904             */
5905            @Override
5906            public void removeByP_V(long parentCategoryId, long vocabularyId) {
5907                    for (AssetCategory assetCategory : findByP_V(parentCategoryId,
5908                                    vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5909                            remove(assetCategory);
5910                    }
5911            }
5912    
5913            /**
5914             * Returns the number of asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
5915             *
5916             * @param parentCategoryId the parent category ID
5917             * @param vocabularyId the vocabulary ID
5918             * @return the number of matching asset categories
5919             */
5920            @Override
5921            public int countByP_V(long parentCategoryId, long vocabularyId) {
5922                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_V;
5923    
5924                    Object[] finderArgs = new Object[] { parentCategoryId, vocabularyId };
5925    
5926                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5927    
5928                    if (count == null) {
5929                            StringBundler query = new StringBundler(3);
5930    
5931                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
5932    
5933                            query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5934    
5935                            query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5936    
5937                            String sql = query.toString();
5938    
5939                            Session session = null;
5940    
5941                            try {
5942                                    session = openSession();
5943    
5944                                    Query q = session.createQuery(sql);
5945    
5946                                    QueryPos qPos = QueryPos.getInstance(q);
5947    
5948                                    qPos.add(parentCategoryId);
5949    
5950                                    qPos.add(vocabularyId);
5951    
5952                                    count = (Long)q.uniqueResult();
5953    
5954                                    finderCache.putResult(finderPath, finderArgs, count);
5955                            }
5956                            catch (Exception e) {
5957                                    finderCache.removeResult(finderPath, finderArgs);
5958    
5959                                    throw processException(e);
5960                            }
5961                            finally {
5962                                    closeSession(session);
5963                            }
5964                    }
5965    
5966                    return count.intValue();
5967            }
5968    
5969            private static final String _FINDER_COLUMN_P_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
5970            private static final String _FINDER_COLUMN_P_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
5971            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5972                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5973                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5974                            "findByN_V",
5975                            new String[] {
5976                                    String.class.getName(), Long.class.getName(),
5977                                    
5978                            Integer.class.getName(), Integer.class.getName(),
5979                                    OrderByComparator.class.getName()
5980                            });
5981            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5982                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5983                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
5984                            "findByN_V",
5985                            new String[] { String.class.getName(), Long.class.getName() },
5986                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
5987                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
5988            public static final FinderPath FINDER_PATH_COUNT_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5989                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5990                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_V",
5991                            new String[] { String.class.getName(), Long.class.getName() });
5992    
5993            /**
5994             * Returns all the asset categories where name = &#63; and vocabularyId = &#63;.
5995             *
5996             * @param name the name
5997             * @param vocabularyId the vocabulary ID
5998             * @return the matching asset categories
5999             */
6000            @Override
6001            public List<AssetCategory> findByN_V(String name, long vocabularyId) {
6002                    return findByN_V(name, vocabularyId, QueryUtil.ALL_POS,
6003                            QueryUtil.ALL_POS, null);
6004            }
6005    
6006            /**
6007             * Returns a range of all the asset categories where name = &#63; and vocabularyId = &#63;.
6008             *
6009             * <p>
6010             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6011             * </p>
6012             *
6013             * @param name the name
6014             * @param vocabularyId the vocabulary ID
6015             * @param start the lower bound of the range of asset categories
6016             * @param end the upper bound of the range of asset categories (not inclusive)
6017             * @return the range of matching asset categories
6018             */
6019            @Override
6020            public List<AssetCategory> findByN_V(String name, long vocabularyId,
6021                    int start, int end) {
6022                    return findByN_V(name, vocabularyId, start, end, null);
6023            }
6024    
6025            /**
6026             * Returns an ordered range of all the asset categories where name = &#63; and vocabularyId = &#63;.
6027             *
6028             * <p>
6029             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6030             * </p>
6031             *
6032             * @param name the name
6033             * @param vocabularyId the vocabulary ID
6034             * @param start the lower bound of the range of asset categories
6035             * @param end the upper bound of the range of asset categories (not inclusive)
6036             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6037             * @return the ordered range of matching asset categories
6038             */
6039            @Override
6040            public List<AssetCategory> findByN_V(String name, long vocabularyId,
6041                    int start, int end, OrderByComparator<AssetCategory> orderByComparator) {
6042                    return findByN_V(name, vocabularyId, start, end, orderByComparator, true);
6043            }
6044    
6045            /**
6046             * Returns an ordered range of all the asset categories where name = &#63; and vocabularyId = &#63;.
6047             *
6048             * <p>
6049             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6050             * </p>
6051             *
6052             * @param name the name
6053             * @param vocabularyId the vocabulary ID
6054             * @param start the lower bound of the range of asset categories
6055             * @param end the upper bound of the range of asset categories (not inclusive)
6056             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6057             * @param retrieveFromCache whether to retrieve from the finder cache
6058             * @return the ordered range of matching asset categories
6059             */
6060            @Override
6061            public List<AssetCategory> findByN_V(String name, long vocabularyId,
6062                    int start, int end, OrderByComparator<AssetCategory> orderByComparator,
6063                    boolean retrieveFromCache) {
6064                    boolean pagination = true;
6065                    FinderPath finderPath = null;
6066                    Object[] finderArgs = null;
6067    
6068                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6069                                    (orderByComparator == null)) {
6070                            pagination = false;
6071                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V;
6072                            finderArgs = new Object[] { name, vocabularyId };
6073                    }
6074                    else {
6075                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_V;
6076                            finderArgs = new Object[] {
6077                                            name, vocabularyId,
6078                                            
6079                                            start, end, orderByComparator
6080                                    };
6081                    }
6082    
6083                    List<AssetCategory> list = null;
6084    
6085                    if (retrieveFromCache) {
6086                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
6087                                            finderArgs, this);
6088    
6089                            if ((list != null) && !list.isEmpty()) {
6090                                    for (AssetCategory assetCategory : list) {
6091                                            if (!Validator.equals(name, assetCategory.getName()) ||
6092                                                            (vocabularyId != assetCategory.getVocabularyId())) {
6093                                                    list = null;
6094    
6095                                                    break;
6096                                            }
6097                                    }
6098                            }
6099                    }
6100    
6101                    if (list == null) {
6102                            StringBundler query = null;
6103    
6104                            if (orderByComparator != null) {
6105                                    query = new StringBundler(4 +
6106                                                    (orderByComparator.getOrderByFields().length * 3));
6107                            }
6108                            else {
6109                                    query = new StringBundler(4);
6110                            }
6111    
6112                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6113    
6114                            boolean bindName = false;
6115    
6116                            if (name == null) {
6117                                    query.append(_FINDER_COLUMN_N_V_NAME_1);
6118                            }
6119                            else if (name.equals(StringPool.BLANK)) {
6120                                    query.append(_FINDER_COLUMN_N_V_NAME_3);
6121                            }
6122                            else {
6123                                    bindName = true;
6124    
6125                                    query.append(_FINDER_COLUMN_N_V_NAME_2);
6126                            }
6127    
6128                            query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
6129    
6130                            if (orderByComparator != null) {
6131                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6132                                            orderByComparator);
6133                            }
6134                            else
6135                             if (pagination) {
6136                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6137                            }
6138    
6139                            String sql = query.toString();
6140    
6141                            Session session = null;
6142    
6143                            try {
6144                                    session = openSession();
6145    
6146                                    Query q = session.createQuery(sql);
6147    
6148                                    QueryPos qPos = QueryPos.getInstance(q);
6149    
6150                                    if (bindName) {
6151                                            qPos.add(name);
6152                                    }
6153    
6154                                    qPos.add(vocabularyId);
6155    
6156                                    if (!pagination) {
6157                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6158                                                            start, end, false);
6159    
6160                                            Collections.sort(list);
6161    
6162                                            list = Collections.unmodifiableList(list);
6163                                    }
6164                                    else {
6165                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6166                                                            start, end);
6167                                    }
6168    
6169                                    cacheResult(list);
6170    
6171                                    finderCache.putResult(finderPath, finderArgs, list);
6172                            }
6173                            catch (Exception e) {
6174                                    finderCache.removeResult(finderPath, finderArgs);
6175    
6176                                    throw processException(e);
6177                            }
6178                            finally {
6179                                    closeSession(session);
6180                            }
6181                    }
6182    
6183                    return list;
6184            }
6185    
6186            /**
6187             * Returns the first asset category in the ordered set where name = &#63; and vocabularyId = &#63;.
6188             *
6189             * @param name the name
6190             * @param vocabularyId the vocabulary ID
6191             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6192             * @return the first matching asset category
6193             * @throws NoSuchCategoryException if a matching asset category could not be found
6194             */
6195            @Override
6196            public AssetCategory findByN_V_First(String name, long vocabularyId,
6197                    OrderByComparator<AssetCategory> orderByComparator)
6198                    throws NoSuchCategoryException {
6199                    AssetCategory assetCategory = fetchByN_V_First(name, vocabularyId,
6200                                    orderByComparator);
6201    
6202                    if (assetCategory != null) {
6203                            return assetCategory;
6204                    }
6205    
6206                    StringBundler msg = new StringBundler(6);
6207    
6208                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6209    
6210                    msg.append("name=");
6211                    msg.append(name);
6212    
6213                    msg.append(", vocabularyId=");
6214                    msg.append(vocabularyId);
6215    
6216                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6217    
6218                    throw new NoSuchCategoryException(msg.toString());
6219            }
6220    
6221            /**
6222             * Returns the first asset category in the ordered set where name = &#63; and vocabularyId = &#63;.
6223             *
6224             * @param name the name
6225             * @param vocabularyId the vocabulary ID
6226             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6227             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
6228             */
6229            @Override
6230            public AssetCategory fetchByN_V_First(String name, long vocabularyId,
6231                    OrderByComparator<AssetCategory> orderByComparator) {
6232                    List<AssetCategory> list = findByN_V(name, vocabularyId, 0, 1,
6233                                    orderByComparator);
6234    
6235                    if (!list.isEmpty()) {
6236                            return list.get(0);
6237                    }
6238    
6239                    return null;
6240            }
6241    
6242            /**
6243             * Returns the last asset category in the ordered set where name = &#63; and vocabularyId = &#63;.
6244             *
6245             * @param name the name
6246             * @param vocabularyId the vocabulary ID
6247             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6248             * @return the last matching asset category
6249             * @throws NoSuchCategoryException if a matching asset category could not be found
6250             */
6251            @Override
6252            public AssetCategory findByN_V_Last(String name, long vocabularyId,
6253                    OrderByComparator<AssetCategory> orderByComparator)
6254                    throws NoSuchCategoryException {
6255                    AssetCategory assetCategory = fetchByN_V_Last(name, vocabularyId,
6256                                    orderByComparator);
6257    
6258                    if (assetCategory != null) {
6259                            return assetCategory;
6260                    }
6261    
6262                    StringBundler msg = new StringBundler(6);
6263    
6264                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6265    
6266                    msg.append("name=");
6267                    msg.append(name);
6268    
6269                    msg.append(", vocabularyId=");
6270                    msg.append(vocabularyId);
6271    
6272                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6273    
6274                    throw new NoSuchCategoryException(msg.toString());
6275            }
6276    
6277            /**
6278             * Returns the last asset category in the ordered set where name = &#63; and vocabularyId = &#63;.
6279             *
6280             * @param name the name
6281             * @param vocabularyId the vocabulary ID
6282             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6283             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
6284             */
6285            @Override
6286            public AssetCategory fetchByN_V_Last(String name, long vocabularyId,
6287                    OrderByComparator<AssetCategory> orderByComparator) {
6288                    int count = countByN_V(name, vocabularyId);
6289    
6290                    if (count == 0) {
6291                            return null;
6292                    }
6293    
6294                    List<AssetCategory> list = findByN_V(name, vocabularyId, count - 1,
6295                                    count, orderByComparator);
6296    
6297                    if (!list.isEmpty()) {
6298                            return list.get(0);
6299                    }
6300    
6301                    return null;
6302            }
6303    
6304            /**
6305             * Returns the asset categories before and after the current asset category in the ordered set where name = &#63; and vocabularyId = &#63;.
6306             *
6307             * @param categoryId the primary key of the current asset category
6308             * @param name the name
6309             * @param vocabularyId the vocabulary ID
6310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6311             * @return the previous, current, and next asset category
6312             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
6313             */
6314            @Override
6315            public AssetCategory[] findByN_V_PrevAndNext(long categoryId, String name,
6316                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator)
6317                    throws NoSuchCategoryException {
6318                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
6319    
6320                    Session session = null;
6321    
6322                    try {
6323                            session = openSession();
6324    
6325                            AssetCategory[] array = new AssetCategoryImpl[3];
6326    
6327                            array[0] = getByN_V_PrevAndNext(session, assetCategory, name,
6328                                            vocabularyId, orderByComparator, true);
6329    
6330                            array[1] = assetCategory;
6331    
6332                            array[2] = getByN_V_PrevAndNext(session, assetCategory, name,
6333                                            vocabularyId, orderByComparator, false);
6334    
6335                            return array;
6336                    }
6337                    catch (Exception e) {
6338                            throw processException(e);
6339                    }
6340                    finally {
6341                            closeSession(session);
6342                    }
6343            }
6344    
6345            protected AssetCategory getByN_V_PrevAndNext(Session session,
6346                    AssetCategory assetCategory, String name, long vocabularyId,
6347                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
6348                    StringBundler query = null;
6349    
6350                    if (orderByComparator != null) {
6351                            query = new StringBundler(6 +
6352                                            (orderByComparator.getOrderByFields().length * 6));
6353                    }
6354                    else {
6355                            query = new StringBundler(3);
6356                    }
6357    
6358                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6359    
6360                    boolean bindName = false;
6361    
6362                    if (name == null) {
6363                            query.append(_FINDER_COLUMN_N_V_NAME_1);
6364                    }
6365                    else if (name.equals(StringPool.BLANK)) {
6366                            query.append(_FINDER_COLUMN_N_V_NAME_3);
6367                    }
6368                    else {
6369                            bindName = true;
6370    
6371                            query.append(_FINDER_COLUMN_N_V_NAME_2);
6372                    }
6373    
6374                    query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
6375    
6376                    if (orderByComparator != null) {
6377                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6378    
6379                            if (orderByConditionFields.length > 0) {
6380                                    query.append(WHERE_AND);
6381                            }
6382    
6383                            for (int i = 0; i < orderByConditionFields.length; i++) {
6384                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6385                                    query.append(orderByConditionFields[i]);
6386    
6387                                    if ((i + 1) < orderByConditionFields.length) {
6388                                            if (orderByComparator.isAscending() ^ previous) {
6389                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6390                                            }
6391                                            else {
6392                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6393                                            }
6394                                    }
6395                                    else {
6396                                            if (orderByComparator.isAscending() ^ previous) {
6397                                                    query.append(WHERE_GREATER_THAN);
6398                                            }
6399                                            else {
6400                                                    query.append(WHERE_LESSER_THAN);
6401                                            }
6402                                    }
6403                            }
6404    
6405                            query.append(ORDER_BY_CLAUSE);
6406    
6407                            String[] orderByFields = orderByComparator.getOrderByFields();
6408    
6409                            for (int i = 0; i < orderByFields.length; i++) {
6410                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6411                                    query.append(orderByFields[i]);
6412    
6413                                    if ((i + 1) < orderByFields.length) {
6414                                            if (orderByComparator.isAscending() ^ previous) {
6415                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6416                                            }
6417                                            else {
6418                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6419                                            }
6420                                    }
6421                                    else {
6422                                            if (orderByComparator.isAscending() ^ previous) {
6423                                                    query.append(ORDER_BY_ASC);
6424                                            }
6425                                            else {
6426                                                    query.append(ORDER_BY_DESC);
6427                                            }
6428                                    }
6429                            }
6430                    }
6431                    else {
6432                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6433                    }
6434    
6435                    String sql = query.toString();
6436    
6437                    Query q = session.createQuery(sql);
6438    
6439                    q.setFirstResult(0);
6440                    q.setMaxResults(2);
6441    
6442                    QueryPos qPos = QueryPos.getInstance(q);
6443    
6444                    if (bindName) {
6445                            qPos.add(name);
6446                    }
6447    
6448                    qPos.add(vocabularyId);
6449    
6450                    if (orderByComparator != null) {
6451                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
6452    
6453                            for (Object value : values) {
6454                                    qPos.add(value);
6455                            }
6456                    }
6457    
6458                    List<AssetCategory> list = q.list();
6459    
6460                    if (list.size() == 2) {
6461                            return list.get(1);
6462                    }
6463                    else {
6464                            return null;
6465                    }
6466            }
6467    
6468            /**
6469             * Removes all the asset categories where name = &#63; and vocabularyId = &#63; from the database.
6470             *
6471             * @param name the name
6472             * @param vocabularyId the vocabulary ID
6473             */
6474            @Override
6475            public void removeByN_V(String name, long vocabularyId) {
6476                    for (AssetCategory assetCategory : findByN_V(name, vocabularyId,
6477                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6478                            remove(assetCategory);
6479                    }
6480            }
6481    
6482            /**
6483             * Returns the number of asset categories where name = &#63; and vocabularyId = &#63;.
6484             *
6485             * @param name the name
6486             * @param vocabularyId the vocabulary ID
6487             * @return the number of matching asset categories
6488             */
6489            @Override
6490            public int countByN_V(String name, long vocabularyId) {
6491                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_V;
6492    
6493                    Object[] finderArgs = new Object[] { name, vocabularyId };
6494    
6495                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6496    
6497                    if (count == null) {
6498                            StringBundler query = new StringBundler(3);
6499    
6500                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
6501    
6502                            boolean bindName = false;
6503    
6504                            if (name == null) {
6505                                    query.append(_FINDER_COLUMN_N_V_NAME_1);
6506                            }
6507                            else if (name.equals(StringPool.BLANK)) {
6508                                    query.append(_FINDER_COLUMN_N_V_NAME_3);
6509                            }
6510                            else {
6511                                    bindName = true;
6512    
6513                                    query.append(_FINDER_COLUMN_N_V_NAME_2);
6514                            }
6515    
6516                            query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
6517    
6518                            String sql = query.toString();
6519    
6520                            Session session = null;
6521    
6522                            try {
6523                                    session = openSession();
6524    
6525                                    Query q = session.createQuery(sql);
6526    
6527                                    QueryPos qPos = QueryPos.getInstance(q);
6528    
6529                                    if (bindName) {
6530                                            qPos.add(name);
6531                                    }
6532    
6533                                    qPos.add(vocabularyId);
6534    
6535                                    count = (Long)q.uniqueResult();
6536    
6537                                    finderCache.putResult(finderPath, finderArgs, count);
6538                            }
6539                            catch (Exception e) {
6540                                    finderCache.removeResult(finderPath, finderArgs);
6541    
6542                                    throw processException(e);
6543                            }
6544                            finally {
6545                                    closeSession(session);
6546                            }
6547                    }
6548    
6549                    return count.intValue();
6550            }
6551    
6552            private static final String _FINDER_COLUMN_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
6553            private static final String _FINDER_COLUMN_N_V_NAME_2 = "assetCategory.name = ? AND ";
6554            private static final String _FINDER_COLUMN_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '') AND ";
6555            private static final String _FINDER_COLUMN_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
6556            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6557                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
6558                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
6559                            "findByG_P_V",
6560                            new String[] {
6561                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
6562                                    
6563                            Integer.class.getName(), Integer.class.getName(),
6564                                    OrderByComparator.class.getName()
6565                            });
6566            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6567                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
6568                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
6569                            "findByG_P_V",
6570                            new String[] {
6571                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
6572                            },
6573                            AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
6574                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
6575                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
6576                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
6577            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6578                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
6579                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_V",
6580                            new String[] {
6581                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
6582                            });
6583    
6584            /**
6585             * Returns all the asset categories where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
6586             *
6587             * @param groupId the group ID
6588             * @param parentCategoryId the parent category ID
6589             * @param vocabularyId the vocabulary ID
6590             * @return the matching asset categories
6591             */
6592            @Override
6593            public List<AssetCategory> findByG_P_V(long groupId, long parentCategoryId,
6594                    long vocabularyId) {
6595                    return findByG_P_V(groupId, parentCategoryId, vocabularyId,
6596                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6597            }
6598    
6599            /**
6600             * Returns a range of all the asset categories where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
6601             *
6602             * <p>
6603             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6604             * </p>
6605             *
6606             * @param groupId the group ID
6607             * @param parentCategoryId the parent category ID
6608             * @param vocabularyId the vocabulary ID
6609             * @param start the lower bound of the range of asset categories
6610             * @param end the upper bound of the range of asset categories (not inclusive)
6611             * @return the range of matching asset categories
6612             */
6613            @Override
6614            public List<AssetCategory> findByG_P_V(long groupId, long parentCategoryId,
6615                    long vocabularyId, int start, int end) {
6616                    return findByG_P_V(groupId, parentCategoryId, vocabularyId, start, end,
6617                            null);
6618            }
6619    
6620            /**
6621             * Returns an ordered range of all the asset categories where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
6622             *
6623             * <p>
6624             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6625             * </p>
6626             *
6627             * @param groupId the group ID
6628             * @param parentCategoryId the parent category ID
6629             * @param vocabularyId the vocabulary ID
6630             * @param start the lower bound of the range of asset categories
6631             * @param end the upper bound of the range of asset categories (not inclusive)
6632             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6633             * @return the ordered range of matching asset categories
6634             */
6635            @Override
6636            public List<AssetCategory> findByG_P_V(long groupId, long parentCategoryId,
6637                    long vocabularyId, int start, int end,
6638                    OrderByComparator<AssetCategory> orderByComparator) {
6639                    return findByG_P_V(groupId, parentCategoryId, vocabularyId, start, end,
6640                            orderByComparator, true);
6641            }
6642    
6643            /**
6644             * Returns an ordered range of all the asset categories where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
6645             *
6646             * <p>
6647             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6648             * </p>
6649             *
6650             * @param groupId the group ID
6651             * @param parentCategoryId the parent category ID
6652             * @param vocabularyId the vocabulary ID
6653             * @param start the lower bound of the range of asset categories
6654             * @param end the upper bound of the range of asset categories (not inclusive)
6655             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6656             * @param retrieveFromCache whether to retrieve from the finder cache
6657             * @return the ordered range of matching asset categories
6658             */
6659            @Override
6660            public List<AssetCategory> findByG_P_V(long groupId, long parentCategoryId,
6661                    long vocabularyId, int start, int end,
6662                    OrderByComparator<AssetCategory> orderByComparator,
6663                    boolean retrieveFromCache) {
6664                    boolean pagination = true;
6665                    FinderPath finderPath = null;
6666                    Object[] finderArgs = null;
6667    
6668                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6669                                    (orderByComparator == null)) {
6670                            pagination = false;
6671                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_V;
6672                            finderArgs = new Object[] { groupId, parentCategoryId, vocabularyId };
6673                    }
6674                    else {
6675                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_V;
6676                            finderArgs = new Object[] {
6677                                            groupId, parentCategoryId, vocabularyId,
6678                                            
6679                                            start, end, orderByComparator
6680                                    };
6681                    }
6682    
6683                    List<AssetCategory> list = null;
6684    
6685                    if (retrieveFromCache) {
6686                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
6687                                            finderArgs, this);
6688    
6689                            if ((list != null) && !list.isEmpty()) {
6690                                    for (AssetCategory assetCategory : list) {
6691                                            if ((groupId != assetCategory.getGroupId()) ||
6692                                                            (parentCategoryId != assetCategory.getParentCategoryId()) ||
6693                                                            (vocabularyId != assetCategory.getVocabularyId())) {
6694                                                    list = null;
6695    
6696                                                    break;
6697                                            }
6698                                    }
6699                            }
6700                    }
6701    
6702                    if (list == null) {
6703                            StringBundler query = null;
6704    
6705                            if (orderByComparator != null) {
6706                                    query = new StringBundler(5 +
6707                                                    (orderByComparator.getOrderByFields().length * 3));
6708                            }
6709                            else {
6710                                    query = new StringBundler(5);
6711                            }
6712    
6713                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6714    
6715                            query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
6716    
6717                            query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
6718    
6719                            query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
6720    
6721                            if (orderByComparator != null) {
6722                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6723                                            orderByComparator);
6724                            }
6725                            else
6726                             if (pagination) {
6727                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6728                            }
6729    
6730                            String sql = query.toString();
6731    
6732                            Session session = null;
6733    
6734                            try {
6735                                    session = openSession();
6736    
6737                                    Query q = session.createQuery(sql);
6738    
6739                                    QueryPos qPos = QueryPos.getInstance(q);
6740    
6741                                    qPos.add(groupId);
6742    
6743                                    qPos.add(parentCategoryId);
6744    
6745                                    qPos.add(vocabularyId);
6746    
6747                                    if (!pagination) {
6748                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6749                                                            start, end, false);
6750    
6751                                            Collections.sort(list);
6752    
6753                                            list = Collections.unmodifiableList(list);
6754                                    }
6755                                    else {
6756                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6757                                                            start, end);
6758                                    }
6759    
6760                                    cacheResult(list);
6761    
6762                                    finderCache.putResult(finderPath, finderArgs, list);
6763                            }
6764                            catch (Exception e) {
6765                                    finderCache.removeResult(finderPath, finderArgs);
6766    
6767                                    throw processException(e);
6768                            }
6769                            finally {
6770                                    closeSession(session);
6771                            }
6772                    }
6773    
6774                    return list;
6775            }
6776    
6777            /**
6778             * Returns the first asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
6779             *
6780             * @param groupId the group ID
6781             * @param parentCategoryId the parent category ID
6782             * @param vocabularyId the vocabulary ID
6783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6784             * @return the first matching asset category
6785             * @throws NoSuchCategoryException if a matching asset category could not be found
6786             */
6787            @Override
6788            public AssetCategory findByG_P_V_First(long groupId, long parentCategoryId,
6789                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator)
6790                    throws NoSuchCategoryException {
6791                    AssetCategory assetCategory = fetchByG_P_V_First(groupId,
6792                                    parentCategoryId, vocabularyId, orderByComparator);
6793    
6794                    if (assetCategory != null) {
6795                            return assetCategory;
6796                    }
6797    
6798                    StringBundler msg = new StringBundler(8);
6799    
6800                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6801    
6802                    msg.append("groupId=");
6803                    msg.append(groupId);
6804    
6805                    msg.append(", parentCategoryId=");
6806                    msg.append(parentCategoryId);
6807    
6808                    msg.append(", vocabularyId=");
6809                    msg.append(vocabularyId);
6810    
6811                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6812    
6813                    throw new NoSuchCategoryException(msg.toString());
6814            }
6815    
6816            /**
6817             * Returns the first asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
6818             *
6819             * @param groupId the group ID
6820             * @param parentCategoryId the parent category ID
6821             * @param vocabularyId the vocabulary ID
6822             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6823             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
6824             */
6825            @Override
6826            public AssetCategory fetchByG_P_V_First(long groupId,
6827                    long parentCategoryId, long vocabularyId,
6828                    OrderByComparator<AssetCategory> orderByComparator) {
6829                    List<AssetCategory> list = findByG_P_V(groupId, parentCategoryId,
6830                                    vocabularyId, 0, 1, orderByComparator);
6831    
6832                    if (!list.isEmpty()) {
6833                            return list.get(0);
6834                    }
6835    
6836                    return null;
6837            }
6838    
6839            /**
6840             * Returns the last asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
6841             *
6842             * @param groupId the group ID
6843             * @param parentCategoryId the parent category ID
6844             * @param vocabularyId the vocabulary ID
6845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6846             * @return the last matching asset category
6847             * @throws NoSuchCategoryException if a matching asset category could not be found
6848             */
6849            @Override
6850            public AssetCategory findByG_P_V_Last(long groupId, long parentCategoryId,
6851                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator)
6852                    throws NoSuchCategoryException {
6853                    AssetCategory assetCategory = fetchByG_P_V_Last(groupId,
6854                                    parentCategoryId, vocabularyId, orderByComparator);
6855    
6856                    if (assetCategory != null) {
6857                            return assetCategory;
6858                    }
6859    
6860                    StringBundler msg = new StringBundler(8);
6861    
6862                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6863    
6864                    msg.append("groupId=");
6865                    msg.append(groupId);
6866    
6867                    msg.append(", parentCategoryId=");
6868                    msg.append(parentCategoryId);
6869    
6870                    msg.append(", vocabularyId=");
6871                    msg.append(vocabularyId);
6872    
6873                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6874    
6875                    throw new NoSuchCategoryException(msg.toString());
6876            }
6877    
6878            /**
6879             * Returns the last asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
6880             *
6881             * @param groupId the group ID
6882             * @param parentCategoryId the parent category ID
6883             * @param vocabularyId the vocabulary ID
6884             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6885             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
6886             */
6887            @Override
6888            public AssetCategory fetchByG_P_V_Last(long groupId, long parentCategoryId,
6889                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator) {
6890                    int count = countByG_P_V(groupId, parentCategoryId, vocabularyId);
6891    
6892                    if (count == 0) {
6893                            return null;
6894                    }
6895    
6896                    List<AssetCategory> list = findByG_P_V(groupId, parentCategoryId,
6897                                    vocabularyId, count - 1, count, orderByComparator);
6898    
6899                    if (!list.isEmpty()) {
6900                            return list.get(0);
6901                    }
6902    
6903                    return null;
6904            }
6905    
6906            /**
6907             * Returns the asset categories before and after the current asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
6908             *
6909             * @param categoryId the primary key of the current asset category
6910             * @param groupId the group ID
6911             * @param parentCategoryId the parent category ID
6912             * @param vocabularyId the vocabulary ID
6913             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6914             * @return the previous, current, and next asset category
6915             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
6916             */
6917            @Override
6918            public AssetCategory[] findByG_P_V_PrevAndNext(long categoryId,
6919                    long groupId, long parentCategoryId, long vocabularyId,
6920                    OrderByComparator<AssetCategory> orderByComparator)
6921                    throws NoSuchCategoryException {
6922                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
6923    
6924                    Session session = null;
6925    
6926                    try {
6927                            session = openSession();
6928    
6929                            AssetCategory[] array = new AssetCategoryImpl[3];
6930    
6931                            array[0] = getByG_P_V_PrevAndNext(session, assetCategory, groupId,
6932                                            parentCategoryId, vocabularyId, orderByComparator, true);
6933    
6934                            array[1] = assetCategory;
6935    
6936                            array[2] = getByG_P_V_PrevAndNext(session, assetCategory, groupId,
6937                                            parentCategoryId, vocabularyId, orderByComparator, false);
6938    
6939                            return array;
6940                    }
6941                    catch (Exception e) {
6942                            throw processException(e);
6943                    }
6944                    finally {
6945                            closeSession(session);
6946                    }
6947            }
6948    
6949            protected AssetCategory getByG_P_V_PrevAndNext(Session session,
6950                    AssetCategory assetCategory, long groupId, long parentCategoryId,
6951                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator,
6952                    boolean previous) {
6953                    StringBundler query = null;
6954    
6955                    if (orderByComparator != null) {
6956                            query = new StringBundler(6 +
6957                                            (orderByComparator.getOrderByFields().length * 6));
6958                    }
6959                    else {
6960                            query = new StringBundler(3);
6961                    }
6962    
6963                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6964    
6965                    query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
6966    
6967                    query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
6968    
6969                    query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
6970    
6971                    if (orderByComparator != null) {
6972                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6973    
6974                            if (orderByConditionFields.length > 0) {
6975                                    query.append(WHERE_AND);
6976                            }
6977    
6978                            for (int i = 0; i < orderByConditionFields.length; i++) {
6979                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6980                                    query.append(orderByConditionFields[i]);
6981    
6982                                    if ((i + 1) < orderByConditionFields.length) {
6983                                            if (orderByComparator.isAscending() ^ previous) {
6984                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6985                                            }
6986                                            else {
6987                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6988                                            }
6989                                    }
6990                                    else {
6991                                            if (orderByComparator.isAscending() ^ previous) {
6992                                                    query.append(WHERE_GREATER_THAN);
6993                                            }
6994                                            else {
6995                                                    query.append(WHERE_LESSER_THAN);
6996                                            }
6997                                    }
6998                            }
6999    
7000                            query.append(ORDER_BY_CLAUSE);
7001    
7002                            String[] orderByFields = orderByComparator.getOrderByFields();
7003    
7004                            for (int i = 0; i < orderByFields.length; i++) {
7005                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7006                                    query.append(orderByFields[i]);
7007    
7008                                    if ((i + 1) < orderByFields.length) {
7009                                            if (orderByComparator.isAscending() ^ previous) {
7010                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7011                                            }
7012                                            else {
7013                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7014                                            }
7015                                    }
7016                                    else {
7017                                            if (orderByComparator.isAscending() ^ previous) {
7018                                                    query.append(ORDER_BY_ASC);
7019                                            }
7020                                            else {
7021                                                    query.append(ORDER_BY_DESC);
7022                                            }
7023                                    }
7024                            }
7025                    }
7026                    else {
7027                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7028                    }
7029    
7030                    String sql = query.toString();
7031    
7032                    Query q = session.createQuery(sql);
7033    
7034                    q.setFirstResult(0);
7035                    q.setMaxResults(2);
7036    
7037                    QueryPos qPos = QueryPos.getInstance(q);
7038    
7039                    qPos.add(groupId);
7040    
7041                    qPos.add(parentCategoryId);
7042    
7043                    qPos.add(vocabularyId);
7044    
7045                    if (orderByComparator != null) {
7046                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
7047    
7048                            for (Object value : values) {
7049                                    qPos.add(value);
7050                            }
7051                    }
7052    
7053                    List<AssetCategory> list = q.list();
7054    
7055                    if (list.size() == 2) {
7056                            return list.get(1);
7057                    }
7058                    else {
7059                            return null;
7060                    }
7061            }
7062    
7063            /**
7064             * Returns all the asset categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
7065             *
7066             * @param groupId the group ID
7067             * @param parentCategoryId the parent category ID
7068             * @param vocabularyId the vocabulary ID
7069             * @return the matching asset categories that the user has permission to view
7070             */
7071            @Override
7072            public List<AssetCategory> filterFindByG_P_V(long groupId,
7073                    long parentCategoryId, long vocabularyId) {
7074                    return filterFindByG_P_V(groupId, parentCategoryId, vocabularyId,
7075                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7076            }
7077    
7078            /**
7079             * Returns a range of all the asset categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
7080             *
7081             * <p>
7082             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7083             * </p>
7084             *
7085             * @param groupId the group ID
7086             * @param parentCategoryId the parent category ID
7087             * @param vocabularyId the vocabulary ID
7088             * @param start the lower bound of the range of asset categories
7089             * @param end the upper bound of the range of asset categories (not inclusive)
7090             * @return the range of matching asset categories that the user has permission to view
7091             */
7092            @Override
7093            public List<AssetCategory> filterFindByG_P_V(long groupId,
7094                    long parentCategoryId, long vocabularyId, int start, int end) {
7095                    return filterFindByG_P_V(groupId, parentCategoryId, vocabularyId,
7096                            start, end, null);
7097            }
7098    
7099            /**
7100             * Returns an ordered range of all the asset categories that the user has permissions to view where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
7101             *
7102             * <p>
7103             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7104             * </p>
7105             *
7106             * @param groupId the group ID
7107             * @param parentCategoryId the parent category ID
7108             * @param vocabularyId the vocabulary ID
7109             * @param start the lower bound of the range of asset categories
7110             * @param end the upper bound of the range of asset categories (not inclusive)
7111             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7112             * @return the ordered range of matching asset categories that the user has permission to view
7113             */
7114            @Override
7115            public List<AssetCategory> filterFindByG_P_V(long groupId,
7116                    long parentCategoryId, long vocabularyId, int start, int end,
7117                    OrderByComparator<AssetCategory> orderByComparator) {
7118                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7119                            return findByG_P_V(groupId, parentCategoryId, vocabularyId, start,
7120                                    end, orderByComparator);
7121                    }
7122    
7123                    StringBundler query = null;
7124    
7125                    if (orderByComparator != null) {
7126                            query = new StringBundler(5 +
7127                                            (orderByComparator.getOrderByFields().length * 3));
7128                    }
7129                    else {
7130                            query = new StringBundler(5);
7131                    }
7132    
7133                    if (getDB().isSupportsInlineDistinct()) {
7134                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
7135                    }
7136                    else {
7137                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7138                    }
7139    
7140                    query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
7141    
7142                    query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
7143    
7144                    query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
7145    
7146                    if (!getDB().isSupportsInlineDistinct()) {
7147                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7148                    }
7149    
7150                    if (orderByComparator != null) {
7151                            if (getDB().isSupportsInlineDistinct()) {
7152                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7153                                            orderByComparator, true);
7154                            }
7155                            else {
7156                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7157                                            orderByComparator, true);
7158                            }
7159                    }
7160                    else {
7161                            if (getDB().isSupportsInlineDistinct()) {
7162                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7163                            }
7164                            else {
7165                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
7166                            }
7167                    }
7168    
7169                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7170                                    AssetCategory.class.getName(),
7171                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7172    
7173                    Session session = null;
7174    
7175                    try {
7176                            session = openSession();
7177    
7178                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7179    
7180                            if (getDB().isSupportsInlineDistinct()) {
7181                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
7182                            }
7183                            else {
7184                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
7185                            }
7186    
7187                            QueryPos qPos = QueryPos.getInstance(q);
7188    
7189                            qPos.add(groupId);
7190    
7191                            qPos.add(parentCategoryId);
7192    
7193                            qPos.add(vocabularyId);
7194    
7195                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
7196                                    end);
7197                    }
7198                    catch (Exception e) {
7199                            throw processException(e);
7200                    }
7201                    finally {
7202                            closeSession(session);
7203                    }
7204            }
7205    
7206            /**
7207             * Returns the asset categories before and after the current asset category in the ordered set of asset categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
7208             *
7209             * @param categoryId the primary key of the current asset category
7210             * @param groupId the group ID
7211             * @param parentCategoryId the parent category ID
7212             * @param vocabularyId the vocabulary ID
7213             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7214             * @return the previous, current, and next asset category
7215             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
7216             */
7217            @Override
7218            public AssetCategory[] filterFindByG_P_V_PrevAndNext(long categoryId,
7219                    long groupId, long parentCategoryId, long vocabularyId,
7220                    OrderByComparator<AssetCategory> orderByComparator)
7221                    throws NoSuchCategoryException {
7222                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7223                            return findByG_P_V_PrevAndNext(categoryId, groupId,
7224                                    parentCategoryId, vocabularyId, orderByComparator);
7225                    }
7226    
7227                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
7228    
7229                    Session session = null;
7230    
7231                    try {
7232                            session = openSession();
7233    
7234                            AssetCategory[] array = new AssetCategoryImpl[3];
7235    
7236                            array[0] = filterGetByG_P_V_PrevAndNext(session, assetCategory,
7237                                            groupId, parentCategoryId, vocabularyId, orderByComparator,
7238                                            true);
7239    
7240                            array[1] = assetCategory;
7241    
7242                            array[2] = filterGetByG_P_V_PrevAndNext(session, assetCategory,
7243                                            groupId, parentCategoryId, vocabularyId, orderByComparator,
7244                                            false);
7245    
7246                            return array;
7247                    }
7248                    catch (Exception e) {
7249                            throw processException(e);
7250                    }
7251                    finally {
7252                            closeSession(session);
7253                    }
7254            }
7255    
7256            protected AssetCategory filterGetByG_P_V_PrevAndNext(Session session,
7257                    AssetCategory assetCategory, long groupId, long parentCategoryId,
7258                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator,
7259                    boolean previous) {
7260                    StringBundler query = null;
7261    
7262                    if (orderByComparator != null) {
7263                            query = new StringBundler(6 +
7264                                            (orderByComparator.getOrderByFields().length * 6));
7265                    }
7266                    else {
7267                            query = new StringBundler(3);
7268                    }
7269    
7270                    if (getDB().isSupportsInlineDistinct()) {
7271                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
7272                    }
7273                    else {
7274                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7275                    }
7276    
7277                    query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
7278    
7279                    query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
7280    
7281                    query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
7282    
7283                    if (!getDB().isSupportsInlineDistinct()) {
7284                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7285                    }
7286    
7287                    if (orderByComparator != null) {
7288                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7289    
7290                            if (orderByConditionFields.length > 0) {
7291                                    query.append(WHERE_AND);
7292                            }
7293    
7294                            for (int i = 0; i < orderByConditionFields.length; i++) {
7295                                    if (getDB().isSupportsInlineDistinct()) {
7296                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7297                                    }
7298                                    else {
7299                                            query.append(_ORDER_BY_ENTITY_TABLE);
7300                                    }
7301    
7302                                    query.append(orderByConditionFields[i]);
7303    
7304                                    if ((i + 1) < orderByConditionFields.length) {
7305                                            if (orderByComparator.isAscending() ^ previous) {
7306                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7307                                            }
7308                                            else {
7309                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7310                                            }
7311                                    }
7312                                    else {
7313                                            if (orderByComparator.isAscending() ^ previous) {
7314                                                    query.append(WHERE_GREATER_THAN);
7315                                            }
7316                                            else {
7317                                                    query.append(WHERE_LESSER_THAN);
7318                                            }
7319                                    }
7320                            }
7321    
7322                            query.append(ORDER_BY_CLAUSE);
7323    
7324                            String[] orderByFields = orderByComparator.getOrderByFields();
7325    
7326                            for (int i = 0; i < orderByFields.length; i++) {
7327                                    if (getDB().isSupportsInlineDistinct()) {
7328                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7329                                    }
7330                                    else {
7331                                            query.append(_ORDER_BY_ENTITY_TABLE);
7332                                    }
7333    
7334                                    query.append(orderByFields[i]);
7335    
7336                                    if ((i + 1) < orderByFields.length) {
7337                                            if (orderByComparator.isAscending() ^ previous) {
7338                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7339                                            }
7340                                            else {
7341                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7342                                            }
7343                                    }
7344                                    else {
7345                                            if (orderByComparator.isAscending() ^ previous) {
7346                                                    query.append(ORDER_BY_ASC);
7347                                            }
7348                                            else {
7349                                                    query.append(ORDER_BY_DESC);
7350                                            }
7351                                    }
7352                            }
7353                    }
7354                    else {
7355                            if (getDB().isSupportsInlineDistinct()) {
7356                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7357                            }
7358                            else {
7359                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
7360                            }
7361                    }
7362    
7363                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7364                                    AssetCategory.class.getName(),
7365                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7366    
7367                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
7368    
7369                    q.setFirstResult(0);
7370                    q.setMaxResults(2);
7371    
7372                    if (getDB().isSupportsInlineDistinct()) {
7373                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
7374                    }
7375                    else {
7376                            q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
7377                    }
7378    
7379                    QueryPos qPos = QueryPos.getInstance(q);
7380    
7381                    qPos.add(groupId);
7382    
7383                    qPos.add(parentCategoryId);
7384    
7385                    qPos.add(vocabularyId);
7386    
7387                    if (orderByComparator != null) {
7388                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
7389    
7390                            for (Object value : values) {
7391                                    qPos.add(value);
7392                            }
7393                    }
7394    
7395                    List<AssetCategory> list = q.list();
7396    
7397                    if (list.size() == 2) {
7398                            return list.get(1);
7399                    }
7400                    else {
7401                            return null;
7402                    }
7403            }
7404    
7405            /**
7406             * Removes all the asset categories where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63; from the database.
7407             *
7408             * @param groupId the group ID
7409             * @param parentCategoryId the parent category ID
7410             * @param vocabularyId the vocabulary ID
7411             */
7412            @Override
7413            public void removeByG_P_V(long groupId, long parentCategoryId,
7414                    long vocabularyId) {
7415                    for (AssetCategory assetCategory : findByG_P_V(groupId,
7416                                    parentCategoryId, vocabularyId, QueryUtil.ALL_POS,
7417                                    QueryUtil.ALL_POS, null)) {
7418                            remove(assetCategory);
7419                    }
7420            }
7421    
7422            /**
7423             * Returns the number of asset categories where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
7424             *
7425             * @param groupId the group ID
7426             * @param parentCategoryId the parent category ID
7427             * @param vocabularyId the vocabulary ID
7428             * @return the number of matching asset categories
7429             */
7430            @Override
7431            public int countByG_P_V(long groupId, long parentCategoryId,
7432                    long vocabularyId) {
7433                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_V;
7434    
7435                    Object[] finderArgs = new Object[] {
7436                                    groupId, parentCategoryId, vocabularyId
7437                            };
7438    
7439                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7440    
7441                    if (count == null) {
7442                            StringBundler query = new StringBundler(4);
7443    
7444                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
7445    
7446                            query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
7447    
7448                            query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
7449    
7450                            query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
7451    
7452                            String sql = query.toString();
7453    
7454                            Session session = null;
7455    
7456                            try {
7457                                    session = openSession();
7458    
7459                                    Query q = session.createQuery(sql);
7460    
7461                                    QueryPos qPos = QueryPos.getInstance(q);
7462    
7463                                    qPos.add(groupId);
7464    
7465                                    qPos.add(parentCategoryId);
7466    
7467                                    qPos.add(vocabularyId);
7468    
7469                                    count = (Long)q.uniqueResult();
7470    
7471                                    finderCache.putResult(finderPath, finderArgs, count);
7472                            }
7473                            catch (Exception e) {
7474                                    finderCache.removeResult(finderPath, finderArgs);
7475    
7476                                    throw processException(e);
7477                            }
7478                            finally {
7479                                    closeSession(session);
7480                            }
7481                    }
7482    
7483                    return count.intValue();
7484            }
7485    
7486            /**
7487             * Returns the number of asset categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and vocabularyId = &#63;.
7488             *
7489             * @param groupId the group ID
7490             * @param parentCategoryId the parent category ID
7491             * @param vocabularyId the vocabulary ID
7492             * @return the number of matching asset categories that the user has permission to view
7493             */
7494            @Override
7495            public int filterCountByG_P_V(long groupId, long parentCategoryId,
7496                    long vocabularyId) {
7497                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7498                            return countByG_P_V(groupId, parentCategoryId, vocabularyId);
7499                    }
7500    
7501                    StringBundler query = new StringBundler(4);
7502    
7503                    query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
7504    
7505                    query.append(_FINDER_COLUMN_G_P_V_GROUPID_2);
7506    
7507                    query.append(_FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2);
7508    
7509                    query.append(_FINDER_COLUMN_G_P_V_VOCABULARYID_2);
7510    
7511                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7512                                    AssetCategory.class.getName(),
7513                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7514    
7515                    Session session = null;
7516    
7517                    try {
7518                            session = openSession();
7519    
7520                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7521    
7522                            q.addScalar(COUNT_COLUMN_NAME,
7523                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7524    
7525                            QueryPos qPos = QueryPos.getInstance(q);
7526    
7527                            qPos.add(groupId);
7528    
7529                            qPos.add(parentCategoryId);
7530    
7531                            qPos.add(vocabularyId);
7532    
7533                            Long count = (Long)q.uniqueResult();
7534    
7535                            return count.intValue();
7536                    }
7537                    catch (Exception e) {
7538                            throw processException(e);
7539                    }
7540                    finally {
7541                            closeSession(session);
7542                    }
7543            }
7544    
7545            private static final String _FINDER_COLUMN_G_P_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
7546            private static final String _FINDER_COLUMN_G_P_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
7547            private static final String _FINDER_COLUMN_G_P_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
7548            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V =
7549                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7550                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
7551                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
7552                            "findByG_LikeN_V",
7553                            new String[] {
7554                                    Long.class.getName(), String.class.getName(),
7555                                    Long.class.getName(),
7556                                    
7557                            Integer.class.getName(), Integer.class.getName(),
7558                                    OrderByComparator.class.getName()
7559                            });
7560            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V =
7561                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7562                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
7563                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_LikeN_V",
7564                            new String[] {
7565                                    Long.class.getName(), String.class.getName(),
7566                                    Long.class.getName()
7567                            });
7568    
7569            /**
7570             * Returns all the asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
7571             *
7572             * @param groupId the group ID
7573             * @param name the name
7574             * @param vocabularyId the vocabulary ID
7575             * @return the matching asset categories
7576             */
7577            @Override
7578            public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
7579                    long vocabularyId) {
7580                    return findByG_LikeN_V(groupId, name, vocabularyId, QueryUtil.ALL_POS,
7581                            QueryUtil.ALL_POS, null);
7582            }
7583    
7584            /**
7585             * Returns a range of all the asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
7586             *
7587             * <p>
7588             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7589             * </p>
7590             *
7591             * @param groupId the group ID
7592             * @param name the name
7593             * @param vocabularyId the vocabulary ID
7594             * @param start the lower bound of the range of asset categories
7595             * @param end the upper bound of the range of asset categories (not inclusive)
7596             * @return the range of matching asset categories
7597             */
7598            @Override
7599            public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
7600                    long vocabularyId, int start, int end) {
7601                    return findByG_LikeN_V(groupId, name, vocabularyId, start, end, null);
7602            }
7603    
7604            /**
7605             * Returns an ordered range of all the asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
7606             *
7607             * <p>
7608             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7609             * </p>
7610             *
7611             * @param groupId the group ID
7612             * @param name the name
7613             * @param vocabularyId the vocabulary ID
7614             * @param start the lower bound of the range of asset categories
7615             * @param end the upper bound of the range of asset categories (not inclusive)
7616             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7617             * @return the ordered range of matching asset categories
7618             */
7619            @Override
7620            public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
7621                    long vocabularyId, int start, int end,
7622                    OrderByComparator<AssetCategory> orderByComparator) {
7623                    return findByG_LikeN_V(groupId, name, vocabularyId, start, end,
7624                            orderByComparator, true);
7625            }
7626    
7627            /**
7628             * Returns an ordered range of all the asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
7629             *
7630             * <p>
7631             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7632             * </p>
7633             *
7634             * @param groupId the group ID
7635             * @param name the name
7636             * @param vocabularyId the vocabulary ID
7637             * @param start the lower bound of the range of asset categories
7638             * @param end the upper bound of the range of asset categories (not inclusive)
7639             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7640             * @param retrieveFromCache whether to retrieve from the finder cache
7641             * @return the ordered range of matching asset categories
7642             */
7643            @Override
7644            public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
7645                    long vocabularyId, int start, int end,
7646                    OrderByComparator<AssetCategory> orderByComparator,
7647                    boolean retrieveFromCache) {
7648                    boolean pagination = true;
7649                    FinderPath finderPath = null;
7650                    Object[] finderArgs = null;
7651    
7652                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V;
7653                    finderArgs = new Object[] {
7654                                    groupId, name, vocabularyId,
7655                                    
7656                                    start, end, orderByComparator
7657                            };
7658    
7659                    List<AssetCategory> list = null;
7660    
7661                    if (retrieveFromCache) {
7662                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
7663                                            finderArgs, this);
7664    
7665                            if ((list != null) && !list.isEmpty()) {
7666                                    for (AssetCategory assetCategory : list) {
7667                                            if ((groupId != assetCategory.getGroupId()) ||
7668                                                            !StringUtil.wildcardMatches(
7669                                                                    assetCategory.getName(), name,
7670                                                                    CharPool.UNDERLINE, CharPool.PERCENT,
7671                                                                    CharPool.BACK_SLASH, false) ||
7672                                                            (vocabularyId != assetCategory.getVocabularyId())) {
7673                                                    list = null;
7674    
7675                                                    break;
7676                                            }
7677                                    }
7678                            }
7679                    }
7680    
7681                    if (list == null) {
7682                            StringBundler query = null;
7683    
7684                            if (orderByComparator != null) {
7685                                    query = new StringBundler(5 +
7686                                                    (orderByComparator.getOrderByFields().length * 3));
7687                            }
7688                            else {
7689                                    query = new StringBundler(5);
7690                            }
7691    
7692                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
7693    
7694                            query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
7695    
7696                            boolean bindName = false;
7697    
7698                            if (name == null) {
7699                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
7700                            }
7701                            else if (name.equals(StringPool.BLANK)) {
7702                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
7703                            }
7704                            else {
7705                                    bindName = true;
7706    
7707                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
7708                            }
7709    
7710                            query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
7711    
7712                            if (orderByComparator != null) {
7713                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7714                                            orderByComparator);
7715                            }
7716                            else
7717                             if (pagination) {
7718                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
7719                            }
7720    
7721                            String sql = query.toString();
7722    
7723                            Session session = null;
7724    
7725                            try {
7726                                    session = openSession();
7727    
7728                                    Query q = session.createQuery(sql);
7729    
7730                                    QueryPos qPos = QueryPos.getInstance(q);
7731    
7732                                    qPos.add(groupId);
7733    
7734                                    if (bindName) {
7735                                            qPos.add(StringUtil.toLowerCase(name));
7736                                    }
7737    
7738                                    qPos.add(vocabularyId);
7739    
7740                                    if (!pagination) {
7741                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
7742                                                            start, end, false);
7743    
7744                                            Collections.sort(list);
7745    
7746                                            list = Collections.unmodifiableList(list);
7747                                    }
7748                                    else {
7749                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
7750                                                            start, end);
7751                                    }
7752    
7753                                    cacheResult(list);
7754    
7755                                    finderCache.putResult(finderPath, finderArgs, list);
7756                            }
7757                            catch (Exception e) {
7758                                    finderCache.removeResult(finderPath, finderArgs);
7759    
7760                                    throw processException(e);
7761                            }
7762                            finally {
7763                                    closeSession(session);
7764                            }
7765                    }
7766    
7767                    return list;
7768            }
7769    
7770            /**
7771             * Returns the first asset category in the ordered set where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
7772             *
7773             * @param groupId the group ID
7774             * @param name the name
7775             * @param vocabularyId the vocabulary ID
7776             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7777             * @return the first matching asset category
7778             * @throws NoSuchCategoryException if a matching asset category could not be found
7779             */
7780            @Override
7781            public AssetCategory findByG_LikeN_V_First(long groupId, String name,
7782                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator)
7783                    throws NoSuchCategoryException {
7784                    AssetCategory assetCategory = fetchByG_LikeN_V_First(groupId, name,
7785                                    vocabularyId, orderByComparator);
7786    
7787                    if (assetCategory != null) {
7788                            return assetCategory;
7789                    }
7790    
7791                    StringBundler msg = new StringBundler(8);
7792    
7793                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7794    
7795                    msg.append("groupId=");
7796                    msg.append(groupId);
7797    
7798                    msg.append(", name=");
7799                    msg.append(name);
7800    
7801                    msg.append(", vocabularyId=");
7802                    msg.append(vocabularyId);
7803    
7804                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7805    
7806                    throw new NoSuchCategoryException(msg.toString());
7807            }
7808    
7809            /**
7810             * Returns the first asset category in the ordered set where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
7811             *
7812             * @param groupId the group ID
7813             * @param name the name
7814             * @param vocabularyId the vocabulary ID
7815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7816             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
7817             */
7818            @Override
7819            public AssetCategory fetchByG_LikeN_V_First(long groupId, String name,
7820                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator) {
7821                    List<AssetCategory> list = findByG_LikeN_V(groupId, name, vocabularyId,
7822                                    0, 1, orderByComparator);
7823    
7824                    if (!list.isEmpty()) {
7825                            return list.get(0);
7826                    }
7827    
7828                    return null;
7829            }
7830    
7831            /**
7832             * Returns the last asset category in the ordered set where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
7833             *
7834             * @param groupId the group ID
7835             * @param name the name
7836             * @param vocabularyId the vocabulary ID
7837             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7838             * @return the last matching asset category
7839             * @throws NoSuchCategoryException if a matching asset category could not be found
7840             */
7841            @Override
7842            public AssetCategory findByG_LikeN_V_Last(long groupId, String name,
7843                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator)
7844                    throws NoSuchCategoryException {
7845                    AssetCategory assetCategory = fetchByG_LikeN_V_Last(groupId, name,
7846                                    vocabularyId, orderByComparator);
7847    
7848                    if (assetCategory != null) {
7849                            return assetCategory;
7850                    }
7851    
7852                    StringBundler msg = new StringBundler(8);
7853    
7854                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7855    
7856                    msg.append("groupId=");
7857                    msg.append(groupId);
7858    
7859                    msg.append(", name=");
7860                    msg.append(name);
7861    
7862                    msg.append(", vocabularyId=");
7863                    msg.append(vocabularyId);
7864    
7865                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7866    
7867                    throw new NoSuchCategoryException(msg.toString());
7868            }
7869    
7870            /**
7871             * Returns the last asset category in the ordered set where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
7872             *
7873             * @param groupId the group ID
7874             * @param name the name
7875             * @param vocabularyId the vocabulary ID
7876             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7877             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
7878             */
7879            @Override
7880            public AssetCategory fetchByG_LikeN_V_Last(long groupId, String name,
7881                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator) {
7882                    int count = countByG_LikeN_V(groupId, name, vocabularyId);
7883    
7884                    if (count == 0) {
7885                            return null;
7886                    }
7887    
7888                    List<AssetCategory> list = findByG_LikeN_V(groupId, name, vocabularyId,
7889                                    count - 1, count, orderByComparator);
7890    
7891                    if (!list.isEmpty()) {
7892                            return list.get(0);
7893                    }
7894    
7895                    return null;
7896            }
7897    
7898            /**
7899             * Returns the asset categories before and after the current asset category in the ordered set where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
7900             *
7901             * @param categoryId the primary key of the current asset category
7902             * @param groupId the group ID
7903             * @param name the name
7904             * @param vocabularyId the vocabulary ID
7905             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7906             * @return the previous, current, and next asset category
7907             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
7908             */
7909            @Override
7910            public AssetCategory[] findByG_LikeN_V_PrevAndNext(long categoryId,
7911                    long groupId, String name, long vocabularyId,
7912                    OrderByComparator<AssetCategory> orderByComparator)
7913                    throws NoSuchCategoryException {
7914                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
7915    
7916                    Session session = null;
7917    
7918                    try {
7919                            session = openSession();
7920    
7921                            AssetCategory[] array = new AssetCategoryImpl[3];
7922    
7923                            array[0] = getByG_LikeN_V_PrevAndNext(session, assetCategory,
7924                                            groupId, name, vocabularyId, orderByComparator, true);
7925    
7926                            array[1] = assetCategory;
7927    
7928                            array[2] = getByG_LikeN_V_PrevAndNext(session, assetCategory,
7929                                            groupId, name, vocabularyId, orderByComparator, false);
7930    
7931                            return array;
7932                    }
7933                    catch (Exception e) {
7934                            throw processException(e);
7935                    }
7936                    finally {
7937                            closeSession(session);
7938                    }
7939            }
7940    
7941            protected AssetCategory getByG_LikeN_V_PrevAndNext(Session session,
7942                    AssetCategory assetCategory, long groupId, String name,
7943                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator,
7944                    boolean previous) {
7945                    StringBundler query = null;
7946    
7947                    if (orderByComparator != null) {
7948                            query = new StringBundler(6 +
7949                                            (orderByComparator.getOrderByFields().length * 6));
7950                    }
7951                    else {
7952                            query = new StringBundler(3);
7953                    }
7954    
7955                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
7956    
7957                    query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
7958    
7959                    boolean bindName = false;
7960    
7961                    if (name == null) {
7962                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
7963                    }
7964                    else if (name.equals(StringPool.BLANK)) {
7965                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
7966                    }
7967                    else {
7968                            bindName = true;
7969    
7970                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
7971                    }
7972    
7973                    query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
7974    
7975                    if (orderByComparator != null) {
7976                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7977    
7978                            if (orderByConditionFields.length > 0) {
7979                                    query.append(WHERE_AND);
7980                            }
7981    
7982                            for (int i = 0; i < orderByConditionFields.length; i++) {
7983                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7984                                    query.append(orderByConditionFields[i]);
7985    
7986                                    if ((i + 1) < orderByConditionFields.length) {
7987                                            if (orderByComparator.isAscending() ^ previous) {
7988                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7989                                            }
7990                                            else {
7991                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7992                                            }
7993                                    }
7994                                    else {
7995                                            if (orderByComparator.isAscending() ^ previous) {
7996                                                    query.append(WHERE_GREATER_THAN);
7997                                            }
7998                                            else {
7999                                                    query.append(WHERE_LESSER_THAN);
8000                                            }
8001                                    }
8002                            }
8003    
8004                            query.append(ORDER_BY_CLAUSE);
8005    
8006                            String[] orderByFields = orderByComparator.getOrderByFields();
8007    
8008                            for (int i = 0; i < orderByFields.length; i++) {
8009                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8010                                    query.append(orderByFields[i]);
8011    
8012                                    if ((i + 1) < orderByFields.length) {
8013                                            if (orderByComparator.isAscending() ^ previous) {
8014                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8015                                            }
8016                                            else {
8017                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8018                                            }
8019                                    }
8020                                    else {
8021                                            if (orderByComparator.isAscending() ^ previous) {
8022                                                    query.append(ORDER_BY_ASC);
8023                                            }
8024                                            else {
8025                                                    query.append(ORDER_BY_DESC);
8026                                            }
8027                                    }
8028                            }
8029                    }
8030                    else {
8031                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8032                    }
8033    
8034                    String sql = query.toString();
8035    
8036                    Query q = session.createQuery(sql);
8037    
8038                    q.setFirstResult(0);
8039                    q.setMaxResults(2);
8040    
8041                    QueryPos qPos = QueryPos.getInstance(q);
8042    
8043                    qPos.add(groupId);
8044    
8045                    if (bindName) {
8046                            qPos.add(StringUtil.toLowerCase(name));
8047                    }
8048    
8049                    qPos.add(vocabularyId);
8050    
8051                    if (orderByComparator != null) {
8052                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
8053    
8054                            for (Object value : values) {
8055                                    qPos.add(value);
8056                            }
8057                    }
8058    
8059                    List<AssetCategory> list = q.list();
8060    
8061                    if (list.size() == 2) {
8062                            return list.get(1);
8063                    }
8064                    else {
8065                            return null;
8066                    }
8067            }
8068    
8069            /**
8070             * Returns all the asset categories that the user has permission to view where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
8071             *
8072             * @param groupId the group ID
8073             * @param name the name
8074             * @param vocabularyId the vocabulary ID
8075             * @return the matching asset categories that the user has permission to view
8076             */
8077            @Override
8078            public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
8079                    long vocabularyId) {
8080                    return filterFindByG_LikeN_V(groupId, name, vocabularyId,
8081                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8082            }
8083    
8084            /**
8085             * Returns a range of all the asset categories that the user has permission to view where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
8086             *
8087             * <p>
8088             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8089             * </p>
8090             *
8091             * @param groupId the group ID
8092             * @param name the name
8093             * @param vocabularyId the vocabulary ID
8094             * @param start the lower bound of the range of asset categories
8095             * @param end the upper bound of the range of asset categories (not inclusive)
8096             * @return the range of matching asset categories that the user has permission to view
8097             */
8098            @Override
8099            public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
8100                    long vocabularyId, int start, int end) {
8101                    return filterFindByG_LikeN_V(groupId, name, vocabularyId, start, end,
8102                            null);
8103            }
8104    
8105            /**
8106             * Returns an ordered range of all the asset categories that the user has permissions to view where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
8107             *
8108             * <p>
8109             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8110             * </p>
8111             *
8112             * @param groupId the group ID
8113             * @param name the name
8114             * @param vocabularyId the vocabulary ID
8115             * @param start the lower bound of the range of asset categories
8116             * @param end the upper bound of the range of asset categories (not inclusive)
8117             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8118             * @return the ordered range of matching asset categories that the user has permission to view
8119             */
8120            @Override
8121            public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
8122                    long vocabularyId, int start, int end,
8123                    OrderByComparator<AssetCategory> orderByComparator) {
8124                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8125                            return findByG_LikeN_V(groupId, name, vocabularyId, start, end,
8126                                    orderByComparator);
8127                    }
8128    
8129                    StringBundler query = null;
8130    
8131                    if (orderByComparator != null) {
8132                            query = new StringBundler(5 +
8133                                            (orderByComparator.getOrderByFields().length * 3));
8134                    }
8135                    else {
8136                            query = new StringBundler(5);
8137                    }
8138    
8139                    if (getDB().isSupportsInlineDistinct()) {
8140                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
8141                    }
8142                    else {
8143                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8144                    }
8145    
8146                    query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
8147    
8148                    boolean bindName = false;
8149    
8150                    if (name == null) {
8151                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
8152                    }
8153                    else if (name.equals(StringPool.BLANK)) {
8154                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
8155                    }
8156                    else {
8157                            bindName = true;
8158    
8159                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
8160                    }
8161    
8162                    query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
8163    
8164                    if (!getDB().isSupportsInlineDistinct()) {
8165                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
8166                    }
8167    
8168                    if (orderByComparator != null) {
8169                            if (getDB().isSupportsInlineDistinct()) {
8170                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8171                                            orderByComparator, true);
8172                            }
8173                            else {
8174                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8175                                            orderByComparator, true);
8176                            }
8177                    }
8178                    else {
8179                            if (getDB().isSupportsInlineDistinct()) {
8180                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8181                            }
8182                            else {
8183                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
8184                            }
8185                    }
8186    
8187                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8188                                    AssetCategory.class.getName(),
8189                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8190    
8191                    Session session = null;
8192    
8193                    try {
8194                            session = openSession();
8195    
8196                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8197    
8198                            if (getDB().isSupportsInlineDistinct()) {
8199                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
8200                            }
8201                            else {
8202                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
8203                            }
8204    
8205                            QueryPos qPos = QueryPos.getInstance(q);
8206    
8207                            qPos.add(groupId);
8208    
8209                            if (bindName) {
8210                                    qPos.add(StringUtil.toLowerCase(name));
8211                            }
8212    
8213                            qPos.add(vocabularyId);
8214    
8215                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
8216                                    end);
8217                    }
8218                    catch (Exception e) {
8219                            throw processException(e);
8220                    }
8221                    finally {
8222                            closeSession(session);
8223                    }
8224            }
8225    
8226            /**
8227             * Returns the asset categories before and after the current asset category in the ordered set of asset categories that the user has permission to view where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
8228             *
8229             * @param categoryId the primary key of the current asset category
8230             * @param groupId the group ID
8231             * @param name the name
8232             * @param vocabularyId the vocabulary ID
8233             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8234             * @return the previous, current, and next asset category
8235             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
8236             */
8237            @Override
8238            public AssetCategory[] filterFindByG_LikeN_V_PrevAndNext(long categoryId,
8239                    long groupId, String name, long vocabularyId,
8240                    OrderByComparator<AssetCategory> orderByComparator)
8241                    throws NoSuchCategoryException {
8242                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8243                            return findByG_LikeN_V_PrevAndNext(categoryId, groupId, name,
8244                                    vocabularyId, orderByComparator);
8245                    }
8246    
8247                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
8248    
8249                    Session session = null;
8250    
8251                    try {
8252                            session = openSession();
8253    
8254                            AssetCategory[] array = new AssetCategoryImpl[3];
8255    
8256                            array[0] = filterGetByG_LikeN_V_PrevAndNext(session, assetCategory,
8257                                            groupId, name, vocabularyId, orderByComparator, true);
8258    
8259                            array[1] = assetCategory;
8260    
8261                            array[2] = filterGetByG_LikeN_V_PrevAndNext(session, assetCategory,
8262                                            groupId, name, vocabularyId, orderByComparator, false);
8263    
8264                            return array;
8265                    }
8266                    catch (Exception e) {
8267                            throw processException(e);
8268                    }
8269                    finally {
8270                            closeSession(session);
8271                    }
8272            }
8273    
8274            protected AssetCategory filterGetByG_LikeN_V_PrevAndNext(Session session,
8275                    AssetCategory assetCategory, long groupId, String name,
8276                    long vocabularyId, OrderByComparator<AssetCategory> orderByComparator,
8277                    boolean previous) {
8278                    StringBundler query = null;
8279    
8280                    if (orderByComparator != null) {
8281                            query = new StringBundler(6 +
8282                                            (orderByComparator.getOrderByFields().length * 6));
8283                    }
8284                    else {
8285                            query = new StringBundler(3);
8286                    }
8287    
8288                    if (getDB().isSupportsInlineDistinct()) {
8289                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
8290                    }
8291                    else {
8292                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8293                    }
8294    
8295                    query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
8296    
8297                    boolean bindName = false;
8298    
8299                    if (name == null) {
8300                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
8301                    }
8302                    else if (name.equals(StringPool.BLANK)) {
8303                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
8304                    }
8305                    else {
8306                            bindName = true;
8307    
8308                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
8309                    }
8310    
8311                    query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
8312    
8313                    if (!getDB().isSupportsInlineDistinct()) {
8314                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
8315                    }
8316    
8317                    if (orderByComparator != null) {
8318                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8319    
8320                            if (orderByConditionFields.length > 0) {
8321                                    query.append(WHERE_AND);
8322                            }
8323    
8324                            for (int i = 0; i < orderByConditionFields.length; i++) {
8325                                    if (getDB().isSupportsInlineDistinct()) {
8326                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8327                                    }
8328                                    else {
8329                                            query.append(_ORDER_BY_ENTITY_TABLE);
8330                                    }
8331    
8332                                    query.append(orderByConditionFields[i]);
8333    
8334                                    if ((i + 1) < orderByConditionFields.length) {
8335                                            if (orderByComparator.isAscending() ^ previous) {
8336                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8337                                            }
8338                                            else {
8339                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8340                                            }
8341                                    }
8342                                    else {
8343                                            if (orderByComparator.isAscending() ^ previous) {
8344                                                    query.append(WHERE_GREATER_THAN);
8345                                            }
8346                                            else {
8347                                                    query.append(WHERE_LESSER_THAN);
8348                                            }
8349                                    }
8350                            }
8351    
8352                            query.append(ORDER_BY_CLAUSE);
8353    
8354                            String[] orderByFields = orderByComparator.getOrderByFields();
8355    
8356                            for (int i = 0; i < orderByFields.length; i++) {
8357                                    if (getDB().isSupportsInlineDistinct()) {
8358                                            query.append(_ORDER_BY_ENTITY_ALIAS);
8359                                    }
8360                                    else {
8361                                            query.append(_ORDER_BY_ENTITY_TABLE);
8362                                    }
8363    
8364                                    query.append(orderByFields[i]);
8365    
8366                                    if ((i + 1) < orderByFields.length) {
8367                                            if (orderByComparator.isAscending() ^ previous) {
8368                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8369                                            }
8370                                            else {
8371                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8372                                            }
8373                                    }
8374                                    else {
8375                                            if (orderByComparator.isAscending() ^ previous) {
8376                                                    query.append(ORDER_BY_ASC);
8377                                            }
8378                                            else {
8379                                                    query.append(ORDER_BY_DESC);
8380                                            }
8381                                    }
8382                            }
8383                    }
8384                    else {
8385                            if (getDB().isSupportsInlineDistinct()) {
8386                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8387                            }
8388                            else {
8389                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
8390                            }
8391                    }
8392    
8393                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8394                                    AssetCategory.class.getName(),
8395                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8396    
8397                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
8398    
8399                    q.setFirstResult(0);
8400                    q.setMaxResults(2);
8401    
8402                    if (getDB().isSupportsInlineDistinct()) {
8403                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
8404                    }
8405                    else {
8406                            q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
8407                    }
8408    
8409                    QueryPos qPos = QueryPos.getInstance(q);
8410    
8411                    qPos.add(groupId);
8412    
8413                    if (bindName) {
8414                            qPos.add(StringUtil.toLowerCase(name));
8415                    }
8416    
8417                    qPos.add(vocabularyId);
8418    
8419                    if (orderByComparator != null) {
8420                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
8421    
8422                            for (Object value : values) {
8423                                    qPos.add(value);
8424                            }
8425                    }
8426    
8427                    List<AssetCategory> list = q.list();
8428    
8429                    if (list.size() == 2) {
8430                            return list.get(1);
8431                    }
8432                    else {
8433                            return null;
8434                    }
8435            }
8436    
8437            /**
8438             * Returns all the asset categories that the user has permission to view where groupId = &#63; and name LIKE &#63; and vocabularyId = any &#63;.
8439             *
8440             * @param groupId the group ID
8441             * @param name the name
8442             * @param vocabularyIds the vocabulary IDs
8443             * @return the matching asset categories that the user has permission to view
8444             */
8445            @Override
8446            public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
8447                    long[] vocabularyIds) {
8448                    return filterFindByG_LikeN_V(groupId, name, vocabularyIds,
8449                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8450            }
8451    
8452            /**
8453             * Returns a range of all the asset categories that the user has permission to view where groupId = &#63; and name LIKE &#63; and vocabularyId = any &#63;.
8454             *
8455             * <p>
8456             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8457             * </p>
8458             *
8459             * @param groupId the group ID
8460             * @param name the name
8461             * @param vocabularyIds the vocabulary IDs
8462             * @param start the lower bound of the range of asset categories
8463             * @param end the upper bound of the range of asset categories (not inclusive)
8464             * @return the range of matching asset categories that the user has permission to view
8465             */
8466            @Override
8467            public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
8468                    long[] vocabularyIds, int start, int end) {
8469                    return filterFindByG_LikeN_V(groupId, name, vocabularyIds, start, end,
8470                            null);
8471            }
8472    
8473            /**
8474             * Returns an ordered range of all the asset categories that the user has permission to view where groupId = &#63; and name LIKE &#63; and vocabularyId = any &#63;.
8475             *
8476             * <p>
8477             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8478             * </p>
8479             *
8480             * @param groupId the group ID
8481             * @param name the name
8482             * @param vocabularyIds the vocabulary IDs
8483             * @param start the lower bound of the range of asset categories
8484             * @param end the upper bound of the range of asset categories (not inclusive)
8485             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8486             * @return the ordered range of matching asset categories that the user has permission to view
8487             */
8488            @Override
8489            public List<AssetCategory> filterFindByG_LikeN_V(long groupId, String name,
8490                    long[] vocabularyIds, int start, int end,
8491                    OrderByComparator<AssetCategory> orderByComparator) {
8492                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8493                            return findByG_LikeN_V(groupId, name, vocabularyIds, start, end,
8494                                    orderByComparator);
8495                    }
8496    
8497                    if (vocabularyIds == null) {
8498                            vocabularyIds = new long[0];
8499                    }
8500                    else if (vocabularyIds.length > 1) {
8501                            vocabularyIds = ArrayUtil.unique(vocabularyIds);
8502    
8503                            Arrays.sort(vocabularyIds);
8504                    }
8505    
8506                    StringBundler query = new StringBundler();
8507    
8508                    if (getDB().isSupportsInlineDistinct()) {
8509                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
8510                    }
8511                    else {
8512                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8513                    }
8514    
8515                    query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
8516    
8517                    boolean bindName = false;
8518    
8519                    if (name == null) {
8520                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
8521                    }
8522                    else if (name.equals(StringPool.BLANK)) {
8523                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
8524                    }
8525                    else {
8526                            bindName = true;
8527    
8528                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
8529                    }
8530    
8531                    if (vocabularyIds.length > 0) {
8532                            query.append(StringPool.OPEN_PARENTHESIS);
8533    
8534                            query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_7);
8535    
8536                            query.append(StringUtil.merge(vocabularyIds));
8537    
8538                            query.append(StringPool.CLOSE_PARENTHESIS);
8539    
8540                            query.append(StringPool.CLOSE_PARENTHESIS);
8541                    }
8542    
8543                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
8544                            query.index() - 1);
8545    
8546                    if (!getDB().isSupportsInlineDistinct()) {
8547                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
8548                    }
8549    
8550                    if (orderByComparator != null) {
8551                            if (getDB().isSupportsInlineDistinct()) {
8552                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8553                                            orderByComparator, true);
8554                            }
8555                            else {
8556                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8557                                            orderByComparator, true);
8558                            }
8559                    }
8560                    else {
8561                            if (getDB().isSupportsInlineDistinct()) {
8562                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8563                            }
8564                            else {
8565                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
8566                            }
8567                    }
8568    
8569                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8570                                    AssetCategory.class.getName(),
8571                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8572    
8573                    Session session = null;
8574    
8575                    try {
8576                            session = openSession();
8577    
8578                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8579    
8580                            if (getDB().isSupportsInlineDistinct()) {
8581                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
8582                            }
8583                            else {
8584                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
8585                            }
8586    
8587                            QueryPos qPos = QueryPos.getInstance(q);
8588    
8589                            qPos.add(groupId);
8590    
8591                            if (bindName) {
8592                                    qPos.add(StringUtil.toLowerCase(name));
8593                            }
8594    
8595                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
8596                                    end);
8597                    }
8598                    catch (Exception e) {
8599                            throw processException(e);
8600                    }
8601                    finally {
8602                            closeSession(session);
8603                    }
8604            }
8605    
8606            /**
8607             * Returns all the asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = any &#63;.
8608             *
8609             * <p>
8610             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8611             * </p>
8612             *
8613             * @param groupId the group ID
8614             * @param name the name
8615             * @param vocabularyIds the vocabulary IDs
8616             * @return the matching asset categories
8617             */
8618            @Override
8619            public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
8620                    long[] vocabularyIds) {
8621                    return findByG_LikeN_V(groupId, name, vocabularyIds, QueryUtil.ALL_POS,
8622                            QueryUtil.ALL_POS, null);
8623            }
8624    
8625            /**
8626             * Returns a range of all the asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = any &#63;.
8627             *
8628             * <p>
8629             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8630             * </p>
8631             *
8632             * @param groupId the group ID
8633             * @param name the name
8634             * @param vocabularyIds the vocabulary IDs
8635             * @param start the lower bound of the range of asset categories
8636             * @param end the upper bound of the range of asset categories (not inclusive)
8637             * @return the range of matching asset categories
8638             */
8639            @Override
8640            public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
8641                    long[] vocabularyIds, int start, int end) {
8642                    return findByG_LikeN_V(groupId, name, vocabularyIds, start, end, null);
8643            }
8644    
8645            /**
8646             * Returns an ordered range of all the asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = any &#63;.
8647             *
8648             * <p>
8649             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8650             * </p>
8651             *
8652             * @param groupId the group ID
8653             * @param name the name
8654             * @param vocabularyIds the vocabulary IDs
8655             * @param start the lower bound of the range of asset categories
8656             * @param end the upper bound of the range of asset categories (not inclusive)
8657             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8658             * @return the ordered range of matching asset categories
8659             */
8660            @Override
8661            public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
8662                    long[] vocabularyIds, int start, int end,
8663                    OrderByComparator<AssetCategory> orderByComparator) {
8664                    return findByG_LikeN_V(groupId, name, vocabularyIds, start, end,
8665                            orderByComparator, true);
8666            }
8667    
8668            /**
8669             * Returns an ordered range of all the asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;, optionally using the finder cache.
8670             *
8671             * <p>
8672             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8673             * </p>
8674             *
8675             * @param groupId the group ID
8676             * @param name the name
8677             * @param vocabularyId the vocabulary ID
8678             * @param start the lower bound of the range of asset categories
8679             * @param end the upper bound of the range of asset categories (not inclusive)
8680             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8681             * @param retrieveFromCache whether to retrieve from the finder cache
8682             * @return the ordered range of matching asset categories
8683             */
8684            @Override
8685            public List<AssetCategory> findByG_LikeN_V(long groupId, String name,
8686                    long[] vocabularyIds, int start, int end,
8687                    OrderByComparator<AssetCategory> orderByComparator,
8688                    boolean retrieveFromCache) {
8689                    if (vocabularyIds == null) {
8690                            vocabularyIds = new long[0];
8691                    }
8692                    else if (vocabularyIds.length > 1) {
8693                            vocabularyIds = ArrayUtil.unique(vocabularyIds);
8694    
8695                            Arrays.sort(vocabularyIds);
8696                    }
8697    
8698                    if (vocabularyIds.length == 1) {
8699                            return findByG_LikeN_V(groupId, name, vocabularyIds[0], start, end,
8700                                    orderByComparator);
8701                    }
8702    
8703                    boolean pagination = true;
8704                    Object[] finderArgs = null;
8705    
8706                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8707                                    (orderByComparator == null)) {
8708                            pagination = false;
8709                            finderArgs = new Object[] {
8710                                            groupId, name, StringUtil.merge(vocabularyIds)
8711                                    };
8712                    }
8713                    else {
8714                            finderArgs = new Object[] {
8715                                            groupId, name, StringUtil.merge(vocabularyIds),
8716                                            
8717                                            start, end, orderByComparator
8718                                    };
8719                    }
8720    
8721                    List<AssetCategory> list = null;
8722    
8723                    if (retrieveFromCache) {
8724                            list = (List<AssetCategory>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V,
8725                                            finderArgs, this);
8726    
8727                            if ((list != null) && !list.isEmpty()) {
8728                                    for (AssetCategory assetCategory : list) {
8729                                            if ((groupId != assetCategory.getGroupId()) ||
8730                                                            !StringUtil.wildcardMatches(
8731                                                                    assetCategory.getName(), name,
8732                                                                    CharPool.UNDERLINE, CharPool.PERCENT,
8733                                                                    CharPool.BACK_SLASH, false) ||
8734                                                            !ArrayUtil.contains(vocabularyIds,
8735                                                                    assetCategory.getVocabularyId())) {
8736                                                    list = null;
8737    
8738                                                    break;
8739                                            }
8740                                    }
8741                            }
8742                    }
8743    
8744                    if (list == null) {
8745                            StringBundler query = new StringBundler();
8746    
8747                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
8748    
8749                            query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
8750    
8751                            boolean bindName = false;
8752    
8753                            if (name == null) {
8754                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
8755                            }
8756                            else if (name.equals(StringPool.BLANK)) {
8757                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
8758                            }
8759                            else {
8760                                    bindName = true;
8761    
8762                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
8763                            }
8764    
8765                            if (vocabularyIds.length > 0) {
8766                                    query.append(StringPool.OPEN_PARENTHESIS);
8767    
8768                                    query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_7);
8769    
8770                                    query.append(StringUtil.merge(vocabularyIds));
8771    
8772                                    query.append(StringPool.CLOSE_PARENTHESIS);
8773    
8774                                    query.append(StringPool.CLOSE_PARENTHESIS);
8775                            }
8776    
8777                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8778                                                    1)), query.index() - 1);
8779    
8780                            if (orderByComparator != null) {
8781                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8782                                            orderByComparator);
8783                            }
8784                            else
8785                             if (pagination) {
8786                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
8787                            }
8788    
8789                            String sql = query.toString();
8790    
8791                            Session session = null;
8792    
8793                            try {
8794                                    session = openSession();
8795    
8796                                    Query q = session.createQuery(sql);
8797    
8798                                    QueryPos qPos = QueryPos.getInstance(q);
8799    
8800                                    qPos.add(groupId);
8801    
8802                                    if (bindName) {
8803                                            qPos.add(StringUtil.toLowerCase(name));
8804                                    }
8805    
8806                                    if (!pagination) {
8807                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
8808                                                            start, end, false);
8809    
8810                                            Collections.sort(list);
8811    
8812                                            list = Collections.unmodifiableList(list);
8813                                    }
8814                                    else {
8815                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
8816                                                            start, end);
8817                                    }
8818    
8819                                    cacheResult(list);
8820    
8821                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V,
8822                                            finderArgs, list);
8823                            }
8824                            catch (Exception e) {
8825                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN_V,
8826                                            finderArgs);
8827    
8828                                    throw processException(e);
8829                            }
8830                            finally {
8831                                    closeSession(session);
8832                            }
8833                    }
8834    
8835                    return list;
8836            }
8837    
8838            /**
8839             * Removes all the asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63; from the database.
8840             *
8841             * @param groupId the group ID
8842             * @param name the name
8843             * @param vocabularyId the vocabulary ID
8844             */
8845            @Override
8846            public void removeByG_LikeN_V(long groupId, String name, long vocabularyId) {
8847                    for (AssetCategory assetCategory : findByG_LikeN_V(groupId, name,
8848                                    vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8849                            remove(assetCategory);
8850                    }
8851            }
8852    
8853            /**
8854             * Returns the number of asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
8855             *
8856             * @param groupId the group ID
8857             * @param name the name
8858             * @param vocabularyId the vocabulary ID
8859             * @return the number of matching asset categories
8860             */
8861            @Override
8862            public int countByG_LikeN_V(long groupId, String name, long vocabularyId) {
8863                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V;
8864    
8865                    Object[] finderArgs = new Object[] { groupId, name, vocabularyId };
8866    
8867                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8868    
8869                    if (count == null) {
8870                            StringBundler query = new StringBundler(4);
8871    
8872                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
8873    
8874                            query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
8875    
8876                            boolean bindName = false;
8877    
8878                            if (name == null) {
8879                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
8880                            }
8881                            else if (name.equals(StringPool.BLANK)) {
8882                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
8883                            }
8884                            else {
8885                                    bindName = true;
8886    
8887                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
8888                            }
8889    
8890                            query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
8891    
8892                            String sql = query.toString();
8893    
8894                            Session session = null;
8895    
8896                            try {
8897                                    session = openSession();
8898    
8899                                    Query q = session.createQuery(sql);
8900    
8901                                    QueryPos qPos = QueryPos.getInstance(q);
8902    
8903                                    qPos.add(groupId);
8904    
8905                                    if (bindName) {
8906                                            qPos.add(StringUtil.toLowerCase(name));
8907                                    }
8908    
8909                                    qPos.add(vocabularyId);
8910    
8911                                    count = (Long)q.uniqueResult();
8912    
8913                                    finderCache.putResult(finderPath, finderArgs, count);
8914                            }
8915                            catch (Exception e) {
8916                                    finderCache.removeResult(finderPath, finderArgs);
8917    
8918                                    throw processException(e);
8919                            }
8920                            finally {
8921                                    closeSession(session);
8922                            }
8923                    }
8924    
8925                    return count.intValue();
8926            }
8927    
8928            /**
8929             * Returns the number of asset categories where groupId = &#63; and name LIKE &#63; and vocabularyId = any &#63;.
8930             *
8931             * @param groupId the group ID
8932             * @param name the name
8933             * @param vocabularyIds the vocabulary IDs
8934             * @return the number of matching asset categories
8935             */
8936            @Override
8937            public int countByG_LikeN_V(long groupId, String name, long[] vocabularyIds) {
8938                    if (vocabularyIds == null) {
8939                            vocabularyIds = new long[0];
8940                    }
8941                    else if (vocabularyIds.length > 1) {
8942                            vocabularyIds = ArrayUtil.unique(vocabularyIds);
8943    
8944                            Arrays.sort(vocabularyIds);
8945                    }
8946    
8947                    Object[] finderArgs = new Object[] {
8948                                    groupId, name, StringUtil.merge(vocabularyIds)
8949                            };
8950    
8951                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V,
8952                                    finderArgs, this);
8953    
8954                    if (count == null) {
8955                            StringBundler query = new StringBundler();
8956    
8957                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
8958    
8959                            query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
8960    
8961                            boolean bindName = false;
8962    
8963                            if (name == null) {
8964                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
8965                            }
8966                            else if (name.equals(StringPool.BLANK)) {
8967                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
8968                            }
8969                            else {
8970                                    bindName = true;
8971    
8972                                    query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
8973                            }
8974    
8975                            if (vocabularyIds.length > 0) {
8976                                    query.append(StringPool.OPEN_PARENTHESIS);
8977    
8978                                    query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_7);
8979    
8980                                    query.append(StringUtil.merge(vocabularyIds));
8981    
8982                                    query.append(StringPool.CLOSE_PARENTHESIS);
8983    
8984                                    query.append(StringPool.CLOSE_PARENTHESIS);
8985                            }
8986    
8987                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8988                                                    1)), query.index() - 1);
8989    
8990                            String sql = query.toString();
8991    
8992                            Session session = null;
8993    
8994                            try {
8995                                    session = openSession();
8996    
8997                                    Query q = session.createQuery(sql);
8998    
8999                                    QueryPos qPos = QueryPos.getInstance(q);
9000    
9001                                    qPos.add(groupId);
9002    
9003                                    if (bindName) {
9004                                            qPos.add(StringUtil.toLowerCase(name));
9005                                    }
9006    
9007                                    count = (Long)q.uniqueResult();
9008    
9009                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V,
9010                                            finderArgs, count);
9011                            }
9012                            catch (Exception e) {
9013                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN_V,
9014                                            finderArgs);
9015    
9016                                    throw processException(e);
9017                            }
9018                            finally {
9019                                    closeSession(session);
9020                            }
9021                    }
9022    
9023                    return count.intValue();
9024            }
9025    
9026            /**
9027             * Returns the number of asset categories that the user has permission to view where groupId = &#63; and name LIKE &#63; and vocabularyId = &#63;.
9028             *
9029             * @param groupId the group ID
9030             * @param name the name
9031             * @param vocabularyId the vocabulary ID
9032             * @return the number of matching asset categories that the user has permission to view
9033             */
9034            @Override
9035            public int filterCountByG_LikeN_V(long groupId, String name,
9036                    long vocabularyId) {
9037                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9038                            return countByG_LikeN_V(groupId, name, vocabularyId);
9039                    }
9040    
9041                    StringBundler query = new StringBundler(4);
9042    
9043                    query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
9044    
9045                    query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
9046    
9047                    boolean bindName = false;
9048    
9049                    if (name == null) {
9050                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
9051                    }
9052                    else if (name.equals(StringPool.BLANK)) {
9053                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
9054                    }
9055                    else {
9056                            bindName = true;
9057    
9058                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
9059                    }
9060    
9061                    query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2);
9062    
9063                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9064                                    AssetCategory.class.getName(),
9065                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9066    
9067                    Session session = null;
9068    
9069                    try {
9070                            session = openSession();
9071    
9072                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9073    
9074                            q.addScalar(COUNT_COLUMN_NAME,
9075                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9076    
9077                            QueryPos qPos = QueryPos.getInstance(q);
9078    
9079                            qPos.add(groupId);
9080    
9081                            if (bindName) {
9082                                    qPos.add(StringUtil.toLowerCase(name));
9083                            }
9084    
9085                            qPos.add(vocabularyId);
9086    
9087                            Long count = (Long)q.uniqueResult();
9088    
9089                            return count.intValue();
9090                    }
9091                    catch (Exception e) {
9092                            throw processException(e);
9093                    }
9094                    finally {
9095                            closeSession(session);
9096                    }
9097            }
9098    
9099            /**
9100             * Returns the number of asset categories that the user has permission to view where groupId = &#63; and name LIKE &#63; and vocabularyId = any &#63;.
9101             *
9102             * @param groupId the group ID
9103             * @param name the name
9104             * @param vocabularyIds the vocabulary IDs
9105             * @return the number of matching asset categories that the user has permission to view
9106             */
9107            @Override
9108            public int filterCountByG_LikeN_V(long groupId, String name,
9109                    long[] vocabularyIds) {
9110                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9111                            return countByG_LikeN_V(groupId, name, vocabularyIds);
9112                    }
9113    
9114                    if (vocabularyIds == null) {
9115                            vocabularyIds = new long[0];
9116                    }
9117                    else if (vocabularyIds.length > 1) {
9118                            vocabularyIds = ArrayUtil.unique(vocabularyIds);
9119    
9120                            Arrays.sort(vocabularyIds);
9121                    }
9122    
9123                    StringBundler query = new StringBundler();
9124    
9125                    query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
9126    
9127                    query.append(_FINDER_COLUMN_G_LIKEN_V_GROUPID_2);
9128    
9129                    boolean bindName = false;
9130    
9131                    if (name == null) {
9132                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_1);
9133                    }
9134                    else if (name.equals(StringPool.BLANK)) {
9135                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_3);
9136                    }
9137                    else {
9138                            bindName = true;
9139    
9140                            query.append(_FINDER_COLUMN_G_LIKEN_V_NAME_2);
9141                    }
9142    
9143                    if (vocabularyIds.length > 0) {
9144                            query.append(StringPool.OPEN_PARENTHESIS);
9145    
9146                            query.append(_FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_7);
9147    
9148                            query.append(StringUtil.merge(vocabularyIds));
9149    
9150                            query.append(StringPool.CLOSE_PARENTHESIS);
9151    
9152                            query.append(StringPool.CLOSE_PARENTHESIS);
9153                    }
9154    
9155                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
9156                            query.index() - 1);
9157    
9158                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9159                                    AssetCategory.class.getName(),
9160                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9161    
9162                    Session session = null;
9163    
9164                    try {
9165                            session = openSession();
9166    
9167                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9168    
9169                            q.addScalar(COUNT_COLUMN_NAME,
9170                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9171    
9172                            QueryPos qPos = QueryPos.getInstance(q);
9173    
9174                            qPos.add(groupId);
9175    
9176                            if (bindName) {
9177                                    qPos.add(StringUtil.toLowerCase(name));
9178                            }
9179    
9180                            Long count = (Long)q.uniqueResult();
9181    
9182                            return count.intValue();
9183                    }
9184                    catch (Exception e) {
9185                            throw processException(e);
9186                    }
9187                    finally {
9188                            closeSession(session);
9189                    }
9190            }
9191    
9192            private static final String _FINDER_COLUMN_G_LIKEN_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
9193            private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_1 = "assetCategory.name IS NULL AND ";
9194            private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_2 = "lower(assetCategory.name) LIKE ? AND ";
9195            private static final String _FINDER_COLUMN_G_LIKEN_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name LIKE '') AND ";
9196            private static final String _FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
9197            private static final String _FINDER_COLUMN_G_LIKEN_V_VOCABULARYID_7 = "assetCategory.vocabularyId IN (";
9198            public static final FinderPath FINDER_PATH_FETCH_BY_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9199                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
9200                            AssetCategoryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByP_N_V",
9201                            new String[] {
9202                                    Long.class.getName(), String.class.getName(),
9203                                    Long.class.getName()
9204                            },
9205                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
9206                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
9207                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
9208            public static final FinderPath FINDER_PATH_COUNT_BY_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9209                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
9210                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N_V",
9211                            new String[] {
9212                                    Long.class.getName(), String.class.getName(),
9213                                    Long.class.getName()
9214                            });
9215    
9216            /**
9217             * Returns the asset category where parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63; or throws a {@link NoSuchCategoryException} if it could not be found.
9218             *
9219             * @param parentCategoryId the parent category ID
9220             * @param name the name
9221             * @param vocabularyId the vocabulary ID
9222             * @return the matching asset category
9223             * @throws NoSuchCategoryException if a matching asset category could not be found
9224             */
9225            @Override
9226            public AssetCategory findByP_N_V(long parentCategoryId, String name,
9227                    long vocabularyId) throws NoSuchCategoryException {
9228                    AssetCategory assetCategory = fetchByP_N_V(parentCategoryId, name,
9229                                    vocabularyId);
9230    
9231                    if (assetCategory == null) {
9232                            StringBundler msg = new StringBundler(8);
9233    
9234                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9235    
9236                            msg.append("parentCategoryId=");
9237                            msg.append(parentCategoryId);
9238    
9239                            msg.append(", name=");
9240                            msg.append(name);
9241    
9242                            msg.append(", vocabularyId=");
9243                            msg.append(vocabularyId);
9244    
9245                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9246    
9247                            if (_log.isWarnEnabled()) {
9248                                    _log.warn(msg.toString());
9249                            }
9250    
9251                            throw new NoSuchCategoryException(msg.toString());
9252                    }
9253    
9254                    return assetCategory;
9255            }
9256    
9257            /**
9258             * Returns the asset category where parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
9259             *
9260             * @param parentCategoryId the parent category ID
9261             * @param name the name
9262             * @param vocabularyId the vocabulary ID
9263             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
9264             */
9265            @Override
9266            public AssetCategory fetchByP_N_V(long parentCategoryId, String name,
9267                    long vocabularyId) {
9268                    return fetchByP_N_V(parentCategoryId, name, vocabularyId, true);
9269            }
9270    
9271            /**
9272             * Returns the asset category where parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
9273             *
9274             * @param parentCategoryId the parent category ID
9275             * @param name the name
9276             * @param vocabularyId the vocabulary ID
9277             * @param retrieveFromCache whether to retrieve from the finder cache
9278             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
9279             */
9280            @Override
9281            public AssetCategory fetchByP_N_V(long parentCategoryId, String name,
9282                    long vocabularyId, boolean retrieveFromCache) {
9283                    Object[] finderArgs = new Object[] { parentCategoryId, name, vocabularyId };
9284    
9285                    Object result = null;
9286    
9287                    if (retrieveFromCache) {
9288                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_P_N_V,
9289                                            finderArgs, this);
9290                    }
9291    
9292                    if (result instanceof AssetCategory) {
9293                            AssetCategory assetCategory = (AssetCategory)result;
9294    
9295                            if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
9296                                            !Validator.equals(name, assetCategory.getName()) ||
9297                                            (vocabularyId != assetCategory.getVocabularyId())) {
9298                                    result = null;
9299                            }
9300                    }
9301    
9302                    if (result == null) {
9303                            StringBundler query = new StringBundler(5);
9304    
9305                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
9306    
9307                            query.append(_FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2);
9308    
9309                            boolean bindName = false;
9310    
9311                            if (name == null) {
9312                                    query.append(_FINDER_COLUMN_P_N_V_NAME_1);
9313                            }
9314                            else if (name.equals(StringPool.BLANK)) {
9315                                    query.append(_FINDER_COLUMN_P_N_V_NAME_3);
9316                            }
9317                            else {
9318                                    bindName = true;
9319    
9320                                    query.append(_FINDER_COLUMN_P_N_V_NAME_2);
9321                            }
9322    
9323                            query.append(_FINDER_COLUMN_P_N_V_VOCABULARYID_2);
9324    
9325                            String sql = query.toString();
9326    
9327                            Session session = null;
9328    
9329                            try {
9330                                    session = openSession();
9331    
9332                                    Query q = session.createQuery(sql);
9333    
9334                                    QueryPos qPos = QueryPos.getInstance(q);
9335    
9336                                    qPos.add(parentCategoryId);
9337    
9338                                    if (bindName) {
9339                                            qPos.add(name);
9340                                    }
9341    
9342                                    qPos.add(vocabularyId);
9343    
9344                                    List<AssetCategory> list = q.list();
9345    
9346                                    if (list.isEmpty()) {
9347                                            finderCache.putResult(FINDER_PATH_FETCH_BY_P_N_V,
9348                                                    finderArgs, list);
9349                                    }
9350                                    else {
9351                                            AssetCategory assetCategory = list.get(0);
9352    
9353                                            result = assetCategory;
9354    
9355                                            cacheResult(assetCategory);
9356    
9357                                            if ((assetCategory.getParentCategoryId() != parentCategoryId) ||
9358                                                            (assetCategory.getName() == null) ||
9359                                                            !assetCategory.getName().equals(name) ||
9360                                                            (assetCategory.getVocabularyId() != vocabularyId)) {
9361                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_P_N_V,
9362                                                            finderArgs, assetCategory);
9363                                            }
9364                                    }
9365                            }
9366                            catch (Exception e) {
9367                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_P_N_V, finderArgs);
9368    
9369                                    throw processException(e);
9370                            }
9371                            finally {
9372                                    closeSession(session);
9373                            }
9374                    }
9375    
9376                    if (result instanceof List<?>) {
9377                            return null;
9378                    }
9379                    else {
9380                            return (AssetCategory)result;
9381                    }
9382            }
9383    
9384            /**
9385             * Removes the asset category where parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63; from the database.
9386             *
9387             * @param parentCategoryId the parent category ID
9388             * @param name the name
9389             * @param vocabularyId the vocabulary ID
9390             * @return the asset category that was removed
9391             */
9392            @Override
9393            public AssetCategory removeByP_N_V(long parentCategoryId, String name,
9394                    long vocabularyId) throws NoSuchCategoryException {
9395                    AssetCategory assetCategory = findByP_N_V(parentCategoryId, name,
9396                                    vocabularyId);
9397    
9398                    return remove(assetCategory);
9399            }
9400    
9401            /**
9402             * Returns the number of asset categories where parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
9403             *
9404             * @param parentCategoryId the parent category ID
9405             * @param name the name
9406             * @param vocabularyId the vocabulary ID
9407             * @return the number of matching asset categories
9408             */
9409            @Override
9410            public int countByP_N_V(long parentCategoryId, String name,
9411                    long vocabularyId) {
9412                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N_V;
9413    
9414                    Object[] finderArgs = new Object[] { parentCategoryId, name, vocabularyId };
9415    
9416                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
9417    
9418                    if (count == null) {
9419                            StringBundler query = new StringBundler(4);
9420    
9421                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
9422    
9423                            query.append(_FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2);
9424    
9425                            boolean bindName = false;
9426    
9427                            if (name == null) {
9428                                    query.append(_FINDER_COLUMN_P_N_V_NAME_1);
9429                            }
9430                            else if (name.equals(StringPool.BLANK)) {
9431                                    query.append(_FINDER_COLUMN_P_N_V_NAME_3);
9432                            }
9433                            else {
9434                                    bindName = true;
9435    
9436                                    query.append(_FINDER_COLUMN_P_N_V_NAME_2);
9437                            }
9438    
9439                            query.append(_FINDER_COLUMN_P_N_V_VOCABULARYID_2);
9440    
9441                            String sql = query.toString();
9442    
9443                            Session session = null;
9444    
9445                            try {
9446                                    session = openSession();
9447    
9448                                    Query q = session.createQuery(sql);
9449    
9450                                    QueryPos qPos = QueryPos.getInstance(q);
9451    
9452                                    qPos.add(parentCategoryId);
9453    
9454                                    if (bindName) {
9455                                            qPos.add(name);
9456                                    }
9457    
9458                                    qPos.add(vocabularyId);
9459    
9460                                    count = (Long)q.uniqueResult();
9461    
9462                                    finderCache.putResult(finderPath, finderArgs, count);
9463                            }
9464                            catch (Exception e) {
9465                                    finderCache.removeResult(finderPath, finderArgs);
9466    
9467                                    throw processException(e);
9468                            }
9469                            finally {
9470                                    closeSession(session);
9471                            }
9472                    }
9473    
9474                    return count.intValue();
9475            }
9476    
9477            private static final String _FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
9478            private static final String _FINDER_COLUMN_P_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
9479            private static final String _FINDER_COLUMN_P_N_V_NAME_2 = "assetCategory.name = ? AND ";
9480            private static final String _FINDER_COLUMN_P_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '') AND ";
9481            private static final String _FINDER_COLUMN_P_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
9482            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9483                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
9484                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
9485                            "findByG_P_N_V",
9486                            new String[] {
9487                                    Long.class.getName(), Long.class.getName(),
9488                                    String.class.getName(), Long.class.getName(),
9489                                    
9490                            Integer.class.getName(), Integer.class.getName(),
9491                                    OrderByComparator.class.getName()
9492                            });
9493            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V =
9494                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9495                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
9496                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
9497                            "findByG_P_N_V",
9498                            new String[] {
9499                                    Long.class.getName(), Long.class.getName(),
9500                                    String.class.getName(), Long.class.getName()
9501                            },
9502                            AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
9503                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
9504                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
9505                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
9506            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
9507                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
9508                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N_V",
9509                            new String[] {
9510                                    Long.class.getName(), Long.class.getName(),
9511                                    String.class.getName(), Long.class.getName()
9512                            });
9513    
9514            /**
9515             * Returns all the asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
9516             *
9517             * @param groupId the group ID
9518             * @param parentCategoryId the parent category ID
9519             * @param name the name
9520             * @param vocabularyId the vocabulary ID
9521             * @return the matching asset categories
9522             */
9523            @Override
9524            public List<AssetCategory> findByG_P_N_V(long groupId,
9525                    long parentCategoryId, String name, long vocabularyId) {
9526                    return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
9527                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9528            }
9529    
9530            /**
9531             * Returns a range of all the asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
9532             *
9533             * <p>
9534             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9535             * </p>
9536             *
9537             * @param groupId the group ID
9538             * @param parentCategoryId the parent category ID
9539             * @param name the name
9540             * @param vocabularyId the vocabulary ID
9541             * @param start the lower bound of the range of asset categories
9542             * @param end the upper bound of the range of asset categories (not inclusive)
9543             * @return the range of matching asset categories
9544             */
9545            @Override
9546            public List<AssetCategory> findByG_P_N_V(long groupId,
9547                    long parentCategoryId, String name, long vocabularyId, int start,
9548                    int end) {
9549                    return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
9550                            start, end, null);
9551            }
9552    
9553            /**
9554             * Returns an ordered range of all the asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
9555             *
9556             * <p>
9557             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9558             * </p>
9559             *
9560             * @param groupId the group ID
9561             * @param parentCategoryId the parent category ID
9562             * @param name the name
9563             * @param vocabularyId the vocabulary ID
9564             * @param start the lower bound of the range of asset categories
9565             * @param end the upper bound of the range of asset categories (not inclusive)
9566             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9567             * @return the ordered range of matching asset categories
9568             */
9569            @Override
9570            public List<AssetCategory> findByG_P_N_V(long groupId,
9571                    long parentCategoryId, String name, long vocabularyId, int start,
9572                    int end, OrderByComparator<AssetCategory> orderByComparator) {
9573                    return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
9574                            start, end, orderByComparator, true);
9575            }
9576    
9577            /**
9578             * Returns an ordered range of all the asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
9579             *
9580             * <p>
9581             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9582             * </p>
9583             *
9584             * @param groupId the group ID
9585             * @param parentCategoryId the parent category ID
9586             * @param name the name
9587             * @param vocabularyId the vocabulary ID
9588             * @param start the lower bound of the range of asset categories
9589             * @param end the upper bound of the range of asset categories (not inclusive)
9590             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9591             * @param retrieveFromCache whether to retrieve from the finder cache
9592             * @return the ordered range of matching asset categories
9593             */
9594            @Override
9595            public List<AssetCategory> findByG_P_N_V(long groupId,
9596                    long parentCategoryId, String name, long vocabularyId, int start,
9597                    int end, OrderByComparator<AssetCategory> orderByComparator,
9598                    boolean retrieveFromCache) {
9599                    boolean pagination = true;
9600                    FinderPath finderPath = null;
9601                    Object[] finderArgs = null;
9602    
9603                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9604                                    (orderByComparator == null)) {
9605                            pagination = false;
9606                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V;
9607                            finderArgs = new Object[] {
9608                                            groupId, parentCategoryId, name, vocabularyId
9609                                    };
9610                    }
9611                    else {
9612                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_N_V;
9613                            finderArgs = new Object[] {
9614                                            groupId, parentCategoryId, name, vocabularyId,
9615                                            
9616                                            start, end, orderByComparator
9617                                    };
9618                    }
9619    
9620                    List<AssetCategory> list = null;
9621    
9622                    if (retrieveFromCache) {
9623                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
9624                                            finderArgs, this);
9625    
9626                            if ((list != null) && !list.isEmpty()) {
9627                                    for (AssetCategory assetCategory : list) {
9628                                            if ((groupId != assetCategory.getGroupId()) ||
9629                                                            (parentCategoryId != assetCategory.getParentCategoryId()) ||
9630                                                            !Validator.equals(name, assetCategory.getName()) ||
9631                                                            (vocabularyId != assetCategory.getVocabularyId())) {
9632                                                    list = null;
9633    
9634                                                    break;
9635                                            }
9636                                    }
9637                            }
9638                    }
9639    
9640                    if (list == null) {
9641                            StringBundler query = null;
9642    
9643                            if (orderByComparator != null) {
9644                                    query = new StringBundler(6 +
9645                                                    (orderByComparator.getOrderByFields().length * 3));
9646                            }
9647                            else {
9648                                    query = new StringBundler(6);
9649                            }
9650    
9651                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
9652    
9653                            query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
9654    
9655                            query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
9656    
9657                            boolean bindName = false;
9658    
9659                            if (name == null) {
9660                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
9661                            }
9662                            else if (name.equals(StringPool.BLANK)) {
9663                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
9664                            }
9665                            else {
9666                                    bindName = true;
9667    
9668                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
9669                            }
9670    
9671                            query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
9672    
9673                            if (orderByComparator != null) {
9674                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9675                                            orderByComparator);
9676                            }
9677                            else
9678                             if (pagination) {
9679                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
9680                            }
9681    
9682                            String sql = query.toString();
9683    
9684                            Session session = null;
9685    
9686                            try {
9687                                    session = openSession();
9688    
9689                                    Query q = session.createQuery(sql);
9690    
9691                                    QueryPos qPos = QueryPos.getInstance(q);
9692    
9693                                    qPos.add(groupId);
9694    
9695                                    qPos.add(parentCategoryId);
9696    
9697                                    if (bindName) {
9698                                            qPos.add(name);
9699                                    }
9700    
9701                                    qPos.add(vocabularyId);
9702    
9703                                    if (!pagination) {
9704                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
9705                                                            start, end, false);
9706    
9707                                            Collections.sort(list);
9708    
9709                                            list = Collections.unmodifiableList(list);
9710                                    }
9711                                    else {
9712                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
9713                                                            start, end);
9714                                    }
9715    
9716                                    cacheResult(list);
9717    
9718                                    finderCache.putResult(finderPath, finderArgs, list);
9719                            }
9720                            catch (Exception e) {
9721                                    finderCache.removeResult(finderPath, finderArgs);
9722    
9723                                    throw processException(e);
9724                            }
9725                            finally {
9726                                    closeSession(session);
9727                            }
9728                    }
9729    
9730                    return list;
9731            }
9732    
9733            /**
9734             * Returns the first asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
9735             *
9736             * @param groupId the group ID
9737             * @param parentCategoryId the parent category ID
9738             * @param name the name
9739             * @param vocabularyId the vocabulary ID
9740             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9741             * @return the first matching asset category
9742             * @throws NoSuchCategoryException if a matching asset category could not be found
9743             */
9744            @Override
9745            public AssetCategory findByG_P_N_V_First(long groupId,
9746                    long parentCategoryId, String name, long vocabularyId,
9747                    OrderByComparator<AssetCategory> orderByComparator)
9748                    throws NoSuchCategoryException {
9749                    AssetCategory assetCategory = fetchByG_P_N_V_First(groupId,
9750                                    parentCategoryId, name, vocabularyId, orderByComparator);
9751    
9752                    if (assetCategory != null) {
9753                            return assetCategory;
9754                    }
9755    
9756                    StringBundler msg = new StringBundler(10);
9757    
9758                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9759    
9760                    msg.append("groupId=");
9761                    msg.append(groupId);
9762    
9763                    msg.append(", parentCategoryId=");
9764                    msg.append(parentCategoryId);
9765    
9766                    msg.append(", name=");
9767                    msg.append(name);
9768    
9769                    msg.append(", vocabularyId=");
9770                    msg.append(vocabularyId);
9771    
9772                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9773    
9774                    throw new NoSuchCategoryException(msg.toString());
9775            }
9776    
9777            /**
9778             * Returns the first asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
9779             *
9780             * @param groupId the group ID
9781             * @param parentCategoryId the parent category ID
9782             * @param name the name
9783             * @param vocabularyId the vocabulary ID
9784             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9785             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
9786             */
9787            @Override
9788            public AssetCategory fetchByG_P_N_V_First(long groupId,
9789                    long parentCategoryId, String name, long vocabularyId,
9790                    OrderByComparator<AssetCategory> orderByComparator) {
9791                    List<AssetCategory> list = findByG_P_N_V(groupId, parentCategoryId,
9792                                    name, vocabularyId, 0, 1, orderByComparator);
9793    
9794                    if (!list.isEmpty()) {
9795                            return list.get(0);
9796                    }
9797    
9798                    return null;
9799            }
9800    
9801            /**
9802             * Returns the last asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
9803             *
9804             * @param groupId the group ID
9805             * @param parentCategoryId the parent category ID
9806             * @param name the name
9807             * @param vocabularyId the vocabulary ID
9808             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9809             * @return the last matching asset category
9810             * @throws NoSuchCategoryException if a matching asset category could not be found
9811             */
9812            @Override
9813            public AssetCategory findByG_P_N_V_Last(long groupId,
9814                    long parentCategoryId, String name, long vocabularyId,
9815                    OrderByComparator<AssetCategory> orderByComparator)
9816                    throws NoSuchCategoryException {
9817                    AssetCategory assetCategory = fetchByG_P_N_V_Last(groupId,
9818                                    parentCategoryId, name, vocabularyId, orderByComparator);
9819    
9820                    if (assetCategory != null) {
9821                            return assetCategory;
9822                    }
9823    
9824                    StringBundler msg = new StringBundler(10);
9825    
9826                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9827    
9828                    msg.append("groupId=");
9829                    msg.append(groupId);
9830    
9831                    msg.append(", parentCategoryId=");
9832                    msg.append(parentCategoryId);
9833    
9834                    msg.append(", name=");
9835                    msg.append(name);
9836    
9837                    msg.append(", vocabularyId=");
9838                    msg.append(vocabularyId);
9839    
9840                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9841    
9842                    throw new NoSuchCategoryException(msg.toString());
9843            }
9844    
9845            /**
9846             * Returns the last asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
9847             *
9848             * @param groupId the group ID
9849             * @param parentCategoryId the parent category ID
9850             * @param name the name
9851             * @param vocabularyId the vocabulary ID
9852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9853             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
9854             */
9855            @Override
9856            public AssetCategory fetchByG_P_N_V_Last(long groupId,
9857                    long parentCategoryId, String name, long vocabularyId,
9858                    OrderByComparator<AssetCategory> orderByComparator) {
9859                    int count = countByG_P_N_V(groupId, parentCategoryId, name, vocabularyId);
9860    
9861                    if (count == 0) {
9862                            return null;
9863                    }
9864    
9865                    List<AssetCategory> list = findByG_P_N_V(groupId, parentCategoryId,
9866                                    name, vocabularyId, count - 1, count, orderByComparator);
9867    
9868                    if (!list.isEmpty()) {
9869                            return list.get(0);
9870                    }
9871    
9872                    return null;
9873            }
9874    
9875            /**
9876             * Returns the asset categories before and after the current asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
9877             *
9878             * @param categoryId the primary key of the current asset category
9879             * @param groupId the group ID
9880             * @param parentCategoryId the parent category ID
9881             * @param name the name
9882             * @param vocabularyId the vocabulary ID
9883             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9884             * @return the previous, current, and next asset category
9885             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
9886             */
9887            @Override
9888            public AssetCategory[] findByG_P_N_V_PrevAndNext(long categoryId,
9889                    long groupId, long parentCategoryId, String name, long vocabularyId,
9890                    OrderByComparator<AssetCategory> orderByComparator)
9891                    throws NoSuchCategoryException {
9892                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
9893    
9894                    Session session = null;
9895    
9896                    try {
9897                            session = openSession();
9898    
9899                            AssetCategory[] array = new AssetCategoryImpl[3];
9900    
9901                            array[0] = getByG_P_N_V_PrevAndNext(session, assetCategory,
9902                                            groupId, parentCategoryId, name, vocabularyId,
9903                                            orderByComparator, true);
9904    
9905                            array[1] = assetCategory;
9906    
9907                            array[2] = getByG_P_N_V_PrevAndNext(session, assetCategory,
9908                                            groupId, parentCategoryId, name, vocabularyId,
9909                                            orderByComparator, false);
9910    
9911                            return array;
9912                    }
9913                    catch (Exception e) {
9914                            throw processException(e);
9915                    }
9916                    finally {
9917                            closeSession(session);
9918                    }
9919            }
9920    
9921            protected AssetCategory getByG_P_N_V_PrevAndNext(Session session,
9922                    AssetCategory assetCategory, long groupId, long parentCategoryId,
9923                    String name, long vocabularyId,
9924                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
9925                    StringBundler query = null;
9926    
9927                    if (orderByComparator != null) {
9928                            query = new StringBundler(6 +
9929                                            (orderByComparator.getOrderByFields().length * 6));
9930                    }
9931                    else {
9932                            query = new StringBundler(3);
9933                    }
9934    
9935                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
9936    
9937                    query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
9938    
9939                    query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
9940    
9941                    boolean bindName = false;
9942    
9943                    if (name == null) {
9944                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
9945                    }
9946                    else if (name.equals(StringPool.BLANK)) {
9947                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
9948                    }
9949                    else {
9950                            bindName = true;
9951    
9952                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
9953                    }
9954    
9955                    query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
9956    
9957                    if (orderByComparator != null) {
9958                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9959    
9960                            if (orderByConditionFields.length > 0) {
9961                                    query.append(WHERE_AND);
9962                            }
9963    
9964                            for (int i = 0; i < orderByConditionFields.length; i++) {
9965                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9966                                    query.append(orderByConditionFields[i]);
9967    
9968                                    if ((i + 1) < orderByConditionFields.length) {
9969                                            if (orderByComparator.isAscending() ^ previous) {
9970                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9971                                            }
9972                                            else {
9973                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9974                                            }
9975                                    }
9976                                    else {
9977                                            if (orderByComparator.isAscending() ^ previous) {
9978                                                    query.append(WHERE_GREATER_THAN);
9979                                            }
9980                                            else {
9981                                                    query.append(WHERE_LESSER_THAN);
9982                                            }
9983                                    }
9984                            }
9985    
9986                            query.append(ORDER_BY_CLAUSE);
9987    
9988                            String[] orderByFields = orderByComparator.getOrderByFields();
9989    
9990                            for (int i = 0; i < orderByFields.length; i++) {
9991                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9992                                    query.append(orderByFields[i]);
9993    
9994                                    if ((i + 1) < orderByFields.length) {
9995                                            if (orderByComparator.isAscending() ^ previous) {
9996                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9997                                            }
9998                                            else {
9999                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10000                                            }
10001                                    }
10002                                    else {
10003                                            if (orderByComparator.isAscending() ^ previous) {
10004                                                    query.append(ORDER_BY_ASC);
10005                                            }
10006                                            else {
10007                                                    query.append(ORDER_BY_DESC);
10008                                            }
10009                                    }
10010                            }
10011                    }
10012                    else {
10013                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
10014                    }
10015    
10016                    String sql = query.toString();
10017    
10018                    Query q = session.createQuery(sql);
10019    
10020                    q.setFirstResult(0);
10021                    q.setMaxResults(2);
10022    
10023                    QueryPos qPos = QueryPos.getInstance(q);
10024    
10025                    qPos.add(groupId);
10026    
10027                    qPos.add(parentCategoryId);
10028    
10029                    if (bindName) {
10030                            qPos.add(name);
10031                    }
10032    
10033                    qPos.add(vocabularyId);
10034    
10035                    if (orderByComparator != null) {
10036                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
10037    
10038                            for (Object value : values) {
10039                                    qPos.add(value);
10040                            }
10041                    }
10042    
10043                    List<AssetCategory> list = q.list();
10044    
10045                    if (list.size() == 2) {
10046                            return list.get(1);
10047                    }
10048                    else {
10049                            return null;
10050                    }
10051            }
10052    
10053            /**
10054             * Returns all the asset categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
10055             *
10056             * @param groupId the group ID
10057             * @param parentCategoryId the parent category ID
10058             * @param name the name
10059             * @param vocabularyId the vocabulary ID
10060             * @return the matching asset categories that the user has permission to view
10061             */
10062            @Override
10063            public List<AssetCategory> filterFindByG_P_N_V(long groupId,
10064                    long parentCategoryId, String name, long vocabularyId) {
10065                    return filterFindByG_P_N_V(groupId, parentCategoryId, name,
10066                            vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10067            }
10068    
10069            /**
10070             * Returns a range of all the asset categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
10071             *
10072             * <p>
10073             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10074             * </p>
10075             *
10076             * @param groupId the group ID
10077             * @param parentCategoryId the parent category ID
10078             * @param name the name
10079             * @param vocabularyId the vocabulary ID
10080             * @param start the lower bound of the range of asset categories
10081             * @param end the upper bound of the range of asset categories (not inclusive)
10082             * @return the range of matching asset categories that the user has permission to view
10083             */
10084            @Override
10085            public List<AssetCategory> filterFindByG_P_N_V(long groupId,
10086                    long parentCategoryId, String name, long vocabularyId, int start,
10087                    int end) {
10088                    return filterFindByG_P_N_V(groupId, parentCategoryId, name,
10089                            vocabularyId, start, end, null);
10090            }
10091    
10092            /**
10093             * Returns an ordered range of all the asset categories that the user has permissions to view where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
10094             *
10095             * <p>
10096             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10097             * </p>
10098             *
10099             * @param groupId the group ID
10100             * @param parentCategoryId the parent category ID
10101             * @param name the name
10102             * @param vocabularyId the vocabulary ID
10103             * @param start the lower bound of the range of asset categories
10104             * @param end the upper bound of the range of asset categories (not inclusive)
10105             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10106             * @return the ordered range of matching asset categories that the user has permission to view
10107             */
10108            @Override
10109            public List<AssetCategory> filterFindByG_P_N_V(long groupId,
10110                    long parentCategoryId, String name, long vocabularyId, int start,
10111                    int end, OrderByComparator<AssetCategory> orderByComparator) {
10112                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10113                            return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
10114                                    start, end, orderByComparator);
10115                    }
10116    
10117                    StringBundler query = null;
10118    
10119                    if (orderByComparator != null) {
10120                            query = new StringBundler(6 +
10121                                            (orderByComparator.getOrderByFields().length * 3));
10122                    }
10123                    else {
10124                            query = new StringBundler(6);
10125                    }
10126    
10127                    if (getDB().isSupportsInlineDistinct()) {
10128                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
10129                    }
10130                    else {
10131                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
10132                    }
10133    
10134                    query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
10135    
10136                    query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
10137    
10138                    boolean bindName = false;
10139    
10140                    if (name == null) {
10141                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
10142                    }
10143                    else if (name.equals(StringPool.BLANK)) {
10144                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
10145                    }
10146                    else {
10147                            bindName = true;
10148    
10149                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
10150                    }
10151    
10152                    query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
10153    
10154                    if (!getDB().isSupportsInlineDistinct()) {
10155                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
10156                    }
10157    
10158                    if (orderByComparator != null) {
10159                            if (getDB().isSupportsInlineDistinct()) {
10160                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10161                                            orderByComparator, true);
10162                            }
10163                            else {
10164                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10165                                            orderByComparator, true);
10166                            }
10167                    }
10168                    else {
10169                            if (getDB().isSupportsInlineDistinct()) {
10170                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
10171                            }
10172                            else {
10173                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
10174                            }
10175                    }
10176    
10177                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10178                                    AssetCategory.class.getName(),
10179                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10180    
10181                    Session session = null;
10182    
10183                    try {
10184                            session = openSession();
10185    
10186                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10187    
10188                            if (getDB().isSupportsInlineDistinct()) {
10189                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
10190                            }
10191                            else {
10192                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
10193                            }
10194    
10195                            QueryPos qPos = QueryPos.getInstance(q);
10196    
10197                            qPos.add(groupId);
10198    
10199                            qPos.add(parentCategoryId);
10200    
10201                            if (bindName) {
10202                                    qPos.add(name);
10203                            }
10204    
10205                            qPos.add(vocabularyId);
10206    
10207                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
10208                                    end);
10209                    }
10210                    catch (Exception e) {
10211                            throw processException(e);
10212                    }
10213                    finally {
10214                            closeSession(session);
10215                    }
10216            }
10217    
10218            /**
10219             * Returns the asset categories before and after the current asset category in the ordered set of asset categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
10220             *
10221             * @param categoryId the primary key of the current asset category
10222             * @param groupId the group ID
10223             * @param parentCategoryId the parent category ID
10224             * @param name the name
10225             * @param vocabularyId the vocabulary ID
10226             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10227             * @return the previous, current, and next asset category
10228             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
10229             */
10230            @Override
10231            public AssetCategory[] filterFindByG_P_N_V_PrevAndNext(long categoryId,
10232                    long groupId, long parentCategoryId, String name, long vocabularyId,
10233                    OrderByComparator<AssetCategory> orderByComparator)
10234                    throws NoSuchCategoryException {
10235                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10236                            return findByG_P_N_V_PrevAndNext(categoryId, groupId,
10237                                    parentCategoryId, name, vocabularyId, orderByComparator);
10238                    }
10239    
10240                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
10241    
10242                    Session session = null;
10243    
10244                    try {
10245                            session = openSession();
10246    
10247                            AssetCategory[] array = new AssetCategoryImpl[3];
10248    
10249                            array[0] = filterGetByG_P_N_V_PrevAndNext(session, assetCategory,
10250                                            groupId, parentCategoryId, name, vocabularyId,
10251                                            orderByComparator, true);
10252    
10253                            array[1] = assetCategory;
10254    
10255                            array[2] = filterGetByG_P_N_V_PrevAndNext(session, assetCategory,
10256                                            groupId, parentCategoryId, name, vocabularyId,
10257                                            orderByComparator, false);
10258    
10259                            return array;
10260                    }
10261                    catch (Exception e) {
10262                            throw processException(e);
10263                    }
10264                    finally {
10265                            closeSession(session);
10266                    }
10267            }
10268    
10269            protected AssetCategory filterGetByG_P_N_V_PrevAndNext(Session session,
10270                    AssetCategory assetCategory, long groupId, long parentCategoryId,
10271                    String name, long vocabularyId,
10272                    OrderByComparator<AssetCategory> orderByComparator, boolean previous) {
10273                    StringBundler query = null;
10274    
10275                    if (orderByComparator != null) {
10276                            query = new StringBundler(6 +
10277                                            (orderByComparator.getOrderByFields().length * 6));
10278                    }
10279                    else {
10280                            query = new StringBundler(3);
10281                    }
10282    
10283                    if (getDB().isSupportsInlineDistinct()) {
10284                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
10285                    }
10286                    else {
10287                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
10288                    }
10289    
10290                    query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
10291    
10292                    query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
10293    
10294                    boolean bindName = false;
10295    
10296                    if (name == null) {
10297                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
10298                    }
10299                    else if (name.equals(StringPool.BLANK)) {
10300                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
10301                    }
10302                    else {
10303                            bindName = true;
10304    
10305                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
10306                    }
10307    
10308                    query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
10309    
10310                    if (!getDB().isSupportsInlineDistinct()) {
10311                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
10312                    }
10313    
10314                    if (orderByComparator != null) {
10315                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10316    
10317                            if (orderByConditionFields.length > 0) {
10318                                    query.append(WHERE_AND);
10319                            }
10320    
10321                            for (int i = 0; i < orderByConditionFields.length; i++) {
10322                                    if (getDB().isSupportsInlineDistinct()) {
10323                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10324                                    }
10325                                    else {
10326                                            query.append(_ORDER_BY_ENTITY_TABLE);
10327                                    }
10328    
10329                                    query.append(orderByConditionFields[i]);
10330    
10331                                    if ((i + 1) < orderByConditionFields.length) {
10332                                            if (orderByComparator.isAscending() ^ previous) {
10333                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10334                                            }
10335                                            else {
10336                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10337                                            }
10338                                    }
10339                                    else {
10340                                            if (orderByComparator.isAscending() ^ previous) {
10341                                                    query.append(WHERE_GREATER_THAN);
10342                                            }
10343                                            else {
10344                                                    query.append(WHERE_LESSER_THAN);
10345                                            }
10346                                    }
10347                            }
10348    
10349                            query.append(ORDER_BY_CLAUSE);
10350    
10351                            String[] orderByFields = orderByComparator.getOrderByFields();
10352    
10353                            for (int i = 0; i < orderByFields.length; i++) {
10354                                    if (getDB().isSupportsInlineDistinct()) {
10355                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10356                                    }
10357                                    else {
10358                                            query.append(_ORDER_BY_ENTITY_TABLE);
10359                                    }
10360    
10361                                    query.append(orderByFields[i]);
10362    
10363                                    if ((i + 1) < orderByFields.length) {
10364                                            if (orderByComparator.isAscending() ^ previous) {
10365                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10366                                            }
10367                                            else {
10368                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10369                                            }
10370                                    }
10371                                    else {
10372                                            if (orderByComparator.isAscending() ^ previous) {
10373                                                    query.append(ORDER_BY_ASC);
10374                                            }
10375                                            else {
10376                                                    query.append(ORDER_BY_DESC);
10377                                            }
10378                                    }
10379                            }
10380                    }
10381                    else {
10382                            if (getDB().isSupportsInlineDistinct()) {
10383                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
10384                            }
10385                            else {
10386                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
10387                            }
10388                    }
10389    
10390                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10391                                    AssetCategory.class.getName(),
10392                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10393    
10394                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
10395    
10396                    q.setFirstResult(0);
10397                    q.setMaxResults(2);
10398    
10399                    if (getDB().isSupportsInlineDistinct()) {
10400                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
10401                    }
10402                    else {
10403                            q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
10404                    }
10405    
10406                    QueryPos qPos = QueryPos.getInstance(q);
10407    
10408                    qPos.add(groupId);
10409    
10410                    qPos.add(parentCategoryId);
10411    
10412                    if (bindName) {
10413                            qPos.add(name);
10414                    }
10415    
10416                    qPos.add(vocabularyId);
10417    
10418                    if (orderByComparator != null) {
10419                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
10420    
10421                            for (Object value : values) {
10422                                    qPos.add(value);
10423                            }
10424                    }
10425    
10426                    List<AssetCategory> list = q.list();
10427    
10428                    if (list.size() == 2) {
10429                            return list.get(1);
10430                    }
10431                    else {
10432                            return null;
10433                    }
10434            }
10435    
10436            /**
10437             * Removes all the asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63; from the database.
10438             *
10439             * @param groupId the group ID
10440             * @param parentCategoryId the parent category ID
10441             * @param name the name
10442             * @param vocabularyId the vocabulary ID
10443             */
10444            @Override
10445            public void removeByG_P_N_V(long groupId, long parentCategoryId,
10446                    String name, long vocabularyId) {
10447                    for (AssetCategory assetCategory : findByG_P_N_V(groupId,
10448                                    parentCategoryId, name, vocabularyId, QueryUtil.ALL_POS,
10449                                    QueryUtil.ALL_POS, null)) {
10450                            remove(assetCategory);
10451                    }
10452            }
10453    
10454            /**
10455             * Returns the number of asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
10456             *
10457             * @param groupId the group ID
10458             * @param parentCategoryId the parent category ID
10459             * @param name the name
10460             * @param vocabularyId the vocabulary ID
10461             * @return the number of matching asset categories
10462             */
10463            @Override
10464            public int countByG_P_N_V(long groupId, long parentCategoryId, String name,
10465                    long vocabularyId) {
10466                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N_V;
10467    
10468                    Object[] finderArgs = new Object[] {
10469                                    groupId, parentCategoryId, name, vocabularyId
10470                            };
10471    
10472                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
10473    
10474                    if (count == null) {
10475                            StringBundler query = new StringBundler(5);
10476    
10477                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
10478    
10479                            query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
10480    
10481                            query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
10482    
10483                            boolean bindName = false;
10484    
10485                            if (name == null) {
10486                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
10487                            }
10488                            else if (name.equals(StringPool.BLANK)) {
10489                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
10490                            }
10491                            else {
10492                                    bindName = true;
10493    
10494                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
10495                            }
10496    
10497                            query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
10498    
10499                            String sql = query.toString();
10500    
10501                            Session session = null;
10502    
10503                            try {
10504                                    session = openSession();
10505    
10506                                    Query q = session.createQuery(sql);
10507    
10508                                    QueryPos qPos = QueryPos.getInstance(q);
10509    
10510                                    qPos.add(groupId);
10511    
10512                                    qPos.add(parentCategoryId);
10513    
10514                                    if (bindName) {
10515                                            qPos.add(name);
10516                                    }
10517    
10518                                    qPos.add(vocabularyId);
10519    
10520                                    count = (Long)q.uniqueResult();
10521    
10522                                    finderCache.putResult(finderPath, finderArgs, count);
10523                            }
10524                            catch (Exception e) {
10525                                    finderCache.removeResult(finderPath, finderArgs);
10526    
10527                                    throw processException(e);
10528                            }
10529                            finally {
10530                                    closeSession(session);
10531                            }
10532                    }
10533    
10534                    return count.intValue();
10535            }
10536    
10537            /**
10538             * Returns the number of asset categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
10539             *
10540             * @param groupId the group ID
10541             * @param parentCategoryId the parent category ID
10542             * @param name the name
10543             * @param vocabularyId the vocabulary ID
10544             * @return the number of matching asset categories that the user has permission to view
10545             */
10546            @Override
10547            public int filterCountByG_P_N_V(long groupId, long parentCategoryId,
10548                    String name, long vocabularyId) {
10549                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10550                            return countByG_P_N_V(groupId, parentCategoryId, name, vocabularyId);
10551                    }
10552    
10553                    StringBundler query = new StringBundler(5);
10554    
10555                    query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
10556    
10557                    query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
10558    
10559                    query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
10560    
10561                    boolean bindName = false;
10562    
10563                    if (name == null) {
10564                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
10565                    }
10566                    else if (name.equals(StringPool.BLANK)) {
10567                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
10568                    }
10569                    else {
10570                            bindName = true;
10571    
10572                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
10573                    }
10574    
10575                    query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
10576    
10577                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10578                                    AssetCategory.class.getName(),
10579                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10580    
10581                    Session session = null;
10582    
10583                    try {
10584                            session = openSession();
10585    
10586                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
10587    
10588                            q.addScalar(COUNT_COLUMN_NAME,
10589                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10590    
10591                            QueryPos qPos = QueryPos.getInstance(q);
10592    
10593                            qPos.add(groupId);
10594    
10595                            qPos.add(parentCategoryId);
10596    
10597                            if (bindName) {
10598                                    qPos.add(name);
10599                            }
10600    
10601                            qPos.add(vocabularyId);
10602    
10603                            Long count = (Long)q.uniqueResult();
10604    
10605                            return count.intValue();
10606                    }
10607                    catch (Exception e) {
10608                            throw processException(e);
10609                    }
10610                    finally {
10611                            closeSession(session);
10612                    }
10613            }
10614    
10615            private static final String _FINDER_COLUMN_G_P_N_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
10616            private static final String _FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
10617            private static final String _FINDER_COLUMN_G_P_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
10618            private static final String _FINDER_COLUMN_G_P_N_V_NAME_2 = "assetCategory.name = ? AND ";
10619            private static final String _FINDER_COLUMN_G_P_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = '') AND ";
10620            private static final String _FINDER_COLUMN_G_P_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
10621    
10622            public AssetCategoryPersistenceImpl() {
10623                    setModelClass(AssetCategory.class);
10624            }
10625    
10626            /**
10627             * Caches the asset category in the entity cache if it is enabled.
10628             *
10629             * @param assetCategory the asset category
10630             */
10631            @Override
10632            public void cacheResult(AssetCategory assetCategory) {
10633                    entityCache.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
10634                            AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
10635                            assetCategory);
10636    
10637                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
10638                            new Object[] { assetCategory.getUuid(), assetCategory.getGroupId() },
10639                            assetCategory);
10640    
10641                    finderCache.putResult(FINDER_PATH_FETCH_BY_P_N_V,
10642                            new Object[] {
10643                                    assetCategory.getParentCategoryId(), assetCategory.getName(),
10644                                    assetCategory.getVocabularyId()
10645                            }, assetCategory);
10646    
10647                    assetCategory.resetOriginalValues();
10648            }
10649    
10650            /**
10651             * Caches the asset categories in the entity cache if it is enabled.
10652             *
10653             * @param assetCategories the asset categories
10654             */
10655            @Override
10656            public void cacheResult(List<AssetCategory> assetCategories) {
10657                    for (AssetCategory assetCategory : assetCategories) {
10658                            if (entityCache.getResult(
10659                                                    AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
10660                                                    AssetCategoryImpl.class, assetCategory.getPrimaryKey()) == null) {
10661                                    cacheResult(assetCategory);
10662                            }
10663                            else {
10664                                    assetCategory.resetOriginalValues();
10665                            }
10666                    }
10667            }
10668    
10669            /**
10670             * Clears the cache for all asset categories.
10671             *
10672             * <p>
10673             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
10674             * </p>
10675             */
10676            @Override
10677            public void clearCache() {
10678                    entityCache.clearCache(AssetCategoryImpl.class);
10679    
10680                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
10681                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10682                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10683            }
10684    
10685            /**
10686             * Clears the cache for the asset category.
10687             *
10688             * <p>
10689             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
10690             * </p>
10691             */
10692            @Override
10693            public void clearCache(AssetCategory assetCategory) {
10694                    entityCache.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
10695                            AssetCategoryImpl.class, assetCategory.getPrimaryKey());
10696    
10697                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10698                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10699    
10700                    clearUniqueFindersCache((AssetCategoryModelImpl)assetCategory);
10701            }
10702    
10703            @Override
10704            public void clearCache(List<AssetCategory> assetCategories) {
10705                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10706                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10707    
10708                    for (AssetCategory assetCategory : assetCategories) {
10709                            entityCache.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
10710                                    AssetCategoryImpl.class, assetCategory.getPrimaryKey());
10711    
10712                            clearUniqueFindersCache((AssetCategoryModelImpl)assetCategory);
10713                    }
10714            }
10715    
10716            protected void cacheUniqueFindersCache(
10717                    AssetCategoryModelImpl assetCategoryModelImpl, boolean isNew) {
10718                    if (isNew) {
10719                            Object[] args = new Object[] {
10720                                            assetCategoryModelImpl.getUuid(),
10721                                            assetCategoryModelImpl.getGroupId()
10722                                    };
10723    
10724                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
10725                                    Long.valueOf(1));
10726                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
10727                                    assetCategoryModelImpl);
10728    
10729                            args = new Object[] {
10730                                            assetCategoryModelImpl.getParentCategoryId(),
10731                                            assetCategoryModelImpl.getName(),
10732                                            assetCategoryModelImpl.getVocabularyId()
10733                                    };
10734    
10735                            finderCache.putResult(FINDER_PATH_COUNT_BY_P_N_V, args,
10736                                    Long.valueOf(1));
10737                            finderCache.putResult(FINDER_PATH_FETCH_BY_P_N_V, args,
10738                                    assetCategoryModelImpl);
10739                    }
10740                    else {
10741                            if ((assetCategoryModelImpl.getColumnBitmask() &
10742                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
10743                                    Object[] args = new Object[] {
10744                                                    assetCategoryModelImpl.getUuid(),
10745                                                    assetCategoryModelImpl.getGroupId()
10746                                            };
10747    
10748                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
10749                                            Long.valueOf(1));
10750                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
10751                                            assetCategoryModelImpl);
10752                            }
10753    
10754                            if ((assetCategoryModelImpl.getColumnBitmask() &
10755                                            FINDER_PATH_FETCH_BY_P_N_V.getColumnBitmask()) != 0) {
10756                                    Object[] args = new Object[] {
10757                                                    assetCategoryModelImpl.getParentCategoryId(),
10758                                                    assetCategoryModelImpl.getName(),
10759                                                    assetCategoryModelImpl.getVocabularyId()
10760                                            };
10761    
10762                                    finderCache.putResult(FINDER_PATH_COUNT_BY_P_N_V, args,
10763                                            Long.valueOf(1));
10764                                    finderCache.putResult(FINDER_PATH_FETCH_BY_P_N_V, args,
10765                                            assetCategoryModelImpl);
10766                            }
10767                    }
10768            }
10769    
10770            protected void clearUniqueFindersCache(
10771                    AssetCategoryModelImpl assetCategoryModelImpl) {
10772                    Object[] args = new Object[] {
10773                                    assetCategoryModelImpl.getUuid(),
10774                                    assetCategoryModelImpl.getGroupId()
10775                            };
10776    
10777                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
10778                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
10779    
10780                    if ((assetCategoryModelImpl.getColumnBitmask() &
10781                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
10782                            args = new Object[] {
10783                                            assetCategoryModelImpl.getOriginalUuid(),
10784                                            assetCategoryModelImpl.getOriginalGroupId()
10785                                    };
10786    
10787                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
10788                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
10789                    }
10790    
10791                    args = new Object[] {
10792                                    assetCategoryModelImpl.getParentCategoryId(),
10793                                    assetCategoryModelImpl.getName(),
10794                                    assetCategoryModelImpl.getVocabularyId()
10795                            };
10796    
10797                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_N_V, args);
10798                    finderCache.removeResult(FINDER_PATH_FETCH_BY_P_N_V, args);
10799    
10800                    if ((assetCategoryModelImpl.getColumnBitmask() &
10801                                    FINDER_PATH_FETCH_BY_P_N_V.getColumnBitmask()) != 0) {
10802                            args = new Object[] {
10803                                            assetCategoryModelImpl.getOriginalParentCategoryId(),
10804                                            assetCategoryModelImpl.getOriginalName(),
10805                                            assetCategoryModelImpl.getOriginalVocabularyId()
10806                                    };
10807    
10808                            finderCache.removeResult(FINDER_PATH_COUNT_BY_P_N_V, args);
10809                            finderCache.removeResult(FINDER_PATH_FETCH_BY_P_N_V, args);
10810                    }
10811            }
10812    
10813            /**
10814             * Creates a new asset category with the primary key. Does not add the asset category to the database.
10815             *
10816             * @param categoryId the primary key for the new asset category
10817             * @return the new asset category
10818             */
10819            @Override
10820            public AssetCategory create(long categoryId) {
10821                    AssetCategory assetCategory = new AssetCategoryImpl();
10822    
10823                    assetCategory.setNew(true);
10824                    assetCategory.setPrimaryKey(categoryId);
10825    
10826                    String uuid = PortalUUIDUtil.generate();
10827    
10828                    assetCategory.setUuid(uuid);
10829    
10830                    assetCategory.setCompanyId(companyProvider.getCompanyId());
10831    
10832                    return assetCategory;
10833            }
10834    
10835            /**
10836             * Removes the asset category with the primary key from the database. Also notifies the appropriate model listeners.
10837             *
10838             * @param categoryId the primary key of the asset category
10839             * @return the asset category that was removed
10840             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
10841             */
10842            @Override
10843            public AssetCategory remove(long categoryId) throws NoSuchCategoryException {
10844                    return remove((Serializable)categoryId);
10845            }
10846    
10847            /**
10848             * Removes the asset category with the primary key from the database. Also notifies the appropriate model listeners.
10849             *
10850             * @param primaryKey the primary key of the asset category
10851             * @return the asset category that was removed
10852             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
10853             */
10854            @Override
10855            public AssetCategory remove(Serializable primaryKey)
10856                    throws NoSuchCategoryException {
10857                    Session session = null;
10858    
10859                    try {
10860                            session = openSession();
10861    
10862                            AssetCategory assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
10863                                            primaryKey);
10864    
10865                            if (assetCategory == null) {
10866                                    if (_log.isWarnEnabled()) {
10867                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
10868                                    }
10869    
10870                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
10871                                            primaryKey);
10872                            }
10873    
10874                            return remove(assetCategory);
10875                    }
10876                    catch (NoSuchCategoryException nsee) {
10877                            throw nsee;
10878                    }
10879                    catch (Exception e) {
10880                            throw processException(e);
10881                    }
10882                    finally {
10883                            closeSession(session);
10884                    }
10885            }
10886    
10887            @Override
10888            protected AssetCategory removeImpl(AssetCategory assetCategory) {
10889                    assetCategory = toUnwrappedModel(assetCategory);
10890    
10891                    assetCategoryToAssetEntryTableMapper.deleteLeftPrimaryKeyTableMappings(assetCategory.getPrimaryKey());
10892    
10893                    Session session = null;
10894    
10895                    try {
10896                            session = openSession();
10897    
10898                            if (rebuildTreeEnabled) {
10899                                    if (session.isDirty()) {
10900                                            session.flush();
10901                                    }
10902    
10903                                    nestedSetsTreeManager.delete(assetCategory);
10904    
10905                                    clearCache();
10906    
10907                                    session.clear();
10908                            }
10909    
10910                            if (!session.contains(assetCategory)) {
10911                                    assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
10912                                                    assetCategory.getPrimaryKeyObj());
10913                            }
10914    
10915                            if (assetCategory != null) {
10916                                    session.delete(assetCategory);
10917                            }
10918                    }
10919                    catch (Exception e) {
10920                            throw processException(e);
10921                    }
10922                    finally {
10923                            closeSession(session);
10924                    }
10925    
10926                    if (assetCategory != null) {
10927                            clearCache(assetCategory);
10928                    }
10929    
10930                    return assetCategory;
10931            }
10932    
10933            @Override
10934            public AssetCategory updateImpl(AssetCategory assetCategory) {
10935                    assetCategory = toUnwrappedModel(assetCategory);
10936    
10937                    boolean isNew = assetCategory.isNew();
10938    
10939                    AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
10940    
10941                    if (Validator.isNull(assetCategory.getUuid())) {
10942                            String uuid = PortalUUIDUtil.generate();
10943    
10944                            assetCategory.setUuid(uuid);
10945                    }
10946    
10947                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
10948    
10949                    Date now = new Date();
10950    
10951                    if (isNew && (assetCategory.getCreateDate() == null)) {
10952                            if (serviceContext == null) {
10953                                    assetCategory.setCreateDate(now);
10954                            }
10955                            else {
10956                                    assetCategory.setCreateDate(serviceContext.getCreateDate(now));
10957                            }
10958                    }
10959    
10960                    if (!assetCategoryModelImpl.hasSetModifiedDate()) {
10961                            if (serviceContext == null) {
10962                                    assetCategory.setModifiedDate(now);
10963                            }
10964                            else {
10965                                    assetCategory.setModifiedDate(serviceContext.getModifiedDate(
10966                                                    now));
10967                            }
10968                    }
10969    
10970                    Session session = null;
10971    
10972                    try {
10973                            session = openSession();
10974    
10975                            if (rebuildTreeEnabled) {
10976                                    if (session.isDirty()) {
10977                                            session.flush();
10978                                    }
10979    
10980                                    if (isNew) {
10981                                            nestedSetsTreeManager.insert(assetCategory,
10982                                                    fetchByPrimaryKey(assetCategory.getParentCategoryId()));
10983                                    }
10984                                    else if (assetCategory.getParentCategoryId() != assetCategoryModelImpl.getOriginalParentCategoryId()) {
10985                                            nestedSetsTreeManager.move(assetCategory,
10986                                                    fetchByPrimaryKey(
10987                                                            assetCategoryModelImpl.getOriginalParentCategoryId()),
10988                                                    fetchByPrimaryKey(assetCategory.getParentCategoryId()));
10989                                    }
10990    
10991                                    clearCache();
10992    
10993                                    session.clear();
10994                            }
10995    
10996                            if (assetCategory.isNew()) {
10997                                    session.save(assetCategory);
10998    
10999                                    assetCategory.setNew(false);
11000                            }
11001                            else {
11002                                    assetCategory = (AssetCategory)session.merge(assetCategory);
11003                            }
11004                    }
11005                    catch (Exception e) {
11006                            throw processException(e);
11007                    }
11008                    finally {
11009                            closeSession(session);
11010                    }
11011    
11012                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11013    
11014                    if (isNew || !AssetCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
11015                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11016                    }
11017    
11018                    else {
11019                            if ((assetCategoryModelImpl.getColumnBitmask() &
11020                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
11021                                    Object[] args = new Object[] {
11022                                                    assetCategoryModelImpl.getOriginalUuid()
11023                                            };
11024    
11025                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
11026                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
11027                                            args);
11028    
11029                                    args = new Object[] { assetCategoryModelImpl.getUuid() };
11030    
11031                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
11032                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
11033                                            args);
11034                            }
11035    
11036                            if ((assetCategoryModelImpl.getColumnBitmask() &
11037                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
11038                                    Object[] args = new Object[] {
11039                                                    assetCategoryModelImpl.getOriginalUuid(),
11040                                                    assetCategoryModelImpl.getOriginalCompanyId()
11041                                            };
11042    
11043                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
11044                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
11045                                            args);
11046    
11047                                    args = new Object[] {
11048                                                    assetCategoryModelImpl.getUuid(),
11049                                                    assetCategoryModelImpl.getCompanyId()
11050                                            };
11051    
11052                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
11053                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
11054                                            args);
11055                            }
11056    
11057                            if ((assetCategoryModelImpl.getColumnBitmask() &
11058                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
11059                                    Object[] args = new Object[] {
11060                                                    assetCategoryModelImpl.getOriginalGroupId()
11061                                            };
11062    
11063                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
11064                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
11065                                            args);
11066    
11067                                    args = new Object[] { assetCategoryModelImpl.getGroupId() };
11068    
11069                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
11070                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
11071                                            args);
11072                            }
11073    
11074                            if ((assetCategoryModelImpl.getColumnBitmask() &
11075                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID.getColumnBitmask()) != 0) {
11076                                    Object[] args = new Object[] {
11077                                                    assetCategoryModelImpl.getOriginalParentCategoryId()
11078                                            };
11079    
11080                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PARENTCATEGORYID,
11081                                            args);
11082                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID,
11083                                            args);
11084    
11085                                    args = new Object[] { assetCategoryModelImpl.getParentCategoryId() };
11086    
11087                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_PARENTCATEGORYID,
11088                                            args);
11089                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID,
11090                                            args);
11091                            }
11092    
11093                            if ((assetCategoryModelImpl.getColumnBitmask() &
11094                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID.getColumnBitmask()) != 0) {
11095                                    Object[] args = new Object[] {
11096                                                    assetCategoryModelImpl.getOriginalVocabularyId()
11097                                            };
11098    
11099                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_VOCABULARYID, args);
11100                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID,
11101                                            args);
11102    
11103                                    args = new Object[] { assetCategoryModelImpl.getVocabularyId() };
11104    
11105                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_VOCABULARYID, args);
11106                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID,
11107                                            args);
11108                            }
11109    
11110                            if ((assetCategoryModelImpl.getColumnBitmask() &
11111                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V.getColumnBitmask()) != 0) {
11112                                    Object[] args = new Object[] {
11113                                                    assetCategoryModelImpl.getOriginalGroupId(),
11114                                                    assetCategoryModelImpl.getOriginalVocabularyId()
11115                                            };
11116    
11117                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_V, args);
11118                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V,
11119                                            args);
11120    
11121                                    args = new Object[] {
11122                                                    assetCategoryModelImpl.getGroupId(),
11123                                                    assetCategoryModelImpl.getVocabularyId()
11124                                            };
11125    
11126                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_V, args);
11127                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V,
11128                                            args);
11129                            }
11130    
11131                            if ((assetCategoryModelImpl.getColumnBitmask() &
11132                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
11133                                    Object[] args = new Object[] {
11134                                                    assetCategoryModelImpl.getOriginalParentCategoryId(),
11135                                                    assetCategoryModelImpl.getOriginalName()
11136                                            };
11137    
11138                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
11139                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
11140                                            args);
11141    
11142                                    args = new Object[] {
11143                                                    assetCategoryModelImpl.getParentCategoryId(),
11144                                                    assetCategoryModelImpl.getName()
11145                                            };
11146    
11147                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
11148                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
11149                                            args);
11150                            }
11151    
11152                            if ((assetCategoryModelImpl.getColumnBitmask() &
11153                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V.getColumnBitmask()) != 0) {
11154                                    Object[] args = new Object[] {
11155                                                    assetCategoryModelImpl.getOriginalParentCategoryId(),
11156                                                    assetCategoryModelImpl.getOriginalVocabularyId()
11157                                            };
11158    
11159                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_V, args);
11160                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V,
11161                                            args);
11162    
11163                                    args = new Object[] {
11164                                                    assetCategoryModelImpl.getParentCategoryId(),
11165                                                    assetCategoryModelImpl.getVocabularyId()
11166                                            };
11167    
11168                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_P_V, args);
11169                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V,
11170                                            args);
11171                            }
11172    
11173                            if ((assetCategoryModelImpl.getColumnBitmask() &
11174                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V.getColumnBitmask()) != 0) {
11175                                    Object[] args = new Object[] {
11176                                                    assetCategoryModelImpl.getOriginalName(),
11177                                                    assetCategoryModelImpl.getOriginalVocabularyId()
11178                                            };
11179    
11180                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_N_V, args);
11181                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V,
11182                                            args);
11183    
11184                                    args = new Object[] {
11185                                                    assetCategoryModelImpl.getName(),
11186                                                    assetCategoryModelImpl.getVocabularyId()
11187                                            };
11188    
11189                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_N_V, args);
11190                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V,
11191                                            args);
11192                            }
11193    
11194                            if ((assetCategoryModelImpl.getColumnBitmask() &
11195                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_V.getColumnBitmask()) != 0) {
11196                                    Object[] args = new Object[] {
11197                                                    assetCategoryModelImpl.getOriginalGroupId(),
11198                                                    assetCategoryModelImpl.getOriginalParentCategoryId(),
11199                                                    assetCategoryModelImpl.getOriginalVocabularyId()
11200                                            };
11201    
11202                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_V, args);
11203                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_V,
11204                                            args);
11205    
11206                                    args = new Object[] {
11207                                                    assetCategoryModelImpl.getGroupId(),
11208                                                    assetCategoryModelImpl.getParentCategoryId(),
11209                                                    assetCategoryModelImpl.getVocabularyId()
11210                                            };
11211    
11212                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_V, args);
11213                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_V,
11214                                            args);
11215                            }
11216    
11217                            if ((assetCategoryModelImpl.getColumnBitmask() &
11218                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V.getColumnBitmask()) != 0) {
11219                                    Object[] args = new Object[] {
11220                                                    assetCategoryModelImpl.getOriginalGroupId(),
11221                                                    assetCategoryModelImpl.getOriginalParentCategoryId(),
11222                                                    assetCategoryModelImpl.getOriginalName(),
11223                                                    assetCategoryModelImpl.getOriginalVocabularyId()
11224                                            };
11225    
11226                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_N_V, args);
11227                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V,
11228                                            args);
11229    
11230                                    args = new Object[] {
11231                                                    assetCategoryModelImpl.getGroupId(),
11232                                                    assetCategoryModelImpl.getParentCategoryId(),
11233                                                    assetCategoryModelImpl.getName(),
11234                                                    assetCategoryModelImpl.getVocabularyId()
11235                                            };
11236    
11237                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_N_V, args);
11238                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V,
11239                                            args);
11240                            }
11241                    }
11242    
11243                    entityCache.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
11244                            AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
11245                            assetCategory, false);
11246    
11247                    clearUniqueFindersCache(assetCategoryModelImpl);
11248                    cacheUniqueFindersCache(assetCategoryModelImpl, isNew);
11249    
11250                    assetCategory.resetOriginalValues();
11251    
11252                    return assetCategory;
11253            }
11254    
11255            protected AssetCategory toUnwrappedModel(AssetCategory assetCategory) {
11256                    if (assetCategory instanceof AssetCategoryImpl) {
11257                            return assetCategory;
11258                    }
11259    
11260                    AssetCategoryImpl assetCategoryImpl = new AssetCategoryImpl();
11261    
11262                    assetCategoryImpl.setNew(assetCategory.isNew());
11263                    assetCategoryImpl.setPrimaryKey(assetCategory.getPrimaryKey());
11264    
11265                    assetCategoryImpl.setUuid(assetCategory.getUuid());
11266                    assetCategoryImpl.setCategoryId(assetCategory.getCategoryId());
11267                    assetCategoryImpl.setGroupId(assetCategory.getGroupId());
11268                    assetCategoryImpl.setCompanyId(assetCategory.getCompanyId());
11269                    assetCategoryImpl.setUserId(assetCategory.getUserId());
11270                    assetCategoryImpl.setUserName(assetCategory.getUserName());
11271                    assetCategoryImpl.setCreateDate(assetCategory.getCreateDate());
11272                    assetCategoryImpl.setModifiedDate(assetCategory.getModifiedDate());
11273                    assetCategoryImpl.setParentCategoryId(assetCategory.getParentCategoryId());
11274                    assetCategoryImpl.setLeftCategoryId(assetCategory.getLeftCategoryId());
11275                    assetCategoryImpl.setRightCategoryId(assetCategory.getRightCategoryId());
11276                    assetCategoryImpl.setName(assetCategory.getName());
11277                    assetCategoryImpl.setTitle(assetCategory.getTitle());
11278                    assetCategoryImpl.setDescription(assetCategory.getDescription());
11279                    assetCategoryImpl.setVocabularyId(assetCategory.getVocabularyId());
11280                    assetCategoryImpl.setLastPublishDate(assetCategory.getLastPublishDate());
11281    
11282                    return assetCategoryImpl;
11283            }
11284    
11285            /**
11286             * Returns the asset category with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
11287             *
11288             * @param primaryKey the primary key of the asset category
11289             * @return the asset category
11290             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
11291             */
11292            @Override
11293            public AssetCategory findByPrimaryKey(Serializable primaryKey)
11294                    throws NoSuchCategoryException {
11295                    AssetCategory assetCategory = fetchByPrimaryKey(primaryKey);
11296    
11297                    if (assetCategory == null) {
11298                            if (_log.isWarnEnabled()) {
11299                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
11300                            }
11301    
11302                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
11303                                    primaryKey);
11304                    }
11305    
11306                    return assetCategory;
11307            }
11308    
11309            /**
11310             * Returns the asset category with the primary key or throws a {@link NoSuchCategoryException} if it could not be found.
11311             *
11312             * @param categoryId the primary key of the asset category
11313             * @return the asset category
11314             * @throws NoSuchCategoryException if a asset category with the primary key could not be found
11315             */
11316            @Override
11317            public AssetCategory findByPrimaryKey(long categoryId)
11318                    throws NoSuchCategoryException {
11319                    return findByPrimaryKey((Serializable)categoryId);
11320            }
11321    
11322            /**
11323             * Returns the asset category with the primary key or returns <code>null</code> if it could not be found.
11324             *
11325             * @param primaryKey the primary key of the asset category
11326             * @return the asset category, or <code>null</code> if a asset category with the primary key could not be found
11327             */
11328            @Override
11329            public AssetCategory fetchByPrimaryKey(Serializable primaryKey) {
11330                    AssetCategory assetCategory = (AssetCategory)entityCache.getResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
11331                                    AssetCategoryImpl.class, primaryKey);
11332    
11333                    if (assetCategory == _nullAssetCategory) {
11334                            return null;
11335                    }
11336    
11337                    if (assetCategory == null) {
11338                            Session session = null;
11339    
11340                            try {
11341                                    session = openSession();
11342    
11343                                    assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
11344                                                    primaryKey);
11345    
11346                                    if (assetCategory != null) {
11347                                            cacheResult(assetCategory);
11348                                    }
11349                                    else {
11350                                            entityCache.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
11351                                                    AssetCategoryImpl.class, primaryKey, _nullAssetCategory);
11352                                    }
11353                            }
11354                            catch (Exception e) {
11355                                    entityCache.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
11356                                            AssetCategoryImpl.class, primaryKey);
11357    
11358                                    throw processException(e);
11359                            }
11360                            finally {
11361                                    closeSession(session);
11362                            }
11363                    }
11364    
11365                    return assetCategory;
11366            }
11367    
11368            /**
11369             * Returns the asset category with the primary key or returns <code>null</code> if it could not be found.
11370             *
11371             * @param categoryId the primary key of the asset category
11372             * @return the asset category, or <code>null</code> if a asset category with the primary key could not be found
11373             */
11374            @Override
11375            public AssetCategory fetchByPrimaryKey(long categoryId) {
11376                    return fetchByPrimaryKey((Serializable)categoryId);
11377            }
11378    
11379            @Override
11380            public Map<Serializable, AssetCategory> fetchByPrimaryKeys(
11381                    Set<Serializable> primaryKeys) {
11382                    if (primaryKeys.isEmpty()) {
11383                            return Collections.emptyMap();
11384                    }
11385    
11386                    Map<Serializable, AssetCategory> map = new HashMap<Serializable, AssetCategory>();
11387    
11388                    if (primaryKeys.size() == 1) {
11389                            Iterator<Serializable> iterator = primaryKeys.iterator();
11390    
11391                            Serializable primaryKey = iterator.next();
11392    
11393                            AssetCategory assetCategory = fetchByPrimaryKey(primaryKey);
11394    
11395                            if (assetCategory != null) {
11396                                    map.put(primaryKey, assetCategory);
11397                            }
11398    
11399                            return map;
11400                    }
11401    
11402                    Set<Serializable> uncachedPrimaryKeys = null;
11403    
11404                    for (Serializable primaryKey : primaryKeys) {
11405                            AssetCategory assetCategory = (AssetCategory)entityCache.getResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
11406                                            AssetCategoryImpl.class, primaryKey);
11407    
11408                            if (assetCategory == null) {
11409                                    if (uncachedPrimaryKeys == null) {
11410                                            uncachedPrimaryKeys = new HashSet<Serializable>();
11411                                    }
11412    
11413                                    uncachedPrimaryKeys.add(primaryKey);
11414                            }
11415                            else {
11416                                    map.put(primaryKey, assetCategory);
11417                            }
11418                    }
11419    
11420                    if (uncachedPrimaryKeys == null) {
11421                            return map;
11422                    }
11423    
11424                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
11425                                    1);
11426    
11427                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE_PKS_IN);
11428    
11429                    for (Serializable primaryKey : uncachedPrimaryKeys) {
11430                            query.append(String.valueOf(primaryKey));
11431    
11432                            query.append(StringPool.COMMA);
11433                    }
11434    
11435                    query.setIndex(query.index() - 1);
11436    
11437                    query.append(StringPool.CLOSE_PARENTHESIS);
11438    
11439                    String sql = query.toString();
11440    
11441                    Session session = null;
11442    
11443                    try {
11444                            session = openSession();
11445    
11446                            Query q = session.createQuery(sql);
11447    
11448                            for (AssetCategory assetCategory : (List<AssetCategory>)q.list()) {
11449                                    map.put(assetCategory.getPrimaryKeyObj(), assetCategory);
11450    
11451                                    cacheResult(assetCategory);
11452    
11453                                    uncachedPrimaryKeys.remove(assetCategory.getPrimaryKeyObj());
11454                            }
11455    
11456                            for (Serializable primaryKey : uncachedPrimaryKeys) {
11457                                    entityCache.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
11458                                            AssetCategoryImpl.class, primaryKey, _nullAssetCategory);
11459                            }
11460                    }
11461                    catch (Exception e) {
11462                            throw processException(e);
11463                    }
11464                    finally {
11465                            closeSession(session);
11466                    }
11467    
11468                    return map;
11469            }
11470    
11471            /**
11472             * Returns all the asset categories.
11473             *
11474             * @return the asset categories
11475             */
11476            @Override
11477            public List<AssetCategory> findAll() {
11478                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11479            }
11480    
11481            /**
11482             * Returns a range of all the asset categories.
11483             *
11484             * <p>
11485             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11486             * </p>
11487             *
11488             * @param start the lower bound of the range of asset categories
11489             * @param end the upper bound of the range of asset categories (not inclusive)
11490             * @return the range of asset categories
11491             */
11492            @Override
11493            public List<AssetCategory> findAll(int start, int end) {
11494                    return findAll(start, end, null);
11495            }
11496    
11497            /**
11498             * Returns an ordered range of all the asset categories.
11499             *
11500             * <p>
11501             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11502             * </p>
11503             *
11504             * @param start the lower bound of the range of asset categories
11505             * @param end the upper bound of the range of asset categories (not inclusive)
11506             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11507             * @return the ordered range of asset categories
11508             */
11509            @Override
11510            public List<AssetCategory> findAll(int start, int end,
11511                    OrderByComparator<AssetCategory> orderByComparator) {
11512                    return findAll(start, end, orderByComparator, true);
11513            }
11514    
11515            /**
11516             * Returns an ordered range of all the asset categories.
11517             *
11518             * <p>
11519             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11520             * </p>
11521             *
11522             * @param start the lower bound of the range of asset categories
11523             * @param end the upper bound of the range of asset categories (not inclusive)
11524             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11525             * @param retrieveFromCache whether to retrieve from the finder cache
11526             * @return the ordered range of asset categories
11527             */
11528            @Override
11529            public List<AssetCategory> findAll(int start, int end,
11530                    OrderByComparator<AssetCategory> orderByComparator,
11531                    boolean retrieveFromCache) {
11532                    boolean pagination = true;
11533                    FinderPath finderPath = null;
11534                    Object[] finderArgs = null;
11535    
11536                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11537                                    (orderByComparator == null)) {
11538                            pagination = false;
11539                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
11540                            finderArgs = FINDER_ARGS_EMPTY;
11541                    }
11542                    else {
11543                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
11544                            finderArgs = new Object[] { start, end, orderByComparator };
11545                    }
11546    
11547                    List<AssetCategory> list = null;
11548    
11549                    if (retrieveFromCache) {
11550                            list = (List<AssetCategory>)finderCache.getResult(finderPath,
11551                                            finderArgs, this);
11552                    }
11553    
11554                    if (list == null) {
11555                            StringBundler query = null;
11556                            String sql = null;
11557    
11558                            if (orderByComparator != null) {
11559                                    query = new StringBundler(2 +
11560                                                    (orderByComparator.getOrderByFields().length * 3));
11561    
11562                                    query.append(_SQL_SELECT_ASSETCATEGORY);
11563    
11564                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11565                                            orderByComparator);
11566    
11567                                    sql = query.toString();
11568                            }
11569                            else {
11570                                    sql = _SQL_SELECT_ASSETCATEGORY;
11571    
11572                                    if (pagination) {
11573                                            sql = sql.concat(AssetCategoryModelImpl.ORDER_BY_JPQL);
11574                                    }
11575                            }
11576    
11577                            Session session = null;
11578    
11579                            try {
11580                                    session = openSession();
11581    
11582                                    Query q = session.createQuery(sql);
11583    
11584                                    if (!pagination) {
11585                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
11586                                                            start, end, false);
11587    
11588                                            Collections.sort(list);
11589    
11590                                            list = Collections.unmodifiableList(list);
11591                                    }
11592                                    else {
11593                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
11594                                                            start, end);
11595                                    }
11596    
11597                                    cacheResult(list);
11598    
11599                                    finderCache.putResult(finderPath, finderArgs, list);
11600                            }
11601                            catch (Exception e) {
11602                                    finderCache.removeResult(finderPath, finderArgs);
11603    
11604                                    throw processException(e);
11605                            }
11606                            finally {
11607                                    closeSession(session);
11608                            }
11609                    }
11610    
11611                    return list;
11612            }
11613    
11614            /**
11615             * Removes all the asset categories from the database.
11616             *
11617             */
11618            @Override
11619            public void removeAll() {
11620                    for (AssetCategory assetCategory : findAll()) {
11621                            remove(assetCategory);
11622                    }
11623            }
11624    
11625            /**
11626             * Returns the number of asset categories.
11627             *
11628             * @return the number of asset categories
11629             */
11630            @Override
11631            public int countAll() {
11632                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
11633                                    FINDER_ARGS_EMPTY, this);
11634    
11635                    if (count == null) {
11636                            Session session = null;
11637    
11638                            try {
11639                                    session = openSession();
11640    
11641                                    Query q = session.createQuery(_SQL_COUNT_ASSETCATEGORY);
11642    
11643                                    count = (Long)q.uniqueResult();
11644    
11645                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
11646                                            count);
11647                            }
11648                            catch (Exception e) {
11649                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
11650                                            FINDER_ARGS_EMPTY);
11651    
11652                                    throw processException(e);
11653                            }
11654                            finally {
11655                                    closeSession(session);
11656                            }
11657                    }
11658    
11659                    return count.intValue();
11660            }
11661    
11662            /**
11663             * Returns the primaryKeys of asset entries associated with the asset category.
11664             *
11665             * @param pk the primary key of the asset category
11666             * @return long[] of the primaryKeys of asset entries associated with the asset category
11667             */
11668            @Override
11669            public long[] getAssetEntryPrimaryKeys(long pk) {
11670                    long[] pks = assetCategoryToAssetEntryTableMapper.getRightPrimaryKeys(pk);
11671    
11672                    return pks.clone();
11673            }
11674    
11675            /**
11676             * Returns all the asset entries associated with the asset category.
11677             *
11678             * @param pk the primary key of the asset category
11679             * @return the asset entries associated with the asset category
11680             */
11681            @Override
11682            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
11683                    long pk) {
11684                    return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
11685            }
11686    
11687            /**
11688             * Returns a range of all the asset entries associated with the asset category.
11689             *
11690             * <p>
11691             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11692             * </p>
11693             *
11694             * @param pk the primary key of the asset category
11695             * @param start the lower bound of the range of asset categories
11696             * @param end the upper bound of the range of asset categories (not inclusive)
11697             * @return the range of asset entries associated with the asset category
11698             */
11699            @Override
11700            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
11701                    long pk, int start, int end) {
11702                    return getAssetEntries(pk, start, end, null);
11703            }
11704    
11705            /**
11706             * Returns an ordered range of all the asset entries associated with the asset category.
11707             *
11708             * <p>
11709             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11710             * </p>
11711             *
11712             * @param pk the primary key of the asset category
11713             * @param start the lower bound of the range of asset categories
11714             * @param end the upper bound of the range of asset categories (not inclusive)
11715             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11716             * @return the ordered range of asset entries associated with the asset category
11717             */
11718            @Override
11719            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
11720                    long pk, int start, int end,
11721                    OrderByComparator<com.liferay.portlet.asset.model.AssetEntry> orderByComparator) {
11722                    return assetCategoryToAssetEntryTableMapper.getRightBaseModels(pk,
11723                            start, end, orderByComparator);
11724            }
11725    
11726            /**
11727             * Returns the number of asset entries associated with the asset category.
11728             *
11729             * @param pk the primary key of the asset category
11730             * @return the number of asset entries associated with the asset category
11731             */
11732            @Override
11733            public int getAssetEntriesSize(long pk) {
11734                    long[] pks = assetCategoryToAssetEntryTableMapper.getRightPrimaryKeys(pk);
11735    
11736                    return pks.length;
11737            }
11738    
11739            /**
11740             * Returns <code>true</code> if the asset entry is associated with the asset category.
11741             *
11742             * @param pk the primary key of the asset category
11743             * @param assetEntryPK the primary key of the asset entry
11744             * @return <code>true</code> if the asset entry is associated with the asset category; <code>false</code> otherwise
11745             */
11746            @Override
11747            public boolean containsAssetEntry(long pk, long assetEntryPK) {
11748                    return assetCategoryToAssetEntryTableMapper.containsTableMapping(pk,
11749                            assetEntryPK);
11750            }
11751    
11752            /**
11753             * Returns <code>true</code> if the asset category has any asset entries associated with it.
11754             *
11755             * @param pk the primary key of the asset category to check for associations with asset entries
11756             * @return <code>true</code> if the asset category has any asset entries associated with it; <code>false</code> otherwise
11757             */
11758            @Override
11759            public boolean containsAssetEntries(long pk) {
11760                    if (getAssetEntriesSize(pk) > 0) {
11761                            return true;
11762                    }
11763                    else {
11764                            return false;
11765                    }
11766            }
11767    
11768            /**
11769             * Adds an association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11770             *
11771             * @param pk the primary key of the asset category
11772             * @param assetEntryPK the primary key of the asset entry
11773             */
11774            @Override
11775            public void addAssetEntry(long pk, long assetEntryPK) {
11776                    AssetCategory assetCategory = fetchByPrimaryKey(pk);
11777    
11778                    if (assetCategory == null) {
11779                            assetCategoryToAssetEntryTableMapper.addTableMapping(companyProvider.getCompanyId(),
11780                                    pk, assetEntryPK);
11781                    }
11782                    else {
11783                            assetCategoryToAssetEntryTableMapper.addTableMapping(assetCategory.getCompanyId(),
11784                                    pk, assetEntryPK);
11785                    }
11786            }
11787    
11788            /**
11789             * Adds an association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11790             *
11791             * @param pk the primary key of the asset category
11792             * @param assetEntry the asset entry
11793             */
11794            @Override
11795            public void addAssetEntry(long pk,
11796                    com.liferay.portlet.asset.model.AssetEntry assetEntry) {
11797                    AssetCategory assetCategory = fetchByPrimaryKey(pk);
11798    
11799                    if (assetCategory == null) {
11800                            assetCategoryToAssetEntryTableMapper.addTableMapping(companyProvider.getCompanyId(),
11801                                    pk, assetEntry.getPrimaryKey());
11802                    }
11803                    else {
11804                            assetCategoryToAssetEntryTableMapper.addTableMapping(assetCategory.getCompanyId(),
11805                                    pk, assetEntry.getPrimaryKey());
11806                    }
11807            }
11808    
11809            /**
11810             * Adds an association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11811             *
11812             * @param pk the primary key of the asset category
11813             * @param assetEntryPKs the primary keys of the asset entries
11814             */
11815            @Override
11816            public void addAssetEntries(long pk, long[] assetEntryPKs) {
11817                    long companyId = 0;
11818    
11819                    AssetCategory assetCategory = fetchByPrimaryKey(pk);
11820    
11821                    if (assetCategory == null) {
11822                            companyId = companyProvider.getCompanyId();
11823                    }
11824                    else {
11825                            companyId = assetCategory.getCompanyId();
11826                    }
11827    
11828                    for (long assetEntryPK : assetEntryPKs) {
11829                            assetCategoryToAssetEntryTableMapper.addTableMapping(companyId, pk,
11830                                    assetEntryPK);
11831                    }
11832            }
11833    
11834            /**
11835             * Adds an association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11836             *
11837             * @param pk the primary key of the asset category
11838             * @param assetEntries the asset entries
11839             */
11840            @Override
11841            public void addAssetEntries(long pk,
11842                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries) {
11843                    long companyId = 0;
11844    
11845                    AssetCategory assetCategory = fetchByPrimaryKey(pk);
11846    
11847                    if (assetCategory == null) {
11848                            companyId = companyProvider.getCompanyId();
11849                    }
11850                    else {
11851                            companyId = assetCategory.getCompanyId();
11852                    }
11853    
11854                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
11855                            assetCategoryToAssetEntryTableMapper.addTableMapping(companyId, pk,
11856                                    assetEntry.getPrimaryKey());
11857                    }
11858            }
11859    
11860            /**
11861             * Clears all associations between the asset category and its asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11862             *
11863             * @param pk the primary key of the asset category to clear the associated asset entries from
11864             */
11865            @Override
11866            public void clearAssetEntries(long pk) {
11867                    assetCategoryToAssetEntryTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
11868            }
11869    
11870            /**
11871             * Removes the association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11872             *
11873             * @param pk the primary key of the asset category
11874             * @param assetEntryPK the primary key of the asset entry
11875             */
11876            @Override
11877            public void removeAssetEntry(long pk, long assetEntryPK) {
11878                    assetCategoryToAssetEntryTableMapper.deleteTableMapping(pk, assetEntryPK);
11879            }
11880    
11881            /**
11882             * Removes the association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11883             *
11884             * @param pk the primary key of the asset category
11885             * @param assetEntry the asset entry
11886             */
11887            @Override
11888            public void removeAssetEntry(long pk,
11889                    com.liferay.portlet.asset.model.AssetEntry assetEntry) {
11890                    assetCategoryToAssetEntryTableMapper.deleteTableMapping(pk,
11891                            assetEntry.getPrimaryKey());
11892            }
11893    
11894            /**
11895             * Removes the association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11896             *
11897             * @param pk the primary key of the asset category
11898             * @param assetEntryPKs the primary keys of the asset entries
11899             */
11900            @Override
11901            public void removeAssetEntries(long pk, long[] assetEntryPKs) {
11902                    for (long assetEntryPK : assetEntryPKs) {
11903                            assetCategoryToAssetEntryTableMapper.deleteTableMapping(pk,
11904                                    assetEntryPK);
11905                    }
11906            }
11907    
11908            /**
11909             * Removes the association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11910             *
11911             * @param pk the primary key of the asset category
11912             * @param assetEntries the asset entries
11913             */
11914            @Override
11915            public void removeAssetEntries(long pk,
11916                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries) {
11917                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
11918                            assetCategoryToAssetEntryTableMapper.deleteTableMapping(pk,
11919                                    assetEntry.getPrimaryKey());
11920                    }
11921            }
11922    
11923            /**
11924             * Sets the asset entries associated with the asset category, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11925             *
11926             * @param pk the primary key of the asset category
11927             * @param assetEntryPKs the primary keys of the asset entries to be associated with the asset category
11928             */
11929            @Override
11930            public void setAssetEntries(long pk, long[] assetEntryPKs) {
11931                    Set<Long> newAssetEntryPKsSet = SetUtil.fromArray(assetEntryPKs);
11932                    Set<Long> oldAssetEntryPKsSet = SetUtil.fromArray(assetCategoryToAssetEntryTableMapper.getRightPrimaryKeys(
11933                                            pk));
11934    
11935                    Set<Long> removeAssetEntryPKsSet = new HashSet<Long>(oldAssetEntryPKsSet);
11936    
11937                    removeAssetEntryPKsSet.removeAll(newAssetEntryPKsSet);
11938    
11939                    for (long removeAssetEntryPK : removeAssetEntryPKsSet) {
11940                            assetCategoryToAssetEntryTableMapper.deleteTableMapping(pk,
11941                                    removeAssetEntryPK);
11942                    }
11943    
11944                    newAssetEntryPKsSet.removeAll(oldAssetEntryPKsSet);
11945    
11946                    long companyId = 0;
11947    
11948                    AssetCategory assetCategory = fetchByPrimaryKey(pk);
11949    
11950                    if (assetCategory == null) {
11951                            companyId = companyProvider.getCompanyId();
11952                    }
11953                    else {
11954                            companyId = assetCategory.getCompanyId();
11955                    }
11956    
11957                    for (long newAssetEntryPK : newAssetEntryPKsSet) {
11958                            assetCategoryToAssetEntryTableMapper.addTableMapping(companyId, pk,
11959                                    newAssetEntryPK);
11960                    }
11961            }
11962    
11963            /**
11964             * Sets the asset entries associated with the asset category, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
11965             *
11966             * @param pk the primary key of the asset category
11967             * @param assetEntries the asset entries to be associated with the asset category
11968             */
11969            @Override
11970            public void setAssetEntries(long pk,
11971                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries) {
11972                    try {
11973                            long[] assetEntryPKs = new long[assetEntries.size()];
11974    
11975                            for (int i = 0; i < assetEntries.size(); i++) {
11976                                    com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
11977    
11978                                    assetEntryPKs[i] = assetEntry.getPrimaryKey();
11979                            }
11980    
11981                            setAssetEntries(pk, assetEntryPKs);
11982                    }
11983                    catch (Exception e) {
11984                            throw processException(e);
11985                    }
11986            }
11987    
11988            @Override
11989            public Set<String> getBadColumnNames() {
11990                    return _badColumnNames;
11991            }
11992    
11993            @Override
11994            protected Map<String, Integer> getTableColumnsMap() {
11995                    return AssetCategoryModelImpl.TABLE_COLUMNS_MAP;
11996            }
11997    
11998            @Override
11999            public long countAncestors(AssetCategory assetCategory) {
12000                    Object[] finderArgs = new Object[] {
12001                                    assetCategory.getGroupId(), assetCategory.getLeftCategoryId(),
12002                                    assetCategory.getRightCategoryId()
12003                            };
12004    
12005                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_ANCESTORS,
12006                                    finderArgs, this);
12007    
12008                    if (count == null) {
12009                            try {
12010                                    count = nestedSetsTreeManager.countAncestors(assetCategory);
12011    
12012                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_ANCESTORS,
12013                                            finderArgs, count);
12014                            }
12015                            catch (SystemException se) {
12016                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_ANCESTORS,
12017                                            finderArgs);
12018    
12019                                    throw se;
12020                            }
12021                    }
12022    
12023                    return count.intValue();
12024            }
12025    
12026            @Override
12027            public long countDescendants(AssetCategory assetCategory) {
12028                    Object[] finderArgs = new Object[] {
12029                                    assetCategory.getGroupId(), assetCategory.getLeftCategoryId(),
12030                                    assetCategory.getRightCategoryId()
12031                            };
12032    
12033                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_DESCENDANTS,
12034                                    finderArgs, this);
12035    
12036                    if (count == null) {
12037                            try {
12038                                    count = nestedSetsTreeManager.countDescendants(assetCategory);
12039    
12040                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_DESCENDANTS,
12041                                            finderArgs, count);
12042                            }
12043                            catch (SystemException se) {
12044                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_DESCENDANTS,
12045                                            finderArgs);
12046    
12047                                    throw se;
12048                            }
12049                    }
12050    
12051                    return count.intValue();
12052            }
12053    
12054            @Override
12055            public List<AssetCategory> getAncestors(AssetCategory assetCategory) {
12056                    Object[] finderArgs = new Object[] {
12057                                    assetCategory.getGroupId(), assetCategory.getLeftCategoryId(),
12058                                    assetCategory.getRightCategoryId()
12059                            };
12060    
12061                    List<AssetCategory> list = (List<AssetCategory>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_GET_ANCESTORS,
12062                                    finderArgs, this);
12063    
12064                    if ((list != null) && !list.isEmpty()) {
12065                            for (AssetCategory tempAssetCategory : list) {
12066                                    if ((assetCategory.getLeftCategoryId() < tempAssetCategory.getLeftCategoryId()) ||
12067                                                    (assetCategory.getRightCategoryId() > tempAssetCategory.getRightCategoryId())) {
12068                                            list = null;
12069    
12070                                            break;
12071                                    }
12072                            }
12073                    }
12074    
12075                    if (list == null) {
12076                            try {
12077                                    list = nestedSetsTreeManager.getAncestors(assetCategory);
12078    
12079                                    cacheResult(list);
12080    
12081                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_GET_ANCESTORS,
12082                                            finderArgs, list);
12083                            }
12084                            catch (SystemException se) {
12085                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_GET_ANCESTORS,
12086                                            finderArgs);
12087    
12088                                    throw se;
12089                            }
12090                    }
12091    
12092                    return list;
12093            }
12094    
12095            @Override
12096            public List<AssetCategory> getDescendants(AssetCategory assetCategory) {
12097                    Object[] finderArgs = new Object[] {
12098                                    assetCategory.getGroupId(), assetCategory.getLeftCategoryId(),
12099                                    assetCategory.getRightCategoryId()
12100                            };
12101    
12102                    List<AssetCategory> list = (List<AssetCategory>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_GET_DESCENDANTS,
12103                                    finderArgs, this);
12104    
12105                    if ((list != null) && !list.isEmpty()) {
12106                            for (AssetCategory tempAssetCategory : list) {
12107                                    if ((assetCategory.getLeftCategoryId() > tempAssetCategory.getLeftCategoryId()) ||
12108                                                    (assetCategory.getRightCategoryId() < tempAssetCategory.getRightCategoryId())) {
12109                                            list = null;
12110    
12111                                            break;
12112                                    }
12113                            }
12114                    }
12115    
12116                    if (list == null) {
12117                            try {
12118                                    list = nestedSetsTreeManager.getDescendants(assetCategory);
12119    
12120                                    cacheResult(list);
12121    
12122                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_GET_DESCENDANTS,
12123                                            finderArgs, list);
12124                            }
12125                            catch (SystemException se) {
12126                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_GET_DESCENDANTS,
12127                                            finderArgs);
12128    
12129                                    throw se;
12130                            }
12131                    }
12132    
12133                    return list;
12134            }
12135    
12136            /**
12137             * Rebuilds the asset categories tree for the scope using the modified pre-order tree traversal algorithm.
12138             *
12139             * <p>
12140             * Only call this method if the tree has become stale through operations other than normal CRUD. Under normal circumstances the tree is automatically rebuilt whenver necessary.
12141             * </p>
12142             *
12143             * @param groupId the ID of the scope
12144             * @param force whether to force the rebuild even if the tree is not stale
12145             */
12146            @Override
12147            public void rebuildTree(long groupId, boolean force) {
12148                    if (!rebuildTreeEnabled) {
12149                            return;
12150                    }
12151    
12152                    if (force || (countOrphanTreeNodes(groupId) > 0)) {
12153                            Session session = null;
12154    
12155                            try {
12156                                    session = openSession();
12157    
12158                                    if (session.isDirty()) {
12159                                            session.flush();
12160                                    }
12161    
12162                                    SQLQuery selectQuery = session.createSQLQuery(
12163                                                    "SELECT categoryId FROM AssetCategory WHERE groupId = ? AND parentCategoryId = ? ORDER BY categoryId ASC");
12164    
12165                                    selectQuery.addScalar("categoryId",
12166                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
12167    
12168                                    SQLQuery updateQuery = session.createSQLQuery(
12169                                                    "UPDATE AssetCategory SET leftCategoryId = ?, rightCategoryId = ? WHERE categoryId = ?");
12170    
12171                                    rebuildTree(session, selectQuery, updateQuery, groupId, 0, 0);
12172                            }
12173                            catch (Exception e) {
12174                                    throw processException(e);
12175                            }
12176                            finally {
12177                                    closeSession(session);
12178                            }
12179    
12180                            clearCache();
12181                    }
12182            }
12183    
12184            @Override
12185            public void setRebuildTreeEnabled(boolean rebuildTreeEnabled) {
12186                    this.rebuildTreeEnabled = rebuildTreeEnabled;
12187            }
12188    
12189            protected long countOrphanTreeNodes(long groupId) {
12190                    Session session = null;
12191    
12192                    try {
12193                            session = openSession();
12194    
12195                            SQLQuery q = session.createSynchronizedSQLQuery(
12196                                            "SELECT COUNT(*) AS COUNT_VALUE FROM AssetCategory WHERE groupId = ? AND (leftCategoryId = 0 OR leftCategoryId IS NULL OR rightCategoryId = 0 OR rightCategoryId IS NULL)");
12197    
12198                            q.addScalar(COUNT_COLUMN_NAME,
12199                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12200    
12201                            QueryPos qPos = QueryPos.getInstance(q);
12202    
12203                            qPos.add(groupId);
12204    
12205                            return (Long)q.uniqueResult();
12206                    }
12207                    catch (Exception e) {
12208                            throw processException(e);
12209                    }
12210                    finally {
12211                            closeSession(session);
12212                    }
12213            }
12214    
12215            protected long rebuildTree(Session session, SQLQuery selectQuery,
12216                    SQLQuery updateQuery, long groupId, long parentCategoryId,
12217                    long leftCategoryId) {
12218                    long rightCategoryId = leftCategoryId + 1;
12219    
12220                    QueryPos qPos = QueryPos.getInstance(selectQuery);
12221    
12222                    qPos.add(groupId);
12223                    qPos.add(parentCategoryId);
12224    
12225                    List<Long> categoryIds = selectQuery.list();
12226    
12227                    for (long categoryId : categoryIds) {
12228                            rightCategoryId = rebuildTree(session, selectQuery, updateQuery,
12229                                            groupId, categoryId, rightCategoryId);
12230                    }
12231    
12232                    if (parentCategoryId > 0) {
12233                            qPos = QueryPos.getInstance(updateQuery);
12234    
12235                            qPos.add(leftCategoryId);
12236                            qPos.add(rightCategoryId);
12237                            qPos.add(parentCategoryId);
12238    
12239                            updateQuery.executeUpdate();
12240                    }
12241    
12242                    return rightCategoryId + 1;
12243            }
12244    
12245            /**
12246             * Initializes the asset category persistence.
12247             */
12248            public void afterPropertiesSet() {
12249                    assetCategoryToAssetEntryTableMapper = TableMapperFactory.getTableMapper("AssetEntries_AssetCategories",
12250                                    "companyId", "categoryId", "entryId", this,
12251                                    assetEntryPersistence);
12252    
12253                    updateTree = new UpdateTree();
12254            }
12255    
12256            public void destroy() {
12257                    entityCache.removeCache(AssetCategoryImpl.class.getName());
12258                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
12259                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12260                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12261    
12262                    TableMapperFactory.removeTableMapper("AssetEntries_AssetCategories");
12263            }
12264    
12265            @BeanReference(type = CompanyProviderWrapper.class)
12266            protected CompanyProvider companyProvider;
12267            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
12268            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
12269            @BeanReference(type = AssetEntryPersistence.class)
12270            protected AssetEntryPersistence assetEntryPersistence;
12271            protected TableMapper<AssetCategory, com.liferay.portlet.asset.model.AssetEntry> assetCategoryToAssetEntryTableMapper;
12272            protected NestedSetsTreeManager<AssetCategory> nestedSetsTreeManager = new PersistenceNestedSetsTreeManager<AssetCategory>(this,
12273                            "AssetCategory", "AssetCategory", AssetCategoryImpl.class,
12274                            "categoryId", "groupId", "leftCategoryId", "rightCategoryId");
12275            protected boolean rebuildTreeEnabled = true;
12276            protected UpdateTree updateTree;
12277    
12278            protected class UpdateTree {
12279                    protected UpdateTree() {
12280                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
12281                                            "UPDATE AssetCategory SET leftCategoryId = ?, rightCategoryId = ? WHERE categoryId = ?",
12282                                            new int[] {
12283                                                    java.sql.Types.BIGINT, java.sql.Types.BIGINT,
12284                                                    java.sql.Types.BIGINT
12285                                            });
12286                    }
12287    
12288                    protected void update(long categoryId, long leftCategoryId,
12289                            long rightCategoryId) {
12290                            _sqlUpdate.update(new Object[] {
12291                                            leftCategoryId, rightCategoryId, categoryId
12292                                    });
12293                    }
12294    
12295                    private SqlUpdate _sqlUpdate;
12296            }
12297    
12298            private static final String _SQL_SELECT_ASSETCATEGORY = "SELECT assetCategory FROM AssetCategory assetCategory";
12299            private static final String _SQL_SELECT_ASSETCATEGORY_WHERE_PKS_IN = "SELECT assetCategory FROM AssetCategory assetCategory WHERE categoryId IN (";
12300            private static final String _SQL_SELECT_ASSETCATEGORY_WHERE = "SELECT assetCategory FROM AssetCategory assetCategory WHERE ";
12301            private static final String _SQL_COUNT_ASSETCATEGORY = "SELECT COUNT(assetCategory) FROM AssetCategory assetCategory";
12302            private static final String _SQL_COUNT_ASSETCATEGORY_WHERE = "SELECT COUNT(assetCategory) FROM AssetCategory assetCategory WHERE ";
12303            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "assetCategory.categoryId";
12304            private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_WHERE = "SELECT DISTINCT {assetCategory.*} FROM AssetCategory assetCategory WHERE ";
12305            private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
12306                    "SELECT {AssetCategory.*} FROM (SELECT DISTINCT assetCategory.categoryId FROM AssetCategory assetCategory WHERE ";
12307            private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
12308                    ") TEMP_TABLE INNER JOIN AssetCategory ON TEMP_TABLE.categoryId = AssetCategory.categoryId";
12309            private static final String _FILTER_SQL_COUNT_ASSETCATEGORY_WHERE = "SELECT COUNT(DISTINCT assetCategory.categoryId) AS COUNT_VALUE FROM AssetCategory assetCategory WHERE ";
12310            private static final String _FILTER_ENTITY_ALIAS = "assetCategory";
12311            private static final String _FILTER_ENTITY_TABLE = "AssetCategory";
12312            private static final String _ORDER_BY_ENTITY_ALIAS = "assetCategory.";
12313            private static final String _ORDER_BY_ENTITY_TABLE = "AssetCategory.";
12314            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetCategory exists with the primary key ";
12315            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetCategory exists with the key {";
12316            private static final Log _log = LogFactoryUtil.getLog(AssetCategoryPersistenceImpl.class);
12317            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
12318                                    "uuid"
12319                            });
12320            private static final AssetCategory _nullAssetCategory = new AssetCategoryImpl() {
12321                            @Override
12322                            public Object clone() {
12323                                    return this;
12324                            }
12325    
12326                            @Override
12327                            public CacheModel<AssetCategory> toCacheModel() {
12328                                    return _nullAssetCategoryCacheModel;
12329                            }
12330                    };
12331    
12332            private static final CacheModel<AssetCategory> _nullAssetCategoryCacheModel = new CacheModel<AssetCategory>() {
12333                            @Override
12334                            public AssetCategory toEntityModel() {
12335                                    return _nullAssetCategory;
12336                            }
12337                    };
12338    }