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