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