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