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