001    /**
002     * Copyright (c) 2000-2010 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.annotation.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.Validator;
044    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
047    import com.liferay.portal.service.persistence.BatchSessionUtil;
048    import com.liferay.portal.service.persistence.ResourcePersistence;
049    import com.liferay.portal.service.persistence.UserPersistence;
050    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
051    
052    import com.liferay.portlet.asset.NoSuchCategoryException;
053    import com.liferay.portlet.asset.model.AssetCategory;
054    import com.liferay.portlet.asset.model.impl.AssetCategoryImpl;
055    import com.liferay.portlet.asset.model.impl.AssetCategoryModelImpl;
056    
057    import java.io.Serializable;
058    
059    import java.util.ArrayList;
060    import java.util.Collections;
061    import java.util.List;
062    import java.util.Set;
063    
064    /**
065     * The persistence implementation for the asset category service.
066     *
067     * <p>
068     * 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.
069     * </p>
070     *
071     * <p>
072     * Caching information and settings can be found in <code>portal.properties</code>
073     * </p>
074     *
075     * @author Brian Wing Shun Chan
076     * @see AssetCategoryPersistence
077     * @see AssetCategoryUtil
078     * @generated
079     */
080    public class AssetCategoryPersistenceImpl extends BasePersistenceImpl<AssetCategory>
081            implements AssetCategoryPersistence {
082            public static final String FINDER_CLASS_NAME_ENTITY = AssetCategoryImpl.class.getName();
083            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
084                    ".List";
085            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
086                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
087                            FINDER_CLASS_NAME_LIST, "findByUuid",
088                            new String[] {
089                                    String.class.getName(),
090                                    
091                            "java.lang.Integer", "java.lang.Integer",
092                                    "com.liferay.portal.kernel.util.OrderByComparator"
093                            });
094            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
095                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
096                            FINDER_CLASS_NAME_LIST, "countByUuid",
097                            new String[] { String.class.getName() });
098            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
099                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
100                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
101                            new String[] { String.class.getName(), Long.class.getName() });
102            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
103                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
104                            FINDER_CLASS_NAME_LIST, "countByUUID_G",
105                            new String[] { String.class.getName(), Long.class.getName() });
106            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
107                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
108                            FINDER_CLASS_NAME_LIST, "findByGroupId",
109                            new String[] {
110                                    Long.class.getName(),
111                                    
112                            "java.lang.Integer", "java.lang.Integer",
113                                    "com.liferay.portal.kernel.util.OrderByComparator"
114                            });
115            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
116                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
117                            FINDER_CLASS_NAME_LIST, "countByGroupId",
118                            new String[] { Long.class.getName() });
119            public static final FinderPath FINDER_PATH_FIND_BY_PARENTCATEGORYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
120                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
121                            FINDER_CLASS_NAME_LIST, "findByParentCategoryId",
122                            new String[] {
123                                    Long.class.getName(),
124                                    
125                            "java.lang.Integer", "java.lang.Integer",
126                                    "com.liferay.portal.kernel.util.OrderByComparator"
127                            });
128            public static final FinderPath FINDER_PATH_COUNT_BY_PARENTCATEGORYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
129                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
130                            FINDER_CLASS_NAME_LIST, "countByParentCategoryId",
131                            new String[] { Long.class.getName() });
132            public static final FinderPath FINDER_PATH_FIND_BY_VOCABULARYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
133                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
134                            FINDER_CLASS_NAME_LIST, "findByVocabularyId",
135                            new String[] {
136                                    Long.class.getName(),
137                                    
138                            "java.lang.Integer", "java.lang.Integer",
139                                    "com.liferay.portal.kernel.util.OrderByComparator"
140                            });
141            public static final FinderPath FINDER_PATH_COUNT_BY_VOCABULARYID = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
142                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
143                            FINDER_CLASS_NAME_LIST, "countByVocabularyId",
144                            new String[] { Long.class.getName() });
145            public static final FinderPath FINDER_PATH_FIND_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
146                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
147                            FINDER_CLASS_NAME_LIST, "findByP_N",
148                            new String[] {
149                                    Long.class.getName(), String.class.getName(),
150                                    
151                            "java.lang.Integer", "java.lang.Integer",
152                                    "com.liferay.portal.kernel.util.OrderByComparator"
153                            });
154            public static final FinderPath FINDER_PATH_COUNT_BY_P_N = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
155                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
156                            FINDER_CLASS_NAME_LIST, "countByP_N",
157                            new String[] { Long.class.getName(), String.class.getName() });
158            public static final FinderPath FINDER_PATH_FIND_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
159                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
160                            FINDER_CLASS_NAME_LIST, "findByP_V",
161                            new String[] {
162                                    Long.class.getName(), Long.class.getName(),
163                                    
164                            "java.lang.Integer", "java.lang.Integer",
165                                    "com.liferay.portal.kernel.util.OrderByComparator"
166                            });
167            public static final FinderPath FINDER_PATH_COUNT_BY_P_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
168                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
169                            FINDER_CLASS_NAME_LIST, "countByP_V",
170                            new String[] { Long.class.getName(), Long.class.getName() });
171            public static final FinderPath FINDER_PATH_FIND_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
172                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
173                            FINDER_CLASS_NAME_LIST, "findByN_V",
174                            new String[] {
175                                    String.class.getName(), Long.class.getName(),
176                                    
177                            "java.lang.Integer", "java.lang.Integer",
178                                    "com.liferay.portal.kernel.util.OrderByComparator"
179                            });
180            public static final FinderPath FINDER_PATH_COUNT_BY_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
181                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
182                            FINDER_CLASS_NAME_LIST, "countByN_V",
183                            new String[] { String.class.getName(), Long.class.getName() });
184            public static final FinderPath FINDER_PATH_FETCH_BY_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
185                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
186                            FINDER_CLASS_NAME_ENTITY, "fetchByP_N_V",
187                            new String[] {
188                                    Long.class.getName(), String.class.getName(),
189                                    Long.class.getName()
190                            });
191            public static final FinderPath FINDER_PATH_COUNT_BY_P_N_V = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
192                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
193                            FINDER_CLASS_NAME_LIST, "countByP_N_V",
194                            new String[] {
195                                    Long.class.getName(), String.class.getName(),
196                                    Long.class.getName()
197                            });
198            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
199                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
200                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
201            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
202                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED,
203                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
204    
205            /**
206             * Caches the asset category in the entity cache if it is enabled.
207             *
208             * @param assetCategory the asset category to cache
209             */
210            public void cacheResult(AssetCategory assetCategory) {
211                    EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
212                            AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
213                            assetCategory);
214    
215                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
216                            new Object[] {
217                                    assetCategory.getUuid(), new Long(assetCategory.getGroupId())
218                            }, assetCategory);
219    
220                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
221                            new Object[] {
222                                    new Long(assetCategory.getParentCategoryId()),
223                                    
224                            assetCategory.getName(), new Long(assetCategory.getVocabularyId())
225                            }, assetCategory);
226            }
227    
228            /**
229             * Caches the asset categories in the entity cache if it is enabled.
230             *
231             * @param assetCategories the asset categories to cache
232             */
233            public void cacheResult(List<AssetCategory> assetCategories) {
234                    for (AssetCategory assetCategory : assetCategories) {
235                            if (EntityCacheUtil.getResult(
236                                                    AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
237                                                    AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
238                                                    this) == null) {
239                                    cacheResult(assetCategory);
240                            }
241                    }
242            }
243    
244            /**
245             * Clears the cache for all asset categories.
246             *
247             * <p>
248             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
249             * </p>
250             */
251            public void clearCache() {
252                    CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
253                    EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
254                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
255                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
256            }
257    
258            /**
259             * Clears the cache for the asset category.
260             *
261             * <p>
262             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
263             * </p>
264             */
265            public void clearCache(AssetCategory assetCategory) {
266                    EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
267                            AssetCategoryImpl.class, assetCategory.getPrimaryKey());
268    
269                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
270                            new Object[] {
271                                    assetCategory.getUuid(), new Long(assetCategory.getGroupId())
272                            });
273    
274                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V,
275                            new Object[] {
276                                    new Long(assetCategory.getParentCategoryId()),
277                                    
278                            assetCategory.getName(), new Long(assetCategory.getVocabularyId())
279                            });
280            }
281    
282            /**
283             * Creates a new asset category with the primary key. Does not add the asset category to the database.
284             *
285             * @param categoryId the primary key for the new asset category
286             * @return the new asset category
287             */
288            public AssetCategory create(long categoryId) {
289                    AssetCategory assetCategory = new AssetCategoryImpl();
290    
291                    assetCategory.setNew(true);
292                    assetCategory.setPrimaryKey(categoryId);
293    
294                    String uuid = PortalUUIDUtil.generate();
295    
296                    assetCategory.setUuid(uuid);
297    
298                    return assetCategory;
299            }
300    
301            /**
302             * Removes the asset category with the primary key from the database. Also notifies the appropriate model listeners.
303             *
304             * @param primaryKey the primary key of the asset category to remove
305             * @return the asset category that was removed
306             * @throws com.liferay.portal.NoSuchModelException if a asset category with the primary key could not be found
307             * @throws SystemException if a system exception occurred
308             */
309            public AssetCategory remove(Serializable primaryKey)
310                    throws NoSuchModelException, SystemException {
311                    return remove(((Long)primaryKey).longValue());
312            }
313    
314            /**
315             * Removes the asset category with the primary key from the database. Also notifies the appropriate model listeners.
316             *
317             * @param categoryId the primary key of the asset category to remove
318             * @return the asset category that was removed
319             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
320             * @throws SystemException if a system exception occurred
321             */
322            public AssetCategory remove(long categoryId)
323                    throws NoSuchCategoryException, SystemException {
324                    Session session = null;
325    
326                    try {
327                            session = openSession();
328    
329                            AssetCategory assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
330                                            new Long(categoryId));
331    
332                            if (assetCategory == null) {
333                                    if (_log.isWarnEnabled()) {
334                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
335                                    }
336    
337                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
338                                            categoryId);
339                            }
340    
341                            return remove(assetCategory);
342                    }
343                    catch (NoSuchCategoryException nsee) {
344                            throw nsee;
345                    }
346                    catch (Exception e) {
347                            throw processException(e);
348                    }
349                    finally {
350                            closeSession(session);
351                    }
352            }
353    
354            protected AssetCategory removeImpl(AssetCategory assetCategory)
355                    throws SystemException {
356                    assetCategory = toUnwrappedModel(assetCategory);
357    
358                    try {
359                            clearAssetEntries.clear(assetCategory.getPrimaryKey());
360                    }
361                    catch (Exception e) {
362                            throw processException(e);
363                    }
364                    finally {
365                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
366                    }
367    
368                    shrinkTree(assetCategory);
369    
370                    Session session = null;
371    
372                    try {
373                            session = openSession();
374    
375                            if (assetCategory.isCachedModel() || BatchSessionUtil.isEnabled()) {
376                                    Object staleObject = session.get(AssetCategoryImpl.class,
377                                                    assetCategory.getPrimaryKeyObj());
378    
379                                    if (staleObject != null) {
380                                            session.evict(staleObject);
381                                    }
382                            }
383    
384                            session.delete(assetCategory);
385    
386                            session.flush();
387                    }
388                    catch (Exception e) {
389                            throw processException(e);
390                    }
391                    finally {
392                            closeSession(session);
393                    }
394    
395                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
396    
397                    AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
398    
399                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
400                            new Object[] {
401                                    assetCategoryModelImpl.getOriginalUuid(),
402                                    new Long(assetCategoryModelImpl.getOriginalGroupId())
403                            });
404    
405                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V,
406                            new Object[] {
407                                    new Long(assetCategoryModelImpl.getOriginalParentCategoryId()),
408                                    
409                            assetCategoryModelImpl.getOriginalName(),
410                                    new Long(assetCategoryModelImpl.getOriginalVocabularyId())
411                            });
412    
413                    EntityCacheUtil.removeResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
414                            AssetCategoryImpl.class, assetCategory.getPrimaryKey());
415    
416                    return assetCategory;
417            }
418    
419            public AssetCategory updateImpl(
420                    com.liferay.portlet.asset.model.AssetCategory assetCategory,
421                    boolean merge) throws SystemException {
422                    assetCategory = toUnwrappedModel(assetCategory);
423    
424                    boolean isNew = assetCategory.isNew();
425    
426                    AssetCategoryModelImpl assetCategoryModelImpl = (AssetCategoryModelImpl)assetCategory;
427    
428                    if (Validator.isNull(assetCategory.getUuid())) {
429                            String uuid = PortalUUIDUtil.generate();
430    
431                            assetCategory.setUuid(uuid);
432                    }
433    
434                    if (isNew) {
435                            expandTree(assetCategory);
436                    }
437                    else {
438                            if (assetCategory.getParentCategoryId() != assetCategoryModelImpl.getOriginalParentCategoryId()) {
439                                    shrinkTree(assetCategory);
440                                    expandTree(assetCategory);
441                            }
442                    }
443    
444                    Session session = null;
445    
446                    try {
447                            session = openSession();
448    
449                            BatchSessionUtil.update(session, assetCategory, merge);
450    
451                            assetCategory.setNew(false);
452                    }
453                    catch (Exception e) {
454                            throw processException(e);
455                    }
456                    finally {
457                            closeSession(session);
458                    }
459    
460                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
461    
462                    EntityCacheUtil.putResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
463                            AssetCategoryImpl.class, assetCategory.getPrimaryKey(),
464                            assetCategory);
465    
466                    if (!isNew &&
467                                    (!Validator.equals(assetCategory.getUuid(),
468                                            assetCategoryModelImpl.getOriginalUuid()) ||
469                                    (assetCategory.getGroupId() != assetCategoryModelImpl.getOriginalGroupId()))) {
470                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
471                                    new Object[] {
472                                            assetCategoryModelImpl.getOriginalUuid(),
473                                            new Long(assetCategoryModelImpl.getOriginalGroupId())
474                                    });
475                    }
476    
477                    if (isNew ||
478                                    (!Validator.equals(assetCategory.getUuid(),
479                                            assetCategoryModelImpl.getOriginalUuid()) ||
480                                    (assetCategory.getGroupId() != assetCategoryModelImpl.getOriginalGroupId()))) {
481                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
482                                    new Object[] {
483                                            assetCategory.getUuid(),
484                                            new Long(assetCategory.getGroupId())
485                                    }, assetCategory);
486                    }
487    
488                    if (!isNew &&
489                                    ((assetCategory.getParentCategoryId() != assetCategoryModelImpl.getOriginalParentCategoryId()) ||
490                                    !Validator.equals(assetCategory.getName(),
491                                            assetCategoryModelImpl.getOriginalName()) ||
492                                    (assetCategory.getVocabularyId() != assetCategoryModelImpl.getOriginalVocabularyId()))) {
493                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_N_V,
494                                    new Object[] {
495                                            new Long(assetCategoryModelImpl.getOriginalParentCategoryId()),
496                                            
497                                    assetCategoryModelImpl.getOriginalName(),
498                                            new Long(assetCategoryModelImpl.getOriginalVocabularyId())
499                                    });
500                    }
501    
502                    if (isNew ||
503                                    ((assetCategory.getParentCategoryId() != assetCategoryModelImpl.getOriginalParentCategoryId()) ||
504                                    !Validator.equals(assetCategory.getName(),
505                                            assetCategoryModelImpl.getOriginalName()) ||
506                                    (assetCategory.getVocabularyId() != assetCategoryModelImpl.getOriginalVocabularyId()))) {
507                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
508                                    new Object[] {
509                                            new Long(assetCategory.getParentCategoryId()),
510                                            
511                                    assetCategory.getName(),
512                                            new Long(assetCategory.getVocabularyId())
513                                    }, assetCategory);
514                    }
515    
516                    return assetCategory;
517            }
518    
519            protected AssetCategory toUnwrappedModel(AssetCategory assetCategory) {
520                    if (assetCategory instanceof AssetCategoryImpl) {
521                            return assetCategory;
522                    }
523    
524                    AssetCategoryImpl assetCategoryImpl = new AssetCategoryImpl();
525    
526                    assetCategoryImpl.setNew(assetCategory.isNew());
527                    assetCategoryImpl.setPrimaryKey(assetCategory.getPrimaryKey());
528    
529                    assetCategoryImpl.setUuid(assetCategory.getUuid());
530                    assetCategoryImpl.setCategoryId(assetCategory.getCategoryId());
531                    assetCategoryImpl.setGroupId(assetCategory.getGroupId());
532                    assetCategoryImpl.setCompanyId(assetCategory.getCompanyId());
533                    assetCategoryImpl.setUserId(assetCategory.getUserId());
534                    assetCategoryImpl.setUserName(assetCategory.getUserName());
535                    assetCategoryImpl.setCreateDate(assetCategory.getCreateDate());
536                    assetCategoryImpl.setModifiedDate(assetCategory.getModifiedDate());
537                    assetCategoryImpl.setParentCategoryId(assetCategory.getParentCategoryId());
538                    assetCategoryImpl.setLeftCategoryId(assetCategory.getLeftCategoryId());
539                    assetCategoryImpl.setRightCategoryId(assetCategory.getRightCategoryId());
540                    assetCategoryImpl.setName(assetCategory.getName());
541                    assetCategoryImpl.setTitle(assetCategory.getTitle());
542                    assetCategoryImpl.setVocabularyId(assetCategory.getVocabularyId());
543    
544                    return assetCategoryImpl;
545            }
546    
547            /**
548             * Finds the asset category with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
549             *
550             * @param primaryKey the primary key of the asset category to find
551             * @return the asset category
552             * @throws com.liferay.portal.NoSuchModelException if a asset category with the primary key could not be found
553             * @throws SystemException if a system exception occurred
554             */
555            public AssetCategory findByPrimaryKey(Serializable primaryKey)
556                    throws NoSuchModelException, SystemException {
557                    return findByPrimaryKey(((Long)primaryKey).longValue());
558            }
559    
560            /**
561             * Finds the asset category with the primary key or throws a {@link com.liferay.portlet.asset.NoSuchCategoryException} if it could not be found.
562             *
563             * @param categoryId the primary key of the asset category to find
564             * @return the asset category
565             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
566             * @throws SystemException if a system exception occurred
567             */
568            public AssetCategory findByPrimaryKey(long categoryId)
569                    throws NoSuchCategoryException, SystemException {
570                    AssetCategory assetCategory = fetchByPrimaryKey(categoryId);
571    
572                    if (assetCategory == null) {
573                            if (_log.isWarnEnabled()) {
574                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
575                            }
576    
577                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
578                                    categoryId);
579                    }
580    
581                    return assetCategory;
582            }
583    
584            /**
585             * Finds the asset category with the primary key or returns <code>null</code> if it could not be found.
586             *
587             * @param primaryKey the primary key of the asset category to find
588             * @return the asset category, or <code>null</code> if a asset category with the primary key could not be found
589             * @throws SystemException if a system exception occurred
590             */
591            public AssetCategory fetchByPrimaryKey(Serializable primaryKey)
592                    throws SystemException {
593                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
594            }
595    
596            /**
597             * Finds the asset category with the primary key or returns <code>null</code> if it could not be found.
598             *
599             * @param categoryId the primary key of the asset category to find
600             * @return the asset category, or <code>null</code> if a asset category with the primary key could not be found
601             * @throws SystemException if a system exception occurred
602             */
603            public AssetCategory fetchByPrimaryKey(long categoryId)
604                    throws SystemException {
605                    AssetCategory assetCategory = (AssetCategory)EntityCacheUtil.getResult(AssetCategoryModelImpl.ENTITY_CACHE_ENABLED,
606                                    AssetCategoryImpl.class, categoryId, this);
607    
608                    if (assetCategory == null) {
609                            Session session = null;
610    
611                            try {
612                                    session = openSession();
613    
614                                    assetCategory = (AssetCategory)session.get(AssetCategoryImpl.class,
615                                                    new Long(categoryId));
616                            }
617                            catch (Exception e) {
618                                    throw processException(e);
619                            }
620                            finally {
621                                    if (assetCategory != null) {
622                                            cacheResult(assetCategory);
623                                    }
624    
625                                    closeSession(session);
626                            }
627                    }
628    
629                    return assetCategory;
630            }
631    
632            /**
633             * Finds all the asset categories where uuid = &#63;.
634             *
635             * @param uuid the uuid to search with
636             * @return the matching asset categories
637             * @throws SystemException if a system exception occurred
638             */
639            public List<AssetCategory> findByUuid(String uuid)
640                    throws SystemException {
641                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
642            }
643    
644            /**
645             * Finds a range of all the asset categories where uuid = &#63;.
646             *
647             * <p>
648             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
649             * </p>
650             *
651             * @param uuid the uuid to search with
652             * @param start the lower bound of the range of asset categories to return
653             * @param end the upper bound of the range of asset categories to return (not inclusive)
654             * @return the range of matching asset categories
655             * @throws SystemException if a system exception occurred
656             */
657            public List<AssetCategory> findByUuid(String uuid, int start, int end)
658                    throws SystemException {
659                    return findByUuid(uuid, start, end, null);
660            }
661    
662            /**
663             * Finds an ordered range of all the asset categories where uuid = &#63;.
664             *
665             * <p>
666             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
667             * </p>
668             *
669             * @param uuid the uuid to search with
670             * @param start the lower bound of the range of asset categories to return
671             * @param end the upper bound of the range of asset categories to return (not inclusive)
672             * @param orderByComparator the comparator to order the results by
673             * @return the ordered range of matching asset categories
674             * @throws SystemException if a system exception occurred
675             */
676            public List<AssetCategory> findByUuid(String uuid, int start, int end,
677                    OrderByComparator orderByComparator) throws SystemException {
678                    Object[] finderArgs = new Object[] {
679                                    uuid,
680                                    
681                                    String.valueOf(start), String.valueOf(end),
682                                    String.valueOf(orderByComparator)
683                            };
684    
685                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
686                                    finderArgs, this);
687    
688                    if (list == null) {
689                            Session session = null;
690    
691                            try {
692                                    session = openSession();
693    
694                                    StringBundler query = null;
695    
696                                    if (orderByComparator != null) {
697                                            query = new StringBundler(3 +
698                                                            (orderByComparator.getOrderByFields().length * 3));
699                                    }
700                                    else {
701                                            query = new StringBundler(3);
702                                    }
703    
704                                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
705    
706                                    if (uuid == null) {
707                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
708                                    }
709                                    else {
710                                            if (uuid.equals(StringPool.BLANK)) {
711                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
712                                            }
713                                            else {
714                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
715                                            }
716                                    }
717    
718                                    if (orderByComparator != null) {
719                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
720                                                    orderByComparator);
721                                    }
722    
723                                    else {
724                                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
725                                    }
726    
727                                    String sql = query.toString();
728    
729                                    Query q = session.createQuery(sql);
730    
731                                    QueryPos qPos = QueryPos.getInstance(q);
732    
733                                    if (uuid != null) {
734                                            qPos.add(uuid);
735                                    }
736    
737                                    list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
738                                                    start, end);
739                            }
740                            catch (Exception e) {
741                                    throw processException(e);
742                            }
743                            finally {
744                                    if (list == null) {
745                                            list = new ArrayList<AssetCategory>();
746                                    }
747    
748                                    cacheResult(list);
749    
750                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
751                                            list);
752    
753                                    closeSession(session);
754                            }
755                    }
756    
757                    return list;
758            }
759    
760            /**
761             * Finds the first asset category in the ordered set where uuid = &#63;.
762             *
763             * <p>
764             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
765             * </p>
766             *
767             * @param uuid the uuid to search with
768             * @param orderByComparator the comparator to order the set by
769             * @return the first matching asset category
770             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
771             * @throws SystemException if a system exception occurred
772             */
773            public AssetCategory findByUuid_First(String uuid,
774                    OrderByComparator orderByComparator)
775                    throws NoSuchCategoryException, SystemException {
776                    List<AssetCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
777    
778                    if (list.isEmpty()) {
779                            StringBundler msg = new StringBundler(4);
780    
781                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
782    
783                            msg.append("uuid=");
784                            msg.append(uuid);
785    
786                            msg.append(StringPool.CLOSE_CURLY_BRACE);
787    
788                            throw new NoSuchCategoryException(msg.toString());
789                    }
790                    else {
791                            return list.get(0);
792                    }
793            }
794    
795            /**
796             * Finds the last asset category in the ordered set where uuid = &#63;.
797             *
798             * <p>
799             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
800             * </p>
801             *
802             * @param uuid the uuid to search with
803             * @param orderByComparator the comparator to order the set by
804             * @return the last matching asset category
805             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
806             * @throws SystemException if a system exception occurred
807             */
808            public AssetCategory findByUuid_Last(String uuid,
809                    OrderByComparator orderByComparator)
810                    throws NoSuchCategoryException, SystemException {
811                    int count = countByUuid(uuid);
812    
813                    List<AssetCategory> list = findByUuid(uuid, count - 1, count,
814                                    orderByComparator);
815    
816                    if (list.isEmpty()) {
817                            StringBundler msg = new StringBundler(4);
818    
819                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
820    
821                            msg.append("uuid=");
822                            msg.append(uuid);
823    
824                            msg.append(StringPool.CLOSE_CURLY_BRACE);
825    
826                            throw new NoSuchCategoryException(msg.toString());
827                    }
828                    else {
829                            return list.get(0);
830                    }
831            }
832    
833            /**
834             * Finds the asset categories before and after the current asset category in the ordered set where uuid = &#63;.
835             *
836             * <p>
837             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
838             * </p>
839             *
840             * @param categoryId the primary key of the current asset category
841             * @param uuid the uuid to search with
842             * @param orderByComparator the comparator to order the set by
843             * @return the previous, current, and next asset category
844             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
845             * @throws SystemException if a system exception occurred
846             */
847            public AssetCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
848                    OrderByComparator orderByComparator)
849                    throws NoSuchCategoryException, SystemException {
850                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
851    
852                    Session session = null;
853    
854                    try {
855                            session = openSession();
856    
857                            AssetCategory[] array = new AssetCategoryImpl[3];
858    
859                            array[0] = getByUuid_PrevAndNext(session, assetCategory, uuid,
860                                            orderByComparator, true);
861    
862                            array[1] = assetCategory;
863    
864                            array[2] = getByUuid_PrevAndNext(session, assetCategory, uuid,
865                                            orderByComparator, false);
866    
867                            return array;
868                    }
869                    catch (Exception e) {
870                            throw processException(e);
871                    }
872                    finally {
873                            closeSession(session);
874                    }
875            }
876    
877            protected AssetCategory getByUuid_PrevAndNext(Session session,
878                    AssetCategory assetCategory, String uuid,
879                    OrderByComparator orderByComparator, boolean previous) {
880                    StringBundler query = null;
881    
882                    if (orderByComparator != null) {
883                            query = new StringBundler(6 +
884                                            (orderByComparator.getOrderByFields().length * 6));
885                    }
886                    else {
887                            query = new StringBundler(3);
888                    }
889    
890                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
891    
892                    if (uuid == null) {
893                            query.append(_FINDER_COLUMN_UUID_UUID_1);
894                    }
895                    else {
896                            if (uuid.equals(StringPool.BLANK)) {
897                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
898                            }
899                            else {
900                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
901                            }
902                    }
903    
904                    if (orderByComparator != null) {
905                            String[] orderByFields = orderByComparator.getOrderByFields();
906    
907                            if (orderByFields.length > 0) {
908                                    query.append(WHERE_AND);
909                            }
910    
911                            for (int i = 0; i < orderByFields.length; i++) {
912                                    query.append(_ORDER_BY_ENTITY_ALIAS);
913                                    query.append(orderByFields[i]);
914    
915                                    if ((i + 1) < orderByFields.length) {
916                                            if (orderByComparator.isAscending() ^ previous) {
917                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
918                                            }
919                                            else {
920                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
921                                            }
922                                    }
923                                    else {
924                                            if (orderByComparator.isAscending() ^ previous) {
925                                                    query.append(WHERE_GREATER_THAN);
926                                            }
927                                            else {
928                                                    query.append(WHERE_LESSER_THAN);
929                                            }
930                                    }
931                            }
932    
933                            query.append(ORDER_BY_CLAUSE);
934    
935                            for (int i = 0; i < orderByFields.length; i++) {
936                                    query.append(_ORDER_BY_ENTITY_ALIAS);
937                                    query.append(orderByFields[i]);
938    
939                                    if ((i + 1) < orderByFields.length) {
940                                            if (orderByComparator.isAscending() ^ previous) {
941                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
942                                            }
943                                            else {
944                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
945                                            }
946                                    }
947                                    else {
948                                            if (orderByComparator.isAscending() ^ previous) {
949                                                    query.append(ORDER_BY_ASC);
950                                            }
951                                            else {
952                                                    query.append(ORDER_BY_DESC);
953                                            }
954                                    }
955                            }
956                    }
957    
958                    else {
959                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
960                    }
961    
962                    String sql = query.toString();
963    
964                    Query q = session.createQuery(sql);
965    
966                    q.setFirstResult(0);
967                    q.setMaxResults(2);
968    
969                    QueryPos qPos = QueryPos.getInstance(q);
970    
971                    if (uuid != null) {
972                            qPos.add(uuid);
973                    }
974    
975                    if (orderByComparator != null) {
976                            Object[] values = orderByComparator.getOrderByValues(assetCategory);
977    
978                            for (Object value : values) {
979                                    qPos.add(value);
980                            }
981                    }
982    
983                    List<AssetCategory> list = q.list();
984    
985                    if (list.size() == 2) {
986                            return list.get(1);
987                    }
988                    else {
989                            return null;
990                    }
991            }
992    
993            /**
994             * Finds the asset category where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchCategoryException} if it could not be found.
995             *
996             * @param uuid the uuid to search with
997             * @param groupId the group id to search with
998             * @return the matching asset category
999             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
1000             * @throws SystemException if a system exception occurred
1001             */
1002            public AssetCategory findByUUID_G(String uuid, long groupId)
1003                    throws NoSuchCategoryException, SystemException {
1004                    AssetCategory assetCategory = fetchByUUID_G(uuid, groupId);
1005    
1006                    if (assetCategory == null) {
1007                            StringBundler msg = new StringBundler(6);
1008    
1009                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1010    
1011                            msg.append("uuid=");
1012                            msg.append(uuid);
1013    
1014                            msg.append(", groupId=");
1015                            msg.append(groupId);
1016    
1017                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1018    
1019                            if (_log.isWarnEnabled()) {
1020                                    _log.warn(msg.toString());
1021                            }
1022    
1023                            throw new NoSuchCategoryException(msg.toString());
1024                    }
1025    
1026                    return assetCategory;
1027            }
1028    
1029            /**
1030             * Finds the asset category where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1031             *
1032             * @param uuid the uuid to search with
1033             * @param groupId the group id to search with
1034             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
1035             * @throws SystemException if a system exception occurred
1036             */
1037            public AssetCategory fetchByUUID_G(String uuid, long groupId)
1038                    throws SystemException {
1039                    return fetchByUUID_G(uuid, groupId, true);
1040            }
1041    
1042            /**
1043             * Finds 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.
1044             *
1045             * @param uuid the uuid to search with
1046             * @param groupId the group id to search with
1047             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
1048             * @throws SystemException if a system exception occurred
1049             */
1050            public AssetCategory fetchByUUID_G(String uuid, long groupId,
1051                    boolean retrieveFromCache) throws SystemException {
1052                    Object[] finderArgs = new Object[] { uuid, groupId };
1053    
1054                    Object result = null;
1055    
1056                    if (retrieveFromCache) {
1057                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1058                                            finderArgs, this);
1059                    }
1060    
1061                    if (result == null) {
1062                            Session session = null;
1063    
1064                            try {
1065                                    session = openSession();
1066    
1067                                    StringBundler query = new StringBundler(4);
1068    
1069                                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1070    
1071                                    if (uuid == null) {
1072                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1073                                    }
1074                                    else {
1075                                            if (uuid.equals(StringPool.BLANK)) {
1076                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1077                                            }
1078                                            else {
1079                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1080                                            }
1081                                    }
1082    
1083                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1084    
1085                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1086    
1087                                    String sql = query.toString();
1088    
1089                                    Query q = session.createQuery(sql);
1090    
1091                                    QueryPos qPos = QueryPos.getInstance(q);
1092    
1093                                    if (uuid != null) {
1094                                            qPos.add(uuid);
1095                                    }
1096    
1097                                    qPos.add(groupId);
1098    
1099                                    List<AssetCategory> list = q.list();
1100    
1101                                    result = list;
1102    
1103                                    AssetCategory assetCategory = null;
1104    
1105                                    if (list.isEmpty()) {
1106                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1107                                                    finderArgs, list);
1108                                    }
1109                                    else {
1110                                            assetCategory = list.get(0);
1111    
1112                                            cacheResult(assetCategory);
1113    
1114                                            if ((assetCategory.getUuid() == null) ||
1115                                                            !assetCategory.getUuid().equals(uuid) ||
1116                                                            (assetCategory.getGroupId() != groupId)) {
1117                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1118                                                            finderArgs, assetCategory);
1119                                            }
1120                                    }
1121    
1122                                    return assetCategory;
1123                            }
1124                            catch (Exception e) {
1125                                    throw processException(e);
1126                            }
1127                            finally {
1128                                    if (result == null) {
1129                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1130                                                    finderArgs, new ArrayList<AssetCategory>());
1131                                    }
1132    
1133                                    closeSession(session);
1134                            }
1135                    }
1136                    else {
1137                            if (result instanceof List<?>) {
1138                                    return null;
1139                            }
1140                            else {
1141                                    return (AssetCategory)result;
1142                            }
1143                    }
1144            }
1145    
1146            /**
1147             * Finds all the asset categories where groupId = &#63;.
1148             *
1149             * @param groupId the group id to search with
1150             * @return the matching asset categories
1151             * @throws SystemException if a system exception occurred
1152             */
1153            public List<AssetCategory> findByGroupId(long groupId)
1154                    throws SystemException {
1155                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1156            }
1157    
1158            /**
1159             * Finds a range of all the asset categories where groupId = &#63;.
1160             *
1161             * <p>
1162             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1163             * </p>
1164             *
1165             * @param groupId the group id to search with
1166             * @param start the lower bound of the range of asset categories to return
1167             * @param end the upper bound of the range of asset categories to return (not inclusive)
1168             * @return the range of matching asset categories
1169             * @throws SystemException if a system exception occurred
1170             */
1171            public List<AssetCategory> findByGroupId(long groupId, int start, int end)
1172                    throws SystemException {
1173                    return findByGroupId(groupId, start, end, null);
1174            }
1175    
1176            /**
1177             * Finds an ordered range of all the asset categories where groupId = &#63;.
1178             *
1179             * <p>
1180             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1181             * </p>
1182             *
1183             * @param groupId the group id to search with
1184             * @param start the lower bound of the range of asset categories to return
1185             * @param end the upper bound of the range of asset categories to return (not inclusive)
1186             * @param orderByComparator the comparator to order the results by
1187             * @return the ordered range of matching asset categories
1188             * @throws SystemException if a system exception occurred
1189             */
1190            public List<AssetCategory> findByGroupId(long groupId, int start, int end,
1191                    OrderByComparator orderByComparator) throws SystemException {
1192                    Object[] finderArgs = new Object[] {
1193                                    groupId,
1194                                    
1195                                    String.valueOf(start), String.valueOf(end),
1196                                    String.valueOf(orderByComparator)
1197                            };
1198    
1199                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1200                                    finderArgs, this);
1201    
1202                    if (list == null) {
1203                            Session session = null;
1204    
1205                            try {
1206                                    session = openSession();
1207    
1208                                    StringBundler query = null;
1209    
1210                                    if (orderByComparator != null) {
1211                                            query = new StringBundler(3 +
1212                                                            (orderByComparator.getOrderByFields().length * 3));
1213                                    }
1214                                    else {
1215                                            query = new StringBundler(3);
1216                                    }
1217    
1218                                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1219    
1220                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1221    
1222                                    if (orderByComparator != null) {
1223                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1224                                                    orderByComparator);
1225                                    }
1226    
1227                                    else {
1228                                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1229                                    }
1230    
1231                                    String sql = query.toString();
1232    
1233                                    Query q = session.createQuery(sql);
1234    
1235                                    QueryPos qPos = QueryPos.getInstance(q);
1236    
1237                                    qPos.add(groupId);
1238    
1239                                    list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1240                                                    start, end);
1241                            }
1242                            catch (Exception e) {
1243                                    throw processException(e);
1244                            }
1245                            finally {
1246                                    if (list == null) {
1247                                            list = new ArrayList<AssetCategory>();
1248                                    }
1249    
1250                                    cacheResult(list);
1251    
1252                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1253                                            finderArgs, list);
1254    
1255                                    closeSession(session);
1256                            }
1257                    }
1258    
1259                    return list;
1260            }
1261    
1262            /**
1263             * Finds the first asset category in the ordered set where groupId = &#63;.
1264             *
1265             * <p>
1266             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1267             * </p>
1268             *
1269             * @param groupId the group id to search with
1270             * @param orderByComparator the comparator to order the set by
1271             * @return the first matching asset category
1272             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
1273             * @throws SystemException if a system exception occurred
1274             */
1275            public AssetCategory findByGroupId_First(long groupId,
1276                    OrderByComparator orderByComparator)
1277                    throws NoSuchCategoryException, SystemException {
1278                    List<AssetCategory> list = findByGroupId(groupId, 0, 1,
1279                                    orderByComparator);
1280    
1281                    if (list.isEmpty()) {
1282                            StringBundler msg = new StringBundler(4);
1283    
1284                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1285    
1286                            msg.append("groupId=");
1287                            msg.append(groupId);
1288    
1289                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1290    
1291                            throw new NoSuchCategoryException(msg.toString());
1292                    }
1293                    else {
1294                            return list.get(0);
1295                    }
1296            }
1297    
1298            /**
1299             * Finds the last asset category in the ordered set where groupId = &#63;.
1300             *
1301             * <p>
1302             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1303             * </p>
1304             *
1305             * @param groupId the group id to search with
1306             * @param orderByComparator the comparator to order the set by
1307             * @return the last matching asset category
1308             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
1309             * @throws SystemException if a system exception occurred
1310             */
1311            public AssetCategory findByGroupId_Last(long groupId,
1312                    OrderByComparator orderByComparator)
1313                    throws NoSuchCategoryException, SystemException {
1314                    int count = countByGroupId(groupId);
1315    
1316                    List<AssetCategory> list = findByGroupId(groupId, count - 1, count,
1317                                    orderByComparator);
1318    
1319                    if (list.isEmpty()) {
1320                            StringBundler msg = new StringBundler(4);
1321    
1322                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1323    
1324                            msg.append("groupId=");
1325                            msg.append(groupId);
1326    
1327                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1328    
1329                            throw new NoSuchCategoryException(msg.toString());
1330                    }
1331                    else {
1332                            return list.get(0);
1333                    }
1334            }
1335    
1336            /**
1337             * Finds the asset categories before and after the current asset category in the ordered set where groupId = &#63;.
1338             *
1339             * <p>
1340             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1341             * </p>
1342             *
1343             * @param categoryId the primary key of the current asset category
1344             * @param groupId the group id to search with
1345             * @param orderByComparator the comparator to order the set by
1346             * @return the previous, current, and next asset category
1347             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
1348             * @throws SystemException if a system exception occurred
1349             */
1350            public AssetCategory[] findByGroupId_PrevAndNext(long categoryId,
1351                    long groupId, OrderByComparator orderByComparator)
1352                    throws NoSuchCategoryException, SystemException {
1353                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
1354    
1355                    Session session = null;
1356    
1357                    try {
1358                            session = openSession();
1359    
1360                            AssetCategory[] array = new AssetCategoryImpl[3];
1361    
1362                            array[0] = getByGroupId_PrevAndNext(session, assetCategory,
1363                                            groupId, orderByComparator, true);
1364    
1365                            array[1] = assetCategory;
1366    
1367                            array[2] = getByGroupId_PrevAndNext(session, assetCategory,
1368                                            groupId, orderByComparator, false);
1369    
1370                            return array;
1371                    }
1372                    catch (Exception e) {
1373                            throw processException(e);
1374                    }
1375                    finally {
1376                            closeSession(session);
1377                    }
1378            }
1379    
1380            protected AssetCategory getByGroupId_PrevAndNext(Session session,
1381                    AssetCategory assetCategory, long groupId,
1382                    OrderByComparator orderByComparator, boolean previous) {
1383                    StringBundler query = null;
1384    
1385                    if (orderByComparator != null) {
1386                            query = new StringBundler(6 +
1387                                            (orderByComparator.getOrderByFields().length * 6));
1388                    }
1389                    else {
1390                            query = new StringBundler(3);
1391                    }
1392    
1393                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1394    
1395                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1396    
1397                    if (orderByComparator != null) {
1398                            String[] orderByFields = orderByComparator.getOrderByFields();
1399    
1400                            if (orderByFields.length > 0) {
1401                                    query.append(WHERE_AND);
1402                            }
1403    
1404                            for (int i = 0; i < orderByFields.length; i++) {
1405                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1406                                    query.append(orderByFields[i]);
1407    
1408                                    if ((i + 1) < orderByFields.length) {
1409                                            if (orderByComparator.isAscending() ^ previous) {
1410                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1411                                            }
1412                                            else {
1413                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1414                                            }
1415                                    }
1416                                    else {
1417                                            if (orderByComparator.isAscending() ^ previous) {
1418                                                    query.append(WHERE_GREATER_THAN);
1419                                            }
1420                                            else {
1421                                                    query.append(WHERE_LESSER_THAN);
1422                                            }
1423                                    }
1424                            }
1425    
1426                            query.append(ORDER_BY_CLAUSE);
1427    
1428                            for (int i = 0; i < orderByFields.length; i++) {
1429                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1430                                    query.append(orderByFields[i]);
1431    
1432                                    if ((i + 1) < orderByFields.length) {
1433                                            if (orderByComparator.isAscending() ^ previous) {
1434                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1435                                            }
1436                                            else {
1437                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1438                                            }
1439                                    }
1440                                    else {
1441                                            if (orderByComparator.isAscending() ^ previous) {
1442                                                    query.append(ORDER_BY_ASC);
1443                                            }
1444                                            else {
1445                                                    query.append(ORDER_BY_DESC);
1446                                            }
1447                                    }
1448                            }
1449                    }
1450    
1451                    else {
1452                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1453                    }
1454    
1455                    String sql = query.toString();
1456    
1457                    Query q = session.createQuery(sql);
1458    
1459                    q.setFirstResult(0);
1460                    q.setMaxResults(2);
1461    
1462                    QueryPos qPos = QueryPos.getInstance(q);
1463    
1464                    qPos.add(groupId);
1465    
1466                    if (orderByComparator != null) {
1467                            Object[] values = orderByComparator.getOrderByValues(assetCategory);
1468    
1469                            for (Object value : values) {
1470                                    qPos.add(value);
1471                            }
1472                    }
1473    
1474                    List<AssetCategory> list = q.list();
1475    
1476                    if (list.size() == 2) {
1477                            return list.get(1);
1478                    }
1479                    else {
1480                            return null;
1481                    }
1482            }
1483    
1484            /**
1485             * Filters by the user's permissions and finds all the asset categories where groupId = &#63;.
1486             *
1487             * @param groupId the group id to search with
1488             * @return the matching asset categories that the user has permission to view
1489             * @throws SystemException if a system exception occurred
1490             */
1491            public List<AssetCategory> filterFindByGroupId(long groupId)
1492                    throws SystemException {
1493                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1494                            QueryUtil.ALL_POS, null);
1495            }
1496    
1497            /**
1498             * Filters by the user's permissions and finds a range of all the asset categories where groupId = &#63;.
1499             *
1500             * <p>
1501             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1502             * </p>
1503             *
1504             * @param groupId the group id to search with
1505             * @param start the lower bound of the range of asset categories to return
1506             * @param end the upper bound of the range of asset categories to return (not inclusive)
1507             * @return the range of matching asset categories that the user has permission to view
1508             * @throws SystemException if a system exception occurred
1509             */
1510            public List<AssetCategory> filterFindByGroupId(long groupId, int start,
1511                    int end) throws SystemException {
1512                    return filterFindByGroupId(groupId, start, end, null);
1513            }
1514    
1515            /**
1516             * Filters by the user's permissions and finds an ordered range of all the asset categories where groupId = &#63;.
1517             *
1518             * <p>
1519             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1520             * </p>
1521             *
1522             * @param groupId the group id to search with
1523             * @param start the lower bound of the range of asset categories to return
1524             * @param end the upper bound of the range of asset categories to return (not inclusive)
1525             * @param orderByComparator the comparator to order the results by
1526             * @return the ordered range of matching asset categories that the user has permission to view
1527             * @throws SystemException if a system exception occurred
1528             */
1529            public List<AssetCategory> filterFindByGroupId(long groupId, int start,
1530                    int end, OrderByComparator orderByComparator) throws SystemException {
1531                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1532                            return findByGroupId(groupId, start, end, orderByComparator);
1533                    }
1534    
1535                    Session session = null;
1536    
1537                    try {
1538                            session = openSession();
1539    
1540                            StringBundler query = null;
1541    
1542                            if (orderByComparator != null) {
1543                                    query = new StringBundler(3 +
1544                                                    (orderByComparator.getOrderByFields().length * 3));
1545                            }
1546                            else {
1547                                    query = new StringBundler(3);
1548                            }
1549    
1550                            query.append(_FILTER_SQL_SELECT_ASSETCATEGORY_WHERE);
1551    
1552                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1553    
1554                            if (orderByComparator != null) {
1555                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1556                                            orderByComparator);
1557                            }
1558    
1559                            else {
1560                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1561                            }
1562    
1563                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1564                                            AssetCategory.class.getName(), _FILTER_COLUMN_PK,
1565                                            _FILTER_COLUMN_USERID, groupId);
1566    
1567                            SQLQuery q = session.createSQLQuery(sql);
1568    
1569                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetCategoryImpl.class);
1570    
1571                            QueryPos qPos = QueryPos.getInstance(q);
1572    
1573                            qPos.add(groupId);
1574    
1575                            return (List<AssetCategory>)QueryUtil.list(q, getDialect(), start,
1576                                    end);
1577                    }
1578                    catch (Exception e) {
1579                            throw processException(e);
1580                    }
1581                    finally {
1582                            closeSession(session);
1583                    }
1584            }
1585    
1586            /**
1587             * Finds all the asset categories where parentCategoryId = &#63;.
1588             *
1589             * @param parentCategoryId the parent category id to search with
1590             * @return the matching asset categories
1591             * @throws SystemException if a system exception occurred
1592             */
1593            public List<AssetCategory> findByParentCategoryId(long parentCategoryId)
1594                    throws SystemException {
1595                    return findByParentCategoryId(parentCategoryId, QueryUtil.ALL_POS,
1596                            QueryUtil.ALL_POS, null);
1597            }
1598    
1599            /**
1600             * Finds a range of all the asset categories where parentCategoryId = &#63;.
1601             *
1602             * <p>
1603             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1604             * </p>
1605             *
1606             * @param parentCategoryId the parent category id to search with
1607             * @param start the lower bound of the range of asset categories to return
1608             * @param end the upper bound of the range of asset categories to return (not inclusive)
1609             * @return the range of matching asset categories
1610             * @throws SystemException if a system exception occurred
1611             */
1612            public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
1613                    int start, int end) throws SystemException {
1614                    return findByParentCategoryId(parentCategoryId, start, end, null);
1615            }
1616    
1617            /**
1618             * Finds an ordered range of all the asset categories where parentCategoryId = &#63;.
1619             *
1620             * <p>
1621             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1622             * </p>
1623             *
1624             * @param parentCategoryId the parent category id to search with
1625             * @param start the lower bound of the range of asset categories to return
1626             * @param end the upper bound of the range of asset categories to return (not inclusive)
1627             * @param orderByComparator the comparator to order the results by
1628             * @return the ordered range of matching asset categories
1629             * @throws SystemException if a system exception occurred
1630             */
1631            public List<AssetCategory> findByParentCategoryId(long parentCategoryId,
1632                    int start, int end, OrderByComparator orderByComparator)
1633                    throws SystemException {
1634                    Object[] finderArgs = new Object[] {
1635                                    parentCategoryId,
1636                                    
1637                                    String.valueOf(start), String.valueOf(end),
1638                                    String.valueOf(orderByComparator)
1639                            };
1640    
1641                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_PARENTCATEGORYID,
1642                                    finderArgs, this);
1643    
1644                    if (list == null) {
1645                            Session session = null;
1646    
1647                            try {
1648                                    session = openSession();
1649    
1650                                    StringBundler query = null;
1651    
1652                                    if (orderByComparator != null) {
1653                                            query = new StringBundler(3 +
1654                                                            (orderByComparator.getOrderByFields().length * 3));
1655                                    }
1656                                    else {
1657                                            query = new StringBundler(3);
1658                                    }
1659    
1660                                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1661    
1662                                    query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
1663    
1664                                    if (orderByComparator != null) {
1665                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1666                                                    orderByComparator);
1667                                    }
1668    
1669                                    else {
1670                                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1671                                    }
1672    
1673                                    String sql = query.toString();
1674    
1675                                    Query q = session.createQuery(sql);
1676    
1677                                    QueryPos qPos = QueryPos.getInstance(q);
1678    
1679                                    qPos.add(parentCategoryId);
1680    
1681                                    list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
1682                                                    start, end);
1683                            }
1684                            catch (Exception e) {
1685                                    throw processException(e);
1686                            }
1687                            finally {
1688                                    if (list == null) {
1689                                            list = new ArrayList<AssetCategory>();
1690                                    }
1691    
1692                                    cacheResult(list);
1693    
1694                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_PARENTCATEGORYID,
1695                                            finderArgs, list);
1696    
1697                                    closeSession(session);
1698                            }
1699                    }
1700    
1701                    return list;
1702            }
1703    
1704            /**
1705             * Finds the first asset category in the ordered set where parentCategoryId = &#63;.
1706             *
1707             * <p>
1708             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1709             * </p>
1710             *
1711             * @param parentCategoryId the parent category id to search with
1712             * @param orderByComparator the comparator to order the set by
1713             * @return the first matching asset category
1714             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
1715             * @throws SystemException if a system exception occurred
1716             */
1717            public AssetCategory findByParentCategoryId_First(long parentCategoryId,
1718                    OrderByComparator orderByComparator)
1719                    throws NoSuchCategoryException, SystemException {
1720                    List<AssetCategory> list = findByParentCategoryId(parentCategoryId, 0,
1721                                    1, orderByComparator);
1722    
1723                    if (list.isEmpty()) {
1724                            StringBundler msg = new StringBundler(4);
1725    
1726                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1727    
1728                            msg.append("parentCategoryId=");
1729                            msg.append(parentCategoryId);
1730    
1731                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1732    
1733                            throw new NoSuchCategoryException(msg.toString());
1734                    }
1735                    else {
1736                            return list.get(0);
1737                    }
1738            }
1739    
1740            /**
1741             * Finds the last asset category in the ordered set where parentCategoryId = &#63;.
1742             *
1743             * <p>
1744             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1745             * </p>
1746             *
1747             * @param parentCategoryId the parent category id to search with
1748             * @param orderByComparator the comparator to order the set by
1749             * @return the last matching asset category
1750             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
1751             * @throws SystemException if a system exception occurred
1752             */
1753            public AssetCategory findByParentCategoryId_Last(long parentCategoryId,
1754                    OrderByComparator orderByComparator)
1755                    throws NoSuchCategoryException, SystemException {
1756                    int count = countByParentCategoryId(parentCategoryId);
1757    
1758                    List<AssetCategory> list = findByParentCategoryId(parentCategoryId,
1759                                    count - 1, count, orderByComparator);
1760    
1761                    if (list.isEmpty()) {
1762                            StringBundler msg = new StringBundler(4);
1763    
1764                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1765    
1766                            msg.append("parentCategoryId=");
1767                            msg.append(parentCategoryId);
1768    
1769                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1770    
1771                            throw new NoSuchCategoryException(msg.toString());
1772                    }
1773                    else {
1774                            return list.get(0);
1775                    }
1776            }
1777    
1778            /**
1779             * Finds the asset categories before and after the current asset category in the ordered set where parentCategoryId = &#63;.
1780             *
1781             * <p>
1782             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1783             * </p>
1784             *
1785             * @param categoryId the primary key of the current asset category
1786             * @param parentCategoryId the parent category id to search with
1787             * @param orderByComparator the comparator to order the set by
1788             * @return the previous, current, and next asset category
1789             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
1790             * @throws SystemException if a system exception occurred
1791             */
1792            public AssetCategory[] findByParentCategoryId_PrevAndNext(long categoryId,
1793                    long parentCategoryId, OrderByComparator orderByComparator)
1794                    throws NoSuchCategoryException, SystemException {
1795                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
1796    
1797                    Session session = null;
1798    
1799                    try {
1800                            session = openSession();
1801    
1802                            AssetCategory[] array = new AssetCategoryImpl[3];
1803    
1804                            array[0] = getByParentCategoryId_PrevAndNext(session,
1805                                            assetCategory, parentCategoryId, orderByComparator, true);
1806    
1807                            array[1] = assetCategory;
1808    
1809                            array[2] = getByParentCategoryId_PrevAndNext(session,
1810                                            assetCategory, parentCategoryId, orderByComparator, false);
1811    
1812                            return array;
1813                    }
1814                    catch (Exception e) {
1815                            throw processException(e);
1816                    }
1817                    finally {
1818                            closeSession(session);
1819                    }
1820            }
1821    
1822            protected AssetCategory getByParentCategoryId_PrevAndNext(Session session,
1823                    AssetCategory assetCategory, long parentCategoryId,
1824                    OrderByComparator orderByComparator, boolean previous) {
1825                    StringBundler query = null;
1826    
1827                    if (orderByComparator != null) {
1828                            query = new StringBundler(6 +
1829                                            (orderByComparator.getOrderByFields().length * 6));
1830                    }
1831                    else {
1832                            query = new StringBundler(3);
1833                    }
1834    
1835                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
1836    
1837                    query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
1838    
1839                    if (orderByComparator != null) {
1840                            String[] orderByFields = orderByComparator.getOrderByFields();
1841    
1842                            if (orderByFields.length > 0) {
1843                                    query.append(WHERE_AND);
1844                            }
1845    
1846                            for (int i = 0; i < orderByFields.length; i++) {
1847                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1848                                    query.append(orderByFields[i]);
1849    
1850                                    if ((i + 1) < orderByFields.length) {
1851                                            if (orderByComparator.isAscending() ^ previous) {
1852                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1853                                            }
1854                                            else {
1855                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1856                                            }
1857                                    }
1858                                    else {
1859                                            if (orderByComparator.isAscending() ^ previous) {
1860                                                    query.append(WHERE_GREATER_THAN);
1861                                            }
1862                                            else {
1863                                                    query.append(WHERE_LESSER_THAN);
1864                                            }
1865                                    }
1866                            }
1867    
1868                            query.append(ORDER_BY_CLAUSE);
1869    
1870                            for (int i = 0; i < orderByFields.length; i++) {
1871                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1872                                    query.append(orderByFields[i]);
1873    
1874                                    if ((i + 1) < orderByFields.length) {
1875                                            if (orderByComparator.isAscending() ^ previous) {
1876                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1877                                            }
1878                                            else {
1879                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1880                                            }
1881                                    }
1882                                    else {
1883                                            if (orderByComparator.isAscending() ^ previous) {
1884                                                    query.append(ORDER_BY_ASC);
1885                                            }
1886                                            else {
1887                                                    query.append(ORDER_BY_DESC);
1888                                            }
1889                                    }
1890                            }
1891                    }
1892    
1893                    else {
1894                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
1895                    }
1896    
1897                    String sql = query.toString();
1898    
1899                    Query q = session.createQuery(sql);
1900    
1901                    q.setFirstResult(0);
1902                    q.setMaxResults(2);
1903    
1904                    QueryPos qPos = QueryPos.getInstance(q);
1905    
1906                    qPos.add(parentCategoryId);
1907    
1908                    if (orderByComparator != null) {
1909                            Object[] values = orderByComparator.getOrderByValues(assetCategory);
1910    
1911                            for (Object value : values) {
1912                                    qPos.add(value);
1913                            }
1914                    }
1915    
1916                    List<AssetCategory> list = q.list();
1917    
1918                    if (list.size() == 2) {
1919                            return list.get(1);
1920                    }
1921                    else {
1922                            return null;
1923                    }
1924            }
1925    
1926            /**
1927             * Finds all the asset categories where vocabularyId = &#63;.
1928             *
1929             * @param vocabularyId the vocabulary id to search with
1930             * @return the matching asset categories
1931             * @throws SystemException if a system exception occurred
1932             */
1933            public List<AssetCategory> findByVocabularyId(long vocabularyId)
1934                    throws SystemException {
1935                    return findByVocabularyId(vocabularyId, QueryUtil.ALL_POS,
1936                            QueryUtil.ALL_POS, null);
1937            }
1938    
1939            /**
1940             * Finds a range of all the asset categories where vocabularyId = &#63;.
1941             *
1942             * <p>
1943             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1944             * </p>
1945             *
1946             * @param vocabularyId the vocabulary id to search with
1947             * @param start the lower bound of the range of asset categories to return
1948             * @param end the upper bound of the range of asset categories to return (not inclusive)
1949             * @return the range of matching asset categories
1950             * @throws SystemException if a system exception occurred
1951             */
1952            public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
1953                    int end) throws SystemException {
1954                    return findByVocabularyId(vocabularyId, start, end, null);
1955            }
1956    
1957            /**
1958             * Finds an ordered range of all the asset categories where vocabularyId = &#63;.
1959             *
1960             * <p>
1961             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1962             * </p>
1963             *
1964             * @param vocabularyId the vocabulary id to search with
1965             * @param start the lower bound of the range of asset categories to return
1966             * @param end the upper bound of the range of asset categories to return (not inclusive)
1967             * @param orderByComparator the comparator to order the results by
1968             * @return the ordered range of matching asset categories
1969             * @throws SystemException if a system exception occurred
1970             */
1971            public List<AssetCategory> findByVocabularyId(long vocabularyId, int start,
1972                    int end, OrderByComparator orderByComparator) throws SystemException {
1973                    Object[] finderArgs = new Object[] {
1974                                    vocabularyId,
1975                                    
1976                                    String.valueOf(start), String.valueOf(end),
1977                                    String.valueOf(orderByComparator)
1978                            };
1979    
1980                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_VOCABULARYID,
1981                                    finderArgs, this);
1982    
1983                    if (list == null) {
1984                            Session session = null;
1985    
1986                            try {
1987                                    session = openSession();
1988    
1989                                    StringBundler query = null;
1990    
1991                                    if (orderByComparator != null) {
1992                                            query = new StringBundler(3 +
1993                                                            (orderByComparator.getOrderByFields().length * 3));
1994                                    }
1995                                    else {
1996                                            query = new StringBundler(3);
1997                                    }
1998    
1999                                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2000    
2001                                    query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
2002    
2003                                    if (orderByComparator != null) {
2004                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2005                                                    orderByComparator);
2006                                    }
2007    
2008                                    else {
2009                                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2010                                    }
2011    
2012                                    String sql = query.toString();
2013    
2014                                    Query q = session.createQuery(sql);
2015    
2016                                    QueryPos qPos = QueryPos.getInstance(q);
2017    
2018                                    qPos.add(vocabularyId);
2019    
2020                                    list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2021                                                    start, end);
2022                            }
2023                            catch (Exception e) {
2024                                    throw processException(e);
2025                            }
2026                            finally {
2027                                    if (list == null) {
2028                                            list = new ArrayList<AssetCategory>();
2029                                    }
2030    
2031                                    cacheResult(list);
2032    
2033                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_VOCABULARYID,
2034                                            finderArgs, list);
2035    
2036                                    closeSession(session);
2037                            }
2038                    }
2039    
2040                    return list;
2041            }
2042    
2043            /**
2044             * Finds the first asset category in the ordered set where vocabularyId = &#63;.
2045             *
2046             * <p>
2047             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2048             * </p>
2049             *
2050             * @param vocabularyId the vocabulary id to search with
2051             * @param orderByComparator the comparator to order the set by
2052             * @return the first matching asset category
2053             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
2054             * @throws SystemException if a system exception occurred
2055             */
2056            public AssetCategory findByVocabularyId_First(long vocabularyId,
2057                    OrderByComparator orderByComparator)
2058                    throws NoSuchCategoryException, SystemException {
2059                    List<AssetCategory> list = findByVocabularyId(vocabularyId, 0, 1,
2060                                    orderByComparator);
2061    
2062                    if (list.isEmpty()) {
2063                            StringBundler msg = new StringBundler(4);
2064    
2065                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2066    
2067                            msg.append("vocabularyId=");
2068                            msg.append(vocabularyId);
2069    
2070                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2071    
2072                            throw new NoSuchCategoryException(msg.toString());
2073                    }
2074                    else {
2075                            return list.get(0);
2076                    }
2077            }
2078    
2079            /**
2080             * Finds the last asset category in the ordered set where vocabularyId = &#63;.
2081             *
2082             * <p>
2083             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2084             * </p>
2085             *
2086             * @param vocabularyId the vocabulary id to search with
2087             * @param orderByComparator the comparator to order the set by
2088             * @return the last matching asset category
2089             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
2090             * @throws SystemException if a system exception occurred
2091             */
2092            public AssetCategory findByVocabularyId_Last(long vocabularyId,
2093                    OrderByComparator orderByComparator)
2094                    throws NoSuchCategoryException, SystemException {
2095                    int count = countByVocabularyId(vocabularyId);
2096    
2097                    List<AssetCategory> list = findByVocabularyId(vocabularyId, count - 1,
2098                                    count, orderByComparator);
2099    
2100                    if (list.isEmpty()) {
2101                            StringBundler msg = new StringBundler(4);
2102    
2103                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2104    
2105                            msg.append("vocabularyId=");
2106                            msg.append(vocabularyId);
2107    
2108                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2109    
2110                            throw new NoSuchCategoryException(msg.toString());
2111                    }
2112                    else {
2113                            return list.get(0);
2114                    }
2115            }
2116    
2117            /**
2118             * Finds the asset categories before and after the current asset category in the ordered set where vocabularyId = &#63;.
2119             *
2120             * <p>
2121             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2122             * </p>
2123             *
2124             * @param categoryId the primary key of the current asset category
2125             * @param vocabularyId the vocabulary id to search with
2126             * @param orderByComparator the comparator to order the set by
2127             * @return the previous, current, and next asset category
2128             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
2129             * @throws SystemException if a system exception occurred
2130             */
2131            public AssetCategory[] findByVocabularyId_PrevAndNext(long categoryId,
2132                    long vocabularyId, OrderByComparator orderByComparator)
2133                    throws NoSuchCategoryException, SystemException {
2134                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
2135    
2136                    Session session = null;
2137    
2138                    try {
2139                            session = openSession();
2140    
2141                            AssetCategory[] array = new AssetCategoryImpl[3];
2142    
2143                            array[0] = getByVocabularyId_PrevAndNext(session, assetCategory,
2144                                            vocabularyId, orderByComparator, true);
2145    
2146                            array[1] = assetCategory;
2147    
2148                            array[2] = getByVocabularyId_PrevAndNext(session, assetCategory,
2149                                            vocabularyId, orderByComparator, false);
2150    
2151                            return array;
2152                    }
2153                    catch (Exception e) {
2154                            throw processException(e);
2155                    }
2156                    finally {
2157                            closeSession(session);
2158                    }
2159            }
2160    
2161            protected AssetCategory getByVocabularyId_PrevAndNext(Session session,
2162                    AssetCategory assetCategory, long vocabularyId,
2163                    OrderByComparator orderByComparator, boolean previous) {
2164                    StringBundler query = null;
2165    
2166                    if (orderByComparator != null) {
2167                            query = new StringBundler(6 +
2168                                            (orderByComparator.getOrderByFields().length * 6));
2169                    }
2170                    else {
2171                            query = new StringBundler(3);
2172                    }
2173    
2174                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2175    
2176                    query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
2177    
2178                    if (orderByComparator != null) {
2179                            String[] orderByFields = orderByComparator.getOrderByFields();
2180    
2181                            if (orderByFields.length > 0) {
2182                                    query.append(WHERE_AND);
2183                            }
2184    
2185                            for (int i = 0; i < orderByFields.length; i++) {
2186                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2187                                    query.append(orderByFields[i]);
2188    
2189                                    if ((i + 1) < orderByFields.length) {
2190                                            if (orderByComparator.isAscending() ^ previous) {
2191                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2192                                            }
2193                                            else {
2194                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2195                                            }
2196                                    }
2197                                    else {
2198                                            if (orderByComparator.isAscending() ^ previous) {
2199                                                    query.append(WHERE_GREATER_THAN);
2200                                            }
2201                                            else {
2202                                                    query.append(WHERE_LESSER_THAN);
2203                                            }
2204                                    }
2205                            }
2206    
2207                            query.append(ORDER_BY_CLAUSE);
2208    
2209                            for (int i = 0; i < orderByFields.length; i++) {
2210                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2211                                    query.append(orderByFields[i]);
2212    
2213                                    if ((i + 1) < orderByFields.length) {
2214                                            if (orderByComparator.isAscending() ^ previous) {
2215                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2216                                            }
2217                                            else {
2218                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2219                                            }
2220                                    }
2221                                    else {
2222                                            if (orderByComparator.isAscending() ^ previous) {
2223                                                    query.append(ORDER_BY_ASC);
2224                                            }
2225                                            else {
2226                                                    query.append(ORDER_BY_DESC);
2227                                            }
2228                                    }
2229                            }
2230                    }
2231    
2232                    else {
2233                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2234                    }
2235    
2236                    String sql = query.toString();
2237    
2238                    Query q = session.createQuery(sql);
2239    
2240                    q.setFirstResult(0);
2241                    q.setMaxResults(2);
2242    
2243                    QueryPos qPos = QueryPos.getInstance(q);
2244    
2245                    qPos.add(vocabularyId);
2246    
2247                    if (orderByComparator != null) {
2248                            Object[] values = orderByComparator.getOrderByValues(assetCategory);
2249    
2250                            for (Object value : values) {
2251                                    qPos.add(value);
2252                            }
2253                    }
2254    
2255                    List<AssetCategory> list = q.list();
2256    
2257                    if (list.size() == 2) {
2258                            return list.get(1);
2259                    }
2260                    else {
2261                            return null;
2262                    }
2263            }
2264    
2265            /**
2266             * Finds all the asset categories where parentCategoryId = &#63; and name = &#63;.
2267             *
2268             * @param parentCategoryId the parent category id to search with
2269             * @param name the name to search with
2270             * @return the matching asset categories
2271             * @throws SystemException if a system exception occurred
2272             */
2273            public List<AssetCategory> findByP_N(long parentCategoryId, String name)
2274                    throws SystemException {
2275                    return findByP_N(parentCategoryId, name, QueryUtil.ALL_POS,
2276                            QueryUtil.ALL_POS, null);
2277            }
2278    
2279            /**
2280             * Finds a range of all the asset categories where parentCategoryId = &#63; and name = &#63;.
2281             *
2282             * <p>
2283             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2284             * </p>
2285             *
2286             * @param parentCategoryId the parent category id to search with
2287             * @param name the name to search with
2288             * @param start the lower bound of the range of asset categories to return
2289             * @param end the upper bound of the range of asset categories to return (not inclusive)
2290             * @return the range of matching asset categories
2291             * @throws SystemException if a system exception occurred
2292             */
2293            public List<AssetCategory> findByP_N(long parentCategoryId, String name,
2294                    int start, int end) throws SystemException {
2295                    return findByP_N(parentCategoryId, name, start, end, null);
2296            }
2297    
2298            /**
2299             * Finds an ordered range of all the asset categories where parentCategoryId = &#63; and name = &#63;.
2300             *
2301             * <p>
2302             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2303             * </p>
2304             *
2305             * @param parentCategoryId the parent category id to search with
2306             * @param name the name to search with
2307             * @param start the lower bound of the range of asset categories to return
2308             * @param end the upper bound of the range of asset categories to return (not inclusive)
2309             * @param orderByComparator the comparator to order the results by
2310             * @return the ordered range of matching asset categories
2311             * @throws SystemException if a system exception occurred
2312             */
2313            public List<AssetCategory> findByP_N(long parentCategoryId, String name,
2314                    int start, int end, OrderByComparator orderByComparator)
2315                    throws SystemException {
2316                    Object[] finderArgs = new Object[] {
2317                                    parentCategoryId, name,
2318                                    
2319                                    String.valueOf(start), String.valueOf(end),
2320                                    String.valueOf(orderByComparator)
2321                            };
2322    
2323                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_P_N,
2324                                    finderArgs, this);
2325    
2326                    if (list == null) {
2327                            Session session = null;
2328    
2329                            try {
2330                                    session = openSession();
2331    
2332                                    StringBundler query = null;
2333    
2334                                    if (orderByComparator != null) {
2335                                            query = new StringBundler(4 +
2336                                                            (orderByComparator.getOrderByFields().length * 3));
2337                                    }
2338                                    else {
2339                                            query = new StringBundler(4);
2340                                    }
2341    
2342                                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2343    
2344                                    query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
2345    
2346                                    if (name == null) {
2347                                            query.append(_FINDER_COLUMN_P_N_NAME_1);
2348                                    }
2349                                    else {
2350                                            if (name.equals(StringPool.BLANK)) {
2351                                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
2352                                            }
2353                                            else {
2354                                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
2355                                            }
2356                                    }
2357    
2358                                    if (orderByComparator != null) {
2359                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2360                                                    orderByComparator);
2361                                    }
2362    
2363                                    else {
2364                                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2365                                    }
2366    
2367                                    String sql = query.toString();
2368    
2369                                    Query q = session.createQuery(sql);
2370    
2371                                    QueryPos qPos = QueryPos.getInstance(q);
2372    
2373                                    qPos.add(parentCategoryId);
2374    
2375                                    if (name != null) {
2376                                            qPos.add(name);
2377                                    }
2378    
2379                                    list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2380                                                    start, end);
2381                            }
2382                            catch (Exception e) {
2383                                    throw processException(e);
2384                            }
2385                            finally {
2386                                    if (list == null) {
2387                                            list = new ArrayList<AssetCategory>();
2388                                    }
2389    
2390                                    cacheResult(list);
2391    
2392                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_P_N, finderArgs,
2393                                            list);
2394    
2395                                    closeSession(session);
2396                            }
2397                    }
2398    
2399                    return list;
2400            }
2401    
2402            /**
2403             * Finds the first asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
2404             *
2405             * <p>
2406             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2407             * </p>
2408             *
2409             * @param parentCategoryId the parent category id to search with
2410             * @param name the name to search with
2411             * @param orderByComparator the comparator to order the set by
2412             * @return the first matching asset category
2413             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
2414             * @throws SystemException if a system exception occurred
2415             */
2416            public AssetCategory findByP_N_First(long parentCategoryId, String name,
2417                    OrderByComparator orderByComparator)
2418                    throws NoSuchCategoryException, SystemException {
2419                    List<AssetCategory> list = findByP_N(parentCategoryId, name, 0, 1,
2420                                    orderByComparator);
2421    
2422                    if (list.isEmpty()) {
2423                            StringBundler msg = new StringBundler(6);
2424    
2425                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2426    
2427                            msg.append("parentCategoryId=");
2428                            msg.append(parentCategoryId);
2429    
2430                            msg.append(", name=");
2431                            msg.append(name);
2432    
2433                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2434    
2435                            throw new NoSuchCategoryException(msg.toString());
2436                    }
2437                    else {
2438                            return list.get(0);
2439                    }
2440            }
2441    
2442            /**
2443             * Finds the last asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
2444             *
2445             * <p>
2446             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2447             * </p>
2448             *
2449             * @param parentCategoryId the parent category id to search with
2450             * @param name the name to search with
2451             * @param orderByComparator the comparator to order the set by
2452             * @return the last matching asset category
2453             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
2454             * @throws SystemException if a system exception occurred
2455             */
2456            public AssetCategory findByP_N_Last(long parentCategoryId, String name,
2457                    OrderByComparator orderByComparator)
2458                    throws NoSuchCategoryException, SystemException {
2459                    int count = countByP_N(parentCategoryId, name);
2460    
2461                    List<AssetCategory> list = findByP_N(parentCategoryId, name, count - 1,
2462                                    count, orderByComparator);
2463    
2464                    if (list.isEmpty()) {
2465                            StringBundler msg = new StringBundler(6);
2466    
2467                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2468    
2469                            msg.append("parentCategoryId=");
2470                            msg.append(parentCategoryId);
2471    
2472                            msg.append(", name=");
2473                            msg.append(name);
2474    
2475                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2476    
2477                            throw new NoSuchCategoryException(msg.toString());
2478                    }
2479                    else {
2480                            return list.get(0);
2481                    }
2482            }
2483    
2484            /**
2485             * Finds the asset categories before and after the current asset category in the ordered set where parentCategoryId = &#63; and name = &#63;.
2486             *
2487             * <p>
2488             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2489             * </p>
2490             *
2491             * @param categoryId the primary key of the current asset category
2492             * @param parentCategoryId the parent category id to search with
2493             * @param name the name to search with
2494             * @param orderByComparator the comparator to order the set by
2495             * @return the previous, current, and next asset category
2496             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
2497             * @throws SystemException if a system exception occurred
2498             */
2499            public AssetCategory[] findByP_N_PrevAndNext(long categoryId,
2500                    long parentCategoryId, String name, OrderByComparator orderByComparator)
2501                    throws NoSuchCategoryException, SystemException {
2502                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
2503    
2504                    Session session = null;
2505    
2506                    try {
2507                            session = openSession();
2508    
2509                            AssetCategory[] array = new AssetCategoryImpl[3];
2510    
2511                            array[0] = getByP_N_PrevAndNext(session, assetCategory,
2512                                            parentCategoryId, name, orderByComparator, true);
2513    
2514                            array[1] = assetCategory;
2515    
2516                            array[2] = getByP_N_PrevAndNext(session, assetCategory,
2517                                            parentCategoryId, name, orderByComparator, false);
2518    
2519                            return array;
2520                    }
2521                    catch (Exception e) {
2522                            throw processException(e);
2523                    }
2524                    finally {
2525                            closeSession(session);
2526                    }
2527            }
2528    
2529            protected AssetCategory getByP_N_PrevAndNext(Session session,
2530                    AssetCategory assetCategory, long parentCategoryId, String name,
2531                    OrderByComparator orderByComparator, boolean previous) {
2532                    StringBundler query = null;
2533    
2534                    if (orderByComparator != null) {
2535                            query = new StringBundler(6 +
2536                                            (orderByComparator.getOrderByFields().length * 6));
2537                    }
2538                    else {
2539                            query = new StringBundler(3);
2540                    }
2541    
2542                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2543    
2544                    query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
2545    
2546                    if (name == null) {
2547                            query.append(_FINDER_COLUMN_P_N_NAME_1);
2548                    }
2549                    else {
2550                            if (name.equals(StringPool.BLANK)) {
2551                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
2552                            }
2553                            else {
2554                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
2555                            }
2556                    }
2557    
2558                    if (orderByComparator != null) {
2559                            String[] orderByFields = orderByComparator.getOrderByFields();
2560    
2561                            if (orderByFields.length > 0) {
2562                                    query.append(WHERE_AND);
2563                            }
2564    
2565                            for (int i = 0; i < orderByFields.length; i++) {
2566                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2567                                    query.append(orderByFields[i]);
2568    
2569                                    if ((i + 1) < orderByFields.length) {
2570                                            if (orderByComparator.isAscending() ^ previous) {
2571                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2572                                            }
2573                                            else {
2574                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2575                                            }
2576                                    }
2577                                    else {
2578                                            if (orderByComparator.isAscending() ^ previous) {
2579                                                    query.append(WHERE_GREATER_THAN);
2580                                            }
2581                                            else {
2582                                                    query.append(WHERE_LESSER_THAN);
2583                                            }
2584                                    }
2585                            }
2586    
2587                            query.append(ORDER_BY_CLAUSE);
2588    
2589                            for (int i = 0; i < orderByFields.length; i++) {
2590                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2591                                    query.append(orderByFields[i]);
2592    
2593                                    if ((i + 1) < orderByFields.length) {
2594                                            if (orderByComparator.isAscending() ^ previous) {
2595                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2596                                            }
2597                                            else {
2598                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2599                                            }
2600                                    }
2601                                    else {
2602                                            if (orderByComparator.isAscending() ^ previous) {
2603                                                    query.append(ORDER_BY_ASC);
2604                                            }
2605                                            else {
2606                                                    query.append(ORDER_BY_DESC);
2607                                            }
2608                                    }
2609                            }
2610                    }
2611    
2612                    else {
2613                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2614                    }
2615    
2616                    String sql = query.toString();
2617    
2618                    Query q = session.createQuery(sql);
2619    
2620                    q.setFirstResult(0);
2621                    q.setMaxResults(2);
2622    
2623                    QueryPos qPos = QueryPos.getInstance(q);
2624    
2625                    qPos.add(parentCategoryId);
2626    
2627                    if (name != null) {
2628                            qPos.add(name);
2629                    }
2630    
2631                    if (orderByComparator != null) {
2632                            Object[] values = orderByComparator.getOrderByValues(assetCategory);
2633    
2634                            for (Object value : values) {
2635                                    qPos.add(value);
2636                            }
2637                    }
2638    
2639                    List<AssetCategory> list = q.list();
2640    
2641                    if (list.size() == 2) {
2642                            return list.get(1);
2643                    }
2644                    else {
2645                            return null;
2646                    }
2647            }
2648    
2649            /**
2650             * Finds all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
2651             *
2652             * @param parentCategoryId the parent category id to search with
2653             * @param vocabularyId the vocabulary id to search with
2654             * @return the matching asset categories
2655             * @throws SystemException if a system exception occurred
2656             */
2657            public List<AssetCategory> findByP_V(long parentCategoryId,
2658                    long vocabularyId) throws SystemException {
2659                    return findByP_V(parentCategoryId, vocabularyId, QueryUtil.ALL_POS,
2660                            QueryUtil.ALL_POS, null);
2661            }
2662    
2663            /**
2664             * Finds a range of all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
2665             *
2666             * <p>
2667             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2668             * </p>
2669             *
2670             * @param parentCategoryId the parent category id to search with
2671             * @param vocabularyId the vocabulary id to search with
2672             * @param start the lower bound of the range of asset categories to return
2673             * @param end the upper bound of the range of asset categories to return (not inclusive)
2674             * @return the range of matching asset categories
2675             * @throws SystemException if a system exception occurred
2676             */
2677            public List<AssetCategory> findByP_V(long parentCategoryId,
2678                    long vocabularyId, int start, int end) throws SystemException {
2679                    return findByP_V(parentCategoryId, vocabularyId, start, end, null);
2680            }
2681    
2682            /**
2683             * Finds an ordered range of all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
2684             *
2685             * <p>
2686             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2687             * </p>
2688             *
2689             * @param parentCategoryId the parent category id to search with
2690             * @param vocabularyId the vocabulary id to search with
2691             * @param start the lower bound of the range of asset categories to return
2692             * @param end the upper bound of the range of asset categories to return (not inclusive)
2693             * @param orderByComparator the comparator to order the results by
2694             * @return the ordered range of matching asset categories
2695             * @throws SystemException if a system exception occurred
2696             */
2697            public List<AssetCategory> findByP_V(long parentCategoryId,
2698                    long vocabularyId, int start, int end,
2699                    OrderByComparator orderByComparator) throws SystemException {
2700                    Object[] finderArgs = new Object[] {
2701                                    parentCategoryId, vocabularyId,
2702                                    
2703                                    String.valueOf(start), String.valueOf(end),
2704                                    String.valueOf(orderByComparator)
2705                            };
2706    
2707                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_P_V,
2708                                    finderArgs, this);
2709    
2710                    if (list == null) {
2711                            Session session = null;
2712    
2713                            try {
2714                                    session = openSession();
2715    
2716                                    StringBundler query = null;
2717    
2718                                    if (orderByComparator != null) {
2719                                            query = new StringBundler(4 +
2720                                                            (orderByComparator.getOrderByFields().length * 3));
2721                                    }
2722                                    else {
2723                                            query = new StringBundler(4);
2724                                    }
2725    
2726                                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2727    
2728                                    query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
2729    
2730                                    query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
2731    
2732                                    if (orderByComparator != null) {
2733                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2734                                                    orderByComparator);
2735                                    }
2736    
2737                                    else {
2738                                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2739                                    }
2740    
2741                                    String sql = query.toString();
2742    
2743                                    Query q = session.createQuery(sql);
2744    
2745                                    QueryPos qPos = QueryPos.getInstance(q);
2746    
2747                                    qPos.add(parentCategoryId);
2748    
2749                                    qPos.add(vocabularyId);
2750    
2751                                    list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
2752                                                    start, end);
2753                            }
2754                            catch (Exception e) {
2755                                    throw processException(e);
2756                            }
2757                            finally {
2758                                    if (list == null) {
2759                                            list = new ArrayList<AssetCategory>();
2760                                    }
2761    
2762                                    cacheResult(list);
2763    
2764                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_P_V, finderArgs,
2765                                            list);
2766    
2767                                    closeSession(session);
2768                            }
2769                    }
2770    
2771                    return list;
2772            }
2773    
2774            /**
2775             * Finds the first asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
2776             *
2777             * <p>
2778             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2779             * </p>
2780             *
2781             * @param parentCategoryId the parent category id to search with
2782             * @param vocabularyId the vocabulary id to search with
2783             * @param orderByComparator the comparator to order the set by
2784             * @return the first matching asset category
2785             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
2786             * @throws SystemException if a system exception occurred
2787             */
2788            public AssetCategory findByP_V_First(long parentCategoryId,
2789                    long vocabularyId, OrderByComparator orderByComparator)
2790                    throws NoSuchCategoryException, SystemException {
2791                    List<AssetCategory> list = findByP_V(parentCategoryId, vocabularyId, 0,
2792                                    1, orderByComparator);
2793    
2794                    if (list.isEmpty()) {
2795                            StringBundler msg = new StringBundler(6);
2796    
2797                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2798    
2799                            msg.append("parentCategoryId=");
2800                            msg.append(parentCategoryId);
2801    
2802                            msg.append(", vocabularyId=");
2803                            msg.append(vocabularyId);
2804    
2805                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2806    
2807                            throw new NoSuchCategoryException(msg.toString());
2808                    }
2809                    else {
2810                            return list.get(0);
2811                    }
2812            }
2813    
2814            /**
2815             * Finds the last asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
2816             *
2817             * <p>
2818             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2819             * </p>
2820             *
2821             * @param parentCategoryId the parent category id to search with
2822             * @param vocabularyId the vocabulary id to search with
2823             * @param orderByComparator the comparator to order the set by
2824             * @return the last matching asset category
2825             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
2826             * @throws SystemException if a system exception occurred
2827             */
2828            public AssetCategory findByP_V_Last(long parentCategoryId,
2829                    long vocabularyId, OrderByComparator orderByComparator)
2830                    throws NoSuchCategoryException, SystemException {
2831                    int count = countByP_V(parentCategoryId, vocabularyId);
2832    
2833                    List<AssetCategory> list = findByP_V(parentCategoryId, vocabularyId,
2834                                    count - 1, count, orderByComparator);
2835    
2836                    if (list.isEmpty()) {
2837                            StringBundler msg = new StringBundler(6);
2838    
2839                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2840    
2841                            msg.append("parentCategoryId=");
2842                            msg.append(parentCategoryId);
2843    
2844                            msg.append(", vocabularyId=");
2845                            msg.append(vocabularyId);
2846    
2847                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2848    
2849                            throw new NoSuchCategoryException(msg.toString());
2850                    }
2851                    else {
2852                            return list.get(0);
2853                    }
2854            }
2855    
2856            /**
2857             * Finds the asset categories before and after the current asset category in the ordered set where parentCategoryId = &#63; and vocabularyId = &#63;.
2858             *
2859             * <p>
2860             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2861             * </p>
2862             *
2863             * @param categoryId the primary key of the current asset category
2864             * @param parentCategoryId the parent category id to search with
2865             * @param vocabularyId the vocabulary id to search with
2866             * @param orderByComparator the comparator to order the set by
2867             * @return the previous, current, and next asset category
2868             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
2869             * @throws SystemException if a system exception occurred
2870             */
2871            public AssetCategory[] findByP_V_PrevAndNext(long categoryId,
2872                    long parentCategoryId, long vocabularyId,
2873                    OrderByComparator orderByComparator)
2874                    throws NoSuchCategoryException, SystemException {
2875                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
2876    
2877                    Session session = null;
2878    
2879                    try {
2880                            session = openSession();
2881    
2882                            AssetCategory[] array = new AssetCategoryImpl[3];
2883    
2884                            array[0] = getByP_V_PrevAndNext(session, assetCategory,
2885                                            parentCategoryId, vocabularyId, orderByComparator, true);
2886    
2887                            array[1] = assetCategory;
2888    
2889                            array[2] = getByP_V_PrevAndNext(session, assetCategory,
2890                                            parentCategoryId, vocabularyId, orderByComparator, false);
2891    
2892                            return array;
2893                    }
2894                    catch (Exception e) {
2895                            throw processException(e);
2896                    }
2897                    finally {
2898                            closeSession(session);
2899                    }
2900            }
2901    
2902            protected AssetCategory getByP_V_PrevAndNext(Session session,
2903                    AssetCategory assetCategory, long parentCategoryId, long vocabularyId,
2904                    OrderByComparator orderByComparator, boolean previous) {
2905                    StringBundler query = null;
2906    
2907                    if (orderByComparator != null) {
2908                            query = new StringBundler(6 +
2909                                            (orderByComparator.getOrderByFields().length * 6));
2910                    }
2911                    else {
2912                            query = new StringBundler(3);
2913                    }
2914    
2915                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
2916    
2917                    query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
2918    
2919                    query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
2920    
2921                    if (orderByComparator != null) {
2922                            String[] orderByFields = orderByComparator.getOrderByFields();
2923    
2924                            if (orderByFields.length > 0) {
2925                                    query.append(WHERE_AND);
2926                            }
2927    
2928                            for (int i = 0; i < orderByFields.length; i++) {
2929                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2930                                    query.append(orderByFields[i]);
2931    
2932                                    if ((i + 1) < orderByFields.length) {
2933                                            if (orderByComparator.isAscending() ^ previous) {
2934                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2935                                            }
2936                                            else {
2937                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2938                                            }
2939                                    }
2940                                    else {
2941                                            if (orderByComparator.isAscending() ^ previous) {
2942                                                    query.append(WHERE_GREATER_THAN);
2943                                            }
2944                                            else {
2945                                                    query.append(WHERE_LESSER_THAN);
2946                                            }
2947                                    }
2948                            }
2949    
2950                            query.append(ORDER_BY_CLAUSE);
2951    
2952                            for (int i = 0; i < orderByFields.length; i++) {
2953                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2954                                    query.append(orderByFields[i]);
2955    
2956                                    if ((i + 1) < orderByFields.length) {
2957                                            if (orderByComparator.isAscending() ^ previous) {
2958                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2959                                            }
2960                                            else {
2961                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2962                                            }
2963                                    }
2964                                    else {
2965                                            if (orderByComparator.isAscending() ^ previous) {
2966                                                    query.append(ORDER_BY_ASC);
2967                                            }
2968                                            else {
2969                                                    query.append(ORDER_BY_DESC);
2970                                            }
2971                                    }
2972                            }
2973                    }
2974    
2975                    else {
2976                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
2977                    }
2978    
2979                    String sql = query.toString();
2980    
2981                    Query q = session.createQuery(sql);
2982    
2983                    q.setFirstResult(0);
2984                    q.setMaxResults(2);
2985    
2986                    QueryPos qPos = QueryPos.getInstance(q);
2987    
2988                    qPos.add(parentCategoryId);
2989    
2990                    qPos.add(vocabularyId);
2991    
2992                    if (orderByComparator != null) {
2993                            Object[] values = orderByComparator.getOrderByValues(assetCategory);
2994    
2995                            for (Object value : values) {
2996                                    qPos.add(value);
2997                            }
2998                    }
2999    
3000                    List<AssetCategory> list = q.list();
3001    
3002                    if (list.size() == 2) {
3003                            return list.get(1);
3004                    }
3005                    else {
3006                            return null;
3007                    }
3008            }
3009    
3010            /**
3011             * Finds all the asset categories where name = &#63; and vocabularyId = &#63;.
3012             *
3013             * @param name the name to search with
3014             * @param vocabularyId the vocabulary id to search with
3015             * @return the matching asset categories
3016             * @throws SystemException if a system exception occurred
3017             */
3018            public List<AssetCategory> findByN_V(String name, long vocabularyId)
3019                    throws SystemException {
3020                    return findByN_V(name, vocabularyId, QueryUtil.ALL_POS,
3021                            QueryUtil.ALL_POS, null);
3022            }
3023    
3024            /**
3025             * Finds a range of all the asset categories where name = &#63; and vocabularyId = &#63;.
3026             *
3027             * <p>
3028             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3029             * </p>
3030             *
3031             * @param name the name to search with
3032             * @param vocabularyId the vocabulary id to search with
3033             * @param start the lower bound of the range of asset categories to return
3034             * @param end the upper bound of the range of asset categories to return (not inclusive)
3035             * @return the range of matching asset categories
3036             * @throws SystemException if a system exception occurred
3037             */
3038            public List<AssetCategory> findByN_V(String name, long vocabularyId,
3039                    int start, int end) throws SystemException {
3040                    return findByN_V(name, vocabularyId, start, end, null);
3041            }
3042    
3043            /**
3044             * Finds an ordered range of all the asset categories where name = &#63; and vocabularyId = &#63;.
3045             *
3046             * <p>
3047             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3048             * </p>
3049             *
3050             * @param name the name to search with
3051             * @param vocabularyId the vocabulary id to search with
3052             * @param start the lower bound of the range of asset categories to return
3053             * @param end the upper bound of the range of asset categories to return (not inclusive)
3054             * @param orderByComparator the comparator to order the results by
3055             * @return the ordered range of matching asset categories
3056             * @throws SystemException if a system exception occurred
3057             */
3058            public List<AssetCategory> findByN_V(String name, long vocabularyId,
3059                    int start, int end, OrderByComparator orderByComparator)
3060                    throws SystemException {
3061                    Object[] finderArgs = new Object[] {
3062                                    name, vocabularyId,
3063                                    
3064                                    String.valueOf(start), String.valueOf(end),
3065                                    String.valueOf(orderByComparator)
3066                            };
3067    
3068                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_N_V,
3069                                    finderArgs, this);
3070    
3071                    if (list == null) {
3072                            Session session = null;
3073    
3074                            try {
3075                                    session = openSession();
3076    
3077                                    StringBundler query = null;
3078    
3079                                    if (orderByComparator != null) {
3080                                            query = new StringBundler(4 +
3081                                                            (orderByComparator.getOrderByFields().length * 3));
3082                                    }
3083                                    else {
3084                                            query = new StringBundler(4);
3085                                    }
3086    
3087                                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3088    
3089                                    if (name == null) {
3090                                            query.append(_FINDER_COLUMN_N_V_NAME_1);
3091                                    }
3092                                    else {
3093                                            if (name.equals(StringPool.BLANK)) {
3094                                                    query.append(_FINDER_COLUMN_N_V_NAME_3);
3095                                            }
3096                                            else {
3097                                                    query.append(_FINDER_COLUMN_N_V_NAME_2);
3098                                            }
3099                                    }
3100    
3101                                    query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
3102    
3103                                    if (orderByComparator != null) {
3104                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3105                                                    orderByComparator);
3106                                    }
3107    
3108                                    else {
3109                                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3110                                    }
3111    
3112                                    String sql = query.toString();
3113    
3114                                    Query q = session.createQuery(sql);
3115    
3116                                    QueryPos qPos = QueryPos.getInstance(q);
3117    
3118                                    if (name != null) {
3119                                            qPos.add(name);
3120                                    }
3121    
3122                                    qPos.add(vocabularyId);
3123    
3124                                    list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3125                                                    start, end);
3126                            }
3127                            catch (Exception e) {
3128                                    throw processException(e);
3129                            }
3130                            finally {
3131                                    if (list == null) {
3132                                            list = new ArrayList<AssetCategory>();
3133                                    }
3134    
3135                                    cacheResult(list);
3136    
3137                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_N_V, finderArgs,
3138                                            list);
3139    
3140                                    closeSession(session);
3141                            }
3142                    }
3143    
3144                    return list;
3145            }
3146    
3147            /**
3148             * Finds the first asset category in the ordered set where name = &#63; and vocabularyId = &#63;.
3149             *
3150             * <p>
3151             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3152             * </p>
3153             *
3154             * @param name the name to search with
3155             * @param vocabularyId the vocabulary id to search with
3156             * @param orderByComparator the comparator to order the set by
3157             * @return the first matching asset category
3158             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
3159             * @throws SystemException if a system exception occurred
3160             */
3161            public AssetCategory findByN_V_First(String name, long vocabularyId,
3162                    OrderByComparator orderByComparator)
3163                    throws NoSuchCategoryException, SystemException {
3164                    List<AssetCategory> list = findByN_V(name, vocabularyId, 0, 1,
3165                                    orderByComparator);
3166    
3167                    if (list.isEmpty()) {
3168                            StringBundler msg = new StringBundler(6);
3169    
3170                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3171    
3172                            msg.append("name=");
3173                            msg.append(name);
3174    
3175                            msg.append(", vocabularyId=");
3176                            msg.append(vocabularyId);
3177    
3178                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3179    
3180                            throw new NoSuchCategoryException(msg.toString());
3181                    }
3182                    else {
3183                            return list.get(0);
3184                    }
3185            }
3186    
3187            /**
3188             * Finds the last asset category in the ordered set where name = &#63; and vocabularyId = &#63;.
3189             *
3190             * <p>
3191             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3192             * </p>
3193             *
3194             * @param name the name to search with
3195             * @param vocabularyId the vocabulary id to search with
3196             * @param orderByComparator the comparator to order the set by
3197             * @return the last matching asset category
3198             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
3199             * @throws SystemException if a system exception occurred
3200             */
3201            public AssetCategory findByN_V_Last(String name, long vocabularyId,
3202                    OrderByComparator orderByComparator)
3203                    throws NoSuchCategoryException, SystemException {
3204                    int count = countByN_V(name, vocabularyId);
3205    
3206                    List<AssetCategory> list = findByN_V(name, vocabularyId, count - 1,
3207                                    count, orderByComparator);
3208    
3209                    if (list.isEmpty()) {
3210                            StringBundler msg = new StringBundler(6);
3211    
3212                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3213    
3214                            msg.append("name=");
3215                            msg.append(name);
3216    
3217                            msg.append(", vocabularyId=");
3218                            msg.append(vocabularyId);
3219    
3220                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3221    
3222                            throw new NoSuchCategoryException(msg.toString());
3223                    }
3224                    else {
3225                            return list.get(0);
3226                    }
3227            }
3228    
3229            /**
3230             * Finds the asset categories before and after the current asset category in the ordered set where name = &#63; and vocabularyId = &#63;.
3231             *
3232             * <p>
3233             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3234             * </p>
3235             *
3236             * @param categoryId the primary key of the current asset category
3237             * @param name the name to search with
3238             * @param vocabularyId the vocabulary id to search with
3239             * @param orderByComparator the comparator to order the set by
3240             * @return the previous, current, and next asset category
3241             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a asset category with the primary key could not be found
3242             * @throws SystemException if a system exception occurred
3243             */
3244            public AssetCategory[] findByN_V_PrevAndNext(long categoryId, String name,
3245                    long vocabularyId, OrderByComparator orderByComparator)
3246                    throws NoSuchCategoryException, SystemException {
3247                    AssetCategory assetCategory = findByPrimaryKey(categoryId);
3248    
3249                    Session session = null;
3250    
3251                    try {
3252                            session = openSession();
3253    
3254                            AssetCategory[] array = new AssetCategoryImpl[3];
3255    
3256                            array[0] = getByN_V_PrevAndNext(session, assetCategory, name,
3257                                            vocabularyId, orderByComparator, true);
3258    
3259                            array[1] = assetCategory;
3260    
3261                            array[2] = getByN_V_PrevAndNext(session, assetCategory, name,
3262                                            vocabularyId, orderByComparator, false);
3263    
3264                            return array;
3265                    }
3266                    catch (Exception e) {
3267                            throw processException(e);
3268                    }
3269                    finally {
3270                            closeSession(session);
3271                    }
3272            }
3273    
3274            protected AssetCategory getByN_V_PrevAndNext(Session session,
3275                    AssetCategory assetCategory, String name, long vocabularyId,
3276                    OrderByComparator orderByComparator, boolean previous) {
3277                    StringBundler query = null;
3278    
3279                    if (orderByComparator != null) {
3280                            query = new StringBundler(6 +
3281                                            (orderByComparator.getOrderByFields().length * 6));
3282                    }
3283                    else {
3284                            query = new StringBundler(3);
3285                    }
3286    
3287                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3288    
3289                    if (name == null) {
3290                            query.append(_FINDER_COLUMN_N_V_NAME_1);
3291                    }
3292                    else {
3293                            if (name.equals(StringPool.BLANK)) {
3294                                    query.append(_FINDER_COLUMN_N_V_NAME_3);
3295                            }
3296                            else {
3297                                    query.append(_FINDER_COLUMN_N_V_NAME_2);
3298                            }
3299                    }
3300    
3301                    query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
3302    
3303                    if (orderByComparator != null) {
3304                            String[] orderByFields = orderByComparator.getOrderByFields();
3305    
3306                            if (orderByFields.length > 0) {
3307                                    query.append(WHERE_AND);
3308                            }
3309    
3310                            for (int i = 0; i < orderByFields.length; i++) {
3311                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3312                                    query.append(orderByFields[i]);
3313    
3314                                    if ((i + 1) < orderByFields.length) {
3315                                            if (orderByComparator.isAscending() ^ previous) {
3316                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3317                                            }
3318                                            else {
3319                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3320                                            }
3321                                    }
3322                                    else {
3323                                            if (orderByComparator.isAscending() ^ previous) {
3324                                                    query.append(WHERE_GREATER_THAN);
3325                                            }
3326                                            else {
3327                                                    query.append(WHERE_LESSER_THAN);
3328                                            }
3329                                    }
3330                            }
3331    
3332                            query.append(ORDER_BY_CLAUSE);
3333    
3334                            for (int i = 0; i < orderByFields.length; i++) {
3335                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3336                                    query.append(orderByFields[i]);
3337    
3338                                    if ((i + 1) < orderByFields.length) {
3339                                            if (orderByComparator.isAscending() ^ previous) {
3340                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3341                                            }
3342                                            else {
3343                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3344                                            }
3345                                    }
3346                                    else {
3347                                            if (orderByComparator.isAscending() ^ previous) {
3348                                                    query.append(ORDER_BY_ASC);
3349                                            }
3350                                            else {
3351                                                    query.append(ORDER_BY_DESC);
3352                                            }
3353                                    }
3354                            }
3355                    }
3356    
3357                    else {
3358                            query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3359                    }
3360    
3361                    String sql = query.toString();
3362    
3363                    Query q = session.createQuery(sql);
3364    
3365                    q.setFirstResult(0);
3366                    q.setMaxResults(2);
3367    
3368                    QueryPos qPos = QueryPos.getInstance(q);
3369    
3370                    if (name != null) {
3371                            qPos.add(name);
3372                    }
3373    
3374                    qPos.add(vocabularyId);
3375    
3376                    if (orderByComparator != null) {
3377                            Object[] values = orderByComparator.getOrderByValues(assetCategory);
3378    
3379                            for (Object value : values) {
3380                                    qPos.add(value);
3381                            }
3382                    }
3383    
3384                    List<AssetCategory> list = q.list();
3385    
3386                    if (list.size() == 2) {
3387                            return list.get(1);
3388                    }
3389                    else {
3390                            return null;
3391                    }
3392            }
3393    
3394            /**
3395             * Finds 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.
3396             *
3397             * @param parentCategoryId the parent category id to search with
3398             * @param name the name to search with
3399             * @param vocabularyId the vocabulary id to search with
3400             * @return the matching asset category
3401             * @throws com.liferay.portlet.asset.NoSuchCategoryException if a matching asset category could not be found
3402             * @throws SystemException if a system exception occurred
3403             */
3404            public AssetCategory findByP_N_V(long parentCategoryId, String name,
3405                    long vocabularyId) throws NoSuchCategoryException, SystemException {
3406                    AssetCategory assetCategory = fetchByP_N_V(parentCategoryId, name,
3407                                    vocabularyId);
3408    
3409                    if (assetCategory == null) {
3410                            StringBundler msg = new StringBundler(8);
3411    
3412                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3413    
3414                            msg.append("parentCategoryId=");
3415                            msg.append(parentCategoryId);
3416    
3417                            msg.append(", name=");
3418                            msg.append(name);
3419    
3420                            msg.append(", vocabularyId=");
3421                            msg.append(vocabularyId);
3422    
3423                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3424    
3425                            if (_log.isWarnEnabled()) {
3426                                    _log.warn(msg.toString());
3427                            }
3428    
3429                            throw new NoSuchCategoryException(msg.toString());
3430                    }
3431    
3432                    return assetCategory;
3433            }
3434    
3435            /**
3436             * Finds 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.
3437             *
3438             * @param parentCategoryId the parent category id to search with
3439             * @param name the name to search with
3440             * @param vocabularyId the vocabulary id to search with
3441             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
3442             * @throws SystemException if a system exception occurred
3443             */
3444            public AssetCategory fetchByP_N_V(long parentCategoryId, String name,
3445                    long vocabularyId) throws SystemException {
3446                    return fetchByP_N_V(parentCategoryId, name, vocabularyId, true);
3447            }
3448    
3449            /**
3450             * Finds 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.
3451             *
3452             * @param parentCategoryId the parent category id to search with
3453             * @param name the name to search with
3454             * @param vocabularyId the vocabulary id to search with
3455             * @return the matching asset category, or <code>null</code> if a matching asset category could not be found
3456             * @throws SystemException if a system exception occurred
3457             */
3458            public AssetCategory fetchByP_N_V(long parentCategoryId, String name,
3459                    long vocabularyId, boolean retrieveFromCache) throws SystemException {
3460                    Object[] finderArgs = new Object[] { parentCategoryId, name, vocabularyId };
3461    
3462                    Object result = null;
3463    
3464                    if (retrieveFromCache) {
3465                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_P_N_V,
3466                                            finderArgs, this);
3467                    }
3468    
3469                    if (result == null) {
3470                            Session session = null;
3471    
3472                            try {
3473                                    session = openSession();
3474    
3475                                    StringBundler query = new StringBundler(5);
3476    
3477                                    query.append(_SQL_SELECT_ASSETCATEGORY_WHERE);
3478    
3479                                    query.append(_FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2);
3480    
3481                                    if (name == null) {
3482                                            query.append(_FINDER_COLUMN_P_N_V_NAME_1);
3483                                    }
3484                                    else {
3485                                            if (name.equals(StringPool.BLANK)) {
3486                                                    query.append(_FINDER_COLUMN_P_N_V_NAME_3);
3487                                            }
3488                                            else {
3489                                                    query.append(_FINDER_COLUMN_P_N_V_NAME_2);
3490                                            }
3491                                    }
3492    
3493                                    query.append(_FINDER_COLUMN_P_N_V_VOCABULARYID_2);
3494    
3495                                    query.append(AssetCategoryModelImpl.ORDER_BY_JPQL);
3496    
3497                                    String sql = query.toString();
3498    
3499                                    Query q = session.createQuery(sql);
3500    
3501                                    QueryPos qPos = QueryPos.getInstance(q);
3502    
3503                                    qPos.add(parentCategoryId);
3504    
3505                                    if (name != null) {
3506                                            qPos.add(name);
3507                                    }
3508    
3509                                    qPos.add(vocabularyId);
3510    
3511                                    List<AssetCategory> list = q.list();
3512    
3513                                    result = list;
3514    
3515                                    AssetCategory assetCategory = null;
3516    
3517                                    if (list.isEmpty()) {
3518                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
3519                                                    finderArgs, list);
3520                                    }
3521                                    else {
3522                                            assetCategory = list.get(0);
3523    
3524                                            cacheResult(assetCategory);
3525    
3526                                            if ((assetCategory.getParentCategoryId() != parentCategoryId) ||
3527                                                            (assetCategory.getName() == null) ||
3528                                                            !assetCategory.getName().equals(name) ||
3529                                                            (assetCategory.getVocabularyId() != vocabularyId)) {
3530                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
3531                                                            finderArgs, assetCategory);
3532                                            }
3533                                    }
3534    
3535                                    return assetCategory;
3536                            }
3537                            catch (Exception e) {
3538                                    throw processException(e);
3539                            }
3540                            finally {
3541                                    if (result == null) {
3542                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_N_V,
3543                                                    finderArgs, new ArrayList<AssetCategory>());
3544                                    }
3545    
3546                                    closeSession(session);
3547                            }
3548                    }
3549                    else {
3550                            if (result instanceof List<?>) {
3551                                    return null;
3552                            }
3553                            else {
3554                                    return (AssetCategory)result;
3555                            }
3556                    }
3557            }
3558    
3559            /**
3560             * Finds all the asset categories.
3561             *
3562             * @return the asset categories
3563             * @throws SystemException if a system exception occurred
3564             */
3565            public List<AssetCategory> findAll() throws SystemException {
3566                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3567            }
3568    
3569            /**
3570             * Finds a range of all the asset categories.
3571             *
3572             * <p>
3573             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3574             * </p>
3575             *
3576             * @param start the lower bound of the range of asset categories to return
3577             * @param end the upper bound of the range of asset categories to return (not inclusive)
3578             * @return the range of asset categories
3579             * @throws SystemException if a system exception occurred
3580             */
3581            public List<AssetCategory> findAll(int start, int end)
3582                    throws SystemException {
3583                    return findAll(start, end, null);
3584            }
3585    
3586            /**
3587             * Finds an ordered range of all the asset categories.
3588             *
3589             * <p>
3590             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3591             * </p>
3592             *
3593             * @param start the lower bound of the range of asset categories to return
3594             * @param end the upper bound of the range of asset categories to return (not inclusive)
3595             * @param orderByComparator the comparator to order the results by
3596             * @return the ordered range of asset categories
3597             * @throws SystemException if a system exception occurred
3598             */
3599            public List<AssetCategory> findAll(int start, int end,
3600                    OrderByComparator orderByComparator) throws SystemException {
3601                    Object[] finderArgs = new Object[] {
3602                                    String.valueOf(start), String.valueOf(end),
3603                                    String.valueOf(orderByComparator)
3604                            };
3605    
3606                    List<AssetCategory> list = (List<AssetCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3607                                    finderArgs, this);
3608    
3609                    if (list == null) {
3610                            Session session = null;
3611    
3612                            try {
3613                                    session = openSession();
3614    
3615                                    StringBundler query = null;
3616                                    String sql = null;
3617    
3618                                    if (orderByComparator != null) {
3619                                            query = new StringBundler(2 +
3620                                                            (orderByComparator.getOrderByFields().length * 3));
3621    
3622                                            query.append(_SQL_SELECT_ASSETCATEGORY);
3623    
3624                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3625                                                    orderByComparator);
3626    
3627                                            sql = query.toString();
3628                                    }
3629                                    else {
3630                                            sql = _SQL_SELECT_ASSETCATEGORY.concat(AssetCategoryModelImpl.ORDER_BY_JPQL);
3631                                    }
3632    
3633                                    Query q = session.createQuery(sql);
3634    
3635                                    if (orderByComparator == null) {
3636                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3637                                                            start, end, false);
3638    
3639                                            Collections.sort(list);
3640                                    }
3641                                    else {
3642                                            list = (List<AssetCategory>)QueryUtil.list(q, getDialect(),
3643                                                            start, end);
3644                                    }
3645                            }
3646                            catch (Exception e) {
3647                                    throw processException(e);
3648                            }
3649                            finally {
3650                                    if (list == null) {
3651                                            list = new ArrayList<AssetCategory>();
3652                                    }
3653    
3654                                    cacheResult(list);
3655    
3656                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3657    
3658                                    closeSession(session);
3659                            }
3660                    }
3661    
3662                    return list;
3663            }
3664    
3665            /**
3666             * Removes all the asset categories where uuid = &#63; from the database.
3667             *
3668             * @param uuid the uuid to search with
3669             * @throws SystemException if a system exception occurred
3670             */
3671            public void removeByUuid(String uuid) throws SystemException {
3672                    for (AssetCategory assetCategory : findByUuid(uuid)) {
3673                            remove(assetCategory);
3674                    }
3675            }
3676    
3677            /**
3678             * Removes the asset category where uuid = &#63; and groupId = &#63; from the database.
3679             *
3680             * @param uuid the uuid to search with
3681             * @param groupId the group id to search with
3682             * @throws SystemException if a system exception occurred
3683             */
3684            public void removeByUUID_G(String uuid, long groupId)
3685                    throws NoSuchCategoryException, SystemException {
3686                    AssetCategory assetCategory = findByUUID_G(uuid, groupId);
3687    
3688                    remove(assetCategory);
3689            }
3690    
3691            /**
3692             * Removes all the asset categories where groupId = &#63; from the database.
3693             *
3694             * @param groupId the group id to search with
3695             * @throws SystemException if a system exception occurred
3696             */
3697            public void removeByGroupId(long groupId) throws SystemException {
3698                    for (AssetCategory assetCategory : findByGroupId(groupId)) {
3699                            remove(assetCategory);
3700                    }
3701            }
3702    
3703            /**
3704             * Removes all the asset categories where parentCategoryId = &#63; from the database.
3705             *
3706             * @param parentCategoryId the parent category id to search with
3707             * @throws SystemException if a system exception occurred
3708             */
3709            public void removeByParentCategoryId(long parentCategoryId)
3710                    throws SystemException {
3711                    for (AssetCategory assetCategory : findByParentCategoryId(
3712                                    parentCategoryId)) {
3713                            remove(assetCategory);
3714                    }
3715            }
3716    
3717            /**
3718             * Removes all the asset categories where vocabularyId = &#63; from the database.
3719             *
3720             * @param vocabularyId the vocabulary id to search with
3721             * @throws SystemException if a system exception occurred
3722             */
3723            public void removeByVocabularyId(long vocabularyId)
3724                    throws SystemException {
3725                    for (AssetCategory assetCategory : findByVocabularyId(vocabularyId)) {
3726                            remove(assetCategory);
3727                    }
3728            }
3729    
3730            /**
3731             * Removes all the asset categories where parentCategoryId = &#63; and name = &#63; from the database.
3732             *
3733             * @param parentCategoryId the parent category id to search with
3734             * @param name the name to search with
3735             * @throws SystemException if a system exception occurred
3736             */
3737            public void removeByP_N(long parentCategoryId, String name)
3738                    throws SystemException {
3739                    for (AssetCategory assetCategory : findByP_N(parentCategoryId, name)) {
3740                            remove(assetCategory);
3741                    }
3742            }
3743    
3744            /**
3745             * Removes all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63; from the database.
3746             *
3747             * @param parentCategoryId the parent category id to search with
3748             * @param vocabularyId the vocabulary id to search with
3749             * @throws SystemException if a system exception occurred
3750             */
3751            public void removeByP_V(long parentCategoryId, long vocabularyId)
3752                    throws SystemException {
3753                    for (AssetCategory assetCategory : findByP_V(parentCategoryId,
3754                                    vocabularyId)) {
3755                            remove(assetCategory);
3756                    }
3757            }
3758    
3759            /**
3760             * Removes all the asset categories where name = &#63; and vocabularyId = &#63; from the database.
3761             *
3762             * @param name the name to search with
3763             * @param vocabularyId the vocabulary id to search with
3764             * @throws SystemException if a system exception occurred
3765             */
3766            public void removeByN_V(String name, long vocabularyId)
3767                    throws SystemException {
3768                    for (AssetCategory assetCategory : findByN_V(name, vocabularyId)) {
3769                            remove(assetCategory);
3770                    }
3771            }
3772    
3773            /**
3774             * Removes the asset category where parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63; from the database.
3775             *
3776             * @param parentCategoryId the parent category id to search with
3777             * @param name the name to search with
3778             * @param vocabularyId the vocabulary id to search with
3779             * @throws SystemException if a system exception occurred
3780             */
3781            public void removeByP_N_V(long parentCategoryId, String name,
3782                    long vocabularyId) throws NoSuchCategoryException, SystemException {
3783                    AssetCategory assetCategory = findByP_N_V(parentCategoryId, name,
3784                                    vocabularyId);
3785    
3786                    remove(assetCategory);
3787            }
3788    
3789            /**
3790             * Removes all the asset categories from the database.
3791             *
3792             * @throws SystemException if a system exception occurred
3793             */
3794            public void removeAll() throws SystemException {
3795                    for (AssetCategory assetCategory : findAll()) {
3796                            remove(assetCategory);
3797                    }
3798            }
3799    
3800            /**
3801             * Counts all the asset categories where uuid = &#63;.
3802             *
3803             * @param uuid the uuid to search with
3804             * @return the number of matching asset categories
3805             * @throws SystemException if a system exception occurred
3806             */
3807            public int countByUuid(String uuid) throws SystemException {
3808                    Object[] finderArgs = new Object[] { uuid };
3809    
3810                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3811                                    finderArgs, this);
3812    
3813                    if (count == null) {
3814                            Session session = null;
3815    
3816                            try {
3817                                    session = openSession();
3818    
3819                                    StringBundler query = new StringBundler(2);
3820    
3821                                    query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
3822    
3823                                    if (uuid == null) {
3824                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
3825                                    }
3826                                    else {
3827                                            if (uuid.equals(StringPool.BLANK)) {
3828                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
3829                                            }
3830                                            else {
3831                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
3832                                            }
3833                                    }
3834    
3835                                    String sql = query.toString();
3836    
3837                                    Query q = session.createQuery(sql);
3838    
3839                                    QueryPos qPos = QueryPos.getInstance(q);
3840    
3841                                    if (uuid != null) {
3842                                            qPos.add(uuid);
3843                                    }
3844    
3845                                    count = (Long)q.uniqueResult();
3846                            }
3847                            catch (Exception e) {
3848                                    throw processException(e);
3849                            }
3850                            finally {
3851                                    if (count == null) {
3852                                            count = Long.valueOf(0);
3853                                    }
3854    
3855                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3856                                            finderArgs, count);
3857    
3858                                    closeSession(session);
3859                            }
3860                    }
3861    
3862                    return count.intValue();
3863            }
3864    
3865            /**
3866             * Counts all the asset categories where uuid = &#63; and groupId = &#63;.
3867             *
3868             * @param uuid the uuid to search with
3869             * @param groupId the group id to search with
3870             * @return the number of matching asset categories
3871             * @throws SystemException if a system exception occurred
3872             */
3873            public int countByUUID_G(String uuid, long groupId)
3874                    throws SystemException {
3875                    Object[] finderArgs = new Object[] { uuid, groupId };
3876    
3877                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3878                                    finderArgs, this);
3879    
3880                    if (count == null) {
3881                            Session session = null;
3882    
3883                            try {
3884                                    session = openSession();
3885    
3886                                    StringBundler query = new StringBundler(3);
3887    
3888                                    query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
3889    
3890                                    if (uuid == null) {
3891                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
3892                                    }
3893                                    else {
3894                                            if (uuid.equals(StringPool.BLANK)) {
3895                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
3896                                            }
3897                                            else {
3898                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
3899                                            }
3900                                    }
3901    
3902                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
3903    
3904                                    String sql = query.toString();
3905    
3906                                    Query q = session.createQuery(sql);
3907    
3908                                    QueryPos qPos = QueryPos.getInstance(q);
3909    
3910                                    if (uuid != null) {
3911                                            qPos.add(uuid);
3912                                    }
3913    
3914                                    qPos.add(groupId);
3915    
3916                                    count = (Long)q.uniqueResult();
3917                            }
3918                            catch (Exception e) {
3919                                    throw processException(e);
3920                            }
3921                            finally {
3922                                    if (count == null) {
3923                                            count = Long.valueOf(0);
3924                                    }
3925    
3926                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3927                                            finderArgs, count);
3928    
3929                                    closeSession(session);
3930                            }
3931                    }
3932    
3933                    return count.intValue();
3934            }
3935    
3936            /**
3937             * Counts all the asset categories where groupId = &#63;.
3938             *
3939             * @param groupId the group id to search with
3940             * @return the number of matching asset categories
3941             * @throws SystemException if a system exception occurred
3942             */
3943            public int countByGroupId(long groupId) throws SystemException {
3944                    Object[] finderArgs = new Object[] { groupId };
3945    
3946                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3947                                    finderArgs, this);
3948    
3949                    if (count == null) {
3950                            Session session = null;
3951    
3952                            try {
3953                                    session = openSession();
3954    
3955                                    StringBundler query = new StringBundler(2);
3956    
3957                                    query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
3958    
3959                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3960    
3961                                    String sql = query.toString();
3962    
3963                                    Query q = session.createQuery(sql);
3964    
3965                                    QueryPos qPos = QueryPos.getInstance(q);
3966    
3967                                    qPos.add(groupId);
3968    
3969                                    count = (Long)q.uniqueResult();
3970                            }
3971                            catch (Exception e) {
3972                                    throw processException(e);
3973                            }
3974                            finally {
3975                                    if (count == null) {
3976                                            count = Long.valueOf(0);
3977                                    }
3978    
3979                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3980                                            finderArgs, count);
3981    
3982                                    closeSession(session);
3983                            }
3984                    }
3985    
3986                    return count.intValue();
3987            }
3988    
3989            /**
3990             * Filters by the user's permissions and counts all the asset categories where groupId = &#63;.
3991             *
3992             * @param groupId the group id to search with
3993             * @return the number of matching asset categories that the user has permission to view
3994             * @throws SystemException if a system exception occurred
3995             */
3996            public int filterCountByGroupId(long groupId) throws SystemException {
3997                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3998                            return countByGroupId(groupId);
3999                    }
4000    
4001                    Session session = null;
4002    
4003                    try {
4004                            session = openSession();
4005    
4006                            StringBundler query = new StringBundler(2);
4007    
4008                            query.append(_FILTER_SQL_COUNT_ASSETCATEGORY_WHERE);
4009    
4010                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4011    
4012                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4013                                            AssetCategory.class.getName(), _FILTER_COLUMN_PK,
4014                                            _FILTER_COLUMN_USERID, groupId);
4015    
4016                            SQLQuery q = session.createSQLQuery(sql);
4017    
4018                            q.addScalar(COUNT_COLUMN_NAME,
4019                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4020    
4021                            QueryPos qPos = QueryPos.getInstance(q);
4022    
4023                            qPos.add(groupId);
4024    
4025                            Long count = (Long)q.uniqueResult();
4026    
4027                            return count.intValue();
4028                    }
4029                    catch (Exception e) {
4030                            throw processException(e);
4031                    }
4032                    finally {
4033                            closeSession(session);
4034                    }
4035            }
4036    
4037            /**
4038             * Counts all the asset categories where parentCategoryId = &#63;.
4039             *
4040             * @param parentCategoryId the parent category id to search with
4041             * @return the number of matching asset categories
4042             * @throws SystemException if a system exception occurred
4043             */
4044            public int countByParentCategoryId(long parentCategoryId)
4045                    throws SystemException {
4046                    Object[] finderArgs = new Object[] { parentCategoryId };
4047    
4048                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PARENTCATEGORYID,
4049                                    finderArgs, this);
4050    
4051                    if (count == null) {
4052                            Session session = null;
4053    
4054                            try {
4055                                    session = openSession();
4056    
4057                                    StringBundler query = new StringBundler(2);
4058    
4059                                    query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4060    
4061                                    query.append(_FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2);
4062    
4063                                    String sql = query.toString();
4064    
4065                                    Query q = session.createQuery(sql);
4066    
4067                                    QueryPos qPos = QueryPos.getInstance(q);
4068    
4069                                    qPos.add(parentCategoryId);
4070    
4071                                    count = (Long)q.uniqueResult();
4072                            }
4073                            catch (Exception e) {
4074                                    throw processException(e);
4075                            }
4076                            finally {
4077                                    if (count == null) {
4078                                            count = Long.valueOf(0);
4079                                    }
4080    
4081                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PARENTCATEGORYID,
4082                                            finderArgs, count);
4083    
4084                                    closeSession(session);
4085                            }
4086                    }
4087    
4088                    return count.intValue();
4089            }
4090    
4091            /**
4092             * Counts all the asset categories where vocabularyId = &#63;.
4093             *
4094             * @param vocabularyId the vocabulary id to search with
4095             * @return the number of matching asset categories
4096             * @throws SystemException if a system exception occurred
4097             */
4098            public int countByVocabularyId(long vocabularyId) throws SystemException {
4099                    Object[] finderArgs = new Object[] { vocabularyId };
4100    
4101                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VOCABULARYID,
4102                                    finderArgs, this);
4103    
4104                    if (count == null) {
4105                            Session session = null;
4106    
4107                            try {
4108                                    session = openSession();
4109    
4110                                    StringBundler query = new StringBundler(2);
4111    
4112                                    query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4113    
4114                                    query.append(_FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2);
4115    
4116                                    String sql = query.toString();
4117    
4118                                    Query q = session.createQuery(sql);
4119    
4120                                    QueryPos qPos = QueryPos.getInstance(q);
4121    
4122                                    qPos.add(vocabularyId);
4123    
4124                                    count = (Long)q.uniqueResult();
4125                            }
4126                            catch (Exception e) {
4127                                    throw processException(e);
4128                            }
4129                            finally {
4130                                    if (count == null) {
4131                                            count = Long.valueOf(0);
4132                                    }
4133    
4134                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VOCABULARYID,
4135                                            finderArgs, count);
4136    
4137                                    closeSession(session);
4138                            }
4139                    }
4140    
4141                    return count.intValue();
4142            }
4143    
4144            /**
4145             * Counts all the asset categories where parentCategoryId = &#63; and name = &#63;.
4146             *
4147             * @param parentCategoryId the parent category id to search with
4148             * @param name the name to search with
4149             * @return the number of matching asset categories
4150             * @throws SystemException if a system exception occurred
4151             */
4152            public int countByP_N(long parentCategoryId, String name)
4153                    throws SystemException {
4154                    Object[] finderArgs = new Object[] { parentCategoryId, name };
4155    
4156                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_N,
4157                                    finderArgs, this);
4158    
4159                    if (count == null) {
4160                            Session session = null;
4161    
4162                            try {
4163                                    session = openSession();
4164    
4165                                    StringBundler query = new StringBundler(3);
4166    
4167                                    query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4168    
4169                                    query.append(_FINDER_COLUMN_P_N_PARENTCATEGORYID_2);
4170    
4171                                    if (name == null) {
4172                                            query.append(_FINDER_COLUMN_P_N_NAME_1);
4173                                    }
4174                                    else {
4175                                            if (name.equals(StringPool.BLANK)) {
4176                                                    query.append(_FINDER_COLUMN_P_N_NAME_3);
4177                                            }
4178                                            else {
4179                                                    query.append(_FINDER_COLUMN_P_N_NAME_2);
4180                                            }
4181                                    }
4182    
4183                                    String sql = query.toString();
4184    
4185                                    Query q = session.createQuery(sql);
4186    
4187                                    QueryPos qPos = QueryPos.getInstance(q);
4188    
4189                                    qPos.add(parentCategoryId);
4190    
4191                                    if (name != null) {
4192                                            qPos.add(name);
4193                                    }
4194    
4195                                    count = (Long)q.uniqueResult();
4196                            }
4197                            catch (Exception e) {
4198                                    throw processException(e);
4199                            }
4200                            finally {
4201                                    if (count == null) {
4202                                            count = Long.valueOf(0);
4203                                    }
4204    
4205                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_N, finderArgs,
4206                                            count);
4207    
4208                                    closeSession(session);
4209                            }
4210                    }
4211    
4212                    return count.intValue();
4213            }
4214    
4215            /**
4216             * Counts all the asset categories where parentCategoryId = &#63; and vocabularyId = &#63;.
4217             *
4218             * @param parentCategoryId the parent category id to search with
4219             * @param vocabularyId the vocabulary id to search with
4220             * @return the number of matching asset categories
4221             * @throws SystemException if a system exception occurred
4222             */
4223            public int countByP_V(long parentCategoryId, long vocabularyId)
4224                    throws SystemException {
4225                    Object[] finderArgs = new Object[] { parentCategoryId, vocabularyId };
4226    
4227                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_V,
4228                                    finderArgs, this);
4229    
4230                    if (count == null) {
4231                            Session session = null;
4232    
4233                            try {
4234                                    session = openSession();
4235    
4236                                    StringBundler query = new StringBundler(3);
4237    
4238                                    query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4239    
4240                                    query.append(_FINDER_COLUMN_P_V_PARENTCATEGORYID_2);
4241    
4242                                    query.append(_FINDER_COLUMN_P_V_VOCABULARYID_2);
4243    
4244                                    String sql = query.toString();
4245    
4246                                    Query q = session.createQuery(sql);
4247    
4248                                    QueryPos qPos = QueryPos.getInstance(q);
4249    
4250                                    qPos.add(parentCategoryId);
4251    
4252                                    qPos.add(vocabularyId);
4253    
4254                                    count = (Long)q.uniqueResult();
4255                            }
4256                            catch (Exception e) {
4257                                    throw processException(e);
4258                            }
4259                            finally {
4260                                    if (count == null) {
4261                                            count = Long.valueOf(0);
4262                                    }
4263    
4264                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_V, finderArgs,
4265                                            count);
4266    
4267                                    closeSession(session);
4268                            }
4269                    }
4270    
4271                    return count.intValue();
4272            }
4273    
4274            /**
4275             * Counts all the asset categories where name = &#63; and vocabularyId = &#63;.
4276             *
4277             * @param name the name to search with
4278             * @param vocabularyId the vocabulary id to search with
4279             * @return the number of matching asset categories
4280             * @throws SystemException if a system exception occurred
4281             */
4282            public int countByN_V(String name, long vocabularyId)
4283                    throws SystemException {
4284                    Object[] finderArgs = new Object[] { name, vocabularyId };
4285    
4286                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_V,
4287                                    finderArgs, this);
4288    
4289                    if (count == null) {
4290                            Session session = null;
4291    
4292                            try {
4293                                    session = openSession();
4294    
4295                                    StringBundler query = new StringBundler(3);
4296    
4297                                    query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4298    
4299                                    if (name == null) {
4300                                            query.append(_FINDER_COLUMN_N_V_NAME_1);
4301                                    }
4302                                    else {
4303                                            if (name.equals(StringPool.BLANK)) {
4304                                                    query.append(_FINDER_COLUMN_N_V_NAME_3);
4305                                            }
4306                                            else {
4307                                                    query.append(_FINDER_COLUMN_N_V_NAME_2);
4308                                            }
4309                                    }
4310    
4311                                    query.append(_FINDER_COLUMN_N_V_VOCABULARYID_2);
4312    
4313                                    String sql = query.toString();
4314    
4315                                    Query q = session.createQuery(sql);
4316    
4317                                    QueryPos qPos = QueryPos.getInstance(q);
4318    
4319                                    if (name != null) {
4320                                            qPos.add(name);
4321                                    }
4322    
4323                                    qPos.add(vocabularyId);
4324    
4325                                    count = (Long)q.uniqueResult();
4326                            }
4327                            catch (Exception e) {
4328                                    throw processException(e);
4329                            }
4330                            finally {
4331                                    if (count == null) {
4332                                            count = Long.valueOf(0);
4333                                    }
4334    
4335                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_V, finderArgs,
4336                                            count);
4337    
4338                                    closeSession(session);
4339                            }
4340                    }
4341    
4342                    return count.intValue();
4343            }
4344    
4345            /**
4346             * Counts all the asset categories where parentCategoryId = &#63; and name = &#63; and vocabularyId = &#63;.
4347             *
4348             * @param parentCategoryId the parent category id to search with
4349             * @param name the name to search with
4350             * @param vocabularyId the vocabulary id to search with
4351             * @return the number of matching asset categories
4352             * @throws SystemException if a system exception occurred
4353             */
4354            public int countByP_N_V(long parentCategoryId, String name,
4355                    long vocabularyId) throws SystemException {
4356                    Object[] finderArgs = new Object[] { parentCategoryId, name, vocabularyId };
4357    
4358                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_N_V,
4359                                    finderArgs, this);
4360    
4361                    if (count == null) {
4362                            Session session = null;
4363    
4364                            try {
4365                                    session = openSession();
4366    
4367                                    StringBundler query = new StringBundler(4);
4368    
4369                                    query.append(_SQL_COUNT_ASSETCATEGORY_WHERE);
4370    
4371                                    query.append(_FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2);
4372    
4373                                    if (name == null) {
4374                                            query.append(_FINDER_COLUMN_P_N_V_NAME_1);
4375                                    }
4376                                    else {
4377                                            if (name.equals(StringPool.BLANK)) {
4378                                                    query.append(_FINDER_COLUMN_P_N_V_NAME_3);
4379                                            }
4380                                            else {
4381                                                    query.append(_FINDER_COLUMN_P_N_V_NAME_2);
4382                                            }
4383                                    }
4384    
4385                                    query.append(_FINDER_COLUMN_P_N_V_VOCABULARYID_2);
4386    
4387                                    String sql = query.toString();
4388    
4389                                    Query q = session.createQuery(sql);
4390    
4391                                    QueryPos qPos = QueryPos.getInstance(q);
4392    
4393                                    qPos.add(parentCategoryId);
4394    
4395                                    if (name != null) {
4396                                            qPos.add(name);
4397                                    }
4398    
4399                                    qPos.add(vocabularyId);
4400    
4401                                    count = (Long)q.uniqueResult();
4402                            }
4403                            catch (Exception e) {
4404                                    throw processException(e);
4405                            }
4406                            finally {
4407                                    if (count == null) {
4408                                            count = Long.valueOf(0);
4409                                    }
4410    
4411                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_N_V,
4412                                            finderArgs, count);
4413    
4414                                    closeSession(session);
4415                            }
4416                    }
4417    
4418                    return count.intValue();
4419            }
4420    
4421            /**
4422             * Counts all the asset categories.
4423             *
4424             * @return the number of asset categories
4425             * @throws SystemException if a system exception occurred
4426             */
4427            public int countAll() throws SystemException {
4428                    Object[] finderArgs = new Object[0];
4429    
4430                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4431                                    finderArgs, this);
4432    
4433                    if (count == null) {
4434                            Session session = null;
4435    
4436                            try {
4437                                    session = openSession();
4438    
4439                                    Query q = session.createQuery(_SQL_COUNT_ASSETCATEGORY);
4440    
4441                                    count = (Long)q.uniqueResult();
4442                            }
4443                            catch (Exception e) {
4444                                    throw processException(e);
4445                            }
4446                            finally {
4447                                    if (count == null) {
4448                                            count = Long.valueOf(0);
4449                                    }
4450    
4451                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
4452                                            count);
4453    
4454                                    closeSession(session);
4455                            }
4456                    }
4457    
4458                    return count.intValue();
4459            }
4460    
4461            /**
4462             * Gets all the asset entries associated with the asset category.
4463             *
4464             * @param pk the primary key of the asset category to get the associated asset entries for
4465             * @return the asset entries associated with the asset category
4466             * @throws SystemException if a system exception occurred
4467             */
4468            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
4469                    long pk) throws SystemException {
4470                    return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4471            }
4472    
4473            /**
4474             * Gets a range of all the asset entries associated with the asset category.
4475             *
4476             * <p>
4477             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4478             * </p>
4479             *
4480             * @param pk the primary key of the asset category to get the associated asset entries for
4481             * @param start the lower bound of the range of asset categories to return
4482             * @param end the upper bound of the range of asset categories to return (not inclusive)
4483             * @return the range of asset entries associated with the asset category
4484             * @throws SystemException if a system exception occurred
4485             */
4486            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
4487                    long pk, int start, int end) throws SystemException {
4488                    return getAssetEntries(pk, start, end, null);
4489            }
4490    
4491            public static final FinderPath FINDER_PATH_GET_ASSETENTRIES = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
4492                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
4493                            AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
4494                            "getAssetEntries",
4495                            new String[] {
4496                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
4497                                    "com.liferay.portal.kernel.util.OrderByComparator"
4498                            });
4499    
4500            /**
4501             * Gets an ordered range of all the asset entries associated with the asset category.
4502             *
4503             * <p>
4504             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
4505             * </p>
4506             *
4507             * @param pk the primary key of the asset category to get the associated asset entries for
4508             * @param start the lower bound of the range of asset categories to return
4509             * @param end the upper bound of the range of asset categories to return (not inclusive)
4510             * @param orderByComparator the comparator to order the results by
4511             * @return the ordered range of asset entries associated with the asset category
4512             * @throws SystemException if a system exception occurred
4513             */
4514            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
4515                    long pk, int start, int end, OrderByComparator orderByComparator)
4516                    throws SystemException {
4517                    Object[] finderArgs = new Object[] {
4518                                    pk, String.valueOf(start), String.valueOf(end),
4519                                    String.valueOf(orderByComparator)
4520                            };
4521    
4522                    List<com.liferay.portlet.asset.model.AssetEntry> list = (List<com.liferay.portlet.asset.model.AssetEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES,
4523                                    finderArgs, this);
4524    
4525                    if (list == null) {
4526                            Session session = null;
4527    
4528                            try {
4529                                    session = openSession();
4530    
4531                                    String sql = null;
4532    
4533                                    if (orderByComparator != null) {
4534                                            sql = _SQL_GETASSETENTRIES.concat(ORDER_BY_CLAUSE)
4535                                                                                              .concat(orderByComparator.getOrderBy());
4536                                    }
4537                                    else {
4538                                            sql = _SQL_GETASSETENTRIES;
4539                                    }
4540    
4541                                    SQLQuery q = session.createSQLQuery(sql);
4542    
4543                                    q.addEntity("AssetEntry",
4544                                            com.liferay.portlet.asset.model.impl.AssetEntryImpl.class);
4545    
4546                                    QueryPos qPos = QueryPos.getInstance(q);
4547    
4548                                    qPos.add(pk);
4549    
4550                                    list = (List<com.liferay.portlet.asset.model.AssetEntry>)QueryUtil.list(q,
4551                                                    getDialect(), start, end);
4552                            }
4553                            catch (Exception e) {
4554                                    throw processException(e);
4555                            }
4556                            finally {
4557                                    if (list == null) {
4558                                            list = new ArrayList<com.liferay.portlet.asset.model.AssetEntry>();
4559                                    }
4560    
4561                                    assetEntryPersistence.cacheResult(list);
4562    
4563                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES,
4564                                            finderArgs, list);
4565    
4566                                    closeSession(session);
4567                            }
4568                    }
4569    
4570                    return list;
4571            }
4572    
4573            public static final FinderPath FINDER_PATH_GET_ASSETENTRIES_SIZE = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
4574                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
4575                            AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
4576                            "getAssetEntriesSize", new String[] { Long.class.getName() });
4577    
4578            /**
4579             * Gets the number of asset entries associated with the asset category.
4580             *
4581             * @param pk the primary key of the asset category to get the number of associated asset entries for
4582             * @return the number of asset entries associated with the asset category
4583             * @throws SystemException if a system exception occurred
4584             */
4585            public int getAssetEntriesSize(long pk) throws SystemException {
4586                    Object[] finderArgs = new Object[] { pk };
4587    
4588                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
4589                                    finderArgs, this);
4590    
4591                    if (count == null) {
4592                            Session session = null;
4593    
4594                            try {
4595                                    session = openSession();
4596    
4597                                    SQLQuery q = session.createSQLQuery(_SQL_GETASSETENTRIESSIZE);
4598    
4599                                    q.addScalar(COUNT_COLUMN_NAME,
4600                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
4601    
4602                                    QueryPos qPos = QueryPos.getInstance(q);
4603    
4604                                    qPos.add(pk);
4605    
4606                                    count = (Long)q.uniqueResult();
4607                            }
4608                            catch (Exception e) {
4609                                    throw processException(e);
4610                            }
4611                            finally {
4612                                    if (count == null) {
4613                                            count = Long.valueOf(0);
4614                                    }
4615    
4616                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
4617                                            finderArgs, count);
4618    
4619                                    closeSession(session);
4620                            }
4621                    }
4622    
4623                    return count.intValue();
4624            }
4625    
4626            public static final FinderPath FINDER_PATH_CONTAINS_ASSETENTRY = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
4627                            AssetCategoryModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETCATEGORIES,
4628                            AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME,
4629                            "containsAssetEntry",
4630                            new String[] { Long.class.getName(), Long.class.getName() });
4631    
4632            /**
4633             * Determines whether the asset entry is associated with the asset category.
4634             *
4635             * @param pk the primary key of the asset category
4636             * @param assetEntryPK the primary key of the asset entry
4637             * @return whether the asset entry is associated with the asset category
4638             * @throws SystemException if a system exception occurred
4639             */
4640            public boolean containsAssetEntry(long pk, long assetEntryPK)
4641                    throws SystemException {
4642                    Object[] finderArgs = new Object[] { pk, assetEntryPK };
4643    
4644                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ASSETENTRY,
4645                                    finderArgs, this);
4646    
4647                    if (value == null) {
4648                            try {
4649                                    value = Boolean.valueOf(containsAssetEntry.contains(pk,
4650                                                            assetEntryPK));
4651                            }
4652                            catch (Exception e) {
4653                                    throw processException(e);
4654                            }
4655                            finally {
4656                                    if (value == null) {
4657                                            value = Boolean.FALSE;
4658                                    }
4659    
4660                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ASSETENTRY,
4661                                            finderArgs, value);
4662                            }
4663                    }
4664    
4665                    return value.booleanValue();
4666            }
4667    
4668            /**
4669             * Determines whether the asset category has any asset entries associated with it.
4670             *
4671             * @param pk the primary key of the asset category to check for associations with asset entries
4672             * @return whether the asset category has any asset entries associated with it
4673             * @throws SystemException if a system exception occurred
4674             */
4675            public boolean containsAssetEntries(long pk) throws SystemException {
4676                    if (getAssetEntriesSize(pk) > 0) {
4677                            return true;
4678                    }
4679                    else {
4680                            return false;
4681                    }
4682            }
4683    
4684            /**
4685             * Adds an association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4686             *
4687             * @param pk the primary key of the asset category
4688             * @param assetEntryPK the primary key of the asset entry
4689             * @throws SystemException if a system exception occurred
4690             */
4691            public void addAssetEntry(long pk, long assetEntryPK)
4692                    throws SystemException {
4693                    try {
4694                            addAssetEntry.add(pk, assetEntryPK);
4695                    }
4696                    catch (Exception e) {
4697                            throw processException(e);
4698                    }
4699                    finally {
4700                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4701                    }
4702            }
4703    
4704            /**
4705             * Adds an association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4706             *
4707             * @param pk the primary key of the asset category
4708             * @param assetEntry the asset entry
4709             * @throws SystemException if a system exception occurred
4710             */
4711            public void addAssetEntry(long pk,
4712                    com.liferay.portlet.asset.model.AssetEntry assetEntry)
4713                    throws SystemException {
4714                    try {
4715                            addAssetEntry.add(pk, assetEntry.getPrimaryKey());
4716                    }
4717                    catch (Exception e) {
4718                            throw processException(e);
4719                    }
4720                    finally {
4721                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4722                    }
4723            }
4724    
4725            /**
4726             * Adds an association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4727             *
4728             * @param pk the primary key of the asset category
4729             * @param assetEntryPKs the primary keys of the asset entries
4730             * @throws SystemException if a system exception occurred
4731             */
4732            public void addAssetEntries(long pk, long[] assetEntryPKs)
4733                    throws SystemException {
4734                    try {
4735                            for (long assetEntryPK : assetEntryPKs) {
4736                                    addAssetEntry.add(pk, assetEntryPK);
4737                            }
4738                    }
4739                    catch (Exception e) {
4740                            throw processException(e);
4741                    }
4742                    finally {
4743                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4744                    }
4745            }
4746    
4747            /**
4748             * Adds an association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4749             *
4750             * @param pk the primary key of the asset category
4751             * @param assetEntries the asset entries
4752             * @throws SystemException if a system exception occurred
4753             */
4754            public void addAssetEntries(long pk,
4755                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
4756                    throws SystemException {
4757                    try {
4758                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
4759                                    addAssetEntry.add(pk, assetEntry.getPrimaryKey());
4760                            }
4761                    }
4762                    catch (Exception e) {
4763                            throw processException(e);
4764                    }
4765                    finally {
4766                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4767                    }
4768            }
4769    
4770            /**
4771             * Clears all associations between the asset category and its asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4772             *
4773             * @param pk the primary key of the asset category to clear the associated asset entries from
4774             * @throws SystemException if a system exception occurred
4775             */
4776            public void clearAssetEntries(long pk) throws SystemException {
4777                    try {
4778                            clearAssetEntries.clear(pk);
4779                    }
4780                    catch (Exception e) {
4781                            throw processException(e);
4782                    }
4783                    finally {
4784                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4785                    }
4786            }
4787    
4788            /**
4789             * Removes the association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4790             *
4791             * @param pk the primary key of the asset category
4792             * @param assetEntryPK the primary key of the asset entry
4793             * @throws SystemException if a system exception occurred
4794             */
4795            public void removeAssetEntry(long pk, long assetEntryPK)
4796                    throws SystemException {
4797                    try {
4798                            removeAssetEntry.remove(pk, assetEntryPK);
4799                    }
4800                    catch (Exception e) {
4801                            throw processException(e);
4802                    }
4803                    finally {
4804                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4805                    }
4806            }
4807    
4808            /**
4809             * Removes the association between the asset category and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4810             *
4811             * @param pk the primary key of the asset category
4812             * @param assetEntry the asset entry
4813             * @throws SystemException if a system exception occurred
4814             */
4815            public void removeAssetEntry(long pk,
4816                    com.liferay.portlet.asset.model.AssetEntry assetEntry)
4817                    throws SystemException {
4818                    try {
4819                            removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
4820                    }
4821                    catch (Exception e) {
4822                            throw processException(e);
4823                    }
4824                    finally {
4825                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4826                    }
4827            }
4828    
4829            /**
4830             * Removes the association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4831             *
4832             * @param pk the primary key of the asset category
4833             * @param assetEntryPKs the primary keys of the asset entries
4834             * @throws SystemException if a system exception occurred
4835             */
4836            public void removeAssetEntries(long pk, long[] assetEntryPKs)
4837                    throws SystemException {
4838                    try {
4839                            for (long assetEntryPK : assetEntryPKs) {
4840                                    removeAssetEntry.remove(pk, assetEntryPK);
4841                            }
4842                    }
4843                    catch (Exception e) {
4844                            throw processException(e);
4845                    }
4846                    finally {
4847                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4848                    }
4849            }
4850    
4851            /**
4852             * Removes the association between the asset category and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4853             *
4854             * @param pk the primary key of the asset category
4855             * @param assetEntries the asset entries
4856             * @throws SystemException if a system exception occurred
4857             */
4858            public void removeAssetEntries(long pk,
4859                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
4860                    throws SystemException {
4861                    try {
4862                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
4863                                    removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
4864                            }
4865                    }
4866                    catch (Exception e) {
4867                            throw processException(e);
4868                    }
4869                    finally {
4870                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4871                    }
4872            }
4873    
4874            /**
4875             * 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.
4876             *
4877             * @param pk the primary key of the asset category to set the associations for
4878             * @param assetEntryPKs the primary keys of the asset entries to be associated with the asset category
4879             * @throws SystemException if a system exception occurred
4880             */
4881            public void setAssetEntries(long pk, long[] assetEntryPKs)
4882                    throws SystemException {
4883                    try {
4884                            Set<Long> assetEntryPKSet = SetUtil.fromArray(assetEntryPKs);
4885    
4886                            List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = getAssetEntries(pk);
4887    
4888                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
4889                                    if (!assetEntryPKSet.remove(assetEntry.getPrimaryKey())) {
4890                                            removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
4891                                    }
4892                            }
4893    
4894                            for (Long assetEntryPK : assetEntryPKSet) {
4895                                    addAssetEntry.add(pk, assetEntryPK);
4896                            }
4897                    }
4898                    catch (Exception e) {
4899                            throw processException(e);
4900                    }
4901                    finally {
4902                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4903                    }
4904            }
4905    
4906            /**
4907             * 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.
4908             *
4909             * @param pk the primary key of the asset category to set the associations for
4910             * @param assetEntries the asset entries to be associated with the asset category
4911             * @throws SystemException if a system exception occurred
4912             */
4913            public void setAssetEntries(long pk,
4914                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
4915                    throws SystemException {
4916                    try {
4917                            long[] assetEntryPKs = new long[assetEntries.size()];
4918    
4919                            for (int i = 0; i < assetEntries.size(); i++) {
4920                                    com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
4921    
4922                                    assetEntryPKs[i] = assetEntry.getPrimaryKey();
4923                            }
4924    
4925                            setAssetEntries(pk, assetEntryPKs);
4926                    }
4927                    catch (Exception e) {
4928                            throw processException(e);
4929                    }
4930                    finally {
4931                            FinderCacheUtil.clearCache(AssetCategoryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4932                    }
4933            }
4934    
4935            /**
4936             * Rebuilds the asset categories tree for the scope using the modified pre-order tree traversal algorithm.
4937             *
4938             * <p>
4939             * 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.
4940             * </p>
4941             *
4942             * @param groupId the id of the scope to rebuild the tree for
4943             * @param force whether to force the rebuild even if the tree is not stale
4944             */
4945            public void rebuildTree(long groupId, boolean force)
4946                    throws SystemException {
4947                    if (force || (countOrphanTreeNodes(groupId) > 0)) {
4948                            rebuildTree(groupId, 0, 1);
4949    
4950                            CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
4951                            EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
4952                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4953                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
4954                    }
4955            }
4956    
4957            protected long countOrphanTreeNodes(long groupId) throws SystemException {
4958                    Session session = null;
4959    
4960                    try {
4961                            session = openSession();
4962    
4963                            SQLQuery q = session.createSQLQuery(
4964                                            "SELECT COUNT(*) AS COUNT_VALUE FROM AssetCategory WHERE groupId = ? AND (leftCategoryId = 0 OR leftCategoryId IS NULL OR rightCategoryId = 0 OR rightCategoryId IS NULL)");
4965    
4966                            q.addScalar(COUNT_COLUMN_NAME,
4967                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4968    
4969                            QueryPos qPos = QueryPos.getInstance(q);
4970    
4971                            qPos.add(groupId);
4972    
4973                            return (Long)q.uniqueResult();
4974                    }
4975                    catch (Exception e) {
4976                            throw processException(e);
4977                    }
4978                    finally {
4979                            closeSession(session);
4980                    }
4981            }
4982    
4983            protected void expandTree(AssetCategory assetCategory)
4984                    throws SystemException {
4985                    long groupId = assetCategory.getGroupId();
4986    
4987                    long lastRightCategoryId = getLastRightCategoryId(groupId,
4988                                    assetCategory.getParentCategoryId());
4989    
4990                    long leftCategoryId = 2;
4991                    long rightCategoryId = 3;
4992    
4993                    if (lastRightCategoryId > 0) {
4994                            leftCategoryId = lastRightCategoryId + 1;
4995                            rightCategoryId = lastRightCategoryId + 2;
4996    
4997                            expandTreeLeftCategoryId.expand(groupId, lastRightCategoryId);
4998                            expandTreeRightCategoryId.expand(groupId, lastRightCategoryId);
4999    
5000                            CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
5001                            EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
5002                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
5003                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
5004                    }
5005    
5006                    assetCategory.setLeftCategoryId(leftCategoryId);
5007                    assetCategory.setRightCategoryId(rightCategoryId);
5008            }
5009    
5010            protected long getLastRightCategoryId(long groupId, long parentCategoryId)
5011                    throws SystemException {
5012                    Session session = null;
5013    
5014                    try {
5015                            session = openSession();
5016    
5017                            SQLQuery q = session.createSQLQuery(
5018                                            "SELECT rightCategoryId FROM AssetCategory WHERE (groupId = ?) AND (parentCategoryId = ?) ORDER BY rightCategoryId DESC");
5019    
5020                            q.addScalar("rightCategoryId",
5021                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5022    
5023                            QueryPos qPos = QueryPos.getInstance(q);
5024    
5025                            qPos.add(groupId);
5026                            qPos.add(parentCategoryId);
5027    
5028                            List<Long> list = (List<Long>)QueryUtil.list(q, getDialect(), 0, 1);
5029    
5030                            if (list.isEmpty()) {
5031                                    if (parentCategoryId > 0) {
5032                                            AssetCategory parentAssetCategory = findByPrimaryKey(parentCategoryId);
5033    
5034                                            return parentAssetCategory.getLeftCategoryId();
5035                                    }
5036    
5037                                    return 0;
5038                            }
5039                            else {
5040                                    return list.get(0);
5041                            }
5042                    }
5043                    catch (Exception e) {
5044                            throw processException(e);
5045                    }
5046                    finally {
5047                            closeSession(session);
5048                    }
5049            }
5050    
5051            protected long rebuildTree(long groupId, long parentCategoryId,
5052                    long leftCategoryId) throws SystemException {
5053                    List<Long> categoryIds = null;
5054    
5055                    Session session = null;
5056    
5057                    try {
5058                            session = openSession();
5059    
5060                            SQLQuery q = session.createSQLQuery(
5061                                            "SELECT categoryId FROM AssetCategory WHERE groupId = ? AND parentCategoryId = ? ORDER BY categoryId ASC");
5062    
5063                            q.addScalar("categoryId",
5064                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5065    
5066                            QueryPos qPos = QueryPos.getInstance(q);
5067    
5068                            qPos.add(groupId);
5069                            qPos.add(parentCategoryId);
5070    
5071                            categoryIds = q.list();
5072                    }
5073                    catch (Exception e) {
5074                            throw processException(e);
5075                    }
5076                    finally {
5077                            closeSession(session);
5078                    }
5079    
5080                    long rightCategoryId = leftCategoryId + 1;
5081    
5082                    for (long categoryId : categoryIds) {
5083                            rightCategoryId = rebuildTree(groupId, categoryId, rightCategoryId);
5084                    }
5085    
5086                    if (parentCategoryId > 0) {
5087                            updateTree.update(parentCategoryId, leftCategoryId, rightCategoryId);
5088                    }
5089    
5090                    return rightCategoryId + 1;
5091            }
5092    
5093            protected void shrinkTree(AssetCategory assetCategory) {
5094                    long groupId = assetCategory.getGroupId();
5095    
5096                    long leftCategoryId = assetCategory.getLeftCategoryId();
5097                    long rightCategoryId = assetCategory.getRightCategoryId();
5098    
5099                    long delta = (rightCategoryId - leftCategoryId) + 1;
5100    
5101                    shrinkTreeLeftCategoryId.shrink(groupId, rightCategoryId, delta);
5102                    shrinkTreeRightCategoryId.shrink(groupId, rightCategoryId, delta);
5103    
5104                    CacheRegistryUtil.clear(AssetCategoryImpl.class.getName());
5105                    EntityCacheUtil.clearCache(AssetCategoryImpl.class.getName());
5106                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
5107                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
5108            }
5109    
5110            /**
5111             * Initializes the asset category persistence.
5112             */
5113            public void afterPropertiesSet() {
5114                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5115                                            com.liferay.portal.util.PropsUtil.get(
5116                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetCategory")));
5117    
5118                    if (listenerClassNames.length > 0) {
5119                            try {
5120                                    List<ModelListener<AssetCategory>> listenersList = new ArrayList<ModelListener<AssetCategory>>();
5121    
5122                                    for (String listenerClassName : listenerClassNames) {
5123                                            listenersList.add((ModelListener<AssetCategory>)InstanceFactory.newInstance(
5124                                                            listenerClassName));
5125                                    }
5126    
5127                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5128                            }
5129                            catch (Exception e) {
5130                                    _log.error(e);
5131                            }
5132                    }
5133    
5134                    containsAssetEntry = new ContainsAssetEntry(this);
5135    
5136                    addAssetEntry = new AddAssetEntry(this);
5137                    clearAssetEntries = new ClearAssetEntries(this);
5138                    removeAssetEntry = new RemoveAssetEntry(this);
5139    
5140                    expandTreeLeftCategoryId = new ExpandTreeLeftCategoryId();
5141                    expandTreeRightCategoryId = new ExpandTreeRightCategoryId();
5142                    shrinkTreeLeftCategoryId = new ShrinkTreeLeftCategoryId();
5143                    shrinkTreeRightCategoryId = new ShrinkTreeRightCategoryId();
5144                    updateTree = new UpdateTree();
5145            }
5146    
5147            @BeanReference(type = AssetCategoryPersistence.class)
5148            protected AssetCategoryPersistence assetCategoryPersistence;
5149            @BeanReference(type = AssetCategoryPropertyPersistence.class)
5150            protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
5151            @BeanReference(type = AssetEntryPersistence.class)
5152            protected AssetEntryPersistence assetEntryPersistence;
5153            @BeanReference(type = AssetLinkPersistence.class)
5154            protected AssetLinkPersistence assetLinkPersistence;
5155            @BeanReference(type = AssetTagPersistence.class)
5156            protected AssetTagPersistence assetTagPersistence;
5157            @BeanReference(type = AssetTagPropertyPersistence.class)
5158            protected AssetTagPropertyPersistence assetTagPropertyPersistence;
5159            @BeanReference(type = AssetTagStatsPersistence.class)
5160            protected AssetTagStatsPersistence assetTagStatsPersistence;
5161            @BeanReference(type = AssetVocabularyPersistence.class)
5162            protected AssetVocabularyPersistence assetVocabularyPersistence;
5163            @BeanReference(type = ResourcePersistence.class)
5164            protected ResourcePersistence resourcePersistence;
5165            @BeanReference(type = UserPersistence.class)
5166            protected UserPersistence userPersistence;
5167            protected ContainsAssetEntry containsAssetEntry;
5168            protected AddAssetEntry addAssetEntry;
5169            protected ClearAssetEntries clearAssetEntries;
5170            protected RemoveAssetEntry removeAssetEntry;
5171    
5172            protected class ContainsAssetEntry {
5173                    protected ContainsAssetEntry(
5174                            AssetCategoryPersistenceImpl persistenceImpl) {
5175                            super();
5176    
5177                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
5178                                            _SQL_CONTAINSASSETENTRY,
5179                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
5180                                            RowMapper.COUNT);
5181                    }
5182    
5183                    protected boolean contains(long categoryId, long entryId) {
5184                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5185                                                    new Long(categoryId), new Long(entryId)
5186                                            });
5187    
5188                            if (results.size() > 0) {
5189                                    Integer count = results.get(0);
5190    
5191                                    if (count.intValue() > 0) {
5192                                            return true;
5193                                    }
5194                            }
5195    
5196                            return false;
5197                    }
5198    
5199                    private MappingSqlQuery<Integer> _mappingSqlQuery;
5200            }
5201    
5202            protected class AddAssetEntry {
5203                    protected AddAssetEntry(AssetCategoryPersistenceImpl persistenceImpl) {
5204                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5205                                            "INSERT INTO AssetEntries_AssetCategories (categoryId, entryId) VALUES (?, ?)",
5206                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
5207                            _persistenceImpl = persistenceImpl;
5208                    }
5209    
5210                    protected void add(long categoryId, long entryId)
5211                            throws SystemException {
5212                            if (!_persistenceImpl.containsAssetEntry.contains(categoryId,
5213                                                    entryId)) {
5214                                    ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
5215                                            assetEntryPersistence.getListeners();
5216    
5217                                    for (ModelListener<AssetCategory> listener : listeners) {
5218                                            listener.onBeforeAddAssociation(categoryId,
5219                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
5220                                                    entryId);
5221                                    }
5222    
5223                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
5224                                            listener.onBeforeAddAssociation(entryId,
5225                                                    AssetCategory.class.getName(), categoryId);
5226                                    }
5227    
5228                                    _sqlUpdate.update(new Object[] {
5229                                                    new Long(categoryId), new Long(entryId)
5230                                            });
5231    
5232                                    for (ModelListener<AssetCategory> listener : listeners) {
5233                                            listener.onAfterAddAssociation(categoryId,
5234                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
5235                                                    entryId);
5236                                    }
5237    
5238                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
5239                                            listener.onAfterAddAssociation(entryId,
5240                                                    AssetCategory.class.getName(), categoryId);
5241                                    }
5242                            }
5243                    }
5244    
5245                    private SqlUpdate _sqlUpdate;
5246                    private AssetCategoryPersistenceImpl _persistenceImpl;
5247            }
5248    
5249            protected class ClearAssetEntries {
5250                    protected ClearAssetEntries(
5251                            AssetCategoryPersistenceImpl persistenceImpl) {
5252                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5253                                            "DELETE FROM AssetEntries_AssetCategories WHERE categoryId = ?",
5254                                            new int[] { java.sql.Types.BIGINT });
5255                    }
5256    
5257                    protected void clear(long categoryId) throws SystemException {
5258                            ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
5259                                    assetEntryPersistence.getListeners();
5260    
5261                            List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = null;
5262    
5263                            if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
5264                                    assetEntries = getAssetEntries(categoryId);
5265    
5266                                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
5267                                            for (ModelListener<AssetCategory> listener : listeners) {
5268                                                    listener.onBeforeRemoveAssociation(categoryId,
5269                                                            com.liferay.portlet.asset.model.AssetEntry.class.getName(),
5270                                                            assetEntry.getPrimaryKey());
5271                                            }
5272    
5273                                            for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
5274                                                    listener.onBeforeRemoveAssociation(assetEntry.getPrimaryKey(),
5275                                                            AssetCategory.class.getName(), categoryId);
5276                                            }
5277                                    }
5278                            }
5279    
5280                            _sqlUpdate.update(new Object[] { new Long(categoryId) });
5281    
5282                            if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
5283                                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
5284                                            for (ModelListener<AssetCategory> listener : listeners) {
5285                                                    listener.onAfterRemoveAssociation(categoryId,
5286                                                            com.liferay.portlet.asset.model.AssetEntry.class.getName(),
5287                                                            assetEntry.getPrimaryKey());
5288                                            }
5289    
5290                                            for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
5291                                                    listener.onAfterRemoveAssociation(assetEntry.getPrimaryKey(),
5292                                                            AssetCategory.class.getName(), categoryId);
5293                                            }
5294                                    }
5295                            }
5296                    }
5297    
5298                    private SqlUpdate _sqlUpdate;
5299            }
5300    
5301            protected class RemoveAssetEntry {
5302                    protected RemoveAssetEntry(AssetCategoryPersistenceImpl persistenceImpl) {
5303                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5304                                            "DELETE FROM AssetEntries_AssetCategories WHERE categoryId = ? AND entryId = ?",
5305                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
5306                            _persistenceImpl = persistenceImpl;
5307                    }
5308    
5309                    protected void remove(long categoryId, long entryId)
5310                            throws SystemException {
5311                            if (_persistenceImpl.containsAssetEntry.contains(categoryId, entryId)) {
5312                                    ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
5313                                            assetEntryPersistence.getListeners();
5314    
5315                                    for (ModelListener<AssetCategory> listener : listeners) {
5316                                            listener.onBeforeRemoveAssociation(categoryId,
5317                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
5318                                                    entryId);
5319                                    }
5320    
5321                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
5322                                            listener.onBeforeRemoveAssociation(entryId,
5323                                                    AssetCategory.class.getName(), categoryId);
5324                                    }
5325    
5326                                    _sqlUpdate.update(new Object[] {
5327                                                    new Long(categoryId), new Long(entryId)
5328                                            });
5329    
5330                                    for (ModelListener<AssetCategory> listener : listeners) {
5331                                            listener.onAfterRemoveAssociation(categoryId,
5332                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
5333                                                    entryId);
5334                                    }
5335    
5336                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
5337                                            listener.onAfterRemoveAssociation(entryId,
5338                                                    AssetCategory.class.getName(), categoryId);
5339                                    }
5340                            }
5341                    }
5342    
5343                    private SqlUpdate _sqlUpdate;
5344                    private AssetCategoryPersistenceImpl _persistenceImpl;
5345            }
5346    
5347            protected ExpandTreeLeftCategoryId expandTreeLeftCategoryId;
5348            protected ExpandTreeRightCategoryId expandTreeRightCategoryId;
5349            protected ShrinkTreeLeftCategoryId shrinkTreeLeftCategoryId;
5350            protected ShrinkTreeRightCategoryId shrinkTreeRightCategoryId;
5351            protected UpdateTree updateTree;
5352    
5353            protected class ExpandTreeLeftCategoryId {
5354                    protected ExpandTreeLeftCategoryId() {
5355                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5356                                            "UPDATE AssetCategory SET leftCategoryId = (leftCategoryId + 2) WHERE (groupId = ?) AND (leftCategoryId > ?)",
5357                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
5358                    }
5359    
5360                    protected void expand(long groupId, long leftCategoryId) {
5361                            _sqlUpdate.update(new Object[] { groupId, leftCategoryId });
5362                    }
5363    
5364                    private SqlUpdate _sqlUpdate;
5365            }
5366    
5367            protected class ExpandTreeRightCategoryId {
5368                    protected ExpandTreeRightCategoryId() {
5369                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5370                                            "UPDATE AssetCategory SET rightCategoryId = (rightCategoryId + 2) WHERE (groupId = ?) AND (rightCategoryId > ?)",
5371                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
5372                    }
5373    
5374                    protected void expand(long groupId, long rightCategoryId) {
5375                            _sqlUpdate.update(new Object[] { groupId, rightCategoryId });
5376                    }
5377    
5378                    private SqlUpdate _sqlUpdate;
5379            }
5380    
5381            protected class ShrinkTreeLeftCategoryId {
5382                    protected ShrinkTreeLeftCategoryId() {
5383                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5384                                            "UPDATE AssetCategory SET leftCategoryId = (leftCategoryId - ?) WHERE (groupId = ?) AND (leftCategoryId > ?)",
5385                                            new int[] {
5386                                                    java.sql.Types.BIGINT, java.sql.Types.BIGINT,
5387                                                    java.sql.Types.BIGINT
5388                                            });
5389                    }
5390    
5391                    protected void shrink(long groupId, long leftCategoryId, long delta) {
5392                            _sqlUpdate.update(new Object[] { delta, groupId, leftCategoryId });
5393                    }
5394    
5395                    private SqlUpdate _sqlUpdate;
5396            }
5397    
5398            protected class ShrinkTreeRightCategoryId {
5399                    protected ShrinkTreeRightCategoryId() {
5400                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5401                                            "UPDATE AssetCategory SET rightCategoryId = (rightCategoryId - ?) WHERE (groupId = ?) AND (rightCategoryId > ?)",
5402                                            new int[] {
5403                                                    java.sql.Types.BIGINT, java.sql.Types.BIGINT,
5404                                                    java.sql.Types.BIGINT
5405                                            });
5406                    }
5407    
5408                    protected void shrink(long groupId, long rightCategoryId, long delta) {
5409                            _sqlUpdate.update(new Object[] { delta, groupId, rightCategoryId });
5410                    }
5411    
5412                    private SqlUpdate _sqlUpdate;
5413            }
5414    
5415            protected class UpdateTree {
5416                    protected UpdateTree() {
5417                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5418                                            "UPDATE AssetCategory SET leftCategoryId = ?, rightCategoryId = ? WHERE categoryId = ?",
5419                                            new int[] {
5420                                                    java.sql.Types.BIGINT, java.sql.Types.BIGINT,
5421                                                    java.sql.Types.BIGINT
5422                                            });
5423                    }
5424    
5425                    protected void update(long categoryId, long leftCategoryId,
5426                            long rightCategoryId) {
5427                            _sqlUpdate.update(new Object[] {
5428                                            leftCategoryId, rightCategoryId, categoryId
5429                                    });
5430                    }
5431    
5432                    private SqlUpdate _sqlUpdate;
5433            }
5434    
5435            private static final String _SQL_SELECT_ASSETCATEGORY = "SELECT assetCategory FROM AssetCategory assetCategory";
5436            private static final String _SQL_SELECT_ASSETCATEGORY_WHERE = "SELECT assetCategory FROM AssetCategory assetCategory WHERE ";
5437            private static final String _SQL_COUNT_ASSETCATEGORY = "SELECT COUNT(assetCategory) FROM AssetCategory assetCategory";
5438            private static final String _SQL_COUNT_ASSETCATEGORY_WHERE = "SELECT COUNT(assetCategory) FROM AssetCategory assetCategory WHERE ";
5439            private static final String _SQL_GETASSETENTRIES = "SELECT {AssetEntry.*} FROM AssetEntry INNER JOIN AssetEntries_AssetCategories ON (AssetEntries_AssetCategories.entryId = AssetEntry.entryId) WHERE (AssetEntries_AssetCategories.categoryId = ?)";
5440            private static final String _SQL_GETASSETENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetCategories WHERE categoryId = ?";
5441            private static final String _SQL_CONTAINSASSETENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetCategories WHERE categoryId = ? AND entryId = ?";
5442            private static final String _FINDER_COLUMN_UUID_UUID_1 = "assetCategory.uuid IS NULL";
5443            private static final String _FINDER_COLUMN_UUID_UUID_2 = "assetCategory.uuid = ?";
5444            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = ?)";
5445            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "assetCategory.uuid IS NULL AND ";
5446            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "assetCategory.uuid = ? AND ";
5447            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(assetCategory.uuid IS NULL OR assetCategory.uuid = ?) AND ";
5448            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "assetCategory.groupId = ?";
5449            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetCategory.groupId = ?";
5450            private static final String _FINDER_COLUMN_PARENTCATEGORYID_PARENTCATEGORYID_2 =
5451                    "assetCategory.parentCategoryId = ?";
5452            private static final String _FINDER_COLUMN_VOCABULARYID_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
5453            private static final String _FINDER_COLUMN_P_N_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
5454            private static final String _FINDER_COLUMN_P_N_NAME_1 = "assetCategory.name IS NULL";
5455            private static final String _FINDER_COLUMN_P_N_NAME_2 = "assetCategory.name = ?";
5456            private static final String _FINDER_COLUMN_P_N_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = ?)";
5457            private static final String _FINDER_COLUMN_P_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
5458            private static final String _FINDER_COLUMN_P_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
5459            private static final String _FINDER_COLUMN_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
5460            private static final String _FINDER_COLUMN_N_V_NAME_2 = "assetCategory.name = ? AND ";
5461            private static final String _FINDER_COLUMN_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = ?) AND ";
5462            private static final String _FINDER_COLUMN_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
5463            private static final String _FINDER_COLUMN_P_N_V_PARENTCATEGORYID_2 = "assetCategory.parentCategoryId = ? AND ";
5464            private static final String _FINDER_COLUMN_P_N_V_NAME_1 = "assetCategory.name IS NULL AND ";
5465            private static final String _FINDER_COLUMN_P_N_V_NAME_2 = "assetCategory.name = ? AND ";
5466            private static final String _FINDER_COLUMN_P_N_V_NAME_3 = "(assetCategory.name IS NULL OR assetCategory.name = ?) AND ";
5467            private static final String _FINDER_COLUMN_P_N_V_VOCABULARYID_2 = "assetCategory.vocabularyId = ?";
5468            private static final String _FILTER_SQL_SELECT_ASSETCATEGORY_WHERE = "SELECT DISTINCT {assetCategory.*} FROM AssetCategory assetCategory WHERE ";
5469            private static final String _FILTER_SQL_COUNT_ASSETCATEGORY_WHERE = "SELECT COUNT(DISTINCT assetCategory.categoryId) AS COUNT_VALUE FROM AssetCategory assetCategory WHERE ";
5470            private static final String _FILTER_COLUMN_PK = "assetCategory.categoryId";
5471            private static final String _FILTER_COLUMN_USERID = "assetCategory.userId";
5472            private static final String _FILTER_ENTITY_ALIAS = "assetCategory";
5473            private static final String _ORDER_BY_ENTITY_ALIAS = "assetCategory.";
5474            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetCategory exists with the primary key ";
5475            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetCategory exists with the key {";
5476            private static Log _log = LogFactoryUtil.getLog(AssetCategoryPersistenceImpl.class);
5477    }