001    /**
002     * Copyright (c) 2000-2012 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;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
022    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
023    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
025    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderPath;
028    import com.liferay.portal.kernel.dao.orm.Query;
029    import com.liferay.portal.kernel.dao.orm.QueryPos;
030    import com.liferay.portal.kernel.dao.orm.QueryUtil;
031    import com.liferay.portal.kernel.dao.orm.SQLQuery;
032    import com.liferay.portal.kernel.dao.orm.Session;
033    import com.liferay.portal.kernel.exception.SystemException;
034    import com.liferay.portal.kernel.log.Log;
035    import com.liferay.portal.kernel.log.LogFactoryUtil;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.InstanceFactory;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.SetUtil;
040    import com.liferay.portal.kernel.util.StringBundler;
041    import com.liferay.portal.kernel.util.StringPool;
042    import com.liferay.portal.kernel.util.StringUtil;
043    import com.liferay.portal.kernel.util.UnmodifiableList;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
046    import com.liferay.portal.model.CacheModel;
047    import com.liferay.portal.model.ModelListener;
048    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
049    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
050    
051    import com.liferay.portlet.asset.NoSuchCategoryException;
052    import com.liferay.portlet.asset.model.AssetCategory;
053    import com.liferay.portlet.asset.model.impl.AssetCategoryImpl;
054    import com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl;
055    
056    import java.io.Serializable;
057    
058    import java.util.ArrayList;
059    import java.util.Collections;
060    import java.util.List;
061    import java.util.Set;
062    
063    /**
064     * The persistence implementation for the asset category service.
065     *
066     * <p>
067     * Caching information and settings can be found in <code>portal.properties</code>
068     * </p>
069     *
070     * @author Brian Wing Shun Chan
071     * @see AssetCategoryPersistence
072     * @see AssetCategoryUtil
073     * @generated
074     */
075    public class AssetCategoryPersistenceImpl extends BasePersistenceImpl<AssetCategory>
076            implements AssetCategoryPersistence {
077            /*
078             * NOTE FOR DEVELOPERS:
079             *
080             * 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.
081             */
082            public static final String FINDER_CLASS_NAME_ENTITY = AssetCategoryImpl.class.getName();
083            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List1";
085            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086                    ".List2";
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
088                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
089                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090                            "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
092                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
093                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
094                            "findAll", new String[0]);
095            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
096                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
099                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
100                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
101                            "findByUuid",
102                            new String[] {
103                                    String.class.getName(),
104                                    
105                            Integer.class.getName(), Integer.class.getName(),
106                                    OrderByComparator.class.getName()
107                            });
108            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
109                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
110                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
111                            "findByUuid", new String[] { String.class.getName() },
112                            AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
113                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
115                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
117                            new String[] { String.class.getName() });
118    
119            /**
120             * Returns all the asset categories where uuid = &#63;.
121             *
122             * @param uuid the uuid
123             * @return the matching asset categories
124             * @throws SystemException if a system exception occurred
125             */
126            public List<AssetCategory> findByUuid(String uuid)
127                    throws SystemException {
128                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
129            }
130    
131            /**
132             * Returns a range of all the asset categories where uuid = &#63;.
133             *
134             * <p>
135             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
136             * </p>
137             *
138             * @param uuid the uuid
139             * @param start the lower bound of the range of asset categories
140             * @param end the upper bound of the range of asset categories (not inclusive)
141             * @return the range of matching asset categories
142             * @throws SystemException if a system exception occurred
143             */
144            public List<AssetCategory> findByUuid(String uuid, int start, int end)
145                    throws SystemException {
146                    return findByUuid(uuid, start, end, null);
147            }
148    
149            /**
150             * Returns an ordered range of all the asset categories where uuid = &#63;.
151             *
152             * <p>
153             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
154             * </p>
155             *
156             * @param uuid the uuid
157             * @param start the lower bound of the range of asset categories
158             * @param end the upper bound of the range of asset categories (not inclusive)
159             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
160             * @return the ordered range of matching asset categories
161             * @throws SystemException if a system exception occurred
162             */
163            public List<AssetCategory> findByUuid(String uuid, int start, int end,
164                    OrderByComparator orderByComparator) throws SystemException {
165                    boolean pagination = true;
166                    FinderPath finderPath = null;
167                    Object[] finderArgs = null;
168    
169                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
170                                    (orderByComparator == null)) {
171                            pagination = false;
172                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
173                            finderArgs = new Object[] { uuid };
174                    }
175                    else {
176                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
177                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
178                    }
179    
180                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
181                                    finderArgs, this);
182    
183                    if ((list != null) && !list.isEmpty()) {
184                            for (AssetCategory assetCategory : list) {
185                                    if (!Validator.equals(uuid, assetCategory.getUuid())) {
186                                            list = null;
187    
188                                            break;
189                                    }
190                            }
191                    }
192    
193                    if (list == null) {
194                            StringBundler query = null;
195    
196                            if (orderByComparator != null) {
197                                    query = new StringBundler(3 +
198                                                    (orderByComparator.getOrderByFields().length * 3));
199                            }
200                            else {
201                                    query = new StringBundler(3);
202                            }
203    
204                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
205    
206                            if (uuid == null) {
207                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
208                            }
209                            else {
210                                    if (uuid.equals(StringPool.BLANK)) {
211                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
212                                    }
213                                    else {
214                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
215                                    }
216                            }
217    
218                            if (orderByComparator != null) {
219                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
220                                            orderByComparator);
221                            }
222                            else
223                             if (pagination) {
224                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
225                            }
226    
227                            String sql = query.toString();
228    
229                            Session session = null;
230    
231                            try {
232                                    session = openSession();
233    
234                                    Query q = session.createQuery(sql);
235    
236                                    QueryPos qPos = QueryPos.getInstance(q);
237    
238                                    if (uuid != null) {
239                                            qPos.add(uuid);
240                                    }
241    
242                                    if (!pagination) {
243                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
244                                                            start, end, false);
245    
246                                            Collections.sort(list);
247    
248                                            list = new UnmodifiableList<AssetCategory>(list);
249                                    }
250                                    else {
251                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
252                                                            start, end);
253                                    }
254    
255                                    cacheResult(list);
256    
257                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
258                            }
259                            catch (Exception e) {
260                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
261    
262                                    throw processException(e);
263                            }
264                            finally {
265                                    closeSession(session);
266                            }
267                    }
268    
269                    return list;
270            }
271    
272            /**
273             * Returns the first asset category in the ordered set where uuid = &#63;.
274             *
275             * @param uuid the uuid
276             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
277             * @return the first matching asset category
278             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
279             * @throws SystemException if a system exception occurred
280             */
281            public AssetCategory findByUuid_First(String uuid,
282                    OrderByComparator orderByComparator)
283                    throws NoSuchCategoryException, SystemException {
284                    AssetCategory assetCategory = fetchByUuid_First(uuid, orderByComparator);
285    
286                    if (assetCategory != null) {
287                            return assetCategory;
288                    }
289    
290                    StringBundler msg = new StringBundler(4);
291    
292                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
293    
294                    msg.append("uuid=");
295                    msg.append(uuid);
296    
297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
298    
299                    throw new NoSuchCategoryException(msg.toString());
300            }
301    
302            /**
303             * Returns the first asset category in the ordered set where uuid = &#63;.
304             *
305             * @param uuid the uuid
306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
307             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            public AssetCategory fetchByUuid_First(String uuid,
311                    OrderByComparator orderByComparator) throws SystemException {
312                    List<AssetCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
313    
314                    if (!list.isEmpty()) {
315                            return list.get(0);
316                    }
317    
318                    return null;
319            }
320    
321            /**
322             * Returns the last asset category in the ordered set where uuid = &#63;.
323             *
324             * @param uuid the uuid
325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
326             * @return the last matching asset category
327             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
328             * @throws SystemException if a system exception occurred
329             */
330            public AssetCategory findByUuid_Last(String uuid,
331                    OrderByComparator orderByComparator)
332                    throws NoSuchCategoryException, SystemException {
333                    AssetCategory assetCategory = fetchByUuid_Last(uuid, orderByComparator);
334    
335                    if (assetCategory != null) {
336                            return assetCategory;
337                    }
338    
339                    StringBundler msg = new StringBundler(4);
340    
341                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
342    
343                    msg.append("uuid=");
344                    msg.append(uuid);
345    
346                    msg.append(StringPool.CLOSE_CURLY_BRACE);
347    
348                    throw new NoSuchCategoryException(msg.toString());
349            }
350    
351            /**
352             * Returns the last asset category in the ordered set where uuid = &#63;.
353             *
354             * @param uuid the uuid
355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
356             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
357             * @throws SystemException if a system exception occurred
358             */
359            public AssetCategory fetchByUuid_Last(String uuid,
360                    OrderByComparator orderByComparator) throws SystemException {
361                    int count = countByUuid(uuid);
362    
363                    List<AssetCategory> list = findByUuid(uuid, count - 1, count,
364                                    orderByComparator);
365    
366                    if (!list.isEmpty()) {
367                            return list.get(0);
368                    }
369    
370                    return null;
371            }
372    
373            /**
374             * Returns the asset categories before and after the current asset category in the ordered set where uuid = &#63;.
375             *
376             * @param categoryId the primary key of the current asset category
377             * @param uuid the uuid
378             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
379             * @return the previous, current, and next asset category
380             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
381             * @throws SystemException if a system exception occurred
382             */
383            public AssetCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
384                    OrderByComparator orderByComparator)
385                    throws NoSuchCategoryException, SystemException {
386                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
387    
388                    Session session = null;
389    
390                    try {
391                            session = openSession();
392    
393                            AssetCategory[] array = new AssetCategoryImpl[3];
394    
395                            array[0] = getByUuid_PrevAndNext(session, assetCategory, uuid,
396                                            orderByComparator, true);
397    
398                            array[1] = assetCategory;
399    
400                            array[2] = getByUuid_PrevAndNext(session, assetCategory, uuid,
401                                            orderByComparator, false);
402    
403                            return array;
404                    }
405                    catch (Exception e) {
406                            throw processException(e);
407                    }
408                    finally {
409                            closeSession(session);
410                    }
411            }
412    
413            protected AssetCategory getByUuid_PrevAndNext(Session session,
414                    AssetCategory assetCategory, String uuid,
415                    OrderByComparator orderByComparator, boolean previous) {
416                    StringBundler query = null;
417    
418                    if (orderByComparator != null) {
419                            query = new StringBundler(6 +
420                                            (orderByComparator.getOrderByFields().length * 6));
421                    }
422                    else {
423                            query = new StringBundler(3);
424                    }
425    
426                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
427    
428                    if (uuid == null) {
429                            query.append(_FINDER_COLUMN_UUID_UUID_1);
430                    }
431                    else {
432                            if (uuid.equals(StringPool.BLANK)) {
433                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
434                            }
435                            else {
436                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
437                            }
438                    }
439    
440                    if (orderByComparator != null) {
441                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
442    
443                            if (orderByConditionFields.length > 0) {
444                                    query.append(WHERE_AND);
445                            }
446    
447                            for (int i = 0; i < orderByConditionFields.length; i++) {
448                                    query.append(_ORDER_BY_ENTITY_ALIAS);
449                                    query.append(orderByConditionFields[i]);
450    
451                                    if ((i + 1) < orderByConditionFields.length) {
452                                            if (orderByComparator.isAscending() ^ previous) {
453                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
454                                            }
455                                            else {
456                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
457                                            }
458                                    }
459                                    else {
460                                            if (orderByComparator.isAscending() ^ previous) {
461                                                    query.append(WHERE_GREATER_THAN);
462                                            }
463                                            else {
464                                                    query.append(WHERE_LESSER_THAN);
465                                            }
466                                    }
467                            }
468    
469                            query.append(ORDER_BY_CLAUSE);
470    
471                            String[] orderByFields = orderByComparator.getOrderByFields();
472    
473                            for (int i = 0; i < orderByFields.length; i++) {
474                                    query.append(_ORDER_BY_ENTITY_ALIAS);
475                                    query.append(orderByFields[i]);
476    
477                                    if ((i + 1) < orderByFields.length) {
478                                            if (orderByComparator.isAscending() ^ previous) {
479                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
480                                            }
481                                            else {
482                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
483                                            }
484                                    }
485                                    else {
486                                            if (orderByComparator.isAscending() ^ previous) {
487                                                    query.append(ORDER_BY_ASC);
488                                            }
489                                            else {
490                                                    query.append(ORDER_BY_DESC);
491                                            }
492                                    }
493                            }
494                    }
495                    else {
496                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
497                    }
498    
499                    String sql = query.toString();
500    
501                    Query q = session.createQuery(sql);
502    
503                    q.setFirstResult(0);
504                    q.setMaxResults(2);
505    
506                    QueryPos qPos = QueryPos.getInstance(q);
507    
508                    if (uuid != null) {
509                            qPos.add(uuid);
510                    }
511    
512                    if (orderByComparator != null) {
513                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
514    
515                            for (Object value : values) {
516                                    qPos.add(value);
517                            }
518                    }
519    
520                    List<AssetCategory> list = q.list();
521    
522                    if (list.size() == 2) {
523                            return list.get(1);
524                    }
525                    else {
526                            return null;
527                    }
528            }
529    
530            /**
531             * Removes all the asset categories where uuid = &#63; from the database.
532             *
533             * @param uuid the uuid
534             * @throws SystemException if a system exception occurred
535             */
536            public void removeByUuid(String uuid) throws SystemException {
537                    for (AssetCategory assetCategory : findByUuid(uuid, QueryUtil.ALL_POS,
538                                    QueryUtil.ALL_POS, null)) {
539                            remove(assetCategory);
540                    }
541            }
542    
543            /**
544             * Returns the number of asset categories where uuid = &#63;.
545             *
546             * @param uuid the uuid
547             * @return the number of matching asset categories
548             * @throws SystemException if a system exception occurred
549             */
550            public int countByUuid(String uuid) throws SystemException {
551                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
552    
553                    Object[] finderArgs = new Object[] { uuid };
554    
555                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
556                                    this);
557    
558                    if (count == null) {
559                            StringBundler query = new StringBundler(2);
560    
561                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
562    
563                            if (uuid == null) {
564                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
565                            }
566                            else {
567                                    if (uuid.equals(StringPool.BLANK)) {
568                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
569                                    }
570                                    else {
571                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
572                                    }
573                            }
574    
575                            String sql = query.toString();
576    
577                            Session session = null;
578    
579                            try {
580                                    session = openSession();
581    
582                                    Query q = session.createQuery(sql);
583    
584                                    QueryPos qPos = QueryPos.getInstance(q);
585    
586                                    if (uuid != null) {
587                                            qPos.add(uuid);
588                                    }
589    
590                                    count = (Long)q.uniqueResult();
591    
592                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
593                            }
594                            catch (Exception e) {
595                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
596    
597                                    throw processException(e);
598                            }
599                            finally {
600                                    closeSession(session);
601                            }
602                    }
603    
604                    return count.intValue();
605            }
606    
607            private static final String _FINDER_COLUMN_UUID_UUID_1 = "assetCategory.uuid IS NULL";
608            private static final String _FINDER_COLUMN_UUID_UUID_2 = "assetCategory.uuid = ?";
609            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = ?)";
610            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
611                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
612                            AssetCategoryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
613                            new String[] { String.class.getName(), Long.class.getName() },
614                            AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
615                            AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK);
616            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
617                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
618                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
619                            new String[] { String.class.getName(), Long.class.getName() });
620    
621            /**
622             * Returns the asset category where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchCategoryException} if it could not be found.
623             *
624             * @param uuid the uuid
625             * @param groupId the group ID
626             * @return the matching asset category
627             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
628             * @throws SystemException if a system exception occurred
629             */
630            public AssetCategory findByUUID_G(String uuid, long groupId)
631                    throws NoSuchCategoryException, SystemException {
632                    AssetCategory assetCategory = fetchByUUID_G(uuid, groupId);
633    
634                    if (assetCategory == null) {
635                            StringBundler msg = new StringBundler(6);
636    
637                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
638    
639                            msg.append("uuid=");
640                            msg.append(uuid);
641    
642                            msg.append(", groupId=");
643                            msg.append(groupId);
644    
645                            msg.append(StringPool.CLOSE_CURLY_BRACE);
646    
647                            if (_log.isWarnEnabled()) {
648                                    _log.warn(msg.toString());
649                            }
650    
651                            throw new NoSuchCategoryException(msg.toString());
652                    }
653    
654                    return assetCategory;
655            }
656    
657            /**
658             * 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.
659             *
660             * @param uuid the uuid
661             * @param groupId the group ID
662             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
663             * @throws SystemException if a system exception occurred
664             */
665            public AssetCategory fetchByUUID_G(String uuid, long groupId)
666                    throws SystemException {
667                    return fetchByUUID_G(uuid, groupId, true);
668            }
669    
670            /**
671             * 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.
672             *
673             * @param uuid the uuid
674             * @param groupId the group ID
675             * @param retrieveFromCache whether to use the finder cache
676             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
677             * @throws SystemException if a system exception occurred
678             */
679            public AssetCategory fetchByUUID_G(String uuid, long groupId,
680                    boolean retrieveFromCache) throws SystemException {
681                    Object[] finderArgs = new Object[] { uuid, groupId };
682    
683                    Object result = null;
684    
685                    if (retrieveFromCache) {
686                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
687                                            finderArgs, this);
688                    }
689    
690                    if (result instanceof AssetCategory) {
691                            AssetCategory assetCategory = (AssetCategory)result;
692    
693                            if (!Validator.equals(uuid, assetCategory.getUuid()) ||
694                                            (groupId != assetCategory.getGroupId())) {
695                                    result = null;
696                            }
697                    }
698    
699                    if (result == null) {
700                            StringBundler query = new StringBundler(4);
701    
702                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
703    
704                            if (uuid == null) {
705                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
706                            }
707                            else {
708                                    if (uuid.equals(StringPool.BLANK)) {
709                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
710                                    }
711                                    else {
712                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
713                                    }
714                            }
715    
716                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
717    
718                            String sql = query.toString();
719    
720                            Session session = null;
721    
722                            try {
723                                    session = openSession();
724    
725                                    Query q = session.createQuery(sql);
726    
727                                    QueryPos qPos = QueryPos.getInstance(q);
728    
729                                    if (uuid != null) {
730                                            qPos.add(uuid);
731                                    }
732    
733                                    qPos.add(groupId);
734    
735                                    List<AssetCategory> list = q.list();
736    
737                                    if (list.isEmpty()) {
738                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
739                                                    finderArgs, list);
740                                    }
741                                    else {
742                                            AssetCategory assetCategory = list.get(0);
743    
744                                            result = assetCategory;
745    
746                                            cacheResult(assetCategory);
747    
748                                            if ((assetCategory.getUuid() == null) ||
749                                                            !assetCategory.getUuid().equals(uuid) ||
750                                                            (assetCategory.getGroupId() != groupId)) {
751                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
752                                                            finderArgs, assetCategory);
753                                            }
754                                    }
755                            }
756                            catch (Exception e) {
757                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
758                                            finderArgs);
759    
760                                    throw processException(e);
761                            }
762                            finally {
763                                    closeSession(session);
764                            }
765                    }
766    
767                    if (result instanceof List<?>) {
768                            return null;
769                    }
770                    else {
771                            return (AssetCategory)result;
772                    }
773            }
774    
775            /**
776             * Removes the asset category where uuid = &#63; and groupId = &#63; from the database.
777             *
778             * @param uuid the uuid
779             * @param groupId the group ID
780             * @return the asset category that was removed
781             * @throws SystemException if a system exception occurred
782             */
783            public AssetCategory removeByUUID_G(String uuid, long groupId)
784                    throws NoSuchCategoryException, SystemException {
785                    AssetCategory assetCategory = findByUUID_G(uuid, groupId);
786    
787                    return remove(assetCategory);
788            }
789    
790            /**
791             * Returns the number of asset categories where uuid = &#63; and groupId = &#63;.
792             *
793             * @param uuid the uuid
794             * @param groupId the group ID
795             * @return the number of matching asset categories
796             * @throws SystemException if a system exception occurred
797             */
798            public int countByUUID_G(String uuid, long groupId)
799                    throws SystemException {
800                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
801    
802                    Object[] finderArgs = new Object[] { uuid, groupId };
803    
804                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
805                                    this);
806    
807                    if (count == null) {
808                            StringBundler query = new StringBundler(3);
809    
810                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
811    
812                            if (uuid == null) {
813                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
814                            }
815                            else {
816                                    if (uuid.equals(StringPool.BLANK)) {
817                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
818                                    }
819                                    else {
820                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
821                                    }
822                            }
823    
824                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
825    
826                            String sql = query.toString();
827    
828                            Session session = null;
829    
830                            try {
831                                    session = openSession();
832    
833                                    Query q = session.createQuery(sql);
834    
835                                    QueryPos qPos = QueryPos.getInstance(q);
836    
837                                    if (uuid != null) {
838                                            qPos.add(uuid);
839                                    }
840    
841                                    qPos.add(groupId);
842    
843                                    count = (Long)q.uniqueResult();
844    
845                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
846                            }
847                            catch (Exception e) {
848                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
849    
850                                    throw processException(e);
851                            }
852                            finally {
853                                    closeSession(session);
854                            }
855                    }
856    
857                    return count.intValue();
858            }
859    
860            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "assetCategory.uuid IS NULL AND ";
861            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "assetCategory.uuid = ? AND ";
862            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = ?) AND ";
863            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "assetCategory.groupId = ?";
864            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
865                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
866                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
867                            "findByUuid_C",
868                            new String[] {
869                                    String.class.getName(), Long.class.getName(),
870                                    
871                            Integer.class.getName(), Integer.class.getName(),
872                                    OrderByComparator.class.getName()
873                            });
874            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
875                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
876                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
877                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
878                            "findByUuid_C",
879                            new String[] { String.class.getName(), Long.class.getName() },
880                            AssetCategoryModelImpl.UUID_COLUMN_BITMASK |
881                            AssetCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
882                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
883            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
884                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
885                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
886                            new String[] { String.class.getName(), Long.class.getName() });
887    
888            /**
889             * Returns all the asset categories where uuid = &#63; and companyId = &#63;.
890             *
891             * @param uuid the uuid
892             * @param companyId the company ID
893             * @return the matching asset categories
894             * @throws SystemException if a system exception occurred
895             */
896            public List<AssetCategory> findByUuid_C(String uuid, long companyId)
897                    throws SystemException {
898                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
899                            QueryUtil.ALL_POS, null);
900            }
901    
902            /**
903             * Returns a range of all the asset categories where uuid = &#63; and companyId = &#63;.
904             *
905             * <p>
906             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
907             * </p>
908             *
909             * @param uuid the uuid
910             * @param companyId the company ID
911             * @param start the lower bound of the range of asset categories
912             * @param end the upper bound of the range of asset categories (not inclusive)
913             * @return the range of matching asset categories
914             * @throws SystemException if a system exception occurred
915             */
916            public List<AssetCategory> findByUuid_C(String uuid, long companyId,
917                    int start, int end) throws SystemException {
918                    return findByUuid_C(uuid, companyId, start, end, null);
919            }
920    
921            /**
922             * Returns an ordered range of all the asset categories where uuid = &#63; and companyId = &#63;.
923             *
924             * <p>
925             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
926             * </p>
927             *
928             * @param uuid the uuid
929             * @param companyId the company ID
930             * @param start the lower bound of the range of asset categories
931             * @param end the upper bound of the range of asset categories (not inclusive)
932             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
933             * @return the ordered range of matching asset categories
934             * @throws SystemException if a system exception occurred
935             */
936            public List<AssetCategory> findByUuid_C(String uuid, long companyId,
937                    int start, int end, OrderByComparator orderByComparator)
938                    throws SystemException {
939                    boolean pagination = true;
940                    FinderPath finderPath = null;
941                    Object[] finderArgs = null;
942    
943                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
944                                    (orderByComparator == null)) {
945                            pagination = false;
946                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
947                            finderArgs = new Object[] { uuid, companyId };
948                    }
949                    else {
950                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
951                            finderArgs = new Object[] {
952                                            uuid, companyId,
953                                            
954                                            start, end, orderByComparator
955                                    };
956                    }
957    
958                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
959                                    finderArgs, this);
960    
961                    if ((list != null) && !list.isEmpty()) {
962                            for (AssetCategory assetCategory : list) {
963                                    if (!Validator.equals(uuid, assetCategory.getUuid()) ||
964                                                    (companyId != assetCategory.getCompanyId())) {
965                                            list = null;
966    
967                                            break;
968                                    }
969                            }
970                    }
971    
972                    if (list == null) {
973                            StringBundler query = null;
974    
975                            if (orderByComparator != null) {
976                                    query = new StringBundler(4 +
977                                                    (orderByComparator.getOrderByFields().length * 3));
978                            }
979                            else {
980                                    query = new StringBundler(4);
981                            }
982    
983                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
984    
985                            if (uuid == null) {
986                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
987                            }
988                            else {
989                                    if (uuid.equals(StringPool.BLANK)) {
990                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
991                                    }
992                                    else {
993                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
994                                    }
995                            }
996    
997                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
998    
999                            if (orderByComparator != null) {
1000                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1001                                            orderByComparator);
1002                            }
1003                            else
1004                             if (pagination) {
1005                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1006                            }
1007    
1008                            String sql = query.toString();
1009    
1010                            Session session = null;
1011    
1012                            try {
1013                                    session = openSession();
1014    
1015                                    Query q = session.createQuery(sql);
1016    
1017                                    QueryPos qPos = QueryPos.getInstance(q);
1018    
1019                                    if (uuid != null) {
1020                                            qPos.add(uuid);
1021                                    }
1022    
1023                                    qPos.add(companyId);
1024    
1025                                    if (!pagination) {
1026                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1027                                                            start, end, false);
1028    
1029                                            Collections.sort(list);
1030    
1031                                            list = new UnmodifiableList<AssetCategory>(list);
1032                                    }
1033                                    else {
1034                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1035                                                            start, end);
1036                                    }
1037    
1038                                    cacheResult(list);
1039    
1040                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1041                            }
1042                            catch (Exception e) {
1043                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1044    
1045                                    throw processException(e);
1046                            }
1047                            finally {
1048                                    closeSession(session);
1049                            }
1050                    }
1051    
1052                    return list;
1053            }
1054    
1055            /**
1056             * Returns the first asset category in the ordered set where uuid = &#63; and companyId = &#63;.
1057             *
1058             * @param uuid the uuid
1059             * @param companyId the company ID
1060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1061             * @return the first matching asset category
1062             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
1063             * @throws SystemException if a system exception occurred
1064             */
1065            public AssetCategory findByUuid_C_First(String uuid, long companyId,
1066                    OrderByComparator orderByComparator)
1067                    throws NoSuchCategoryException, SystemException {
1068                    AssetCategory assetCategory = fetchByUuid_C_First(uuid, companyId,
1069                                    orderByComparator);
1070    
1071                    if (assetCategory != null) {
1072                            return assetCategory;
1073                    }
1074    
1075                    StringBundler msg = new StringBundler(6);
1076    
1077                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1078    
1079                    msg.append("uuid=");
1080                    msg.append(uuid);
1081    
1082                    msg.append(", companyId=");
1083                    msg.append(companyId);
1084    
1085                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1086    
1087                    throw new NoSuchCategoryException(msg.toString());
1088            }
1089    
1090            /**
1091             * Returns the first asset category in the ordered set where uuid = &#63; and companyId = &#63;.
1092             *
1093             * @param uuid the uuid
1094             * @param companyId the company ID
1095             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1096             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
1097             * @throws SystemException if a system exception occurred
1098             */
1099            public AssetCategory fetchByUuid_C_First(String uuid, long companyId,
1100                    OrderByComparator orderByComparator) throws SystemException {
1101                    List<AssetCategory> list = findByUuid_C(uuid, companyId, 0, 1,
1102                                    orderByComparator);
1103    
1104                    if (!list.isEmpty()) {
1105                            return list.get(0);
1106                    }
1107    
1108                    return null;
1109            }
1110    
1111            /**
1112             * Returns the last asset category in the ordered set where uuid = &#63; and companyId = &#63;.
1113             *
1114             * @param uuid the uuid
1115             * @param companyId the company ID
1116             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1117             * @return the last matching asset category
1118             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
1119             * @throws SystemException if a system exception occurred
1120             */
1121            public AssetCategory findByUuid_C_Last(String uuid, long companyId,
1122                    OrderByComparator orderByComparator)
1123                    throws NoSuchCategoryException, SystemException {
1124                    AssetCategory assetCategory = fetchByUuid_C_Last(uuid, companyId,
1125                                    orderByComparator);
1126    
1127                    if (assetCategory != null) {
1128                            return assetCategory;
1129                    }
1130    
1131                    StringBundler msg = new StringBundler(6);
1132    
1133                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1134    
1135                    msg.append("uuid=");
1136                    msg.append(uuid);
1137    
1138                    msg.append(", companyId=");
1139                    msg.append(companyId);
1140    
1141                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1142    
1143                    throw new NoSuchCategoryException(msg.toString());
1144            }
1145    
1146            /**
1147             * Returns the last asset category in the ordered set where uuid = &#63; and companyId = &#63;.
1148             *
1149             * @param uuid the uuid
1150             * @param companyId the company ID
1151             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1152             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
1153             * @throws SystemException if a system exception occurred
1154             */
1155            public AssetCategory fetchByUuid_C_Last(String uuid, long companyId,
1156                    OrderByComparator orderByComparator) throws SystemException {
1157                    int count = countByUuid_C(uuid, companyId);
1158    
1159                    List<AssetCategory> list = findByUuid_C(uuid, companyId, count - 1,
1160                                    count, orderByComparator);
1161    
1162                    if (!list.isEmpty()) {
1163                            return list.get(0);
1164                    }
1165    
1166                    return null;
1167            }
1168    
1169            /**
1170             * Returns the asset categories before and after the current asset category in the ordered set where uuid = &#63; and companyId = &#63;.
1171             *
1172             * @param categoryId the primary key of the current asset category
1173             * @param uuid the uuid
1174             * @param companyId the company ID
1175             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1176             * @return the previous, current, and next asset category
1177             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
1178             * @throws SystemException if a system exception occurred
1179             */
1180            public AssetCategory[] findByUuid_C_PrevAndNext(long categoryId,
1181                    String uuid, long companyId, OrderByComparator orderByComparator)
1182                    throws NoSuchCategoryException, SystemException {
1183                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
1184    
1185                    Session session = null;
1186    
1187                    try {
1188                            session = openSession();
1189    
1190                            AssetCategory[] array = new AssetCategoryImpl[3];
1191    
1192                            array[0] = getByUuid_C_PrevAndNext(session, assetCategory, uuid,
1193                                            companyId, orderByComparator, true);
1194    
1195                            array[1] = assetCategory;
1196    
1197                            array[2] = getByUuid_C_PrevAndNext(session, assetCategory, uuid,
1198                                            companyId, orderByComparator, false);
1199    
1200                            return array;
1201                    }
1202                    catch (Exception e) {
1203                            throw processException(e);
1204                    }
1205                    finally {
1206                            closeSession(session);
1207                    }
1208            }
1209    
1210            protected AssetCategory getByUuid_C_PrevAndNext(Session session,
1211                    AssetCategory assetCategory, String uuid, long companyId,
1212                    OrderByComparator orderByComparator, boolean previous) {
1213                    StringBundler query = null;
1214    
1215                    if (orderByComparator != null) {
1216                            query = new StringBundler(6 +
1217                                            (orderByComparator.getOrderByFields().length * 6));
1218                    }
1219                    else {
1220                            query = new StringBundler(3);
1221                    }
1222    
1223                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1224    
1225                    if (uuid == null) {
1226                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1227                    }
1228                    else {
1229                            if (uuid.equals(StringPool.BLANK)) {
1230                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1231                            }
1232                            else {
1233                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1234                            }
1235                    }
1236    
1237                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1238    
1239                    if (orderByComparator != null) {
1240                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1241    
1242                            if (orderByConditionFields.length > 0) {
1243                                    query.append(WHERE_AND);
1244                            }
1245    
1246                            for (int i = 0; i < orderByConditionFields.length; i++) {
1247                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1248                                    query.append(orderByConditionFields[i]);
1249    
1250                                    if ((i + 1) < orderByConditionFields.length) {
1251                                            if (orderByComparator.isAscending() ^ previous) {
1252                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1253                                            }
1254                                            else {
1255                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1256                                            }
1257                                    }
1258                                    else {
1259                                            if (orderByComparator.isAscending() ^ previous) {
1260                                                    query.append(WHERE_GREATER_THAN);
1261                                            }
1262                                            else {
1263                                                    query.append(WHERE_LESSER_THAN);
1264                                            }
1265                                    }
1266                            }
1267    
1268                            query.append(ORDER_BY_CLAUSE);
1269    
1270                            String[] orderByFields = orderByComparator.getOrderByFields();
1271    
1272                            for (int i = 0; i < orderByFields.length; i++) {
1273                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1274                                    query.append(orderByFields[i]);
1275    
1276                                    if ((i + 1) < orderByFields.length) {
1277                                            if (orderByComparator.isAscending() ^ previous) {
1278                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1279                                            }
1280                                            else {
1281                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1282                                            }
1283                                    }
1284                                    else {
1285                                            if (orderByComparator.isAscending() ^ previous) {
1286                                                    query.append(ORDER_BY_ASC);
1287                                            }
1288                                            else {
1289                                                    query.append(ORDER_BY_DESC);
1290                                            }
1291                                    }
1292                            }
1293                    }
1294                    else {
1295                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1296                    }
1297    
1298                    String sql = query.toString();
1299    
1300                    Query q = session.createQuery(sql);
1301    
1302                    q.setFirstResult(0);
1303                    q.setMaxResults(2);
1304    
1305                    QueryPos qPos = QueryPos.getInstance(q);
1306    
1307                    if (uuid != null) {
1308                            qPos.add(uuid);
1309                    }
1310    
1311                    qPos.add(companyId);
1312    
1313                    if (orderByComparator != null) {
1314                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
1315    
1316                            for (Object value : values) {
1317                                    qPos.add(value);
1318                            }
1319                    }
1320    
1321                    List<AssetCategory> list = q.list();
1322    
1323                    if (list.size() == 2) {
1324                            return list.get(1);
1325                    }
1326                    else {
1327                            return null;
1328                    }
1329            }
1330    
1331            /**
1332             * Removes all the asset categories where uuid = &#63; and companyId = &#63; from the database.
1333             *
1334             * @param uuid the uuid
1335             * @param companyId the company ID
1336             * @throws SystemException if a system exception occurred
1337             */
1338            public void removeByUuid_C(String uuid, long companyId)
1339                    throws SystemException {
1340                    for (AssetCategory assetCategory : findByUuid_C(uuid, companyId,
1341                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1342                            remove(assetCategory);
1343                    }
1344            }
1345    
1346            /**
1347             * Returns the number of asset categories where uuid = &#63; and companyId = &#63;.
1348             *
1349             * @param uuid the uuid
1350             * @param companyId the company ID
1351             * @return the number of matching asset categories
1352             * @throws SystemException if a system exception occurred
1353             */
1354            public int countByUuid_C(String uuid, long companyId)
1355                    throws SystemException {
1356                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1357    
1358                    Object[] finderArgs = new Object[] { uuid, companyId };
1359    
1360                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1361                                    this);
1362    
1363                    if (count == null) {
1364                            StringBundler query = new StringBundler(3);
1365    
1366                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
1367    
1368                            if (uuid == null) {
1369                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1370                            }
1371                            else {
1372                                    if (uuid.equals(StringPool.BLANK)) {
1373                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1374                                    }
1375                                    else {
1376                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1377                                    }
1378                            }
1379    
1380                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1381    
1382                            String sql = query.toString();
1383    
1384                            Session session = null;
1385    
1386                            try {
1387                                    session = openSession();
1388    
1389                                    Query q = session.createQuery(sql);
1390    
1391                                    QueryPos qPos = QueryPos.getInstance(q);
1392    
1393                                    if (uuid != null) {
1394                                            qPos.add(uuid);
1395                                    }
1396    
1397                                    qPos.add(companyId);
1398    
1399                                    count = (Long)q.uniqueResult();
1400    
1401                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1402                            }
1403                            catch (Exception e) {
1404                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1405    
1406                                    throw processException(e);
1407                            }
1408                            finally {
1409                                    closeSession(session);
1410                            }
1411                    }
1412    
1413                    return count.intValue();
1414            }
1415    
1416            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "assetCategory.uuid IS NULL AND ";
1417            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "assetCategory.uuid = ? AND ";
1418            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = ?) AND ";
1419            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "assetCategory.companyId = ?";
1420            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1421                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
1422                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1423                            "findByGroupId",
1424                            new String[] {
1425                                    Long.class.getName(),
1426                                    
1427                            Integer.class.getName(), Integer.class.getName(),
1428                                    OrderByComparator.class.getName()
1429                            });
1430            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1431                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1432                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
1433                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1434                            "findByGroupId", new String[] { Long.class.getName() },
1435                            AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
1436                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
1437            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
1438                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1439                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1440                            new String[] { Long.class.getName() });
1441    
1442            /**
1443             * Returns all the asset categories where groupId = &#63;.
1444             *
1445             * @param groupId the group ID
1446             * @return the matching asset categories
1447             * @throws SystemException if a system exception occurred
1448             */
1449            public List<AssetCategory> findByGroupId(long groupId)
1450                    throws SystemException {
1451                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1452            }
1453    
1454            /**
1455             * Returns a range of all the asset categories where groupId = &#63;.
1456             *
1457             * <p>
1458             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1459             * </p>
1460             *
1461             * @param groupId the group ID
1462             * @param start the lower bound of the range of asset categories
1463             * @param end the upper bound of the range of asset categories (not inclusive)
1464             * @return the range of matching asset categories
1465             * @throws SystemException if a system exception occurred
1466             */
1467            public List<AssetCategory> findByGroupId(long groupId, int start, int end)
1468                    throws SystemException {
1469                    return findByGroupId(groupId, start, end, null);
1470            }
1471    
1472            /**
1473             * Returns an ordered range of all the asset categories where groupId = &#63;.
1474             *
1475             * <p>
1476             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1477             * </p>
1478             *
1479             * @param groupId the group ID
1480             * @param start the lower bound of the range of asset categories
1481             * @param end the upper bound of the range of asset categories (not inclusive)
1482             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1483             * @return the ordered range of matching asset categories
1484             * @throws SystemException if a system exception occurred
1485             */
1486            public List<AssetCategory> findByGroupId(long groupId, int start, int end,
1487                    OrderByComparator orderByComparator) throws SystemException {
1488                    boolean pagination = true;
1489                    FinderPath finderPath = null;
1490                    Object[] finderArgs = null;
1491    
1492                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1493                                    (orderByComparator == null)) {
1494                            pagination = false;
1495                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1496                            finderArgs = new Object[] { groupId };
1497                    }
1498                    else {
1499                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1500                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1501                    }
1502    
1503                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
1504                                    finderArgs, this);
1505    
1506                    if ((list != null) && !list.isEmpty()) {
1507                            for (AssetCategory assetCategory : list) {
1508                                    if ((groupId != assetCategory.getGroupId())) {
1509                                            list = null;
1510    
1511                                            break;
1512                                    }
1513                            }
1514                    }
1515    
1516                    if (list == null) {
1517                            StringBundler query = null;
1518    
1519                            if (orderByComparator != null) {
1520                                    query = new StringBundler(3 +
1521                                                    (orderByComparator.getOrderByFields().length * 3));
1522                            }
1523                            else {
1524                                    query = new StringBundler(3);
1525                            }
1526    
1527                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1528    
1529                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1530    
1531                            if (orderByComparator != null) {
1532                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1533                                            orderByComparator);
1534                            }
1535                            else
1536                             if (pagination) {
1537                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1538                            }
1539    
1540                            String sql = query.toString();
1541    
1542                            Session session = null;
1543    
1544                            try {
1545                                    session = openSession();
1546    
1547                                    Query q = session.createQuery(sql);
1548    
1549                                    QueryPos qPos = QueryPos.getInstance(q);
1550    
1551                                    qPos.add(groupId);
1552    
1553                                    if (!pagination) {
1554                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1555                                                            start, end, false);
1556    
1557                                            Collections.sort(list);
1558    
1559                                            list = new UnmodifiableList<AssetCategory>(list);
1560                                    }
1561                                    else {
1562                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1563                                                            start, end);
1564                                    }
1565    
1566                                    cacheResult(list);
1567    
1568                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1569                            }
1570                            catch (Exception e) {
1571                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1572    
1573                                    throw processException(e);
1574                            }
1575                            finally {
1576                                    closeSession(session);
1577                            }
1578                    }
1579    
1580                    return list;
1581            }
1582    
1583            /**
1584             * Returns the first asset category in the ordered set where groupId = &#63;.
1585             *
1586             * @param groupId the group ID
1587             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1588             * @return the first matching asset category
1589             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
1590             * @throws SystemException if a system exception occurred
1591             */
1592            public AssetCategory findByGroupId_First(long groupId,
1593                    OrderByComparator orderByComparator)
1594                    throws NoSuchCategoryException, SystemException {
1595                    AssetCategory assetCategory = fetchByGroupId_First(groupId,
1596                                    orderByComparator);
1597    
1598                    if (assetCategory != null) {
1599                            return assetCategory;
1600                    }
1601    
1602                    StringBundler msg = new StringBundler(4);
1603    
1604                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1605    
1606                    msg.append("groupId=");
1607                    msg.append(groupId);
1608    
1609                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1610    
1611                    throw new NoSuchCategoryException(msg.toString());
1612            }
1613    
1614            /**
1615             * Returns the first asset category in the ordered set where groupId = &#63;.
1616             *
1617             * @param groupId the group ID
1618             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1619             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
1620             * @throws SystemException if a system exception occurred
1621             */
1622            public AssetCategory fetchByGroupId_First(long groupId,
1623                    OrderByComparator orderByComparator) throws SystemException {
1624                    List<AssetCategory> list = findByGroupId(groupId, 0, 1,
1625                                    orderByComparator);
1626    
1627                    if (!list.isEmpty()) {
1628                            return list.get(0);
1629                    }
1630    
1631                    return null;
1632            }
1633    
1634            /**
1635             * Returns the last asset category in the ordered set where groupId = &#63;.
1636             *
1637             * @param groupId the group ID
1638             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1639             * @return the last matching asset category
1640             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
1641             * @throws SystemException if a system exception occurred
1642             */
1643            public AssetCategory findByGroupId_Last(long groupId,
1644                    OrderByComparator orderByComparator)
1645                    throws NoSuchCategoryException, SystemException {
1646                    AssetCategory assetCategory = fetchByGroupId_Last(groupId,
1647                                    orderByComparator);
1648    
1649                    if (assetCategory != null) {
1650                            return assetCategory;
1651                    }
1652    
1653                    StringBundler msg = new StringBundler(4);
1654    
1655                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1656    
1657                    msg.append("groupId=");
1658                    msg.append(groupId);
1659    
1660                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1661    
1662                    throw new NoSuchCategoryException(msg.toString());
1663            }
1664    
1665            /**
1666             * Returns the last asset category in the ordered set where groupId = &#63;.
1667             *
1668             * @param groupId the group ID
1669             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1670             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
1671             * @throws SystemException if a system exception occurred
1672             */
1673            public AssetCategory fetchByGroupId_Last(long groupId,
1674                    OrderByComparator orderByComparator) throws SystemException {
1675                    int count = countByGroupId(groupId);
1676    
1677                    List<AssetCategory> list = findByGroupId(groupId, count - 1, count,
1678                                    orderByComparator);
1679    
1680                    if (!list.isEmpty()) {
1681                            return list.get(0);
1682                    }
1683    
1684                    return null;
1685            }
1686    
1687            /**
1688             * Returns the asset categories before and after the current asset category in the ordered set where groupId = &#63;.
1689             *
1690             * @param categoryId the primary key of the current asset category
1691             * @param groupId the group ID
1692             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1693             * @return the previous, current, and next asset category
1694             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
1695             * @throws SystemException if a system exception occurred
1696             */
1697            public AssetCategory[] findByGroupId_PrevAndNext(long categoryId,
1698                    long groupId, OrderByComparator orderByComparator)
1699                    throws NoSuchCategoryException, SystemException {
1700                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
1701    
1702                    Session session = null;
1703    
1704                    try {
1705                            session = openSession();
1706    
1707                            AssetCategory[] array = new AssetCategoryImpl[3];
1708    
1709                            array[0] = getByGroupId_PrevAndNext(session, assetCategory,
1710                                            groupId, orderByComparator, true);
1711    
1712                            array[1] = assetCategory;
1713    
1714                            array[2] = getByGroupId_PrevAndNext(session, assetCategory,
1715                                            groupId, orderByComparator, false);
1716    
1717                            return array;
1718                    }
1719                    catch (Exception e) {
1720                            throw processException(e);
1721                    }
1722                    finally {
1723                            closeSession(session);
1724                    }
1725            }
1726    
1727            protected AssetCategory getByGroupId_PrevAndNext(Session session,
1728                    AssetCategory assetCategory, long groupId,
1729                    OrderByComparator orderByComparator, boolean previous) {
1730                    StringBundler query = null;
1731    
1732                    if (orderByComparator != null) {
1733                            query = new StringBundler(6 +
1734                                            (orderByComparator.getOrderByFields().length * 6));
1735                    }
1736                    else {
1737                            query = new StringBundler(3);
1738                    }
1739    
1740                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1741    
1742                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1743    
1744                    if (orderByComparator != null) {
1745                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1746    
1747                            if (orderByConditionFields.length > 0) {
1748                                    query.append(WHERE_AND);
1749                            }
1750    
1751                            for (int i = 0; i < orderByConditionFields.length; i++) {
1752                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1753                                    query.append(orderByConditionFields[i]);
1754    
1755                                    if ((i + 1) < orderByConditionFields.length) {
1756                                            if (orderByComparator.isAscending() ^ previous) {
1757                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1758                                            }
1759                                            else {
1760                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1761                                            }
1762                                    }
1763                                    else {
1764                                            if (orderByComparator.isAscending() ^ previous) {
1765                                                    query.append(WHERE_GREATER_THAN);
1766                                            }
1767                                            else {
1768                                                    query.append(WHERE_LESSER_THAN);
1769                                            }
1770                                    }
1771                            }
1772    
1773                            query.append(ORDER_BY_CLAUSE);
1774    
1775                            String[] orderByFields = orderByComparator.getOrderByFields();
1776    
1777                            for (int i = 0; i < orderByFields.length; i++) {
1778                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1779                                    query.append(orderByFields[i]);
1780    
1781                                    if ((i + 1) < orderByFields.length) {
1782                                            if (orderByComparator.isAscending() ^ previous) {
1783                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1784                                            }
1785                                            else {
1786                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1787                                            }
1788                                    }
1789                                    else {
1790                                            if (orderByComparator.isAscending() ^ previous) {
1791                                                    query.append(ORDER_BY_ASC);
1792                                            }
1793                                            else {
1794                                                    query.append(ORDER_BY_DESC);
1795                                            }
1796                                    }
1797                            }
1798                    }
1799                    else {
1800                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1801                    }
1802    
1803                    String sql = query.toString();
1804    
1805                    Query q = session.createQuery(sql);
1806    
1807                    q.setFirstResult(0);
1808                    q.setMaxResults(2);
1809    
1810                    QueryPos qPos = QueryPos.getInstance(q);
1811    
1812                    qPos.add(groupId);
1813    
1814                    if (orderByComparator != null) {
1815                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
1816    
1817                            for (Object value : values) {
1818                                    qPos.add(value);
1819                            }
1820                    }
1821    
1822                    List<AssetCategory> list = q.list();
1823    
1824                    if (list.size() == 2) {
1825                            return list.get(1);
1826                    }
1827                    else {
1828                            return null;
1829                    }
1830            }
1831    
1832            /**
1833             * Returns all the asset categories that the user has permission to view where groupId = &#63;.
1834             *
1835             * @param groupId the group ID
1836             * @return the matching asset categories that the user has permission to view
1837             * @throws SystemException if a system exception occurred
1838             */
1839            public List<AssetCategory> filterFindByGroupId(long groupId)
1840                    throws SystemException {
1841                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1842                            QueryUtil.ALL_POS, null);
1843            }
1844    
1845            /**
1846             * Returns a range of all the asset categories that the user has permission to view where groupId = &#63;.
1847             *
1848             * <p>
1849             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1850             * </p>
1851             *
1852             * @param groupId the group ID
1853             * @param start the lower bound of the range of asset categories
1854             * @param end the upper bound of the range of asset categories (not inclusive)
1855             * @return the range of matching asset categories that the user has permission to view
1856             * @throws SystemException if a system exception occurred
1857             */
1858            public List<AssetCategory> filterFindByGroupId(long groupId, int start,
1859                    int end) throws SystemException {
1860                    return filterFindByGroupId(groupId, start, end, null);
1861            }
1862    
1863            /**
1864             * Returns an ordered range of all the asset categories that the user has permissions to view where groupId = &#63;.
1865             *
1866             * <p>
1867             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1868             * </p>
1869             *
1870             * @param groupId the group ID
1871             * @param start the lower bound of the range of asset categories
1872             * @param end the upper bound of the range of asset categories (not inclusive)
1873             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1874             * @return the ordered range of matching asset categories that the user has permission to view
1875             * @throws SystemException if a system exception occurred
1876             */
1877            public List<AssetCategory> filterFindByGroupId(long groupId, int start,
1878                    int end, OrderByComparator orderByComparator) throws SystemException {
1879                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1880                            return findByGroupId(groupId, start, end, orderByComparator);
1881                    }
1882    
1883                    StringBundler query = null;
1884    
1885                    if (orderByComparator != null) {
1886                            query = new StringBundler(3 +
1887                                            (orderByComparator.getOrderByFields().length * 3));
1888                    }
1889                    else {
1890                            query = new StringBundler(3);
1891                    }
1892    
1893                    if (getDB().isSupportsInlineDistinct()) {
1894                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
1895                    }
1896                    else {
1897                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1898                    }
1899    
1900                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1901    
1902                    if (!getDB().isSupportsInlineDistinct()) {
1903                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1904                    }
1905    
1906                    if (orderByComparator != null) {
1907                            if (getDB().isSupportsInlineDistinct()) {
1908                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1909                                            orderByComparator);
1910                            }
1911                            else {
1912                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1913                                            orderByComparator);
1914                            }
1915                    }
1916                    else {
1917                            if (getDB().isSupportsInlineDistinct()) {
1918                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1919                            }
1920                            else {
1921                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
1922                            }
1923                    }
1924    
1925                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1926                                    AssetCategory.class.getName(),
1927                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1928    
1929                    Session session = null;
1930    
1931                    try {
1932                            session = openSession();
1933    
1934                            SQLQuery q = session.createSQLQuery(sql);
1935    
1936                            if (getDB().isSupportsInlineDistinct()) {
1937                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
1938                            }
1939                            else {
1940                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
1941                            }
1942    
1943                            QueryPos qPos = QueryPos.getInstance(q);
1944    
1945                            qPos.add(groupId);
1946    
1947                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
1948                                    end);
1949                    }
1950                    catch (Exception e) {
1951                            throw processException(e);
1952                    }
1953                    finally {
1954                            closeSession(session);
1955                    }
1956            }
1957    
1958            /**
1959             * 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;.
1960             *
1961             * @param categoryId the primary key of the current asset category
1962             * @param groupId the group ID
1963             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1964             * @return the previous, current, and next asset category
1965             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
1966             * @throws SystemException if a system exception occurred
1967             */
1968            public AssetCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
1969                    long groupId, OrderByComparator orderByComparator)
1970                    throws NoSuchCategoryException, SystemException {
1971                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1972                            return findByGroupId_PrevAndNext(categoryId, groupId,
1973                                    orderByComparator);
1974                    }
1975    
1976                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
1977    
1978                    Session session = null;
1979    
1980                    try {
1981                            session = openSession();
1982    
1983                            AssetCategory[] array = new AssetCategoryImpl[3];
1984    
1985                            array[0] = filterGetByGroupId_PrevAndNext(session, assetCategory,
1986                                            groupId, orderByComparator, true);
1987    
1988                            array[1] = assetCategory;
1989    
1990                            array[2] = filterGetByGroupId_PrevAndNext(session, assetCategory,
1991                                            groupId, orderByComparator, false);
1992    
1993                            return array;
1994                    }
1995                    catch (Exception e) {
1996                            throw processException(e);
1997                    }
1998                    finally {
1999                            closeSession(session);
2000                    }
2001            }
2002    
2003            protected AssetCategory filterGetByGroupId_PrevAndNext(Session session,
2004                    AssetCategory assetCategory, long groupId,
2005                    OrderByComparator orderByComparator, boolean previous) {
2006                    StringBundler query = null;
2007    
2008                    if (orderByComparator != null) {
2009                            query = new StringBundler(6 +
2010                                            (orderByComparator.getOrderByFields().length * 6));
2011                    }
2012                    else {
2013                            query = new StringBundler(3);
2014                    }
2015    
2016                    if (getDB().isSupportsInlineDistinct()) {
2017                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
2018                    }
2019                    else {
2020                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2021                    }
2022    
2023                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2024    
2025                    if (!getDB().isSupportsInlineDistinct()) {
2026                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2027                    }
2028    
2029                    if (orderByComparator != null) {
2030                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2031    
2032                            if (orderByConditionFields.length > 0) {
2033                                    query.append(WHERE_AND);
2034                            }
2035    
2036                            for (int i = 0; i < orderByConditionFields.length; i++) {
2037                                    if (getDB().isSupportsInlineDistinct()) {
2038                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2039                                    }
2040                                    else {
2041                                            query.append(_ORDER_BY_ENTITY_TABLE);
2042                                    }
2043    
2044                                    query.append(orderByConditionFields[i]);
2045    
2046                                    if ((i + 1) < orderByConditionFields.length) {
2047                                            if (orderByComparator.isAscending() ^ previous) {
2048                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2049                                            }
2050                                            else {
2051                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2052                                            }
2053                                    }
2054                                    else {
2055                                            if (orderByComparator.isAscending() ^ previous) {
2056                                                    query.append(WHERE_GREATER_THAN);
2057                                            }
2058                                            else {
2059                                                    query.append(WHERE_LESSER_THAN);
2060                                            }
2061                                    }
2062                            }
2063    
2064                            query.append(ORDER_BY_CLAUSE);
2065    
2066                            String[] orderByFields = orderByComparator.getOrderByFields();
2067    
2068                            for (int i = 0; i < orderByFields.length; i++) {
2069                                    if (getDB().isSupportsInlineDistinct()) {
2070                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2071                                    }
2072                                    else {
2073                                            query.append(_ORDER_BY_ENTITY_TABLE);
2074                                    }
2075    
2076                                    query.append(orderByFields[i]);
2077    
2078                                    if ((i + 1) < orderByFields.length) {
2079                                            if (orderByComparator.isAscending() ^ previous) {
2080                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2081                                            }
2082                                            else {
2083                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2084                                            }
2085                                    }
2086                                    else {
2087                                            if (orderByComparator.isAscending() ^ previous) {
2088                                                    query.append(ORDER_BY_ASC);
2089                                            }
2090                                            else {
2091                                                    query.append(ORDER_BY_DESC);
2092                                            }
2093                                    }
2094                            }
2095                    }
2096                    else {
2097                            if (getDB().isSupportsInlineDistinct()) {
2098                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2099                            }
2100                            else {
2101                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
2102                            }
2103                    }
2104    
2105                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2106                                    AssetCategory.class.getName(),
2107                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2108    
2109                    SQLQuery q = session.createSQLQuery(sql);
2110    
2111                    q.setFirstResult(0);
2112                    q.setMaxResults(2);
2113    
2114                    if (getDB().isSupportsInlineDistinct()) {
2115                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
2116                    }
2117                    else {
2118                            q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
2119                    }
2120    
2121                    QueryPos qPos = QueryPos.getInstance(q);
2122    
2123                    qPos.add(groupId);
2124    
2125                    if (orderByComparator != null) {
2126                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
2127    
2128                            for (Object value : values) {
2129                                    qPos.add(value);
2130                            }
2131                    }
2132    
2133                    List<AssetCategory> list = q.list();
2134    
2135                    if (list.size() == 2) {
2136                            return list.get(1);
2137                    }
2138                    else {
2139                            return null;
2140                    }
2141            }
2142    
2143            /**
2144             * Removes all the asset categories where groupId = &#63; from the database.
2145             *
2146             * @param groupId the group ID
2147             * @throws SystemException if a system exception occurred
2148             */
2149            public void removeByGroupId(long groupId) throws SystemException {
2150                    for (AssetCategory assetCategory : findByGroupId(groupId,
2151                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2152                            remove(assetCategory);
2153                    }
2154            }
2155    
2156            /**
2157             * Returns the number of asset categories where groupId = &#63;.
2158             *
2159             * @param groupId the group ID
2160             * @return the number of matching asset categories
2161             * @throws SystemException if a system exception occurred
2162             */
2163            public int countByGroupId(long groupId) throws SystemException {
2164                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2165    
2166                    Object[] finderArgs = new Object[] { groupId };
2167    
2168                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2169                                    this);
2170    
2171                    if (count == null) {
2172                            StringBundler query = new StringBundler(2);
2173    
2174                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
2175    
2176                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2177    
2178                            String sql = query.toString();
2179    
2180                            Session session = null;
2181    
2182                            try {
2183                                    session = openSession();
2184    
2185                                    Query q = session.createQuery(sql);
2186    
2187                                    QueryPos qPos = QueryPos.getInstance(q);
2188    
2189                                    qPos.add(groupId);
2190    
2191                                    count = (Long)q.uniqueResult();
2192    
2193                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2194                            }
2195                            catch (Exception e) {
2196                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2197    
2198                                    throw processException(e);
2199                            }
2200                            finally {
2201                                    closeSession(session);
2202                            }
2203                    }
2204    
2205                    return count.intValue();
2206            }
2207    
2208            /**
2209             * Returns the number of asset categories that the user has permission to view where groupId = &#63;.
2210             *
2211             * @param groupId the group ID
2212             * @return the number of matching asset categories that the user has permission to view
2213             * @throws SystemException if a system exception occurred
2214             */
2215            public int filterCountByGroupId(long groupId) throws SystemException {
2216                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2217                            return countByGroupId(groupId);
2218                    }
2219    
2220                    StringBundler query = new StringBundler(2);
2221    
2222                    query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
2223    
2224                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2225    
2226                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2227                                    AssetCategory.class.getName(),
2228                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2229    
2230                    Session session = null;
2231    
2232                    try {
2233                            session = openSession();
2234    
2235                            SQLQuery q = session.createSQLQuery(sql);
2236    
2237                            q.addScalar(COUNT_COLUMN_NAME,
2238                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2239    
2240                            QueryPos qPos = QueryPos.getInstance(q);
2241    
2242                            qPos.add(groupId);
2243    
2244                            Long count = (Long)q.uniqueResult();
2245    
2246                            return count.intValue();
2247                    }
2248                    catch (Exception e) {
2249                            throw processException(e);
2250                    }
2251                    finally {
2252                            closeSession(session);
2253                    }
2254            }
2255    
2256            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetCategory.groupId = ?";
2257            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTCATEGORYID =
2258                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2259                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2260                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2261                            "findByParentCategoryId",
2262                            new String[] {
2263                                    Long.class.getName(),
2264                                    
2265                            Integer.class.getName(), Integer.class.getName(),
2266                                    OrderByComparator.class.getName()
2267                            });
2268            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID =
2269                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2270                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2271                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2272                            "findByParentCategoryId", new String[] { Long.class.getName() },
2273                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2274                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
2275            public static final FinderPath FINDER_PATH_COUNT_BY_PARENTCATEGORYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2276                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2277                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2278                            "countByParentCategoryId", new String[] { Long.class.getName() });
2279    
2280            /**
2281             * Returns all the asset categories where parentCategoryId = &#63;.
2282             *
2283             * @param parentCategoryId the parent category ID
2284             * @return the matching asset categories
2285             * @throws SystemException if a system exception occurred
2286             */
2287            public List<AssetCategory> findByParentCategoryId(long parentCategoryId)
2288                    throws SystemException {
2289                    return findByParentCategoryId(parentCategoryId, QueryUtil.ALL_POS,
2290                            QueryUtil.ALL_POS, null);
2291            }
2292    
2293            /**
2294             * Returns a range of all the asset categories where parentCategoryId = &#63;.
2295             *
2296             * <p>
2297             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2298             * </p>
2299             *
2300             * @param parentCategoryId the parent category ID
2301             * @param start the lower bound of the range of asset categories
2302             * @param end the upper bound of the range of asset categories (not inclusive)
2303             * @return the range of matching asset categories
2304             * @throws SystemException if a system exception occurred
2305             */
2306            public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
2307                    int start, int end) throws SystemException {
2308                    return findByParentCategoryId(parentCategoryId, start, end, null);
2309            }
2310    
2311            /**
2312             * Returns an ordered range of all the asset categories where parentCategoryId = &#63;.
2313             *
2314             * <p>
2315             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2316             * </p>
2317             *
2318             * @param parentCategoryId the parent category ID
2319             * @param start the lower bound of the range of asset categories
2320             * @param end the upper bound of the range of asset categories (not inclusive)
2321             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2322             * @return the ordered range of matching asset categories
2323             * @throws SystemException if a system exception occurred
2324             */
2325            public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
2326                    int start, int end, OrderByComparator orderByComparator)
2327                    throws SystemException {
2328                    boolean pagination = true;
2329                    FinderPath finderPath = null;
2330                    Object[] finderArgs = null;
2331    
2332                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2333                                    (orderByComparator == null)) {
2334                            pagination = false;
2335                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID;
2336                            finderArgs = new Object[] { parentCategoryId };
2337                    }
2338                    else {
2339                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PARENTCATEGORYID;
2340                            finderArgs = new Object[] {
2341                                            parentCategoryId,
2342                                            
2343                                            start, end, orderByComparator
2344                                    };
2345                    }
2346    
2347                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
2348                                    finderArgs, this);
2349    
2350                    if ((list != null) && !list.isEmpty()) {
2351                            for (AssetCategory assetCategory : list) {
2352                                    if ((parentCategoryId != assetCategory.getParentCategoryId())) {
2353                                            list = null;
2354    
2355                                            break;
2356                                    }
2357                            }
2358                    }
2359    
2360                    if (list == null) {
2361                            StringBundler query = null;
2362    
2363                            if (orderByComparator != null) {
2364                                    query = new StringBundler(3 +
2365                                                    (orderByComparator.getOrderByFields().length * 3));
2366                            }
2367                            else {
2368                                    query = new StringBundler(3);
2369                            }
2370    
2371                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2372    
2373                            query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2374    
2375                            if (orderByComparator != null) {
2376                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2377                                            orderByComparator);
2378                            }
2379                            else
2380                             if (pagination) {
2381                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2382                            }
2383    
2384                            String sql = query.toString();
2385    
2386                            Session session = null;
2387    
2388                            try {
2389                                    session = openSession();
2390    
2391                                    Query q = session.createQuery(sql);
2392    
2393                                    QueryPos qPos = QueryPos.getInstance(q);
2394    
2395                                    qPos.add(parentCategoryId);
2396    
2397                                    if (!pagination) {
2398                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2399                                                            start, end, false);
2400    
2401                                            Collections.sort(list);
2402    
2403                                            list = new UnmodifiableList<AssetCategory>(list);
2404                                    }
2405                                    else {
2406                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2407                                                            start, end);
2408                                    }
2409    
2410                                    cacheResult(list);
2411    
2412                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2413                            }
2414                            catch (Exception e) {
2415                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2416    
2417                                    throw processException(e);
2418                            }
2419                            finally {
2420                                    closeSession(session);
2421                            }
2422                    }
2423    
2424                    return list;
2425            }
2426    
2427            /**
2428             * Returns the first asset category in the ordered set where parentCategoryId = &#63;.
2429             *
2430             * @param parentCategoryId the parent category ID
2431             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2432             * @return the first matching asset category
2433             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
2434             * @throws SystemException if a system exception occurred
2435             */
2436            public AssetCategory findByParentCategoryId_First(long parentCategoryId,
2437                    OrderByComparator orderByComparator)
2438                    throws NoSuchCategoryException, SystemException {
2439                    AssetCategory assetCategory = fetchByParentCategoryId_First(parentCategoryId,
2440                                    orderByComparator);
2441    
2442                    if (assetCategory != null) {
2443                            return assetCategory;
2444                    }
2445    
2446                    StringBundler msg = new StringBundler(4);
2447    
2448                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2449    
2450                    msg.append("parentCategoryId=");
2451                    msg.append(parentCategoryId);
2452    
2453                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2454    
2455                    throw new NoSuchCategoryException(msg.toString());
2456            }
2457    
2458            /**
2459             * Returns the first asset category in the ordered set where parentCategoryId = &#63;.
2460             *
2461             * @param parentCategoryId the parent category ID
2462             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2463             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
2464             * @throws SystemException if a system exception occurred
2465             */
2466            public AssetCategory fetchByParentCategoryId_First(long parentCategoryId,
2467                    OrderByComparator orderByComparator) throws SystemException {
2468                    List<AssetCategory> list = findByParentCategoryId(parentCategoryId, 0,
2469                                    1, orderByComparator);
2470    
2471                    if (!list.isEmpty()) {
2472                            return list.get(0);
2473                    }
2474    
2475                    return null;
2476            }
2477    
2478            /**
2479             * Returns the last 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 last matching asset category
2484             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
2485             * @throws SystemException if a system exception occurred
2486             */
2487            public AssetCategory findByParentCategoryId_Last(long parentCategoryId,
2488                    OrderByComparator orderByComparator)
2489                    throws NoSuchCategoryException, SystemException {
2490                    AssetCategory assetCategory = fetchByParentCategoryId_Last(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 last 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 last matching asset category, or <code>null</code> if a matching asset category could not be found
2515             * @throws SystemException if a system exception occurred
2516             */
2517            public AssetCategory fetchByParentCategoryId_Last(long parentCategoryId,
2518                    OrderByComparator orderByComparator) throws SystemException {
2519                    int count = countByParentCategoryId(parentCategoryId);
2520    
2521                    List<AssetCategory> list = findByParentCategoryId(parentCategoryId,
2522                                    count - 1, count, orderByComparator);
2523    
2524                    if (!list.isEmpty()) {
2525                            return list.get(0);
2526                    }
2527    
2528                    return null;
2529            }
2530    
2531            /**
2532             * Returns the asset categories before and after the current asset category in the ordered set where parentCategoryId = &#63;.
2533             *
2534             * @param categoryId the primary key of the current asset category
2535             * @param parentCategoryId the parent category ID
2536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2537             * @return the previous, current, and next asset category
2538             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
2539             * @throws SystemException if a system exception occurred
2540             */
2541            public AssetCategory[] findByParentCategoryId_PrevAndNext(long categoryId,
2542                    long parentCategoryId, OrderByComparator orderByComparator)
2543                    throws NoSuchCategoryException, SystemException {
2544                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
2545    
2546                    Session session = null;
2547    
2548                    try {
2549                            session = openSession();
2550    
2551                            AssetCategory[] array = new AssetCategoryImpl[3];
2552    
2553                            array[0] = getByParentCategoryId_PrevAndNext(session,
2554                                            assetCategory, parentCategoryId, orderByComparator, true);
2555    
2556                            array[1] = assetCategory;
2557    
2558                            array[2] = getByParentCategoryId_PrevAndNext(session,
2559                                            assetCategory, parentCategoryId, orderByComparator, false);
2560    
2561                            return array;
2562                    }
2563                    catch (Exception e) {
2564                            throw processException(e);
2565                    }
2566                    finally {
2567                            closeSession(session);
2568                    }
2569            }
2570    
2571            protected AssetCategory getByParentCategoryId_PrevAndNext(Session session,
2572                    AssetCategory assetCategory, long parentCategoryId,
2573                    OrderByComparator orderByComparator, boolean previous) {
2574                    StringBundler query = null;
2575    
2576                    if (orderByComparator != null) {
2577                            query = new StringBundler(6 +
2578                                            (orderByComparator.getOrderByFields().length * 6));
2579                    }
2580                    else {
2581                            query = new StringBundler(3);
2582                    }
2583    
2584                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2585    
2586                    query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2587    
2588                    if (orderByComparator != null) {
2589                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2590    
2591                            if (orderByConditionFields.length > 0) {
2592                                    query.append(WHERE_AND);
2593                            }
2594    
2595                            for (int i = 0; i < orderByConditionFields.length; i++) {
2596                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2597                                    query.append(orderByConditionFields[i]);
2598    
2599                                    if ((i + 1) < orderByConditionFields.length) {
2600                                            if (orderByComparator.isAscending() ^ previous) {
2601                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2602                                            }
2603                                            else {
2604                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2605                                            }
2606                                    }
2607                                    else {
2608                                            if (orderByComparator.isAscending() ^ previous) {
2609                                                    query.append(WHERE_GREATER_THAN);
2610                                            }
2611                                            else {
2612                                                    query.append(WHERE_LESSER_THAN);
2613                                            }
2614                                    }
2615                            }
2616    
2617                            query.append(ORDER_BY_CLAUSE);
2618    
2619                            String[] orderByFields = orderByComparator.getOrderByFields();
2620    
2621                            for (int i = 0; i < orderByFields.length; i++) {
2622                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2623                                    query.append(orderByFields[i]);
2624    
2625                                    if ((i + 1) < orderByFields.length) {
2626                                            if (orderByComparator.isAscending() ^ previous) {
2627                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2628                                            }
2629                                            else {
2630                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2631                                            }
2632                                    }
2633                                    else {
2634                                            if (orderByComparator.isAscending() ^ previous) {
2635                                                    query.append(ORDER_BY_ASC);
2636                                            }
2637                                            else {
2638                                                    query.append(ORDER_BY_DESC);
2639                                            }
2640                                    }
2641                            }
2642                    }
2643                    else {
2644                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2645                    }
2646    
2647                    String sql = query.toString();
2648    
2649                    Query q = session.createQuery(sql);
2650    
2651                    q.setFirstResult(0);
2652                    q.setMaxResults(2);
2653    
2654                    QueryPos qPos = QueryPos.getInstance(q);
2655    
2656                    qPos.add(parentCategoryId);
2657    
2658                    if (orderByComparator != null) {
2659                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
2660    
2661                            for (Object value : values) {
2662                                    qPos.add(value);
2663                            }
2664                    }
2665    
2666                    List<AssetCategory> list = q.list();
2667    
2668                    if (list.size() == 2) {
2669                            return list.get(1);
2670                    }
2671                    else {
2672                            return null;
2673                    }
2674            }
2675    
2676            /**
2677             * Removes all the asset categories where parentCategoryId = &#63; from the database.
2678             *
2679             * @param parentCategoryId the parent category ID
2680             * @throws SystemException if a system exception occurred
2681             */
2682            public void removeByParentCategoryId(long parentCategoryId)
2683                    throws SystemException {
2684                    for (AssetCategory assetCategory : findByParentCategoryId(
2685                                    parentCategoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2686                            remove(assetCategory);
2687                    }
2688            }
2689    
2690            /**
2691             * Returns the number of asset categories where parentCategoryId = &#63;.
2692             *
2693             * @param parentCategoryId the parent category ID
2694             * @return the number of matching asset categories
2695             * @throws SystemException if a system exception occurred
2696             */
2697            public int countByParentCategoryId(long parentCategoryId)
2698                    throws SystemException {
2699                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PARENTCATEGORYID;
2700    
2701                    Object[] finderArgs = new Object[] { parentCategoryId };
2702    
2703                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2704                                    this);
2705    
2706                    if (count == null) {
2707                            StringBundler query = new StringBundler(2);
2708    
2709                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
2710    
2711                            query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
2712    
2713                            String sql = query.toString();
2714    
2715                            Session session = null;
2716    
2717                            try {
2718                                    session = openSession();
2719    
2720                                    Query q = session.createQuery(sql);
2721    
2722                                    QueryPos qPos = QueryPos.getInstance(q);
2723    
2724                                    qPos.add(parentCategoryId);
2725    
2726                                    count = (Long)q.uniqueResult();
2727    
2728                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2729                            }
2730                            catch (Exception e) {
2731                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2732    
2733                                    throw processException(e);
2734                            }
2735                            finally {
2736                                    closeSession(session);
2737                            }
2738                    }
2739    
2740                    return count.intValue();
2741            }
2742    
2743            private static final String _FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2 =
2744                    "assetCategory.parentCategoryId = ?";
2745            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_VOCABULARYID =
2746                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2747                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2748                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2749                            "findByVocabularyId",
2750                            new String[] {
2751                                    Long.class.getName(),
2752                                    
2753                            Integer.class.getName(), Integer.class.getName(),
2754                                    OrderByComparator.class.getName()
2755                            });
2756            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID =
2757                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2758                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
2759                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2760                            "findByVocabularyId", new String[] { Long.class.getName() },
2761                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
2762                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
2763            public static final FinderPath FINDER_PATH_COUNT_BY_VOCABULARYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
2764                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2765                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByVocabularyId",
2766                            new String[] { Long.class.getName() });
2767    
2768            /**
2769             * Returns all the asset categories where vocabularyId = &#63;.
2770             *
2771             * @param vocabularyId the vocabulary ID
2772             * @return the matching asset categories
2773             * @throws SystemException if a system exception occurred
2774             */
2775            public List<AssetCategory> findByVocabularyId(long vocabularyId)
2776                    throws SystemException {
2777                    return findByVocabularyId(vocabularyId, QueryUtil.ALL_POS,
2778                            QueryUtil.ALL_POS, null);
2779            }
2780    
2781            /**
2782             * Returns a range of all the asset categories where vocabularyId = &#63;.
2783             *
2784             * <p>
2785             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2786             * </p>
2787             *
2788             * @param vocabularyId the vocabulary ID
2789             * @param start the lower bound of the range of asset categories
2790             * @param end the upper bound of the range of asset categories (not inclusive)
2791             * @return the range of matching asset categories
2792             * @throws SystemException if a system exception occurred
2793             */
2794            public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
2795                    int end) throws SystemException {
2796                    return findByVocabularyId(vocabularyId, start, end, null);
2797            }
2798    
2799            /**
2800             * Returns an ordered range of all the asset categories where vocabularyId = &#63;.
2801             *
2802             * <p>
2803             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2804             * </p>
2805             *
2806             * @param vocabularyId the vocabulary ID
2807             * @param start the lower bound of the range of asset categories
2808             * @param end the upper bound of the range of asset categories (not inclusive)
2809             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2810             * @return the ordered range of matching asset categories
2811             * @throws SystemException if a system exception occurred
2812             */
2813            public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
2814                    int end, OrderByComparator orderByComparator) throws SystemException {
2815                    boolean pagination = true;
2816                    FinderPath finderPath = null;
2817                    Object[] finderArgs = null;
2818    
2819                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2820                                    (orderByComparator == null)) {
2821                            pagination = false;
2822                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID;
2823                            finderArgs = new Object[] { vocabularyId };
2824                    }
2825                    else {
2826                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_VOCABULARYID;
2827                            finderArgs = new Object[] {
2828                                            vocabularyId,
2829                                            
2830                                            start, end, orderByComparator
2831                                    };
2832                    }
2833    
2834                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
2835                                    finderArgs, this);
2836    
2837                    if ((list != null) && !list.isEmpty()) {
2838                            for (AssetCategory assetCategory : list) {
2839                                    if ((vocabularyId != assetCategory.getVocabularyId())) {
2840                                            list = null;
2841    
2842                                            break;
2843                                    }
2844                            }
2845                    }
2846    
2847                    if (list == null) {
2848                            StringBundler query = null;
2849    
2850                            if (orderByComparator != null) {
2851                                    query = new StringBundler(3 +
2852                                                    (orderByComparator.getOrderByFields().length * 3));
2853                            }
2854                            else {
2855                                    query = new StringBundler(3);
2856                            }
2857    
2858                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2859    
2860                            query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
2861    
2862                            if (orderByComparator != null) {
2863                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2864                                            orderByComparator);
2865                            }
2866                            else
2867                             if (pagination) {
2868                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2869                            }
2870    
2871                            String sql = query.toString();
2872    
2873                            Session session = null;
2874    
2875                            try {
2876                                    session = openSession();
2877    
2878                                    Query q = session.createQuery(sql);
2879    
2880                                    QueryPos qPos = QueryPos.getInstance(q);
2881    
2882                                    qPos.add(vocabularyId);
2883    
2884                                    if (!pagination) {
2885                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2886                                                            start, end, false);
2887    
2888                                            Collections.sort(list);
2889    
2890                                            list = new UnmodifiableList<AssetCategory>(list);
2891                                    }
2892                                    else {
2893                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2894                                                            start, end);
2895                                    }
2896    
2897                                    cacheResult(list);
2898    
2899                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2900                            }
2901                            catch (Exception e) {
2902                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2903    
2904                                    throw processException(e);
2905                            }
2906                            finally {
2907                                    closeSession(session);
2908                            }
2909                    }
2910    
2911                    return list;
2912            }
2913    
2914            /**
2915             * Returns the first asset category in the ordered set where vocabularyId = &#63;.
2916             *
2917             * @param vocabularyId the vocabulary ID
2918             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2919             * @return the first matching asset category
2920             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
2921             * @throws SystemException if a system exception occurred
2922             */
2923            public AssetCategory findByVocabularyId_First(long vocabularyId,
2924                    OrderByComparator orderByComparator)
2925                    throws NoSuchCategoryException, SystemException {
2926                    AssetCategory assetCategory = fetchByVocabularyId_First(vocabularyId,
2927                                    orderByComparator);
2928    
2929                    if (assetCategory != null) {
2930                            return assetCategory;
2931                    }
2932    
2933                    StringBundler msg = new StringBundler(4);
2934    
2935                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2936    
2937                    msg.append("vocabularyId=");
2938                    msg.append(vocabularyId);
2939    
2940                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2941    
2942                    throw new NoSuchCategoryException(msg.toString());
2943            }
2944    
2945            /**
2946             * Returns the first asset category in the ordered set where vocabularyId = &#63;.
2947             *
2948             * @param vocabularyId the vocabulary ID
2949             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2950             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
2951             * @throws SystemException if a system exception occurred
2952             */
2953            public AssetCategory fetchByVocabularyId_First(long vocabularyId,
2954                    OrderByComparator orderByComparator) throws SystemException {
2955                    List<AssetCategory> list = findByVocabularyId(vocabularyId, 0, 1,
2956                                    orderByComparator);
2957    
2958                    if (!list.isEmpty()) {
2959                            return list.get(0);
2960                    }
2961    
2962                    return null;
2963            }
2964    
2965            /**
2966             * Returns the last asset category in the ordered set where vocabularyId = &#63;.
2967             *
2968             * @param vocabularyId the vocabulary ID
2969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2970             * @return the last matching asset category
2971             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
2972             * @throws SystemException if a system exception occurred
2973             */
2974            public AssetCategory findByVocabularyId_Last(long vocabularyId,
2975                    OrderByComparator orderByComparator)
2976                    throws NoSuchCategoryException, SystemException {
2977                    AssetCategory assetCategory = fetchByVocabularyId_Last(vocabularyId,
2978                                    orderByComparator);
2979    
2980                    if (assetCategory != null) {
2981                            return assetCategory;
2982                    }
2983    
2984                    StringBundler msg = new StringBundler(4);
2985    
2986                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2987    
2988                    msg.append("vocabularyId=");
2989                    msg.append(vocabularyId);
2990    
2991                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2992    
2993                    throw new NoSuchCategoryException(msg.toString());
2994            }
2995    
2996            /**
2997             * Returns the last asset category in the ordered set where vocabularyId = &#63;.
2998             *
2999             * @param vocabularyId the vocabulary ID
3000             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3001             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
3002             * @throws SystemException if a system exception occurred
3003             */
3004            public AssetCategory fetchByVocabularyId_Last(long vocabularyId,
3005                    OrderByComparator orderByComparator) throws SystemException {
3006                    int count = countByVocabularyId(vocabularyId);
3007    
3008                    List<AssetCategory> list = findByVocabularyId(vocabularyId, count - 1,
3009                                    count, orderByComparator);
3010    
3011                    if (!list.isEmpty()) {
3012                            return list.get(0);
3013                    }
3014    
3015                    return null;
3016            }
3017    
3018            /**
3019             * Returns the asset categories before and after the current asset category in the ordered set where vocabularyId = &#63;.
3020             *
3021             * @param categoryId the primary key of the current asset category
3022             * @param vocabularyId the vocabulary ID
3023             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3024             * @return the previous, current, and next asset category
3025             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
3026             * @throws SystemException if a system exception occurred
3027             */
3028            public AssetCategory[] findByVocabularyId_PrevAndNext(long categoryId,
3029                    long vocabularyId, OrderByComparator orderByComparator)
3030                    throws NoSuchCategoryException, SystemException {
3031                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
3032    
3033                    Session session = null;
3034    
3035                    try {
3036                            session = openSession();
3037    
3038                            AssetCategory[] array = new AssetCategoryImpl[3];
3039    
3040                            array[0] = getByVocabularyId_PrevAndNext(session, assetCategory,
3041                                            vocabularyId, orderByComparator, true);
3042    
3043                            array[1] = assetCategory;
3044    
3045                            array[2] = getByVocabularyId_PrevAndNext(session, assetCategory,
3046                                            vocabularyId, orderByComparator, false);
3047    
3048                            return array;
3049                    }
3050                    catch (Exception e) {
3051                            throw processException(e);
3052                    }
3053                    finally {
3054                            closeSession(session);
3055                    }
3056            }
3057    
3058            protected AssetCategory getByVocabularyId_PrevAndNext(Session session,
3059                    AssetCategory assetCategory, long vocabularyId,
3060                    OrderByComparator orderByComparator, boolean previous) {
3061                    StringBundler query = null;
3062    
3063                    if (orderByComparator != null) {
3064                            query = new StringBundler(6 +
3065                                            (orderByComparator.getOrderByFields().length * 6));
3066                    }
3067                    else {
3068                            query = new StringBundler(3);
3069                    }
3070    
3071                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3072    
3073                    query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
3074    
3075                    if (orderByComparator != null) {
3076                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3077    
3078                            if (orderByConditionFields.length > 0) {
3079                                    query.append(WHERE_AND);
3080                            }
3081    
3082                            for (int i = 0; i < orderByConditionFields.length; i++) {
3083                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3084                                    query.append(orderByConditionFields[i]);
3085    
3086                                    if ((i + 1) < orderByConditionFields.length) {
3087                                            if (orderByComparator.isAscending() ^ previous) {
3088                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3089                                            }
3090                                            else {
3091                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3092                                            }
3093                                    }
3094                                    else {
3095                                            if (orderByComparator.isAscending() ^ previous) {
3096                                                    query.append(WHERE_GREATER_THAN);
3097                                            }
3098                                            else {
3099                                                    query.append(WHERE_LESSER_THAN);
3100                                            }
3101                                    }
3102                            }
3103    
3104                            query.append(ORDER_BY_CLAUSE);
3105    
3106                            String[] orderByFields = orderByComparator.getOrderByFields();
3107    
3108                            for (int i = 0; i < orderByFields.length; i++) {
3109                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3110                                    query.append(orderByFields[i]);
3111    
3112                                    if ((i + 1) < orderByFields.length) {
3113                                            if (orderByComparator.isAscending() ^ previous) {
3114                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3115                                            }
3116                                            else {
3117                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3118                                            }
3119                                    }
3120                                    else {
3121                                            if (orderByComparator.isAscending() ^ previous) {
3122                                                    query.append(ORDER_BY_ASC);
3123                                            }
3124                                            else {
3125                                                    query.append(ORDER_BY_DESC);
3126                                            }
3127                                    }
3128                            }
3129                    }
3130                    else {
3131                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3132                    }
3133    
3134                    String sql = query.toString();
3135    
3136                    Query q = session.createQuery(sql);
3137    
3138                    q.setFirstResult(0);
3139                    q.setMaxResults(2);
3140    
3141                    QueryPos qPos = QueryPos.getInstance(q);
3142    
3143                    qPos.add(vocabularyId);
3144    
3145                    if (orderByComparator != null) {
3146                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
3147    
3148                            for (Object value : values) {
3149                                    qPos.add(value);
3150                            }
3151                    }
3152    
3153                    List<AssetCategory> list = q.list();
3154    
3155                    if (list.size() == 2) {
3156                            return list.get(1);
3157                    }
3158                    else {
3159                            return null;
3160                    }
3161            }
3162    
3163            /**
3164             * Removes all the asset categories where vocabularyId = &#63; from the database.
3165             *
3166             * @param vocabularyId the vocabulary ID
3167             * @throws SystemException if a system exception occurred
3168             */
3169            public void removeByVocabularyId(long vocabularyId)
3170                    throws SystemException {
3171                    for (AssetCategory assetCategory : findByVocabularyId(vocabularyId,
3172                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3173                            remove(assetCategory);
3174                    }
3175            }
3176    
3177            /**
3178             * Returns the number of asset categories where vocabularyId = &#63;.
3179             *
3180             * @param vocabularyId the vocabulary ID
3181             * @return the number of matching asset categories
3182             * @throws SystemException if a system exception occurred
3183             */
3184            public int countByVocabularyId(long vocabularyId) throws SystemException {
3185                    FinderPath finderPath = FINDER_PATH_COUNT_BY_VOCABULARYID;
3186    
3187                    Object[] finderArgs = new Object[] { vocabularyId };
3188    
3189                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3190                                    this);
3191    
3192                    if (count == null) {
3193                            StringBundler query = new StringBundler(2);
3194    
3195                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
3196    
3197                            query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
3198    
3199                            String sql = query.toString();
3200    
3201                            Session session = null;
3202    
3203                            try {
3204                                    session = openSession();
3205    
3206                                    Query q = session.createQuery(sql);
3207    
3208                                    QueryPos qPos = QueryPos.getInstance(q);
3209    
3210                                    qPos.add(vocabularyId);
3211    
3212                                    count = (Long)q.uniqueResult();
3213    
3214                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3215                            }
3216                            catch (Exception e) {
3217                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3218    
3219                                    throw processException(e);
3220                            }
3221                            finally {
3222                                    closeSession(session);
3223                            }
3224                    }
3225    
3226                    return count.intValue();
3227            }
3228    
3229            private static final String _FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
3230            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3231                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
3232                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3233                            "findByG_V",
3234                            new String[] {
3235                                    Long.class.getName(), Long.class.getName(),
3236                                    
3237                            Integer.class.getName(), Integer.class.getName(),
3238                                    OrderByComparator.class.getName()
3239                            });
3240            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3241                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
3242                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3243                            "findByG_V",
3244                            new String[] { Long.class.getName(), Long.class.getName() },
3245                            AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
3246                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
3247                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
3248            public static final FinderPath FINDER_PATH_COUNT_BY_G_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
3249                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
3250                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_V",
3251                            new String[] { Long.class.getName(), Long.class.getName() });
3252    
3253            /**
3254             * Returns all the asset categories where groupId = &#63; and vocabularyId = &#63;.
3255             *
3256             * @param groupId the group ID
3257             * @param vocabularyId the vocabulary ID
3258             * @return the matching asset categories
3259             * @throws SystemException if a system exception occurred
3260             */
3261            public List<AssetCategory> findByG_V(long groupId, long vocabularyId)
3262                    throws SystemException {
3263                    return findByG_V(groupId, vocabularyId, QueryUtil.ALL_POS,
3264                            QueryUtil.ALL_POS, null);
3265            }
3266    
3267            /**
3268             * Returns a range of all the asset categories where groupId = &#63; and vocabularyId = &#63;.
3269             *
3270             * <p>
3271             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3272             * </p>
3273             *
3274             * @param groupId the group ID
3275             * @param vocabularyId the vocabulary ID
3276             * @param start the lower bound of the range of asset categories
3277             * @param end the upper bound of the range of asset categories (not inclusive)
3278             * @return the range of matching asset categories
3279             * @throws SystemException if a system exception occurred
3280             */
3281            public List<AssetCategory> findByG_V(long groupId, long vocabularyId,
3282                    int start, int end) throws SystemException {
3283                    return findByG_V(groupId, vocabularyId, start, end, null);
3284            }
3285    
3286            /**
3287             * Returns an ordered range of all the asset categories where groupId = &#63; and vocabularyId = &#63;.
3288             *
3289             * <p>
3290             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3291             * </p>
3292             *
3293             * @param groupId the group ID
3294             * @param vocabularyId the vocabulary ID
3295             * @param start the lower bound of the range of asset categories
3296             * @param end the upper bound of the range of asset categories (not inclusive)
3297             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3298             * @return the ordered range of matching asset categories
3299             * @throws SystemException if a system exception occurred
3300             */
3301            public List<AssetCategory> findByG_V(long groupId, long vocabularyId,
3302                    int start, int end, OrderByComparator orderByComparator)
3303                    throws SystemException {
3304                    boolean pagination = true;
3305                    FinderPath finderPath = null;
3306                    Object[] finderArgs = null;
3307    
3308                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3309                                    (orderByComparator == null)) {
3310                            pagination = false;
3311                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V;
3312                            finderArgs = new Object[] { groupId, vocabularyId };
3313                    }
3314                    else {
3315                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_V;
3316                            finderArgs = new Object[] {
3317                                            groupId, vocabularyId,
3318                                            
3319                                            start, end, orderByComparator
3320                                    };
3321                    }
3322    
3323                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
3324                                    finderArgs, this);
3325    
3326                    if ((list != null) && !list.isEmpty()) {
3327                            for (AssetCategory assetCategory : list) {
3328                                    if ((groupId != assetCategory.getGroupId()) ||
3329                                                    (vocabularyId != assetCategory.getVocabularyId())) {
3330                                            list = null;
3331    
3332                                            break;
3333                                    }
3334                            }
3335                    }
3336    
3337                    if (list == null) {
3338                            StringBundler query = null;
3339    
3340                            if (orderByComparator != null) {
3341                                    query = new StringBundler(4 +
3342                                                    (orderByComparator.getOrderByFields().length * 3));
3343                            }
3344                            else {
3345                                    query = new StringBundler(4);
3346                            }
3347    
3348                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3349    
3350                            query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3351    
3352                            query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3353    
3354                            if (orderByComparator != null) {
3355                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3356                                            orderByComparator);
3357                            }
3358                            else
3359                             if (pagination) {
3360                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3361                            }
3362    
3363                            String sql = query.toString();
3364    
3365                            Session session = null;
3366    
3367                            try {
3368                                    session = openSession();
3369    
3370                                    Query q = session.createQuery(sql);
3371    
3372                                    QueryPos qPos = QueryPos.getInstance(q);
3373    
3374                                    qPos.add(groupId);
3375    
3376                                    qPos.add(vocabularyId);
3377    
3378                                    if (!pagination) {
3379                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3380                                                            start, end, false);
3381    
3382                                            Collections.sort(list);
3383    
3384                                            list = new UnmodifiableList<AssetCategory>(list);
3385                                    }
3386                                    else {
3387                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3388                                                            start, end);
3389                                    }
3390    
3391                                    cacheResult(list);
3392    
3393                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3394                            }
3395                            catch (Exception e) {
3396                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3397    
3398                                    throw processException(e);
3399                            }
3400                            finally {
3401                                    closeSession(session);
3402                            }
3403                    }
3404    
3405                    return list;
3406            }
3407    
3408            /**
3409             * Returns the first asset category in the ordered set where groupId = &#63; and vocabularyId = &#63;.
3410             *
3411             * @param groupId the group ID
3412             * @param vocabularyId the vocabulary ID
3413             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3414             * @return the first matching asset category
3415             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
3416             * @throws SystemException if a system exception occurred
3417             */
3418            public AssetCategory findByG_V_First(long groupId, long vocabularyId,
3419                    OrderByComparator orderByComparator)
3420                    throws NoSuchCategoryException, SystemException {
3421                    AssetCategory assetCategory = fetchByG_V_First(groupId, vocabularyId,
3422                                    orderByComparator);
3423    
3424                    if (assetCategory != null) {
3425                            return assetCategory;
3426                    }
3427    
3428                    StringBundler msg = new StringBundler(6);
3429    
3430                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3431    
3432                    msg.append("groupId=");
3433                    msg.append(groupId);
3434    
3435                    msg.append(", vocabularyId=");
3436                    msg.append(vocabularyId);
3437    
3438                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3439    
3440                    throw new NoSuchCategoryException(msg.toString());
3441            }
3442    
3443            /**
3444             * Returns the first asset category in the ordered set where groupId = &#63; and vocabularyId = &#63;.
3445             *
3446             * @param groupId the group ID
3447             * @param vocabularyId the vocabulary ID
3448             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3449             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
3450             * @throws SystemException if a system exception occurred
3451             */
3452            public AssetCategory fetchByG_V_First(long groupId, long vocabularyId,
3453                    OrderByComparator orderByComparator) throws SystemException {
3454                    List<AssetCategory> list = findByG_V(groupId, vocabularyId, 0, 1,
3455                                    orderByComparator);
3456    
3457                    if (!list.isEmpty()) {
3458                            return list.get(0);
3459                    }
3460    
3461                    return null;
3462            }
3463    
3464            /**
3465             * Returns the last asset category in the ordered set where groupId = &#63; and vocabularyId = &#63;.
3466             *
3467             * @param groupId the group ID
3468             * @param vocabularyId the vocabulary ID
3469             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3470             * @return the last matching asset category
3471             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
3472             * @throws SystemException if a system exception occurred
3473             */
3474            public AssetCategory findByG_V_Last(long groupId, long vocabularyId,
3475                    OrderByComparator orderByComparator)
3476                    throws NoSuchCategoryException, SystemException {
3477                    AssetCategory assetCategory = fetchByG_V_Last(groupId, vocabularyId,
3478                                    orderByComparator);
3479    
3480                    if (assetCategory != null) {
3481                            return assetCategory;
3482                    }
3483    
3484                    StringBundler msg = new StringBundler(6);
3485    
3486                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3487    
3488                    msg.append("groupId=");
3489                    msg.append(groupId);
3490    
3491                    msg.append(", vocabularyId=");
3492                    msg.append(vocabularyId);
3493    
3494                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3495    
3496                    throw new NoSuchCategoryException(msg.toString());
3497            }
3498    
3499            /**
3500             * Returns the last asset category in the ordered set where groupId = &#63; and vocabularyId = &#63;.
3501             *
3502             * @param groupId the group ID
3503             * @param vocabularyId the vocabulary ID
3504             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3505             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
3506             * @throws SystemException if a system exception occurred
3507             */
3508            public AssetCategory fetchByG_V_Last(long groupId, long vocabularyId,
3509                    OrderByComparator orderByComparator) throws SystemException {
3510                    int count = countByG_V(groupId, vocabularyId);
3511    
3512                    List<AssetCategory> list = findByG_V(groupId, vocabularyId, count - 1,
3513                                    count, orderByComparator);
3514    
3515                    if (!list.isEmpty()) {
3516                            return list.get(0);
3517                    }
3518    
3519                    return null;
3520            }
3521    
3522            /**
3523             * Returns the asset categories before and after the current asset category in the ordered set where groupId = &#63; and vocabularyId = &#63;.
3524             *
3525             * @param categoryId the primary key of the current asset category
3526             * @param groupId the group ID
3527             * @param vocabularyId the vocabulary ID
3528             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3529             * @return the previous, current, and next asset category
3530             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
3531             * @throws SystemException if a system exception occurred
3532             */
3533            public AssetCategory[] findByG_V_PrevAndNext(long categoryId, long groupId,
3534                    long vocabularyId, OrderByComparator orderByComparator)
3535                    throws NoSuchCategoryException, SystemException {
3536                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
3537    
3538                    Session session = null;
3539    
3540                    try {
3541                            session = openSession();
3542    
3543                            AssetCategory[] array = new AssetCategoryImpl[3];
3544    
3545                            array[0] = getByG_V_PrevAndNext(session, assetCategory, groupId,
3546                                            vocabularyId, orderByComparator, true);
3547    
3548                            array[1] = assetCategory;
3549    
3550                            array[2] = getByG_V_PrevAndNext(session, assetCategory, groupId,
3551                                            vocabularyId, orderByComparator, false);
3552    
3553                            return array;
3554                    }
3555                    catch (Exception e) {
3556                            throw processException(e);
3557                    }
3558                    finally {
3559                            closeSession(session);
3560                    }
3561            }
3562    
3563            protected AssetCategory getByG_V_PrevAndNext(Session session,
3564                    AssetCategory assetCategory, long groupId, long vocabularyId,
3565                    OrderByComparator orderByComparator, boolean previous) {
3566                    StringBundler query = null;
3567    
3568                    if (orderByComparator != null) {
3569                            query = new StringBundler(6 +
3570                                            (orderByComparator.getOrderByFields().length * 6));
3571                    }
3572                    else {
3573                            query = new StringBundler(3);
3574                    }
3575    
3576                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3577    
3578                    query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3579    
3580                    query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3581    
3582                    if (orderByComparator != null) {
3583                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3584    
3585                            if (orderByConditionFields.length > 0) {
3586                                    query.append(WHERE_AND);
3587                            }
3588    
3589                            for (int i = 0; i < orderByConditionFields.length; i++) {
3590                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3591                                    query.append(orderByConditionFields[i]);
3592    
3593                                    if ((i + 1) < orderByConditionFields.length) {
3594                                            if (orderByComparator.isAscending() ^ previous) {
3595                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3596                                            }
3597                                            else {
3598                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3599                                            }
3600                                    }
3601                                    else {
3602                                            if (orderByComparator.isAscending() ^ previous) {
3603                                                    query.append(WHERE_GREATER_THAN);
3604                                            }
3605                                            else {
3606                                                    query.append(WHERE_LESSER_THAN);
3607                                            }
3608                                    }
3609                            }
3610    
3611                            query.append(ORDER_BY_CLAUSE);
3612    
3613                            String[] orderByFields = orderByComparator.getOrderByFields();
3614    
3615                            for (int i = 0; i < orderByFields.length; i++) {
3616                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3617                                    query.append(orderByFields[i]);
3618    
3619                                    if ((i + 1) < orderByFields.length) {
3620                                            if (orderByComparator.isAscending() ^ previous) {
3621                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3622                                            }
3623                                            else {
3624                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3625                                            }
3626                                    }
3627                                    else {
3628                                            if (orderByComparator.isAscending() ^ previous) {
3629                                                    query.append(ORDER_BY_ASC);
3630                                            }
3631                                            else {
3632                                                    query.append(ORDER_BY_DESC);
3633                                            }
3634                                    }
3635                            }
3636                    }
3637                    else {
3638                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3639                    }
3640    
3641                    String sql = query.toString();
3642    
3643                    Query q = session.createQuery(sql);
3644    
3645                    q.setFirstResult(0);
3646                    q.setMaxResults(2);
3647    
3648                    QueryPos qPos = QueryPos.getInstance(q);
3649    
3650                    qPos.add(groupId);
3651    
3652                    qPos.add(vocabularyId);
3653    
3654                    if (orderByComparator != null) {
3655                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
3656    
3657                            for (Object value : values) {
3658                                    qPos.add(value);
3659                            }
3660                    }
3661    
3662                    List<AssetCategory> list = q.list();
3663    
3664                    if (list.size() == 2) {
3665                            return list.get(1);
3666                    }
3667                    else {
3668                            return null;
3669                    }
3670            }
3671    
3672            /**
3673             * Returns all the asset categories that the user has permission to view where groupId = &#63; and vocabularyId = &#63;.
3674             *
3675             * @param groupId the group ID
3676             * @param vocabularyId the vocabulary ID
3677             * @return the matching asset categories that the user has permission to view
3678             * @throws SystemException if a system exception occurred
3679             */
3680            public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId)
3681                    throws SystemException {
3682                    return filterFindByG_V(groupId, vocabularyId, QueryUtil.ALL_POS,
3683                            QueryUtil.ALL_POS, null);
3684            }
3685    
3686            /**
3687             * Returns a range of all the asset categories that the user has permission to view where groupId = &#63; and vocabularyId = &#63;.
3688             *
3689             * <p>
3690             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3691             * </p>
3692             *
3693             * @param groupId the group ID
3694             * @param vocabularyId the vocabulary ID
3695             * @param start the lower bound of the range of asset categories
3696             * @param end the upper bound of the range of asset categories (not inclusive)
3697             * @return the range of matching asset categories that the user has permission to view
3698             * @throws SystemException if a system exception occurred
3699             */
3700            public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId,
3701                    int start, int end) throws SystemException {
3702                    return filterFindByG_V(groupId, vocabularyId, start, end, null);
3703            }
3704    
3705            /**
3706             * Returns an ordered range of all the asset categories that the user has permissions to view where groupId = &#63; and vocabularyId = &#63;.
3707             *
3708             * <p>
3709             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3710             * </p>
3711             *
3712             * @param groupId the group ID
3713             * @param vocabularyId the vocabulary ID
3714             * @param start the lower bound of the range of asset categories
3715             * @param end the upper bound of the range of asset categories (not inclusive)
3716             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3717             * @return the ordered range of matching asset categories that the user has permission to view
3718             * @throws SystemException if a system exception occurred
3719             */
3720            public List<AssetCategory> filterFindByG_V(long groupId, long vocabularyId,
3721                    int start, int end, OrderByComparator orderByComparator)
3722                    throws SystemException {
3723                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3724                            return findByG_V(groupId, vocabularyId, start, end,
3725                                    orderByComparator);
3726                    }
3727    
3728                    StringBundler query = null;
3729    
3730                    if (orderByComparator != null) {
3731                            query = new StringBundler(4 +
3732                                            (orderByComparator.getOrderByFields().length * 3));
3733                    }
3734                    else {
3735                            query = new StringBundler(4);
3736                    }
3737    
3738                    if (getDB().isSupportsInlineDistinct()) {
3739                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
3740                    }
3741                    else {
3742                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3743                    }
3744    
3745                    query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3746    
3747                    query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3748    
3749                    if (!getDB().isSupportsInlineDistinct()) {
3750                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3751                    }
3752    
3753                    if (orderByComparator != null) {
3754                            if (getDB().isSupportsInlineDistinct()) {
3755                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3756                                            orderByComparator);
3757                            }
3758                            else {
3759                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3760                                            orderByComparator);
3761                            }
3762                    }
3763                    else {
3764                            if (getDB().isSupportsInlineDistinct()) {
3765                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3766                            }
3767                            else {
3768                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
3769                            }
3770                    }
3771    
3772                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3773                                    AssetCategory.class.getName(),
3774                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3775    
3776                    Session session = null;
3777    
3778                    try {
3779                            session = openSession();
3780    
3781                            SQLQuery q = session.createSQLQuery(sql);
3782    
3783                            if (getDB().isSupportsInlineDistinct()) {
3784                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
3785                            }
3786                            else {
3787                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
3788                            }
3789    
3790                            QueryPos qPos = QueryPos.getInstance(q);
3791    
3792                            qPos.add(groupId);
3793    
3794                            qPos.add(vocabularyId);
3795    
3796                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
3797                                    end);
3798                    }
3799                    catch (Exception e) {
3800                            throw processException(e);
3801                    }
3802                    finally {
3803                            closeSession(session);
3804                    }
3805            }
3806    
3807            /**
3808             * 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;.
3809             *
3810             * @param categoryId the primary key of the current asset category
3811             * @param groupId the group ID
3812             * @param vocabularyId the vocabulary ID
3813             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3814             * @return the previous, current, and next asset category
3815             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
3816             * @throws SystemException if a system exception occurred
3817             */
3818            public AssetCategory[] filterFindByG_V_PrevAndNext(long categoryId,
3819                    long groupId, long vocabularyId, OrderByComparator orderByComparator)
3820                    throws NoSuchCategoryException, SystemException {
3821                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3822                            return findByG_V_PrevAndNext(categoryId, groupId, vocabularyId,
3823                                    orderByComparator);
3824                    }
3825    
3826                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
3827    
3828                    Session session = null;
3829    
3830                    try {
3831                            session = openSession();
3832    
3833                            AssetCategory[] array = new AssetCategoryImpl[3];
3834    
3835                            array[0] = filterGetByG_V_PrevAndNext(session, assetCategory,
3836                                            groupId, vocabularyId, orderByComparator, true);
3837    
3838                            array[1] = assetCategory;
3839    
3840                            array[2] = filterGetByG_V_PrevAndNext(session, assetCategory,
3841                                            groupId, vocabularyId, orderByComparator, false);
3842    
3843                            return array;
3844                    }
3845                    catch (Exception e) {
3846                            throw processException(e);
3847                    }
3848                    finally {
3849                            closeSession(session);
3850                    }
3851            }
3852    
3853            protected AssetCategory filterGetByG_V_PrevAndNext(Session session,
3854                    AssetCategory assetCategory, long groupId, long vocabularyId,
3855                    OrderByComparator orderByComparator, boolean previous) {
3856                    StringBundler query = null;
3857    
3858                    if (orderByComparator != null) {
3859                            query = new StringBundler(6 +
3860                                            (orderByComparator.getOrderByFields().length * 6));
3861                    }
3862                    else {
3863                            query = new StringBundler(3);
3864                    }
3865    
3866                    if (getDB().isSupportsInlineDistinct()) {
3867                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
3868                    }
3869                    else {
3870                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3871                    }
3872    
3873                    query.append(_FINDER_COLUMN_G_V_GROUPID_2);
3874    
3875                    query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
3876    
3877                    if (!getDB().isSupportsInlineDistinct()) {
3878                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3879                    }
3880    
3881                    if (orderByComparator != null) {
3882                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3883    
3884                            if (orderByConditionFields.length > 0) {
3885                                    query.append(WHERE_AND);
3886                            }
3887    
3888                            for (int i = 0; i < orderByConditionFields.length; i++) {
3889                                    if (getDB().isSupportsInlineDistinct()) {
3890                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3891                                    }
3892                                    else {
3893                                            query.append(_ORDER_BY_ENTITY_TABLE);
3894                                    }
3895    
3896                                    query.append(orderByConditionFields[i]);
3897    
3898                                    if ((i + 1) < orderByConditionFields.length) {
3899                                            if (orderByComparator.isAscending() ^ previous) {
3900                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3901                                            }
3902                                            else {
3903                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3904                                            }
3905                                    }
3906                                    else {
3907                                            if (orderByComparator.isAscending() ^ previous) {
3908                                                    query.append(WHERE_GREATER_THAN);
3909                                            }
3910                                            else {
3911                                                    query.append(WHERE_LESSER_THAN);
3912                                            }
3913                                    }
3914                            }
3915    
3916                            query.append(ORDER_BY_CLAUSE);
3917    
3918                            String[] orderByFields = orderByComparator.getOrderByFields();
3919    
3920                            for (int i = 0; i < orderByFields.length; i++) {
3921                                    if (getDB().isSupportsInlineDistinct()) {
3922                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3923                                    }
3924                                    else {
3925                                            query.append(_ORDER_BY_ENTITY_TABLE);
3926                                    }
3927    
3928                                    query.append(orderByFields[i]);
3929    
3930                                    if ((i + 1) < orderByFields.length) {
3931                                            if (orderByComparator.isAscending() ^ previous) {
3932                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3933                                            }
3934                                            else {
3935                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3936                                            }
3937                                    }
3938                                    else {
3939                                            if (orderByComparator.isAscending() ^ previous) {
3940                                                    query.append(ORDER_BY_ASC);
3941                                            }
3942                                            else {
3943                                                    query.append(ORDER_BY_DESC);
3944                                            }
3945                                    }
3946                            }
3947                    }
3948                    else {
3949                            if (getDB().isSupportsInlineDistinct()) {
3950                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3951                            }
3952                            else {
3953                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
3954                            }
3955                    }
3956    
3957                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3958                                    AssetCategory.class.getName(),
3959                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3960    
3961                    SQLQuery q = session.createSQLQuery(sql);
3962    
3963                    q.setFirstResult(0);
3964                    q.setMaxResults(2);
3965    
3966                    if (getDB().isSupportsInlineDistinct()) {
3967                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
3968                    }
3969                    else {
3970                            q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
3971                    }
3972    
3973                    QueryPos qPos = QueryPos.getInstance(q);
3974    
3975                    qPos.add(groupId);
3976    
3977                    qPos.add(vocabularyId);
3978    
3979                    if (orderByComparator != null) {
3980                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
3981    
3982                            for (Object value : values) {
3983                                    qPos.add(value);
3984                            }
3985                    }
3986    
3987                    List<AssetCategory> list = q.list();
3988    
3989                    if (list.size() == 2) {
3990                            return list.get(1);
3991                    }
3992                    else {
3993                            return null;
3994                    }
3995            }
3996    
3997            /**
3998             * Removes all the asset categories where groupId = &#63; and vocabularyId = &#63; from the database.
3999             *
4000             * @param groupId the group ID
4001             * @param vocabularyId the vocabulary ID
4002             * @throws SystemException if a system exception occurred
4003             */
4004            public void removeByG_V(long groupId, long vocabularyId)
4005                    throws SystemException {
4006                    for (AssetCategory assetCategory : findByG_V(groupId, vocabularyId,
4007                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4008                            remove(assetCategory);
4009                    }
4010            }
4011    
4012            /**
4013             * Returns the number of asset categories where groupId = &#63; and vocabularyId = &#63;.
4014             *
4015             * @param groupId the group ID
4016             * @param vocabularyId the vocabulary ID
4017             * @return the number of matching asset categories
4018             * @throws SystemException if a system exception occurred
4019             */
4020            public int countByG_V(long groupId, long vocabularyId)
4021                    throws SystemException {
4022                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_V;
4023    
4024                    Object[] finderArgs = new Object[] { groupId, vocabularyId };
4025    
4026                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4027                                    this);
4028    
4029                    if (count == null) {
4030                            StringBundler query = new StringBundler(3);
4031    
4032                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4033    
4034                            query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4035    
4036                            query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
4037    
4038                            String sql = query.toString();
4039    
4040                            Session session = null;
4041    
4042                            try {
4043                                    session = openSession();
4044    
4045                                    Query q = session.createQuery(sql);
4046    
4047                                    QueryPos qPos = QueryPos.getInstance(q);
4048    
4049                                    qPos.add(groupId);
4050    
4051                                    qPos.add(vocabularyId);
4052    
4053                                    count = (Long)q.uniqueResult();
4054    
4055                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4056                            }
4057                            catch (Exception e) {
4058                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4059    
4060                                    throw processException(e);
4061                            }
4062                            finally {
4063                                    closeSession(session);
4064                            }
4065                    }
4066    
4067                    return count.intValue();
4068            }
4069    
4070            /**
4071             * Returns the number of asset categories that the user has permission to view where groupId = &#63; and vocabularyId = &#63;.
4072             *
4073             * @param groupId the group ID
4074             * @param vocabularyId the vocabulary ID
4075             * @return the number of matching asset categories that the user has permission to view
4076             * @throws SystemException if a system exception occurred
4077             */
4078            public int filterCountByG_V(long groupId, long vocabularyId)
4079                    throws SystemException {
4080                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4081                            return countByG_V(groupId, vocabularyId);
4082                    }
4083    
4084                    StringBundler query = new StringBundler(3);
4085    
4086                    query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
4087    
4088                    query.append(_FINDER_COLUMN_G_V_GROUPID_2);
4089    
4090                    query.append(_FINDER_COLUMN_G_V_VOCABULARYID_2);
4091    
4092                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4093                                    AssetCategory.class.getName(),
4094                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4095    
4096                    Session session = null;
4097    
4098                    try {
4099                            session = openSession();
4100    
4101                            SQLQuery q = session.createSQLQuery(sql);
4102    
4103                            q.addScalar(COUNT_COLUMN_NAME,
4104                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4105    
4106                            QueryPos qPos = QueryPos.getInstance(q);
4107    
4108                            qPos.add(groupId);
4109    
4110                            qPos.add(vocabularyId);
4111    
4112                            Long count = (Long)q.uniqueResult();
4113    
4114                            return count.intValue();
4115                    }
4116                    catch (Exception e) {
4117                            throw processException(e);
4118                    }
4119                    finally {
4120                            closeSession(session);
4121                    }
4122            }
4123    
4124            private static final String _FINDER_COLUMN_G_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
4125            private static final String _FINDER_COLUMN_G_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
4126            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4127                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
4128                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4129                            "findByP_N",
4130                            new String[] {
4131                                    Long.class.getName(), String.class.getName(),
4132                                    
4133                            Integer.class.getName(), Integer.class.getName(),
4134                                    OrderByComparator.class.getName()
4135                            });
4136            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4137                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
4138                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4139                            "findByP_N",
4140                            new String[] { Long.class.getName(), String.class.getName() },
4141                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
4142                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
4143            public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4144                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
4145                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N",
4146                            new String[] { Long.class.getName(), String.class.getName() });
4147    
4148            /**
4149             * Returns all the asset categories where parentCategoryId = &#63; and name = &#63;.
4150             *
4151             * @param parentCategoryId the parent category ID
4152             * @param name the name
4153             * @return the matching asset categories
4154             * @throws SystemException if a system exception occurred
4155             */
4156            public List<AssetCategory> findByP_N(long parentCategoryId, String name)
4157                    throws SystemException {
4158                    return findByP_N(parentCategoryId, name, QueryUtil.ALL_POS,
4159                            QueryUtil.ALL_POS, null);
4160            }
4161    
4162            /**
4163             * Returns a range of all the asset categories where parentCategoryId = &#63; and name = &#63;.
4164             *
4165             * <p>
4166             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4167             * </p>
4168             *
4169             * @param parentCategoryId the parent category ID
4170             * @param name the name
4171             * @param start the lower bound of the range of asset categories
4172             * @param end the upper bound of the range of asset categories (not inclusive)
4173             * @return the range of matching asset categories
4174             * @throws SystemException if a system exception occurred
4175             */
4176            public List<AssetCategory> findByP_N(long parentCategoryId, String name,
4177                    int start, int end) throws SystemException {
4178                    return findByP_N(parentCategoryId, name, start, end, null);
4179            }
4180    
4181            /**
4182             * Returns an ordered range of all the asset categories where parentCategoryId = &#63; and name = &#63;.
4183             *
4184             * <p>
4185             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4186             * </p>
4187             *
4188             * @param parentCategoryId the parent category ID
4189             * @param name the name
4190             * @param start the lower bound of the range of asset categories
4191             * @param end the upper bound of the range of asset categories (not inclusive)
4192             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4193             * @return the ordered range of matching asset categories
4194             * @throws SystemException if a system exception occurred
4195             */
4196            public List<AssetCategory> findByP_N(long parentCategoryId, String name,
4197                    int start, int end, OrderByComparator orderByComparator)
4198                    throws SystemException {
4199                    boolean pagination = true;
4200                    FinderPath finderPath = null;
4201                    Object[] finderArgs = null;
4202    
4203                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4204                                    (orderByComparator == null)) {
4205                            pagination = false;
4206                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N;
4207                            finderArgs = new Object[] { parentCategoryId, name };
4208                    }
4209                    else {
4210                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_N;
4211                            finderArgs = new Object[] {
4212                                            parentCategoryId, name,
4213                                            
4214                                            start, end, orderByComparator
4215                                    };
4216                    }
4217    
4218                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
4219                                    finderArgs, this);
4220    
4221                    if ((list != null) && !list.isEmpty()) {
4222                            for (AssetCategory assetCategory : list) {
4223                                    if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
4224                                                    !Validator.equals(name, assetCategory.getName())) {
4225                                            list = null;
4226    
4227                                            break;
4228                                    }
4229                            }
4230                    }
4231    
4232                    if (list == null) {
4233                            StringBundler query = null;
4234    
4235                            if (orderByComparator != null) {
4236                                    query = new StringBundler(4 +
4237                                                    (orderByComparator.getOrderByFields().length * 3));
4238                            }
4239                            else {
4240                                    query = new StringBundler(4);
4241                            }
4242    
4243                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
4244    
4245                            query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
4246    
4247                            if (name == null) {
4248                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
4249                            }
4250                            else {
4251                                    if (name.equals(StringPool.BLANK)) {
4252                                            query.append(_FINDER_COLUMN_P_N_NAME_3);
4253                                    }
4254                                    else {
4255                                            query.append(_FINDER_COLUMN_P_N_NAME_2);
4256                                    }
4257                            }
4258    
4259                            if (orderByComparator != null) {
4260                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4261                                            orderByComparator);
4262                            }
4263                            else
4264                             if (pagination) {
4265                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4266                            }
4267    
4268                            String sql = query.toString();
4269    
4270                            Session session = null;
4271    
4272                            try {
4273                                    session = openSession();
4274    
4275                                    Query q = session.createQuery(sql);
4276    
4277                                    QueryPos qPos = QueryPos.getInstance(q);
4278    
4279                                    qPos.add(parentCategoryId);
4280    
4281                                    if (name != null) {
4282                                            qPos.add(name);
4283                                    }
4284    
4285                                    if (!pagination) {
4286                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4287                                                            start, end, false);
4288    
4289                                            Collections.sort(list);
4290    
4291                                            list = new UnmodifiableList<AssetCategory>(list);
4292                                    }
4293                                    else {
4294                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4295                                                            start, end);
4296                                    }
4297    
4298                                    cacheResult(list);
4299    
4300                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4301                            }
4302                            catch (Exception e) {
4303                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4304    
4305                                    throw processException(e);
4306                            }
4307                            finally {
4308                                    closeSession(session);
4309                            }
4310                    }
4311    
4312                    return list;
4313            }
4314    
4315            /**
4316             * Returns the first asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
4317             *
4318             * @param parentCategoryId the parent category ID
4319             * @param name the name
4320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4321             * @return the first matching asset category
4322             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
4323             * @throws SystemException if a system exception occurred
4324             */
4325            public AssetCategory findByP_N_First(long parentCategoryId, String name,
4326                    OrderByComparator orderByComparator)
4327                    throws NoSuchCategoryException, SystemException {
4328                    AssetCategory assetCategory = fetchByP_N_First(parentCategoryId, name,
4329                                    orderByComparator);
4330    
4331                    if (assetCategory != null) {
4332                            return assetCategory;
4333                    }
4334    
4335                    StringBundler msg = new StringBundler(6);
4336    
4337                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4338    
4339                    msg.append("parentCategoryId=");
4340                    msg.append(parentCategoryId);
4341    
4342                    msg.append(", name=");
4343                    msg.append(name);
4344    
4345                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4346    
4347                    throw new NoSuchCategoryException(msg.toString());
4348            }
4349    
4350            /**
4351             * Returns the first asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
4352             *
4353             * @param parentCategoryId the parent category ID
4354             * @param name the name
4355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4356             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
4357             * @throws SystemException if a system exception occurred
4358             */
4359            public AssetCategory fetchByP_N_First(long parentCategoryId, String name,
4360                    OrderByComparator orderByComparator) throws SystemException {
4361                    List<AssetCategory> list = findByP_N(parentCategoryId, name, 0, 1,
4362                                    orderByComparator);
4363    
4364                    if (!list.isEmpty()) {
4365                            return list.get(0);
4366                    }
4367    
4368                    return null;
4369            }
4370    
4371            /**
4372             * Returns the last asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
4373             *
4374             * @param parentCategoryId the parent category ID
4375             * @param name the name
4376             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4377             * @return the last matching asset category
4378             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
4379             * @throws SystemException if a system exception occurred
4380             */
4381            public AssetCategory findByP_N_Last(long parentCategoryId, String name,
4382                    OrderByComparator orderByComparator)
4383                    throws NoSuchCategoryException, SystemException {
4384                    AssetCategory assetCategory = fetchByP_N_Last(parentCategoryId, name,
4385                                    orderByComparator);
4386    
4387                    if (assetCategory != null) {
4388                            return assetCategory;
4389                    }
4390    
4391                    StringBundler msg = new StringBundler(6);
4392    
4393                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4394    
4395                    msg.append("parentCategoryId=");
4396                    msg.append(parentCategoryId);
4397    
4398                    msg.append(", name=");
4399                    msg.append(name);
4400    
4401                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4402    
4403                    throw new NoSuchCategoryException(msg.toString());
4404            }
4405    
4406            /**
4407             * Returns the last asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
4408             *
4409             * @param parentCategoryId the parent category ID
4410             * @param name the name
4411             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4412             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
4413             * @throws SystemException if a system exception occurred
4414             */
4415            public AssetCategory fetchByP_N_Last(long parentCategoryId, String name,
4416                    OrderByComparator orderByComparator) throws SystemException {
4417                    int count = countByP_N(parentCategoryId, name);
4418    
4419                    List<AssetCategory> list = findByP_N(parentCategoryId, name, count - 1,
4420                                    count, orderByComparator);
4421    
4422                    if (!list.isEmpty()) {
4423                            return list.get(0);
4424                    }
4425    
4426                    return null;
4427            }
4428    
4429            /**
4430             * Returns the asset categories before and after the current asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
4431             *
4432             * @param categoryId the primary key of the current asset category
4433             * @param parentCategoryId the parent category ID
4434             * @param name the name
4435             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4436             * @return the previous, current, and next asset category
4437             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
4438             * @throws SystemException if a system exception occurred
4439             */
4440            public AssetCategory[] findByP_N_PrevAndNext(long categoryId,
4441                    long parentCategoryId, String name, OrderByComparator orderByComparator)
4442                    throws NoSuchCategoryException, SystemException {
4443                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
4444    
4445                    Session session = null;
4446    
4447                    try {
4448                            session = openSession();
4449    
4450                            AssetCategory[] array = new AssetCategoryImpl[3];
4451    
4452                            array[0] = getByP_N_PrevAndNext(session, assetCategory,
4453                                            parentCategoryId, name, orderByComparator, true);
4454    
4455                            array[1] = assetCategory;
4456    
4457                            array[2] = getByP_N_PrevAndNext(session, assetCategory,
4458                                            parentCategoryId, name, orderByComparator, false);
4459    
4460                            return array;
4461                    }
4462                    catch (Exception e) {
4463                            throw processException(e);
4464                    }
4465                    finally {
4466                            closeSession(session);
4467                    }
4468            }
4469    
4470            protected AssetCategory getByP_N_PrevAndNext(Session session,
4471                    AssetCategory assetCategory, long parentCategoryId, String name,
4472                    OrderByComparator orderByComparator, boolean previous) {
4473                    StringBundler query = null;
4474    
4475                    if (orderByComparator != null) {
4476                            query = new StringBundler(6 +
4477                                            (orderByComparator.getOrderByFields().length * 6));
4478                    }
4479                    else {
4480                            query = new StringBundler(3);
4481                    }
4482    
4483                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
4484    
4485                    query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
4486    
4487                    if (name == null) {
4488                            query.append(_FINDER_COLUMN_P_N_NAME_1);
4489                    }
4490                    else {
4491                            if (name.equals(StringPool.BLANK)) {
4492                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
4493                            }
4494                            else {
4495                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
4496                            }
4497                    }
4498    
4499                    if (orderByComparator != null) {
4500                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4501    
4502                            if (orderByConditionFields.length > 0) {
4503                                    query.append(WHERE_AND);
4504                            }
4505    
4506                            for (int i = 0; i < orderByConditionFields.length; i++) {
4507                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4508                                    query.append(orderByConditionFields[i]);
4509    
4510                                    if ((i + 1) < orderByConditionFields.length) {
4511                                            if (orderByComparator.isAscending() ^ previous) {
4512                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4513                                            }
4514                                            else {
4515                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4516                                            }
4517                                    }
4518                                    else {
4519                                            if (orderByComparator.isAscending() ^ previous) {
4520                                                    query.append(WHERE_GREATER_THAN);
4521                                            }
4522                                            else {
4523                                                    query.append(WHERE_LESSER_THAN);
4524                                            }
4525                                    }
4526                            }
4527    
4528                            query.append(ORDER_BY_CLAUSE);
4529    
4530                            String[] orderByFields = orderByComparator.getOrderByFields();
4531    
4532                            for (int i = 0; i < orderByFields.length; i++) {
4533                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4534                                    query.append(orderByFields[i]);
4535    
4536                                    if ((i + 1) < orderByFields.length) {
4537                                            if (orderByComparator.isAscending() ^ previous) {
4538                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4539                                            }
4540                                            else {
4541                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4542                                            }
4543                                    }
4544                                    else {
4545                                            if (orderByComparator.isAscending() ^ previous) {
4546                                                    query.append(ORDER_BY_ASC);
4547                                            }
4548                                            else {
4549                                                    query.append(ORDER_BY_DESC);
4550                                            }
4551                                    }
4552                            }
4553                    }
4554                    else {
4555                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4556                    }
4557    
4558                    String sql = query.toString();
4559    
4560                    Query q = session.createQuery(sql);
4561    
4562                    q.setFirstResult(0);
4563                    q.setMaxResults(2);
4564    
4565                    QueryPos qPos = QueryPos.getInstance(q);
4566    
4567                    qPos.add(parentCategoryId);
4568    
4569                    if (name != null) {
4570                            qPos.add(name);
4571                    }
4572    
4573                    if (orderByComparator != null) {
4574                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
4575    
4576                            for (Object value : values) {
4577                                    qPos.add(value);
4578                            }
4579                    }
4580    
4581                    List<AssetCategory> list = q.list();
4582    
4583                    if (list.size() == 2) {
4584                            return list.get(1);
4585                    }
4586                    else {
4587                            return null;
4588                    }
4589            }
4590    
4591            /**
4592             * Removes all the asset categories where parentCategoryId = &#63; and name = &#63; from the database.
4593             *
4594             * @param parentCategoryId the parent category ID
4595             * @param name the name
4596             * @throws SystemException if a system exception occurred
4597             */
4598            public void removeByP_N(long parentCategoryId, String name)
4599                    throws SystemException {
4600                    for (AssetCategory assetCategory : findByP_N(parentCategoryId, name,
4601                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4602                            remove(assetCategory);
4603                    }
4604            }
4605    
4606            /**
4607             * Returns the number of asset categories where parentCategoryId = &#63; and name = &#63;.
4608             *
4609             * @param parentCategoryId the parent category ID
4610             * @param name the name
4611             * @return the number of matching asset categories
4612             * @throws SystemException if a system exception occurred
4613             */
4614            public int countByP_N(long parentCategoryId, String name)
4615                    throws SystemException {
4616                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N;
4617    
4618                    Object[] finderArgs = new Object[] { parentCategoryId, name };
4619    
4620                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4621                                    this);
4622    
4623                    if (count == null) {
4624                            StringBundler query = new StringBundler(3);
4625    
4626                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4627    
4628                            query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
4629    
4630                            if (name == null) {
4631                                    query.append(_FINDER_COLUMN_P_N_NAME_1);
4632                            }
4633                            else {
4634                                    if (name.equals(StringPool.BLANK)) {
4635                                            query.append(_FINDER_COLUMN_P_N_NAME_3);
4636                                    }
4637                                    else {
4638                                            query.append(_FINDER_COLUMN_P_N_NAME_2);
4639                                    }
4640                            }
4641    
4642                            String sql = query.toString();
4643    
4644                            Session session = null;
4645    
4646                            try {
4647                                    session = openSession();
4648    
4649                                    Query q = session.createQuery(sql);
4650    
4651                                    QueryPos qPos = QueryPos.getInstance(q);
4652    
4653                                    qPos.add(parentCategoryId);
4654    
4655                                    if (name != null) {
4656                                            qPos.add(name);
4657                                    }
4658    
4659                                    count = (Long)q.uniqueResult();
4660    
4661                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4662                            }
4663                            catch (Exception e) {
4664                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4665    
4666                                    throw processException(e);
4667                            }
4668                            finally {
4669                                    closeSession(session);
4670                            }
4671                    }
4672    
4673                    return count.intValue();
4674            }
4675    
4676            private static final String _FINDER_COLUMN_P_N_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
4677            private static final String _FINDER_COLUMN_P_N_NAME_1 = "assetCategory.name IS NULL";
4678            private static final String _FINDER_COLUMN_P_N_NAME_2 = "assetCategory.name = ?";
4679            private static final String _FINDER_COLUMN_P_N_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = ?)";
4680            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4681                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
4682                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4683                            "findByP_V",
4684                            new String[] {
4685                                    Long.class.getName(), Long.class.getName(),
4686                                    
4687                            Integer.class.getName(), Integer.class.getName(),
4688                                    OrderByComparator.class.getName()
4689                            });
4690            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4691                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
4692                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4693                            "findByP_V",
4694                            new String[] { Long.class.getName(), Long.class.getName() },
4695                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
4696                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK |
4697                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK);
4698            public static final FinderPath FINDER_PATH_COUNT_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
4699                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
4700                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_V",
4701                            new String[] { Long.class.getName(), Long.class.getName() });
4702    
4703            /**
4704             * Returns all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
4705             *
4706             * @param parentCategoryId the parent category ID
4707             * @param vocabularyId the vocabulary ID
4708             * @return the matching asset categories
4709             * @throws SystemException if a system exception occurred
4710             */
4711            public List<AssetCategory> findByP_V(long parentCategoryId,
4712                    long vocabularyId) throws SystemException {
4713                    return findByP_V(parentCategoryId, vocabularyId, QueryUtil.ALL_POS,
4714                            QueryUtil.ALL_POS, null);
4715            }
4716    
4717            /**
4718             * Returns a range of all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
4719             *
4720             * <p>
4721             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4722             * </p>
4723             *
4724             * @param parentCategoryId the parent category ID
4725             * @param vocabularyId the vocabulary ID
4726             * @param start the lower bound of the range of asset categories
4727             * @param end the upper bound of the range of asset categories (not inclusive)
4728             * @return the range of matching asset categories
4729             * @throws SystemException if a system exception occurred
4730             */
4731            public List<AssetCategory> findByP_V(long parentCategoryId,
4732                    long vocabularyId, int start, int end) throws SystemException {
4733                    return findByP_V(parentCategoryId, vocabularyId, start, end, null);
4734            }
4735    
4736            /**
4737             * Returns an ordered range of all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
4738             *
4739             * <p>
4740             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4741             * </p>
4742             *
4743             * @param parentCategoryId the parent category ID
4744             * @param vocabularyId the vocabulary ID
4745             * @param start the lower bound of the range of asset categories
4746             * @param end the upper bound of the range of asset categories (not inclusive)
4747             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4748             * @return the ordered range of matching asset categories
4749             * @throws SystemException if a system exception occurred
4750             */
4751            public List<AssetCategory> findByP_V(long parentCategoryId,
4752                    long vocabularyId, int start, int end,
4753                    OrderByComparator orderByComparator) throws SystemException {
4754                    boolean pagination = true;
4755                    FinderPath finderPath = null;
4756                    Object[] finderArgs = null;
4757    
4758                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4759                                    (orderByComparator == null)) {
4760                            pagination = false;
4761                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V;
4762                            finderArgs = new Object[] { parentCategoryId, vocabularyId };
4763                    }
4764                    else {
4765                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_V;
4766                            finderArgs = new Object[] {
4767                                            parentCategoryId, vocabularyId,
4768                                            
4769                                            start, end, orderByComparator
4770                                    };
4771                    }
4772    
4773                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
4774                                    finderArgs, this);
4775    
4776                    if ((list != null) && !list.isEmpty()) {
4777                            for (AssetCategory assetCategory : list) {
4778                                    if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
4779                                                    (vocabularyId != assetCategory.getVocabularyId())) {
4780                                            list = null;
4781    
4782                                            break;
4783                                    }
4784                            }
4785                    }
4786    
4787                    if (list == null) {
4788                            StringBundler query = null;
4789    
4790                            if (orderByComparator != null) {
4791                                    query = new StringBundler(4 +
4792                                                    (orderByComparator.getOrderByFields().length * 3));
4793                            }
4794                            else {
4795                                    query = new StringBundler(4);
4796                            }
4797    
4798                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
4799    
4800                            query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
4801    
4802                            query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
4803    
4804                            if (orderByComparator != null) {
4805                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4806                                            orderByComparator);
4807                            }
4808                            else
4809                             if (pagination) {
4810                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
4811                            }
4812    
4813                            String sql = query.toString();
4814    
4815                            Session session = null;
4816    
4817                            try {
4818                                    session = openSession();
4819    
4820                                    Query q = session.createQuery(sql);
4821    
4822                                    QueryPos qPos = QueryPos.getInstance(q);
4823    
4824                                    qPos.add(parentCategoryId);
4825    
4826                                    qPos.add(vocabularyId);
4827    
4828                                    if (!pagination) {
4829                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4830                                                            start, end, false);
4831    
4832                                            Collections.sort(list);
4833    
4834                                            list = new UnmodifiableList<AssetCategory>(list);
4835                                    }
4836                                    else {
4837                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
4838                                                            start, end);
4839                                    }
4840    
4841                                    cacheResult(list);
4842    
4843                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4844                            }
4845                            catch (Exception e) {
4846                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4847    
4848                                    throw processException(e);
4849                            }
4850                            finally {
4851                                    closeSession(session);
4852                            }
4853                    }
4854    
4855                    return list;
4856            }
4857    
4858            /**
4859             * Returns the first asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
4860             *
4861             * @param parentCategoryId the parent category ID
4862             * @param vocabularyId the vocabulary ID
4863             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4864             * @return the first matching asset category
4865             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
4866             * @throws SystemException if a system exception occurred
4867             */
4868            public AssetCategory findByP_V_First(long parentCategoryId,
4869                    long vocabularyId, OrderByComparator orderByComparator)
4870                    throws NoSuchCategoryException, SystemException {
4871                    AssetCategory assetCategory = fetchByP_V_First(parentCategoryId,
4872                                    vocabularyId, orderByComparator);
4873    
4874                    if (assetCategory != null) {
4875                            return assetCategory;
4876                    }
4877    
4878                    StringBundler msg = new StringBundler(6);
4879    
4880                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4881    
4882                    msg.append("parentCategoryId=");
4883                    msg.append(parentCategoryId);
4884    
4885                    msg.append(", vocabularyId=");
4886                    msg.append(vocabularyId);
4887    
4888                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4889    
4890                    throw new NoSuchCategoryException(msg.toString());
4891            }
4892    
4893            /**
4894             * Returns the first asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
4895             *
4896             * @param parentCategoryId the parent category ID
4897             * @param vocabularyId the vocabulary ID
4898             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4899             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
4900             * @throws SystemException if a system exception occurred
4901             */
4902            public AssetCategory fetchByP_V_First(long parentCategoryId,
4903                    long vocabularyId, OrderByComparator orderByComparator)
4904                    throws SystemException {
4905                    List<AssetCategory> list = findByP_V(parentCategoryId, vocabularyId, 0,
4906                                    1, orderByComparator);
4907    
4908                    if (!list.isEmpty()) {
4909                            return list.get(0);
4910                    }
4911    
4912                    return null;
4913            }
4914    
4915            /**
4916             * Returns the last asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
4917             *
4918             * @param parentCategoryId the parent category ID
4919             * @param vocabularyId the vocabulary ID
4920             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4921             * @return the last matching asset category
4922             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
4923             * @throws SystemException if a system exception occurred
4924             */
4925            public AssetCategory findByP_V_Last(long parentCategoryId,
4926                    long vocabularyId, OrderByComparator orderByComparator)
4927                    throws NoSuchCategoryException, SystemException {
4928                    AssetCategory assetCategory = fetchByP_V_Last(parentCategoryId,
4929                                    vocabularyId, orderByComparator);
4930    
4931                    if (assetCategory != null) {
4932                            return assetCategory;
4933                    }
4934    
4935                    StringBundler msg = new StringBundler(6);
4936    
4937                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4938    
4939                    msg.append("parentCategoryId=");
4940                    msg.append(parentCategoryId);
4941    
4942                    msg.append(", vocabularyId=");
4943                    msg.append(vocabularyId);
4944    
4945                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4946    
4947                    throw new NoSuchCategoryException(msg.toString());
4948            }
4949    
4950            /**
4951             * Returns the last asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
4952             *
4953             * @param parentCategoryId the parent category ID
4954             * @param vocabularyId the vocabulary ID
4955             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4956             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
4957             * @throws SystemException if a system exception occurred
4958             */
4959            public AssetCategory fetchByP_V_Last(long parentCategoryId,
4960                    long vocabularyId, OrderByComparator orderByComparator)
4961                    throws SystemException {
4962                    int count = countByP_V(parentCategoryId, vocabularyId);
4963    
4964                    List<AssetCategory> list = findByP_V(parentCategoryId, vocabularyId,
4965                                    count - 1, count, orderByComparator);
4966    
4967                    if (!list.isEmpty()) {
4968                            return list.get(0);
4969                    }
4970    
4971                    return null;
4972            }
4973    
4974            /**
4975             * Returns the asset categories before and after the current asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
4976             *
4977             * @param categoryId the primary key of the current asset category
4978             * @param parentCategoryId the parent category ID
4979             * @param vocabularyId the vocabulary ID
4980             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4981             * @return the previous, current, and next asset category
4982             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
4983             * @throws SystemException if a system exception occurred
4984             */
4985            public AssetCategory[] findByP_V_PrevAndNext(long categoryId,
4986                    long parentCategoryId, long vocabularyId,
4987                    OrderByComparator orderByComparator)
4988                    throws NoSuchCategoryException, SystemException {
4989                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
4990    
4991                    Session session = null;
4992    
4993                    try {
4994                            session = openSession();
4995    
4996                            AssetCategory[] array = new AssetCategoryImpl[3];
4997    
4998                            array[0] = getByP_V_PrevAndNext(session, assetCategory,
4999                                            parentCategoryId, vocabularyId, orderByComparator, true);
5000    
5001                            array[1] = assetCategory;
5002    
5003                            array[2] = getByP_V_PrevAndNext(session, assetCategory,
5004                                            parentCategoryId, vocabularyId, orderByComparator, false);
5005    
5006                            return array;
5007                    }
5008                    catch (Exception e) {
5009                            throw processException(e);
5010                    }
5011                    finally {
5012                            closeSession(session);
5013                    }
5014            }
5015    
5016            protected AssetCategory getByP_V_PrevAndNext(Session session,
5017                    AssetCategory assetCategory, long parentCategoryId, long vocabularyId,
5018                    OrderByComparator orderByComparator, boolean previous) {
5019                    StringBundler query = null;
5020    
5021                    if (orderByComparator != null) {
5022                            query = new StringBundler(6 +
5023                                            (orderByComparator.getOrderByFields().length * 6));
5024                    }
5025                    else {
5026                            query = new StringBundler(3);
5027                    }
5028    
5029                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5030    
5031                    query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5032    
5033                    query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5034    
5035                    if (orderByComparator != null) {
5036                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5037    
5038                            if (orderByConditionFields.length > 0) {
5039                                    query.append(WHERE_AND);
5040                            }
5041    
5042                            for (int i = 0; i < orderByConditionFields.length; i++) {
5043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5044                                    query.append(orderByConditionFields[i]);
5045    
5046                                    if ((i + 1) < orderByConditionFields.length) {
5047                                            if (orderByComparator.isAscending() ^ previous) {
5048                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5049                                            }
5050                                            else {
5051                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5052                                            }
5053                                    }
5054                                    else {
5055                                            if (orderByComparator.isAscending() ^ previous) {
5056                                                    query.append(WHERE_GREATER_THAN);
5057                                            }
5058                                            else {
5059                                                    query.append(WHERE_LESSER_THAN);
5060                                            }
5061                                    }
5062                            }
5063    
5064                            query.append(ORDER_BY_CLAUSE);
5065    
5066                            String[] orderByFields = orderByComparator.getOrderByFields();
5067    
5068                            for (int i = 0; i < orderByFields.length; i++) {
5069                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5070                                    query.append(orderByFields[i]);
5071    
5072                                    if ((i + 1) < orderByFields.length) {
5073                                            if (orderByComparator.isAscending() ^ previous) {
5074                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5075                                            }
5076                                            else {
5077                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5078                                            }
5079                                    }
5080                                    else {
5081                                            if (orderByComparator.isAscending() ^ previous) {
5082                                                    query.append(ORDER_BY_ASC);
5083                                            }
5084                                            else {
5085                                                    query.append(ORDER_BY_DESC);
5086                                            }
5087                                    }
5088                            }
5089                    }
5090                    else {
5091                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5092                    }
5093    
5094                    String sql = query.toString();
5095    
5096                    Query q = session.createQuery(sql);
5097    
5098                    q.setFirstResult(0);
5099                    q.setMaxResults(2);
5100    
5101                    QueryPos qPos = QueryPos.getInstance(q);
5102    
5103                    qPos.add(parentCategoryId);
5104    
5105                    qPos.add(vocabularyId);
5106    
5107                    if (orderByComparator != null) {
5108                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
5109    
5110                            for (Object value : values) {
5111                                    qPos.add(value);
5112                            }
5113                    }
5114    
5115                    List<AssetCategory> list = q.list();
5116    
5117                    if (list.size() == 2) {
5118                            return list.get(1);
5119                    }
5120                    else {
5121                            return null;
5122                    }
5123            }
5124    
5125            /**
5126             * Removes all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63; from the database.
5127             *
5128             * @param parentCategoryId the parent category ID
5129             * @param vocabularyId the vocabulary ID
5130             * @throws SystemException if a system exception occurred
5131             */
5132            public void removeByP_V(long parentCategoryId, long vocabularyId)
5133                    throws SystemException {
5134                    for (AssetCategory assetCategory : findByP_V(parentCategoryId,
5135                                    vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5136                            remove(assetCategory);
5137                    }
5138            }
5139    
5140            /**
5141             * Returns the number of asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
5142             *
5143             * @param parentCategoryId the parent category ID
5144             * @param vocabularyId the vocabulary ID
5145             * @return the number of matching asset categories
5146             * @throws SystemException if a system exception occurred
5147             */
5148            public int countByP_V(long parentCategoryId, long vocabularyId)
5149                    throws SystemException {
5150                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_V;
5151    
5152                    Object[] finderArgs = new Object[] { parentCategoryId, vocabularyId };
5153    
5154                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5155                                    this);
5156    
5157                    if (count == null) {
5158                            StringBundler query = new StringBundler(3);
5159    
5160                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
5161    
5162                            query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
5163    
5164                            query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
5165    
5166                            String sql = query.toString();
5167    
5168                            Session session = null;
5169    
5170                            try {
5171                                    session = openSession();
5172    
5173                                    Query q = session.createQuery(sql);
5174    
5175                                    QueryPos qPos = QueryPos.getInstance(q);
5176    
5177                                    qPos.add(parentCategoryId);
5178    
5179                                    qPos.add(vocabularyId);
5180    
5181                                    count = (Long)q.uniqueResult();
5182    
5183                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5184                            }
5185                            catch (Exception e) {
5186                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5187    
5188                                    throw processException(e);
5189                            }
5190                            finally {
5191                                    closeSession(session);
5192                            }
5193                    }
5194    
5195                    return count.intValue();
5196            }
5197    
5198            private static final String _FINDER_COLUMN_P_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
5199            private static final String _FINDER_COLUMN_P_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
5200            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5201                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5202                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5203                            "findByN_V",
5204                            new String[] {
5205                                    String.class.getName(), Long.class.getName(),
5206                                    
5207                            Integer.class.getName(), Integer.class.getName(),
5208                                    OrderByComparator.class.getName()
5209                            });
5210            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5211                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5212                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
5213                            "findByN_V",
5214                            new String[] { String.class.getName(), Long.class.getName() },
5215                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
5216                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
5217            public static final FinderPath FINDER_PATH_COUNT_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5218                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5219                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_V",
5220                            new String[] { String.class.getName(), Long.class.getName() });
5221    
5222            /**
5223             * Returns all the asset categories where name = &#63; and vocabularyId = &#63;.
5224             *
5225             * @param name the name
5226             * @param vocabularyId the vocabulary ID
5227             * @return the matching asset categories
5228             * @throws SystemException if a system exception occurred
5229             */
5230            public List<AssetCategory> findByN_V(String name, long vocabularyId)
5231                    throws SystemException {
5232                    return findByN_V(name, vocabularyId, QueryUtil.ALL_POS,
5233                            QueryUtil.ALL_POS, null);
5234            }
5235    
5236            /**
5237             * Returns a range of all the asset categories where name = &#63; and vocabularyId = &#63;.
5238             *
5239             * <p>
5240             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5241             * </p>
5242             *
5243             * @param name the name
5244             * @param vocabularyId the vocabulary ID
5245             * @param start the lower bound of the range of asset categories
5246             * @param end the upper bound of the range of asset categories (not inclusive)
5247             * @return the range of matching asset categories
5248             * @throws SystemException if a system exception occurred
5249             */
5250            public List<AssetCategory> findByN_V(String name, long vocabularyId,
5251                    int start, int end) throws SystemException {
5252                    return findByN_V(name, vocabularyId, start, end, null);
5253            }
5254    
5255            /**
5256             * Returns an ordered range of all the asset categories where name = &#63; and vocabularyId = &#63;.
5257             *
5258             * <p>
5259             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5260             * </p>
5261             *
5262             * @param name the name
5263             * @param vocabularyId the vocabulary ID
5264             * @param start the lower bound of the range of asset categories
5265             * @param end the upper bound of the range of asset categories (not inclusive)
5266             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5267             * @return the ordered range of matching asset categories
5268             * @throws SystemException if a system exception occurred
5269             */
5270            public List<AssetCategory> findByN_V(String name, long vocabularyId,
5271                    int start, int end, OrderByComparator orderByComparator)
5272                    throws SystemException {
5273                    boolean pagination = true;
5274                    FinderPath finderPath = null;
5275                    Object[] finderArgs = null;
5276    
5277                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5278                                    (orderByComparator == null)) {
5279                            pagination = false;
5280                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V;
5281                            finderArgs = new Object[] { name, vocabularyId };
5282                    }
5283                    else {
5284                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_N_V;
5285                            finderArgs = new Object[] {
5286                                            name, vocabularyId,
5287                                            
5288                                            start, end, orderByComparator
5289                                    };
5290                    }
5291    
5292                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
5293                                    finderArgs, this);
5294    
5295                    if ((list != null) && !list.isEmpty()) {
5296                            for (AssetCategory assetCategory : list) {
5297                                    if (!Validator.equals(name, assetCategory.getName()) ||
5298                                                    (vocabularyId != assetCategory.getVocabularyId())) {
5299                                            list = null;
5300    
5301                                            break;
5302                                    }
5303                            }
5304                    }
5305    
5306                    if (list == null) {
5307                            StringBundler query = null;
5308    
5309                            if (orderByComparator != null) {
5310                                    query = new StringBundler(4 +
5311                                                    (orderByComparator.getOrderByFields().length * 3));
5312                            }
5313                            else {
5314                                    query = new StringBundler(4);
5315                            }
5316    
5317                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5318    
5319                            if (name == null) {
5320                                    query.append(_FINDER_COLUMN_N_V_NAME_1);
5321                            }
5322                            else {
5323                                    if (name.equals(StringPool.BLANK)) {
5324                                            query.append(_FINDER_COLUMN_N_V_NAME_3);
5325                                    }
5326                                    else {
5327                                            query.append(_FINDER_COLUMN_N_V_NAME_2);
5328                                    }
5329                            }
5330    
5331                            query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
5332    
5333                            if (orderByComparator != null) {
5334                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5335                                            orderByComparator);
5336                            }
5337                            else
5338                             if (pagination) {
5339                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5340                            }
5341    
5342                            String sql = query.toString();
5343    
5344                            Session session = null;
5345    
5346                            try {
5347                                    session = openSession();
5348    
5349                                    Query q = session.createQuery(sql);
5350    
5351                                    QueryPos qPos = QueryPos.getInstance(q);
5352    
5353                                    if (name != null) {
5354                                            qPos.add(name);
5355                                    }
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 = new UnmodifiableList<AssetCategory>(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 name = &#63; and vocabularyId = &#63;.
5391             *
5392             * @param name the name
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 com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
5397             * @throws SystemException if a system exception occurred
5398             */
5399            public AssetCategory findByN_V_First(String name, long vocabularyId,
5400                    OrderByComparator orderByComparator)
5401                    throws NoSuchCategoryException, SystemException {
5402                    AssetCategory assetCategory = fetchByN_V_First(name, vocabularyId,
5403                                    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("name=");
5414                    msg.append(name);
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 name = &#63; and vocabularyId = &#63;.
5426             *
5427             * @param name the name
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             * @throws SystemException if a system exception occurred
5432             */
5433            public AssetCategory fetchByN_V_First(String name, long vocabularyId,
5434                    OrderByComparator orderByComparator) throws SystemException {
5435                    List<AssetCategory> list = findByN_V(name, vocabularyId, 0, 1,
5436                                    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 name = &#63; and vocabularyId = &#63;.
5447             *
5448             * @param name the name
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 com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
5453             * @throws SystemException if a system exception occurred
5454             */
5455            public AssetCategory findByN_V_Last(String name, long vocabularyId,
5456                    OrderByComparator orderByComparator)
5457                    throws NoSuchCategoryException, SystemException {
5458                    AssetCategory assetCategory = fetchByN_V_Last(name, vocabularyId,
5459                                    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("name=");
5470                    msg.append(name);
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 name = &#63; and vocabularyId = &#63;.
5482             *
5483             * @param name the name
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             * @throws SystemException if a system exception occurred
5488             */
5489            public AssetCategory fetchByN_V_Last(String name, long vocabularyId,
5490                    OrderByComparator orderByComparator) throws SystemException {
5491                    int count = countByN_V(name, vocabularyId);
5492    
5493                    List<AssetCategory> list = findByN_V(name, vocabularyId, count - 1,
5494                                    count, orderByComparator);
5495    
5496                    if (!list.isEmpty()) {
5497                            return list.get(0);
5498                    }
5499    
5500                    return null;
5501            }
5502    
5503            /**
5504             * Returns the asset categories before and after the current asset category in the ordered set where name = &#63; and vocabularyId = &#63;.
5505             *
5506             * @param categoryId the primary key of the current asset category
5507             * @param name the name
5508             * @param vocabularyId the vocabulary ID
5509             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5510             * @return the previous, current, and next asset category
5511             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
5512             * @throws SystemException if a system exception occurred
5513             */
5514            public AssetCategory[] findByN_V_PrevAndNext(long categoryId, String name,
5515                    long vocabularyId, OrderByComparator orderByComparator)
5516                    throws NoSuchCategoryException, SystemException {
5517                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
5518    
5519                    Session session = null;
5520    
5521                    try {
5522                            session = openSession();
5523    
5524                            AssetCategory[] array = new AssetCategoryImpl[3];
5525    
5526                            array[0] = getByN_V_PrevAndNext(session, assetCategory, name,
5527                                            vocabularyId, orderByComparator, true);
5528    
5529                            array[1] = assetCategory;
5530    
5531                            array[2] = getByN_V_PrevAndNext(session, assetCategory, name,
5532                                            vocabularyId, orderByComparator, false);
5533    
5534                            return array;
5535                    }
5536                    catch (Exception e) {
5537                            throw processException(e);
5538                    }
5539                    finally {
5540                            closeSession(session);
5541                    }
5542            }
5543    
5544            protected AssetCategory getByN_V_PrevAndNext(Session session,
5545                    AssetCategory assetCategory, String name, long vocabularyId,
5546                    OrderByComparator orderByComparator, boolean previous) {
5547                    StringBundler query = null;
5548    
5549                    if (orderByComparator != null) {
5550                            query = new StringBundler(6 +
5551                                            (orderByComparator.getOrderByFields().length * 6));
5552                    }
5553                    else {
5554                            query = new StringBundler(3);
5555                    }
5556    
5557                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5558    
5559                    if (name == null) {
5560                            query.append(_FINDER_COLUMN_N_V_NAME_1);
5561                    }
5562                    else {
5563                            if (name.equals(StringPool.BLANK)) {
5564                                    query.append(_FINDER_COLUMN_N_V_NAME_3);
5565                            }
5566                            else {
5567                                    query.append(_FINDER_COLUMN_N_V_NAME_2);
5568                            }
5569                    }
5570    
5571                    query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
5572    
5573                    if (orderByComparator != null) {
5574                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5575    
5576                            if (orderByConditionFields.length > 0) {
5577                                    query.append(WHERE_AND);
5578                            }
5579    
5580                            for (int i = 0; i < orderByConditionFields.length; i++) {
5581                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5582                                    query.append(orderByConditionFields[i]);
5583    
5584                                    if ((i + 1) < orderByConditionFields.length) {
5585                                            if (orderByComparator.isAscending() ^ previous) {
5586                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5587                                            }
5588                                            else {
5589                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5590                                            }
5591                                    }
5592                                    else {
5593                                            if (orderByComparator.isAscending() ^ previous) {
5594                                                    query.append(WHERE_GREATER_THAN);
5595                                            }
5596                                            else {
5597                                                    query.append(WHERE_LESSER_THAN);
5598                                            }
5599                                    }
5600                            }
5601    
5602                            query.append(ORDER_BY_CLAUSE);
5603    
5604                            String[] orderByFields = orderByComparator.getOrderByFields();
5605    
5606                            for (int i = 0; i < orderByFields.length; i++) {
5607                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5608                                    query.append(orderByFields[i]);
5609    
5610                                    if ((i + 1) < orderByFields.length) {
5611                                            if (orderByComparator.isAscending() ^ previous) {
5612                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5613                                            }
5614                                            else {
5615                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5616                                            }
5617                                    }
5618                                    else {
5619                                            if (orderByComparator.isAscending() ^ previous) {
5620                                                    query.append(ORDER_BY_ASC);
5621                                            }
5622                                            else {
5623                                                    query.append(ORDER_BY_DESC);
5624                                            }
5625                                    }
5626                            }
5627                    }
5628                    else {
5629                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
5630                    }
5631    
5632                    String sql = query.toString();
5633    
5634                    Query q = session.createQuery(sql);
5635    
5636                    q.setFirstResult(0);
5637                    q.setMaxResults(2);
5638    
5639                    QueryPos qPos = QueryPos.getInstance(q);
5640    
5641                    if (name != null) {
5642                            qPos.add(name);
5643                    }
5644    
5645                    qPos.add(vocabularyId);
5646    
5647                    if (orderByComparator != null) {
5648                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
5649    
5650                            for (Object value : values) {
5651                                    qPos.add(value);
5652                            }
5653                    }
5654    
5655                    List<AssetCategory> list = q.list();
5656    
5657                    if (list.size() == 2) {
5658                            return list.get(1);
5659                    }
5660                    else {
5661                            return null;
5662                    }
5663            }
5664    
5665            /**
5666             * Removes all the asset categories where name = &#63; and vocabularyId = &#63; from the database.
5667             *
5668             * @param name the name
5669             * @param vocabularyId the vocabulary ID
5670             * @throws SystemException if a system exception occurred
5671             */
5672            public void removeByN_V(String name, long vocabularyId)
5673                    throws SystemException {
5674                    for (AssetCategory assetCategory : findByN_V(name, vocabularyId,
5675                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5676                            remove(assetCategory);
5677                    }
5678            }
5679    
5680            /**
5681             * Returns the number of asset categories where name = &#63; and vocabularyId = &#63;.
5682             *
5683             * @param name the name
5684             * @param vocabularyId the vocabulary ID
5685             * @return the number of matching asset categories
5686             * @throws SystemException if a system exception occurred
5687             */
5688            public int countByN_V(String name, long vocabularyId)
5689                    throws SystemException {
5690                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_V;
5691    
5692                    Object[] finderArgs = new Object[] { name, vocabularyId };
5693    
5694                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5695                                    this);
5696    
5697                    if (count == null) {
5698                            StringBundler query = new StringBundler(3);
5699    
5700                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
5701    
5702                            if (name == null) {
5703                                    query.append(_FINDER_COLUMN_N_V_NAME_1);
5704                            }
5705                            else {
5706                                    if (name.equals(StringPool.BLANK)) {
5707                                            query.append(_FINDER_COLUMN_N_V_NAME_3);
5708                                    }
5709                                    else {
5710                                            query.append(_FINDER_COLUMN_N_V_NAME_2);
5711                                    }
5712                            }
5713    
5714                            query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
5715    
5716                            String sql = query.toString();
5717    
5718                            Session session = null;
5719    
5720                            try {
5721                                    session = openSession();
5722    
5723                                    Query q = session.createQuery(sql);
5724    
5725                                    QueryPos qPos = QueryPos.getInstance(q);
5726    
5727                                    if (name != null) {
5728                                            qPos.add(name);
5729                                    }
5730    
5731                                    qPos.add(vocabularyId);
5732    
5733                                    count = (Long)q.uniqueResult();
5734    
5735                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5736                            }
5737                            catch (Exception e) {
5738                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5739    
5740                                    throw processException(e);
5741                            }
5742                            finally {
5743                                    closeSession(session);
5744                            }
5745                    }
5746    
5747                    return count.intValue();
5748            }
5749    
5750            private static final String _FINDER_COLUMN_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
5751            private static final String _FINDER_COLUMN_N_V_NAME_2 = "assetCategory.name = ? AND ";
5752            private static final String _FINDER_COLUMN_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = ?) AND ";
5753            private static final String _FINDER_COLUMN_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
5754            public static final FinderPath FINDER_PATH_FETCH_BY_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5755                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
5756                            AssetCategoryImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByP_N_V",
5757                            new String[] {
5758                                    Long.class.getName(), String.class.getName(),
5759                                    Long.class.getName()
5760                            },
5761                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5762                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
5763                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
5764            public static final FinderPath FINDER_PATH_COUNT_BY_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
5765                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5766                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_N_V",
5767                            new String[] {
5768                                    Long.class.getName(), String.class.getName(),
5769                                    Long.class.getName()
5770                            });
5771    
5772            /**
5773             * Returns the asset category where parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchCategoryException} if it could not be found.
5774             *
5775             * @param parentCategoryId the parent category ID
5776             * @param name the name
5777             * @param vocabularyId the vocabulary ID
5778             * @return the matching asset category
5779             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
5780             * @throws SystemException if a system exception occurred
5781             */
5782            public AssetCategory findByP_N_V(long parentCategoryId, String name,
5783                    long vocabularyId) throws NoSuchCategoryException, SystemException {
5784                    AssetCategory assetCategory = fetchByP_N_V(parentCategoryId, name,
5785                                    vocabularyId);
5786    
5787                    if (assetCategory == null) {
5788                            StringBundler msg = new StringBundler(8);
5789    
5790                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5791    
5792                            msg.append("parentCategoryId=");
5793                            msg.append(parentCategoryId);
5794    
5795                            msg.append(", name=");
5796                            msg.append(name);
5797    
5798                            msg.append(", vocabularyId=");
5799                            msg.append(vocabularyId);
5800    
5801                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5802    
5803                            if (_log.isWarnEnabled()) {
5804                                    _log.warn(msg.toString());
5805                            }
5806    
5807                            throw new NoSuchCategoryException(msg.toString());
5808                    }
5809    
5810                    return assetCategory;
5811            }
5812    
5813            /**
5814             * 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.
5815             *
5816             * @param parentCategoryId the parent category ID
5817             * @param name the name
5818             * @param vocabularyId the vocabulary ID
5819             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
5820             * @throws SystemException if a system exception occurred
5821             */
5822            public AssetCategory fetchByP_N_V(long parentCategoryId, String name,
5823                    long vocabularyId) throws SystemException {
5824                    return fetchByP_N_V(parentCategoryId, name, vocabularyId, true);
5825            }
5826    
5827            /**
5828             * 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.
5829             *
5830             * @param parentCategoryId the parent category ID
5831             * @param name the name
5832             * @param vocabularyId the vocabulary ID
5833             * @param retrieveFromCache whether to use the finder cache
5834             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
5835             * @throws SystemException if a system exception occurred
5836             */
5837            public AssetCategory fetchByP_N_V(long parentCategoryId, String name,
5838                    long vocabularyId, boolean retrieveFromCache) throws SystemException {
5839                    Object[] finderArgs = new Object[] { parentCategoryId, name, vocabularyId };
5840    
5841                    Object result = null;
5842    
5843                    if (retrieveFromCache) {
5844                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_P_N_V,
5845                                            finderArgs, this);
5846                    }
5847    
5848                    if (result instanceof AssetCategory) {
5849                            AssetCategory assetCategory = (AssetCategory)result;
5850    
5851                            if ((parentCategoryId != assetCategory.getParentCategoryId()) ||
5852                                            !Validator.equals(name, assetCategory.getName()) ||
5853                                            (vocabularyId != assetCategory.getVocabularyId())) {
5854                                    result = null;
5855                            }
5856                    }
5857    
5858                    if (result == null) {
5859                            StringBundler query = new StringBundler(5);
5860    
5861                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
5862    
5863                            query.append(_FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2);
5864    
5865                            if (name == null) {
5866                                    query.append(_FINDER_COLUMN_P_N_V_NAME_1);
5867                            }
5868                            else {
5869                                    if (name.equals(StringPool.BLANK)) {
5870                                            query.append(_FINDER_COLUMN_P_N_V_NAME_3);
5871                                    }
5872                                    else {
5873                                            query.append(_FINDER_COLUMN_P_N_V_NAME_2);
5874                                    }
5875                            }
5876    
5877                            query.append(_FINDER_COLUMN_P_N_V_VOCABULARYID_2);
5878    
5879                            String sql = query.toString();
5880    
5881                            Session session = null;
5882    
5883                            try {
5884                                    session = openSession();
5885    
5886                                    Query q = session.createQuery(sql);
5887    
5888                                    QueryPos qPos = QueryPos.getInstance(q);
5889    
5890                                    qPos.add(parentCategoryId);
5891    
5892                                    if (name != null) {
5893                                            qPos.add(name);
5894                                    }
5895    
5896                                    qPos.add(vocabularyId);
5897    
5898                                    List<AssetCategory> list = q.list();
5899    
5900                                    if (list.isEmpty()) {
5901                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
5902                                                    finderArgs, list);
5903                                    }
5904                                    else {
5905                                            AssetCategory assetCategory = list.get(0);
5906    
5907                                            result = assetCategory;
5908    
5909                                            cacheResult(assetCategory);
5910    
5911                                            if ((assetCategory.getParentCategoryId() != parentCategoryId) ||
5912                                                            (assetCategory.getName() == null) ||
5913                                                            !assetCategory.getName().equals(name) ||
5914                                                            (assetCategory.getVocabularyId() != vocabularyId)) {
5915                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
5916                                                            finderArgs, assetCategory);
5917                                            }
5918                                    }
5919                            }
5920                            catch (Exception e) {
5921                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V,
5922                                            finderArgs);
5923    
5924                                    throw processException(e);
5925                            }
5926                            finally {
5927                                    closeSession(session);
5928                            }
5929                    }
5930    
5931                    if (result instanceof List<?>) {
5932                            return null;
5933                    }
5934                    else {
5935                            return (AssetCategory)result;
5936                    }
5937            }
5938    
5939            /**
5940             * Removes the asset category where parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63; from the database.
5941             *
5942             * @param parentCategoryId the parent category ID
5943             * @param name the name
5944             * @param vocabularyId the vocabulary ID
5945             * @return the asset category that was removed
5946             * @throws SystemException if a system exception occurred
5947             */
5948            public AssetCategory removeByP_N_V(long parentCategoryId, String name,
5949                    long vocabularyId) throws NoSuchCategoryException, SystemException {
5950                    AssetCategory assetCategory = findByP_N_V(parentCategoryId, name,
5951                                    vocabularyId);
5952    
5953                    return remove(assetCategory);
5954            }
5955    
5956            /**
5957             * Returns the number of asset categories where parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
5958             *
5959             * @param parentCategoryId the parent category ID
5960             * @param name the name
5961             * @param vocabularyId the vocabulary ID
5962             * @return the number of matching asset categories
5963             * @throws SystemException if a system exception occurred
5964             */
5965            public int countByP_N_V(long parentCategoryId, String name,
5966                    long vocabularyId) throws SystemException {
5967                    FinderPath finderPath = FINDER_PATH_COUNT_BY_P_N_V;
5968    
5969                    Object[] finderArgs = new Object[] { parentCategoryId, name, vocabularyId };
5970    
5971                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5972                                    this);
5973    
5974                    if (count == null) {
5975                            StringBundler query = new StringBundler(4);
5976    
5977                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
5978    
5979                            query.append(_FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2);
5980    
5981                            if (name == null) {
5982                                    query.append(_FINDER_COLUMN_P_N_V_NAME_1);
5983                            }
5984                            else {
5985                                    if (name.equals(StringPool.BLANK)) {
5986                                            query.append(_FINDER_COLUMN_P_N_V_NAME_3);
5987                                    }
5988                                    else {
5989                                            query.append(_FINDER_COLUMN_P_N_V_NAME_2);
5990                                    }
5991                            }
5992    
5993                            query.append(_FINDER_COLUMN_P_N_V_VOCABULARYID_2);
5994    
5995                            String sql = query.toString();
5996    
5997                            Session session = null;
5998    
5999                            try {
6000                                    session = openSession();
6001    
6002                                    Query q = session.createQuery(sql);
6003    
6004                                    QueryPos qPos = QueryPos.getInstance(q);
6005    
6006                                    qPos.add(parentCategoryId);
6007    
6008                                    if (name != null) {
6009                                            qPos.add(name);
6010                                    }
6011    
6012                                    qPos.add(vocabularyId);
6013    
6014                                    count = (Long)q.uniqueResult();
6015    
6016                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6017                            }
6018                            catch (Exception e) {
6019                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6020    
6021                                    throw processException(e);
6022                            }
6023                            finally {
6024                                    closeSession(session);
6025                            }
6026                    }
6027    
6028                    return count.intValue();
6029            }
6030    
6031            private static final String _FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
6032            private static final String _FINDER_COLUMN_P_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
6033            private static final String _FINDER_COLUMN_P_N_V_NAME_2 = "assetCategory.name = ? AND ";
6034            private static final String _FINDER_COLUMN_P_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = ?) AND ";
6035            private static final String _FINDER_COLUMN_P_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
6036            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6037                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
6038                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
6039                            "findByG_P_N_V",
6040                            new String[] {
6041                                    Long.class.getName(), Long.class.getName(),
6042                                    String.class.getName(), Long.class.getName(),
6043                                    
6044                            Integer.class.getName(), Integer.class.getName(),
6045                                    OrderByComparator.class.getName()
6046                            });
6047            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V =
6048                    new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6049                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
6050                            AssetCategoryImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
6051                            "findByG_P_N_V",
6052                            new String[] {
6053                                    Long.class.getName(), Long.class.getName(),
6054                                    String.class.getName(), Long.class.getName()
6055                            },
6056                            AssetCategoryModelImpl.GROUPID_COLUMN_BITMASK |
6057                            AssetCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
6058                            AssetCategoryModelImpl.NAME_COLUMN_BITMASK |
6059                            AssetCategoryModelImpl.VOCABULARYID_COLUMN_BITMASK);
6060            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
6061                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
6062                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_N_V",
6063                            new String[] {
6064                                    Long.class.getName(), Long.class.getName(),
6065                                    String.class.getName(), Long.class.getName()
6066                            });
6067    
6068            /**
6069             * Returns all the asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
6070             *
6071             * @param groupId the group ID
6072             * @param parentCategoryId the parent category ID
6073             * @param name the name
6074             * @param vocabularyId the vocabulary ID
6075             * @return the matching asset categories
6076             * @throws SystemException if a system exception occurred
6077             */
6078            public List<AssetCategory> findByG_P_N_V(long groupId,
6079                    long parentCategoryId, String name, long vocabularyId)
6080                    throws SystemException {
6081                    return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
6082                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6083            }
6084    
6085            /**
6086             * Returns a range of all the asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
6087             *
6088             * <p>
6089             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6090             * </p>
6091             *
6092             * @param groupId the group ID
6093             * @param parentCategoryId the parent category ID
6094             * @param name the name
6095             * @param vocabularyId the vocabulary ID
6096             * @param start the lower bound of the range of asset categories
6097             * @param end the upper bound of the range of asset categories (not inclusive)
6098             * @return the range of matching asset categories
6099             * @throws SystemException if a system exception occurred
6100             */
6101            public List<AssetCategory> findByG_P_N_V(long groupId,
6102                    long parentCategoryId, String name, long vocabularyId, int start,
6103                    int end) throws SystemException {
6104                    return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
6105                            start, end, null);
6106            }
6107    
6108            /**
6109             * Returns an ordered range of all the asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
6110             *
6111             * <p>
6112             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6113             * </p>
6114             *
6115             * @param groupId the group ID
6116             * @param parentCategoryId the parent category ID
6117             * @param name the name
6118             * @param vocabularyId the vocabulary ID
6119             * @param start the lower bound of the range of asset categories
6120             * @param end the upper bound of the range of asset categories (not inclusive)
6121             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6122             * @return the ordered range of matching asset categories
6123             * @throws SystemException if a system exception occurred
6124             */
6125            public List<AssetCategory> findByG_P_N_V(long groupId,
6126                    long parentCategoryId, String name, long vocabularyId, int start,
6127                    int end, OrderByComparator orderByComparator) throws SystemException {
6128                    boolean pagination = true;
6129                    FinderPath finderPath = null;
6130                    Object[] finderArgs = null;
6131    
6132                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6133                                    (orderByComparator == null)) {
6134                            pagination = false;
6135                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V;
6136                            finderArgs = new Object[] {
6137                                            groupId, parentCategoryId, name, vocabularyId
6138                                    };
6139                    }
6140                    else {
6141                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_N_V;
6142                            finderArgs = new Object[] {
6143                                            groupId, parentCategoryId, name, vocabularyId,
6144                                            
6145                                            start, end, orderByComparator
6146                                    };
6147                    }
6148    
6149                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
6150                                    finderArgs, this);
6151    
6152                    if ((list != null) && !list.isEmpty()) {
6153                            for (AssetCategory assetCategory : list) {
6154                                    if ((groupId != assetCategory.getGroupId()) ||
6155                                                    (parentCategoryId != assetCategory.getParentCategoryId()) ||
6156                                                    !Validator.equals(name, assetCategory.getName()) ||
6157                                                    (vocabularyId != assetCategory.getVocabularyId())) {
6158                                            list = null;
6159    
6160                                            break;
6161                                    }
6162                            }
6163                    }
6164    
6165                    if (list == null) {
6166                            StringBundler query = null;
6167    
6168                            if (orderByComparator != null) {
6169                                    query = new StringBundler(6 +
6170                                                    (orderByComparator.getOrderByFields().length * 3));
6171                            }
6172                            else {
6173                                    query = new StringBundler(6);
6174                            }
6175    
6176                            query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6177    
6178                            query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
6179    
6180                            query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
6181    
6182                            if (name == null) {
6183                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
6184                            }
6185                            else {
6186                                    if (name.equals(StringPool.BLANK)) {
6187                                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
6188                                    }
6189                                    else {
6190                                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
6191                                    }
6192                            }
6193    
6194                            query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
6195    
6196                            if (orderByComparator != null) {
6197                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6198                                            orderByComparator);
6199                            }
6200                            else
6201                             if (pagination) {
6202                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6203                            }
6204    
6205                            String sql = query.toString();
6206    
6207                            Session session = null;
6208    
6209                            try {
6210                                    session = openSession();
6211    
6212                                    Query q = session.createQuery(sql);
6213    
6214                                    QueryPos qPos = QueryPos.getInstance(q);
6215    
6216                                    qPos.add(groupId);
6217    
6218                                    qPos.add(parentCategoryId);
6219    
6220                                    if (name != null) {
6221                                            qPos.add(name);
6222                                    }
6223    
6224                                    qPos.add(vocabularyId);
6225    
6226                                    if (!pagination) {
6227                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6228                                                            start, end, false);
6229    
6230                                            Collections.sort(list);
6231    
6232                                            list = new UnmodifiableList<AssetCategory>(list);
6233                                    }
6234                                    else {
6235                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
6236                                                            start, end);
6237                                    }
6238    
6239                                    cacheResult(list);
6240    
6241                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6242                            }
6243                            catch (Exception e) {
6244                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6245    
6246                                    throw processException(e);
6247                            }
6248                            finally {
6249                                    closeSession(session);
6250                            }
6251                    }
6252    
6253                    return list;
6254            }
6255    
6256            /**
6257             * Returns the first asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
6258             *
6259             * @param groupId the group ID
6260             * @param parentCategoryId the parent category ID
6261             * @param name the name
6262             * @param vocabularyId the vocabulary ID
6263             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6264             * @return the first matching asset category
6265             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
6266             * @throws SystemException if a system exception occurred
6267             */
6268            public AssetCategory findByG_P_N_V_First(long groupId,
6269                    long parentCategoryId, String name, long vocabularyId,
6270                    OrderByComparator orderByComparator)
6271                    throws NoSuchCategoryException, SystemException {
6272                    AssetCategory assetCategory = fetchByG_P_N_V_First(groupId,
6273                                    parentCategoryId, name, vocabularyId, orderByComparator);
6274    
6275                    if (assetCategory != null) {
6276                            return assetCategory;
6277                    }
6278    
6279                    StringBundler msg = new StringBundler(10);
6280    
6281                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6282    
6283                    msg.append("groupId=");
6284                    msg.append(groupId);
6285    
6286                    msg.append(", parentCategoryId=");
6287                    msg.append(parentCategoryId);
6288    
6289                    msg.append(", name=");
6290                    msg.append(name);
6291    
6292                    msg.append(", vocabularyId=");
6293                    msg.append(vocabularyId);
6294    
6295                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6296    
6297                    throw new NoSuchCategoryException(msg.toString());
6298            }
6299    
6300            /**
6301             * Returns the first asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
6302             *
6303             * @param groupId the group ID
6304             * @param parentCategoryId the parent category ID
6305             * @param name the name
6306             * @param vocabularyId the vocabulary ID
6307             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6308             * @return the first matching asset category, or <code>null</code> if a matching asset category could not be found
6309             * @throws SystemException if a system exception occurred
6310             */
6311            public AssetCategory fetchByG_P_N_V_First(long groupId,
6312                    long parentCategoryId, String name, long vocabularyId,
6313                    OrderByComparator orderByComparator) throws SystemException {
6314                    List<AssetCategory> list = findByG_P_N_V(groupId, parentCategoryId,
6315                                    name, vocabularyId, 0, 1, orderByComparator);
6316    
6317                    if (!list.isEmpty()) {
6318                            return list.get(0);
6319                    }
6320    
6321                    return null;
6322            }
6323    
6324            /**
6325             * Returns the last asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
6326             *
6327             * @param groupId the group ID
6328             * @param parentCategoryId the parent category ID
6329             * @param name the name
6330             * @param vocabularyId the vocabulary ID
6331             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6332             * @return the last matching asset category
6333             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
6334             * @throws SystemException if a system exception occurred
6335             */
6336            public AssetCategory findByG_P_N_V_Last(long groupId,
6337                    long parentCategoryId, String name, long vocabularyId,
6338                    OrderByComparator orderByComparator)
6339                    throws NoSuchCategoryException, SystemException {
6340                    AssetCategory assetCategory = fetchByG_P_N_V_Last(groupId,
6341                                    parentCategoryId, name, vocabularyId, orderByComparator);
6342    
6343                    if (assetCategory != null) {
6344                            return assetCategory;
6345                    }
6346    
6347                    StringBundler msg = new StringBundler(10);
6348    
6349                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6350    
6351                    msg.append("groupId=");
6352                    msg.append(groupId);
6353    
6354                    msg.append(", parentCategoryId=");
6355                    msg.append(parentCategoryId);
6356    
6357                    msg.append(", name=");
6358                    msg.append(name);
6359    
6360                    msg.append(", vocabularyId=");
6361                    msg.append(vocabularyId);
6362    
6363                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6364    
6365                    throw new NoSuchCategoryException(msg.toString());
6366            }
6367    
6368            /**
6369             * Returns the last asset category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
6370             *
6371             * @param groupId the group ID
6372             * @param parentCategoryId the parent category ID
6373             * @param name the name
6374             * @param vocabularyId the vocabulary ID
6375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6376             * @return the last matching asset category, or <code>null</code> if a matching asset category could not be found
6377             * @throws SystemException if a system exception occurred
6378             */
6379            public AssetCategory fetchByG_P_N_V_Last(long groupId,
6380                    long parentCategoryId, String name, long vocabularyId,
6381                    OrderByComparator orderByComparator) throws SystemException {
6382                    int count = countByG_P_N_V(groupId, parentCategoryId, name, vocabularyId);
6383    
6384                    List<AssetCategory> list = findByG_P_N_V(groupId, parentCategoryId,
6385                                    name, vocabularyId, count - 1, count, orderByComparator);
6386    
6387                    if (!list.isEmpty()) {
6388                            return list.get(0);
6389                    }
6390    
6391                    return null;
6392            }
6393    
6394            /**
6395             * 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;.
6396             *
6397             * @param categoryId the primary key of the current asset category
6398             * @param groupId the group ID
6399             * @param parentCategoryId the parent category ID
6400             * @param name the name
6401             * @param vocabularyId the vocabulary ID
6402             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6403             * @return the previous, current, and next asset category
6404             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
6405             * @throws SystemException if a system exception occurred
6406             */
6407            public AssetCategory[] findByG_P_N_V_PrevAndNext(long categoryId,
6408                    long groupId, long parentCategoryId, String name, long vocabularyId,
6409                    OrderByComparator orderByComparator)
6410                    throws NoSuchCategoryException, SystemException {
6411                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
6412    
6413                    Session session = null;
6414    
6415                    try {
6416                            session = openSession();
6417    
6418                            AssetCategory[] array = new AssetCategoryImpl[3];
6419    
6420                            array[0] = getByG_P_N_V_PrevAndNext(session, assetCategory,
6421                                            groupId, parentCategoryId, name, vocabularyId,
6422                                            orderByComparator, true);
6423    
6424                            array[1] = assetCategory;
6425    
6426                            array[2] = getByG_P_N_V_PrevAndNext(session, assetCategory,
6427                                            groupId, parentCategoryId, name, vocabularyId,
6428                                            orderByComparator, false);
6429    
6430                            return array;
6431                    }
6432                    catch (Exception e) {
6433                            throw processException(e);
6434                    }
6435                    finally {
6436                            closeSession(session);
6437                    }
6438            }
6439    
6440            protected AssetCategory getByG_P_N_V_PrevAndNext(Session session,
6441                    AssetCategory assetCategory, long groupId, long parentCategoryId,
6442                    String name, long vocabularyId, OrderByComparator orderByComparator,
6443                    boolean previous) {
6444                    StringBundler query = null;
6445    
6446                    if (orderByComparator != null) {
6447                            query = new StringBundler(6 +
6448                                            (orderByComparator.getOrderByFields().length * 6));
6449                    }
6450                    else {
6451                            query = new StringBundler(3);
6452                    }
6453    
6454                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
6455    
6456                    query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
6457    
6458                    query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
6459    
6460                    if (name == null) {
6461                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
6462                    }
6463                    else {
6464                            if (name.equals(StringPool.BLANK)) {
6465                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
6466                            }
6467                            else {
6468                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
6469                            }
6470                    }
6471    
6472                    query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
6473    
6474                    if (orderByComparator != null) {
6475                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6476    
6477                            if (orderByConditionFields.length > 0) {
6478                                    query.append(WHERE_AND);
6479                            }
6480    
6481                            for (int i = 0; i < orderByConditionFields.length; i++) {
6482                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6483                                    query.append(orderByConditionFields[i]);
6484    
6485                                    if ((i + 1) < orderByConditionFields.length) {
6486                                            if (orderByComparator.isAscending() ^ previous) {
6487                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6488                                            }
6489                                            else {
6490                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6491                                            }
6492                                    }
6493                                    else {
6494                                            if (orderByComparator.isAscending() ^ previous) {
6495                                                    query.append(WHERE_GREATER_THAN);
6496                                            }
6497                                            else {
6498                                                    query.append(WHERE_LESSER_THAN);
6499                                            }
6500                                    }
6501                            }
6502    
6503                            query.append(ORDER_BY_CLAUSE);
6504    
6505                            String[] orderByFields = orderByComparator.getOrderByFields();
6506    
6507                            for (int i = 0; i < orderByFields.length; i++) {
6508                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6509                                    query.append(orderByFields[i]);
6510    
6511                                    if ((i + 1) < orderByFields.length) {
6512                                            if (orderByComparator.isAscending() ^ previous) {
6513                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6514                                            }
6515                                            else {
6516                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6517                                            }
6518                                    }
6519                                    else {
6520                                            if (orderByComparator.isAscending() ^ previous) {
6521                                                    query.append(ORDER_BY_ASC);
6522                                            }
6523                                            else {
6524                                                    query.append(ORDER_BY_DESC);
6525                                            }
6526                                    }
6527                            }
6528                    }
6529                    else {
6530                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6531                    }
6532    
6533                    String sql = query.toString();
6534    
6535                    Query q = session.createQuery(sql);
6536    
6537                    q.setFirstResult(0);
6538                    q.setMaxResults(2);
6539    
6540                    QueryPos qPos = QueryPos.getInstance(q);
6541    
6542                    qPos.add(groupId);
6543    
6544                    qPos.add(parentCategoryId);
6545    
6546                    if (name != null) {
6547                            qPos.add(name);
6548                    }
6549    
6550                    qPos.add(vocabularyId);
6551    
6552                    if (orderByComparator != null) {
6553                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
6554    
6555                            for (Object value : values) {
6556                                    qPos.add(value);
6557                            }
6558                    }
6559    
6560                    List<AssetCategory> list = q.list();
6561    
6562                    if (list.size() == 2) {
6563                            return list.get(1);
6564                    }
6565                    else {
6566                            return null;
6567                    }
6568            }
6569    
6570            /**
6571             * Returns all the asset categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
6572             *
6573             * @param groupId the group ID
6574             * @param parentCategoryId the parent category ID
6575             * @param name the name
6576             * @param vocabularyId the vocabulary ID
6577             * @return the matching asset categories that the user has permission to view
6578             * @throws SystemException if a system exception occurred
6579             */
6580            public List<AssetCategory> filterFindByG_P_N_V(long groupId,
6581                    long parentCategoryId, String name, long vocabularyId)
6582                    throws SystemException {
6583                    return filterFindByG_P_N_V(groupId, parentCategoryId, name,
6584                            vocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6585            }
6586    
6587            /**
6588             * 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;.
6589             *
6590             * <p>
6591             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6592             * </p>
6593             *
6594             * @param groupId the group ID
6595             * @param parentCategoryId the parent category ID
6596             * @param name the name
6597             * @param vocabularyId the vocabulary ID
6598             * @param start the lower bound of the range of asset categories
6599             * @param end the upper bound of the range of asset categories (not inclusive)
6600             * @return the range of matching asset categories that the user has permission to view
6601             * @throws SystemException if a system exception occurred
6602             */
6603            public List<AssetCategory> filterFindByG_P_N_V(long groupId,
6604                    long parentCategoryId, String name, long vocabularyId, int start,
6605                    int end) throws SystemException {
6606                    return filterFindByG_P_N_V(groupId, parentCategoryId, name,
6607                            vocabularyId, start, end, null);
6608            }
6609    
6610            /**
6611             * 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;.
6612             *
6613             * <p>
6614             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6615             * </p>
6616             *
6617             * @param groupId the group ID
6618             * @param parentCategoryId the parent category ID
6619             * @param name the name
6620             * @param vocabularyId the vocabulary ID
6621             * @param start the lower bound of the range of asset categories
6622             * @param end the upper bound of the range of asset categories (not inclusive)
6623             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6624             * @return the ordered range of matching asset categories that the user has permission to view
6625             * @throws SystemException if a system exception occurred
6626             */
6627            public List<AssetCategory> filterFindByG_P_N_V(long groupId,
6628                    long parentCategoryId, String name, long vocabularyId, int start,
6629                    int end, OrderByComparator orderByComparator) throws SystemException {
6630                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6631                            return findByG_P_N_V(groupId, parentCategoryId, name, vocabularyId,
6632                                    start, end, orderByComparator);
6633                    }
6634    
6635                    StringBundler query = null;
6636    
6637                    if (orderByComparator != null) {
6638                            query = new StringBundler(6 +
6639                                            (orderByComparator.getOrderByFields().length * 3));
6640                    }
6641                    else {
6642                            query = new StringBundler(6);
6643                    }
6644    
6645                    if (getDB().isSupportsInlineDistinct()) {
6646                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
6647                    }
6648                    else {
6649                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6650                    }
6651    
6652                    query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
6653    
6654                    query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
6655    
6656                    if (name == null) {
6657                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
6658                    }
6659                    else {
6660                            if (name.equals(StringPool.BLANK)) {
6661                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
6662                            }
6663                            else {
6664                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
6665                            }
6666                    }
6667    
6668                    query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
6669    
6670                    if (!getDB().isSupportsInlineDistinct()) {
6671                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6672                    }
6673    
6674                    if (orderByComparator != null) {
6675                            if (getDB().isSupportsInlineDistinct()) {
6676                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6677                                            orderByComparator);
6678                            }
6679                            else {
6680                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6681                                            orderByComparator);
6682                            }
6683                    }
6684                    else {
6685                            if (getDB().isSupportsInlineDistinct()) {
6686                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6687                            }
6688                            else {
6689                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
6690                            }
6691                    }
6692    
6693                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6694                                    AssetCategory.class.getName(),
6695                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6696    
6697                    Session session = null;
6698    
6699                    try {
6700                            session = openSession();
6701    
6702                            SQLQuery q = session.createSQLQuery(sql);
6703    
6704                            if (getDB().isSupportsInlineDistinct()) {
6705                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
6706                            }
6707                            else {
6708                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
6709                            }
6710    
6711                            QueryPos qPos = QueryPos.getInstance(q);
6712    
6713                            qPos.add(groupId);
6714    
6715                            qPos.add(parentCategoryId);
6716    
6717                            if (name != null) {
6718                                    qPos.add(name);
6719                            }
6720    
6721                            qPos.add(vocabularyId);
6722    
6723                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
6724                                    end);
6725                    }
6726                    catch (Exception e) {
6727                            throw processException(e);
6728                    }
6729                    finally {
6730                            closeSession(session);
6731                    }
6732            }
6733    
6734            /**
6735             * 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;.
6736             *
6737             * @param categoryId the primary key of the current asset category
6738             * @param groupId the group ID
6739             * @param parentCategoryId the parent category ID
6740             * @param name the name
6741             * @param vocabularyId the vocabulary ID
6742             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6743             * @return the previous, current, and next asset category
6744             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
6745             * @throws SystemException if a system exception occurred
6746             */
6747            public AssetCategory[] filterFindByG_P_N_V_PrevAndNext(long categoryId,
6748                    long groupId, long parentCategoryId, String name, long vocabularyId,
6749                    OrderByComparator orderByComparator)
6750                    throws NoSuchCategoryException, SystemException {
6751                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6752                            return findByG_P_N_V_PrevAndNext(categoryId, groupId,
6753                                    parentCategoryId, name, vocabularyId, orderByComparator);
6754                    }
6755    
6756                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
6757    
6758                    Session session = null;
6759    
6760                    try {
6761                            session = openSession();
6762    
6763                            AssetCategory[] array = new AssetCategoryImpl[3];
6764    
6765                            array[0] = filterGetByG_P_N_V_PrevAndNext(session, assetCategory,
6766                                            groupId, parentCategoryId, name, vocabularyId,
6767                                            orderByComparator, true);
6768    
6769                            array[1] = assetCategory;
6770    
6771                            array[2] = filterGetByG_P_N_V_PrevAndNext(session, assetCategory,
6772                                            groupId, parentCategoryId, name, vocabularyId,
6773                                            orderByComparator, false);
6774    
6775                            return array;
6776                    }
6777                    catch (Exception e) {
6778                            throw processException(e);
6779                    }
6780                    finally {
6781                            closeSession(session);
6782                    }
6783            }
6784    
6785            protected AssetCategory filterGetByG_P_N_V_PrevAndNext(Session session,
6786                    AssetCategory assetCategory, long groupId, long parentCategoryId,
6787                    String name, long vocabularyId, OrderByComparator orderByComparator,
6788                    boolean previous) {
6789                    StringBundler query = null;
6790    
6791                    if (orderByComparator != null) {
6792                            query = new StringBundler(6 +
6793                                            (orderByComparator.getOrderByFields().length * 6));
6794                    }
6795                    else {
6796                            query = new StringBundler(3);
6797                    }
6798    
6799                    if (getDB().isSupportsInlineDistinct()) {
6800                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
6801                    }
6802                    else {
6803                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6804                    }
6805    
6806                    query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
6807    
6808                    query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
6809    
6810                    if (name == null) {
6811                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
6812                    }
6813                    else {
6814                            if (name.equals(StringPool.BLANK)) {
6815                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
6816                            }
6817                            else {
6818                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
6819                            }
6820                    }
6821    
6822                    query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
6823    
6824                    if (!getDB().isSupportsInlineDistinct()) {
6825                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6826                    }
6827    
6828                    if (orderByComparator != null) {
6829                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6830    
6831                            if (orderByConditionFields.length > 0) {
6832                                    query.append(WHERE_AND);
6833                            }
6834    
6835                            for (int i = 0; i < orderByConditionFields.length; i++) {
6836                                    if (getDB().isSupportsInlineDistinct()) {
6837                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6838                                    }
6839                                    else {
6840                                            query.append(_ORDER_BY_ENTITY_TABLE);
6841                                    }
6842    
6843                                    query.append(orderByConditionFields[i]);
6844    
6845                                    if ((i + 1) < orderByConditionFields.length) {
6846                                            if (orderByComparator.isAscending() ^ previous) {
6847                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6848                                            }
6849                                            else {
6850                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6851                                            }
6852                                    }
6853                                    else {
6854                                            if (orderByComparator.isAscending() ^ previous) {
6855                                                    query.append(WHERE_GREATER_THAN);
6856                                            }
6857                                            else {
6858                                                    query.append(WHERE_LESSER_THAN);
6859                                            }
6860                                    }
6861                            }
6862    
6863                            query.append(ORDER_BY_CLAUSE);
6864    
6865                            String[] orderByFields = orderByComparator.getOrderByFields();
6866    
6867                            for (int i = 0; i < orderByFields.length; i++) {
6868                                    if (getDB().isSupportsInlineDistinct()) {
6869                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6870                                    }
6871                                    else {
6872                                            query.append(_ORDER_BY_ENTITY_TABLE);
6873                                    }
6874    
6875                                    query.append(orderByFields[i]);
6876    
6877                                    if ((i + 1) < orderByFields.length) {
6878                                            if (orderByComparator.isAscending() ^ previous) {
6879                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6880                                            }
6881                                            else {
6882                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6883                                            }
6884                                    }
6885                                    else {
6886                                            if (orderByComparator.isAscending() ^ previous) {
6887                                                    query.append(ORDER_BY_ASC);
6888                                            }
6889                                            else {
6890                                                    query.append(ORDER_BY_DESC);
6891                                            }
6892                                    }
6893                            }
6894                    }
6895                    else {
6896                            if (getDB().isSupportsInlineDistinct()) {
6897                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
6898                            }
6899                            else {
6900                                    query.append(AssetCategoryModelImpl.ORDER_BY_SQL);
6901                            }
6902                    }
6903    
6904                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6905                                    AssetCategory.class.getName(),
6906                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6907    
6908                    SQLQuery q = session.createSQLQuery(sql);
6909    
6910                    q.setFirstResult(0);
6911                    q.setMaxResults(2);
6912    
6913                    if (getDB().isSupportsInlineDistinct()) {
6914                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
6915                    }
6916                    else {
6917                            q.addEntity(_FILTER_ENTITY_TABLE, AssetCategoryImpl.class);
6918                    }
6919    
6920                    QueryPos qPos = QueryPos.getInstance(q);
6921    
6922                    qPos.add(groupId);
6923    
6924                    qPos.add(parentCategoryId);
6925    
6926                    if (name != null) {
6927                            qPos.add(name);
6928                    }
6929    
6930                    qPos.add(vocabularyId);
6931    
6932                    if (orderByComparator != null) {
6933                            Object[] values = orderByComparator.getOrderByConditionValues(assetCategory);
6934    
6935                            for (Object value : values) {
6936                                    qPos.add(value);
6937                            }
6938                    }
6939    
6940                    List<AssetCategory> list = q.list();
6941    
6942                    if (list.size() == 2) {
6943                            return list.get(1);
6944                    }
6945                    else {
6946                            return null;
6947                    }
6948            }
6949    
6950            /**
6951             * Removes all the asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63; from the database.
6952             *
6953             * @param groupId the group ID
6954             * @param parentCategoryId the parent category ID
6955             * @param name the name
6956             * @param vocabularyId the vocabulary ID
6957             * @throws SystemException if a system exception occurred
6958             */
6959            public void removeByG_P_N_V(long groupId, long parentCategoryId,
6960                    String name, long vocabularyId) throws SystemException {
6961                    for (AssetCategory assetCategory : findByG_P_N_V(groupId,
6962                                    parentCategoryId, name, vocabularyId, QueryUtil.ALL_POS,
6963                                    QueryUtil.ALL_POS, null)) {
6964                            remove(assetCategory);
6965                    }
6966            }
6967    
6968            /**
6969             * Returns the number of asset categories where groupId = &#63; and parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
6970             *
6971             * @param groupId the group ID
6972             * @param parentCategoryId the parent category ID
6973             * @param name the name
6974             * @param vocabularyId the vocabulary ID
6975             * @return the number of matching asset categories
6976             * @throws SystemException if a system exception occurred
6977             */
6978            public int countByG_P_N_V(long groupId, long parentCategoryId, String name,
6979                    long vocabularyId) throws SystemException {
6980                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_N_V;
6981    
6982                    Object[] finderArgs = new Object[] {
6983                                    groupId, parentCategoryId, name, vocabularyId
6984                            };
6985    
6986                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6987                                    this);
6988    
6989                    if (count == null) {
6990                            StringBundler query = new StringBundler(5);
6991    
6992                            query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
6993    
6994                            query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
6995    
6996                            query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
6997    
6998                            if (name == null) {
6999                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
7000                            }
7001                            else {
7002                                    if (name.equals(StringPool.BLANK)) {
7003                                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
7004                                    }
7005                                    else {
7006                                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
7007                                    }
7008                            }
7009    
7010                            query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
7011    
7012                            String sql = query.toString();
7013    
7014                            Session session = null;
7015    
7016                            try {
7017                                    session = openSession();
7018    
7019                                    Query q = session.createQuery(sql);
7020    
7021                                    QueryPos qPos = QueryPos.getInstance(q);
7022    
7023                                    qPos.add(groupId);
7024    
7025                                    qPos.add(parentCategoryId);
7026    
7027                                    if (name != null) {
7028                                            qPos.add(name);
7029                                    }
7030    
7031                                    qPos.add(vocabularyId);
7032    
7033                                    count = (Long)q.uniqueResult();
7034    
7035                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7036                            }
7037                            catch (Exception e) {
7038                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7039    
7040                                    throw processException(e);
7041                            }
7042                            finally {
7043                                    closeSession(session);
7044                            }
7045                    }
7046    
7047                    return count.intValue();
7048            }
7049    
7050            /**
7051             * 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;.
7052             *
7053             * @param groupId the group ID
7054             * @param parentCategoryId the parent category ID
7055             * @param name the name
7056             * @param vocabularyId the vocabulary ID
7057             * @return the number of matching asset categories that the user has permission to view
7058             * @throws SystemException if a system exception occurred
7059             */
7060            public int filterCountByG_P_N_V(long groupId, long parentCategoryId,
7061                    String name, long vocabularyId) throws SystemException {
7062                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7063                            return countByG_P_N_V(groupId, parentCategoryId, name, vocabularyId);
7064                    }
7065    
7066                    StringBundler query = new StringBundler(5);
7067    
7068                    query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
7069    
7070                    query.append(_FINDER_COLUMN_G_P_N_V_GROUPID_2);
7071    
7072                    query.append(_FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2);
7073    
7074                    if (name == null) {
7075                            query.append(_FINDER_COLUMN_G_P_N_V_NAME_1);
7076                    }
7077                    else {
7078                            if (name.equals(StringPool.BLANK)) {
7079                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_3);
7080                            }
7081                            else {
7082                                    query.append(_FINDER_COLUMN_G_P_N_V_NAME_2);
7083                            }
7084                    }
7085    
7086                    query.append(_FINDER_COLUMN_G_P_N_V_VOCABULARYID_2);
7087    
7088                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7089                                    AssetCategory.class.getName(),
7090                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7091    
7092                    Session session = null;
7093    
7094                    try {
7095                            session = openSession();
7096    
7097                            SQLQuery q = session.createSQLQuery(sql);
7098    
7099                            q.addScalar(COUNT_COLUMN_NAME,
7100                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7101    
7102                            QueryPos qPos = QueryPos.getInstance(q);
7103    
7104                            qPos.add(groupId);
7105    
7106                            qPos.add(parentCategoryId);
7107    
7108                            if (name != null) {
7109                                    qPos.add(name);
7110                            }
7111    
7112                            qPos.add(vocabularyId);
7113    
7114                            Long count = (Long)q.uniqueResult();
7115    
7116                            return count.intValue();
7117                    }
7118                    catch (Exception e) {
7119                            throw processException(e);
7120                    }
7121                    finally {
7122                            closeSession(session);
7123                    }
7124            }
7125    
7126            private static final String _FINDER_COLUMN_G_P_N_V_GROUPID_2 = "assetCategory.groupId = ? AND ";
7127            private static final String _FINDER_COLUMN_G_P_N_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
7128            private static final String _FINDER_COLUMN_G_P_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
7129            private static final String _FINDER_COLUMN_G_P_N_V_NAME_2 = "assetCategory.name = ? AND ";
7130            private static final String _FINDER_COLUMN_G_P_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = ?) AND ";
7131            private static final String _FINDER_COLUMN_G_P_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
7132    
7133            /**
7134             * Caches the asset category in the entity cache if it is enabled.
7135             *
7136             * @param assetCategory the asset category
7137             */
7138            public void cacheResult(AssetCategory assetCategory) {
7139                    EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7140                            AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
7141                            assetCategory);
7142    
7143                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
7144                            new Object[] {
7145                                    assetCategory.getUuid(),
7146                                    Long.valueOf(assetCategory.getGroupId())
7147                            }, assetCategory);
7148    
7149                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
7150                            new Object[] {
7151                                    Long.valueOf(assetCategory.getParentCategoryId()),
7152                                    
7153                            assetCategory.getName(),
7154                                    Long.valueOf(assetCategory.getVocabularyId())
7155                            }, assetCategory);
7156    
7157                    assetCategory.resetOriginalValues();
7158            }
7159    
7160            /**
7161             * Caches the asset categories in the entity cache if it is enabled.
7162             *
7163             * @param assetCategories the asset categories
7164             */
7165            public void cacheResult(List<AssetCategory> assetCategories) {
7166                    for (AssetCategory assetCategory : assetCategories) {
7167                            if (EntityCacheUtil.getResult(
7168                                                    AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7169                                                    AssetCategoryImpl.class, assetCategory.getPrimaryKey()) == null) {
7170                                    cacheResult(assetCategory);
7171                            }
7172                            else {
7173                                    assetCategory.resetOriginalValues();
7174                            }
7175                    }
7176            }
7177    
7178            /**
7179             * Clears the cache for all asset categories.
7180             *
7181             * <p>
7182             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7183             * </p>
7184             */
7185            @Override
7186            public void clearCache() {
7187                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7188                            CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
7189                    }
7190    
7191                    EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
7192    
7193                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7194                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7195                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7196            }
7197    
7198            /**
7199             * Clears the cache for the asset category.
7200             *
7201             * <p>
7202             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7203             * </p>
7204             */
7205            @Override
7206            public void clearCache(AssetCategory assetCategory) {
7207                    EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7208                            AssetCategoryImpl.class, assetCategory.getPrimaryKey());
7209    
7210                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7211                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7212    
7213                    clearUniqueFindersCache(assetCategory);
7214            }
7215    
7216            @Override
7217            public void clearCache(List<AssetCategory> assetCategories) {
7218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7219                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7220    
7221                    for (AssetCategory assetCategory : assetCategories) {
7222                            EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7223                                    AssetCategoryImpl.class, assetCategory.getPrimaryKey());
7224    
7225                            clearUniqueFindersCache(assetCategory);
7226                    }
7227            }
7228    
7229            protected void cacheUniqueFindersCache(AssetCategory assetCategory) {
7230                    if (assetCategory.isNew()) {
7231                            Object[] args = new Object[] {
7232                                            assetCategory.getUuid(),
7233                                            Long.valueOf(assetCategory.getGroupId())
7234                                    };
7235    
7236                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7237                                    Long.valueOf(1));
7238                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7239                                    assetCategory);
7240    
7241                            args = new Object[] {
7242                                            Long.valueOf(assetCategory.getParentCategoryId()),
7243                                            
7244                                            assetCategory.getName(),
7245                                            Long.valueOf(assetCategory.getVocabularyId())
7246                                    };
7247    
7248                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_N_V, args,
7249                                    Long.valueOf(1));
7250                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V, args,
7251                                    assetCategory);
7252                    }
7253                    else {
7254                            AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
7255    
7256                            if ((assetCategoryModelImpl.getColumnBitmask() &
7257                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7258                                    Object[] args = new Object[] {
7259                                                    assetCategory.getUuid(),
7260                                                    Long.valueOf(assetCategory.getGroupId())
7261                                            };
7262    
7263                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7264                                            Long.valueOf(1));
7265                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7266                                            assetCategory);
7267                            }
7268    
7269                            if ((assetCategoryModelImpl.getColumnBitmask() &
7270                                            FINDER_PATH_FETCH_BY_P_N_V.getColumnBitmask()) != 0) {
7271                                    Object[] args = new Object[] {
7272                                                    Long.valueOf(assetCategory.getParentCategoryId()),
7273                                                    
7274                                                    assetCategory.getName(),
7275                                                    Long.valueOf(assetCategory.getVocabularyId())
7276                                            };
7277    
7278                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_N_V, args,
7279                                            Long.valueOf(1));
7280                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V, args,
7281                                            assetCategory);
7282                            }
7283                    }
7284            }
7285    
7286            protected void clearUniqueFindersCache(AssetCategory assetCategory) {
7287                    AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
7288    
7289                    Object[] args = new Object[] {
7290                                    assetCategory.getUuid(),
7291                                    Long.valueOf(assetCategory.getGroupId())
7292                            };
7293    
7294                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7295                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7296    
7297                    if ((assetCategoryModelImpl.getColumnBitmask() &
7298                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7299                            args = new Object[] {
7300                                            assetCategoryModelImpl.getOriginalUuid(),
7301                                            Long.valueOf(assetCategoryModelImpl.getOriginalGroupId())
7302                                    };
7303    
7304                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7305                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7306                    }
7307    
7308                    args = new Object[] {
7309                                    Long.valueOf(assetCategory.getParentCategoryId()),
7310                                    
7311                                    assetCategory.getName(),
7312                                    Long.valueOf(assetCategory.getVocabularyId())
7313                            };
7314    
7315                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N_V, args);
7316                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V, args);
7317    
7318                    if ((assetCategoryModelImpl.getColumnBitmask() &
7319                                    FINDER_PATH_FETCH_BY_P_N_V.getColumnBitmask()) != 0) {
7320                            args = new Object[] {
7321                                            Long.valueOf(assetCategoryModelImpl.getOriginalParentCategoryId()),
7322                                            
7323                                            assetCategoryModelImpl.getOriginalName(),
7324                                            Long.valueOf(assetCategoryModelImpl.getOriginalVocabularyId())
7325                                    };
7326    
7327                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N_V, args);
7328                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V, args);
7329                    }
7330            }
7331    
7332            /**
7333             * Creates a new asset category with the primary key. Does not add the asset category to the database.
7334             *
7335             * @param categoryId the primary key for the new asset category
7336             * @return the new asset category
7337             */
7338            public AssetCategory create(long categoryId) {
7339                    AssetCategory assetCategory = new AssetCategoryImpl();
7340    
7341                    assetCategory.setNew(true);
7342                    assetCategory.setPrimaryKey(categoryId);
7343    
7344                    String uuid = PortalUUIDUtil.generate();
7345    
7346                    assetCategory.setUuid(uuid);
7347    
7348                    return assetCategory;
7349            }
7350    
7351            /**
7352             * Removes the asset category with the primary key from the database. Also notifies the appropriate model listeners.
7353             *
7354             * @param categoryId the primary key of the asset category
7355             * @return the asset category that was removed
7356             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
7357             * @throws SystemException if a system exception occurred
7358             */
7359            public AssetCategory remove(long categoryId)
7360                    throws NoSuchCategoryException, SystemException {
7361                    return remove(Long.valueOf(categoryId));
7362            }
7363    
7364            /**
7365             * Removes the asset category with the primary key from the database. Also notifies the appropriate model listeners.
7366             *
7367             * @param primaryKey the primary key of the asset category
7368             * @return the asset category that was removed
7369             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
7370             * @throws SystemException if a system exception occurred
7371             */
7372            @Override
7373            public AssetCategory remove(Serializable primaryKey)
7374                    throws NoSuchCategoryException, SystemException {
7375                    Session session = null;
7376    
7377                    try {
7378                            session = openSession();
7379    
7380                            AssetCategory assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
7381                                            primaryKey);
7382    
7383                            if (assetCategory == null) {
7384                                    if (_log.isWarnEnabled()) {
7385                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7386                                    }
7387    
7388                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7389                                            primaryKey);
7390                            }
7391    
7392                            return remove(assetCategory);
7393                    }
7394                    catch (NoSuchCategoryException nsee) {
7395                            throw nsee;
7396                    }
7397                    catch (Exception e) {
7398                            throw processException(e);
7399                    }
7400                    finally {
7401                            closeSession(session);
7402                    }
7403            }
7404    
7405            @Override
7406            protected AssetCategory removeImpl(AssetCategory assetCategory)
7407                    throws SystemException {
7408                    assetCategory = toUnwrappedModel(assetCategory);
7409    
7410                    try {
7411                            clearAssetEntries.clear(assetCategory.getPrimaryKey());
7412                    }
7413                    catch (Exception e) {
7414                            throw processException(e);
7415                    }
7416                    finally {
7417                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
7418                    }
7419    
7420                    shrinkTree(assetCategory);
7421    
7422                    Session session = null;
7423    
7424                    try {
7425                            session = openSession();
7426    
7427                            if (!session.contains(assetCategory)) {
7428                                    assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
7429                                                    assetCategory.getPrimaryKeyObj());
7430                            }
7431    
7432                            if (assetCategory != null) {
7433                                    session.delete(assetCategory);
7434                            }
7435                    }
7436                    catch (Exception e) {
7437                            throw processException(e);
7438                    }
7439                    finally {
7440                            closeSession(session);
7441                    }
7442    
7443                    if (assetCategory != null) {
7444                            clearCache(assetCategory);
7445                    }
7446    
7447                    return assetCategory;
7448            }
7449    
7450            @Override
7451            public AssetCategory updateImpl(
7452                    com.liferay.portlet.asset.model.AssetCategory assetCategory)
7453                    throws SystemException {
7454                    assetCategory = toUnwrappedModel(assetCategory);
7455    
7456                    boolean isNew = assetCategory.isNew();
7457    
7458                    AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
7459    
7460                    if (Validator.isNull(assetCategory.getUuid())) {
7461                            String uuid = PortalUUIDUtil.generate();
7462    
7463                            assetCategory.setUuid(uuid);
7464                    }
7465    
7466                    if (isNew) {
7467                            expandTree(assetCategory, null);
7468                    }
7469                    else {
7470                            if (assetCategory.getParentCategoryId() != assetCategoryModelImpl.getOriginalParentCategoryId()) {
7471                                    List<Long> childrenCategoryIds = getChildrenTreeCategoryIds(assetCategory);
7472    
7473                                    shrinkTree(assetCategory);
7474                                    expandTree(assetCategory, childrenCategoryIds);
7475                            }
7476                    }
7477    
7478                    Session session = null;
7479    
7480                    try {
7481                            session = openSession();
7482    
7483                            if (assetCategory.isNew()) {
7484                                    session.save(assetCategory);
7485    
7486                                    assetCategory.setNew(false);
7487                            }
7488                            else {
7489                                    session.merge(assetCategory);
7490                            }
7491                    }
7492                    catch (Exception e) {
7493                            throw processException(e);
7494                    }
7495                    finally {
7496                            closeSession(session);
7497                    }
7498    
7499                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7500    
7501                    if (isNew || !AssetCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
7502                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7503                    }
7504    
7505                    else {
7506                            if ((assetCategoryModelImpl.getColumnBitmask() &
7507                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
7508                                    Object[] args = new Object[] {
7509                                                    assetCategoryModelImpl.getOriginalUuid()
7510                                            };
7511    
7512                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7513                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7514                                            args);
7515    
7516                                    args = new Object[] { assetCategoryModelImpl.getUuid() };
7517    
7518                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7519                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7520                                            args);
7521                            }
7522    
7523                            if ((assetCategoryModelImpl.getColumnBitmask() &
7524                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
7525                                    Object[] args = new Object[] {
7526                                                    assetCategoryModelImpl.getOriginalUuid(),
7527                                                    Long.valueOf(assetCategoryModelImpl.getOriginalCompanyId())
7528                                            };
7529    
7530                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7531                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7532                                            args);
7533    
7534                                    args = new Object[] {
7535                                                    assetCategoryModelImpl.getUuid(),
7536                                                    Long.valueOf(assetCategoryModelImpl.getCompanyId())
7537                                            };
7538    
7539                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7540                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7541                                            args);
7542                            }
7543    
7544                            if ((assetCategoryModelImpl.getColumnBitmask() &
7545                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
7546                                    Object[] args = new Object[] {
7547                                                    Long.valueOf(assetCategoryModelImpl.getOriginalGroupId())
7548                                            };
7549    
7550                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7551                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7552                                            args);
7553    
7554                                    args = new Object[] {
7555                                                    Long.valueOf(assetCategoryModelImpl.getGroupId())
7556                                            };
7557    
7558                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7559                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7560                                            args);
7561                            }
7562    
7563                            if ((assetCategoryModelImpl.getColumnBitmask() &
7564                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID.getColumnBitmask()) != 0) {
7565                                    Object[] args = new Object[] {
7566                                                    Long.valueOf(assetCategoryModelImpl.getOriginalParentCategoryId())
7567                                            };
7568    
7569                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTCATEGORYID,
7570                                            args);
7571                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID,
7572                                            args);
7573    
7574                                    args = new Object[] {
7575                                                    Long.valueOf(assetCategoryModelImpl.getParentCategoryId())
7576                                            };
7577    
7578                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PARENTCATEGORYID,
7579                                            args);
7580                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PARENTCATEGORYID,
7581                                            args);
7582                            }
7583    
7584                            if ((assetCategoryModelImpl.getColumnBitmask() &
7585                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID.getColumnBitmask()) != 0) {
7586                                    Object[] args = new Object[] {
7587                                                    Long.valueOf(assetCategoryModelImpl.getOriginalVocabularyId())
7588                                            };
7589    
7590                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VOCABULARYID,
7591                                            args);
7592                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID,
7593                                            args);
7594    
7595                                    args = new Object[] {
7596                                                    Long.valueOf(assetCategoryModelImpl.getVocabularyId())
7597                                            };
7598    
7599                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VOCABULARYID,
7600                                            args);
7601                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VOCABULARYID,
7602                                            args);
7603                            }
7604    
7605                            if ((assetCategoryModelImpl.getColumnBitmask() &
7606                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V.getColumnBitmask()) != 0) {
7607                                    Object[] args = new Object[] {
7608                                                    Long.valueOf(assetCategoryModelImpl.getOriginalGroupId()),
7609                                                    Long.valueOf(assetCategoryModelImpl.getOriginalVocabularyId())
7610                                            };
7611    
7612                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_V, args);
7613                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V,
7614                                            args);
7615    
7616                                    args = new Object[] {
7617                                                    Long.valueOf(assetCategoryModelImpl.getGroupId()),
7618                                                    Long.valueOf(assetCategoryModelImpl.getVocabularyId())
7619                                            };
7620    
7621                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_V, args);
7622                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_V,
7623                                            args);
7624                            }
7625    
7626                            if ((assetCategoryModelImpl.getColumnBitmask() &
7627                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N.getColumnBitmask()) != 0) {
7628                                    Object[] args = new Object[] {
7629                                                    Long.valueOf(assetCategoryModelImpl.getOriginalParentCategoryId()),
7630                                                    
7631                                                    assetCategoryModelImpl.getOriginalName()
7632                                            };
7633    
7634                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
7635                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
7636                                            args);
7637    
7638                                    args = new Object[] {
7639                                                    Long.valueOf(assetCategoryModelImpl.getParentCategoryId()),
7640                                                    
7641                                                    assetCategoryModelImpl.getName()
7642                                            };
7643    
7644                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_N, args);
7645                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_N,
7646                                            args);
7647                            }
7648    
7649                            if ((assetCategoryModelImpl.getColumnBitmask() &
7650                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V.getColumnBitmask()) != 0) {
7651                                    Object[] args = new Object[] {
7652                                                    Long.valueOf(assetCategoryModelImpl.getOriginalParentCategoryId()),
7653                                                    Long.valueOf(assetCategoryModelImpl.getOriginalVocabularyId())
7654                                            };
7655    
7656                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_V, args);
7657                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V,
7658                                            args);
7659    
7660                                    args = new Object[] {
7661                                                    Long.valueOf(assetCategoryModelImpl.getParentCategoryId()),
7662                                                    Long.valueOf(assetCategoryModelImpl.getVocabularyId())
7663                                            };
7664    
7665                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_V, args);
7666                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_V,
7667                                            args);
7668                            }
7669    
7670                            if ((assetCategoryModelImpl.getColumnBitmask() &
7671                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V.getColumnBitmask()) != 0) {
7672                                    Object[] args = new Object[] {
7673                                                    assetCategoryModelImpl.getOriginalName(),
7674                                                    Long.valueOf(assetCategoryModelImpl.getOriginalVocabularyId())
7675                                            };
7676    
7677                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_V, args);
7678                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V,
7679                                            args);
7680    
7681                                    args = new Object[] {
7682                                                    assetCategoryModelImpl.getName(),
7683                                                    Long.valueOf(assetCategoryModelImpl.getVocabularyId())
7684                                            };
7685    
7686                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_V, args);
7687                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_N_V,
7688                                            args);
7689                            }
7690    
7691                            if ((assetCategoryModelImpl.getColumnBitmask() &
7692                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V.getColumnBitmask()) != 0) {
7693                                    Object[] args = new Object[] {
7694                                                    Long.valueOf(assetCategoryModelImpl.getOriginalGroupId()),
7695                                                    Long.valueOf(assetCategoryModelImpl.getOriginalParentCategoryId()),
7696                                                    
7697                                                    assetCategoryModelImpl.getOriginalName(),
7698                                                    Long.valueOf(assetCategoryModelImpl.getOriginalVocabularyId())
7699                                            };
7700    
7701                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N_V, args);
7702                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V,
7703                                            args);
7704    
7705                                    args = new Object[] {
7706                                                    Long.valueOf(assetCategoryModelImpl.getGroupId()),
7707                                                    Long.valueOf(assetCategoryModelImpl.getParentCategoryId()),
7708                                                    
7709                                                    assetCategoryModelImpl.getName(),
7710                                                    Long.valueOf(assetCategoryModelImpl.getVocabularyId())
7711                                            };
7712    
7713                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_N_V, args);
7714                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_N_V,
7715                                            args);
7716                            }
7717                    }
7718    
7719                    EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7720                            AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
7721                            assetCategory);
7722    
7723                    clearUniqueFindersCache(assetCategory);
7724                    cacheUniqueFindersCache(assetCategory);
7725    
7726                    return assetCategory;
7727            }
7728    
7729            protected AssetCategory toUnwrappedModel(AssetCategory assetCategory) {
7730                    if (assetCategory instanceof AssetCategoryImpl) {
7731                            return assetCategory;
7732                    }
7733    
7734                    AssetCategoryImpl assetCategoryImpl = new AssetCategoryImpl();
7735    
7736                    assetCategoryImpl.setNew(assetCategory.isNew());
7737                    assetCategoryImpl.setPrimaryKey(assetCategory.getPrimaryKey());
7738    
7739                    assetCategoryImpl.setUuid(assetCategory.getUuid());
7740                    assetCategoryImpl.setCategoryId(assetCategory.getCategoryId());
7741                    assetCategoryImpl.setGroupId(assetCategory.getGroupId());
7742                    assetCategoryImpl.setCompanyId(assetCategory.getCompanyId());
7743                    assetCategoryImpl.setUserId(assetCategory.getUserId());
7744                    assetCategoryImpl.setUserName(assetCategory.getUserName());
7745                    assetCategoryImpl.setCreateDate(assetCategory.getCreateDate());
7746                    assetCategoryImpl.setModifiedDate(assetCategory.getModifiedDate());
7747                    assetCategoryImpl.setParentCategoryId(assetCategory.getParentCategoryId());
7748                    assetCategoryImpl.setLeftCategoryId(assetCategory.getLeftCategoryId());
7749                    assetCategoryImpl.setRightCategoryId(assetCategory.getRightCategoryId());
7750                    assetCategoryImpl.setName(assetCategory.getName());
7751                    assetCategoryImpl.setTitle(assetCategory.getTitle());
7752                    assetCategoryImpl.setDescription(assetCategory.getDescription());
7753                    assetCategoryImpl.setVocabularyId(assetCategory.getVocabularyId());
7754    
7755                    return assetCategoryImpl;
7756            }
7757    
7758            /**
7759             * Returns the asset category with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
7760             *
7761             * @param primaryKey the primary key of the asset category
7762             * @return the asset category
7763             * @throws com.liferay.portal.NoSuchModelException if a asset category with the primary key could not be found
7764             * @throws SystemException if a system exception occurred
7765             */
7766            @Override
7767            public AssetCategory findByPrimaryKey(Serializable primaryKey)
7768                    throws NoSuchModelException, SystemException {
7769                    return findByPrimaryKey(((Long)primaryKey).longValue());
7770            }
7771    
7772            /**
7773             * Returns the asset category with the primary key or throws a {@link com.liferay.portlet.asset.NoSuchCategoryException} if it could not be found.
7774             *
7775             * @param categoryId the primary key of the asset category
7776             * @return the asset category
7777             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
7778             * @throws SystemException if a system exception occurred
7779             */
7780            public AssetCategory findByPrimaryKey(long categoryId)
7781                    throws NoSuchCategoryException, SystemException {
7782                    AssetCategory assetCategory = fetchByPrimaryKey(categoryId);
7783    
7784                    if (assetCategory == null) {
7785                            if (_log.isWarnEnabled()) {
7786                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
7787                            }
7788    
7789                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7790                                    categoryId);
7791                    }
7792    
7793                    return assetCategory;
7794            }
7795    
7796            /**
7797             * Returns the asset category with the primary key or returns <code>null</code> if it could not be found.
7798             *
7799             * @param primaryKey the primary key of the asset category
7800             * @return the asset category, or <code>null</code> if a asset category with the primary key could not be found
7801             * @throws SystemException if a system exception occurred
7802             */
7803            @Override
7804            public AssetCategory fetchByPrimaryKey(Serializable primaryKey)
7805                    throws SystemException {
7806                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
7807            }
7808    
7809            /**
7810             * Returns the asset category with the primary key or returns <code>null</code> if it could not be found.
7811             *
7812             * @param categoryId the primary key of the asset category
7813             * @return the asset category, or <code>null</code> if a asset category with the primary key could not be found
7814             * @throws SystemException if a system exception occurred
7815             */
7816            public AssetCategory fetchByPrimaryKey(long categoryId)
7817                    throws SystemException {
7818                    AssetCategory assetCategory = (AssetCategory)EntityCacheUtil.getResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7819                                    AssetCategoryImpl.class, categoryId);
7820    
7821                    if (assetCategory == _nullAssetCategory) {
7822                            return null;
7823                    }
7824    
7825                    if (assetCategory == null) {
7826                            Session session = null;
7827    
7828                            try {
7829                                    session = openSession();
7830    
7831                                    assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
7832                                                    Long.valueOf(categoryId));
7833    
7834                                    if (assetCategory != null) {
7835                                            cacheResult(assetCategory);
7836                                    }
7837                                    else {
7838                                            EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7839                                                    AssetCategoryImpl.class, categoryId, _nullAssetCategory);
7840                                    }
7841                            }
7842                            catch (Exception e) {
7843                                    EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
7844                                            AssetCategoryImpl.class, categoryId);
7845    
7846                                    throw processException(e);
7847                            }
7848                            finally {
7849                                    closeSession(session);
7850                            }
7851                    }
7852    
7853                    return assetCategory;
7854            }
7855    
7856            /**
7857             * Returns all the asset categories.
7858             *
7859             * @return the asset categories
7860             * @throws SystemException if a system exception occurred
7861             */
7862            public List<AssetCategory> findAll() throws SystemException {
7863                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7864            }
7865    
7866            /**
7867             * Returns a range of all the asset categories.
7868             *
7869             * <p>
7870             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7871             * </p>
7872             *
7873             * @param start the lower bound of the range of asset categories
7874             * @param end the upper bound of the range of asset categories (not inclusive)
7875             * @return the range of asset categories
7876             * @throws SystemException if a system exception occurred
7877             */
7878            public List<AssetCategory> findAll(int start, int end)
7879                    throws SystemException {
7880                    return findAll(start, end, null);
7881            }
7882    
7883            /**
7884             * Returns an ordered range of all the asset categories.
7885             *
7886             * <p>
7887             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7888             * </p>
7889             *
7890             * @param start the lower bound of the range of asset categories
7891             * @param end the upper bound of the range of asset categories (not inclusive)
7892             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7893             * @return the ordered range of asset categories
7894             * @throws SystemException if a system exception occurred
7895             */
7896            public List<AssetCategory> findAll(int start, int end,
7897                    OrderByComparator orderByComparator) throws SystemException {
7898                    boolean pagination = true;
7899                    FinderPath finderPath = null;
7900                    Object[] finderArgs = null;
7901    
7902                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7903                                    (orderByComparator == null)) {
7904                            pagination = false;
7905                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7906                            finderArgs = FINDER_ARGS_EMPTY;
7907                    }
7908                    else {
7909                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7910                            finderArgs = new Object[] { start, end, orderByComparator };
7911                    }
7912    
7913                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(finderPath,
7914                                    finderArgs, this);
7915    
7916                    if (list == null) {
7917                            StringBundler query = null;
7918                            String sql = null;
7919    
7920                            if (orderByComparator != null) {
7921                                    query = new StringBundler(2 +
7922                                                    (orderByComparator.getOrderByFields().length * 3));
7923    
7924                                    query.append(_SQL_SELECT_ASSETCATEGORY);
7925    
7926                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7927                                            orderByComparator);
7928    
7929                                    sql = query.toString();
7930                            }
7931                            else {
7932                                    sql = _SQL_SELECT_ASSETCATEGORY;
7933    
7934                                    if (pagination) {
7935                                            sql = sql.concat(AssetCategoryModelImpl.ORDER_BY_JPQL);
7936                                    }
7937                            }
7938    
7939                            Session session = null;
7940    
7941                            try {
7942                                    session = openSession();
7943    
7944                                    Query q = session.createQuery(sql);
7945    
7946                                    if (!pagination) {
7947                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
7948                                                            start, end, false);
7949    
7950                                            Collections.sort(list);
7951    
7952                                            list = new UnmodifiableList<AssetCategory>(list);
7953                                    }
7954                                    else {
7955                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
7956                                                            start, end);
7957                                    }
7958    
7959                                    cacheResult(list);
7960    
7961                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7962                            }
7963                            catch (Exception e) {
7964                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7965    
7966                                    throw processException(e);
7967                            }
7968                            finally {
7969                                    closeSession(session);
7970                            }
7971                    }
7972    
7973                    return list;
7974            }
7975    
7976            /**
7977             * Removes all the asset categories from the database.
7978             *
7979             * @throws SystemException if a system exception occurred
7980             */
7981            public void removeAll() throws SystemException {
7982                    for (AssetCategory assetCategory : findAll()) {
7983                            remove(assetCategory);
7984                    }
7985            }
7986    
7987            /**
7988             * Returns the number of asset categories.
7989             *
7990             * @return the number of asset categories
7991             * @throws SystemException if a system exception occurred
7992             */
7993            public int countAll() throws SystemException {
7994                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7995                                    FINDER_ARGS_EMPTY, this);
7996    
7997                    if (count == null) {
7998                            Session session = null;
7999    
8000                            try {
8001                                    session = openSession();
8002    
8003                                    Query q = session.createQuery(_SQL_COUNT_ASSETCATEGORY);
8004    
8005                                    count = (Long)q.uniqueResult();
8006    
8007                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
8008                                            FINDER_ARGS_EMPTY, count);
8009                            }
8010                            catch (Exception e) {
8011                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
8012                                            FINDER_ARGS_EMPTY);
8013    
8014                                    throw processException(e);
8015                            }
8016                            finally {
8017                                    closeSession(session);
8018                            }
8019                    }
8020    
8021                    return count.intValue();
8022            }
8023    
8024            /**
8025             * Returns all the asset entries associated with the asset category.
8026             *
8027             * @param pk the primary key of the asset category
8028             * @return the asset entries associated with the asset category
8029             * @throws SystemException if a system exception occurred
8030             */
8031            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
8032                    long pk) throws SystemException {
8033                    return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8034            }
8035    
8036            /**
8037             * Returns a range of all the asset entries associated with the asset category.
8038             *
8039             * <p>
8040             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8041             * </p>
8042             *
8043             * @param pk the primary key of the asset category
8044             * @param start the lower bound of the range of asset categories
8045             * @param end the upper bound of the range of asset categories (not inclusive)
8046             * @return the range of asset entries associated with the asset category
8047             * @throws SystemException if a system exception occurred
8048             */
8049            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
8050                    long pk, int start, int end) throws SystemException {
8051                    return getAssetEntries(pk, start, end, null);
8052            }
8053    
8054            public static final FinderPath FINDER_PATH_GET_ASSETENTRIES = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
8055                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
8056                            com.liferay.portlet.asset.model.impl.AssetEntryImpl.class,
8057                            AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
8058                            "getAssetEntries",
8059                            new String[] {
8060                                    Long.class.getName(), Integer.class.getName(),
8061                                    Integer.class.getName(), OrderByComparator.class.getName()
8062                            });
8063    
8064            static {
8065                    FINDER_PATH_GET_ASSETENTRIES.setCacheKeyGeneratorCacheName(null);
8066            }
8067    
8068            /**
8069             * Returns an ordered range of all the asset entries associated with the asset category.
8070             *
8071             * <p>
8072             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8073             * </p>
8074             *
8075             * @param pk the primary key of the asset category
8076             * @param start the lower bound of the range of asset categories
8077             * @param end the upper bound of the range of asset categories (not inclusive)
8078             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8079             * @return the ordered range of asset entries associated with the asset category
8080             * @throws SystemException if a system exception occurred
8081             */
8082            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
8083                    long pk, int start, int end, OrderByComparator orderByComparator)
8084                    throws SystemException {
8085                    boolean pagination = true;
8086                    Object[] finderArgs = null;
8087    
8088                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8089                                    (orderByComparator == null)) {
8090                            pagination = false;
8091                            finderArgs = new Object[] { pk };
8092                    }
8093                    else {
8094                            finderArgs = new Object[] { pk, start, end, orderByComparator };
8095                    }
8096    
8097                    List<com.liferay.portlet.asset.model.AssetEntry> list = (List<com.liferay.portlet.asset.model.AssetEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES,
8098                                    finderArgs, this);
8099    
8100                    if (list == null) {
8101                            Session session = null;
8102    
8103                            try {
8104                                    session = openSession();
8105    
8106                                    String sql = null;
8107    
8108                                    if (orderByComparator != null) {
8109                                            sql = _SQL_GETASSETENTRIES.concat(ORDER_BY_CLAUSE)
8110                                                                                              .concat(orderByComparator.getOrderBy());
8111                                    }
8112                                    else {
8113                                            sql = _SQL_GETASSETENTRIES;
8114    
8115                                            if (pagination) {
8116                                                    sql = sql.concat(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ORDER_BY_SQL);
8117                                            }
8118                                    }
8119    
8120                                    SQLQuery q = session.createSQLQuery(sql);
8121    
8122                                    q.addEntity("AssetEntry",
8123                                            com.liferay.portlet.asset.model.impl.AssetEntryImpl.class);
8124    
8125                                    QueryPos qPos = QueryPos.getInstance(q);
8126    
8127                                    qPos.add(pk);
8128    
8129                                    if (!pagination) {
8130                                            list = (List<com.liferay.portlet.asset.model.AssetEntry>)QueryUtil.list(q,
8131                                                            getDialect(), start, end, false);
8132    
8133                                            Collections.sort(list);
8134    
8135                                            list = new UnmodifiableList<com.liferay.portlet.asset.model.AssetEntry>(list);
8136                                    }
8137                                    else {
8138                                            list = (List<com.liferay.portlet.asset.model.AssetEntry>)QueryUtil.list(q,
8139                                                            getDialect(), start, end);
8140                                    }
8141    
8142                                    assetEntryPersistence.cacheResult(list);
8143    
8144                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES,
8145                                            finderArgs, list);
8146                            }
8147                            catch (Exception e) {
8148                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_ASSETENTRIES,
8149                                            finderArgs);
8150    
8151                                    throw processException(e);
8152                            }
8153                            finally {
8154                                    closeSession(session);
8155                            }
8156                    }
8157    
8158                    return list;
8159            }
8160    
8161            public static final FinderPath FINDER_PATH_GET_ASSETENTRIES_SIZE = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
8162                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
8163                            Long.class,
8164                            AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
8165                            "getAssetEntriesSize", new String[] { Long.class.getName() });
8166    
8167            static {
8168                    FINDER_PATH_GET_ASSETENTRIES_SIZE.setCacheKeyGeneratorCacheName(null);
8169            }
8170    
8171            /**
8172             * Returns the number of asset entries associated with the asset category.
8173             *
8174             * @param pk the primary key of the asset category
8175             * @return the number of asset entries associated with the asset category
8176             * @throws SystemException if a system exception occurred
8177             */
8178            public int getAssetEntriesSize(long pk) throws SystemException {
8179                    Object[] finderArgs = new Object[] { pk };
8180    
8181                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
8182                                    finderArgs, this);
8183    
8184                    if (count == null) {
8185                            Session session = null;
8186    
8187                            try {
8188                                    session = openSession();
8189    
8190                                    SQLQuery q = session.createSQLQuery(_SQL_GETASSETENTRIESSIZE);
8191    
8192                                    q.addScalar(COUNT_COLUMN_NAME,
8193                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
8194    
8195                                    QueryPos qPos = QueryPos.getInstance(q);
8196    
8197                                    qPos.add(pk);
8198    
8199                                    count = (Long)q.uniqueResult();
8200    
8201                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
8202                                            finderArgs, count);
8203                            }
8204                            catch (Exception e) {
8205                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
8206                                            finderArgs);
8207    
8208                                    throw processException(e);
8209                            }
8210                            finally {
8211                                    closeSession(session);
8212                            }
8213                    }
8214    
8215                    return count.intValue();
8216            }
8217    
8218            public static final FinderPath FINDER_PATH_CONTAINS_ASSETENTRY = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
8219                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
8220                            Boolean.class,
8221                            AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
8222                            "containsAssetEntry",
8223                            new String[] { Long.class.getName(), Long.class.getName() });
8224    
8225            /**
8226             * Returns <code>true</code> if the asset entry is associated with the asset category.
8227             *
8228             * @param pk the primary key of the asset category
8229             * @param assetEntryPK the primary key of the asset entry
8230             * @return <code>true</code> if the asset entry is associated with the asset category; <code>false</code> otherwise
8231             * @throws SystemException if a system exception occurred
8232             */
8233            public boolean containsAssetEntry(long pk, long assetEntryPK)
8234                    throws SystemException {
8235                    Object[] finderArgs = new Object[] { pk, assetEntryPK };
8236    
8237                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ASSETENTRY,
8238                                    finderArgs, this);
8239    
8240                    if (value == null) {
8241                            try {
8242                                    value = Boolean.valueOf(containsAssetEntry.contains(pk,
8243                                                            assetEntryPK));
8244    
8245                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ASSETENTRY,
8246                                            finderArgs, value);
8247                            }
8248                            catch (Exception e) {
8249                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_ASSETENTRY,
8250                                            finderArgs);
8251    
8252                                    throw processException(e);
8253                            }
8254                    }
8255    
8256                    return value.booleanValue();
8257            }
8258    
8259            /**
8260             * Returns <code>true</code> if the asset category has any asset entries associated with it.
8261             *
8262             * @param pk the primary key of the asset category to check for associations with asset entries
8263             * @return <code>true</code> if the asset category has any asset entries associated with it; <code>false</code> otherwise
8264             * @throws SystemException if a system exception occurred
8265             */
8266            public boolean containsAssetEntries(long pk) throws SystemException {
8267                    if (getAssetEntriesSize(pk) > 0) {
8268                            return true;
8269                    }
8270                    else {
8271                            return false;
8272                    }
8273            }
8274    
8275            /**
8276             * Adds an association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8277             *
8278             * @param pk the primary key of the asset category
8279             * @param assetEntryPK the primary key of the asset entry
8280             * @throws SystemException if a system exception occurred
8281             */
8282            public void addAssetEntry(long pk, long assetEntryPK)
8283                    throws SystemException {
8284                    try {
8285                            addAssetEntry.add(pk, assetEntryPK);
8286                    }
8287                    catch (Exception e) {
8288                            throw processException(e);
8289                    }
8290                    finally {
8291                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8292                    }
8293            }
8294    
8295            /**
8296             * Adds an association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8297             *
8298             * @param pk the primary key of the asset category
8299             * @param assetEntry the asset entry
8300             * @throws SystemException if a system exception occurred
8301             */
8302            public void addAssetEntry(long pk,
8303                    com.liferay.portlet.asset.model.AssetEntry assetEntry)
8304                    throws SystemException {
8305                    try {
8306                            addAssetEntry.add(pk, assetEntry.getPrimaryKey());
8307                    }
8308                    catch (Exception e) {
8309                            throw processException(e);
8310                    }
8311                    finally {
8312                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8313                    }
8314            }
8315    
8316            /**
8317             * Adds an association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8318             *
8319             * @param pk the primary key of the asset category
8320             * @param assetEntryPKs the primary keys of the asset entries
8321             * @throws SystemException if a system exception occurred
8322             */
8323            public void addAssetEntries(long pk, long[] assetEntryPKs)
8324                    throws SystemException {
8325                    try {
8326                            for (long assetEntryPK : assetEntryPKs) {
8327                                    addAssetEntry.add(pk, assetEntryPK);
8328                            }
8329                    }
8330                    catch (Exception e) {
8331                            throw processException(e);
8332                    }
8333                    finally {
8334                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8335                    }
8336            }
8337    
8338            /**
8339             * Adds an association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8340             *
8341             * @param pk the primary key of the asset category
8342             * @param assetEntries the asset entries
8343             * @throws SystemException if a system exception occurred
8344             */
8345            public void addAssetEntries(long pk,
8346                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
8347                    throws SystemException {
8348                    try {
8349                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
8350                                    addAssetEntry.add(pk, assetEntry.getPrimaryKey());
8351                            }
8352                    }
8353                    catch (Exception e) {
8354                            throw processException(e);
8355                    }
8356                    finally {
8357                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8358                    }
8359            }
8360    
8361            /**
8362             * Clears all associations between the asset category and its asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8363             *
8364             * @param pk the primary key of the asset category to clear the associated asset entries from
8365             * @throws SystemException if a system exception occurred
8366             */
8367            public void clearAssetEntries(long pk) throws SystemException {
8368                    try {
8369                            clearAssetEntries.clear(pk);
8370                    }
8371                    catch (Exception e) {
8372                            throw processException(e);
8373                    }
8374                    finally {
8375                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8376                    }
8377            }
8378    
8379            /**
8380             * Removes the association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8381             *
8382             * @param pk the primary key of the asset category
8383             * @param assetEntryPK the primary key of the asset entry
8384             * @throws SystemException if a system exception occurred
8385             */
8386            public void removeAssetEntry(long pk, long assetEntryPK)
8387                    throws SystemException {
8388                    try {
8389                            removeAssetEntry.remove(pk, assetEntryPK);
8390                    }
8391                    catch (Exception e) {
8392                            throw processException(e);
8393                    }
8394                    finally {
8395                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8396                    }
8397            }
8398    
8399            /**
8400             * Removes the association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8401             *
8402             * @param pk the primary key of the asset category
8403             * @param assetEntry the asset entry
8404             * @throws SystemException if a system exception occurred
8405             */
8406            public void removeAssetEntry(long pk,
8407                    com.liferay.portlet.asset.model.AssetEntry assetEntry)
8408                    throws SystemException {
8409                    try {
8410                            removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
8411                    }
8412                    catch (Exception e) {
8413                            throw processException(e);
8414                    }
8415                    finally {
8416                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8417                    }
8418            }
8419    
8420            /**
8421             * Removes the association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8422             *
8423             * @param pk the primary key of the asset category
8424             * @param assetEntryPKs the primary keys of the asset entries
8425             * @throws SystemException if a system exception occurred
8426             */
8427            public void removeAssetEntries(long pk, long[] assetEntryPKs)
8428                    throws SystemException {
8429                    try {
8430                            for (long assetEntryPK : assetEntryPKs) {
8431                                    removeAssetEntry.remove(pk, assetEntryPK);
8432                            }
8433                    }
8434                    catch (Exception e) {
8435                            throw processException(e);
8436                    }
8437                    finally {
8438                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8439                    }
8440            }
8441    
8442            /**
8443             * Removes the association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8444             *
8445             * @param pk the primary key of the asset category
8446             * @param assetEntries the asset entries
8447             * @throws SystemException if a system exception occurred
8448             */
8449            public void removeAssetEntries(long pk,
8450                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
8451                    throws SystemException {
8452                    try {
8453                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
8454                                    removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
8455                            }
8456                    }
8457                    catch (Exception e) {
8458                            throw processException(e);
8459                    }
8460                    finally {
8461                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8462                    }
8463            }
8464    
8465            /**
8466             * 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.
8467             *
8468             * @param pk the primary key of the asset category
8469             * @param assetEntryPKs the primary keys of the asset entries to be associated with the asset category
8470             * @throws SystemException if a system exception occurred
8471             */
8472            public void setAssetEntries(long pk, long[] assetEntryPKs)
8473                    throws SystemException {
8474                    try {
8475                            Set<Long> assetEntryPKSet = SetUtil.fromArray(assetEntryPKs);
8476    
8477                            List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = getAssetEntries(pk);
8478    
8479                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
8480                                    if (!assetEntryPKSet.remove(assetEntry.getPrimaryKey())) {
8481                                            removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
8482                                    }
8483                            }
8484    
8485                            for (Long assetEntryPK : assetEntryPKSet) {
8486                                    addAssetEntry.add(pk, assetEntryPK);
8487                            }
8488                    }
8489                    catch (Exception e) {
8490                            throw processException(e);
8491                    }
8492                    finally {
8493                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8494                    }
8495            }
8496    
8497            /**
8498             * 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.
8499             *
8500             * @param pk the primary key of the asset category
8501             * @param assetEntries the asset entries to be associated with the asset category
8502             * @throws SystemException if a system exception occurred
8503             */
8504            public void setAssetEntries(long pk,
8505                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
8506                    throws SystemException {
8507                    try {
8508                            long[] assetEntryPKs = new long[assetEntries.size()];
8509    
8510                            for (int i = 0; i < assetEntries.size(); i++) {
8511                                    com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
8512    
8513                                    assetEntryPKs[i] = assetEntry.getPrimaryKey();
8514                            }
8515    
8516                            setAssetEntries(pk, assetEntryPKs);
8517                    }
8518                    catch (Exception e) {
8519                            throw processException(e);
8520                    }
8521                    finally {
8522                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
8523                    }
8524            }
8525    
8526            /**
8527             * Rebuilds the asset categories tree for the scope using the modified pre-order tree traversal algorithm.
8528             *
8529             * <p>
8530             * 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.
8531             * </p>
8532             *
8533             * @param groupId the ID of the scope
8534             * @param force whether to force the rebuild even if the tree is not stale
8535             */
8536            public void rebuildTree(long groupId, boolean force)
8537                    throws SystemException {
8538                    if (!rebuildTreeEnabled) {
8539                            return;
8540                    }
8541    
8542                    if (force || (countOrphanTreeNodes(groupId) > 0)) {
8543                            rebuildTree(groupId, 0, 1);
8544    
8545                            CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
8546                            EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
8547                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
8548                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8549                    }
8550            }
8551    
8552            public void setRebuildTreeEnabled(boolean rebuildTreeEnabled) {
8553                    this.rebuildTreeEnabled = rebuildTreeEnabled;
8554            }
8555    
8556            protected long countOrphanTreeNodes(long groupId) throws SystemException {
8557                    Session session = null;
8558    
8559                    try {
8560                            session = openSession();
8561    
8562                            SQLQuery q = session.createSQLQuery(
8563                                            "SELECT COUNT(*) AS COUNT_VALUE FROM AssetCategory WHERE groupId = ? AND (leftCategoryId = 0 OR leftCategoryId IS NULL OR rightCategoryId = 0 OR rightCategoryId IS NULL)");
8564    
8565                            q.addScalar(COUNT_COLUMN_NAME,
8566                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8567    
8568                            QueryPos qPos = QueryPos.getInstance(q);
8569    
8570                            qPos.add(groupId);
8571    
8572                            return (Long)q.uniqueResult();
8573                    }
8574                    catch (Exception e) {
8575                            throw processException(e);
8576                    }
8577                    finally {
8578                            closeSession(session);
8579                    }
8580            }
8581    
8582            protected void expandNoChildrenLeftCategoryId(long groupId,
8583                    long leftCategoryId, List<Long> childrenCategoryIds, long delta) {
8584                    String sql = "UPDATE AssetCategory SET leftcategoryId = (leftcategoryId + ?) WHERE (groupId = ?) AND (leftcategoryId > ?) AND (categoryId NOT IN (" +
8585                            StringUtil.merge(childrenCategoryIds) + "))";
8586    
8587                    SqlUpdate _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
8588                                    sql,
8589                                    new int[] {
8590                                            java.sql.Types.BIGINT, java.sql.Types.BIGINT,
8591                                            java.sql.Types.BIGINT
8592                                    });
8593    
8594                    _sqlUpdate.update(new Object[] { delta, groupId, leftCategoryId });
8595            }
8596    
8597            protected void expandNoChildrenRightCategoryId(long groupId,
8598                    long rightCategoryId, List<Long> childrenCategoryIds, long delta) {
8599                    String sql = "UPDATE AssetCategory SET rightcategoryId = (rightcategoryId + ?) WHERE (groupId = ?) AND (rightcategoryId > ?) AND (categoryId NOT IN (" +
8600                            StringUtil.merge(childrenCategoryIds) + "))";
8601    
8602                    SqlUpdate _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
8603                                    sql,
8604                                    new int[] {
8605                                            java.sql.Types.BIGINT, java.sql.Types.BIGINT,
8606                                            java.sql.Types.BIGINT
8607                                    });
8608    
8609                    _sqlUpdate.update(new Object[] { delta, groupId, rightCategoryId });
8610            }
8611    
8612            protected void expandTree(AssetCategory assetCategory,
8613                    List<Long> childrenCategoryIds) throws SystemException {
8614                    if (!rebuildTreeEnabled) {
8615                            return;
8616                    }
8617    
8618                    long groupId = assetCategory.getGroupId();
8619    
8620                    long lastRightCategoryId = getLastRightCategoryId(groupId,
8621                                    assetCategory.getParentCategoryId());
8622    
8623                    long leftCategoryId = 2;
8624                    long rightCategoryId = 3;
8625    
8626                    if (lastRightCategoryId > 0) {
8627                            leftCategoryId = lastRightCategoryId + 1;
8628    
8629                            long childrenDistance = assetCategory.getRightCategoryId() -
8630                                    assetCategory.getLeftCategoryId();
8631    
8632                            if (childrenDistance > 1) {
8633                                    rightCategoryId = leftCategoryId + childrenDistance;
8634    
8635                                    updateChildrenTree(groupId, childrenCategoryIds,
8636                                            leftCategoryId - assetCategory.getLeftCategoryId());
8637    
8638                                    expandNoChildrenLeftCategoryId(groupId, lastRightCategoryId,
8639                                            childrenCategoryIds, childrenDistance + 1);
8640                                    expandNoChildrenRightCategoryId(groupId, lastRightCategoryId,
8641                                            childrenCategoryIds, childrenDistance + 1);
8642                            }
8643                            else {
8644                                    rightCategoryId = lastRightCategoryId + 2;
8645    
8646                                    expandTreeLeftCategoryId.expand(groupId, lastRightCategoryId);
8647                                    expandTreeRightCategoryId.expand(groupId, lastRightCategoryId);
8648                            }
8649    
8650                            CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
8651                            EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
8652                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
8653                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8654                    }
8655    
8656                    assetCategory.setLeftCategoryId(leftCategoryId);
8657                    assetCategory.setRightCategoryId(rightCategoryId);
8658            }
8659    
8660            protected List<Long> getChildrenTreeCategoryIds(
8661                    AssetCategory parentAssetCategory) throws SystemException {
8662                    Session session = null;
8663    
8664                    try {
8665                            session = openSession();
8666    
8667                            SQLQuery q = session.createSQLQuery(
8668                                            "SELECT categoryId FROM AssetCategory WHERE (groupId = ?) AND (leftcategoryId BETWEEN ? AND ?)");
8669    
8670                            q.addScalar("CategoryId",
8671                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8672    
8673                            QueryPos qPos = QueryPos.getInstance(q);
8674    
8675                            qPos.add(parentAssetCategory.getGroupId());
8676                            qPos.add(parentAssetCategory.getLeftCategoryId() + 1);
8677                            qPos.add(parentAssetCategory.getRightCategoryId());
8678    
8679                            return q.list();
8680                    }
8681                    catch (Exception e) {
8682                            throw processException(e);
8683                    }
8684                    finally {
8685                            closeSession(session);
8686                    }
8687            }
8688    
8689            protected long getLastRightCategoryId(long groupId, long parentCategoryId)
8690                    throws SystemException {
8691                    Session session = null;
8692    
8693                    try {
8694                            session = openSession();
8695    
8696                            SQLQuery q = session.createSQLQuery(
8697                                            "SELECT rightCategoryId FROM AssetCategory WHERE (groupId = ?) AND (parentCategoryId = ?) ORDER BY rightCategoryId DESC");
8698    
8699                            q.addScalar("rightCategoryId",
8700                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8701    
8702                            QueryPos qPos = QueryPos.getInstance(q);
8703    
8704                            qPos.add(groupId);
8705                            qPos.add(parentCategoryId);
8706    
8707                            List<Long> list = (List<Long>)QueryUtil.list(q, getDialect(), 0, 1);
8708    
8709                            if (list.isEmpty()) {
8710                                    if (parentCategoryId > 0) {
8711                                            session.clear();
8712    
8713                                            AssetCategory parentAssetCategory = findByPrimaryKey(parentCategoryId);
8714    
8715                                            return parentAssetCategory.getLeftCategoryId();
8716                                    }
8717    
8718                                    return 0;
8719                            }
8720                            else {
8721                                    return list.get(0);
8722                            }
8723                    }
8724                    catch (Exception e) {
8725                            throw processException(e);
8726                    }
8727                    finally {
8728                            closeSession(session);
8729                    }
8730            }
8731    
8732            protected long rebuildTree(long groupId, long parentCategoryId,
8733                    long leftCategoryId) throws SystemException {
8734                    if (!rebuildTreeEnabled) {
8735                            return 0;
8736                    }
8737    
8738                    List<Long> categoryIds = null;
8739    
8740                    Session session = null;
8741    
8742                    try {
8743                            session = openSession();
8744    
8745                            SQLQuery q = session.createSQLQuery(
8746                                            "SELECT categoryId FROM AssetCategory WHERE groupId = ? AND parentCategoryId = ? ORDER BY categoryId ASC");
8747    
8748                            q.addScalar("categoryId",
8749                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8750    
8751                            QueryPos qPos = QueryPos.getInstance(q);
8752    
8753                            qPos.add(groupId);
8754                            qPos.add(parentCategoryId);
8755    
8756                            categoryIds = q.list();
8757                    }
8758                    catch (Exception e) {
8759                            throw processException(e);
8760                    }
8761                    finally {
8762                            closeSession(session);
8763                    }
8764    
8765                    long rightCategoryId = leftCategoryId + 1;
8766    
8767                    for (long categoryId : categoryIds) {
8768                            rightCategoryId = rebuildTree(groupId, categoryId, rightCategoryId);
8769                    }
8770    
8771                    if (parentCategoryId > 0) {
8772                            updateTree.update(parentCategoryId, leftCategoryId, rightCategoryId);
8773                    }
8774    
8775                    return rightCategoryId + 1;
8776            }
8777    
8778            protected void shrinkTree(AssetCategory assetCategory) {
8779                    if (!rebuildTreeEnabled) {
8780                            return;
8781                    }
8782    
8783                    long groupId = assetCategory.getGroupId();
8784    
8785                    long leftCategoryId = assetCategory.getLeftCategoryId();
8786                    long rightCategoryId = assetCategory.getRightCategoryId();
8787    
8788                    long delta = (rightCategoryId - leftCategoryId) + 1;
8789    
8790                    shrinkTreeLeftCategoryId.shrink(groupId, rightCategoryId, delta);
8791                    shrinkTreeRightCategoryId.shrink(groupId, rightCategoryId, delta);
8792    
8793                    CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
8794                    EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
8795                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
8796                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8797            }
8798    
8799            protected void updateChildrenTree(long groupId,
8800                    List<Long> childrenCategoryIds, long delta) {
8801                    String sql = "UPDATE AssetCategory SET leftcategoryId = (leftcategoryId + ?), rightcategoryId = (rightcategoryId + ?) WHERE (groupId = ?) AND (categoryId IN (" +
8802                            StringUtil.merge(childrenCategoryIds) + "))";
8803    
8804                    SqlUpdate _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
8805                                    sql,
8806                                    new int[] {
8807                                            java.sql.Types.BIGINT, java.sql.Types.BIGINT,
8808                                            java.sql.Types.BIGINT
8809                                    });
8810    
8811                    _sqlUpdate.update(new Object[] { delta, delta, groupId });
8812            }
8813    
8814            /**
8815             * Initializes the asset category persistence.
8816             */
8817            public void afterPropertiesSet() {
8818                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
8819                                            com.liferay.portal.util.PropsUtil.get(
8820                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetCategory")));
8821    
8822                    if (listenerClassNames.length > 0) {
8823                            try {
8824                                    List<ModelListener<AssetCategory>> listenersList = new ArrayList<ModelListener<AssetCategory>>();
8825    
8826                                    for (String listenerClassName : listenerClassNames) {
8827                                            listenersList.add((ModelListener<AssetCategory>)InstanceFactory.newInstance(
8828                                                            listenerClassName));
8829                                    }
8830    
8831                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
8832                            }
8833                            catch (Exception e) {
8834                                    _log.error(e);
8835                            }
8836                    }
8837    
8838                    containsAssetEntry = new ContainsAssetEntry();
8839    
8840                    addAssetEntry = new AddAssetEntry();
8841                    clearAssetEntries = new ClearAssetEntries();
8842                    removeAssetEntry = new RemoveAssetEntry();
8843    
8844                    expandTreeLeftCategoryId = new ExpandTreeLeftCategoryId();
8845                    expandTreeRightCategoryId = new ExpandTreeRightCategoryId();
8846                    shrinkTreeLeftCategoryId = new ShrinkTreeLeftCategoryId();
8847                    shrinkTreeRightCategoryId = new ShrinkTreeRightCategoryId();
8848                    updateTree = new UpdateTree();
8849            }
8850    
8851            public void destroy() {
8852                    EntityCacheUtil.removeCache(AssetCategoryImpl.class.getName());
8853                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
8854                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8855                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8856            }
8857    
8858            @BeanReference(type = AssetEntryPersistence.class)
8859            protected AssetEntryPersistence assetEntryPersistence;
8860            protected ContainsAssetEntry containsAssetEntry;
8861            protected AddAssetEntry addAssetEntry;
8862            protected ClearAssetEntries clearAssetEntries;
8863            protected RemoveAssetEntry removeAssetEntry;
8864    
8865            protected class ContainsAssetEntry {
8866                    protected ContainsAssetEntry() {
8867                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
8868                                            _SQL_CONTAINSASSETENTRY,
8869                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
8870                                            RowMapper.COUNT);
8871                    }
8872    
8873                    protected boolean contains(long categoryId, long entryId) {
8874                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
8875                                                    new Long(categoryId), new Long(entryId)
8876                                            });
8877    
8878                            if (results.size() > 0) {
8879                                    Integer count = results.get(0);
8880    
8881                                    if (count.intValue() > 0) {
8882                                            return true;
8883                                    }
8884                            }
8885    
8886                            return false;
8887                    }
8888    
8889                    private MappingSqlQuery<Integer> _mappingSqlQuery;
8890            }
8891    
8892            protected class AddAssetEntry {
8893                    protected AddAssetEntry() {
8894                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
8895                                            "INSERT INTO AssetEntries_AssetCategories (categoryId, entryId) VALUES (?, ?)",
8896                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
8897                    }
8898    
8899                    protected void add(long categoryId, long entryId)
8900                            throws SystemException {
8901                            if (!containsAssetEntry.contains(categoryId, entryId)) {
8902                                    ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
8903                                            assetEntryPersistence.getListeners();
8904    
8905                                    for (ModelListener<AssetCategory> listener : listeners) {
8906                                            listener.onBeforeAddAssociation(categoryId,
8907                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
8908                                                    entryId);
8909                                    }
8910    
8911                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
8912                                            listener.onBeforeAddAssociation(entryId,
8913                                                    AssetCategory.class.getName(), categoryId);
8914                                    }
8915    
8916                                    _sqlUpdate.update(new Object[] {
8917                                                    new Long(categoryId), new Long(entryId)
8918                                            });
8919    
8920                                    for (ModelListener<AssetCategory> listener : listeners) {
8921                                            listener.onAfterAddAssociation(categoryId,
8922                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
8923                                                    entryId);
8924                                    }
8925    
8926                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
8927                                            listener.onAfterAddAssociation(entryId,
8928                                                    AssetCategory.class.getName(), categoryId);
8929                                    }
8930                            }
8931                    }
8932    
8933                    private SqlUpdate _sqlUpdate;
8934            }
8935    
8936            protected class ClearAssetEntries {
8937                    protected ClearAssetEntries() {
8938                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
8939                                            "DELETE FROM AssetEntries_AssetCategories WHERE categoryId = ?",
8940                                            new int[] { java.sql.Types.BIGINT });
8941                    }
8942    
8943                    protected void clear(long categoryId) throws SystemException {
8944                            ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
8945                                    assetEntryPersistence.getListeners();
8946    
8947                            List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = null;
8948    
8949                            if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
8950                                    assetEntries = getAssetEntries(categoryId);
8951    
8952                                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
8953                                            for (ModelListener<AssetCategory> listener : listeners) {
8954                                                    listener.onBeforeRemoveAssociation(categoryId,
8955                                                            com.liferay.portlet.asset.model.AssetEntry.class.getName(),
8956                                                            assetEntry.getPrimaryKey());
8957                                            }
8958    
8959                                            for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
8960                                                    listener.onBeforeRemoveAssociation(assetEntry.getPrimaryKey(),
8961                                                            AssetCategory.class.getName(), categoryId);
8962                                            }
8963                                    }
8964                            }
8965    
8966                            _sqlUpdate.update(new Object[] { new Long(categoryId) });
8967    
8968                            if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
8969                                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
8970                                            for (ModelListener<AssetCategory> listener : listeners) {
8971                                                    listener.onAfterRemoveAssociation(categoryId,
8972                                                            com.liferay.portlet.asset.model.AssetEntry.class.getName(),
8973                                                            assetEntry.getPrimaryKey());
8974                                            }
8975    
8976                                            for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
8977                                                    listener.onAfterRemoveAssociation(assetEntry.getPrimaryKey(),
8978                                                            AssetCategory.class.getName(), categoryId);
8979                                            }
8980                                    }
8981                            }
8982                    }
8983    
8984                    private SqlUpdate _sqlUpdate;
8985            }
8986    
8987            protected class RemoveAssetEntry {
8988                    protected RemoveAssetEntry() {
8989                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
8990                                            "DELETE FROM AssetEntries_AssetCategories WHERE categoryId = ? AND entryId = ?",
8991                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
8992                    }
8993    
8994                    protected void remove(long categoryId, long entryId)
8995                            throws SystemException {
8996                            if (containsAssetEntry.contains(categoryId, entryId)) {
8997                                    ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
8998                                            assetEntryPersistence.getListeners();
8999    
9000                                    for (ModelListener<AssetCategory> listener : listeners) {
9001                                            listener.onBeforeRemoveAssociation(categoryId,
9002                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
9003                                                    entryId);
9004                                    }
9005    
9006                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
9007                                            listener.onBeforeRemoveAssociation(entryId,
9008                                                    AssetCategory.class.getName(), categoryId);
9009                                    }
9010    
9011                                    _sqlUpdate.update(new Object[] {
9012                                                    new Long(categoryId), new Long(entryId)
9013                                            });
9014    
9015                                    for (ModelListener<AssetCategory> listener : listeners) {
9016                                            listener.onAfterRemoveAssociation(categoryId,
9017                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
9018                                                    entryId);
9019                                    }
9020    
9021                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
9022                                            listener.onAfterRemoveAssociation(entryId,
9023                                                    AssetCategory.class.getName(), categoryId);
9024                                    }
9025                            }
9026                    }
9027    
9028                    private SqlUpdate _sqlUpdate;
9029            }
9030    
9031            protected boolean rebuildTreeEnabled = true;
9032            protected ExpandTreeLeftCategoryId expandTreeLeftCategoryId;
9033            protected ExpandTreeRightCategoryId expandTreeRightCategoryId;
9034            protected ShrinkTreeLeftCategoryId shrinkTreeLeftCategoryId;
9035            protected ShrinkTreeRightCategoryId shrinkTreeRightCategoryId;
9036            protected UpdateTree updateTree;
9037    
9038            protected class ExpandTreeLeftCategoryId {
9039                    protected ExpandTreeLeftCategoryId() {
9040                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9041                                            "UPDATE AssetCategory SET leftCategoryId = (leftCategoryId + 2) WHERE (groupId = ?) AND (leftCategoryId > ?)",
9042                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9043                    }
9044    
9045                    protected void expand(long groupId, long leftCategoryId) {
9046                            _sqlUpdate.update(new Object[] { groupId, leftCategoryId });
9047                    }
9048    
9049                    private SqlUpdate _sqlUpdate;
9050            }
9051    
9052            protected class ExpandTreeRightCategoryId {
9053                    protected ExpandTreeRightCategoryId() {
9054                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9055                                            "UPDATE AssetCategory SET rightCategoryId = (rightCategoryId + 2) WHERE (groupId = ?) AND (rightCategoryId > ?)",
9056                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9057                    }
9058    
9059                    protected void expand(long groupId, long rightCategoryId) {
9060                            _sqlUpdate.update(new Object[] { groupId, rightCategoryId });
9061                    }
9062    
9063                    private SqlUpdate _sqlUpdate;
9064            }
9065    
9066            protected class ShrinkTreeLeftCategoryId {
9067                    protected ShrinkTreeLeftCategoryId() {
9068                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9069                                            "UPDATE AssetCategory SET leftCategoryId = (leftCategoryId - ?) WHERE (groupId = ?) AND (leftCategoryId > ?)",
9070                                            new int[] {
9071                                                    java.sql.Types.BIGINT, java.sql.Types.BIGINT,
9072                                                    java.sql.Types.BIGINT
9073                                            });
9074                    }
9075    
9076                    protected void shrink(long groupId, long rightCategoryId, long delta) {
9077                            _sqlUpdate.update(new Object[] { delta, groupId, rightCategoryId });
9078                    }
9079    
9080                    private SqlUpdate _sqlUpdate;
9081            }
9082    
9083            protected class ShrinkTreeRightCategoryId {
9084                    protected ShrinkTreeRightCategoryId() {
9085                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9086                                            "UPDATE AssetCategory SET rightCategoryId = (rightCategoryId - ?) WHERE (groupId = ?) AND (rightCategoryId > ?)",
9087                                            new int[] {
9088                                                    java.sql.Types.BIGINT, java.sql.Types.BIGINT,
9089                                                    java.sql.Types.BIGINT
9090                                            });
9091                    }
9092    
9093                    protected void shrink(long groupId, long rightCategoryId, long delta) {
9094                            _sqlUpdate.update(new Object[] { delta, groupId, rightCategoryId });
9095                    }
9096    
9097                    private SqlUpdate _sqlUpdate;
9098            }
9099    
9100            protected class UpdateTree {
9101                    protected UpdateTree() {
9102                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9103                                            "UPDATE AssetCategory SET leftCategoryId = ?, rightCategoryId = ? WHERE categoryId = ?",
9104                                            new int[] {
9105                                                    java.sql.Types.BIGINT, java.sql.Types.BIGINT,
9106                                                    java.sql.Types.BIGINT
9107                                            });
9108                    }
9109    
9110                    protected void update(long categoryId, long leftCategoryId,
9111                            long rightCategoryId) {
9112                            _sqlUpdate.update(new Object[] {
9113                                            leftCategoryId, rightCategoryId, categoryId
9114                                    });
9115                    }
9116    
9117                    private SqlUpdate _sqlUpdate;
9118            }
9119    
9120            private static final String _SQL_SELECT_ASSETCATEGORY = "SELECT assetCategory FROM AssetCategory assetCategory";
9121            private static final String _SQL_SELECT_ASSETCATEGORY_WHERE = "SELECT assetCategory FROM AssetCategory assetCategory WHERE ";
9122            private static final String _SQL_COUNT_ASSETCATEGORY = "SELECT COUNT(assetCategory) FROM AssetCategory assetCategory";
9123            private static final String _SQL_COUNT_ASSETCATEGORY_WHERE = "SELECT COUNT(assetCategory) FROM AssetCategory assetCategory WHERE ";
9124            private static final String _SQL_GETASSETENTRIES = "SELECT {AssetEntry.*} FROM AssetEntry INNER JOIN AssetEntries_AssetCategories ON (AssetEntries_AssetCategories.entryId = AssetEntry.entryId) WHERE (AssetEntries_AssetCategories.categoryId = ?)";
9125            private static final String _SQL_GETASSETENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetCategories WHERE categoryId = ?";
9126            private static final String _SQL_CONTAINSASSETENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetCategories WHERE categoryId = ? AND entryId = ?";
9127            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "assetCategory.categoryId";
9128            private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_WHERE = "SELECT DISTINCT {assetCategory.*} FROM AssetCategory assetCategory WHERE ";
9129            private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
9130                    "SELECT {AssetCategory.*} FROM (SELECT DISTINCT assetCategory.categoryId FROM AssetCategory assetCategory WHERE ";
9131            private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
9132                    ") TEMP_TABLE INNER JOIN AssetCategory ON TEMP_TABLE.categoryId = AssetCategory.categoryId";
9133            private static final String _FILTER_SQL_COUNT_ASSETCATEGORY_WHERE = "SELECT COUNT(DISTINCT assetCategory.categoryId) AS COUNT_VALUE FROM AssetCategory assetCategory WHERE ";
9134            private static final String _FILTER_ENTITY_ALIAS = "assetCategory";
9135            private static final String _FILTER_ENTITY_TABLE = "AssetCategory";
9136            private static final String _ORDER_BY_ENTITY_ALIAS = "assetCategory.";
9137            private static final String _ORDER_BY_ENTITY_TABLE = "AssetCategory.";
9138            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetCategory exists with the primary key ";
9139            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetCategory exists with the key {";
9140            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9141            private static Log _log = LogFactoryUtil.getLog(AssetCategoryPersistenceImpl.class);
9142            private static AssetCategory _nullAssetCategory = new AssetCategoryImpl() {
9143                            @Override
9144                            public Object clone() {
9145                                    return this;
9146                            }
9147    
9148                            @Override
9149                            public CacheModel<AssetCategory> toCacheModel() {
9150                                    return _nullAssetCategoryCacheModel;
9151                            }
9152                    };
9153    
9154            private static CacheModel<AssetCategory> _nullAssetCategoryCacheModel = new CacheModel<AssetCategory>() {
9155                            public AssetCategory toEntityModel() {
9156                                    return _nullAssetCategory;
9157                            }
9158                    };
9159    }