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