001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.asset.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.BatchSessionUtil;
042    import com.liferay.portal.service.persistence.GroupPersistence;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.UserPersistence;
045    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046    
047    import com.liferay.portlet.asset.NoSuchVocabularyException;
048    import com.liferay.portlet.asset.model.AssetVocabulary;
049    import com.liferay.portlet.asset.model.impl.AssetVocabularyImpl;
050    import com.liferay.portlet.asset.model.impl.AssetVocabularyModelImpl;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    
058    /**
059     * @author    Brian Wing Shun Chan
060     * @see       AssetVocabularyPersistence
061     * @see       AssetVocabularyUtil
062     * @generated
063     */
064    public class AssetVocabularyPersistenceImpl extends BasePersistenceImpl<AssetVocabulary>
065            implements AssetVocabularyPersistence {
066            public static final String FINDER_CLASS_NAME_ENTITY = AssetVocabularyImpl.class.getName();
067            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
068                    ".List";
069            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
070                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
071                            FINDER_CLASS_NAME_LIST, "findByUuid",
072                            new String[] {
073                                    String.class.getName(),
074                                    
075                            "java.lang.Integer", "java.lang.Integer",
076                                    "com.liferay.portal.kernel.util.OrderByComparator"
077                            });
078            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
079                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
080                            FINDER_CLASS_NAME_LIST, "countByUuid",
081                            new String[] { String.class.getName() });
082            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
083                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
084                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
085                            new String[] { String.class.getName(), Long.class.getName() });
086            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
087                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
088                            FINDER_CLASS_NAME_LIST, "countByUUID_G",
089                            new String[] { String.class.getName(), Long.class.getName() });
090            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
091                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
092                            FINDER_CLASS_NAME_LIST, "findByGroupId",
093                            new String[] {
094                                    Long.class.getName(),
095                                    
096                            "java.lang.Integer", "java.lang.Integer",
097                                    "com.liferay.portal.kernel.util.OrderByComparator"
098                            });
099            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
100                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
101                            FINDER_CLASS_NAME_LIST, "countByGroupId",
102                            new String[] { Long.class.getName() });
103            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
104                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
105                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
106                            new String[] {
107                                    Long.class.getName(),
108                                    
109                            "java.lang.Integer", "java.lang.Integer",
110                                    "com.liferay.portal.kernel.util.OrderByComparator"
111                            });
112            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
113                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
114                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
115                            new String[] { Long.class.getName() });
116            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
117                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
118                            FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
119                            new String[] { Long.class.getName(), String.class.getName() });
120            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
121                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
122                            FINDER_CLASS_NAME_LIST, "countByG_N",
123                            new String[] { Long.class.getName(), String.class.getName() });
124            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
125                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
126                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
127            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
128                            AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
129                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
130    
131            public void cacheResult(AssetVocabulary assetVocabulary) {
132                    EntityCacheUtil.putResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
133                            AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey(),
134                            assetVocabulary);
135    
136                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
137                            new Object[] {
138                                    assetVocabulary.getUuid(),
139                                    new Long(assetVocabulary.getGroupId())
140                            }, assetVocabulary);
141    
142                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
143                            new Object[] {
144                                    new Long(assetVocabulary.getGroupId()),
145                                    
146                            assetVocabulary.getName()
147                            }, assetVocabulary);
148            }
149    
150            public void cacheResult(List<AssetVocabulary> assetVocabularies) {
151                    for (AssetVocabulary assetVocabulary : assetVocabularies) {
152                            if (EntityCacheUtil.getResult(
153                                                    AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
154                                                    AssetVocabularyImpl.class,
155                                                    assetVocabulary.getPrimaryKey(), this) == null) {
156                                    cacheResult(assetVocabulary);
157                            }
158                    }
159            }
160    
161            public void clearCache() {
162                    CacheRegistryUtil.clear(AssetVocabularyImpl.class.getName());
163                    EntityCacheUtil.clearCache(AssetVocabularyImpl.class.getName());
164                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
165                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
166            }
167    
168            public void clearCache(AssetVocabulary assetVocabulary) {
169                    EntityCacheUtil.removeResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
170                            AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey());
171    
172                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
173                            new Object[] {
174                                    assetVocabulary.getUuid(),
175                                    new Long(assetVocabulary.getGroupId())
176                            });
177    
178                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
179                            new Object[] {
180                                    new Long(assetVocabulary.getGroupId()),
181                                    
182                            assetVocabulary.getName()
183                            });
184            }
185    
186            public AssetVocabulary create(long vocabularyId) {
187                    AssetVocabulary assetVocabulary = new AssetVocabularyImpl();
188    
189                    assetVocabulary.setNew(true);
190                    assetVocabulary.setPrimaryKey(vocabularyId);
191    
192                    String uuid = PortalUUIDUtil.generate();
193    
194                    assetVocabulary.setUuid(uuid);
195    
196                    return assetVocabulary;
197            }
198    
199            public AssetVocabulary remove(Serializable primaryKey)
200                    throws NoSuchModelException, SystemException {
201                    return remove(((Long)primaryKey).longValue());
202            }
203    
204            public AssetVocabulary remove(long vocabularyId)
205                    throws NoSuchVocabularyException, SystemException {
206                    Session session = null;
207    
208                    try {
209                            session = openSession();
210    
211                            AssetVocabulary assetVocabulary = (AssetVocabulary)session.get(AssetVocabularyImpl.class,
212                                            new Long(vocabularyId));
213    
214                            if (assetVocabulary == null) {
215                                    if (_log.isWarnEnabled()) {
216                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + vocabularyId);
217                                    }
218    
219                                    throw new NoSuchVocabularyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
220                                            vocabularyId);
221                            }
222    
223                            return remove(assetVocabulary);
224                    }
225                    catch (NoSuchVocabularyException nsee) {
226                            throw nsee;
227                    }
228                    catch (Exception e) {
229                            throw processException(e);
230                    }
231                    finally {
232                            closeSession(session);
233                    }
234            }
235    
236            protected AssetVocabulary removeImpl(AssetVocabulary assetVocabulary)
237                    throws SystemException {
238                    assetVocabulary = toUnwrappedModel(assetVocabulary);
239    
240                    Session session = null;
241    
242                    try {
243                            session = openSession();
244    
245                            if (assetVocabulary.isCachedModel() ||
246                                            BatchSessionUtil.isEnabled()) {
247                                    Object staleObject = session.get(AssetVocabularyImpl.class,
248                                                    assetVocabulary.getPrimaryKeyObj());
249    
250                                    if (staleObject != null) {
251                                            session.evict(staleObject);
252                                    }
253                            }
254    
255                            session.delete(assetVocabulary);
256    
257                            session.flush();
258                    }
259                    catch (Exception e) {
260                            throw processException(e);
261                    }
262                    finally {
263                            closeSession(session);
264                    }
265    
266                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
267    
268                    AssetVocabularyModelImpl assetVocabularyModelImpl = (AssetVocabularyModelImpl)assetVocabulary;
269    
270                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
271                            new Object[] {
272                                    assetVocabularyModelImpl.getOriginalUuid(),
273                                    new Long(assetVocabularyModelImpl.getOriginalGroupId())
274                            });
275    
276                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
277                            new Object[] {
278                                    new Long(assetVocabularyModelImpl.getOriginalGroupId()),
279                                    
280                            assetVocabularyModelImpl.getOriginalName()
281                            });
282    
283                    EntityCacheUtil.removeResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
284                            AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey());
285    
286                    return assetVocabulary;
287            }
288    
289            public AssetVocabulary updateImpl(
290                    com.liferay.portlet.asset.model.AssetVocabulary assetVocabulary,
291                    boolean merge) throws SystemException {
292                    assetVocabulary = toUnwrappedModel(assetVocabulary);
293    
294                    boolean isNew = assetVocabulary.isNew();
295    
296                    AssetVocabularyModelImpl assetVocabularyModelImpl = (AssetVocabularyModelImpl)assetVocabulary;
297    
298                    if (Validator.isNull(assetVocabulary.getUuid())) {
299                            String uuid = PortalUUIDUtil.generate();
300    
301                            assetVocabulary.setUuid(uuid);
302                    }
303    
304                    Session session = null;
305    
306                    try {
307                            session = openSession();
308    
309                            BatchSessionUtil.update(session, assetVocabulary, merge);
310    
311                            assetVocabulary.setNew(false);
312                    }
313                    catch (Exception e) {
314                            throw processException(e);
315                    }
316                    finally {
317                            closeSession(session);
318                    }
319    
320                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
321    
322                    EntityCacheUtil.putResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
323                            AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey(),
324                            assetVocabulary);
325    
326                    if (!isNew &&
327                                    (!Validator.equals(assetVocabulary.getUuid(),
328                                            assetVocabularyModelImpl.getOriginalUuid()) ||
329                                    (assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()))) {
330                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
331                                    new Object[] {
332                                            assetVocabularyModelImpl.getOriginalUuid(),
333                                            new Long(assetVocabularyModelImpl.getOriginalGroupId())
334                                    });
335                    }
336    
337                    if (isNew ||
338                                    (!Validator.equals(assetVocabulary.getUuid(),
339                                            assetVocabularyModelImpl.getOriginalUuid()) ||
340                                    (assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()))) {
341                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
342                                    new Object[] {
343                                            assetVocabulary.getUuid(),
344                                            new Long(assetVocabulary.getGroupId())
345                                    }, assetVocabulary);
346                    }
347    
348                    if (!isNew &&
349                                    ((assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()) ||
350                                    !Validator.equals(assetVocabulary.getName(),
351                                            assetVocabularyModelImpl.getOriginalName()))) {
352                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
353                                    new Object[] {
354                                            new Long(assetVocabularyModelImpl.getOriginalGroupId()),
355                                            
356                                    assetVocabularyModelImpl.getOriginalName()
357                                    });
358                    }
359    
360                    if (isNew ||
361                                    ((assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()) ||
362                                    !Validator.equals(assetVocabulary.getName(),
363                                            assetVocabularyModelImpl.getOriginalName()))) {
364                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
365                                    new Object[] {
366                                            new Long(assetVocabulary.getGroupId()),
367                                            
368                                    assetVocabulary.getName()
369                                    }, assetVocabulary);
370                    }
371    
372                    return assetVocabulary;
373            }
374    
375            protected AssetVocabulary toUnwrappedModel(AssetVocabulary assetVocabulary) {
376                    if (assetVocabulary instanceof AssetVocabularyImpl) {
377                            return assetVocabulary;
378                    }
379    
380                    AssetVocabularyImpl assetVocabularyImpl = new AssetVocabularyImpl();
381    
382                    assetVocabularyImpl.setNew(assetVocabulary.isNew());
383                    assetVocabularyImpl.setPrimaryKey(assetVocabulary.getPrimaryKey());
384    
385                    assetVocabularyImpl.setUuid(assetVocabulary.getUuid());
386                    assetVocabularyImpl.setVocabularyId(assetVocabulary.getVocabularyId());
387                    assetVocabularyImpl.setGroupId(assetVocabulary.getGroupId());
388                    assetVocabularyImpl.setCompanyId(assetVocabulary.getCompanyId());
389                    assetVocabularyImpl.setUserId(assetVocabulary.getUserId());
390                    assetVocabularyImpl.setUserName(assetVocabulary.getUserName());
391                    assetVocabularyImpl.setCreateDate(assetVocabulary.getCreateDate());
392                    assetVocabularyImpl.setModifiedDate(assetVocabulary.getModifiedDate());
393                    assetVocabularyImpl.setName(assetVocabulary.getName());
394                    assetVocabularyImpl.setTitle(assetVocabulary.getTitle());
395                    assetVocabularyImpl.setDescription(assetVocabulary.getDescription());
396                    assetVocabularyImpl.setSettings(assetVocabulary.getSettings());
397    
398                    return assetVocabularyImpl;
399            }
400    
401            public AssetVocabulary findByPrimaryKey(Serializable primaryKey)
402                    throws NoSuchModelException, SystemException {
403                    return findByPrimaryKey(((Long)primaryKey).longValue());
404            }
405    
406            public AssetVocabulary findByPrimaryKey(long vocabularyId)
407                    throws NoSuchVocabularyException, SystemException {
408                    AssetVocabulary assetVocabulary = fetchByPrimaryKey(vocabularyId);
409    
410                    if (assetVocabulary == null) {
411                            if (_log.isWarnEnabled()) {
412                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + vocabularyId);
413                            }
414    
415                            throw new NoSuchVocabularyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
416                                    vocabularyId);
417                    }
418    
419                    return assetVocabulary;
420            }
421    
422            public AssetVocabulary fetchByPrimaryKey(Serializable primaryKey)
423                    throws SystemException {
424                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
425            }
426    
427            public AssetVocabulary fetchByPrimaryKey(long vocabularyId)
428                    throws SystemException {
429                    AssetVocabulary assetVocabulary = (AssetVocabulary)EntityCacheUtil.getResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
430                                    AssetVocabularyImpl.class, vocabularyId, this);
431    
432                    if (assetVocabulary == null) {
433                            Session session = null;
434    
435                            try {
436                                    session = openSession();
437    
438                                    assetVocabulary = (AssetVocabulary)session.get(AssetVocabularyImpl.class,
439                                                    new Long(vocabularyId));
440                            }
441                            catch (Exception e) {
442                                    throw processException(e);
443                            }
444                            finally {
445                                    if (assetVocabulary != null) {
446                                            cacheResult(assetVocabulary);
447                                    }
448    
449                                    closeSession(session);
450                            }
451                    }
452    
453                    return assetVocabulary;
454            }
455    
456            public List<AssetVocabulary> findByUuid(String uuid)
457                    throws SystemException {
458                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
459            }
460    
461            public List<AssetVocabulary> findByUuid(String uuid, int start, int end)
462                    throws SystemException {
463                    return findByUuid(uuid, start, end, null);
464            }
465    
466            public List<AssetVocabulary> findByUuid(String uuid, int start, int end,
467                    OrderByComparator orderByComparator) throws SystemException {
468                    Object[] finderArgs = new Object[] {
469                                    uuid,
470                                    
471                                    String.valueOf(start), String.valueOf(end),
472                                    String.valueOf(orderByComparator)
473                            };
474    
475                    List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
476                                    finderArgs, this);
477    
478                    if (list == null) {
479                            Session session = null;
480    
481                            try {
482                                    session = openSession();
483    
484                                    StringBundler query = null;
485    
486                                    if (orderByComparator != null) {
487                                            query = new StringBundler(3 +
488                                                            (orderByComparator.getOrderByFields().length * 3));
489                                    }
490                                    else {
491                                            query = new StringBundler(3);
492                                    }
493    
494                                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
495    
496                                    if (uuid == null) {
497                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
498                                    }
499                                    else {
500                                            if (uuid.equals(StringPool.BLANK)) {
501                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
502                                            }
503                                            else {
504                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
505                                            }
506                                    }
507    
508                                    if (orderByComparator != null) {
509                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
510                                                    orderByComparator);
511                                    }
512    
513                                    else {
514                                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
515                                    }
516    
517                                    String sql = query.toString();
518    
519                                    Query q = session.createQuery(sql);
520    
521                                    QueryPos qPos = QueryPos.getInstance(q);
522    
523                                    if (uuid != null) {
524                                            qPos.add(uuid);
525                                    }
526    
527                                    list = (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
528                                                    start, end);
529                            }
530                            catch (Exception e) {
531                                    throw processException(e);
532                            }
533                            finally {
534                                    if (list == null) {
535                                            list = new ArrayList<AssetVocabulary>();
536                                    }
537    
538                                    cacheResult(list);
539    
540                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
541                                            list);
542    
543                                    closeSession(session);
544                            }
545                    }
546    
547                    return list;
548            }
549    
550            public AssetVocabulary findByUuid_First(String uuid,
551                    OrderByComparator orderByComparator)
552                    throws NoSuchVocabularyException, SystemException {
553                    List<AssetVocabulary> list = findByUuid(uuid, 0, 1, orderByComparator);
554    
555                    if (list.isEmpty()) {
556                            StringBundler msg = new StringBundler(4);
557    
558                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
559    
560                            msg.append("uuid=");
561                            msg.append(uuid);
562    
563                            msg.append(StringPool.CLOSE_CURLY_BRACE);
564    
565                            throw new NoSuchVocabularyException(msg.toString());
566                    }
567                    else {
568                            return list.get(0);
569                    }
570            }
571    
572            public AssetVocabulary findByUuid_Last(String uuid,
573                    OrderByComparator orderByComparator)
574                    throws NoSuchVocabularyException, SystemException {
575                    int count = countByUuid(uuid);
576    
577                    List<AssetVocabulary> list = findByUuid(uuid, count - 1, count,
578                                    orderByComparator);
579    
580                    if (list.isEmpty()) {
581                            StringBundler msg = new StringBundler(4);
582    
583                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
584    
585                            msg.append("uuid=");
586                            msg.append(uuid);
587    
588                            msg.append(StringPool.CLOSE_CURLY_BRACE);
589    
590                            throw new NoSuchVocabularyException(msg.toString());
591                    }
592                    else {
593                            return list.get(0);
594                    }
595            }
596    
597            public AssetVocabulary[] findByUuid_PrevAndNext(long vocabularyId,
598                    String uuid, OrderByComparator orderByComparator)
599                    throws NoSuchVocabularyException, SystemException {
600                    AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
601    
602                    Session session = null;
603    
604                    try {
605                            session = openSession();
606    
607                            AssetVocabulary[] array = new AssetVocabularyImpl[3];
608    
609                            array[0] = getByUuid_PrevAndNext(session, assetVocabulary, uuid,
610                                            orderByComparator, true);
611    
612                            array[1] = assetVocabulary;
613    
614                            array[2] = getByUuid_PrevAndNext(session, assetVocabulary, uuid,
615                                            orderByComparator, false);
616    
617                            return array;
618                    }
619                    catch (Exception e) {
620                            throw processException(e);
621                    }
622                    finally {
623                            closeSession(session);
624                    }
625            }
626    
627            protected AssetVocabulary getByUuid_PrevAndNext(Session session,
628                    AssetVocabulary assetVocabulary, String uuid,
629                    OrderByComparator orderByComparator, boolean previous) {
630                    StringBundler query = null;
631    
632                    if (orderByComparator != null) {
633                            query = new StringBundler(6 +
634                                            (orderByComparator.getOrderByFields().length * 6));
635                    }
636                    else {
637                            query = new StringBundler(3);
638                    }
639    
640                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
641    
642                    if (uuid == null) {
643                            query.append(_FINDER_COLUMN_UUID_UUID_1);
644                    }
645                    else {
646                            if (uuid.equals(StringPool.BLANK)) {
647                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
648                            }
649                            else {
650                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
651                            }
652                    }
653    
654                    if (orderByComparator != null) {
655                            String[] orderByFields = orderByComparator.getOrderByFields();
656    
657                            if (orderByFields.length > 0) {
658                                    query.append(WHERE_AND);
659                            }
660    
661                            for (int i = 0; i < orderByFields.length; i++) {
662                                    query.append(_ORDER_BY_ENTITY_ALIAS);
663                                    query.append(orderByFields[i]);
664    
665                                    if ((i + 1) < orderByFields.length) {
666                                            if (orderByComparator.isAscending() ^ previous) {
667                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
668                                            }
669                                            else {
670                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
671                                            }
672                                    }
673                                    else {
674                                            if (orderByComparator.isAscending() ^ previous) {
675                                                    query.append(WHERE_GREATER_THAN);
676                                            }
677                                            else {
678                                                    query.append(WHERE_LESSER_THAN);
679                                            }
680                                    }
681                            }
682    
683                            query.append(ORDER_BY_CLAUSE);
684    
685                            for (int i = 0; i < orderByFields.length; i++) {
686                                    query.append(_ORDER_BY_ENTITY_ALIAS);
687                                    query.append(orderByFields[i]);
688    
689                                    if ((i + 1) < orderByFields.length) {
690                                            if (orderByComparator.isAscending() ^ previous) {
691                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
692                                            }
693                                            else {
694                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
695                                            }
696                                    }
697                                    else {
698                                            if (orderByComparator.isAscending() ^ previous) {
699                                                    query.append(ORDER_BY_ASC);
700                                            }
701                                            else {
702                                                    query.append(ORDER_BY_DESC);
703                                            }
704                                    }
705                            }
706                    }
707    
708                    else {
709                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
710                    }
711    
712                    String sql = query.toString();
713    
714                    Query q = session.createQuery(sql);
715    
716                    q.setFirstResult(0);
717                    q.setMaxResults(2);
718    
719                    QueryPos qPos = QueryPos.getInstance(q);
720    
721                    if (uuid != null) {
722                            qPos.add(uuid);
723                    }
724    
725                    if (orderByComparator != null) {
726                            Object[] values = orderByComparator.getOrderByValues(assetVocabulary);
727    
728                            for (Object value : values) {
729                                    qPos.add(value);
730                            }
731                    }
732    
733                    List<AssetVocabulary> list = q.list();
734    
735                    if (list.size() == 2) {
736                            return list.get(1);
737                    }
738                    else {
739                            return null;
740                    }
741            }
742    
743            public AssetVocabulary findByUUID_G(String uuid, long groupId)
744                    throws NoSuchVocabularyException, SystemException {
745                    AssetVocabulary assetVocabulary = fetchByUUID_G(uuid, groupId);
746    
747                    if (assetVocabulary == null) {
748                            StringBundler msg = new StringBundler(6);
749    
750                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
751    
752                            msg.append("uuid=");
753                            msg.append(uuid);
754    
755                            msg.append(", groupId=");
756                            msg.append(groupId);
757    
758                            msg.append(StringPool.CLOSE_CURLY_BRACE);
759    
760                            if (_log.isWarnEnabled()) {
761                                    _log.warn(msg.toString());
762                            }
763    
764                            throw new NoSuchVocabularyException(msg.toString());
765                    }
766    
767                    return assetVocabulary;
768            }
769    
770            public AssetVocabulary fetchByUUID_G(String uuid, long groupId)
771                    throws SystemException {
772                    return fetchByUUID_G(uuid, groupId, true);
773            }
774    
775            public AssetVocabulary fetchByUUID_G(String uuid, long groupId,
776                    boolean retrieveFromCache) throws SystemException {
777                    Object[] finderArgs = new Object[] { uuid, groupId };
778    
779                    Object result = null;
780    
781                    if (retrieveFromCache) {
782                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
783                                            finderArgs, this);
784                    }
785    
786                    if (result == null) {
787                            Session session = null;
788    
789                            try {
790                                    session = openSession();
791    
792                                    StringBundler query = new StringBundler(4);
793    
794                                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
795    
796                                    if (uuid == null) {
797                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
798                                    }
799                                    else {
800                                            if (uuid.equals(StringPool.BLANK)) {
801                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
802                                            }
803                                            else {
804                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
805                                            }
806                                    }
807    
808                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
809    
810                                    query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
811    
812                                    String sql = query.toString();
813    
814                                    Query q = session.createQuery(sql);
815    
816                                    QueryPos qPos = QueryPos.getInstance(q);
817    
818                                    if (uuid != null) {
819                                            qPos.add(uuid);
820                                    }
821    
822                                    qPos.add(groupId);
823    
824                                    List<AssetVocabulary> list = q.list();
825    
826                                    result = list;
827    
828                                    AssetVocabulary assetVocabulary = null;
829    
830                                    if (list.isEmpty()) {
831                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
832                                                    finderArgs, list);
833                                    }
834                                    else {
835                                            assetVocabulary = list.get(0);
836    
837                                            cacheResult(assetVocabulary);
838    
839                                            if ((assetVocabulary.getUuid() == null) ||
840                                                            !assetVocabulary.getUuid().equals(uuid) ||
841                                                            (assetVocabulary.getGroupId() != groupId)) {
842                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
843                                                            finderArgs, assetVocabulary);
844                                            }
845                                    }
846    
847                                    return assetVocabulary;
848                            }
849                            catch (Exception e) {
850                                    throw processException(e);
851                            }
852                            finally {
853                                    if (result == null) {
854                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
855                                                    finderArgs, new ArrayList<AssetVocabulary>());
856                                    }
857    
858                                    closeSession(session);
859                            }
860                    }
861                    else {
862                            if (result instanceof List<?>) {
863                                    return null;
864                            }
865                            else {
866                                    return (AssetVocabulary)result;
867                            }
868                    }
869            }
870    
871            public List<AssetVocabulary> findByGroupId(long groupId)
872                    throws SystemException {
873                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
874            }
875    
876            public List<AssetVocabulary> findByGroupId(long groupId, int start, int end)
877                    throws SystemException {
878                    return findByGroupId(groupId, start, end, null);
879            }
880    
881            public List<AssetVocabulary> findByGroupId(long groupId, int start,
882                    int end, OrderByComparator orderByComparator) throws SystemException {
883                    Object[] finderArgs = new Object[] {
884                                    groupId,
885                                    
886                                    String.valueOf(start), String.valueOf(end),
887                                    String.valueOf(orderByComparator)
888                            };
889    
890                    List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
891                                    finderArgs, this);
892    
893                    if (list == null) {
894                            Session session = null;
895    
896                            try {
897                                    session = openSession();
898    
899                                    StringBundler query = null;
900    
901                                    if (orderByComparator != null) {
902                                            query = new StringBundler(3 +
903                                                            (orderByComparator.getOrderByFields().length * 3));
904                                    }
905                                    else {
906                                            query = new StringBundler(3);
907                                    }
908    
909                                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
910    
911                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
912    
913                                    if (orderByComparator != null) {
914                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
915                                                    orderByComparator);
916                                    }
917    
918                                    else {
919                                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
920                                    }
921    
922                                    String sql = query.toString();
923    
924                                    Query q = session.createQuery(sql);
925    
926                                    QueryPos qPos = QueryPos.getInstance(q);
927    
928                                    qPos.add(groupId);
929    
930                                    list = (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
931                                                    start, end);
932                            }
933                            catch (Exception e) {
934                                    throw processException(e);
935                            }
936                            finally {
937                                    if (list == null) {
938                                            list = new ArrayList<AssetVocabulary>();
939                                    }
940    
941                                    cacheResult(list);
942    
943                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
944                                            finderArgs, list);
945    
946                                    closeSession(session);
947                            }
948                    }
949    
950                    return list;
951            }
952    
953            public AssetVocabulary findByGroupId_First(long groupId,
954                    OrderByComparator orderByComparator)
955                    throws NoSuchVocabularyException, SystemException {
956                    List<AssetVocabulary> list = findByGroupId(groupId, 0, 1,
957                                    orderByComparator);
958    
959                    if (list.isEmpty()) {
960                            StringBundler msg = new StringBundler(4);
961    
962                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
963    
964                            msg.append("groupId=");
965                            msg.append(groupId);
966    
967                            msg.append(StringPool.CLOSE_CURLY_BRACE);
968    
969                            throw new NoSuchVocabularyException(msg.toString());
970                    }
971                    else {
972                            return list.get(0);
973                    }
974            }
975    
976            public AssetVocabulary findByGroupId_Last(long groupId,
977                    OrderByComparator orderByComparator)
978                    throws NoSuchVocabularyException, SystemException {
979                    int count = countByGroupId(groupId);
980    
981                    List<AssetVocabulary> list = findByGroupId(groupId, count - 1, count,
982                                    orderByComparator);
983    
984                    if (list.isEmpty()) {
985                            StringBundler msg = new StringBundler(4);
986    
987                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
988    
989                            msg.append("groupId=");
990                            msg.append(groupId);
991    
992                            msg.append(StringPool.CLOSE_CURLY_BRACE);
993    
994                            throw new NoSuchVocabularyException(msg.toString());
995                    }
996                    else {
997                            return list.get(0);
998                    }
999            }
1000    
1001            public AssetVocabulary[] findByGroupId_PrevAndNext(long vocabularyId,
1002                    long groupId, OrderByComparator orderByComparator)
1003                    throws NoSuchVocabularyException, SystemException {
1004                    AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
1005    
1006                    Session session = null;
1007    
1008                    try {
1009                            session = openSession();
1010    
1011                            AssetVocabulary[] array = new AssetVocabularyImpl[3];
1012    
1013                            array[0] = getByGroupId_PrevAndNext(session, assetVocabulary,
1014                                            groupId, orderByComparator, true);
1015    
1016                            array[1] = assetVocabulary;
1017    
1018                            array[2] = getByGroupId_PrevAndNext(session, assetVocabulary,
1019                                            groupId, orderByComparator, false);
1020    
1021                            return array;
1022                    }
1023                    catch (Exception e) {
1024                            throw processException(e);
1025                    }
1026                    finally {
1027                            closeSession(session);
1028                    }
1029            }
1030    
1031            protected AssetVocabulary getByGroupId_PrevAndNext(Session session,
1032                    AssetVocabulary assetVocabulary, long groupId,
1033                    OrderByComparator orderByComparator, boolean previous) {
1034                    StringBundler query = null;
1035    
1036                    if (orderByComparator != null) {
1037                            query = new StringBundler(6 +
1038                                            (orderByComparator.getOrderByFields().length * 6));
1039                    }
1040                    else {
1041                            query = new StringBundler(3);
1042                    }
1043    
1044                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1045    
1046                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1047    
1048                    if (orderByComparator != null) {
1049                            String[] orderByFields = orderByComparator.getOrderByFields();
1050    
1051                            if (orderByFields.length > 0) {
1052                                    query.append(WHERE_AND);
1053                            }
1054    
1055                            for (int i = 0; i < orderByFields.length; i++) {
1056                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1057                                    query.append(orderByFields[i]);
1058    
1059                                    if ((i + 1) < orderByFields.length) {
1060                                            if (orderByComparator.isAscending() ^ previous) {
1061                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1062                                            }
1063                                            else {
1064                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1065                                            }
1066                                    }
1067                                    else {
1068                                            if (orderByComparator.isAscending() ^ previous) {
1069                                                    query.append(WHERE_GREATER_THAN);
1070                                            }
1071                                            else {
1072                                                    query.append(WHERE_LESSER_THAN);
1073                                            }
1074                                    }
1075                            }
1076    
1077                            query.append(ORDER_BY_CLAUSE);
1078    
1079                            for (int i = 0; i < orderByFields.length; i++) {
1080                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1081                                    query.append(orderByFields[i]);
1082    
1083                                    if ((i + 1) < orderByFields.length) {
1084                                            if (orderByComparator.isAscending() ^ previous) {
1085                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1086                                            }
1087                                            else {
1088                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1089                                            }
1090                                    }
1091                                    else {
1092                                            if (orderByComparator.isAscending() ^ previous) {
1093                                                    query.append(ORDER_BY_ASC);
1094                                            }
1095                                            else {
1096                                                    query.append(ORDER_BY_DESC);
1097                                            }
1098                                    }
1099                            }
1100                    }
1101    
1102                    else {
1103                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1104                    }
1105    
1106                    String sql = query.toString();
1107    
1108                    Query q = session.createQuery(sql);
1109    
1110                    q.setFirstResult(0);
1111                    q.setMaxResults(2);
1112    
1113                    QueryPos qPos = QueryPos.getInstance(q);
1114    
1115                    qPos.add(groupId);
1116    
1117                    if (orderByComparator != null) {
1118                            Object[] values = orderByComparator.getOrderByValues(assetVocabulary);
1119    
1120                            for (Object value : values) {
1121                                    qPos.add(value);
1122                            }
1123                    }
1124    
1125                    List<AssetVocabulary> list = q.list();
1126    
1127                    if (list.size() == 2) {
1128                            return list.get(1);
1129                    }
1130                    else {
1131                            return null;
1132                    }
1133            }
1134    
1135            public List<AssetVocabulary> filterFindByGroupId(long groupId)
1136                    throws SystemException {
1137                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1138                            QueryUtil.ALL_POS, null);
1139            }
1140    
1141            public List<AssetVocabulary> filterFindByGroupId(long groupId, int start,
1142                    int end) throws SystemException {
1143                    return filterFindByGroupId(groupId, start, end, null);
1144            }
1145    
1146            public List<AssetVocabulary> filterFindByGroupId(long groupId, int start,
1147                    int end, OrderByComparator orderByComparator) throws SystemException {
1148                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1149                            return findByGroupId(groupId, start, end, orderByComparator);
1150                    }
1151    
1152                    Session session = null;
1153    
1154                    try {
1155                            session = openSession();
1156    
1157                            StringBundler query = null;
1158    
1159                            if (orderByComparator != null) {
1160                                    query = new StringBundler(3 +
1161                                                    (orderByComparator.getOrderByFields().length * 3));
1162                            }
1163                            else {
1164                                    query = new StringBundler(3);
1165                            }
1166    
1167                            query.append(_FILTER_SQL_SELECT_ASSETVOCABULARY_WHERE);
1168    
1169                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1170    
1171                            if (orderByComparator != null) {
1172                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1173                                            orderByComparator);
1174                            }
1175    
1176                            else {
1177                                    query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1178                            }
1179    
1180                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1181                                            AssetVocabulary.class.getName(), _FILTER_COLUMN_PK,
1182                                            _FILTER_COLUMN_USERID, groupId);
1183    
1184                            SQLQuery q = session.createSQLQuery(sql);
1185    
1186                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetVocabularyImpl.class);
1187    
1188                            QueryPos qPos = QueryPos.getInstance(q);
1189    
1190                            qPos.add(groupId);
1191    
1192                            return (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
1193                                    start, end);
1194                    }
1195                    catch (Exception e) {
1196                            throw processException(e);
1197                    }
1198                    finally {
1199                            closeSession(session);
1200                    }
1201            }
1202    
1203            public List<AssetVocabulary> findByCompanyId(long companyId)
1204                    throws SystemException {
1205                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1206                            null);
1207            }
1208    
1209            public List<AssetVocabulary> findByCompanyId(long companyId, int start,
1210                    int end) throws SystemException {
1211                    return findByCompanyId(companyId, start, end, null);
1212            }
1213    
1214            public List<AssetVocabulary> findByCompanyId(long companyId, int start,
1215                    int end, OrderByComparator orderByComparator) throws SystemException {
1216                    Object[] finderArgs = new Object[] {
1217                                    companyId,
1218                                    
1219                                    String.valueOf(start), String.valueOf(end),
1220                                    String.valueOf(orderByComparator)
1221                            };
1222    
1223                    List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1224                                    finderArgs, this);
1225    
1226                    if (list == null) {
1227                            Session session = null;
1228    
1229                            try {
1230                                    session = openSession();
1231    
1232                                    StringBundler query = null;
1233    
1234                                    if (orderByComparator != null) {
1235                                            query = new StringBundler(3 +
1236                                                            (orderByComparator.getOrderByFields().length * 3));
1237                                    }
1238                                    else {
1239                                            query = new StringBundler(3);
1240                                    }
1241    
1242                                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1243    
1244                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1245    
1246                                    if (orderByComparator != null) {
1247                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1248                                                    orderByComparator);
1249                                    }
1250    
1251                                    else {
1252                                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1253                                    }
1254    
1255                                    String sql = query.toString();
1256    
1257                                    Query q = session.createQuery(sql);
1258    
1259                                    QueryPos qPos = QueryPos.getInstance(q);
1260    
1261                                    qPos.add(companyId);
1262    
1263                                    list = (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
1264                                                    start, end);
1265                            }
1266                            catch (Exception e) {
1267                                    throw processException(e);
1268                            }
1269                            finally {
1270                                    if (list == null) {
1271                                            list = new ArrayList<AssetVocabulary>();
1272                                    }
1273    
1274                                    cacheResult(list);
1275    
1276                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1277                                            finderArgs, list);
1278    
1279                                    closeSession(session);
1280                            }
1281                    }
1282    
1283                    return list;
1284            }
1285    
1286            public AssetVocabulary findByCompanyId_First(long companyId,
1287                    OrderByComparator orderByComparator)
1288                    throws NoSuchVocabularyException, SystemException {
1289                    List<AssetVocabulary> list = findByCompanyId(companyId, 0, 1,
1290                                    orderByComparator);
1291    
1292                    if (list.isEmpty()) {
1293                            StringBundler msg = new StringBundler(4);
1294    
1295                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1296    
1297                            msg.append("companyId=");
1298                            msg.append(companyId);
1299    
1300                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1301    
1302                            throw new NoSuchVocabularyException(msg.toString());
1303                    }
1304                    else {
1305                            return list.get(0);
1306                    }
1307            }
1308    
1309            public AssetVocabulary findByCompanyId_Last(long companyId,
1310                    OrderByComparator orderByComparator)
1311                    throws NoSuchVocabularyException, SystemException {
1312                    int count = countByCompanyId(companyId);
1313    
1314                    List<AssetVocabulary> list = findByCompanyId(companyId, count - 1,
1315                                    count, orderByComparator);
1316    
1317                    if (list.isEmpty()) {
1318                            StringBundler msg = new StringBundler(4);
1319    
1320                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1321    
1322                            msg.append("companyId=");
1323                            msg.append(companyId);
1324    
1325                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1326    
1327                            throw new NoSuchVocabularyException(msg.toString());
1328                    }
1329                    else {
1330                            return list.get(0);
1331                    }
1332            }
1333    
1334            public AssetVocabulary[] findByCompanyId_PrevAndNext(long vocabularyId,
1335                    long companyId, OrderByComparator orderByComparator)
1336                    throws NoSuchVocabularyException, SystemException {
1337                    AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
1338    
1339                    Session session = null;
1340    
1341                    try {
1342                            session = openSession();
1343    
1344                            AssetVocabulary[] array = new AssetVocabularyImpl[3];
1345    
1346                            array[0] = getByCompanyId_PrevAndNext(session, assetVocabulary,
1347                                            companyId, orderByComparator, true);
1348    
1349                            array[1] = assetVocabulary;
1350    
1351                            array[2] = getByCompanyId_PrevAndNext(session, assetVocabulary,
1352                                            companyId, orderByComparator, false);
1353    
1354                            return array;
1355                    }
1356                    catch (Exception e) {
1357                            throw processException(e);
1358                    }
1359                    finally {
1360                            closeSession(session);
1361                    }
1362            }
1363    
1364            protected AssetVocabulary getByCompanyId_PrevAndNext(Session session,
1365                    AssetVocabulary assetVocabulary, long companyId,
1366                    OrderByComparator orderByComparator, boolean previous) {
1367                    StringBundler query = null;
1368    
1369                    if (orderByComparator != null) {
1370                            query = new StringBundler(6 +
1371                                            (orderByComparator.getOrderByFields().length * 6));
1372                    }
1373                    else {
1374                            query = new StringBundler(3);
1375                    }
1376    
1377                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1378    
1379                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1380    
1381                    if (orderByComparator != null) {
1382                            String[] orderByFields = orderByComparator.getOrderByFields();
1383    
1384                            if (orderByFields.length > 0) {
1385                                    query.append(WHERE_AND);
1386                            }
1387    
1388                            for (int i = 0; i < orderByFields.length; i++) {
1389                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1390                                    query.append(orderByFields[i]);
1391    
1392                                    if ((i + 1) < orderByFields.length) {
1393                                            if (orderByComparator.isAscending() ^ previous) {
1394                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1395                                            }
1396                                            else {
1397                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1398                                            }
1399                                    }
1400                                    else {
1401                                            if (orderByComparator.isAscending() ^ previous) {
1402                                                    query.append(WHERE_GREATER_THAN);
1403                                            }
1404                                            else {
1405                                                    query.append(WHERE_LESSER_THAN);
1406                                            }
1407                                    }
1408                            }
1409    
1410                            query.append(ORDER_BY_CLAUSE);
1411    
1412                            for (int i = 0; i < orderByFields.length; i++) {
1413                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1414                                    query.append(orderByFields[i]);
1415    
1416                                    if ((i + 1) < orderByFields.length) {
1417                                            if (orderByComparator.isAscending() ^ previous) {
1418                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1419                                            }
1420                                            else {
1421                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1422                                            }
1423                                    }
1424                                    else {
1425                                            if (orderByComparator.isAscending() ^ previous) {
1426                                                    query.append(ORDER_BY_ASC);
1427                                            }
1428                                            else {
1429                                                    query.append(ORDER_BY_DESC);
1430                                            }
1431                                    }
1432                            }
1433                    }
1434    
1435                    else {
1436                            query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1437                    }
1438    
1439                    String sql = query.toString();
1440    
1441                    Query q = session.createQuery(sql);
1442    
1443                    q.setFirstResult(0);
1444                    q.setMaxResults(2);
1445    
1446                    QueryPos qPos = QueryPos.getInstance(q);
1447    
1448                    qPos.add(companyId);
1449    
1450                    if (orderByComparator != null) {
1451                            Object[] values = orderByComparator.getOrderByValues(assetVocabulary);
1452    
1453                            for (Object value : values) {
1454                                    qPos.add(value);
1455                            }
1456                    }
1457    
1458                    List<AssetVocabulary> list = q.list();
1459    
1460                    if (list.size() == 2) {
1461                            return list.get(1);
1462                    }
1463                    else {
1464                            return null;
1465                    }
1466            }
1467    
1468            public AssetVocabulary findByG_N(long groupId, String name)
1469                    throws NoSuchVocabularyException, SystemException {
1470                    AssetVocabulary assetVocabulary = fetchByG_N(groupId, name);
1471    
1472                    if (assetVocabulary == null) {
1473                            StringBundler msg = new StringBundler(6);
1474    
1475                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1476    
1477                            msg.append("groupId=");
1478                            msg.append(groupId);
1479    
1480                            msg.append(", name=");
1481                            msg.append(name);
1482    
1483                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1484    
1485                            if (_log.isWarnEnabled()) {
1486                                    _log.warn(msg.toString());
1487                            }
1488    
1489                            throw new NoSuchVocabularyException(msg.toString());
1490                    }
1491    
1492                    return assetVocabulary;
1493            }
1494    
1495            public AssetVocabulary fetchByG_N(long groupId, String name)
1496                    throws SystemException {
1497                    return fetchByG_N(groupId, name, true);
1498            }
1499    
1500            public AssetVocabulary fetchByG_N(long groupId, String name,
1501                    boolean retrieveFromCache) throws SystemException {
1502                    Object[] finderArgs = new Object[] { groupId, name };
1503    
1504                    Object result = null;
1505    
1506                    if (retrieveFromCache) {
1507                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1508                                            finderArgs, this);
1509                    }
1510    
1511                    if (result == null) {
1512                            Session session = null;
1513    
1514                            try {
1515                                    session = openSession();
1516    
1517                                    StringBundler query = new StringBundler(4);
1518    
1519                                    query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1520    
1521                                    query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1522    
1523                                    if (name == null) {
1524                                            query.append(_FINDER_COLUMN_G_N_NAME_1);
1525                                    }
1526                                    else {
1527                                            if (name.equals(StringPool.BLANK)) {
1528                                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
1529                                            }
1530                                            else {
1531                                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
1532                                            }
1533                                    }
1534    
1535                                    query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1536    
1537                                    String sql = query.toString();
1538    
1539                                    Query q = session.createQuery(sql);
1540    
1541                                    QueryPos qPos = QueryPos.getInstance(q);
1542    
1543                                    qPos.add(groupId);
1544    
1545                                    if (name != null) {
1546                                            qPos.add(name);
1547                                    }
1548    
1549                                    List<AssetVocabulary> list = q.list();
1550    
1551                                    result = list;
1552    
1553                                    AssetVocabulary assetVocabulary = null;
1554    
1555                                    if (list.isEmpty()) {
1556                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1557                                                    finderArgs, list);
1558                                    }
1559                                    else {
1560                                            assetVocabulary = list.get(0);
1561    
1562                                            cacheResult(assetVocabulary);
1563    
1564                                            if ((assetVocabulary.getGroupId() != groupId) ||
1565                                                            (assetVocabulary.getName() == null) ||
1566                                                            !assetVocabulary.getName().equals(name)) {
1567                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1568                                                            finderArgs, assetVocabulary);
1569                                            }
1570                                    }
1571    
1572                                    return assetVocabulary;
1573                            }
1574                            catch (Exception e) {
1575                                    throw processException(e);
1576                            }
1577                            finally {
1578                                    if (result == null) {
1579                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1580                                                    finderArgs, new ArrayList<AssetVocabulary>());
1581                                    }
1582    
1583                                    closeSession(session);
1584                            }
1585                    }
1586                    else {
1587                            if (result instanceof List<?>) {
1588                                    return null;
1589                            }
1590                            else {
1591                                    return (AssetVocabulary)result;
1592                            }
1593                    }
1594            }
1595    
1596            public List<AssetVocabulary> findAll() throws SystemException {
1597                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1598            }
1599    
1600            public List<AssetVocabulary> findAll(int start, int end)
1601                    throws SystemException {
1602                    return findAll(start, end, null);
1603            }
1604    
1605            public List<AssetVocabulary> findAll(int start, int end,
1606                    OrderByComparator orderByComparator) throws SystemException {
1607                    Object[] finderArgs = new Object[] {
1608                                    String.valueOf(start), String.valueOf(end),
1609                                    String.valueOf(orderByComparator)
1610                            };
1611    
1612                    List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1613                                    finderArgs, this);
1614    
1615                    if (list == null) {
1616                            Session session = null;
1617    
1618                            try {
1619                                    session = openSession();
1620    
1621                                    StringBundler query = null;
1622                                    String sql = null;
1623    
1624                                    if (orderByComparator != null) {
1625                                            query = new StringBundler(2 +
1626                                                            (orderByComparator.getOrderByFields().length * 3));
1627    
1628                                            query.append(_SQL_SELECT_ASSETVOCABULARY);
1629    
1630                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1631                                                    orderByComparator);
1632    
1633                                            sql = query.toString();
1634                                    }
1635                                    else {
1636                                            sql = _SQL_SELECT_ASSETVOCABULARY.concat(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1637                                    }
1638    
1639                                    Query q = session.createQuery(sql);
1640    
1641                                    if (orderByComparator == null) {
1642                                            list = (List<AssetVocabulary>)QueryUtil.list(q,
1643                                                            getDialect(), start, end, false);
1644    
1645                                            Collections.sort(list);
1646                                    }
1647                                    else {
1648                                            list = (List<AssetVocabulary>)QueryUtil.list(q,
1649                                                            getDialect(), start, end);
1650                                    }
1651                            }
1652                            catch (Exception e) {
1653                                    throw processException(e);
1654                            }
1655                            finally {
1656                                    if (list == null) {
1657                                            list = new ArrayList<AssetVocabulary>();
1658                                    }
1659    
1660                                    cacheResult(list);
1661    
1662                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1663    
1664                                    closeSession(session);
1665                            }
1666                    }
1667    
1668                    return list;
1669            }
1670    
1671            public void removeByUuid(String uuid) throws SystemException {
1672                    for (AssetVocabulary assetVocabulary : findByUuid(uuid)) {
1673                            remove(assetVocabulary);
1674                    }
1675            }
1676    
1677            public void removeByUUID_G(String uuid, long groupId)
1678                    throws NoSuchVocabularyException, SystemException {
1679                    AssetVocabulary assetVocabulary = findByUUID_G(uuid, groupId);
1680    
1681                    remove(assetVocabulary);
1682            }
1683    
1684            public void removeByGroupId(long groupId) throws SystemException {
1685                    for (AssetVocabulary assetVocabulary : findByGroupId(groupId)) {
1686                            remove(assetVocabulary);
1687                    }
1688            }
1689    
1690            public void removeByCompanyId(long companyId) throws SystemException {
1691                    for (AssetVocabulary assetVocabulary : findByCompanyId(companyId)) {
1692                            remove(assetVocabulary);
1693                    }
1694            }
1695    
1696            public void removeByG_N(long groupId, String name)
1697                    throws NoSuchVocabularyException, SystemException {
1698                    AssetVocabulary assetVocabulary = findByG_N(groupId, name);
1699    
1700                    remove(assetVocabulary);
1701            }
1702    
1703            public void removeAll() throws SystemException {
1704                    for (AssetVocabulary assetVocabulary : findAll()) {
1705                            remove(assetVocabulary);
1706                    }
1707            }
1708    
1709            public int countByUuid(String uuid) throws SystemException {
1710                    Object[] finderArgs = new Object[] { uuid };
1711    
1712                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1713                                    finderArgs, this);
1714    
1715                    if (count == null) {
1716                            Session session = null;
1717    
1718                            try {
1719                                    session = openSession();
1720    
1721                                    StringBundler query = new StringBundler(2);
1722    
1723                                    query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1724    
1725                                    if (uuid == null) {
1726                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1727                                    }
1728                                    else {
1729                                            if (uuid.equals(StringPool.BLANK)) {
1730                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1731                                            }
1732                                            else {
1733                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1734                                            }
1735                                    }
1736    
1737                                    String sql = query.toString();
1738    
1739                                    Query q = session.createQuery(sql);
1740    
1741                                    QueryPos qPos = QueryPos.getInstance(q);
1742    
1743                                    if (uuid != null) {
1744                                            qPos.add(uuid);
1745                                    }
1746    
1747                                    count = (Long)q.uniqueResult();
1748                            }
1749                            catch (Exception e) {
1750                                    throw processException(e);
1751                            }
1752                            finally {
1753                                    if (count == null) {
1754                                            count = Long.valueOf(0);
1755                                    }
1756    
1757                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1758                                            finderArgs, count);
1759    
1760                                    closeSession(session);
1761                            }
1762                    }
1763    
1764                    return count.intValue();
1765            }
1766    
1767            public int countByUUID_G(String uuid, long groupId)
1768                    throws SystemException {
1769                    Object[] finderArgs = new Object[] { uuid, groupId };
1770    
1771                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1772                                    finderArgs, this);
1773    
1774                    if (count == null) {
1775                            Session session = null;
1776    
1777                            try {
1778                                    session = openSession();
1779    
1780                                    StringBundler query = new StringBundler(3);
1781    
1782                                    query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1783    
1784                                    if (uuid == null) {
1785                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1786                                    }
1787                                    else {
1788                                            if (uuid.equals(StringPool.BLANK)) {
1789                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1790                                            }
1791                                            else {
1792                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1793                                            }
1794                                    }
1795    
1796                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1797    
1798                                    String sql = query.toString();
1799    
1800                                    Query q = session.createQuery(sql);
1801    
1802                                    QueryPos qPos = QueryPos.getInstance(q);
1803    
1804                                    if (uuid != null) {
1805                                            qPos.add(uuid);
1806                                    }
1807    
1808                                    qPos.add(groupId);
1809    
1810                                    count = (Long)q.uniqueResult();
1811                            }
1812                            catch (Exception e) {
1813                                    throw processException(e);
1814                            }
1815                            finally {
1816                                    if (count == null) {
1817                                            count = Long.valueOf(0);
1818                                    }
1819    
1820                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1821                                            finderArgs, count);
1822    
1823                                    closeSession(session);
1824                            }
1825                    }
1826    
1827                    return count.intValue();
1828            }
1829    
1830            public int countByGroupId(long groupId) throws SystemException {
1831                    Object[] finderArgs = new Object[] { groupId };
1832    
1833                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1834                                    finderArgs, this);
1835    
1836                    if (count == null) {
1837                            Session session = null;
1838    
1839                            try {
1840                                    session = openSession();
1841    
1842                                    StringBundler query = new StringBundler(2);
1843    
1844                                    query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1845    
1846                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1847    
1848                                    String sql = query.toString();
1849    
1850                                    Query q = session.createQuery(sql);
1851    
1852                                    QueryPos qPos = QueryPos.getInstance(q);
1853    
1854                                    qPos.add(groupId);
1855    
1856                                    count = (Long)q.uniqueResult();
1857                            }
1858                            catch (Exception e) {
1859                                    throw processException(e);
1860                            }
1861                            finally {
1862                                    if (count == null) {
1863                                            count = Long.valueOf(0);
1864                                    }
1865    
1866                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1867                                            finderArgs, count);
1868    
1869                                    closeSession(session);
1870                            }
1871                    }
1872    
1873                    return count.intValue();
1874            }
1875    
1876            public int filterCountByGroupId(long groupId) throws SystemException {
1877                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1878                            return countByGroupId(groupId);
1879                    }
1880    
1881                    Session session = null;
1882    
1883                    try {
1884                            session = openSession();
1885    
1886                            StringBundler query = new StringBundler(2);
1887    
1888                            query.append(_FILTER_SQL_COUNT_ASSETVOCABULARY_WHERE);
1889    
1890                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1891    
1892                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1893                                            AssetVocabulary.class.getName(), _FILTER_COLUMN_PK,
1894                                            _FILTER_COLUMN_USERID, groupId);
1895    
1896                            SQLQuery q = session.createSQLQuery(sql);
1897    
1898                            q.addScalar(COUNT_COLUMN_NAME,
1899                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1900    
1901                            QueryPos qPos = QueryPos.getInstance(q);
1902    
1903                            qPos.add(groupId);
1904    
1905                            Long count = (Long)q.uniqueResult();
1906    
1907                            return count.intValue();
1908                    }
1909                    catch (Exception e) {
1910                            throw processException(e);
1911                    }
1912                    finally {
1913                            closeSession(session);
1914                    }
1915            }
1916    
1917            public int countByCompanyId(long companyId) throws SystemException {
1918                    Object[] finderArgs = new Object[] { companyId };
1919    
1920                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1921                                    finderArgs, this);
1922    
1923                    if (count == null) {
1924                            Session session = null;
1925    
1926                            try {
1927                                    session = openSession();
1928    
1929                                    StringBundler query = new StringBundler(2);
1930    
1931                                    query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1932    
1933                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1934    
1935                                    String sql = query.toString();
1936    
1937                                    Query q = session.createQuery(sql);
1938    
1939                                    QueryPos qPos = QueryPos.getInstance(q);
1940    
1941                                    qPos.add(companyId);
1942    
1943                                    count = (Long)q.uniqueResult();
1944                            }
1945                            catch (Exception e) {
1946                                    throw processException(e);
1947                            }
1948                            finally {
1949                                    if (count == null) {
1950                                            count = Long.valueOf(0);
1951                                    }
1952    
1953                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1954                                            finderArgs, count);
1955    
1956                                    closeSession(session);
1957                            }
1958                    }
1959    
1960                    return count.intValue();
1961            }
1962    
1963            public int countByG_N(long groupId, String name) throws SystemException {
1964                    Object[] finderArgs = new Object[] { groupId, name };
1965    
1966                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
1967                                    finderArgs, this);
1968    
1969                    if (count == null) {
1970                            Session session = null;
1971    
1972                            try {
1973                                    session = openSession();
1974    
1975                                    StringBundler query = new StringBundler(3);
1976    
1977                                    query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1978    
1979                                    query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1980    
1981                                    if (name == null) {
1982                                            query.append(_FINDER_COLUMN_G_N_NAME_1);
1983                                    }
1984                                    else {
1985                                            if (name.equals(StringPool.BLANK)) {
1986                                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
1987                                            }
1988                                            else {
1989                                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
1990                                            }
1991                                    }
1992    
1993                                    String sql = query.toString();
1994    
1995                                    Query q = session.createQuery(sql);
1996    
1997                                    QueryPos qPos = QueryPos.getInstance(q);
1998    
1999                                    qPos.add(groupId);
2000    
2001                                    if (name != null) {
2002                                            qPos.add(name);
2003                                    }
2004    
2005                                    count = (Long)q.uniqueResult();
2006                            }
2007                            catch (Exception e) {
2008                                    throw processException(e);
2009                            }
2010                            finally {
2011                                    if (count == null) {
2012                                            count = Long.valueOf(0);
2013                                    }
2014    
2015                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
2016                                            count);
2017    
2018                                    closeSession(session);
2019                            }
2020                    }
2021    
2022                    return count.intValue();
2023            }
2024    
2025            public int filterCountByG_N(long groupId, String name)
2026                    throws SystemException {
2027                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2028                            return countByG_N(groupId, name);
2029                    }
2030    
2031                    Session session = null;
2032    
2033                    try {
2034                            session = openSession();
2035    
2036                            StringBundler query = new StringBundler(3);
2037    
2038                            query.append(_FILTER_SQL_COUNT_ASSETVOCABULARY_WHERE);
2039    
2040                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2041    
2042                            if (name == null) {
2043                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
2044                            }
2045                            else {
2046                                    if (name.equals(StringPool.BLANK)) {
2047                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
2048                                    }
2049                                    else {
2050                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
2051                                    }
2052                            }
2053    
2054                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2055                                            AssetVocabulary.class.getName(), _FILTER_COLUMN_PK,
2056                                            _FILTER_COLUMN_USERID, groupId);
2057    
2058                            SQLQuery q = session.createSQLQuery(sql);
2059    
2060                            q.addScalar(COUNT_COLUMN_NAME,
2061                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2062    
2063                            QueryPos qPos = QueryPos.getInstance(q);
2064    
2065                            qPos.add(groupId);
2066    
2067                            if (name != null) {
2068                                    qPos.add(name);
2069                            }
2070    
2071                            Long count = (Long)q.uniqueResult();
2072    
2073                            return count.intValue();
2074                    }
2075                    catch (Exception e) {
2076                            throw processException(e);
2077                    }
2078                    finally {
2079                            closeSession(session);
2080                    }
2081            }
2082    
2083            public int countAll() throws SystemException {
2084                    Object[] finderArgs = new Object[0];
2085    
2086                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2087                                    finderArgs, this);
2088    
2089                    if (count == null) {
2090                            Session session = null;
2091    
2092                            try {
2093                                    session = openSession();
2094    
2095                                    Query q = session.createQuery(_SQL_COUNT_ASSETVOCABULARY);
2096    
2097                                    count = (Long)q.uniqueResult();
2098                            }
2099                            catch (Exception e) {
2100                                    throw processException(e);
2101                            }
2102                            finally {
2103                                    if (count == null) {
2104                                            count = Long.valueOf(0);
2105                                    }
2106    
2107                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2108                                            count);
2109    
2110                                    closeSession(session);
2111                            }
2112                    }
2113    
2114                    return count.intValue();
2115            }
2116    
2117            public void afterPropertiesSet() {
2118                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2119                                            com.liferay.portal.util.PropsUtil.get(
2120                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetVocabulary")));
2121    
2122                    if (listenerClassNames.length > 0) {
2123                            try {
2124                                    List<ModelListener<AssetVocabulary>> listenersList = new ArrayList<ModelListener<AssetVocabulary>>();
2125    
2126                                    for (String listenerClassName : listenerClassNames) {
2127                                            listenersList.add((ModelListener<AssetVocabulary>)InstanceFactory.newInstance(
2128                                                            listenerClassName));
2129                                    }
2130    
2131                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2132                            }
2133                            catch (Exception e) {
2134                                    _log.error(e);
2135                            }
2136                    }
2137            }
2138    
2139            @BeanReference(type = AssetCategoryPersistence.class)
2140            protected AssetCategoryPersistence assetCategoryPersistence;
2141            @BeanReference(type = AssetCategoryPropertyPersistence.class)
2142            protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
2143            @BeanReference(type = AssetEntryPersistence.class)
2144            protected AssetEntryPersistence assetEntryPersistence;
2145            @BeanReference(type = AssetLinkPersistence.class)
2146            protected AssetLinkPersistence assetLinkPersistence;
2147            @BeanReference(type = AssetTagPersistence.class)
2148            protected AssetTagPersistence assetTagPersistence;
2149            @BeanReference(type = AssetTagPropertyPersistence.class)
2150            protected AssetTagPropertyPersistence assetTagPropertyPersistence;
2151            @BeanReference(type = AssetTagStatsPersistence.class)
2152            protected AssetTagStatsPersistence assetTagStatsPersistence;
2153            @BeanReference(type = AssetVocabularyPersistence.class)
2154            protected AssetVocabularyPersistence assetVocabularyPersistence;
2155            @BeanReference(type = GroupPersistence.class)
2156            protected GroupPersistence groupPersistence;
2157            @BeanReference(type = ResourcePersistence.class)
2158            protected ResourcePersistence resourcePersistence;
2159            @BeanReference(type = UserPersistence.class)
2160            protected UserPersistence userPersistence;
2161            private static final String _SQL_SELECT_ASSETVOCABULARY = "SELECT assetVocabulary FROM AssetVocabulary assetVocabulary";
2162            private static final String _SQL_SELECT_ASSETVOCABULARY_WHERE = "SELECT assetVocabulary FROM AssetVocabulary assetVocabulary WHERE ";
2163            private static final String _SQL_COUNT_ASSETVOCABULARY = "SELECT COUNT(assetVocabulary) FROM AssetVocabulary assetVocabulary";
2164            private static final String _SQL_COUNT_ASSETVOCABULARY_WHERE = "SELECT COUNT(assetVocabulary) FROM AssetVocabulary assetVocabulary WHERE ";
2165            private static final String _FINDER_COLUMN_UUID_UUID_1 = "assetVocabulary.uuid IS NULL";
2166            private static final String _FINDER_COLUMN_UUID_UUID_2 = "assetVocabulary.uuid = ?";
2167            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(assetVocabulary.uuid IS NULL OR assetVocabulary.uuid = ?)";
2168            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "assetVocabulary.uuid IS NULL AND ";
2169            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "assetVocabulary.uuid = ? AND ";
2170            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(assetVocabulary.uuid IS NULL OR assetVocabulary.uuid = ?) AND ";
2171            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "assetVocabulary.groupId = ?";
2172            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetVocabulary.groupId = ?";
2173            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetVocabulary.companyId = ?";
2174            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "assetVocabulary.groupId = ? AND ";
2175            private static final String _FINDER_COLUMN_G_N_NAME_1 = "assetVocabulary.name IS NULL";
2176            private static final String _FINDER_COLUMN_G_N_NAME_2 = "assetVocabulary.name = ?";
2177            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(assetVocabulary.name IS NULL OR assetVocabulary.name = ?)";
2178            private static final String _FILTER_SQL_SELECT_ASSETVOCABULARY_WHERE = "SELECT DISTINCT {assetVocabulary.*} FROM AssetVocabulary assetVocabulary WHERE ";
2179            private static final String _FILTER_SQL_COUNT_ASSETVOCABULARY_WHERE = "SELECT COUNT(DISTINCT assetVocabulary.vocabularyId) AS COUNT_VALUE FROM AssetVocabulary assetVocabulary WHERE ";
2180            private static final String _FILTER_COLUMN_PK = "assetVocabulary.vocabularyId";
2181            private static final String _FILTER_COLUMN_USERID = "assetVocabulary.userId";
2182            private static final String _FILTER_ENTITY_ALIAS = "assetVocabulary";
2183            private static final String _ORDER_BY_ENTITY_ALIAS = "assetVocabulary.";
2184            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetVocabulary exists with the primary key ";
2185            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetVocabulary exists with the key {";
2186            private static Log _log = LogFactoryUtil.getLog(AssetVocabularyPersistenceImpl.class);
2187    }