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