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