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