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