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