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