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