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