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