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