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.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.BatchSessionUtil;
042    import com.liferay.portal.service.persistence.GroupPersistence;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.UserPersistence;
045    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046    
047    import com.liferay.portlet.asset.NoSuchVocabularyException;
048    import com.liferay.portlet.asset.model.AssetVocabulary;
049    import com.liferay.portlet.asset.model.impl.AssetVocabularyImpl;
050    import com.liferay.portlet.asset.model.impl.AssetVocabularyModelImpl;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    
058    /**
059     * The persistence for the asset vocabulary service.
060     *
061     * <p>
062     * Never modify this class directly. Modify <code>service.xml</code> and rerun ServiceBuilder to regnerate this class.
063     * </p>
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see AssetVocabularyPersistence
071     * @see AssetVocabularyUtil
072     * @generated
073     */
074    public class AssetVocabularyPersistenceImpl extends BasePersistenceImpl<AssetVocabulary>
075            implements AssetVocabularyPersistence {
076            public static final String FINDER_CLASS_NAME_ENTITY = AssetVocabularyImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
078                    ".List";
079            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
080                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
081                            FINDER_CLASS_NAME_LIST, "findByUuid",
082                            new String[] {
083                                    String.class.getName(),
084                                    
085                            "java.lang.Integer", "java.lang.Integer",
086                                    "com.liferay.portal.kernel.util.OrderByComparator"
087                            });
088            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
089                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
090                            FINDER_CLASS_NAME_LIST, "countByUuid",
091                            new String[] { String.class.getName() });
092            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
093                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
094                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
095                            new String[] { String.class.getName(), Long.class.getName() });
096            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
097                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
098                            FINDER_CLASS_NAME_LIST, "countByUUID_G",
099                            new String[] { String.class.getName(), Long.class.getName() });
100            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
101                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
102                            FINDER_CLASS_NAME_LIST, "findByGroupId",
103                            new String[] {
104                                    Long.class.getName(),
105                                    
106                            "java.lang.Integer", "java.lang.Integer",
107                                    "com.liferay.portal.kernel.util.OrderByComparator"
108                            });
109            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
110                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
111                            FINDER_CLASS_NAME_LIST, "countByGroupId",
112                            new String[] { Long.class.getName() });
113            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
114                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
115                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
116                            new String[] {
117                                    Long.class.getName(),
118                                    
119                            "java.lang.Integer", "java.lang.Integer",
120                                    "com.liferay.portal.kernel.util.OrderByComparator"
121                            });
122            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
123                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
124                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
125                            new String[] { Long.class.getName() });
126            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
127                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
128                            FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
129                            new String[] { Long.class.getName(), String.class.getName() });
130            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
131                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
132                            FINDER_CLASS_NAME_LIST, "countByG_N",
133                            new String[] { Long.class.getName(), String.class.getName() });
134            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
135                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
136                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
137            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
138                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
139                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
140    
141            /**
142             * Caches the asset vocabulary in the entity cache if it is enabled.
143             *
144             * @param assetVocabulary the asset vocabulary to cache
145             */
146            public void cacheResult(AssetVocabulary assetVocabulary) {
147                    EntityCacheUtil.putResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
148                            AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey(),
149                            assetVocabulary);
150    
151                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
152                            new Object[] {
153                                    assetVocabulary.getUuid(),
154                                    new Long(assetVocabulary.getGroupId())
155                            }, assetVocabulary);
156    
157                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
158                            new Object[] {
159                                    new Long(assetVocabulary.getGroupId()),
160                                    
161                            assetVocabulary.getName()
162                            }, assetVocabulary);
163            }
164    
165            /**
166             * Caches the asset vocabularies in the entity cache if it is enabled.
167             *
168             * @param assetVocabularies the asset vocabularies to cache
169             */
170            public void cacheResult(List<AssetVocabulary> assetVocabularies) {
171                    for (AssetVocabulary assetVocabulary : assetVocabularies) {
172                            if (EntityCacheUtil.getResult(
173                                                    AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
174                                                    AssetVocabularyImpl.class,
175                                                    assetVocabulary.getPrimaryKey(), this) == null) {
176                                    cacheResult(assetVocabulary);
177                            }
178                    }
179            }
180    
181            /**
182             * Clears the cache for all asset vocabularies.
183             *
184             * <p>
185             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
186             * </p>
187             */
188            public void clearCache() {
189                    CacheRegistryUtil.clear(AssetVocabularyImpl.class.getName());
190                    EntityCacheUtil.clearCache(AssetVocabularyImpl.class.getName());
191                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
192                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
193            }
194    
195            /**
196             * Clears the cache for the asset vocabulary.
197             *
198             * <p>
199             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
200             * </p>
201             */
202            public void clearCache(AssetVocabulary assetVocabulary) {
203                    EntityCacheUtil.removeResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
204                            AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey());
205    
206                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
207                            new Object[] {
208                                    assetVocabulary.getUuid(),
209                                    new Long(assetVocabulary.getGroupId())
210                            });
211    
212                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
213                            new Object[] {
214                                    new Long(assetVocabulary.getGroupId()),
215                                    
216                            assetVocabulary.getName()
217                            });
218            }
219    
220            /**
221             * Creates a new asset vocabulary with the primary key.
222             *
223             * @param vocabularyId the primary key for the new asset vocabulary
224             * @return the new asset vocabulary
225             */
226            public AssetVocabulary create(long vocabularyId) {
227                    AssetVocabulary assetVocabulary = new AssetVocabularyImpl();
228    
229                    assetVocabulary.setNew(true);
230                    assetVocabulary.setPrimaryKey(vocabularyId);
231    
232                    String uuid = PortalUUIDUtil.generate();
233    
234                    assetVocabulary.setUuid(uuid);
235    
236                    return assetVocabulary;
237            }
238    
239            /**
240             * Removes the asset vocabulary with the primary key from the database. Also notifies the appropriate model listeners.
241             *
242             * @param primaryKey the primary key of the asset vocabulary to remove
243             * @return the asset vocabulary that was removed
244             * @throws com.liferay.portal.NoSuchModelException if a asset vocabulary with the primary key could not be found
245             * @throws SystemException if a system exception occurred
246             */
247            public AssetVocabulary remove(Serializable primaryKey)
248                    throws NoSuchModelException, SystemException {
249                    return remove(((Long)primaryKey).longValue());
250            }
251    
252            /**
253             * Removes the asset vocabulary with the primary key from the database. Also notifies the appropriate model listeners.
254             *
255             * @param vocabularyId the primary key of the asset vocabulary to remove
256             * @return the asset vocabulary that was removed
257             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a asset vocabulary with the primary key could not be found
258             * @throws SystemException if a system exception occurred
259             */
260            public AssetVocabulary remove(long vocabularyId)
261                    throws NoSuchVocabularyException, SystemException {
262                    Session session = null;
263    
264                    try {
265                            session = openSession();
266    
267                            AssetVocabulary assetVocabulary = (AssetVocabulary)session.get(AssetVocabularyImpl.class,
268                                            new Long(vocabularyId));
269    
270                            if (assetVocabulary == null) {
271                                    if (_log.isWarnEnabled()) {
272                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + vocabularyId);
273                                    }
274    
275                                    throw new NoSuchVocabularyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
276                                            vocabularyId);
277                            }
278    
279                            return remove(assetVocabulary);
280                    }
281                    catch (NoSuchVocabularyException nsee) {
282                            throw nsee;
283                    }
284                    catch (Exception e) {
285                            throw processException(e);
286                    }
287                    finally {
288                            closeSession(session);
289                    }
290            }
291    
292            protected AssetVocabulary removeImpl(AssetVocabulary assetVocabulary)
293                    throws SystemException {
294                    assetVocabulary = toUnwrappedModel(assetVocabulary);
295    
296                    Session session = null;
297    
298                    try {
299                            session = openSession();
300    
301                            if (assetVocabulary.isCachedModel() ||
302                                            BatchSessionUtil.isEnabled()) {
303                                    Object staleObject = session.get(AssetVocabularyImpl.class,
304                                                    assetVocabulary.getPrimaryKeyObj());
305    
306                                    if (staleObject != null) {
307                                            session.evict(staleObject);
308                                    }
309                            }
310    
311                            session.delete(assetVocabulary);
312    
313                            session.flush();
314                    }
315                    catch (Exception e) {
316                            throw processException(e);
317                    }
318                    finally {
319                            closeSession(session);
320                    }
321    
322                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
323    
324                    AssetVocabularyModelImpl assetVocabularyModelImpl = (AssetVocabularyModelImpl)assetVocabulary;
325    
326                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
327                            new Object[] {
328                                    assetVocabularyModelImpl.getOriginalUuid(),
329                                    new Long(assetVocabularyModelImpl.getOriginalGroupId())
330                            });
331    
332                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
333                            new Object[] {
334                                    new Long(assetVocabularyModelImpl.getOriginalGroupId()),
335                                    
336                            assetVocabularyModelImpl.getOriginalName()
337                            });
338    
339                    EntityCacheUtil.removeResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
340                            AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey());
341    
342                    return assetVocabulary;
343            }
344    
345            public AssetVocabulary updateImpl(
346                    com.liferay.portlet.asset.model.AssetVocabulary assetVocabulary,
347                    boolean merge) throws SystemException {
348                    assetVocabulary = toUnwrappedModel(assetVocabulary);
349    
350                    boolean isNew = assetVocabulary.isNew();
351    
352                    AssetVocabularyModelImpl assetVocabularyModelImpl = (AssetVocabularyModelImpl)assetVocabulary;
353    
354                    if (Validator.isNull(assetVocabulary.getUuid())) {
355                            String uuid = PortalUUIDUtil.generate();
356    
357                            assetVocabulary.setUuid(uuid);
358                    }
359    
360                    Session session = null;
361    
362                    try {
363                            session = openSession();
364    
365                            BatchSessionUtil.update(session, assetVocabulary, merge);
366    
367                            assetVocabulary.setNew(false);
368                    }
369                    catch (Exception e) {
370                            throw processException(e);
371                    }
372                    finally {
373                            closeSession(session);
374                    }
375    
376                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
377    
378                    EntityCacheUtil.putResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
379                            AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey(),
380                            assetVocabulary);
381    
382                    if (!isNew &&
383                                    (!Validator.equals(assetVocabulary.getUuid(),
384                                            assetVocabularyModelImpl.getOriginalUuid()) ||
385                                    (assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()))) {
386                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
387                                    new Object[] {
388                                            assetVocabularyModelImpl.getOriginalUuid(),
389                                            new Long(assetVocabularyModelImpl.getOriginalGroupId())
390                                    });
391                    }
392    
393                    if (isNew ||
394                                    (!Validator.equals(assetVocabulary.getUuid(),
395                                            assetVocabularyModelImpl.getOriginalUuid()) ||
396                                    (assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()))) {
397                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
398                                    new Object[] {
399                                            assetVocabulary.getUuid(),
400                                            new Long(assetVocabulary.getGroupId())
401                                    }, assetVocabulary);
402                    }
403    
404                    if (!isNew &&
405                                    ((assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()) ||
406                                    !Validator.equals(assetVocabulary.getName(),
407                                            assetVocabularyModelImpl.getOriginalName()))) {
408                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
409                                    new Object[] {
410                                            new Long(assetVocabularyModelImpl.getOriginalGroupId()),
411                                            
412                                    assetVocabularyModelImpl.getOriginalName()
413                                    });
414                    }
415    
416                    if (isNew ||
417                                    ((assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()) ||
418                                    !Validator.equals(assetVocabulary.getName(),
419                                            assetVocabularyModelImpl.getOriginalName()))) {
420                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
421                                    new Object[] {
422                                            new Long(assetVocabulary.getGroupId()),
423                                            
424                                    assetVocabulary.getName()
425                                    }, assetVocabulary);
426                    }
427    
428                    return assetVocabulary;
429            }
430    
431            protected AssetVocabulary toUnwrappedModel(AssetVocabulary assetVocabulary) {
432                    if (assetVocabulary instanceof AssetVocabularyImpl) {
433                            return assetVocabulary;
434                    }
435    
436                    AssetVocabularyImpl assetVocabularyImpl = new AssetVocabularyImpl();
437    
438                    assetVocabularyImpl.setNew(assetVocabulary.isNew());
439                    assetVocabularyImpl.setPrimaryKey(assetVocabulary.getPrimaryKey());
440    
441                    assetVocabularyImpl.setUuid(assetVocabulary.getUuid());
442                    assetVocabularyImpl.setVocabularyId(assetVocabulary.getVocabularyId());
443                    assetVocabularyImpl.setGroupId(assetVocabulary.getGroupId());
444                    assetVocabularyImpl.setCompanyId(assetVocabulary.getCompanyId());
445                    assetVocabularyImpl.setUserId(assetVocabulary.getUserId());
446                    assetVocabularyImpl.setUserName(assetVocabulary.getUserName());
447                    assetVocabularyImpl.setCreateDate(assetVocabulary.getCreateDate());
448                    assetVocabularyImpl.setModifiedDate(assetVocabulary.getModifiedDate());
449                    assetVocabularyImpl.setName(assetVocabulary.getName());
450                    assetVocabularyImpl.setTitle(assetVocabulary.getTitle());
451                    assetVocabularyImpl.setDescription(assetVocabulary.getDescription());
452                    assetVocabularyImpl.setSettings(assetVocabulary.getSettings());
453    
454                    return assetVocabularyImpl;
455            }
456    
457            /**
458             * Finds the asset vocabulary with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
459             *
460             * @param primaryKey the primary key of the asset vocabulary to find
461             * @return the asset vocabulary
462             * @throws com.liferay.portal.NoSuchModelException if a asset vocabulary with the primary key could not be found
463             * @throws SystemException if a system exception occurred
464             */
465            public AssetVocabulary findByPrimaryKey(Serializable primaryKey)
466                    throws NoSuchModelException, SystemException {
467                    return findByPrimaryKey(((Long)primaryKey).longValue());
468            }
469    
470            /**
471             * Finds the asset vocabulary with the primary key or throws a {@link com.liferay.portlet.asset.NoSuchVocabularyException} if it could not be found.
472             *
473             * @param vocabularyId the primary key of the asset vocabulary to find
474             * @return the asset vocabulary
475             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a asset vocabulary with the primary key could not be found
476             * @throws SystemException if a system exception occurred
477             */
478            public AssetVocabulary findByPrimaryKey(long vocabularyId)
479                    throws NoSuchVocabularyException, SystemException {
480                    AssetVocabulary assetVocabulary = fetchByPrimaryKey(vocabularyId);
481    
482                    if (assetVocabulary == null) {
483                            if (_log.isWarnEnabled()) {
484                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + vocabularyId);
485                            }
486    
487                            throw new NoSuchVocabularyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
488                                    vocabularyId);
489                    }
490    
491                    return assetVocabulary;
492            }
493    
494            /**
495             * Finds the asset vocabulary with the primary key or returns <code>null</code> if it could not be found.
496             *
497             * @param primaryKey the primary key of the asset vocabulary to find
498             * @return the asset vocabulary, or <code>null</code> if a asset vocabulary with the primary key could not be found
499             * @throws SystemException if a system exception occurred
500             */
501            public AssetVocabulary fetchByPrimaryKey(Serializable primaryKey)
502                    throws SystemException {
503                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
504            }
505    
506            /**
507             * Finds the asset vocabulary with the primary key or returns <code>null</code> if it could not be found.
508             *
509             * @param vocabularyId the primary key of the asset vocabulary to find
510             * @return the asset vocabulary, or <code>null</code> if a asset vocabulary with the primary key could not be found
511             * @throws SystemException if a system exception occurred
512             */
513            public AssetVocabulary fetchByPrimaryKey(long vocabularyId)
514                    throws SystemException {
515                    AssetVocabulary assetVocabulary = (AssetVocabulary)EntityCacheUtil.getResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
516                                    AssetVocabularyImpl.class, vocabularyId, this);
517    
518                    if (assetVocabulary == null) {
519                            Session session = null;
520    
521                            try {
522                                    session = openSession();
523    
524                                    assetVocabulary = (AssetVocabulary)session.get(AssetVocabularyImpl.class,
525                                                    new Long(vocabularyId));
526                            }
527                            catch (Exception e) {
528                                    throw processException(e);
529                            }
530                            finally {
531                                    if (assetVocabulary != null) {
532                                            cacheResult(assetVocabulary);
533                                    }
534    
535                                    closeSession(session);
536                            }
537                    }
538    
539                    return assetVocabulary;
540            }
541    
542            /**
543             * Finds all the asset vocabularies where uuid = &#63;.
544             *
545             * @param uuid the uuid to search with
546             * @return the matching asset vocabularies
547             * @throws SystemException if a system exception occurred
548             */
549            public List<AssetVocabulary> findByUuid(String uuid)
550                    throws SystemException {
551                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
552            }
553    
554            /**
555             * Finds a range of all the asset vocabularies where uuid = &#63;.
556             *
557             * <p>
558             * 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.
559             * </p>
560             *
561             * @param uuid the uuid to search with
562             * @param start the lower bound of the range of asset vocabularies to return
563             * @param end the upper bound of the range of asset vocabularies to return (not inclusive)
564             * @return the range of matching asset vocabularies
565             * @throws SystemException if a system exception occurred
566             */
567            public List<AssetVocabulary> findByUuid(String uuid, int start, int end)
568                    throws SystemException {
569                    return findByUuid(uuid, start, end, null);
570            }
571    
572            /**
573             * Finds an ordered range of all the asset vocabularies where uuid = &#63;.
574             *
575             * <p>
576             * 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.
577             * </p>
578             *
579             * @param uuid the uuid to search with
580             * @param start the lower bound of the range of asset vocabularies to return
581             * @param end the upper bound of the range of asset vocabularies to return (not inclusive)
582             * @param orderByComparator the comparator to order the results by
583             * @return the ordered range of matching asset vocabularies
584             * @throws SystemException if a system exception occurred
585             */
586            public List<AssetVocabulary> findByUuid(String uuid, int start, int end,
587                    OrderByComparator orderByComparator) throws SystemException {
588                    Object[] finderArgs = new Object[] {
589                                    uuid,
590                                    
591                                    String.valueOf(start), String.valueOf(end),
592                                    String.valueOf(orderByComparator)
593                            };
594    
595                    List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
596                                    finderArgs, this);
597    
598                    if (list == null) {
599                            Session session = null;
600    
601                            try {
602                                    session = openSession();
603    
604                                    StringBundler query = null;
605    
606                                    if (orderByComparator != null) {
607                                            query = new StringBundler(3 +
608                                                            (orderByComparator.getOrderByFields().length * 3));
609                                    }
610                                    else {
611                                            query = new StringBundler(3);
612                                    }
613    
614                                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
615    
616                                    if (uuid == null) {
617                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
618                                    }
619                                    else {
620                                            if (uuid.equals(StringPool.BLANK)) {
621                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
622                                            }
623                                            else {
624                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
625                                            }
626                                    }
627    
628                                    if (orderByComparator != null) {
629                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
630                                                    orderByComparator);
631                                    }
632    
633                                    else {
634                                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
635                                    }
636    
637                                    String sql = query.toString();
638    
639                                    Query q = session.createQuery(sql);
640    
641                                    QueryPos qPos = QueryPos.getInstance(q);
642    
643                                    if (uuid != null) {
644                                            qPos.add(uuid);
645                                    }
646    
647                                    list = (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
648                                                    start, end);
649                            }
650                            catch (Exception e) {
651                                    throw processException(e);
652                            }
653                            finally {
654                                    if (list == null) {
655                                            list = new ArrayList<AssetVocabulary>();
656                                    }
657    
658                                    cacheResult(list);
659    
660                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
661                                            list);
662    
663                                    closeSession(session);
664                            }
665                    }
666    
667                    return list;
668            }
669    
670            /**
671             * Finds the first asset vocabulary in the ordered set where uuid = &#63;.
672             *
673             * <p>
674             * 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.
675             * </p>
676             *
677             * @param uuid the uuid to search with
678             * @param orderByComparator the comparator to order the set by
679             * @return the first matching asset vocabulary
680             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a matching asset vocabulary could not be found
681             * @throws SystemException if a system exception occurred
682             */
683            public AssetVocabulary findByUuid_First(String uuid,
684                    OrderByComparator orderByComparator)
685                    throws NoSuchVocabularyException, SystemException {
686                    List<AssetVocabulary> list = findByUuid(uuid, 0, 1, orderByComparator);
687    
688                    if (list.isEmpty()) {
689                            StringBundler msg = new StringBundler(4);
690    
691                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
692    
693                            msg.append("uuid=");
694                            msg.append(uuid);
695    
696                            msg.append(StringPool.CLOSE_CURLY_BRACE);
697    
698                            throw new NoSuchVocabularyException(msg.toString());
699                    }
700                    else {
701                            return list.get(0);
702                    }
703            }
704    
705            /**
706             * Finds the last asset vocabulary in the ordered set where uuid = &#63;.
707             *
708             * <p>
709             * 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.
710             * </p>
711             *
712             * @param uuid the uuid to search with
713             * @param orderByComparator the comparator to order the set by
714             * @return the last matching asset vocabulary
715             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a matching asset vocabulary could not be found
716             * @throws SystemException if a system exception occurred
717             */
718            public AssetVocabulary findByUuid_Last(String uuid,
719                    OrderByComparator orderByComparator)
720                    throws NoSuchVocabularyException, SystemException {
721                    int count = countByUuid(uuid);
722    
723                    List<AssetVocabulary> list = findByUuid(uuid, count - 1, count,
724                                    orderByComparator);
725    
726                    if (list.isEmpty()) {
727                            StringBundler msg = new StringBundler(4);
728    
729                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
730    
731                            msg.append("uuid=");
732                            msg.append(uuid);
733    
734                            msg.append(StringPool.CLOSE_CURLY_BRACE);
735    
736                            throw new NoSuchVocabularyException(msg.toString());
737                    }
738                    else {
739                            return list.get(0);
740                    }
741            }
742    
743            /**
744             * Finds the asset vocabularies before and after the current asset vocabulary in the ordered set where uuid = &#63;.
745             *
746             * <p>
747             * 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.
748             * </p>
749             *
750             * @param vocabularyId the primary key of the current asset vocabulary
751             * @param uuid the uuid to search with
752             * @param orderByComparator the comparator to order the set by
753             * @return the previous, current, and next asset vocabulary
754             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a asset vocabulary with the primary key could not be found
755             * @throws SystemException if a system exception occurred
756             */
757            public AssetVocabulary[] findByUuid_PrevAndNext(long vocabularyId,
758                    String uuid, OrderByComparator orderByComparator)
759                    throws NoSuchVocabularyException, SystemException {
760                    AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
761    
762                    Session session = null;
763    
764                    try {
765                            session = openSession();
766    
767                            AssetVocabulary[] array = new AssetVocabularyImpl[3];
768    
769                            array[0] = getByUuid_PrevAndNext(session, assetVocabulary, uuid,
770                                            orderByComparator, true);
771    
772                            array[1] = assetVocabulary;
773    
774                            array[2] = getByUuid_PrevAndNext(session, assetVocabulary, uuid,
775                                            orderByComparator, false);
776    
777                            return array;
778                    }
779                    catch (Exception e) {
780                            throw processException(e);
781                    }
782                    finally {
783                            closeSession(session);
784                    }
785            }
786    
787            protected AssetVocabulary getByUuid_PrevAndNext(Session session,
788                    AssetVocabulary assetVocabulary, String uuid,
789                    OrderByComparator orderByComparator, boolean previous) {
790                    StringBundler query = null;
791    
792                    if (orderByComparator != null) {
793                            query = new StringBundler(6 +
794                                            (orderByComparator.getOrderByFields().length * 6));
795                    }
796                    else {
797                            query = new StringBundler(3);
798                    }
799    
800                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
801    
802                    if (uuid == null) {
803                            query.append(_FINDER_COLUMN_UUID_UUID_1);
804                    }
805                    else {
806                            if (uuid.equals(StringPool.BLANK)) {
807                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
808                            }
809                            else {
810                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
811                            }
812                    }
813    
814                    if (orderByComparator != null) {
815                            String[] orderByFields = orderByComparator.getOrderByFields();
816    
817                            if (orderByFields.length > 0) {
818                                    query.append(WHERE_AND);
819                            }
820    
821                            for (int i = 0; i < orderByFields.length; i++) {
822                                    query.append(_ORDER_BY_ENTITY_ALIAS);
823                                    query.append(orderByFields[i]);
824    
825                                    if ((i + 1) < orderByFields.length) {
826                                            if (orderByComparator.isAscending() ^ previous) {
827                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
828                                            }
829                                            else {
830                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
831                                            }
832                                    }
833                                    else {
834                                            if (orderByComparator.isAscending() ^ previous) {
835                                                    query.append(WHERE_GREATER_THAN);
836                                            }
837                                            else {
838                                                    query.append(WHERE_LESSER_THAN);
839                                            }
840                                    }
841                            }
842    
843                            query.append(ORDER_BY_CLAUSE);
844    
845                            for (int i = 0; i < orderByFields.length; i++) {
846                                    query.append(_ORDER_BY_ENTITY_ALIAS);
847                                    query.append(orderByFields[i]);
848    
849                                    if ((i + 1) < orderByFields.length) {
850                                            if (orderByComparator.isAscending() ^ previous) {
851                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
852                                            }
853                                            else {
854                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
855                                            }
856                                    }
857                                    else {
858                                            if (orderByComparator.isAscending() ^ previous) {
859                                                    query.append(ORDER_BY_ASC);
860                                            }
861                                            else {
862                                                    query.append(ORDER_BY_DESC);
863                                            }
864                                    }
865                            }
866                    }
867    
868                    else {
869                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
870                    }
871    
872                    String sql = query.toString();
873    
874                    Query q = session.createQuery(sql);
875    
876                    q.setFirstResult(0);
877                    q.setMaxResults(2);
878    
879                    QueryPos qPos = QueryPos.getInstance(q);
880    
881                    if (uuid != null) {
882                            qPos.add(uuid);
883                    }
884    
885                    if (orderByComparator != null) {
886                            Object[] values = orderByComparator.getOrderByValues(assetVocabulary);
887    
888                            for (Object value : values) {
889                                    qPos.add(value);
890                            }
891                    }
892    
893                    List<AssetVocabulary> list = q.list();
894    
895                    if (list.size() == 2) {
896                            return list.get(1);
897                    }
898                    else {
899                            return null;
900                    }
901            }
902    
903            /**
904             * Finds the asset vocabulary where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchVocabularyException} if it could not be found.
905             *
906             * @param uuid the uuid to search with
907             * @param groupId the group id to search with
908             * @return the matching asset vocabulary
909             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a matching asset vocabulary could not be found
910             * @throws SystemException if a system exception occurred
911             */
912            public AssetVocabulary findByUUID_G(String uuid, long groupId)
913                    throws NoSuchVocabularyException, SystemException {
914                    AssetVocabulary assetVocabulary = fetchByUUID_G(uuid, groupId);
915    
916                    if (assetVocabulary == null) {
917                            StringBundler msg = new StringBundler(6);
918    
919                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
920    
921                            msg.append("uuid=");
922                            msg.append(uuid);
923    
924                            msg.append(", groupId=");
925                            msg.append(groupId);
926    
927                            msg.append(StringPool.CLOSE_CURLY_BRACE);
928    
929                            if (_log.isWarnEnabled()) {
930                                    _log.warn(msg.toString());
931                            }
932    
933                            throw new NoSuchVocabularyException(msg.toString());
934                    }
935    
936                    return assetVocabulary;
937            }
938    
939            /**
940             * Finds the asset vocabulary where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
941             *
942             * @param uuid the uuid to search with
943             * @param groupId the group id to search with
944             * @return the matching asset vocabulary, or <code>null</code> if a matching asset vocabulary could not be found
945             * @throws SystemException if a system exception occurred
946             */
947            public AssetVocabulary fetchByUUID_G(String uuid, long groupId)
948                    throws SystemException {
949                    return fetchByUUID_G(uuid, groupId, true);
950            }
951    
952            /**
953             * Finds the asset vocabulary where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
954             *
955             * @param uuid the uuid to search with
956             * @param groupId the group id to search with
957             * @return the matching asset vocabulary, or <code>null</code> if a matching asset vocabulary could not be found
958             * @throws SystemException if a system exception occurred
959             */
960            public AssetVocabulary fetchByUUID_G(String uuid, long groupId,
961                    boolean retrieveFromCache) throws SystemException {
962                    Object[] finderArgs = new Object[] { uuid, groupId };
963    
964                    Object result = null;
965    
966                    if (retrieveFromCache) {
967                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
968                                            finderArgs, this);
969                    }
970    
971                    if (result == null) {
972                            Session session = null;
973    
974                            try {
975                                    session = openSession();
976    
977                                    StringBundler query = new StringBundler(4);
978    
979                                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
980    
981                                    if (uuid == null) {
982                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
983                                    }
984                                    else {
985                                            if (uuid.equals(StringPool.BLANK)) {
986                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
987                                            }
988                                            else {
989                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
990                                            }
991                                    }
992    
993                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
994    
995                                    query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
996    
997                                    String sql = query.toString();
998    
999                                    Query q = session.createQuery(sql);
1000    
1001                                    QueryPos qPos = QueryPos.getInstance(q);
1002    
1003                                    if (uuid != null) {
1004                                            qPos.add(uuid);
1005                                    }
1006    
1007                                    qPos.add(groupId);
1008    
1009                                    List<AssetVocabulary> list = q.list();
1010    
1011                                    result = list;
1012    
1013                                    AssetVocabulary assetVocabulary = null;
1014    
1015                                    if (list.isEmpty()) {
1016                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1017                                                    finderArgs, list);
1018                                    }
1019                                    else {
1020                                            assetVocabulary = list.get(0);
1021    
1022                                            cacheResult(assetVocabulary);
1023    
1024                                            if ((assetVocabulary.getUuid() == null) ||
1025                                                            !assetVocabulary.getUuid().equals(uuid) ||
1026                                                            (assetVocabulary.getGroupId() != groupId)) {
1027                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1028                                                            finderArgs, assetVocabulary);
1029                                            }
1030                                    }
1031    
1032                                    return assetVocabulary;
1033                            }
1034                            catch (Exception e) {
1035                                    throw processException(e);
1036                            }
1037                            finally {
1038                                    if (result == null) {
1039                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1040                                                    finderArgs, new ArrayList<AssetVocabulary>());
1041                                    }
1042    
1043                                    closeSession(session);
1044                            }
1045                    }
1046                    else {
1047                            if (result instanceof List<?>) {
1048                                    return null;
1049                            }
1050                            else {
1051                                    return (AssetVocabulary)result;
1052                            }
1053                    }
1054            }
1055    
1056            /**
1057             * Finds all the asset vocabularies where groupId = &#63;.
1058             *
1059             * @param groupId the group id to search with
1060             * @return the matching asset vocabularies
1061             * @throws SystemException if a system exception occurred
1062             */
1063            public List<AssetVocabulary> findByGroupId(long groupId)
1064                    throws SystemException {
1065                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1066            }
1067    
1068            /**
1069             * Finds a range of all the asset vocabularies where groupId = &#63;.
1070             *
1071             * <p>
1072             * 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.
1073             * </p>
1074             *
1075             * @param groupId the group id to search with
1076             * @param start the lower bound of the range of asset vocabularies to return
1077             * @param end the upper bound of the range of asset vocabularies to return (not inclusive)
1078             * @return the range of matching asset vocabularies
1079             * @throws SystemException if a system exception occurred
1080             */
1081            public List<AssetVocabulary> findByGroupId(long groupId, int start, int end)
1082                    throws SystemException {
1083                    return findByGroupId(groupId, start, end, null);
1084            }
1085    
1086            /**
1087             * Finds an ordered range of all the asset vocabularies where groupId = &#63;.
1088             *
1089             * <p>
1090             * 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.
1091             * </p>
1092             *
1093             * @param groupId the group id to search with
1094             * @param start the lower bound of the range of asset vocabularies to return
1095             * @param end the upper bound of the range of asset vocabularies to return (not inclusive)
1096             * @param orderByComparator the comparator to order the results by
1097             * @return the ordered range of matching asset vocabularies
1098             * @throws SystemException if a system exception occurred
1099             */
1100            public List<AssetVocabulary> findByGroupId(long groupId, int start,
1101                    int end, OrderByComparator orderByComparator) throws SystemException {
1102                    Object[] finderArgs = new Object[] {
1103                                    groupId,
1104                                    
1105                                    String.valueOf(start), String.valueOf(end),
1106                                    String.valueOf(orderByComparator)
1107                            };
1108    
1109                    List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1110                                    finderArgs, this);
1111    
1112                    if (list == null) {
1113                            Session session = null;
1114    
1115                            try {
1116                                    session = openSession();
1117    
1118                                    StringBundler query = null;
1119    
1120                                    if (orderByComparator != null) {
1121                                            query = new StringBundler(3 +
1122                                                            (orderByComparator.getOrderByFields().length * 3));
1123                                    }
1124                                    else {
1125                                            query = new StringBundler(3);
1126                                    }
1127    
1128                                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1129    
1130                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1131    
1132                                    if (orderByComparator != null) {
1133                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1134                                                    orderByComparator);
1135                                    }
1136    
1137                                    else {
1138                                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1139                                    }
1140    
1141                                    String sql = query.toString();
1142    
1143                                    Query q = session.createQuery(sql);
1144    
1145                                    QueryPos qPos = QueryPos.getInstance(q);
1146    
1147                                    qPos.add(groupId);
1148    
1149                                    list = (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
1150                                                    start, end);
1151                            }
1152                            catch (Exception e) {
1153                                    throw processException(e);
1154                            }
1155                            finally {
1156                                    if (list == null) {
1157                                            list = new ArrayList<AssetVocabulary>();
1158                                    }
1159    
1160                                    cacheResult(list);
1161    
1162                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1163                                            finderArgs, list);
1164    
1165                                    closeSession(session);
1166                            }
1167                    }
1168    
1169                    return list;
1170            }
1171    
1172            /**
1173             * Finds the first asset vocabulary in the ordered set where groupId = &#63;.
1174             *
1175             * <p>
1176             * 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.
1177             * </p>
1178             *
1179             * @param groupId the group id to search with
1180             * @param orderByComparator the comparator to order the set by
1181             * @return the first matching asset vocabulary
1182             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a matching asset vocabulary could not be found
1183             * @throws SystemException if a system exception occurred
1184             */
1185            public AssetVocabulary findByGroupId_First(long groupId,
1186                    OrderByComparator orderByComparator)
1187                    throws NoSuchVocabularyException, SystemException {
1188                    List<AssetVocabulary> list = findByGroupId(groupId, 0, 1,
1189                                    orderByComparator);
1190    
1191                    if (list.isEmpty()) {
1192                            StringBundler msg = new StringBundler(4);
1193    
1194                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1195    
1196                            msg.append("groupId=");
1197                            msg.append(groupId);
1198    
1199                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1200    
1201                            throw new NoSuchVocabularyException(msg.toString());
1202                    }
1203                    else {
1204                            return list.get(0);
1205                    }
1206            }
1207    
1208            /**
1209             * Finds the last asset vocabulary in the ordered set where groupId = &#63;.
1210             *
1211             * <p>
1212             * 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.
1213             * </p>
1214             *
1215             * @param groupId the group id to search with
1216             * @param orderByComparator the comparator to order the set by
1217             * @return the last matching asset vocabulary
1218             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a matching asset vocabulary could not be found
1219             * @throws SystemException if a system exception occurred
1220             */
1221            public AssetVocabulary findByGroupId_Last(long groupId,
1222                    OrderByComparator orderByComparator)
1223                    throws NoSuchVocabularyException, SystemException {
1224                    int count = countByGroupId(groupId);
1225    
1226                    List<AssetVocabulary> list = findByGroupId(groupId, count - 1, count,
1227                                    orderByComparator);
1228    
1229                    if (list.isEmpty()) {
1230                            StringBundler msg = new StringBundler(4);
1231    
1232                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1233    
1234                            msg.append("groupId=");
1235                            msg.append(groupId);
1236    
1237                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1238    
1239                            throw new NoSuchVocabularyException(msg.toString());
1240                    }
1241                    else {
1242                            return list.get(0);
1243                    }
1244            }
1245    
1246            /**
1247             * Finds the asset vocabularies before and after the current asset vocabulary in the ordered set where groupId = &#63;.
1248             *
1249             * <p>
1250             * 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.
1251             * </p>
1252             *
1253             * @param vocabularyId the primary key of the current asset vocabulary
1254             * @param groupId the group id to search with
1255             * @param orderByComparator the comparator to order the set by
1256             * @return the previous, current, and next asset vocabulary
1257             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a asset vocabulary with the primary key could not be found
1258             * @throws SystemException if a system exception occurred
1259             */
1260            public AssetVocabulary[] findByGroupId_PrevAndNext(long vocabularyId,
1261                    long groupId, OrderByComparator orderByComparator)
1262                    throws NoSuchVocabularyException, SystemException {
1263                    AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
1264    
1265                    Session session = null;
1266    
1267                    try {
1268                            session = openSession();
1269    
1270                            AssetVocabulary[] array = new AssetVocabularyImpl[3];
1271    
1272                            array[0] = getByGroupId_PrevAndNext(session, assetVocabulary,
1273                                            groupId, orderByComparator, true);
1274    
1275                            array[1] = assetVocabulary;
1276    
1277                            array[2] = getByGroupId_PrevAndNext(session, assetVocabulary,
1278                                            groupId, orderByComparator, false);
1279    
1280                            return array;
1281                    }
1282                    catch (Exception e) {
1283                            throw processException(e);
1284                    }
1285                    finally {
1286                            closeSession(session);
1287                    }
1288            }
1289    
1290            protected AssetVocabulary getByGroupId_PrevAndNext(Session session,
1291                    AssetVocabulary assetVocabulary, long groupId,
1292                    OrderByComparator orderByComparator, boolean previous) {
1293                    StringBundler query = null;
1294    
1295                    if (orderByComparator != null) {
1296                            query = new StringBundler(6 +
1297                                            (orderByComparator.getOrderByFields().length * 6));
1298                    }
1299                    else {
1300                            query = new StringBundler(3);
1301                    }
1302    
1303                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1304    
1305                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1306    
1307                    if (orderByComparator != null) {
1308                            String[] orderByFields = orderByComparator.getOrderByFields();
1309    
1310                            if (orderByFields.length > 0) {
1311                                    query.append(WHERE_AND);
1312                            }
1313    
1314                            for (int i = 0; i < orderByFields.length; i++) {
1315                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1316                                    query.append(orderByFields[i]);
1317    
1318                                    if ((i + 1) < orderByFields.length) {
1319                                            if (orderByComparator.isAscending() ^ previous) {
1320                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1321                                            }
1322                                            else {
1323                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1324                                            }
1325                                    }
1326                                    else {
1327                                            if (orderByComparator.isAscending() ^ previous) {
1328                                                    query.append(WHERE_GREATER_THAN);
1329                                            }
1330                                            else {
1331                                                    query.append(WHERE_LESSER_THAN);
1332                                            }
1333                                    }
1334                            }
1335    
1336                            query.append(ORDER_BY_CLAUSE);
1337    
1338                            for (int i = 0; i < orderByFields.length; i++) {
1339                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1340                                    query.append(orderByFields[i]);
1341    
1342                                    if ((i + 1) < orderByFields.length) {
1343                                            if (orderByComparator.isAscending() ^ previous) {
1344                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1345                                            }
1346                                            else {
1347                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1348                                            }
1349                                    }
1350                                    else {
1351                                            if (orderByComparator.isAscending() ^ previous) {
1352                                                    query.append(ORDER_BY_ASC);
1353                                            }
1354                                            else {
1355                                                    query.append(ORDER_BY_DESC);
1356                                            }
1357                                    }
1358                            }
1359                    }
1360    
1361                    else {
1362                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1363                    }
1364    
1365                    String sql = query.toString();
1366    
1367                    Query q = session.createQuery(sql);
1368    
1369                    q.setFirstResult(0);
1370                    q.setMaxResults(2);
1371    
1372                    QueryPos qPos = QueryPos.getInstance(q);
1373    
1374                    qPos.add(groupId);
1375    
1376                    if (orderByComparator != null) {
1377                            Object[] values = orderByComparator.getOrderByValues(assetVocabulary);
1378    
1379                            for (Object value : values) {
1380                                    qPos.add(value);
1381                            }
1382                    }
1383    
1384                    List<AssetVocabulary> list = q.list();
1385    
1386                    if (list.size() == 2) {
1387                            return list.get(1);
1388                    }
1389                    else {
1390                            return null;
1391                    }
1392            }
1393    
1394            /**
1395             * Filters by the user's permissions and finds all the asset vocabularies where groupId = &#63;.
1396             *
1397             * @param groupId the group id to search with
1398             * @return the matching asset vocabularies that the user has permission to view
1399             * @throws SystemException if a system exception occurred
1400             */
1401            public List<AssetVocabulary> filterFindByGroupId(long groupId)
1402                    throws SystemException {
1403                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1404                            QueryUtil.ALL_POS, null);
1405            }
1406    
1407            /**
1408             * Filters by the user's permissions and finds a range of all the asset vocabularies where groupId = &#63;.
1409             *
1410             * <p>
1411             * 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.
1412             * </p>
1413             *
1414             * @param groupId the group id to search with
1415             * @param start the lower bound of the range of asset vocabularies to return
1416             * @param end the upper bound of the range of asset vocabularies to return (not inclusive)
1417             * @return the range of matching asset vocabularies that the user has permission to view
1418             * @throws SystemException if a system exception occurred
1419             */
1420            public List<AssetVocabulary> filterFindByGroupId(long groupId, int start,
1421                    int end) throws SystemException {
1422                    return filterFindByGroupId(groupId, start, end, null);
1423            }
1424    
1425            /**
1426             * Filters by the user's permissions and finds an ordered range of all the asset vocabularies where groupId = &#63;.
1427             *
1428             * <p>
1429             * 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.
1430             * </p>
1431             *
1432             * @param groupId the group id to search with
1433             * @param start the lower bound of the range of asset vocabularies to return
1434             * @param end the upper bound of the range of asset vocabularies to return (not inclusive)
1435             * @param orderByComparator the comparator to order the results by
1436             * @return the ordered range of matching asset vocabularies that the user has permission to view
1437             * @throws SystemException if a system exception occurred
1438             */
1439            public List<AssetVocabulary> filterFindByGroupId(long groupId, int start,
1440                    int end, OrderByComparator orderByComparator) throws SystemException {
1441                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1442                            return findByGroupId(groupId, start, end, orderByComparator);
1443                    }
1444    
1445                    Session session = null;
1446    
1447                    try {
1448                            session = openSession();
1449    
1450                            StringBundler query = null;
1451    
1452                            if (orderByComparator != null) {
1453                                    query = new StringBundler(3 +
1454                                                    (orderByComparator.getOrderByFields().length * 3));
1455                            }
1456                            else {
1457                                    query = new StringBundler(3);
1458                            }
1459    
1460                            query.append(_FILTER_SQL_SELECT_ASSETVOCABULARY_WHERE);
1461    
1462                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1463    
1464                            if (orderByComparator != null) {
1465                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1466                                            orderByComparator);
1467                            }
1468    
1469                            else {
1470                                    query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1471                            }
1472    
1473                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1474                                            AssetVocabulary.class.getName(), _FILTER_COLUMN_PK,
1475                                            _FILTER_COLUMN_USERID, groupId);
1476    
1477                            SQLQuery q = session.createSQLQuery(sql);
1478    
1479                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetVocabularyImpl.class);
1480    
1481                            QueryPos qPos = QueryPos.getInstance(q);
1482    
1483                            qPos.add(groupId);
1484    
1485                            return (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
1486                                    start, end);
1487                    }
1488                    catch (Exception e) {
1489                            throw processException(e);
1490                    }
1491                    finally {
1492                            closeSession(session);
1493                    }
1494            }
1495    
1496            /**
1497             * Finds all the asset vocabularies where companyId = &#63;.
1498             *
1499             * @param companyId the company id to search with
1500             * @return the matching asset vocabularies
1501             * @throws SystemException if a system exception occurred
1502             */
1503            public List<AssetVocabulary> findByCompanyId(long companyId)
1504                    throws SystemException {
1505                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1506                            null);
1507            }
1508    
1509            /**
1510             * Finds a range of all the asset vocabularies where companyId = &#63;.
1511             *
1512             * <p>
1513             * 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.
1514             * </p>
1515             *
1516             * @param companyId the company id to search with
1517             * @param start the lower bound of the range of asset vocabularies to return
1518             * @param end the upper bound of the range of asset vocabularies to return (not inclusive)
1519             * @return the range of matching asset vocabularies
1520             * @throws SystemException if a system exception occurred
1521             */
1522            public List<AssetVocabulary> findByCompanyId(long companyId, int start,
1523                    int end) throws SystemException {
1524                    return findByCompanyId(companyId, start, end, null);
1525            }
1526    
1527            /**
1528             * Finds an ordered range of all the asset vocabularies where companyId = &#63;.
1529             *
1530             * <p>
1531             * 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.
1532             * </p>
1533             *
1534             * @param companyId the company id to search with
1535             * @param start the lower bound of the range of asset vocabularies to return
1536             * @param end the upper bound of the range of asset vocabularies to return (not inclusive)
1537             * @param orderByComparator the comparator to order the results by
1538             * @return the ordered range of matching asset vocabularies
1539             * @throws SystemException if a system exception occurred
1540             */
1541            public List<AssetVocabulary> findByCompanyId(long companyId, int start,
1542                    int end, OrderByComparator orderByComparator) throws SystemException {
1543                    Object[] finderArgs = new Object[] {
1544                                    companyId,
1545                                    
1546                                    String.valueOf(start), String.valueOf(end),
1547                                    String.valueOf(orderByComparator)
1548                            };
1549    
1550                    List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1551                                    finderArgs, this);
1552    
1553                    if (list == null) {
1554                            Session session = null;
1555    
1556                            try {
1557                                    session = openSession();
1558    
1559                                    StringBundler query = null;
1560    
1561                                    if (orderByComparator != null) {
1562                                            query = new StringBundler(3 +
1563                                                            (orderByComparator.getOrderByFields().length * 3));
1564                                    }
1565                                    else {
1566                                            query = new StringBundler(3);
1567                                    }
1568    
1569                                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1570    
1571                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1572    
1573                                    if (orderByComparator != null) {
1574                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1575                                                    orderByComparator);
1576                                    }
1577    
1578                                    else {
1579                                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1580                                    }
1581    
1582                                    String sql = query.toString();
1583    
1584                                    Query q = session.createQuery(sql);
1585    
1586                                    QueryPos qPos = QueryPos.getInstance(q);
1587    
1588                                    qPos.add(companyId);
1589    
1590                                    list = (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
1591                                                    start, end);
1592                            }
1593                            catch (Exception e) {
1594                                    throw processException(e);
1595                            }
1596                            finally {
1597                                    if (list == null) {
1598                                            list = new ArrayList<AssetVocabulary>();
1599                                    }
1600    
1601                                    cacheResult(list);
1602    
1603                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1604                                            finderArgs, list);
1605    
1606                                    closeSession(session);
1607                            }
1608                    }
1609    
1610                    return list;
1611            }
1612    
1613            /**
1614             * Finds the first asset vocabulary in the ordered set where companyId = &#63;.
1615             *
1616             * <p>
1617             * 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.
1618             * </p>
1619             *
1620             * @param companyId the company id to search with
1621             * @param orderByComparator the comparator to order the set by
1622             * @return the first matching asset vocabulary
1623             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a matching asset vocabulary could not be found
1624             * @throws SystemException if a system exception occurred
1625             */
1626            public AssetVocabulary findByCompanyId_First(long companyId,
1627                    OrderByComparator orderByComparator)
1628                    throws NoSuchVocabularyException, SystemException {
1629                    List<AssetVocabulary> list = findByCompanyId(companyId, 0, 1,
1630                                    orderByComparator);
1631    
1632                    if (list.isEmpty()) {
1633                            StringBundler msg = new StringBundler(4);
1634    
1635                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1636    
1637                            msg.append("companyId=");
1638                            msg.append(companyId);
1639    
1640                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1641    
1642                            throw new NoSuchVocabularyException(msg.toString());
1643                    }
1644                    else {
1645                            return list.get(0);
1646                    }
1647            }
1648    
1649            /**
1650             * Finds the last asset vocabulary in the ordered set where companyId = &#63;.
1651             *
1652             * <p>
1653             * 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.
1654             * </p>
1655             *
1656             * @param companyId the company id to search with
1657             * @param orderByComparator the comparator to order the set by
1658             * @return the last matching asset vocabulary
1659             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a matching asset vocabulary could not be found
1660             * @throws SystemException if a system exception occurred
1661             */
1662            public AssetVocabulary findByCompanyId_Last(long companyId,
1663                    OrderByComparator orderByComparator)
1664                    throws NoSuchVocabularyException, SystemException {
1665                    int count = countByCompanyId(companyId);
1666    
1667                    List<AssetVocabulary> list = findByCompanyId(companyId, count - 1,
1668                                    count, orderByComparator);
1669    
1670                    if (list.isEmpty()) {
1671                            StringBundler msg = new StringBundler(4);
1672    
1673                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1674    
1675                            msg.append("companyId=");
1676                            msg.append(companyId);
1677    
1678                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1679    
1680                            throw new NoSuchVocabularyException(msg.toString());
1681                    }
1682                    else {
1683                            return list.get(0);
1684                    }
1685            }
1686    
1687            /**
1688             * Finds the asset vocabularies before and after the current asset vocabulary in the ordered set where companyId = &#63;.
1689             *
1690             * <p>
1691             * 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.
1692             * </p>
1693             *
1694             * @param vocabularyId the primary key of the current asset vocabulary
1695             * @param companyId the company id to search with
1696             * @param orderByComparator the comparator to order the set by
1697             * @return the previous, current, and next asset vocabulary
1698             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a asset vocabulary with the primary key could not be found
1699             * @throws SystemException if a system exception occurred
1700             */
1701            public AssetVocabulary[] findByCompanyId_PrevAndNext(long vocabularyId,
1702                    long companyId, OrderByComparator orderByComparator)
1703                    throws NoSuchVocabularyException, SystemException {
1704                    AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
1705    
1706                    Session session = null;
1707    
1708                    try {
1709                            session = openSession();
1710    
1711                            AssetVocabulary[] array = new AssetVocabularyImpl[3];
1712    
1713                            array[0] = getByCompanyId_PrevAndNext(session, assetVocabulary,
1714                                            companyId, orderByComparator, true);
1715    
1716                            array[1] = assetVocabulary;
1717    
1718                            array[2] = getByCompanyId_PrevAndNext(session, assetVocabulary,
1719                                            companyId, orderByComparator, false);
1720    
1721                            return array;
1722                    }
1723                    catch (Exception e) {
1724                            throw processException(e);
1725                    }
1726                    finally {
1727                            closeSession(session);
1728                    }
1729            }
1730    
1731            protected AssetVocabulary getByCompanyId_PrevAndNext(Session session,
1732                    AssetVocabulary assetVocabulary, long companyId,
1733                    OrderByComparator orderByComparator, boolean previous) {
1734                    StringBundler query = null;
1735    
1736                    if (orderByComparator != null) {
1737                            query = new StringBundler(6 +
1738                                            (orderByComparator.getOrderByFields().length * 6));
1739                    }
1740                    else {
1741                            query = new StringBundler(3);
1742                    }
1743    
1744                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1745    
1746                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1747    
1748                    if (orderByComparator != null) {
1749                            String[] orderByFields = orderByComparator.getOrderByFields();
1750    
1751                            if (orderByFields.length > 0) {
1752                                    query.append(WHERE_AND);
1753                            }
1754    
1755                            for (int i = 0; i < orderByFields.length; i++) {
1756                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1757                                    query.append(orderByFields[i]);
1758    
1759                                    if ((i + 1) < orderByFields.length) {
1760                                            if (orderByComparator.isAscending() ^ previous) {
1761                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1762                                            }
1763                                            else {
1764                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1765                                            }
1766                                    }
1767                                    else {
1768                                            if (orderByComparator.isAscending() ^ previous) {
1769                                                    query.append(WHERE_GREATER_THAN);
1770                                            }
1771                                            else {
1772                                                    query.append(WHERE_LESSER_THAN);
1773                                            }
1774                                    }
1775                            }
1776    
1777                            query.append(ORDER_BY_CLAUSE);
1778    
1779                            for (int i = 0; i < orderByFields.length; i++) {
1780                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1781                                    query.append(orderByFields[i]);
1782    
1783                                    if ((i + 1) < orderByFields.length) {
1784                                            if (orderByComparator.isAscending() ^ previous) {
1785                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1786                                            }
1787                                            else {
1788                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1789                                            }
1790                                    }
1791                                    else {
1792                                            if (orderByComparator.isAscending() ^ previous) {
1793                                                    query.append(ORDER_BY_ASC);
1794                                            }
1795                                            else {
1796                                                    query.append(ORDER_BY_DESC);
1797                                            }
1798                                    }
1799                            }
1800                    }
1801    
1802                    else {
1803                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1804                    }
1805    
1806                    String sql = query.toString();
1807    
1808                    Query q = session.createQuery(sql);
1809    
1810                    q.setFirstResult(0);
1811                    q.setMaxResults(2);
1812    
1813                    QueryPos qPos = QueryPos.getInstance(q);
1814    
1815                    qPos.add(companyId);
1816    
1817                    if (orderByComparator != null) {
1818                            Object[] values = orderByComparator.getOrderByValues(assetVocabulary);
1819    
1820                            for (Object value : values) {
1821                                    qPos.add(value);
1822                            }
1823                    }
1824    
1825                    List<AssetVocabulary> list = q.list();
1826    
1827                    if (list.size() == 2) {
1828                            return list.get(1);
1829                    }
1830                    else {
1831                            return null;
1832                    }
1833            }
1834    
1835            /**
1836             * Finds the asset vocabulary where groupId = &#63; and name = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchVocabularyException} if it could not be found.
1837             *
1838             * @param groupId the group id to search with
1839             * @param name the name to search with
1840             * @return the matching asset vocabulary
1841             * @throws com.liferay.portlet.asset.NoSuchVocabularyException if a matching asset vocabulary could not be found
1842             * @throws SystemException if a system exception occurred
1843             */
1844            public AssetVocabulary findByG_N(long groupId, String name)
1845                    throws NoSuchVocabularyException, SystemException {
1846                    AssetVocabulary assetVocabulary = fetchByG_N(groupId, name);
1847    
1848                    if (assetVocabulary == null) {
1849                            StringBundler msg = new StringBundler(6);
1850    
1851                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1852    
1853                            msg.append("groupId=");
1854                            msg.append(groupId);
1855    
1856                            msg.append(", name=");
1857                            msg.append(name);
1858    
1859                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1860    
1861                            if (_log.isWarnEnabled()) {
1862                                    _log.warn(msg.toString());
1863                            }
1864    
1865                            throw new NoSuchVocabularyException(msg.toString());
1866                    }
1867    
1868                    return assetVocabulary;
1869            }
1870    
1871            /**
1872             * Finds the asset vocabulary where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1873             *
1874             * @param groupId the group id to search with
1875             * @param name the name to search with
1876             * @return the matching asset vocabulary, or <code>null</code> if a matching asset vocabulary could not be found
1877             * @throws SystemException if a system exception occurred
1878             */
1879            public AssetVocabulary fetchByG_N(long groupId, String name)
1880                    throws SystemException {
1881                    return fetchByG_N(groupId, name, true);
1882            }
1883    
1884            /**
1885             * Finds the asset vocabulary where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1886             *
1887             * @param groupId the group id to search with
1888             * @param name the name to search with
1889             * @return the matching asset vocabulary, or <code>null</code> if a matching asset vocabulary could not be found
1890             * @throws SystemException if a system exception occurred
1891             */
1892            public AssetVocabulary fetchByG_N(long groupId, String name,
1893                    boolean retrieveFromCache) throws SystemException {
1894                    Object[] finderArgs = new Object[] { groupId, name };
1895    
1896                    Object result = null;
1897    
1898                    if (retrieveFromCache) {
1899                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1900                                            finderArgs, this);
1901                    }
1902    
1903                    if (result == null) {
1904                            Session session = null;
1905    
1906                            try {
1907                                    session = openSession();
1908    
1909                                    StringBundler query = new StringBundler(4);
1910    
1911                                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1912    
1913                                    query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1914    
1915                                    if (name == null) {
1916                                            query.append(_FINDER_COLUMN_G_N_NAME_1);
1917                                    }
1918                                    else {
1919                                            if (name.equals(StringPool.BLANK)) {
1920                                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
1921                                            }
1922                                            else {
1923                                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
1924                                            }
1925                                    }
1926    
1927                                    query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1928    
1929                                    String sql = query.toString();
1930    
1931                                    Query q = session.createQuery(sql);
1932    
1933                                    QueryPos qPos = QueryPos.getInstance(q);
1934    
1935                                    qPos.add(groupId);
1936    
1937                                    if (name != null) {
1938                                            qPos.add(name);
1939                                    }
1940    
1941                                    List<AssetVocabulary> list = q.list();
1942    
1943                                    result = list;
1944    
1945                                    AssetVocabulary assetVocabulary = null;
1946    
1947                                    if (list.isEmpty()) {
1948                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1949                                                    finderArgs, list);
1950                                    }
1951                                    else {
1952                                            assetVocabulary = list.get(0);
1953    
1954                                            cacheResult(assetVocabulary);
1955    
1956                                            if ((assetVocabulary.getGroupId() != groupId) ||
1957                                                            (assetVocabulary.getName() == null) ||
1958                                                            !assetVocabulary.getName().equals(name)) {
1959                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1960                                                            finderArgs, assetVocabulary);
1961                                            }
1962                                    }
1963    
1964                                    return assetVocabulary;
1965                            }
1966                            catch (Exception e) {
1967                                    throw processException(e);
1968                            }
1969                            finally {
1970                                    if (result == null) {
1971                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1972                                                    finderArgs, new ArrayList<AssetVocabulary>());
1973                                    }
1974    
1975                                    closeSession(session);
1976                            }
1977                    }
1978                    else {
1979                            if (result instanceof List<?>) {
1980                                    return null;
1981                            }
1982                            else {
1983                                    return (AssetVocabulary)result;
1984                            }
1985                    }
1986            }
1987    
1988            /**
1989             * Finds all the asset vocabularies.
1990             *
1991             * @return the asset vocabularies
1992             * @throws SystemException if a system exception occurred
1993             */
1994            public List<AssetVocabulary> findAll() throws SystemException {
1995                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1996            }
1997    
1998            /**
1999             * Finds a range of all the asset vocabularies.
2000             *
2001             * <p>
2002             * 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.
2003             * </p>
2004             *
2005             * @param start the lower bound of the range of asset vocabularies to return
2006             * @param end the upper bound of the range of asset vocabularies to return (not inclusive)
2007             * @return the range of asset vocabularies
2008             * @throws SystemException if a system exception occurred
2009             */
2010            public List<AssetVocabulary> findAll(int start, int end)
2011                    throws SystemException {
2012                    return findAll(start, end, null);
2013            }
2014    
2015            /**
2016             * Finds an ordered range of all the asset vocabularies.
2017             *
2018             * <p>
2019             * 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.
2020             * </p>
2021             *
2022             * @param start the lower bound of the range of asset vocabularies to return
2023             * @param end the upper bound of the range of asset vocabularies to return (not inclusive)
2024             * @param orderByComparator the comparator to order the results by
2025             * @return the ordered range of asset vocabularies
2026             * @throws SystemException if a system exception occurred
2027             */
2028            public List<AssetVocabulary> findAll(int start, int end,
2029                    OrderByComparator orderByComparator) throws SystemException {
2030                    Object[] finderArgs = new Object[] {
2031                                    String.valueOf(start), String.valueOf(end),
2032                                    String.valueOf(orderByComparator)
2033                            };
2034    
2035                    List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2036                                    finderArgs, this);
2037    
2038                    if (list == null) {
2039                            Session session = null;
2040    
2041                            try {
2042                                    session = openSession();
2043    
2044                                    StringBundler query = null;
2045                                    String sql = null;
2046    
2047                                    if (orderByComparator != null) {
2048                                            query = new StringBundler(2 +
2049                                                            (orderByComparator.getOrderByFields().length * 3));
2050    
2051                                            query.append(_SQL_SELECT_ASSETVOCABULARY);
2052    
2053                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2054                                                    orderByComparator);
2055    
2056                                            sql = query.toString();
2057                                    }
2058                                    else {
2059                                            sql = _SQL_SELECT_ASSETVOCABULARY.concat(AssetVocabularyModelImpl.ORDER_BY_JPQL);
2060                                    }
2061    
2062                                    Query q = session.createQuery(sql);
2063    
2064                                    if (orderByComparator == null) {
2065                                            list = (List<AssetVocabulary>)QueryUtil.list(q,
2066                                                            getDialect(), start, end, false);
2067    
2068                                            Collections.sort(list);
2069                                    }
2070                                    else {
2071                                            list = (List<AssetVocabulary>)QueryUtil.list(q,
2072                                                            getDialect(), start, end);
2073                                    }
2074                            }
2075                            catch (Exception e) {
2076                                    throw processException(e);
2077                            }
2078                            finally {
2079                                    if (list == null) {
2080                                            list = new ArrayList<AssetVocabulary>();
2081                                    }
2082    
2083                                    cacheResult(list);
2084    
2085                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2086    
2087                                    closeSession(session);
2088                            }
2089                    }
2090    
2091                    return list;
2092            }
2093    
2094            /**
2095             * Removes all the asset vocabularies where uuid = &#63; from the database.
2096             *
2097             * @param uuid the uuid to search with
2098             * @throws SystemException if a system exception occurred
2099             */
2100            public void removeByUuid(String uuid) throws SystemException {
2101                    for (AssetVocabulary assetVocabulary : findByUuid(uuid)) {
2102                            remove(assetVocabulary);
2103                    }
2104            }
2105    
2106            /**
2107             * Removes the asset vocabulary where uuid = &#63; and groupId = &#63; from the database.
2108             *
2109             * @param uuid the uuid to search with
2110             * @param groupId the group id to search with
2111             * @throws SystemException if a system exception occurred
2112             */
2113            public void removeByUUID_G(String uuid, long groupId)
2114                    throws NoSuchVocabularyException, SystemException {
2115                    AssetVocabulary assetVocabulary = findByUUID_G(uuid, groupId);
2116    
2117                    remove(assetVocabulary);
2118            }
2119    
2120            /**
2121             * Removes all the asset vocabularies where groupId = &#63; from the database.
2122             *
2123             * @param groupId the group id to search with
2124             * @throws SystemException if a system exception occurred
2125             */
2126            public void removeByGroupId(long groupId) throws SystemException {
2127                    for (AssetVocabulary assetVocabulary : findByGroupId(groupId)) {
2128                            remove(assetVocabulary);
2129                    }
2130            }
2131    
2132            /**
2133             * Removes all the asset vocabularies where companyId = &#63; from the database.
2134             *
2135             * @param companyId the company id to search with
2136             * @throws SystemException if a system exception occurred
2137             */
2138            public void removeByCompanyId(long companyId) throws SystemException {
2139                    for (AssetVocabulary assetVocabulary : findByCompanyId(companyId)) {
2140                            remove(assetVocabulary);
2141                    }
2142            }
2143    
2144            /**
2145             * Removes the asset vocabulary where groupId = &#63; and name = &#63; from the database.
2146             *
2147             * @param groupId the group id to search with
2148             * @param name the name to search with
2149             * @throws SystemException if a system exception occurred
2150             */
2151            public void removeByG_N(long groupId, String name)
2152                    throws NoSuchVocabularyException, SystemException {
2153                    AssetVocabulary assetVocabulary = findByG_N(groupId, name);
2154    
2155                    remove(assetVocabulary);
2156            }
2157    
2158            /**
2159             * Removes all the asset vocabularies from the database.
2160             *
2161             * @throws SystemException if a system exception occurred
2162             */
2163            public void removeAll() throws SystemException {
2164                    for (AssetVocabulary assetVocabulary : findAll()) {
2165                            remove(assetVocabulary);
2166                    }
2167            }
2168    
2169            /**
2170             * Counts all the asset vocabularies where uuid = &#63;.
2171             *
2172             * @param uuid the uuid to search with
2173             * @return the number of matching asset vocabularies
2174             * @throws SystemException if a system exception occurred
2175             */
2176            public int countByUuid(String uuid) throws SystemException {
2177                    Object[] finderArgs = new Object[] { uuid };
2178    
2179                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2180                                    finderArgs, this);
2181    
2182                    if (count == null) {
2183                            Session session = null;
2184    
2185                            try {
2186                                    session = openSession();
2187    
2188                                    StringBundler query = new StringBundler(2);
2189    
2190                                    query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
2191    
2192                                    if (uuid == null) {
2193                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
2194                                    }
2195                                    else {
2196                                            if (uuid.equals(StringPool.BLANK)) {
2197                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
2198                                            }
2199                                            else {
2200                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
2201                                            }
2202                                    }
2203    
2204                                    String sql = query.toString();
2205    
2206                                    Query q = session.createQuery(sql);
2207    
2208                                    QueryPos qPos = QueryPos.getInstance(q);
2209    
2210                                    if (uuid != null) {
2211                                            qPos.add(uuid);
2212                                    }
2213    
2214                                    count = (Long)q.uniqueResult();
2215                            }
2216                            catch (Exception e) {
2217                                    throw processException(e);
2218                            }
2219                            finally {
2220                                    if (count == null) {
2221                                            count = Long.valueOf(0);
2222                                    }
2223    
2224                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2225                                            finderArgs, count);
2226    
2227                                    closeSession(session);
2228                            }
2229                    }
2230    
2231                    return count.intValue();
2232            }
2233    
2234            /**
2235             * Counts all the asset vocabularies where uuid = &#63; and groupId = &#63;.
2236             *
2237             * @param uuid the uuid to search with
2238             * @param groupId the group id to search with
2239             * @return the number of matching asset vocabularies
2240             * @throws SystemException if a system exception occurred
2241             */
2242            public int countByUUID_G(String uuid, long groupId)
2243                    throws SystemException {
2244                    Object[] finderArgs = new Object[] { uuid, groupId };
2245    
2246                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2247                                    finderArgs, this);
2248    
2249                    if (count == null) {
2250                            Session session = null;
2251    
2252                            try {
2253                                    session = openSession();
2254    
2255                                    StringBundler query = new StringBundler(3);
2256    
2257                                    query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
2258    
2259                                    if (uuid == null) {
2260                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2261                                    }
2262                                    else {
2263                                            if (uuid.equals(StringPool.BLANK)) {
2264                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2265                                            }
2266                                            else {
2267                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2268                                            }
2269                                    }
2270    
2271                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2272    
2273                                    String sql = query.toString();
2274    
2275                                    Query q = session.createQuery(sql);
2276    
2277                                    QueryPos qPos = QueryPos.getInstance(q);
2278    
2279                                    if (uuid != null) {
2280                                            qPos.add(uuid);
2281                                    }
2282    
2283                                    qPos.add(groupId);
2284    
2285                                    count = (Long)q.uniqueResult();
2286                            }
2287                            catch (Exception e) {
2288                                    throw processException(e);
2289                            }
2290                            finally {
2291                                    if (count == null) {
2292                                            count = Long.valueOf(0);
2293                                    }
2294    
2295                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2296                                            finderArgs, count);
2297    
2298                                    closeSession(session);
2299                            }
2300                    }
2301    
2302                    return count.intValue();
2303            }
2304    
2305            /**
2306             * Counts all the asset vocabularies where groupId = &#63;.
2307             *
2308             * @param groupId the group id to search with
2309             * @return the number of matching asset vocabularies
2310             * @throws SystemException if a system exception occurred
2311             */
2312            public int countByGroupId(long groupId) throws SystemException {
2313                    Object[] finderArgs = new Object[] { groupId };
2314    
2315                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2316                                    finderArgs, this);
2317    
2318                    if (count == null) {
2319                            Session session = null;
2320    
2321                            try {
2322                                    session = openSession();
2323    
2324                                    StringBundler query = new StringBundler(2);
2325    
2326                                    query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
2327    
2328                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2329    
2330                                    String sql = query.toString();
2331    
2332                                    Query q = session.createQuery(sql);
2333    
2334                                    QueryPos qPos = QueryPos.getInstance(q);
2335    
2336                                    qPos.add(groupId);
2337    
2338                                    count = (Long)q.uniqueResult();
2339                            }
2340                            catch (Exception e) {
2341                                    throw processException(e);
2342                            }
2343                            finally {
2344                                    if (count == null) {
2345                                            count = Long.valueOf(0);
2346                                    }
2347    
2348                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2349                                            finderArgs, count);
2350    
2351                                    closeSession(session);
2352                            }
2353                    }
2354    
2355                    return count.intValue();
2356            }
2357    
2358            /**
2359             * Filters by the user's permissions and counts all the asset vocabularies where groupId = &#63;.
2360             *
2361             * @param groupId the group id to search with
2362             * @return the number of matching asset vocabularies that the user has permission to view
2363             * @throws SystemException if a system exception occurred
2364             */
2365            public int filterCountByGroupId(long groupId) throws SystemException {
2366                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2367                            return countByGroupId(groupId);
2368                    }
2369    
2370                    Session session = null;
2371    
2372                    try {
2373                            session = openSession();
2374    
2375                            StringBundler query = new StringBundler(2);
2376    
2377                            query.append(_FILTER_SQL_COUNT_ASSETVOCABULARY_WHERE);
2378    
2379                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2380    
2381                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2382                                            AssetVocabulary.class.getName(), _FILTER_COLUMN_PK,
2383                                            _FILTER_COLUMN_USERID, groupId);
2384    
2385                            SQLQuery q = session.createSQLQuery(sql);
2386    
2387                            q.addScalar(COUNT_COLUMN_NAME,
2388                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2389    
2390                            QueryPos qPos = QueryPos.getInstance(q);
2391    
2392                            qPos.add(groupId);
2393    
2394                            Long count = (Long)q.uniqueResult();
2395    
2396                            return count.intValue();
2397                    }
2398                    catch (Exception e) {
2399                            throw processException(e);
2400                    }
2401                    finally {
2402                            closeSession(session);
2403                    }
2404            }
2405    
2406            /**
2407             * Counts all the asset vocabularies where companyId = &#63;.
2408             *
2409             * @param companyId the company id to search with
2410             * @return the number of matching asset vocabularies
2411             * @throws SystemException if a system exception occurred
2412             */
2413            public int countByCompanyId(long companyId) throws SystemException {
2414                    Object[] finderArgs = new Object[] { companyId };
2415    
2416                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2417                                    finderArgs, this);
2418    
2419                    if (count == null) {
2420                            Session session = null;
2421    
2422                            try {
2423                                    session = openSession();
2424    
2425                                    StringBundler query = new StringBundler(2);
2426    
2427                                    query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
2428    
2429                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2430    
2431                                    String sql = query.toString();
2432    
2433                                    Query q = session.createQuery(sql);
2434    
2435                                    QueryPos qPos = QueryPos.getInstance(q);
2436    
2437                                    qPos.add(companyId);
2438    
2439                                    count = (Long)q.uniqueResult();
2440                            }
2441                            catch (Exception e) {
2442                                    throw processException(e);
2443                            }
2444                            finally {
2445                                    if (count == null) {
2446                                            count = Long.valueOf(0);
2447                                    }
2448    
2449                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2450                                            finderArgs, count);
2451    
2452                                    closeSession(session);
2453                            }
2454                    }
2455    
2456                    return count.intValue();
2457            }
2458    
2459            /**
2460             * Counts all the asset vocabularies where groupId = &#63; and name = &#63;.
2461             *
2462             * @param groupId the group id to search with
2463             * @param name the name to search with
2464             * @return the number of matching asset vocabularies
2465             * @throws SystemException if a system exception occurred
2466             */
2467            public int countByG_N(long groupId, String name) throws SystemException {
2468                    Object[] finderArgs = new Object[] { groupId, name };
2469    
2470                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
2471                                    finderArgs, this);
2472    
2473                    if (count == null) {
2474                            Session session = null;
2475    
2476                            try {
2477                                    session = openSession();
2478    
2479                                    StringBundler query = new StringBundler(3);
2480    
2481                                    query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
2482    
2483                                    query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2484    
2485                                    if (name == null) {
2486                                            query.append(_FINDER_COLUMN_G_N_NAME_1);
2487                                    }
2488                                    else {
2489                                            if (name.equals(StringPool.BLANK)) {
2490                                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
2491                                            }
2492                                            else {
2493                                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
2494                                            }
2495                                    }
2496    
2497                                    String sql = query.toString();
2498    
2499                                    Query q = session.createQuery(sql);
2500    
2501                                    QueryPos qPos = QueryPos.getInstance(q);
2502    
2503                                    qPos.add(groupId);
2504    
2505                                    if (name != null) {
2506                                            qPos.add(name);
2507                                    }
2508    
2509                                    count = (Long)q.uniqueResult();
2510                            }
2511                            catch (Exception e) {
2512                                    throw processException(e);
2513                            }
2514                            finally {
2515                                    if (count == null) {
2516                                            count = Long.valueOf(0);
2517                                    }
2518    
2519                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
2520                                            count);
2521    
2522                                    closeSession(session);
2523                            }
2524                    }
2525    
2526                    return count.intValue();
2527            }
2528    
2529            /**
2530             * Filters by the user's permissions and counts all the asset vocabularies where groupId = &#63; and name = &#63;.
2531             *
2532             * @param groupId the group id to search with
2533             * @param name the name to search with
2534             * @return the number of matching asset vocabularies that the user has permission to view
2535             * @throws SystemException if a system exception occurred
2536             */
2537            public int filterCountByG_N(long groupId, String name)
2538                    throws SystemException {
2539                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2540                            return countByG_N(groupId, name);
2541                    }
2542    
2543                    Session session = null;
2544    
2545                    try {
2546                            session = openSession();
2547    
2548                            StringBundler query = new StringBundler(3);
2549    
2550                            query.append(_FILTER_SQL_COUNT_ASSETVOCABULARY_WHERE);
2551    
2552                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2553    
2554                            if (name == null) {
2555                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
2556                            }
2557                            else {
2558                                    if (name.equals(StringPool.BLANK)) {
2559                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
2560                                    }
2561                                    else {
2562                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
2563                                    }
2564                            }
2565    
2566                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2567                                            AssetVocabulary.class.getName(), _FILTER_COLUMN_PK,
2568                                            _FILTER_COLUMN_USERID, groupId);
2569    
2570                            SQLQuery q = session.createSQLQuery(sql);
2571    
2572                            q.addScalar(COUNT_COLUMN_NAME,
2573                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2574    
2575                            QueryPos qPos = QueryPos.getInstance(q);
2576    
2577                            qPos.add(groupId);
2578    
2579                            if (name != null) {
2580                                    qPos.add(name);
2581                            }
2582    
2583                            Long count = (Long)q.uniqueResult();
2584    
2585                            return count.intValue();
2586                    }
2587                    catch (Exception e) {
2588                            throw processException(e);
2589                    }
2590                    finally {
2591                            closeSession(session);
2592                    }
2593            }
2594    
2595            /**
2596             * Counts all the asset vocabularies.
2597             *
2598             * @return the number of asset vocabularies
2599             * @throws SystemException if a system exception occurred
2600             */
2601            public int countAll() throws SystemException {
2602                    Object[] finderArgs = new Object[0];
2603    
2604                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2605                                    finderArgs, this);
2606    
2607                    if (count == null) {
2608                            Session session = null;
2609    
2610                            try {
2611                                    session = openSession();
2612    
2613                                    Query q = session.createQuery(_SQL_COUNT_ASSETVOCABULARY);
2614    
2615                                    count = (Long)q.uniqueResult();
2616                            }
2617                            catch (Exception e) {
2618                                    throw processException(e);
2619                            }
2620                            finally {
2621                                    if (count == null) {
2622                                            count = Long.valueOf(0);
2623                                    }
2624    
2625                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2626                                            count);
2627    
2628                                    closeSession(session);
2629                            }
2630                    }
2631    
2632                    return count.intValue();
2633            }
2634    
2635            /**
2636             * Initializes the asset vocabulary persistence.
2637             */
2638            public void afterPropertiesSet() {
2639                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2640                                            com.liferay.portal.util.PropsUtil.get(
2641                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetVocabulary")));
2642    
2643                    if (listenerClassNames.length > 0) {
2644                            try {
2645                                    List<ModelListener<AssetVocabulary>> listenersList = new ArrayList<ModelListener<AssetVocabulary>>();
2646    
2647                                    for (String listenerClassName : listenerClassNames) {
2648                                            listenersList.add((ModelListener<AssetVocabulary>)InstanceFactory.newInstance(
2649                                                            listenerClassName));
2650                                    }
2651    
2652                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2653                            }
2654                            catch (Exception e) {
2655                                    _log.error(e);
2656                            }
2657                    }
2658            }
2659    
2660            @BeanReference(type = AssetCategoryPersistence.class)
2661            protected AssetCategoryPersistence assetCategoryPersistence;
2662            @BeanReference(type = AssetCategoryPropertyPersistence.class)
2663            protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
2664            @BeanReference(type = AssetEntryPersistence.class)
2665            protected AssetEntryPersistence assetEntryPersistence;
2666            @BeanReference(type = AssetLinkPersistence.class)
2667            protected AssetLinkPersistence assetLinkPersistence;
2668            @BeanReference(type = AssetTagPersistence.class)
2669            protected AssetTagPersistence assetTagPersistence;
2670            @BeanReference(type = AssetTagPropertyPersistence.class)
2671            protected AssetTagPropertyPersistence assetTagPropertyPersistence;
2672            @BeanReference(type = AssetTagStatsPersistence.class)
2673            protected AssetTagStatsPersistence assetTagStatsPersistence;
2674            @BeanReference(type = AssetVocabularyPersistence.class)
2675            protected AssetVocabularyPersistence assetVocabularyPersistence;
2676            @BeanReference(type = GroupPersistence.class)
2677            protected GroupPersistence groupPersistence;
2678            @BeanReference(type = ResourcePersistence.class)
2679            protected ResourcePersistence resourcePersistence;
2680            @BeanReference(type = UserPersistence.class)
2681            protected UserPersistence userPersistence;
2682            private static final String _SQL_SELECT_ASSETVOCABULARY = "SELECT assetVocabulary FROM AssetVocabulary assetVocabulary";
2683            private static final String _SQL_SELECT_ASSETVOCABULARY_WHERE = "SELECT assetVocabulary FROM AssetVocabulary assetVocabulary WHERE ";
2684            private static final String _SQL_COUNT_ASSETVOCABULARY = "SELECT COUNT(assetVocabulary) FROM AssetVocabulary assetVocabulary";
2685            private static final String _SQL_COUNT_ASSETVOCABULARY_WHERE = "SELECT COUNT(assetVocabulary) FROM AssetVocabulary assetVocabulary WHERE ";
2686            private static final String _FINDER_COLUMN_UUID_UUID_1 = "assetVocabulary.uuid IS NULL";
2687            private static final String _FINDER_COLUMN_UUID_UUID_2 = "assetVocabulary.uuid = ?";
2688            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(assetVocabulary.uuid IS NULL OR assetVocabulary.uuid = ?)";
2689            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "assetVocabulary.uuid IS NULL AND ";
2690            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "assetVocabulary.uuid = ? AND ";
2691            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(assetVocabulary.uuid IS NULL OR assetVocabulary.uuid = ?) AND ";
2692            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "assetVocabulary.groupId = ?";
2693            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetVocabulary.groupId = ?";
2694            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetVocabulary.companyId = ?";
2695            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "assetVocabulary.groupId = ? AND ";
2696            private static final String _FINDER_COLUMN_G_N_NAME_1 = "assetVocabulary.name IS NULL";
2697            private static final String _FINDER_COLUMN_G_N_NAME_2 = "assetVocabulary.name = ?";
2698            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(assetVocabulary.name IS NULL OR assetVocabulary.name = ?)";
2699            private static final String _FILTER_SQL_SELECT_ASSETVOCABULARY_WHERE = "SELECT DISTINCT {assetVocabulary.*} FROM AssetVocabulary assetVocabulary WHERE ";
2700            private static final String _FILTER_SQL_COUNT_ASSETVOCABULARY_WHERE = "SELECT COUNT(DISTINCT assetVocabulary.vocabularyId) AS COUNT_VALUE FROM AssetVocabulary assetVocabulary WHERE ";
2701            private static final String _FILTER_COLUMN_PK = "assetVocabulary.vocabularyId";
2702            private static final String _FILTER_COLUMN_USERID = "assetVocabulary.userId";
2703            private static final String _FILTER_ENTITY_ALIAS = "assetVocabulary";
2704            private static final String _ORDER_BY_ENTITY_ALIAS = "assetVocabulary.";
2705            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetVocabulary exists with the primary key ";
2706            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetVocabulary exists with the key {";
2707            private static Log _log = LogFactoryUtil.getLog(AssetVocabularyPersistenceImpl.class);
2708    }