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