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