1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.asset.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.exception.SystemException;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.kernel.util.Validator;
37  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.service.persistence.BatchSessionUtil;
40  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41  
42  import com.liferay.portlet.asset.NoSuchVocabularyException;
43  import com.liferay.portlet.asset.model.AssetVocabulary;
44  import com.liferay.portlet.asset.model.impl.AssetVocabularyImpl;
45  import com.liferay.portlet.asset.model.impl.AssetVocabularyModelImpl;
46  
47  import java.io.Serializable;
48  
49  import java.util.ArrayList;
50  import java.util.Collections;
51  import java.util.List;
52  
53  /**
54   * <a href="AssetVocabularyPersistenceImpl.java.html"><b><i>View Source</i></b></a>
55   *
56   * <p>
57   * ServiceBuilder generated this class. Modifications in this class will be
58   * overwritten the next time is generated.
59   * </p>
60   *
61   * @author    Brian Wing Shun Chan
62   * @see       AssetVocabularyPersistence
63   * @see       AssetVocabularyUtil
64   * @generated
65   */
66  public class AssetVocabularyPersistenceImpl extends BasePersistenceImpl<AssetVocabulary>
67      implements AssetVocabularyPersistence {
68      public static final String FINDER_CLASS_NAME_ENTITY = AssetVocabularyImpl.class.getName();
69      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
70          ".List";
71      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
72              AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
73              FINDER_CLASS_NAME_LIST, "findByUuid",
74              new String[] { String.class.getName() });
75      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
76              AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
77              FINDER_CLASS_NAME_LIST, "findByUuid",
78              new String[] {
79                  String.class.getName(),
80                  
81              "java.lang.Integer", "java.lang.Integer",
82                  "com.liferay.portal.kernel.util.OrderByComparator"
83              });
84      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
85              AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
86              FINDER_CLASS_NAME_LIST, "countByUuid",
87              new String[] { String.class.getName() });
88      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
89              AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
90              FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
91              new String[] { String.class.getName(), Long.class.getName() });
92      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
93              AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
94              FINDER_CLASS_NAME_LIST, "countByUUID_G",
95              new String[] { String.class.getName(), Long.class.getName() });
96      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
97              AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
98              FINDER_CLASS_NAME_LIST, "findByGroupId",
99              new String[] { Long.class.getName() });
100     public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
101             AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
102             FINDER_CLASS_NAME_LIST, "findByGroupId",
103             new String[] {
104                 Long.class.getName(),
105                 
106             "java.lang.Integer", "java.lang.Integer",
107                 "com.liferay.portal.kernel.util.OrderByComparator"
108             });
109     public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
110             AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
111             FINDER_CLASS_NAME_LIST, "countByGroupId",
112             new String[] { Long.class.getName() });
113     public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
114             AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
115             FINDER_CLASS_NAME_LIST, "findByCompanyId",
116             new String[] { Long.class.getName() });
117     public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
118             AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
119             FINDER_CLASS_NAME_LIST, "findByCompanyId",
120             new String[] {
121                 Long.class.getName(),
122                 
123             "java.lang.Integer", "java.lang.Integer",
124                 "com.liferay.portal.kernel.util.OrderByComparator"
125             });
126     public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
127             AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
128             FINDER_CLASS_NAME_LIST, "countByCompanyId",
129             new String[] { Long.class.getName() });
130     public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
131             AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
132             FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
133             new String[] { Long.class.getName(), String.class.getName() });
134     public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
135             AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
136             FINDER_CLASS_NAME_LIST, "countByG_N",
137             new String[] { Long.class.getName(), String.class.getName() });
138     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
139             AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
140             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
141     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
142             AssetVocabularyModelImpl.FINDER_CACHE_ENABLED,
143             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
144 
145     public void cacheResult(AssetVocabulary assetVocabulary) {
146         EntityCacheUtil.putResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
147             AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey(),
148             assetVocabulary);
149 
150         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
151             new Object[] {
152                 assetVocabulary.getUuid(),
153                 new Long(assetVocabulary.getGroupId())
154             }, assetVocabulary);
155 
156         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
157             new Object[] {
158                 new Long(assetVocabulary.getGroupId()),
159                 
160             assetVocabulary.getName()
161             }, assetVocabulary);
162     }
163 
164     public void cacheResult(List<AssetVocabulary> assetVocabularies) {
165         for (AssetVocabulary assetVocabulary : assetVocabularies) {
166             if (EntityCacheUtil.getResult(
167                         AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
168                         AssetVocabularyImpl.class,
169                         assetVocabulary.getPrimaryKey(), this) == null) {
170                 cacheResult(assetVocabulary);
171             }
172         }
173     }
174 
175     public void clearCache() {
176         CacheRegistry.clear(AssetVocabularyImpl.class.getName());
177         EntityCacheUtil.clearCache(AssetVocabularyImpl.class.getName());
178         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
179         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
180     }
181 
182     public AssetVocabulary create(long vocabularyId) {
183         AssetVocabulary assetVocabulary = new AssetVocabularyImpl();
184 
185         assetVocabulary.setNew(true);
186         assetVocabulary.setPrimaryKey(vocabularyId);
187 
188         String uuid = PortalUUIDUtil.generate();
189 
190         assetVocabulary.setUuid(uuid);
191 
192         return assetVocabulary;
193     }
194 
195     public AssetVocabulary remove(Serializable primaryKey)
196         throws NoSuchModelException, SystemException {
197         return remove(((Long)primaryKey).longValue());
198     }
199 
200     public AssetVocabulary remove(long vocabularyId)
201         throws NoSuchVocabularyException, SystemException {
202         Session session = null;
203 
204         try {
205             session = openSession();
206 
207             AssetVocabulary assetVocabulary = (AssetVocabulary)session.get(AssetVocabularyImpl.class,
208                     new Long(vocabularyId));
209 
210             if (assetVocabulary == null) {
211                 if (_log.isWarnEnabled()) {
212                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + vocabularyId);
213                 }
214 
215                 throw new NoSuchVocabularyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
216                     vocabularyId);
217             }
218 
219             return remove(assetVocabulary);
220         }
221         catch (NoSuchVocabularyException nsee) {
222             throw nsee;
223         }
224         catch (Exception e) {
225             throw processException(e);
226         }
227         finally {
228             closeSession(session);
229         }
230     }
231 
232     public AssetVocabulary remove(AssetVocabulary assetVocabulary)
233         throws SystemException {
234         for (ModelListener<AssetVocabulary> listener : listeners) {
235             listener.onBeforeRemove(assetVocabulary);
236         }
237 
238         assetVocabulary = removeImpl(assetVocabulary);
239 
240         for (ModelListener<AssetVocabulary> listener : listeners) {
241             listener.onAfterRemove(assetVocabulary);
242         }
243 
244         return assetVocabulary;
245     }
246 
247     protected AssetVocabulary removeImpl(AssetVocabulary assetVocabulary)
248         throws SystemException {
249         assetVocabulary = toUnwrappedModel(assetVocabulary);
250 
251         Session session = null;
252 
253         try {
254             session = openSession();
255 
256             if (assetVocabulary.isCachedModel() ||
257                     BatchSessionUtil.isEnabled()) {
258                 Object staleObject = session.get(AssetVocabularyImpl.class,
259                         assetVocabulary.getPrimaryKeyObj());
260 
261                 if (staleObject != null) {
262                     session.evict(staleObject);
263                 }
264             }
265 
266             session.delete(assetVocabulary);
267 
268             session.flush();
269         }
270         catch (Exception e) {
271             throw processException(e);
272         }
273         finally {
274             closeSession(session);
275         }
276 
277         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
278 
279         AssetVocabularyModelImpl assetVocabularyModelImpl = (AssetVocabularyModelImpl)assetVocabulary;
280 
281         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
282             new Object[] {
283                 assetVocabularyModelImpl.getOriginalUuid(),
284                 new Long(assetVocabularyModelImpl.getOriginalGroupId())
285             });
286 
287         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
288             new Object[] {
289                 new Long(assetVocabularyModelImpl.getOriginalGroupId()),
290                 
291             assetVocabularyModelImpl.getOriginalName()
292             });
293 
294         EntityCacheUtil.removeResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
295             AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey());
296 
297         return assetVocabulary;
298     }
299 
300     public AssetVocabulary updateImpl(
301         com.liferay.portlet.asset.model.AssetVocabulary assetVocabulary,
302         boolean merge) throws SystemException {
303         assetVocabulary = toUnwrappedModel(assetVocabulary);
304 
305         boolean isNew = assetVocabulary.isNew();
306 
307         AssetVocabularyModelImpl assetVocabularyModelImpl = (AssetVocabularyModelImpl)assetVocabulary;
308 
309         if (Validator.isNull(assetVocabulary.getUuid())) {
310             String uuid = PortalUUIDUtil.generate();
311 
312             assetVocabulary.setUuid(uuid);
313         }
314 
315         Session session = null;
316 
317         try {
318             session = openSession();
319 
320             BatchSessionUtil.update(session, assetVocabulary, merge);
321 
322             assetVocabulary.setNew(false);
323         }
324         catch (Exception e) {
325             throw processException(e);
326         }
327         finally {
328             closeSession(session);
329         }
330 
331         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
332 
333         EntityCacheUtil.putResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
334             AssetVocabularyImpl.class, assetVocabulary.getPrimaryKey(),
335             assetVocabulary);
336 
337         if (!isNew &&
338                 (!Validator.equals(assetVocabulary.getUuid(),
339                     assetVocabularyModelImpl.getOriginalUuid()) ||
340                 (assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()))) {
341             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
342                 new Object[] {
343                     assetVocabularyModelImpl.getOriginalUuid(),
344                     new Long(assetVocabularyModelImpl.getOriginalGroupId())
345                 });
346         }
347 
348         if (isNew ||
349                 (!Validator.equals(assetVocabulary.getUuid(),
350                     assetVocabularyModelImpl.getOriginalUuid()) ||
351                 (assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()))) {
352             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
353                 new Object[] {
354                     assetVocabulary.getUuid(),
355                     new Long(assetVocabulary.getGroupId())
356                 }, assetVocabulary);
357         }
358 
359         if (!isNew &&
360                 ((assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()) ||
361                 !Validator.equals(assetVocabulary.getName(),
362                     assetVocabularyModelImpl.getOriginalName()))) {
363             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
364                 new Object[] {
365                     new Long(assetVocabularyModelImpl.getOriginalGroupId()),
366                     
367                 assetVocabularyModelImpl.getOriginalName()
368                 });
369         }
370 
371         if (isNew ||
372                 ((assetVocabulary.getGroupId() != assetVocabularyModelImpl.getOriginalGroupId()) ||
373                 !Validator.equals(assetVocabulary.getName(),
374                     assetVocabularyModelImpl.getOriginalName()))) {
375             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
376                 new Object[] {
377                     new Long(assetVocabulary.getGroupId()),
378                     
379                 assetVocabulary.getName()
380                 }, assetVocabulary);
381         }
382 
383         return assetVocabulary;
384     }
385 
386     protected AssetVocabulary toUnwrappedModel(AssetVocabulary assetVocabulary) {
387         if (assetVocabulary instanceof AssetVocabularyImpl) {
388             return assetVocabulary;
389         }
390 
391         AssetVocabularyImpl assetVocabularyImpl = new AssetVocabularyImpl();
392 
393         assetVocabularyImpl.setNew(assetVocabulary.isNew());
394         assetVocabularyImpl.setPrimaryKey(assetVocabulary.getPrimaryKey());
395 
396         assetVocabularyImpl.setUuid(assetVocabulary.getUuid());
397         assetVocabularyImpl.setVocabularyId(assetVocabulary.getVocabularyId());
398         assetVocabularyImpl.setGroupId(assetVocabulary.getGroupId());
399         assetVocabularyImpl.setCompanyId(assetVocabulary.getCompanyId());
400         assetVocabularyImpl.setUserId(assetVocabulary.getUserId());
401         assetVocabularyImpl.setUserName(assetVocabulary.getUserName());
402         assetVocabularyImpl.setCreateDate(assetVocabulary.getCreateDate());
403         assetVocabularyImpl.setModifiedDate(assetVocabulary.getModifiedDate());
404         assetVocabularyImpl.setName(assetVocabulary.getName());
405         assetVocabularyImpl.setTitle(assetVocabulary.getTitle());
406         assetVocabularyImpl.setDescription(assetVocabulary.getDescription());
407         assetVocabularyImpl.setSettings(assetVocabulary.getSettings());
408 
409         return assetVocabularyImpl;
410     }
411 
412     public AssetVocabulary findByPrimaryKey(Serializable primaryKey)
413         throws NoSuchModelException, SystemException {
414         return findByPrimaryKey(((Long)primaryKey).longValue());
415     }
416 
417     public AssetVocabulary findByPrimaryKey(long vocabularyId)
418         throws NoSuchVocabularyException, SystemException {
419         AssetVocabulary assetVocabulary = fetchByPrimaryKey(vocabularyId);
420 
421         if (assetVocabulary == null) {
422             if (_log.isWarnEnabled()) {
423                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + vocabularyId);
424             }
425 
426             throw new NoSuchVocabularyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
427                 vocabularyId);
428         }
429 
430         return assetVocabulary;
431     }
432 
433     public AssetVocabulary fetchByPrimaryKey(Serializable primaryKey)
434         throws SystemException {
435         return fetchByPrimaryKey(((Long)primaryKey).longValue());
436     }
437 
438     public AssetVocabulary fetchByPrimaryKey(long vocabularyId)
439         throws SystemException {
440         AssetVocabulary assetVocabulary = (AssetVocabulary)EntityCacheUtil.getResult(AssetVocabularyModelImpl.ENTITY_CACHE_ENABLED,
441                 AssetVocabularyImpl.class, vocabularyId, this);
442 
443         if (assetVocabulary == null) {
444             Session session = null;
445 
446             try {
447                 session = openSession();
448 
449                 assetVocabulary = (AssetVocabulary)session.get(AssetVocabularyImpl.class,
450                         new Long(vocabularyId));
451             }
452             catch (Exception e) {
453                 throw processException(e);
454             }
455             finally {
456                 if (assetVocabulary != null) {
457                     cacheResult(assetVocabulary);
458                 }
459 
460                 closeSession(session);
461             }
462         }
463 
464         return assetVocabulary;
465     }
466 
467     public List<AssetVocabulary> findByUuid(String uuid)
468         throws SystemException {
469         Object[] finderArgs = new Object[] { uuid };
470 
471         List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
472                 finderArgs, this);
473 
474         if (list == null) {
475             Session session = null;
476 
477             try {
478                 session = openSession();
479 
480                 StringBundler query = new StringBundler(3);
481 
482                 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
483 
484                 if (uuid == null) {
485                     query.append(_FINDER_COLUMN_UUID_UUID_1);
486                 }
487                 else {
488                     if (uuid.equals(StringPool.BLANK)) {
489                         query.append(_FINDER_COLUMN_UUID_UUID_3);
490                     }
491                     else {
492                         query.append(_FINDER_COLUMN_UUID_UUID_2);
493                     }
494                 }
495 
496                 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
497 
498                 String sql = query.toString();
499 
500                 Query q = session.createQuery(sql);
501 
502                 QueryPos qPos = QueryPos.getInstance(q);
503 
504                 if (uuid != null) {
505                     qPos.add(uuid);
506                 }
507 
508                 list = q.list();
509             }
510             catch (Exception e) {
511                 throw processException(e);
512             }
513             finally {
514                 if (list == null) {
515                     list = new ArrayList<AssetVocabulary>();
516                 }
517 
518                 cacheResult(list);
519 
520                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
521                     list);
522 
523                 closeSession(session);
524             }
525         }
526 
527         return list;
528     }
529 
530     public List<AssetVocabulary> findByUuid(String uuid, int start, int end)
531         throws SystemException {
532         return findByUuid(uuid, start, end, null);
533     }
534 
535     public List<AssetVocabulary> findByUuid(String uuid, int start, int end,
536         OrderByComparator obc) throws SystemException {
537         Object[] finderArgs = new Object[] {
538                 uuid,
539                 
540                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
541             };
542 
543         List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
544                 finderArgs, this);
545 
546         if (list == null) {
547             Session session = null;
548 
549             try {
550                 session = openSession();
551 
552                 StringBundler query = null;
553 
554                 if (obc != null) {
555                     query = new StringBundler(3 +
556                             (obc.getOrderByFields().length * 3));
557                 }
558                 else {
559                     query = new StringBundler(3);
560                 }
561 
562                 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
563 
564                 if (uuid == null) {
565                     query.append(_FINDER_COLUMN_UUID_UUID_1);
566                 }
567                 else {
568                     if (uuid.equals(StringPool.BLANK)) {
569                         query.append(_FINDER_COLUMN_UUID_UUID_3);
570                     }
571                     else {
572                         query.append(_FINDER_COLUMN_UUID_UUID_2);
573                     }
574                 }
575 
576                 if (obc != null) {
577                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
578                 }
579 
580                 else {
581                     query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
582                 }
583 
584                 String sql = query.toString();
585 
586                 Query q = session.createQuery(sql);
587 
588                 QueryPos qPos = QueryPos.getInstance(q);
589 
590                 if (uuid != null) {
591                     qPos.add(uuid);
592                 }
593 
594                 list = (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
595                         start, end);
596             }
597             catch (Exception e) {
598                 throw processException(e);
599             }
600             finally {
601                 if (list == null) {
602                     list = new ArrayList<AssetVocabulary>();
603                 }
604 
605                 cacheResult(list);
606 
607                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
608                     finderArgs, list);
609 
610                 closeSession(session);
611             }
612         }
613 
614         return list;
615     }
616 
617     public AssetVocabulary findByUuid_First(String uuid, OrderByComparator obc)
618         throws NoSuchVocabularyException, SystemException {
619         List<AssetVocabulary> list = findByUuid(uuid, 0, 1, obc);
620 
621         if (list.isEmpty()) {
622             StringBundler msg = new StringBundler(4);
623 
624             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
625 
626             msg.append("uuid=");
627             msg.append(uuid);
628 
629             msg.append(StringPool.CLOSE_CURLY_BRACE);
630 
631             throw new NoSuchVocabularyException(msg.toString());
632         }
633         else {
634             return list.get(0);
635         }
636     }
637 
638     public AssetVocabulary findByUuid_Last(String uuid, OrderByComparator obc)
639         throws NoSuchVocabularyException, SystemException {
640         int count = countByUuid(uuid);
641 
642         List<AssetVocabulary> list = findByUuid(uuid, count - 1, count, obc);
643 
644         if (list.isEmpty()) {
645             StringBundler msg = new StringBundler(4);
646 
647             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
648 
649             msg.append("uuid=");
650             msg.append(uuid);
651 
652             msg.append(StringPool.CLOSE_CURLY_BRACE);
653 
654             throw new NoSuchVocabularyException(msg.toString());
655         }
656         else {
657             return list.get(0);
658         }
659     }
660 
661     public AssetVocabulary[] findByUuid_PrevAndNext(long vocabularyId,
662         String uuid, OrderByComparator obc)
663         throws NoSuchVocabularyException, SystemException {
664         AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
665 
666         int count = countByUuid(uuid);
667 
668         Session session = null;
669 
670         try {
671             session = openSession();
672 
673             StringBundler query = null;
674 
675             if (obc != null) {
676                 query = new StringBundler(3 +
677                         (obc.getOrderByFields().length * 3));
678             }
679             else {
680                 query = new StringBundler(3);
681             }
682 
683             query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
684 
685             if (uuid == null) {
686                 query.append(_FINDER_COLUMN_UUID_UUID_1);
687             }
688             else {
689                 if (uuid.equals(StringPool.BLANK)) {
690                     query.append(_FINDER_COLUMN_UUID_UUID_3);
691                 }
692                 else {
693                     query.append(_FINDER_COLUMN_UUID_UUID_2);
694                 }
695             }
696 
697             if (obc != null) {
698                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
699             }
700 
701             else {
702                 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
703             }
704 
705             String sql = query.toString();
706 
707             Query q = session.createQuery(sql);
708 
709             QueryPos qPos = QueryPos.getInstance(q);
710 
711             if (uuid != null) {
712                 qPos.add(uuid);
713             }
714 
715             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
716                     assetVocabulary);
717 
718             AssetVocabulary[] array = new AssetVocabularyImpl[3];
719 
720             array[0] = (AssetVocabulary)objArray[0];
721             array[1] = (AssetVocabulary)objArray[1];
722             array[2] = (AssetVocabulary)objArray[2];
723 
724             return array;
725         }
726         catch (Exception e) {
727             throw processException(e);
728         }
729         finally {
730             closeSession(session);
731         }
732     }
733 
734     public AssetVocabulary findByUUID_G(String uuid, long groupId)
735         throws NoSuchVocabularyException, SystemException {
736         AssetVocabulary assetVocabulary = fetchByUUID_G(uuid, groupId);
737 
738         if (assetVocabulary == null) {
739             StringBundler msg = new StringBundler(6);
740 
741             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
742 
743             msg.append("uuid=");
744             msg.append(uuid);
745 
746             msg.append(", groupId=");
747             msg.append(groupId);
748 
749             msg.append(StringPool.CLOSE_CURLY_BRACE);
750 
751             if (_log.isWarnEnabled()) {
752                 _log.warn(msg.toString());
753             }
754 
755             throw new NoSuchVocabularyException(msg.toString());
756         }
757 
758         return assetVocabulary;
759     }
760 
761     public AssetVocabulary fetchByUUID_G(String uuid, long groupId)
762         throws SystemException {
763         return fetchByUUID_G(uuid, groupId, true);
764     }
765 
766     public AssetVocabulary fetchByUUID_G(String uuid, long groupId,
767         boolean retrieveFromCache) throws SystemException {
768         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
769 
770         Object result = null;
771 
772         if (retrieveFromCache) {
773             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
774                     finderArgs, this);
775         }
776 
777         if (result == null) {
778             Session session = null;
779 
780             try {
781                 session = openSession();
782 
783                 StringBundler query = new StringBundler(4);
784 
785                 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
786 
787                 if (uuid == null) {
788                     query.append(_FINDER_COLUMN_UUID_G_UUID_1);
789                 }
790                 else {
791                     if (uuid.equals(StringPool.BLANK)) {
792                         query.append(_FINDER_COLUMN_UUID_G_UUID_3);
793                     }
794                     else {
795                         query.append(_FINDER_COLUMN_UUID_G_UUID_2);
796                     }
797                 }
798 
799                 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
800 
801                 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
802 
803                 String sql = query.toString();
804 
805                 Query q = session.createQuery(sql);
806 
807                 QueryPos qPos = QueryPos.getInstance(q);
808 
809                 if (uuid != null) {
810                     qPos.add(uuid);
811                 }
812 
813                 qPos.add(groupId);
814 
815                 List<AssetVocabulary> list = q.list();
816 
817                 result = list;
818 
819                 AssetVocabulary assetVocabulary = null;
820 
821                 if (list.isEmpty()) {
822                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
823                         finderArgs, list);
824                 }
825                 else {
826                     assetVocabulary = list.get(0);
827 
828                     cacheResult(assetVocabulary);
829 
830                     if ((assetVocabulary.getUuid() == null) ||
831                             !assetVocabulary.getUuid().equals(uuid) ||
832                             (assetVocabulary.getGroupId() != groupId)) {
833                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
834                             finderArgs, assetVocabulary);
835                     }
836                 }
837 
838                 return assetVocabulary;
839             }
840             catch (Exception e) {
841                 throw processException(e);
842             }
843             finally {
844                 if (result == null) {
845                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
846                         finderArgs, new ArrayList<AssetVocabulary>());
847                 }
848 
849                 closeSession(session);
850             }
851         }
852         else {
853             if (result instanceof List<?>) {
854                 return null;
855             }
856             else {
857                 return (AssetVocabulary)result;
858             }
859         }
860     }
861 
862     public List<AssetVocabulary> findByGroupId(long groupId)
863         throws SystemException {
864         Object[] finderArgs = new Object[] { new Long(groupId) };
865 
866         List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
867                 finderArgs, this);
868 
869         if (list == null) {
870             Session session = null;
871 
872             try {
873                 session = openSession();
874 
875                 StringBundler query = new StringBundler(3);
876 
877                 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
878 
879                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
880 
881                 query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
882 
883                 String sql = query.toString();
884 
885                 Query q = session.createQuery(sql);
886 
887                 QueryPos qPos = QueryPos.getInstance(q);
888 
889                 qPos.add(groupId);
890 
891                 list = q.list();
892             }
893             catch (Exception e) {
894                 throw processException(e);
895             }
896             finally {
897                 if (list == null) {
898                     list = new ArrayList<AssetVocabulary>();
899                 }
900 
901                 cacheResult(list);
902 
903                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
904                     finderArgs, list);
905 
906                 closeSession(session);
907             }
908         }
909 
910         return list;
911     }
912 
913     public List<AssetVocabulary> findByGroupId(long groupId, int start, int end)
914         throws SystemException {
915         return findByGroupId(groupId, start, end, null);
916     }
917 
918     public List<AssetVocabulary> findByGroupId(long groupId, int start,
919         int end, OrderByComparator obc) throws SystemException {
920         Object[] finderArgs = new Object[] {
921                 new Long(groupId),
922                 
923                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
924             };
925 
926         List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
927                 finderArgs, this);
928 
929         if (list == null) {
930             Session session = null;
931 
932             try {
933                 session = openSession();
934 
935                 StringBundler query = null;
936 
937                 if (obc != null) {
938                     query = new StringBundler(3 +
939                             (obc.getOrderByFields().length * 3));
940                 }
941                 else {
942                     query = new StringBundler(3);
943                 }
944 
945                 query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
946 
947                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
948 
949                 if (obc != null) {
950                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
951                 }
952 
953                 else {
954                     query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
955                 }
956 
957                 String sql = query.toString();
958 
959                 Query q = session.createQuery(sql);
960 
961                 QueryPos qPos = QueryPos.getInstance(q);
962 
963                 qPos.add(groupId);
964 
965                 list = (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
966                         start, end);
967             }
968             catch (Exception e) {
969                 throw processException(e);
970             }
971             finally {
972                 if (list == null) {
973                     list = new ArrayList<AssetVocabulary>();
974                 }
975 
976                 cacheResult(list);
977 
978                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
979                     finderArgs, list);
980 
981                 closeSession(session);
982             }
983         }
984 
985         return list;
986     }
987 
988     public AssetVocabulary findByGroupId_First(long groupId,
989         OrderByComparator obc)
990         throws NoSuchVocabularyException, SystemException {
991         List<AssetVocabulary> list = findByGroupId(groupId, 0, 1, obc);
992 
993         if (list.isEmpty()) {
994             StringBundler msg = new StringBundler(4);
995 
996             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
997 
998             msg.append("groupId=");
999             msg.append(groupId);
1000
1001            msg.append(StringPool.CLOSE_CURLY_BRACE);
1002
1003            throw new NoSuchVocabularyException(msg.toString());
1004        }
1005        else {
1006            return list.get(0);
1007        }
1008    }
1009
1010    public AssetVocabulary findByGroupId_Last(long groupId,
1011        OrderByComparator obc)
1012        throws NoSuchVocabularyException, SystemException {
1013        int count = countByGroupId(groupId);
1014
1015        List<AssetVocabulary> list = findByGroupId(groupId, count - 1, count,
1016                obc);
1017
1018        if (list.isEmpty()) {
1019            StringBundler msg = new StringBundler(4);
1020
1021            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1022
1023            msg.append("groupId=");
1024            msg.append(groupId);
1025
1026            msg.append(StringPool.CLOSE_CURLY_BRACE);
1027
1028            throw new NoSuchVocabularyException(msg.toString());
1029        }
1030        else {
1031            return list.get(0);
1032        }
1033    }
1034
1035    public AssetVocabulary[] findByGroupId_PrevAndNext(long vocabularyId,
1036        long groupId, OrderByComparator obc)
1037        throws NoSuchVocabularyException, SystemException {
1038        AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
1039
1040        int count = countByGroupId(groupId);
1041
1042        Session session = null;
1043
1044        try {
1045            session = openSession();
1046
1047            StringBundler query = null;
1048
1049            if (obc != null) {
1050                query = new StringBundler(3 +
1051                        (obc.getOrderByFields().length * 3));
1052            }
1053            else {
1054                query = new StringBundler(3);
1055            }
1056
1057            query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1058
1059            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1060
1061            if (obc != null) {
1062                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1063            }
1064
1065            else {
1066                query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1067            }
1068
1069            String sql = query.toString();
1070
1071            Query q = session.createQuery(sql);
1072
1073            QueryPos qPos = QueryPos.getInstance(q);
1074
1075            qPos.add(groupId);
1076
1077            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1078                    assetVocabulary);
1079
1080            AssetVocabulary[] array = new AssetVocabularyImpl[3];
1081
1082            array[0] = (AssetVocabulary)objArray[0];
1083            array[1] = (AssetVocabulary)objArray[1];
1084            array[2] = (AssetVocabulary)objArray[2];
1085
1086            return array;
1087        }
1088        catch (Exception e) {
1089            throw processException(e);
1090        }
1091        finally {
1092            closeSession(session);
1093        }
1094    }
1095
1096    public List<AssetVocabulary> findByCompanyId(long companyId)
1097        throws SystemException {
1098        Object[] finderArgs = new Object[] { new Long(companyId) };
1099
1100        List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1101                finderArgs, this);
1102
1103        if (list == null) {
1104            Session session = null;
1105
1106            try {
1107                session = openSession();
1108
1109                StringBundler query = new StringBundler(3);
1110
1111                query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1112
1113                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1114
1115                query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1116
1117                String sql = query.toString();
1118
1119                Query q = session.createQuery(sql);
1120
1121                QueryPos qPos = QueryPos.getInstance(q);
1122
1123                qPos.add(companyId);
1124
1125                list = q.list();
1126            }
1127            catch (Exception e) {
1128                throw processException(e);
1129            }
1130            finally {
1131                if (list == null) {
1132                    list = new ArrayList<AssetVocabulary>();
1133                }
1134
1135                cacheResult(list);
1136
1137                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1138                    finderArgs, list);
1139
1140                closeSession(session);
1141            }
1142        }
1143
1144        return list;
1145    }
1146
1147    public List<AssetVocabulary> findByCompanyId(long companyId, int start,
1148        int end) throws SystemException {
1149        return findByCompanyId(companyId, start, end, null);
1150    }
1151
1152    public List<AssetVocabulary> findByCompanyId(long companyId, int start,
1153        int end, OrderByComparator obc) throws SystemException {
1154        Object[] finderArgs = new Object[] {
1155                new Long(companyId),
1156                
1157                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1158            };
1159
1160        List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1161                finderArgs, this);
1162
1163        if (list == null) {
1164            Session session = null;
1165
1166            try {
1167                session = openSession();
1168
1169                StringBundler query = null;
1170
1171                if (obc != null) {
1172                    query = new StringBundler(3 +
1173                            (obc.getOrderByFields().length * 3));
1174                }
1175                else {
1176                    query = new StringBundler(3);
1177                }
1178
1179                query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1180
1181                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1182
1183                if (obc != null) {
1184                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1185                }
1186
1187                else {
1188                    query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1189                }
1190
1191                String sql = query.toString();
1192
1193                Query q = session.createQuery(sql);
1194
1195                QueryPos qPos = QueryPos.getInstance(q);
1196
1197                qPos.add(companyId);
1198
1199                list = (List<AssetVocabulary>)QueryUtil.list(q, getDialect(),
1200                        start, end);
1201            }
1202            catch (Exception e) {
1203                throw processException(e);
1204            }
1205            finally {
1206                if (list == null) {
1207                    list = new ArrayList<AssetVocabulary>();
1208                }
1209
1210                cacheResult(list);
1211
1212                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1213                    finderArgs, list);
1214
1215                closeSession(session);
1216            }
1217        }
1218
1219        return list;
1220    }
1221
1222    public AssetVocabulary findByCompanyId_First(long companyId,
1223        OrderByComparator obc)
1224        throws NoSuchVocabularyException, SystemException {
1225        List<AssetVocabulary> list = findByCompanyId(companyId, 0, 1, obc);
1226
1227        if (list.isEmpty()) {
1228            StringBundler msg = new StringBundler(4);
1229
1230            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1231
1232            msg.append("companyId=");
1233            msg.append(companyId);
1234
1235            msg.append(StringPool.CLOSE_CURLY_BRACE);
1236
1237            throw new NoSuchVocabularyException(msg.toString());
1238        }
1239        else {
1240            return list.get(0);
1241        }
1242    }
1243
1244    public AssetVocabulary findByCompanyId_Last(long companyId,
1245        OrderByComparator obc)
1246        throws NoSuchVocabularyException, SystemException {
1247        int count = countByCompanyId(companyId);
1248
1249        List<AssetVocabulary> list = findByCompanyId(companyId, count - 1,
1250                count, obc);
1251
1252        if (list.isEmpty()) {
1253            StringBundler msg = new StringBundler(4);
1254
1255            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1256
1257            msg.append("companyId=");
1258            msg.append(companyId);
1259
1260            msg.append(StringPool.CLOSE_CURLY_BRACE);
1261
1262            throw new NoSuchVocabularyException(msg.toString());
1263        }
1264        else {
1265            return list.get(0);
1266        }
1267    }
1268
1269    public AssetVocabulary[] findByCompanyId_PrevAndNext(long vocabularyId,
1270        long companyId, OrderByComparator obc)
1271        throws NoSuchVocabularyException, SystemException {
1272        AssetVocabulary assetVocabulary = findByPrimaryKey(vocabularyId);
1273
1274        int count = countByCompanyId(companyId);
1275
1276        Session session = null;
1277
1278        try {
1279            session = openSession();
1280
1281            StringBundler query = null;
1282
1283            if (obc != null) {
1284                query = new StringBundler(3 +
1285                        (obc.getOrderByFields().length * 3));
1286            }
1287            else {
1288                query = new StringBundler(3);
1289            }
1290
1291            query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1292
1293            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1294
1295            if (obc != null) {
1296                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1297            }
1298
1299            else {
1300                query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1301            }
1302
1303            String sql = query.toString();
1304
1305            Query q = session.createQuery(sql);
1306
1307            QueryPos qPos = QueryPos.getInstance(q);
1308
1309            qPos.add(companyId);
1310
1311            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1312                    assetVocabulary);
1313
1314            AssetVocabulary[] array = new AssetVocabularyImpl[3];
1315
1316            array[0] = (AssetVocabulary)objArray[0];
1317            array[1] = (AssetVocabulary)objArray[1];
1318            array[2] = (AssetVocabulary)objArray[2];
1319
1320            return array;
1321        }
1322        catch (Exception e) {
1323            throw processException(e);
1324        }
1325        finally {
1326            closeSession(session);
1327        }
1328    }
1329
1330    public AssetVocabulary findByG_N(long groupId, String name)
1331        throws NoSuchVocabularyException, SystemException {
1332        AssetVocabulary assetVocabulary = fetchByG_N(groupId, name);
1333
1334        if (assetVocabulary == null) {
1335            StringBundler msg = new StringBundler(6);
1336
1337            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1338
1339            msg.append("groupId=");
1340            msg.append(groupId);
1341
1342            msg.append(", name=");
1343            msg.append(name);
1344
1345            msg.append(StringPool.CLOSE_CURLY_BRACE);
1346
1347            if (_log.isWarnEnabled()) {
1348                _log.warn(msg.toString());
1349            }
1350
1351            throw new NoSuchVocabularyException(msg.toString());
1352        }
1353
1354        return assetVocabulary;
1355    }
1356
1357    public AssetVocabulary fetchByG_N(long groupId, String name)
1358        throws SystemException {
1359        return fetchByG_N(groupId, name, true);
1360    }
1361
1362    public AssetVocabulary fetchByG_N(long groupId, String name,
1363        boolean retrieveFromCache) throws SystemException {
1364        Object[] finderArgs = new Object[] { new Long(groupId), name };
1365
1366        Object result = null;
1367
1368        if (retrieveFromCache) {
1369            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1370                    finderArgs, this);
1371        }
1372
1373        if (result == null) {
1374            Session session = null;
1375
1376            try {
1377                session = openSession();
1378
1379                StringBundler query = new StringBundler(4);
1380
1381                query.append(_SQL_SELECT_ASSETVOCABULARY_WHERE);
1382
1383                query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1384
1385                if (name == null) {
1386                    query.append(_FINDER_COLUMN_G_N_NAME_1);
1387                }
1388                else {
1389                    if (name.equals(StringPool.BLANK)) {
1390                        query.append(_FINDER_COLUMN_G_N_NAME_3);
1391                    }
1392                    else {
1393                        query.append(_FINDER_COLUMN_G_N_NAME_2);
1394                    }
1395                }
1396
1397                query.append(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1398
1399                String sql = query.toString();
1400
1401                Query q = session.createQuery(sql);
1402
1403                QueryPos qPos = QueryPos.getInstance(q);
1404
1405                qPos.add(groupId);
1406
1407                if (name != null) {
1408                    qPos.add(name);
1409                }
1410
1411                List<AssetVocabulary> list = q.list();
1412
1413                result = list;
1414
1415                AssetVocabulary assetVocabulary = null;
1416
1417                if (list.isEmpty()) {
1418                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1419                        finderArgs, list);
1420                }
1421                else {
1422                    assetVocabulary = list.get(0);
1423
1424                    cacheResult(assetVocabulary);
1425
1426                    if ((assetVocabulary.getGroupId() != groupId) ||
1427                            (assetVocabulary.getName() == null) ||
1428                            !assetVocabulary.getName().equals(name)) {
1429                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1430                            finderArgs, assetVocabulary);
1431                    }
1432                }
1433
1434                return assetVocabulary;
1435            }
1436            catch (Exception e) {
1437                throw processException(e);
1438            }
1439            finally {
1440                if (result == null) {
1441                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1442                        finderArgs, new ArrayList<AssetVocabulary>());
1443                }
1444
1445                closeSession(session);
1446            }
1447        }
1448        else {
1449            if (result instanceof List<?>) {
1450                return null;
1451            }
1452            else {
1453                return (AssetVocabulary)result;
1454            }
1455        }
1456    }
1457
1458    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1459        throws SystemException {
1460        Session session = null;
1461
1462        try {
1463            session = openSession();
1464
1465            dynamicQuery.compile(session);
1466
1467            return dynamicQuery.list();
1468        }
1469        catch (Exception e) {
1470            throw processException(e);
1471        }
1472        finally {
1473            closeSession(session);
1474        }
1475    }
1476
1477    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1478        int start, int end) throws SystemException {
1479        Session session = null;
1480
1481        try {
1482            session = openSession();
1483
1484            dynamicQuery.setLimit(start, end);
1485
1486            dynamicQuery.compile(session);
1487
1488            return dynamicQuery.list();
1489        }
1490        catch (Exception e) {
1491            throw processException(e);
1492        }
1493        finally {
1494            closeSession(session);
1495        }
1496    }
1497
1498    public List<AssetVocabulary> findAll() throws SystemException {
1499        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1500    }
1501
1502    public List<AssetVocabulary> findAll(int start, int end)
1503        throws SystemException {
1504        return findAll(start, end, null);
1505    }
1506
1507    public List<AssetVocabulary> findAll(int start, int end,
1508        OrderByComparator obc) throws SystemException {
1509        Object[] finderArgs = new Object[] {
1510                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1511            };
1512
1513        List<AssetVocabulary> list = (List<AssetVocabulary>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1514                finderArgs, this);
1515
1516        if (list == null) {
1517            Session session = null;
1518
1519            try {
1520                session = openSession();
1521
1522                StringBundler query = null;
1523                String sql = null;
1524
1525                if (obc != null) {
1526                    query = new StringBundler(2 +
1527                            (obc.getOrderByFields().length * 3));
1528
1529                    query.append(_SQL_SELECT_ASSETVOCABULARY);
1530
1531                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1532
1533                    sql = query.toString();
1534                }
1535
1536                else {
1537                    sql = _SQL_SELECT_ASSETVOCABULARY.concat(AssetVocabularyModelImpl.ORDER_BY_JPQL);
1538                }
1539
1540                Query q = session.createQuery(sql);
1541
1542                if (obc == null) {
1543                    list = (List<AssetVocabulary>)QueryUtil.list(q,
1544                            getDialect(), start, end, false);
1545
1546                    Collections.sort(list);
1547                }
1548                else {
1549                    list = (List<AssetVocabulary>)QueryUtil.list(q,
1550                            getDialect(), start, end);
1551                }
1552            }
1553            catch (Exception e) {
1554                throw processException(e);
1555            }
1556            finally {
1557                if (list == null) {
1558                    list = new ArrayList<AssetVocabulary>();
1559                }
1560
1561                cacheResult(list);
1562
1563                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1564
1565                closeSession(session);
1566            }
1567        }
1568
1569        return list;
1570    }
1571
1572    public void removeByUuid(String uuid) throws SystemException {
1573        for (AssetVocabulary assetVocabulary : findByUuid(uuid)) {
1574            remove(assetVocabulary);
1575        }
1576    }
1577
1578    public void removeByUUID_G(String uuid, long groupId)
1579        throws NoSuchVocabularyException, SystemException {
1580        AssetVocabulary assetVocabulary = findByUUID_G(uuid, groupId);
1581
1582        remove(assetVocabulary);
1583    }
1584
1585    public void removeByGroupId(long groupId) throws SystemException {
1586        for (AssetVocabulary assetVocabulary : findByGroupId(groupId)) {
1587            remove(assetVocabulary);
1588        }
1589    }
1590
1591    public void removeByCompanyId(long companyId) throws SystemException {
1592        for (AssetVocabulary assetVocabulary : findByCompanyId(companyId)) {
1593            remove(assetVocabulary);
1594        }
1595    }
1596
1597    public void removeByG_N(long groupId, String name)
1598        throws NoSuchVocabularyException, SystemException {
1599        AssetVocabulary assetVocabulary = findByG_N(groupId, name);
1600
1601        remove(assetVocabulary);
1602    }
1603
1604    public void removeAll() throws SystemException {
1605        for (AssetVocabulary assetVocabulary : findAll()) {
1606            remove(assetVocabulary);
1607        }
1608    }
1609
1610    public int countByUuid(String uuid) throws SystemException {
1611        Object[] finderArgs = new Object[] { uuid };
1612
1613        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1614                finderArgs, this);
1615
1616        if (count == null) {
1617            Session session = null;
1618
1619            try {
1620                session = openSession();
1621
1622                StringBundler query = new StringBundler(2);
1623
1624                query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1625
1626                if (uuid == null) {
1627                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1628                }
1629                else {
1630                    if (uuid.equals(StringPool.BLANK)) {
1631                        query.append(_FINDER_COLUMN_UUID_UUID_3);
1632                    }
1633                    else {
1634                        query.append(_FINDER_COLUMN_UUID_UUID_2);
1635                    }
1636                }
1637
1638                String sql = query.toString();
1639
1640                Query q = session.createQuery(sql);
1641
1642                QueryPos qPos = QueryPos.getInstance(q);
1643
1644                if (uuid != null) {
1645                    qPos.add(uuid);
1646                }
1647
1648                count = (Long)q.uniqueResult();
1649            }
1650            catch (Exception e) {
1651                throw processException(e);
1652            }
1653            finally {
1654                if (count == null) {
1655                    count = Long.valueOf(0);
1656                }
1657
1658                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1659                    finderArgs, count);
1660
1661                closeSession(session);
1662            }
1663        }
1664
1665        return count.intValue();
1666    }
1667
1668    public int countByUUID_G(String uuid, long groupId)
1669        throws SystemException {
1670        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1671
1672        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1673                finderArgs, this);
1674
1675        if (count == null) {
1676            Session session = null;
1677
1678            try {
1679                session = openSession();
1680
1681                StringBundler query = new StringBundler(3);
1682
1683                query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1684
1685                if (uuid == null) {
1686                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1687                }
1688                else {
1689                    if (uuid.equals(StringPool.BLANK)) {
1690                        query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1691                    }
1692                    else {
1693                        query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1694                    }
1695                }
1696
1697                query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1698
1699                String sql = query.toString();
1700
1701                Query q = session.createQuery(sql);
1702
1703                QueryPos qPos = QueryPos.getInstance(q);
1704
1705                if (uuid != null) {
1706                    qPos.add(uuid);
1707                }
1708
1709                qPos.add(groupId);
1710
1711                count = (Long)q.uniqueResult();
1712            }
1713            catch (Exception e) {
1714                throw processException(e);
1715            }
1716            finally {
1717                if (count == null) {
1718                    count = Long.valueOf(0);
1719                }
1720
1721                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1722                    finderArgs, count);
1723
1724                closeSession(session);
1725            }
1726        }
1727
1728        return count.intValue();
1729    }
1730
1731    public int countByGroupId(long groupId) throws SystemException {
1732        Object[] finderArgs = new Object[] { new Long(groupId) };
1733
1734        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1735                finderArgs, this);
1736
1737        if (count == null) {
1738            Session session = null;
1739
1740            try {
1741                session = openSession();
1742
1743                StringBundler query = new StringBundler(2);
1744
1745                query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1746
1747                query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1748
1749                String sql = query.toString();
1750
1751                Query q = session.createQuery(sql);
1752
1753                QueryPos qPos = QueryPos.getInstance(q);
1754
1755                qPos.add(groupId);
1756
1757                count = (Long)q.uniqueResult();
1758            }
1759            catch (Exception e) {
1760                throw processException(e);
1761            }
1762            finally {
1763                if (count == null) {
1764                    count = Long.valueOf(0);
1765                }
1766
1767                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1768                    finderArgs, count);
1769
1770                closeSession(session);
1771            }
1772        }
1773
1774        return count.intValue();
1775    }
1776
1777    public int countByCompanyId(long companyId) throws SystemException {
1778        Object[] finderArgs = new Object[] { new Long(companyId) };
1779
1780        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1781                finderArgs, this);
1782
1783        if (count == null) {
1784            Session session = null;
1785
1786            try {
1787                session = openSession();
1788
1789                StringBundler query = new StringBundler(2);
1790
1791                query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1792
1793                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1794
1795                String sql = query.toString();
1796
1797                Query q = session.createQuery(sql);
1798
1799                QueryPos qPos = QueryPos.getInstance(q);
1800
1801                qPos.add(companyId);
1802
1803                count = (Long)q.uniqueResult();
1804            }
1805            catch (Exception e) {
1806                throw processException(e);
1807            }
1808            finally {
1809                if (count == null) {
1810                    count = Long.valueOf(0);
1811                }
1812
1813                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1814                    finderArgs, count);
1815
1816                closeSession(session);
1817            }
1818        }
1819
1820        return count.intValue();
1821    }
1822
1823    public int countByG_N(long groupId, String name) throws SystemException {
1824        Object[] finderArgs = new Object[] { new Long(groupId), name };
1825
1826        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
1827                finderArgs, this);
1828
1829        if (count == null) {
1830            Session session = null;
1831
1832            try {
1833                session = openSession();
1834
1835                StringBundler query = new StringBundler(3);
1836
1837                query.append(_SQL_COUNT_ASSETVOCABULARY_WHERE);
1838
1839                query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1840
1841                if (name == null) {
1842                    query.append(_FINDER_COLUMN_G_N_NAME_1);
1843                }
1844                else {
1845                    if (name.equals(StringPool.BLANK)) {
1846                        query.append(_FINDER_COLUMN_G_N_NAME_3);
1847                    }
1848                    else {
1849                        query.append(_FINDER_COLUMN_G_N_NAME_2);
1850                    }
1851                }
1852
1853                String sql = query.toString();
1854
1855                Query q = session.createQuery(sql);
1856
1857                QueryPos qPos = QueryPos.getInstance(q);
1858
1859                qPos.add(groupId);
1860
1861                if (name != null) {
1862                    qPos.add(name);
1863                }
1864
1865                count = (Long)q.uniqueResult();
1866            }
1867            catch (Exception e) {
1868                throw processException(e);
1869            }
1870            finally {
1871                if (count == null) {
1872                    count = Long.valueOf(0);
1873                }
1874
1875                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
1876                    count);
1877
1878                closeSession(session);
1879            }
1880        }
1881
1882        return count.intValue();
1883    }
1884
1885    public int countAll() throws SystemException {
1886        Object[] finderArgs = new Object[0];
1887
1888        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1889                finderArgs, this);
1890
1891        if (count == null) {
1892            Session session = null;
1893
1894            try {
1895                session = openSession();
1896
1897                Query q = session.createQuery(_SQL_COUNT_ASSETVOCABULARY);
1898
1899                count = (Long)q.uniqueResult();
1900            }
1901            catch (Exception e) {
1902                throw processException(e);
1903            }
1904            finally {
1905                if (count == null) {
1906                    count = Long.valueOf(0);
1907                }
1908
1909                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1910                    count);
1911
1912                closeSession(session);
1913            }
1914        }
1915
1916        return count.intValue();
1917    }
1918
1919    public void afterPropertiesSet() {
1920        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1921                    com.liferay.portal.util.PropsUtil.get(
1922                        "value.object.listener.com.liferay.portlet.asset.model.AssetVocabulary")));
1923
1924        if (listenerClassNames.length > 0) {
1925            try {
1926                List<ModelListener<AssetVocabulary>> listenersList = new ArrayList<ModelListener<AssetVocabulary>>();
1927
1928                for (String listenerClassName : listenerClassNames) {
1929                    listenersList.add((ModelListener<AssetVocabulary>)Class.forName(
1930                            listenerClassName).newInstance());
1931                }
1932
1933                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1934            }
1935            catch (Exception e) {
1936                _log.error(e);
1937            }
1938        }
1939    }
1940
1941    @BeanReference(name = "com.liferay.portlet.asset.service.persistence.AssetCategoryPersistence")
1942    protected com.liferay.portlet.asset.service.persistence.AssetCategoryPersistence assetCategoryPersistence;
1943    @BeanReference(name = "com.liferay.portlet.asset.service.persistence.AssetCategoryPropertyPersistence")
1944    protected com.liferay.portlet.asset.service.persistence.AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
1945    @BeanReference(name = "com.liferay.portlet.asset.service.persistence.AssetEntryPersistence")
1946    protected com.liferay.portlet.asset.service.persistence.AssetEntryPersistence assetEntryPersistence;
1947    @BeanReference(name = "com.liferay.portlet.asset.service.persistence.AssetTagPersistence")
1948    protected com.liferay.portlet.asset.service.persistence.AssetTagPersistence assetTagPersistence;
1949    @BeanReference(name = "com.liferay.portlet.asset.service.persistence.AssetTagPropertyPersistence")
1950    protected com.liferay.portlet.asset.service.persistence.AssetTagPropertyPersistence assetTagPropertyPersistence;
1951    @BeanReference(name = "com.liferay.portlet.asset.service.persistence.AssetTagStatsPersistence")
1952    protected com.liferay.portlet.asset.service.persistence.AssetTagStatsPersistence assetTagStatsPersistence;
1953    @BeanReference(name = "com.liferay.portlet.asset.service.persistence.AssetVocabularyPersistence")
1954    protected com.liferay.portlet.asset.service.persistence.AssetVocabularyPersistence assetVocabularyPersistence;
1955    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
1956    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1957    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1958    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1959    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1960    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1961    private static final String _SQL_SELECT_ASSETVOCABULARY = "SELECT assetVocabulary FROM AssetVocabulary assetVocabulary";
1962    private static final String _SQL_SELECT_ASSETVOCABULARY_WHERE = "SELECT assetVocabulary FROM AssetVocabulary assetVocabulary WHERE ";
1963    private static final String _SQL_COUNT_ASSETVOCABULARY = "SELECT COUNT(assetVocabulary) FROM AssetVocabulary assetVocabulary";
1964    private static final String _SQL_COUNT_ASSETVOCABULARY_WHERE = "SELECT COUNT(assetVocabulary) FROM AssetVocabulary assetVocabulary WHERE ";
1965    private static final String _FINDER_COLUMN_UUID_UUID_1 = "assetVocabulary.uuid IS NULL";
1966    private static final String _FINDER_COLUMN_UUID_UUID_2 = "assetVocabulary.uuid = ?";
1967    private static final String _FINDER_COLUMN_UUID_UUID_3 = "(assetVocabulary.uuid IS NULL OR assetVocabulary.uuid = ?)";
1968    private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "assetVocabulary.uuid IS NULL AND ";
1969    private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "assetVocabulary.uuid = ? AND ";
1970    private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(assetVocabulary.uuid IS NULL OR assetVocabulary.uuid = ?) AND ";
1971    private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "assetVocabulary.groupId = ?";
1972    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetVocabulary.groupId = ?";
1973    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetVocabulary.companyId = ?";
1974    private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "assetVocabulary.groupId = ? AND ";
1975    private static final String _FINDER_COLUMN_G_N_NAME_1 = "assetVocabulary.name IS NULL";
1976    private static final String _FINDER_COLUMN_G_N_NAME_2 = "assetVocabulary.name = ?";
1977    private static final String _FINDER_COLUMN_G_N_NAME_3 = "(assetVocabulary.name IS NULL OR assetVocabulary.name = ?)";
1978    private static final String _ORDER_BY_ENTITY_ALIAS = "assetVocabulary.";
1979    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetVocabulary exists with the primary key ";
1980    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetVocabulary exists with the key {";
1981    private static Log _log = LogFactoryUtil.getLog(AssetVocabularyPersistenceImpl.class);
1982}