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