001
014
015 package com.liferay.portlet.asset.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.SetUtil;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.service.ServiceContext;
038 import com.liferay.portal.service.ServiceContextThreadLocal;
039 import com.liferay.portal.service.persistence.CompanyProvider;
040 import com.liferay.portal.service.persistence.CompanyProviderWrapper;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.asset.exception.NoSuchCategoryPropertyException;
044 import com.liferay.portlet.asset.model.AssetCategoryProperty;
045 import com.liferay.portlet.asset.model.impl.AssetCategoryPropertyImpl;
046 import com.liferay.portlet.asset.model.impl.AssetCategoryPropertyModelImpl;
047 import com.liferay.portlet.asset.service.persistence.AssetCategoryPropertyPersistence;
048
049 import java.io.Serializable;
050
051 import java.util.Collections;
052 import java.util.Date;
053 import java.util.HashMap;
054 import java.util.HashSet;
055 import java.util.Iterator;
056 import java.util.List;
057 import java.util.Map;
058 import java.util.Set;
059
060
072 @ProviderType
073 public class AssetCategoryPropertyPersistenceImpl extends BasePersistenceImpl<AssetCategoryProperty>
074 implements AssetCategoryPropertyPersistence {
075
080 public static final String FINDER_CLASS_NAME_ENTITY = AssetCategoryPropertyImpl.class.getName();
081 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082 ".List1";
083 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List2";
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
086 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
087 AssetCategoryPropertyImpl.class,
088 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
089 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
090 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
091 AssetCategoryPropertyImpl.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
093 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
094 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
097 new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
098 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
099 AssetCategoryPropertyImpl.class,
100 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
101 new String[] {
102 Long.class.getName(),
103
104 Integer.class.getName(), Integer.class.getName(),
105 OrderByComparator.class.getName()
106 });
107 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
108 new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
109 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
110 AssetCategoryPropertyImpl.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
112 new String[] { Long.class.getName() },
113 AssetCategoryPropertyModelImpl.COMPANYID_COLUMN_BITMASK |
114 AssetCategoryPropertyModelImpl.KEY_COLUMN_BITMASK);
115 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
116 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED, Long.class,
117 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
118 new String[] { Long.class.getName() });
119
120
126 @Override
127 public List<AssetCategoryProperty> findByCompanyId(long companyId) {
128 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
129 null);
130 }
131
132
144 @Override
145 public List<AssetCategoryProperty> findByCompanyId(long companyId,
146 int start, int end) {
147 return findByCompanyId(companyId, start, end, null);
148 }
149
150
163 @Override
164 public List<AssetCategoryProperty> findByCompanyId(long companyId,
165 int start, int end,
166 OrderByComparator<AssetCategoryProperty> orderByComparator) {
167 return findByCompanyId(companyId, start, end, orderByComparator, true);
168 }
169
170
184 @Override
185 public List<AssetCategoryProperty> findByCompanyId(long companyId,
186 int start, int end,
187 OrderByComparator<AssetCategoryProperty> orderByComparator,
188 boolean retrieveFromCache) {
189 boolean pagination = true;
190 FinderPath finderPath = null;
191 Object[] finderArgs = null;
192
193 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
194 (orderByComparator == null)) {
195 pagination = false;
196 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
197 finderArgs = new Object[] { companyId };
198 }
199 else {
200 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
201 finderArgs = new Object[] { companyId, start, end, orderByComparator };
202 }
203
204 List<AssetCategoryProperty> list = null;
205
206 if (retrieveFromCache) {
207 list = (List<AssetCategoryProperty>)finderCache.getResult(finderPath,
208 finderArgs, this);
209
210 if ((list != null) && !list.isEmpty()) {
211 for (AssetCategoryProperty assetCategoryProperty : list) {
212 if ((companyId != assetCategoryProperty.getCompanyId())) {
213 list = null;
214
215 break;
216 }
217 }
218 }
219 }
220
221 if (list == null) {
222 StringBundler query = null;
223
224 if (orderByComparator != null) {
225 query = new StringBundler(3 +
226 (orderByComparator.getOrderByFields().length * 2));
227 }
228 else {
229 query = new StringBundler(3);
230 }
231
232 query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
233
234 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
235
236 if (orderByComparator != null) {
237 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
238 orderByComparator);
239 }
240 else
241 if (pagination) {
242 query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
243 }
244
245 String sql = query.toString();
246
247 Session session = null;
248
249 try {
250 session = openSession();
251
252 Query q = session.createQuery(sql);
253
254 QueryPos qPos = QueryPos.getInstance(q);
255
256 qPos.add(companyId);
257
258 if (!pagination) {
259 list = (List<AssetCategoryProperty>)QueryUtil.list(q,
260 getDialect(), start, end, false);
261
262 Collections.sort(list);
263
264 list = Collections.unmodifiableList(list);
265 }
266 else {
267 list = (List<AssetCategoryProperty>)QueryUtil.list(q,
268 getDialect(), start, end);
269 }
270
271 cacheResult(list);
272
273 finderCache.putResult(finderPath, finderArgs, list);
274 }
275 catch (Exception e) {
276 finderCache.removeResult(finderPath, finderArgs);
277
278 throw processException(e);
279 }
280 finally {
281 closeSession(session);
282 }
283 }
284
285 return list;
286 }
287
288
296 @Override
297 public AssetCategoryProperty findByCompanyId_First(long companyId,
298 OrderByComparator<AssetCategoryProperty> orderByComparator)
299 throws NoSuchCategoryPropertyException {
300 AssetCategoryProperty assetCategoryProperty = fetchByCompanyId_First(companyId,
301 orderByComparator);
302
303 if (assetCategoryProperty != null) {
304 return assetCategoryProperty;
305 }
306
307 StringBundler msg = new StringBundler(4);
308
309 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
310
311 msg.append("companyId=");
312 msg.append(companyId);
313
314 msg.append(StringPool.CLOSE_CURLY_BRACE);
315
316 throw new NoSuchCategoryPropertyException(msg.toString());
317 }
318
319
326 @Override
327 public AssetCategoryProperty fetchByCompanyId_First(long companyId,
328 OrderByComparator<AssetCategoryProperty> orderByComparator) {
329 List<AssetCategoryProperty> list = findByCompanyId(companyId, 0, 1,
330 orderByComparator);
331
332 if (!list.isEmpty()) {
333 return list.get(0);
334 }
335
336 return null;
337 }
338
339
347 @Override
348 public AssetCategoryProperty findByCompanyId_Last(long companyId,
349 OrderByComparator<AssetCategoryProperty> orderByComparator)
350 throws NoSuchCategoryPropertyException {
351 AssetCategoryProperty assetCategoryProperty = fetchByCompanyId_Last(companyId,
352 orderByComparator);
353
354 if (assetCategoryProperty != null) {
355 return assetCategoryProperty;
356 }
357
358 StringBundler msg = new StringBundler(4);
359
360 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
361
362 msg.append("companyId=");
363 msg.append(companyId);
364
365 msg.append(StringPool.CLOSE_CURLY_BRACE);
366
367 throw new NoSuchCategoryPropertyException(msg.toString());
368 }
369
370
377 @Override
378 public AssetCategoryProperty fetchByCompanyId_Last(long companyId,
379 OrderByComparator<AssetCategoryProperty> orderByComparator) {
380 int count = countByCompanyId(companyId);
381
382 if (count == 0) {
383 return null;
384 }
385
386 List<AssetCategoryProperty> list = findByCompanyId(companyId,
387 count - 1, count, orderByComparator);
388
389 if (!list.isEmpty()) {
390 return list.get(0);
391 }
392
393 return null;
394 }
395
396
405 @Override
406 public AssetCategoryProperty[] findByCompanyId_PrevAndNext(
407 long categoryPropertyId, long companyId,
408 OrderByComparator<AssetCategoryProperty> orderByComparator)
409 throws NoSuchCategoryPropertyException {
410 AssetCategoryProperty assetCategoryProperty = findByPrimaryKey(categoryPropertyId);
411
412 Session session = null;
413
414 try {
415 session = openSession();
416
417 AssetCategoryProperty[] array = new AssetCategoryPropertyImpl[3];
418
419 array[0] = getByCompanyId_PrevAndNext(session,
420 assetCategoryProperty, companyId, orderByComparator, true);
421
422 array[1] = assetCategoryProperty;
423
424 array[2] = getByCompanyId_PrevAndNext(session,
425 assetCategoryProperty, companyId, orderByComparator, false);
426
427 return array;
428 }
429 catch (Exception e) {
430 throw processException(e);
431 }
432 finally {
433 closeSession(session);
434 }
435 }
436
437 protected AssetCategoryProperty getByCompanyId_PrevAndNext(
438 Session session, AssetCategoryProperty assetCategoryProperty,
439 long companyId,
440 OrderByComparator<AssetCategoryProperty> orderByComparator,
441 boolean previous) {
442 StringBundler query = null;
443
444 if (orderByComparator != null) {
445 query = new StringBundler(4 +
446 (orderByComparator.getOrderByConditionFields().length * 3) +
447 (orderByComparator.getOrderByFields().length * 3));
448 }
449 else {
450 query = new StringBundler(3);
451 }
452
453 query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
454
455 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
456
457 if (orderByComparator != null) {
458 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
459
460 if (orderByConditionFields.length > 0) {
461 query.append(WHERE_AND);
462 }
463
464 for (int i = 0; i < orderByConditionFields.length; i++) {
465 query.append(_ORDER_BY_ENTITY_ALIAS);
466 query.append(orderByConditionFields[i]);
467
468 if ((i + 1) < orderByConditionFields.length) {
469 if (orderByComparator.isAscending() ^ previous) {
470 query.append(WHERE_GREATER_THAN_HAS_NEXT);
471 }
472 else {
473 query.append(WHERE_LESSER_THAN_HAS_NEXT);
474 }
475 }
476 else {
477 if (orderByComparator.isAscending() ^ previous) {
478 query.append(WHERE_GREATER_THAN);
479 }
480 else {
481 query.append(WHERE_LESSER_THAN);
482 }
483 }
484 }
485
486 query.append(ORDER_BY_CLAUSE);
487
488 String[] orderByFields = orderByComparator.getOrderByFields();
489
490 for (int i = 0; i < orderByFields.length; i++) {
491 query.append(_ORDER_BY_ENTITY_ALIAS);
492 query.append(orderByFields[i]);
493
494 if ((i + 1) < orderByFields.length) {
495 if (orderByComparator.isAscending() ^ previous) {
496 query.append(ORDER_BY_ASC_HAS_NEXT);
497 }
498 else {
499 query.append(ORDER_BY_DESC_HAS_NEXT);
500 }
501 }
502 else {
503 if (orderByComparator.isAscending() ^ previous) {
504 query.append(ORDER_BY_ASC);
505 }
506 else {
507 query.append(ORDER_BY_DESC);
508 }
509 }
510 }
511 }
512 else {
513 query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
514 }
515
516 String sql = query.toString();
517
518 Query q = session.createQuery(sql);
519
520 q.setFirstResult(0);
521 q.setMaxResults(2);
522
523 QueryPos qPos = QueryPos.getInstance(q);
524
525 qPos.add(companyId);
526
527 if (orderByComparator != null) {
528 Object[] values = orderByComparator.getOrderByConditionValues(assetCategoryProperty);
529
530 for (Object value : values) {
531 qPos.add(value);
532 }
533 }
534
535 List<AssetCategoryProperty> list = q.list();
536
537 if (list.size() == 2) {
538 return list.get(1);
539 }
540 else {
541 return null;
542 }
543 }
544
545
550 @Override
551 public void removeByCompanyId(long companyId) {
552 for (AssetCategoryProperty assetCategoryProperty : findByCompanyId(
553 companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
554 remove(assetCategoryProperty);
555 }
556 }
557
558
564 @Override
565 public int countByCompanyId(long companyId) {
566 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
567
568 Object[] finderArgs = new Object[] { companyId };
569
570 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
571
572 if (count == null) {
573 StringBundler query = new StringBundler(2);
574
575 query.append(_SQL_COUNT_ASSETCATEGORYPROPERTY_WHERE);
576
577 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
578
579 String sql = query.toString();
580
581 Session session = null;
582
583 try {
584 session = openSession();
585
586 Query q = session.createQuery(sql);
587
588 QueryPos qPos = QueryPos.getInstance(q);
589
590 qPos.add(companyId);
591
592 count = (Long)q.uniqueResult();
593
594 finderCache.putResult(finderPath, finderArgs, count);
595 }
596 catch (Exception e) {
597 finderCache.removeResult(finderPath, finderArgs);
598
599 throw processException(e);
600 }
601 finally {
602 closeSession(session);
603 }
604 }
605
606 return count.intValue();
607 }
608
609 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetCategoryProperty.companyId = ?";
610 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CATEGORYID =
611 new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
612 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
613 AssetCategoryPropertyImpl.class,
614 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCategoryId",
615 new String[] {
616 Long.class.getName(),
617
618 Integer.class.getName(), Integer.class.getName(),
619 OrderByComparator.class.getName()
620 });
621 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CATEGORYID =
622 new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
623 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
624 AssetCategoryPropertyImpl.class,
625 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCategoryId",
626 new String[] { Long.class.getName() },
627 AssetCategoryPropertyModelImpl.CATEGORYID_COLUMN_BITMASK |
628 AssetCategoryPropertyModelImpl.KEY_COLUMN_BITMASK);
629 public static final FinderPath FINDER_PATH_COUNT_BY_CATEGORYID = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
630 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED, Long.class,
631 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCategoryId",
632 new String[] { Long.class.getName() });
633
634
640 @Override
641 public List<AssetCategoryProperty> findByCategoryId(long categoryId) {
642 return findByCategoryId(categoryId, QueryUtil.ALL_POS,
643 QueryUtil.ALL_POS, null);
644 }
645
646
658 @Override
659 public List<AssetCategoryProperty> findByCategoryId(long categoryId,
660 int start, int end) {
661 return findByCategoryId(categoryId, start, end, null);
662 }
663
664
677 @Override
678 public List<AssetCategoryProperty> findByCategoryId(long categoryId,
679 int start, int end,
680 OrderByComparator<AssetCategoryProperty> orderByComparator) {
681 return findByCategoryId(categoryId, start, end, orderByComparator, true);
682 }
683
684
698 @Override
699 public List<AssetCategoryProperty> findByCategoryId(long categoryId,
700 int start, int end,
701 OrderByComparator<AssetCategoryProperty> orderByComparator,
702 boolean retrieveFromCache) {
703 boolean pagination = true;
704 FinderPath finderPath = null;
705 Object[] finderArgs = null;
706
707 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
708 (orderByComparator == null)) {
709 pagination = false;
710 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CATEGORYID;
711 finderArgs = new Object[] { categoryId };
712 }
713 else {
714 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CATEGORYID;
715 finderArgs = new Object[] { categoryId, start, end, orderByComparator };
716 }
717
718 List<AssetCategoryProperty> list = null;
719
720 if (retrieveFromCache) {
721 list = (List<AssetCategoryProperty>)finderCache.getResult(finderPath,
722 finderArgs, this);
723
724 if ((list != null) && !list.isEmpty()) {
725 for (AssetCategoryProperty assetCategoryProperty : list) {
726 if ((categoryId != assetCategoryProperty.getCategoryId())) {
727 list = null;
728
729 break;
730 }
731 }
732 }
733 }
734
735 if (list == null) {
736 StringBundler query = null;
737
738 if (orderByComparator != null) {
739 query = new StringBundler(3 +
740 (orderByComparator.getOrderByFields().length * 2));
741 }
742 else {
743 query = new StringBundler(3);
744 }
745
746 query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
747
748 query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
749
750 if (orderByComparator != null) {
751 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
752 orderByComparator);
753 }
754 else
755 if (pagination) {
756 query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
757 }
758
759 String sql = query.toString();
760
761 Session session = null;
762
763 try {
764 session = openSession();
765
766 Query q = session.createQuery(sql);
767
768 QueryPos qPos = QueryPos.getInstance(q);
769
770 qPos.add(categoryId);
771
772 if (!pagination) {
773 list = (List<AssetCategoryProperty>)QueryUtil.list(q,
774 getDialect(), start, end, false);
775
776 Collections.sort(list);
777
778 list = Collections.unmodifiableList(list);
779 }
780 else {
781 list = (List<AssetCategoryProperty>)QueryUtil.list(q,
782 getDialect(), start, end);
783 }
784
785 cacheResult(list);
786
787 finderCache.putResult(finderPath, finderArgs, list);
788 }
789 catch (Exception e) {
790 finderCache.removeResult(finderPath, finderArgs);
791
792 throw processException(e);
793 }
794 finally {
795 closeSession(session);
796 }
797 }
798
799 return list;
800 }
801
802
810 @Override
811 public AssetCategoryProperty findByCategoryId_First(long categoryId,
812 OrderByComparator<AssetCategoryProperty> orderByComparator)
813 throws NoSuchCategoryPropertyException {
814 AssetCategoryProperty assetCategoryProperty = fetchByCategoryId_First(categoryId,
815 orderByComparator);
816
817 if (assetCategoryProperty != null) {
818 return assetCategoryProperty;
819 }
820
821 StringBundler msg = new StringBundler(4);
822
823 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
824
825 msg.append("categoryId=");
826 msg.append(categoryId);
827
828 msg.append(StringPool.CLOSE_CURLY_BRACE);
829
830 throw new NoSuchCategoryPropertyException(msg.toString());
831 }
832
833
840 @Override
841 public AssetCategoryProperty fetchByCategoryId_First(long categoryId,
842 OrderByComparator<AssetCategoryProperty> orderByComparator) {
843 List<AssetCategoryProperty> list = findByCategoryId(categoryId, 0, 1,
844 orderByComparator);
845
846 if (!list.isEmpty()) {
847 return list.get(0);
848 }
849
850 return null;
851 }
852
853
861 @Override
862 public AssetCategoryProperty findByCategoryId_Last(long categoryId,
863 OrderByComparator<AssetCategoryProperty> orderByComparator)
864 throws NoSuchCategoryPropertyException {
865 AssetCategoryProperty assetCategoryProperty = fetchByCategoryId_Last(categoryId,
866 orderByComparator);
867
868 if (assetCategoryProperty != null) {
869 return assetCategoryProperty;
870 }
871
872 StringBundler msg = new StringBundler(4);
873
874 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
875
876 msg.append("categoryId=");
877 msg.append(categoryId);
878
879 msg.append(StringPool.CLOSE_CURLY_BRACE);
880
881 throw new NoSuchCategoryPropertyException(msg.toString());
882 }
883
884
891 @Override
892 public AssetCategoryProperty fetchByCategoryId_Last(long categoryId,
893 OrderByComparator<AssetCategoryProperty> orderByComparator) {
894 int count = countByCategoryId(categoryId);
895
896 if (count == 0) {
897 return null;
898 }
899
900 List<AssetCategoryProperty> list = findByCategoryId(categoryId,
901 count - 1, count, orderByComparator);
902
903 if (!list.isEmpty()) {
904 return list.get(0);
905 }
906
907 return null;
908 }
909
910
919 @Override
920 public AssetCategoryProperty[] findByCategoryId_PrevAndNext(
921 long categoryPropertyId, long categoryId,
922 OrderByComparator<AssetCategoryProperty> orderByComparator)
923 throws NoSuchCategoryPropertyException {
924 AssetCategoryProperty assetCategoryProperty = findByPrimaryKey(categoryPropertyId);
925
926 Session session = null;
927
928 try {
929 session = openSession();
930
931 AssetCategoryProperty[] array = new AssetCategoryPropertyImpl[3];
932
933 array[0] = getByCategoryId_PrevAndNext(session,
934 assetCategoryProperty, categoryId, orderByComparator, true);
935
936 array[1] = assetCategoryProperty;
937
938 array[2] = getByCategoryId_PrevAndNext(session,
939 assetCategoryProperty, categoryId, orderByComparator, false);
940
941 return array;
942 }
943 catch (Exception e) {
944 throw processException(e);
945 }
946 finally {
947 closeSession(session);
948 }
949 }
950
951 protected AssetCategoryProperty getByCategoryId_PrevAndNext(
952 Session session, AssetCategoryProperty assetCategoryProperty,
953 long categoryId,
954 OrderByComparator<AssetCategoryProperty> orderByComparator,
955 boolean previous) {
956 StringBundler query = null;
957
958 if (orderByComparator != null) {
959 query = new StringBundler(4 +
960 (orderByComparator.getOrderByConditionFields().length * 3) +
961 (orderByComparator.getOrderByFields().length * 3));
962 }
963 else {
964 query = new StringBundler(3);
965 }
966
967 query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
968
969 query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
970
971 if (orderByComparator != null) {
972 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
973
974 if (orderByConditionFields.length > 0) {
975 query.append(WHERE_AND);
976 }
977
978 for (int i = 0; i < orderByConditionFields.length; i++) {
979 query.append(_ORDER_BY_ENTITY_ALIAS);
980 query.append(orderByConditionFields[i]);
981
982 if ((i + 1) < orderByConditionFields.length) {
983 if (orderByComparator.isAscending() ^ previous) {
984 query.append(WHERE_GREATER_THAN_HAS_NEXT);
985 }
986 else {
987 query.append(WHERE_LESSER_THAN_HAS_NEXT);
988 }
989 }
990 else {
991 if (orderByComparator.isAscending() ^ previous) {
992 query.append(WHERE_GREATER_THAN);
993 }
994 else {
995 query.append(WHERE_LESSER_THAN);
996 }
997 }
998 }
999
1000 query.append(ORDER_BY_CLAUSE);
1001
1002 String[] orderByFields = orderByComparator.getOrderByFields();
1003
1004 for (int i = 0; i < orderByFields.length; i++) {
1005 query.append(_ORDER_BY_ENTITY_ALIAS);
1006 query.append(orderByFields[i]);
1007
1008 if ((i + 1) < orderByFields.length) {
1009 if (orderByComparator.isAscending() ^ previous) {
1010 query.append(ORDER_BY_ASC_HAS_NEXT);
1011 }
1012 else {
1013 query.append(ORDER_BY_DESC_HAS_NEXT);
1014 }
1015 }
1016 else {
1017 if (orderByComparator.isAscending() ^ previous) {
1018 query.append(ORDER_BY_ASC);
1019 }
1020 else {
1021 query.append(ORDER_BY_DESC);
1022 }
1023 }
1024 }
1025 }
1026 else {
1027 query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
1028 }
1029
1030 String sql = query.toString();
1031
1032 Query q = session.createQuery(sql);
1033
1034 q.setFirstResult(0);
1035 q.setMaxResults(2);
1036
1037 QueryPos qPos = QueryPos.getInstance(q);
1038
1039 qPos.add(categoryId);
1040
1041 if (orderByComparator != null) {
1042 Object[] values = orderByComparator.getOrderByConditionValues(assetCategoryProperty);
1043
1044 for (Object value : values) {
1045 qPos.add(value);
1046 }
1047 }
1048
1049 List<AssetCategoryProperty> list = q.list();
1050
1051 if (list.size() == 2) {
1052 return list.get(1);
1053 }
1054 else {
1055 return null;
1056 }
1057 }
1058
1059
1064 @Override
1065 public void removeByCategoryId(long categoryId) {
1066 for (AssetCategoryProperty assetCategoryProperty : findByCategoryId(
1067 categoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1068 remove(assetCategoryProperty);
1069 }
1070 }
1071
1072
1078 @Override
1079 public int countByCategoryId(long categoryId) {
1080 FinderPath finderPath = FINDER_PATH_COUNT_BY_CATEGORYID;
1081
1082 Object[] finderArgs = new Object[] { categoryId };
1083
1084 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1085
1086 if (count == null) {
1087 StringBundler query = new StringBundler(2);
1088
1089 query.append(_SQL_COUNT_ASSETCATEGORYPROPERTY_WHERE);
1090
1091 query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
1092
1093 String sql = query.toString();
1094
1095 Session session = null;
1096
1097 try {
1098 session = openSession();
1099
1100 Query q = session.createQuery(sql);
1101
1102 QueryPos qPos = QueryPos.getInstance(q);
1103
1104 qPos.add(categoryId);
1105
1106 count = (Long)q.uniqueResult();
1107
1108 finderCache.putResult(finderPath, finderArgs, count);
1109 }
1110 catch (Exception e) {
1111 finderCache.removeResult(finderPath, finderArgs);
1112
1113 throw processException(e);
1114 }
1115 finally {
1116 closeSession(session);
1117 }
1118 }
1119
1120 return count.intValue();
1121 }
1122
1123 private static final String _FINDER_COLUMN_CATEGORYID_CATEGORYID_2 = "assetCategoryProperty.categoryId = ?";
1124 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_K = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
1125 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
1126 AssetCategoryPropertyImpl.class,
1127 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_K",
1128 new String[] {
1129 Long.class.getName(), String.class.getName(),
1130
1131 Integer.class.getName(), Integer.class.getName(),
1132 OrderByComparator.class.getName()
1133 });
1134 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
1135 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
1136 AssetCategoryPropertyImpl.class,
1137 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_K",
1138 new String[] { Long.class.getName(), String.class.getName() },
1139 AssetCategoryPropertyModelImpl.COMPANYID_COLUMN_BITMASK |
1140 AssetCategoryPropertyModelImpl.KEY_COLUMN_BITMASK);
1141 public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
1142 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED, Long.class,
1143 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K",
1144 new String[] { Long.class.getName(), String.class.getName() });
1145
1146
1153 @Override
1154 public List<AssetCategoryProperty> findByC_K(long companyId, String key) {
1155 return findByC_K(companyId, key, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1156 null);
1157 }
1158
1159
1172 @Override
1173 public List<AssetCategoryProperty> findByC_K(long companyId, String key,
1174 int start, int end) {
1175 return findByC_K(companyId, key, start, end, null);
1176 }
1177
1178
1192 @Override
1193 public List<AssetCategoryProperty> findByC_K(long companyId, String key,
1194 int start, int end,
1195 OrderByComparator<AssetCategoryProperty> orderByComparator) {
1196 return findByC_K(companyId, key, start, end, orderByComparator, true);
1197 }
1198
1199
1214 @Override
1215 public List<AssetCategoryProperty> findByC_K(long companyId, String key,
1216 int start, int end,
1217 OrderByComparator<AssetCategoryProperty> orderByComparator,
1218 boolean retrieveFromCache) {
1219 boolean pagination = true;
1220 FinderPath finderPath = null;
1221 Object[] finderArgs = null;
1222
1223 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1224 (orderByComparator == null)) {
1225 pagination = false;
1226 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K;
1227 finderArgs = new Object[] { companyId, key };
1228 }
1229 else {
1230 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_K;
1231 finderArgs = new Object[] {
1232 companyId, key,
1233
1234 start, end, orderByComparator
1235 };
1236 }
1237
1238 List<AssetCategoryProperty> list = null;
1239
1240 if (retrieveFromCache) {
1241 list = (List<AssetCategoryProperty>)finderCache.getResult(finderPath,
1242 finderArgs, this);
1243
1244 if ((list != null) && !list.isEmpty()) {
1245 for (AssetCategoryProperty assetCategoryProperty : list) {
1246 if ((companyId != assetCategoryProperty.getCompanyId()) ||
1247 !Validator.equals(key,
1248 assetCategoryProperty.getKey())) {
1249 list = null;
1250
1251 break;
1252 }
1253 }
1254 }
1255 }
1256
1257 if (list == null) {
1258 StringBundler query = null;
1259
1260 if (orderByComparator != null) {
1261 query = new StringBundler(4 +
1262 (orderByComparator.getOrderByFields().length * 2));
1263 }
1264 else {
1265 query = new StringBundler(4);
1266 }
1267
1268 query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
1269
1270 query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1271
1272 boolean bindKey = false;
1273
1274 if (key == null) {
1275 query.append(_FINDER_COLUMN_C_K_KEY_1);
1276 }
1277 else if (key.equals(StringPool.BLANK)) {
1278 query.append(_FINDER_COLUMN_C_K_KEY_3);
1279 }
1280 else {
1281 bindKey = true;
1282
1283 query.append(_FINDER_COLUMN_C_K_KEY_2);
1284 }
1285
1286 if (orderByComparator != null) {
1287 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1288 orderByComparator);
1289 }
1290 else
1291 if (pagination) {
1292 query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
1293 }
1294
1295 String sql = query.toString();
1296
1297 Session session = null;
1298
1299 try {
1300 session = openSession();
1301
1302 Query q = session.createQuery(sql);
1303
1304 QueryPos qPos = QueryPos.getInstance(q);
1305
1306 qPos.add(companyId);
1307
1308 if (bindKey) {
1309 qPos.add(key);
1310 }
1311
1312 if (!pagination) {
1313 list = (List<AssetCategoryProperty>)QueryUtil.list(q,
1314 getDialect(), start, end, false);
1315
1316 Collections.sort(list);
1317
1318 list = Collections.unmodifiableList(list);
1319 }
1320 else {
1321 list = (List<AssetCategoryProperty>)QueryUtil.list(q,
1322 getDialect(), start, end);
1323 }
1324
1325 cacheResult(list);
1326
1327 finderCache.putResult(finderPath, finderArgs, list);
1328 }
1329 catch (Exception e) {
1330 finderCache.removeResult(finderPath, finderArgs);
1331
1332 throw processException(e);
1333 }
1334 finally {
1335 closeSession(session);
1336 }
1337 }
1338
1339 return list;
1340 }
1341
1342
1351 @Override
1352 public AssetCategoryProperty findByC_K_First(long companyId, String key,
1353 OrderByComparator<AssetCategoryProperty> orderByComparator)
1354 throws NoSuchCategoryPropertyException {
1355 AssetCategoryProperty assetCategoryProperty = fetchByC_K_First(companyId,
1356 key, orderByComparator);
1357
1358 if (assetCategoryProperty != null) {
1359 return assetCategoryProperty;
1360 }
1361
1362 StringBundler msg = new StringBundler(6);
1363
1364 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1365
1366 msg.append("companyId=");
1367 msg.append(companyId);
1368
1369 msg.append(", key=");
1370 msg.append(key);
1371
1372 msg.append(StringPool.CLOSE_CURLY_BRACE);
1373
1374 throw new NoSuchCategoryPropertyException(msg.toString());
1375 }
1376
1377
1385 @Override
1386 public AssetCategoryProperty fetchByC_K_First(long companyId, String key,
1387 OrderByComparator<AssetCategoryProperty> orderByComparator) {
1388 List<AssetCategoryProperty> list = findByC_K(companyId, key, 0, 1,
1389 orderByComparator);
1390
1391 if (!list.isEmpty()) {
1392 return list.get(0);
1393 }
1394
1395 return null;
1396 }
1397
1398
1407 @Override
1408 public AssetCategoryProperty findByC_K_Last(long companyId, String key,
1409 OrderByComparator<AssetCategoryProperty> orderByComparator)
1410 throws NoSuchCategoryPropertyException {
1411 AssetCategoryProperty assetCategoryProperty = fetchByC_K_Last(companyId,
1412 key, orderByComparator);
1413
1414 if (assetCategoryProperty != null) {
1415 return assetCategoryProperty;
1416 }
1417
1418 StringBundler msg = new StringBundler(6);
1419
1420 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1421
1422 msg.append("companyId=");
1423 msg.append(companyId);
1424
1425 msg.append(", key=");
1426 msg.append(key);
1427
1428 msg.append(StringPool.CLOSE_CURLY_BRACE);
1429
1430 throw new NoSuchCategoryPropertyException(msg.toString());
1431 }
1432
1433
1441 @Override
1442 public AssetCategoryProperty fetchByC_K_Last(long companyId, String key,
1443 OrderByComparator<AssetCategoryProperty> orderByComparator) {
1444 int count = countByC_K(companyId, key);
1445
1446 if (count == 0) {
1447 return null;
1448 }
1449
1450 List<AssetCategoryProperty> list = findByC_K(companyId, key, count - 1,
1451 count, orderByComparator);
1452
1453 if (!list.isEmpty()) {
1454 return list.get(0);
1455 }
1456
1457 return null;
1458 }
1459
1460
1470 @Override
1471 public AssetCategoryProperty[] findByC_K_PrevAndNext(
1472 long categoryPropertyId, long companyId, String key,
1473 OrderByComparator<AssetCategoryProperty> orderByComparator)
1474 throws NoSuchCategoryPropertyException {
1475 AssetCategoryProperty assetCategoryProperty = findByPrimaryKey(categoryPropertyId);
1476
1477 Session session = null;
1478
1479 try {
1480 session = openSession();
1481
1482 AssetCategoryProperty[] array = new AssetCategoryPropertyImpl[3];
1483
1484 array[0] = getByC_K_PrevAndNext(session, assetCategoryProperty,
1485 companyId, key, orderByComparator, true);
1486
1487 array[1] = assetCategoryProperty;
1488
1489 array[2] = getByC_K_PrevAndNext(session, assetCategoryProperty,
1490 companyId, key, orderByComparator, false);
1491
1492 return array;
1493 }
1494 catch (Exception e) {
1495 throw processException(e);
1496 }
1497 finally {
1498 closeSession(session);
1499 }
1500 }
1501
1502 protected AssetCategoryProperty getByC_K_PrevAndNext(Session session,
1503 AssetCategoryProperty assetCategoryProperty, long companyId,
1504 String key, OrderByComparator<AssetCategoryProperty> orderByComparator,
1505 boolean previous) {
1506 StringBundler query = null;
1507
1508 if (orderByComparator != null) {
1509 query = new StringBundler(5 +
1510 (orderByComparator.getOrderByConditionFields().length * 3) +
1511 (orderByComparator.getOrderByFields().length * 3));
1512 }
1513 else {
1514 query = new StringBundler(4);
1515 }
1516
1517 query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
1518
1519 query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1520
1521 boolean bindKey = false;
1522
1523 if (key == null) {
1524 query.append(_FINDER_COLUMN_C_K_KEY_1);
1525 }
1526 else if (key.equals(StringPool.BLANK)) {
1527 query.append(_FINDER_COLUMN_C_K_KEY_3);
1528 }
1529 else {
1530 bindKey = true;
1531
1532 query.append(_FINDER_COLUMN_C_K_KEY_2);
1533 }
1534
1535 if (orderByComparator != null) {
1536 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1537
1538 if (orderByConditionFields.length > 0) {
1539 query.append(WHERE_AND);
1540 }
1541
1542 for (int i = 0; i < orderByConditionFields.length; i++) {
1543 query.append(_ORDER_BY_ENTITY_ALIAS);
1544 query.append(orderByConditionFields[i]);
1545
1546 if ((i + 1) < orderByConditionFields.length) {
1547 if (orderByComparator.isAscending() ^ previous) {
1548 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1549 }
1550 else {
1551 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1552 }
1553 }
1554 else {
1555 if (orderByComparator.isAscending() ^ previous) {
1556 query.append(WHERE_GREATER_THAN);
1557 }
1558 else {
1559 query.append(WHERE_LESSER_THAN);
1560 }
1561 }
1562 }
1563
1564 query.append(ORDER_BY_CLAUSE);
1565
1566 String[] orderByFields = orderByComparator.getOrderByFields();
1567
1568 for (int i = 0; i < orderByFields.length; i++) {
1569 query.append(_ORDER_BY_ENTITY_ALIAS);
1570 query.append(orderByFields[i]);
1571
1572 if ((i + 1) < orderByFields.length) {
1573 if (orderByComparator.isAscending() ^ previous) {
1574 query.append(ORDER_BY_ASC_HAS_NEXT);
1575 }
1576 else {
1577 query.append(ORDER_BY_DESC_HAS_NEXT);
1578 }
1579 }
1580 else {
1581 if (orderByComparator.isAscending() ^ previous) {
1582 query.append(ORDER_BY_ASC);
1583 }
1584 else {
1585 query.append(ORDER_BY_DESC);
1586 }
1587 }
1588 }
1589 }
1590 else {
1591 query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
1592 }
1593
1594 String sql = query.toString();
1595
1596 Query q = session.createQuery(sql);
1597
1598 q.setFirstResult(0);
1599 q.setMaxResults(2);
1600
1601 QueryPos qPos = QueryPos.getInstance(q);
1602
1603 qPos.add(companyId);
1604
1605 if (bindKey) {
1606 qPos.add(key);
1607 }
1608
1609 if (orderByComparator != null) {
1610 Object[] values = orderByComparator.getOrderByConditionValues(assetCategoryProperty);
1611
1612 for (Object value : values) {
1613 qPos.add(value);
1614 }
1615 }
1616
1617 List<AssetCategoryProperty> list = q.list();
1618
1619 if (list.size() == 2) {
1620 return list.get(1);
1621 }
1622 else {
1623 return null;
1624 }
1625 }
1626
1627
1633 @Override
1634 public void removeByC_K(long companyId, String key) {
1635 for (AssetCategoryProperty assetCategoryProperty : findByC_K(
1636 companyId, key, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1637 remove(assetCategoryProperty);
1638 }
1639 }
1640
1641
1648 @Override
1649 public int countByC_K(long companyId, String key) {
1650 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_K;
1651
1652 Object[] finderArgs = new Object[] { companyId, key };
1653
1654 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1655
1656 if (count == null) {
1657 StringBundler query = new StringBundler(3);
1658
1659 query.append(_SQL_COUNT_ASSETCATEGORYPROPERTY_WHERE);
1660
1661 query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1662
1663 boolean bindKey = false;
1664
1665 if (key == null) {
1666 query.append(_FINDER_COLUMN_C_K_KEY_1);
1667 }
1668 else if (key.equals(StringPool.BLANK)) {
1669 query.append(_FINDER_COLUMN_C_K_KEY_3);
1670 }
1671 else {
1672 bindKey = true;
1673
1674 query.append(_FINDER_COLUMN_C_K_KEY_2);
1675 }
1676
1677 String sql = query.toString();
1678
1679 Session session = null;
1680
1681 try {
1682 session = openSession();
1683
1684 Query q = session.createQuery(sql);
1685
1686 QueryPos qPos = QueryPos.getInstance(q);
1687
1688 qPos.add(companyId);
1689
1690 if (bindKey) {
1691 qPos.add(key);
1692 }
1693
1694 count = (Long)q.uniqueResult();
1695
1696 finderCache.putResult(finderPath, finderArgs, count);
1697 }
1698 catch (Exception e) {
1699 finderCache.removeResult(finderPath, finderArgs);
1700
1701 throw processException(e);
1702 }
1703 finally {
1704 closeSession(session);
1705 }
1706 }
1707
1708 return count.intValue();
1709 }
1710
1711 private static final String _FINDER_COLUMN_C_K_COMPANYID_2 = "assetCategoryProperty.companyId = ? AND ";
1712 private static final String _FINDER_COLUMN_C_K_KEY_1 = "assetCategoryProperty.key IS NULL";
1713 private static final String _FINDER_COLUMN_C_K_KEY_2 = "assetCategoryProperty.key = ?";
1714 private static final String _FINDER_COLUMN_C_K_KEY_3 = "(assetCategoryProperty.key IS NULL OR assetCategoryProperty.key = '')";
1715 public static final FinderPath FINDER_PATH_FETCH_BY_CA_K = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
1716 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
1717 AssetCategoryPropertyImpl.class, FINDER_CLASS_NAME_ENTITY,
1718 "fetchByCA_K",
1719 new String[] { Long.class.getName(), String.class.getName() },
1720 AssetCategoryPropertyModelImpl.CATEGORYID_COLUMN_BITMASK |
1721 AssetCategoryPropertyModelImpl.KEY_COLUMN_BITMASK);
1722 public static final FinderPath FINDER_PATH_COUNT_BY_CA_K = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
1723 AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED, Long.class,
1724 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCA_K",
1725 new String[] { Long.class.getName(), String.class.getName() });
1726
1727
1735 @Override
1736 public AssetCategoryProperty findByCA_K(long categoryId, String key)
1737 throws NoSuchCategoryPropertyException {
1738 AssetCategoryProperty assetCategoryProperty = fetchByCA_K(categoryId,
1739 key);
1740
1741 if (assetCategoryProperty == null) {
1742 StringBundler msg = new StringBundler(6);
1743
1744 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1745
1746 msg.append("categoryId=");
1747 msg.append(categoryId);
1748
1749 msg.append(", key=");
1750 msg.append(key);
1751
1752 msg.append(StringPool.CLOSE_CURLY_BRACE);
1753
1754 if (_log.isWarnEnabled()) {
1755 _log.warn(msg.toString());
1756 }
1757
1758 throw new NoSuchCategoryPropertyException(msg.toString());
1759 }
1760
1761 return assetCategoryProperty;
1762 }
1763
1764
1771 @Override
1772 public AssetCategoryProperty fetchByCA_K(long categoryId, String key) {
1773 return fetchByCA_K(categoryId, key, true);
1774 }
1775
1776
1784 @Override
1785 public AssetCategoryProperty fetchByCA_K(long categoryId, String key,
1786 boolean retrieveFromCache) {
1787 Object[] finderArgs = new Object[] { categoryId, key };
1788
1789 Object result = null;
1790
1791 if (retrieveFromCache) {
1792 result = finderCache.getResult(FINDER_PATH_FETCH_BY_CA_K,
1793 finderArgs, this);
1794 }
1795
1796 if (result instanceof AssetCategoryProperty) {
1797 AssetCategoryProperty assetCategoryProperty = (AssetCategoryProperty)result;
1798
1799 if ((categoryId != assetCategoryProperty.getCategoryId()) ||
1800 !Validator.equals(key, assetCategoryProperty.getKey())) {
1801 result = null;
1802 }
1803 }
1804
1805 if (result == null) {
1806 StringBundler query = new StringBundler(4);
1807
1808 query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
1809
1810 query.append(_FINDER_COLUMN_CA_K_CATEGORYID_2);
1811
1812 boolean bindKey = false;
1813
1814 if (key == null) {
1815 query.append(_FINDER_COLUMN_CA_K_KEY_1);
1816 }
1817 else if (key.equals(StringPool.BLANK)) {
1818 query.append(_FINDER_COLUMN_CA_K_KEY_3);
1819 }
1820 else {
1821 bindKey = true;
1822
1823 query.append(_FINDER_COLUMN_CA_K_KEY_2);
1824 }
1825
1826 String sql = query.toString();
1827
1828 Session session = null;
1829
1830 try {
1831 session = openSession();
1832
1833 Query q = session.createQuery(sql);
1834
1835 QueryPos qPos = QueryPos.getInstance(q);
1836
1837 qPos.add(categoryId);
1838
1839 if (bindKey) {
1840 qPos.add(key);
1841 }
1842
1843 List<AssetCategoryProperty> list = q.list();
1844
1845 if (list.isEmpty()) {
1846 finderCache.putResult(FINDER_PATH_FETCH_BY_CA_K,
1847 finderArgs, list);
1848 }
1849 else {
1850 AssetCategoryProperty assetCategoryProperty = list.get(0);
1851
1852 result = assetCategoryProperty;
1853
1854 cacheResult(assetCategoryProperty);
1855
1856 if ((assetCategoryProperty.getCategoryId() != categoryId) ||
1857 (assetCategoryProperty.getKey() == null) ||
1858 !assetCategoryProperty.getKey().equals(key)) {
1859 finderCache.putResult(FINDER_PATH_FETCH_BY_CA_K,
1860 finderArgs, assetCategoryProperty);
1861 }
1862 }
1863 }
1864 catch (Exception e) {
1865 finderCache.removeResult(FINDER_PATH_FETCH_BY_CA_K, finderArgs);
1866
1867 throw processException(e);
1868 }
1869 finally {
1870 closeSession(session);
1871 }
1872 }
1873
1874 if (result instanceof List<?>) {
1875 return null;
1876 }
1877 else {
1878 return (AssetCategoryProperty)result;
1879 }
1880 }
1881
1882
1889 @Override
1890 public AssetCategoryProperty removeByCA_K(long categoryId, String key)
1891 throws NoSuchCategoryPropertyException {
1892 AssetCategoryProperty assetCategoryProperty = findByCA_K(categoryId, key);
1893
1894 return remove(assetCategoryProperty);
1895 }
1896
1897
1904 @Override
1905 public int countByCA_K(long categoryId, String key) {
1906 FinderPath finderPath = FINDER_PATH_COUNT_BY_CA_K;
1907
1908 Object[] finderArgs = new Object[] { categoryId, key };
1909
1910 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1911
1912 if (count == null) {
1913 StringBundler query = new StringBundler(3);
1914
1915 query.append(_SQL_COUNT_ASSETCATEGORYPROPERTY_WHERE);
1916
1917 query.append(_FINDER_COLUMN_CA_K_CATEGORYID_2);
1918
1919 boolean bindKey = false;
1920
1921 if (key == null) {
1922 query.append(_FINDER_COLUMN_CA_K_KEY_1);
1923 }
1924 else if (key.equals(StringPool.BLANK)) {
1925 query.append(_FINDER_COLUMN_CA_K_KEY_3);
1926 }
1927 else {
1928 bindKey = true;
1929
1930 query.append(_FINDER_COLUMN_CA_K_KEY_2);
1931 }
1932
1933 String sql = query.toString();
1934
1935 Session session = null;
1936
1937 try {
1938 session = openSession();
1939
1940 Query q = session.createQuery(sql);
1941
1942 QueryPos qPos = QueryPos.getInstance(q);
1943
1944 qPos.add(categoryId);
1945
1946 if (bindKey) {
1947 qPos.add(key);
1948 }
1949
1950 count = (Long)q.uniqueResult();
1951
1952 finderCache.putResult(finderPath, finderArgs, count);
1953 }
1954 catch (Exception e) {
1955 finderCache.removeResult(finderPath, finderArgs);
1956
1957 throw processException(e);
1958 }
1959 finally {
1960 closeSession(session);
1961 }
1962 }
1963
1964 return count.intValue();
1965 }
1966
1967 private static final String _FINDER_COLUMN_CA_K_CATEGORYID_2 = "assetCategoryProperty.categoryId = ? AND ";
1968 private static final String _FINDER_COLUMN_CA_K_KEY_1 = "assetCategoryProperty.key IS NULL";
1969 private static final String _FINDER_COLUMN_CA_K_KEY_2 = "assetCategoryProperty.key = ?";
1970 private static final String _FINDER_COLUMN_CA_K_KEY_3 = "(assetCategoryProperty.key IS NULL OR assetCategoryProperty.key = '')";
1971
1972 public AssetCategoryPropertyPersistenceImpl() {
1973 setModelClass(AssetCategoryProperty.class);
1974 }
1975
1976
1981 @Override
1982 public void cacheResult(AssetCategoryProperty assetCategoryProperty) {
1983 entityCache.putResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
1984 AssetCategoryPropertyImpl.class,
1985 assetCategoryProperty.getPrimaryKey(), assetCategoryProperty);
1986
1987 finderCache.putResult(FINDER_PATH_FETCH_BY_CA_K,
1988 new Object[] {
1989 assetCategoryProperty.getCategoryId(),
1990 assetCategoryProperty.getKey()
1991 }, assetCategoryProperty);
1992
1993 assetCategoryProperty.resetOriginalValues();
1994 }
1995
1996
2001 @Override
2002 public void cacheResult(List<AssetCategoryProperty> assetCategoryProperties) {
2003 for (AssetCategoryProperty assetCategoryProperty : assetCategoryProperties) {
2004 if (entityCache.getResult(
2005 AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
2006 AssetCategoryPropertyImpl.class,
2007 assetCategoryProperty.getPrimaryKey()) == null) {
2008 cacheResult(assetCategoryProperty);
2009 }
2010 else {
2011 assetCategoryProperty.resetOriginalValues();
2012 }
2013 }
2014 }
2015
2016
2023 @Override
2024 public void clearCache() {
2025 entityCache.clearCache(AssetCategoryPropertyImpl.class);
2026
2027 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
2028 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2029 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2030 }
2031
2032
2039 @Override
2040 public void clearCache(AssetCategoryProperty assetCategoryProperty) {
2041 entityCache.removeResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
2042 AssetCategoryPropertyImpl.class,
2043 assetCategoryProperty.getPrimaryKey());
2044
2045 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2046 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2047
2048 clearUniqueFindersCache((AssetCategoryPropertyModelImpl)assetCategoryProperty);
2049 }
2050
2051 @Override
2052 public void clearCache(List<AssetCategoryProperty> assetCategoryProperties) {
2053 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2054 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2055
2056 for (AssetCategoryProperty assetCategoryProperty : assetCategoryProperties) {
2057 entityCache.removeResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
2058 AssetCategoryPropertyImpl.class,
2059 assetCategoryProperty.getPrimaryKey());
2060
2061 clearUniqueFindersCache((AssetCategoryPropertyModelImpl)assetCategoryProperty);
2062 }
2063 }
2064
2065 protected void cacheUniqueFindersCache(
2066 AssetCategoryPropertyModelImpl assetCategoryPropertyModelImpl,
2067 boolean isNew) {
2068 if (isNew) {
2069 Object[] args = new Object[] {
2070 assetCategoryPropertyModelImpl.getCategoryId(),
2071 assetCategoryPropertyModelImpl.getKey()
2072 };
2073
2074 finderCache.putResult(FINDER_PATH_COUNT_BY_CA_K, args,
2075 Long.valueOf(1));
2076 finderCache.putResult(FINDER_PATH_FETCH_BY_CA_K, args,
2077 assetCategoryPropertyModelImpl);
2078 }
2079 else {
2080 if ((assetCategoryPropertyModelImpl.getColumnBitmask() &
2081 FINDER_PATH_FETCH_BY_CA_K.getColumnBitmask()) != 0) {
2082 Object[] args = new Object[] {
2083 assetCategoryPropertyModelImpl.getCategoryId(),
2084 assetCategoryPropertyModelImpl.getKey()
2085 };
2086
2087 finderCache.putResult(FINDER_PATH_COUNT_BY_CA_K, args,
2088 Long.valueOf(1));
2089 finderCache.putResult(FINDER_PATH_FETCH_BY_CA_K, args,
2090 assetCategoryPropertyModelImpl);
2091 }
2092 }
2093 }
2094
2095 protected void clearUniqueFindersCache(
2096 AssetCategoryPropertyModelImpl assetCategoryPropertyModelImpl) {
2097 Object[] args = new Object[] {
2098 assetCategoryPropertyModelImpl.getCategoryId(),
2099 assetCategoryPropertyModelImpl.getKey()
2100 };
2101
2102 finderCache.removeResult(FINDER_PATH_COUNT_BY_CA_K, args);
2103 finderCache.removeResult(FINDER_PATH_FETCH_BY_CA_K, args);
2104
2105 if ((assetCategoryPropertyModelImpl.getColumnBitmask() &
2106 FINDER_PATH_FETCH_BY_CA_K.getColumnBitmask()) != 0) {
2107 args = new Object[] {
2108 assetCategoryPropertyModelImpl.getOriginalCategoryId(),
2109 assetCategoryPropertyModelImpl.getOriginalKey()
2110 };
2111
2112 finderCache.removeResult(FINDER_PATH_COUNT_BY_CA_K, args);
2113 finderCache.removeResult(FINDER_PATH_FETCH_BY_CA_K, args);
2114 }
2115 }
2116
2117
2123 @Override
2124 public AssetCategoryProperty create(long categoryPropertyId) {
2125 AssetCategoryProperty assetCategoryProperty = new AssetCategoryPropertyImpl();
2126
2127 assetCategoryProperty.setNew(true);
2128 assetCategoryProperty.setPrimaryKey(categoryPropertyId);
2129
2130 assetCategoryProperty.setCompanyId(companyProvider.getCompanyId());
2131
2132 return assetCategoryProperty;
2133 }
2134
2135
2142 @Override
2143 public AssetCategoryProperty remove(long categoryPropertyId)
2144 throws NoSuchCategoryPropertyException {
2145 return remove((Serializable)categoryPropertyId);
2146 }
2147
2148
2155 @Override
2156 public AssetCategoryProperty remove(Serializable primaryKey)
2157 throws NoSuchCategoryPropertyException {
2158 Session session = null;
2159
2160 try {
2161 session = openSession();
2162
2163 AssetCategoryProperty assetCategoryProperty = (AssetCategoryProperty)session.get(AssetCategoryPropertyImpl.class,
2164 primaryKey);
2165
2166 if (assetCategoryProperty == null) {
2167 if (_log.isWarnEnabled()) {
2168 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2169 }
2170
2171 throw new NoSuchCategoryPropertyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2172 primaryKey);
2173 }
2174
2175 return remove(assetCategoryProperty);
2176 }
2177 catch (NoSuchCategoryPropertyException nsee) {
2178 throw nsee;
2179 }
2180 catch (Exception e) {
2181 throw processException(e);
2182 }
2183 finally {
2184 closeSession(session);
2185 }
2186 }
2187
2188 @Override
2189 protected AssetCategoryProperty removeImpl(
2190 AssetCategoryProperty assetCategoryProperty) {
2191 assetCategoryProperty = toUnwrappedModel(assetCategoryProperty);
2192
2193 Session session = null;
2194
2195 try {
2196 session = openSession();
2197
2198 if (!session.contains(assetCategoryProperty)) {
2199 assetCategoryProperty = (AssetCategoryProperty)session.get(AssetCategoryPropertyImpl.class,
2200 assetCategoryProperty.getPrimaryKeyObj());
2201 }
2202
2203 if (assetCategoryProperty != null) {
2204 session.delete(assetCategoryProperty);
2205 }
2206 }
2207 catch (Exception e) {
2208 throw processException(e);
2209 }
2210 finally {
2211 closeSession(session);
2212 }
2213
2214 if (assetCategoryProperty != null) {
2215 clearCache(assetCategoryProperty);
2216 }
2217
2218 return assetCategoryProperty;
2219 }
2220
2221 @Override
2222 public AssetCategoryProperty updateImpl(
2223 AssetCategoryProperty assetCategoryProperty) {
2224 assetCategoryProperty = toUnwrappedModel(assetCategoryProperty);
2225
2226 boolean isNew = assetCategoryProperty.isNew();
2227
2228 AssetCategoryPropertyModelImpl assetCategoryPropertyModelImpl = (AssetCategoryPropertyModelImpl)assetCategoryProperty;
2229
2230 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2231
2232 Date now = new Date();
2233
2234 if (isNew && (assetCategoryProperty.getCreateDate() == null)) {
2235 if (serviceContext == null) {
2236 assetCategoryProperty.setCreateDate(now);
2237 }
2238 else {
2239 assetCategoryProperty.setCreateDate(serviceContext.getCreateDate(
2240 now));
2241 }
2242 }
2243
2244 if (!assetCategoryPropertyModelImpl.hasSetModifiedDate()) {
2245 if (serviceContext == null) {
2246 assetCategoryProperty.setModifiedDate(now);
2247 }
2248 else {
2249 assetCategoryProperty.setModifiedDate(serviceContext.getModifiedDate(
2250 now));
2251 }
2252 }
2253
2254 Session session = null;
2255
2256 try {
2257 session = openSession();
2258
2259 if (assetCategoryProperty.isNew()) {
2260 session.save(assetCategoryProperty);
2261
2262 assetCategoryProperty.setNew(false);
2263 }
2264 else {
2265 assetCategoryProperty = (AssetCategoryProperty)session.merge(assetCategoryProperty);
2266 }
2267 }
2268 catch (Exception e) {
2269 throw processException(e);
2270 }
2271 finally {
2272 closeSession(session);
2273 }
2274
2275 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2276
2277 if (isNew || !AssetCategoryPropertyModelImpl.COLUMN_BITMASK_ENABLED) {
2278 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2279 }
2280
2281 else {
2282 if ((assetCategoryPropertyModelImpl.getColumnBitmask() &
2283 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2284 Object[] args = new Object[] {
2285 assetCategoryPropertyModelImpl.getOriginalCompanyId()
2286 };
2287
2288 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
2289 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2290 args);
2291
2292 args = new Object[] {
2293 assetCategoryPropertyModelImpl.getCompanyId()
2294 };
2295
2296 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
2297 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2298 args);
2299 }
2300
2301 if ((assetCategoryPropertyModelImpl.getColumnBitmask() &
2302 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CATEGORYID.getColumnBitmask()) != 0) {
2303 Object[] args = new Object[] {
2304 assetCategoryPropertyModelImpl.getOriginalCategoryId()
2305 };
2306
2307 finderCache.removeResult(FINDER_PATH_COUNT_BY_CATEGORYID, args);
2308 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CATEGORYID,
2309 args);
2310
2311 args = new Object[] {
2312 assetCategoryPropertyModelImpl.getCategoryId()
2313 };
2314
2315 finderCache.removeResult(FINDER_PATH_COUNT_BY_CATEGORYID, args);
2316 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CATEGORYID,
2317 args);
2318 }
2319
2320 if ((assetCategoryPropertyModelImpl.getColumnBitmask() &
2321 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K.getColumnBitmask()) != 0) {
2322 Object[] args = new Object[] {
2323 assetCategoryPropertyModelImpl.getOriginalCompanyId(),
2324 assetCategoryPropertyModelImpl.getOriginalKey()
2325 };
2326
2327 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2328 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K,
2329 args);
2330
2331 args = new Object[] {
2332 assetCategoryPropertyModelImpl.getCompanyId(),
2333 assetCategoryPropertyModelImpl.getKey()
2334 };
2335
2336 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2337 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K,
2338 args);
2339 }
2340 }
2341
2342 entityCache.putResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
2343 AssetCategoryPropertyImpl.class,
2344 assetCategoryProperty.getPrimaryKey(), assetCategoryProperty, false);
2345
2346 clearUniqueFindersCache(assetCategoryPropertyModelImpl);
2347 cacheUniqueFindersCache(assetCategoryPropertyModelImpl, isNew);
2348
2349 assetCategoryProperty.resetOriginalValues();
2350
2351 return assetCategoryProperty;
2352 }
2353
2354 protected AssetCategoryProperty toUnwrappedModel(
2355 AssetCategoryProperty assetCategoryProperty) {
2356 if (assetCategoryProperty instanceof AssetCategoryPropertyImpl) {
2357 return assetCategoryProperty;
2358 }
2359
2360 AssetCategoryPropertyImpl assetCategoryPropertyImpl = new AssetCategoryPropertyImpl();
2361
2362 assetCategoryPropertyImpl.setNew(assetCategoryProperty.isNew());
2363 assetCategoryPropertyImpl.setPrimaryKey(assetCategoryProperty.getPrimaryKey());
2364
2365 assetCategoryPropertyImpl.setCategoryPropertyId(assetCategoryProperty.getCategoryPropertyId());
2366 assetCategoryPropertyImpl.setCompanyId(assetCategoryProperty.getCompanyId());
2367 assetCategoryPropertyImpl.setUserId(assetCategoryProperty.getUserId());
2368 assetCategoryPropertyImpl.setUserName(assetCategoryProperty.getUserName());
2369 assetCategoryPropertyImpl.setCreateDate(assetCategoryProperty.getCreateDate());
2370 assetCategoryPropertyImpl.setModifiedDate(assetCategoryProperty.getModifiedDate());
2371 assetCategoryPropertyImpl.setCategoryId(assetCategoryProperty.getCategoryId());
2372 assetCategoryPropertyImpl.setKey(assetCategoryProperty.getKey());
2373 assetCategoryPropertyImpl.setValue(assetCategoryProperty.getValue());
2374
2375 return assetCategoryPropertyImpl;
2376 }
2377
2378
2385 @Override
2386 public AssetCategoryProperty findByPrimaryKey(Serializable primaryKey)
2387 throws NoSuchCategoryPropertyException {
2388 AssetCategoryProperty assetCategoryProperty = fetchByPrimaryKey(primaryKey);
2389
2390 if (assetCategoryProperty == null) {
2391 if (_log.isWarnEnabled()) {
2392 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2393 }
2394
2395 throw new NoSuchCategoryPropertyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2396 primaryKey);
2397 }
2398
2399 return assetCategoryProperty;
2400 }
2401
2402
2409 @Override
2410 public AssetCategoryProperty findByPrimaryKey(long categoryPropertyId)
2411 throws NoSuchCategoryPropertyException {
2412 return findByPrimaryKey((Serializable)categoryPropertyId);
2413 }
2414
2415
2421 @Override
2422 public AssetCategoryProperty fetchByPrimaryKey(Serializable primaryKey) {
2423 AssetCategoryProperty assetCategoryProperty = (AssetCategoryProperty)entityCache.getResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
2424 AssetCategoryPropertyImpl.class, primaryKey);
2425
2426 if (assetCategoryProperty == _nullAssetCategoryProperty) {
2427 return null;
2428 }
2429
2430 if (assetCategoryProperty == null) {
2431 Session session = null;
2432
2433 try {
2434 session = openSession();
2435
2436 assetCategoryProperty = (AssetCategoryProperty)session.get(AssetCategoryPropertyImpl.class,
2437 primaryKey);
2438
2439 if (assetCategoryProperty != null) {
2440 cacheResult(assetCategoryProperty);
2441 }
2442 else {
2443 entityCache.putResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
2444 AssetCategoryPropertyImpl.class, primaryKey,
2445 _nullAssetCategoryProperty);
2446 }
2447 }
2448 catch (Exception e) {
2449 entityCache.removeResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
2450 AssetCategoryPropertyImpl.class, primaryKey);
2451
2452 throw processException(e);
2453 }
2454 finally {
2455 closeSession(session);
2456 }
2457 }
2458
2459 return assetCategoryProperty;
2460 }
2461
2462
2468 @Override
2469 public AssetCategoryProperty fetchByPrimaryKey(long categoryPropertyId) {
2470 return fetchByPrimaryKey((Serializable)categoryPropertyId);
2471 }
2472
2473 @Override
2474 public Map<Serializable, AssetCategoryProperty> fetchByPrimaryKeys(
2475 Set<Serializable> primaryKeys) {
2476 if (primaryKeys.isEmpty()) {
2477 return Collections.emptyMap();
2478 }
2479
2480 Map<Serializable, AssetCategoryProperty> map = new HashMap<Serializable, AssetCategoryProperty>();
2481
2482 if (primaryKeys.size() == 1) {
2483 Iterator<Serializable> iterator = primaryKeys.iterator();
2484
2485 Serializable primaryKey = iterator.next();
2486
2487 AssetCategoryProperty assetCategoryProperty = fetchByPrimaryKey(primaryKey);
2488
2489 if (assetCategoryProperty != null) {
2490 map.put(primaryKey, assetCategoryProperty);
2491 }
2492
2493 return map;
2494 }
2495
2496 Set<Serializable> uncachedPrimaryKeys = null;
2497
2498 for (Serializable primaryKey : primaryKeys) {
2499 AssetCategoryProperty assetCategoryProperty = (AssetCategoryProperty)entityCache.getResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
2500 AssetCategoryPropertyImpl.class, primaryKey);
2501
2502 if (assetCategoryProperty == null) {
2503 if (uncachedPrimaryKeys == null) {
2504 uncachedPrimaryKeys = new HashSet<Serializable>();
2505 }
2506
2507 uncachedPrimaryKeys.add(primaryKey);
2508 }
2509 else {
2510 map.put(primaryKey, assetCategoryProperty);
2511 }
2512 }
2513
2514 if (uncachedPrimaryKeys == null) {
2515 return map;
2516 }
2517
2518 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2519 1);
2520
2521 query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE_PKS_IN);
2522
2523 for (Serializable primaryKey : uncachedPrimaryKeys) {
2524 query.append(String.valueOf(primaryKey));
2525
2526 query.append(StringPool.COMMA);
2527 }
2528
2529 query.setIndex(query.index() - 1);
2530
2531 query.append(StringPool.CLOSE_PARENTHESIS);
2532
2533 String sql = query.toString();
2534
2535 Session session = null;
2536
2537 try {
2538 session = openSession();
2539
2540 Query q = session.createQuery(sql);
2541
2542 for (AssetCategoryProperty assetCategoryProperty : (List<AssetCategoryProperty>)q.list()) {
2543 map.put(assetCategoryProperty.getPrimaryKeyObj(),
2544 assetCategoryProperty);
2545
2546 cacheResult(assetCategoryProperty);
2547
2548 uncachedPrimaryKeys.remove(assetCategoryProperty.getPrimaryKeyObj());
2549 }
2550
2551 for (Serializable primaryKey : uncachedPrimaryKeys) {
2552 entityCache.putResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
2553 AssetCategoryPropertyImpl.class, primaryKey,
2554 _nullAssetCategoryProperty);
2555 }
2556 }
2557 catch (Exception e) {
2558 throw processException(e);
2559 }
2560 finally {
2561 closeSession(session);
2562 }
2563
2564 return map;
2565 }
2566
2567
2572 @Override
2573 public List<AssetCategoryProperty> findAll() {
2574 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2575 }
2576
2577
2588 @Override
2589 public List<AssetCategoryProperty> findAll(int start, int end) {
2590 return findAll(start, end, null);
2591 }
2592
2593
2605 @Override
2606 public List<AssetCategoryProperty> findAll(int start, int end,
2607 OrderByComparator<AssetCategoryProperty> orderByComparator) {
2608 return findAll(start, end, orderByComparator, true);
2609 }
2610
2611
2624 @Override
2625 public List<AssetCategoryProperty> findAll(int start, int end,
2626 OrderByComparator<AssetCategoryProperty> orderByComparator,
2627 boolean retrieveFromCache) {
2628 boolean pagination = true;
2629 FinderPath finderPath = null;
2630 Object[] finderArgs = null;
2631
2632 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2633 (orderByComparator == null)) {
2634 pagination = false;
2635 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2636 finderArgs = FINDER_ARGS_EMPTY;
2637 }
2638 else {
2639 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2640 finderArgs = new Object[] { start, end, orderByComparator };
2641 }
2642
2643 List<AssetCategoryProperty> list = null;
2644
2645 if (retrieveFromCache) {
2646 list = (List<AssetCategoryProperty>)finderCache.getResult(finderPath,
2647 finderArgs, this);
2648 }
2649
2650 if (list == null) {
2651 StringBundler query = null;
2652 String sql = null;
2653
2654 if (orderByComparator != null) {
2655 query = new StringBundler(2 +
2656 (orderByComparator.getOrderByFields().length * 2));
2657
2658 query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY);
2659
2660 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2661 orderByComparator);
2662
2663 sql = query.toString();
2664 }
2665 else {
2666 sql = _SQL_SELECT_ASSETCATEGORYPROPERTY;
2667
2668 if (pagination) {
2669 sql = sql.concat(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
2670 }
2671 }
2672
2673 Session session = null;
2674
2675 try {
2676 session = openSession();
2677
2678 Query q = session.createQuery(sql);
2679
2680 if (!pagination) {
2681 list = (List<AssetCategoryProperty>)QueryUtil.list(q,
2682 getDialect(), start, end, false);
2683
2684 Collections.sort(list);
2685
2686 list = Collections.unmodifiableList(list);
2687 }
2688 else {
2689 list = (List<AssetCategoryProperty>)QueryUtil.list(q,
2690 getDialect(), start, end);
2691 }
2692
2693 cacheResult(list);
2694
2695 finderCache.putResult(finderPath, finderArgs, list);
2696 }
2697 catch (Exception e) {
2698 finderCache.removeResult(finderPath, finderArgs);
2699
2700 throw processException(e);
2701 }
2702 finally {
2703 closeSession(session);
2704 }
2705 }
2706
2707 return list;
2708 }
2709
2710
2714 @Override
2715 public void removeAll() {
2716 for (AssetCategoryProperty assetCategoryProperty : findAll()) {
2717 remove(assetCategoryProperty);
2718 }
2719 }
2720
2721
2726 @Override
2727 public int countAll() {
2728 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2729 FINDER_ARGS_EMPTY, this);
2730
2731 if (count == null) {
2732 Session session = null;
2733
2734 try {
2735 session = openSession();
2736
2737 Query q = session.createQuery(_SQL_COUNT_ASSETCATEGORYPROPERTY);
2738
2739 count = (Long)q.uniqueResult();
2740
2741 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2742 count);
2743 }
2744 catch (Exception e) {
2745 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2746 FINDER_ARGS_EMPTY);
2747
2748 throw processException(e);
2749 }
2750 finally {
2751 closeSession(session);
2752 }
2753 }
2754
2755 return count.intValue();
2756 }
2757
2758 @Override
2759 public Set<String> getBadColumnNames() {
2760 return _badColumnNames;
2761 }
2762
2763 @Override
2764 protected Map<String, Integer> getTableColumnsMap() {
2765 return AssetCategoryPropertyModelImpl.TABLE_COLUMNS_MAP;
2766 }
2767
2768
2771 public void afterPropertiesSet() {
2772 }
2773
2774 public void destroy() {
2775 entityCache.removeCache(AssetCategoryPropertyImpl.class.getName());
2776 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2777 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2778 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2779 }
2780
2781 @BeanReference(type = CompanyProviderWrapper.class)
2782 protected CompanyProvider companyProvider;
2783 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2784 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2785 private static final String _SQL_SELECT_ASSETCATEGORYPROPERTY = "SELECT assetCategoryProperty FROM AssetCategoryProperty assetCategoryProperty";
2786 private static final String _SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE_PKS_IN = "SELECT assetCategoryProperty FROM AssetCategoryProperty assetCategoryProperty WHERE categoryPropertyId IN (";
2787 private static final String _SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE = "SELECT assetCategoryProperty FROM AssetCategoryProperty assetCategoryProperty WHERE ";
2788 private static final String _SQL_COUNT_ASSETCATEGORYPROPERTY = "SELECT COUNT(assetCategoryProperty) FROM AssetCategoryProperty assetCategoryProperty";
2789 private static final String _SQL_COUNT_ASSETCATEGORYPROPERTY_WHERE = "SELECT COUNT(assetCategoryProperty) FROM AssetCategoryProperty assetCategoryProperty WHERE ";
2790 private static final String _ORDER_BY_ENTITY_ALIAS = "assetCategoryProperty.";
2791 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetCategoryProperty exists with the primary key ";
2792 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetCategoryProperty exists with the key {";
2793 private static final Log _log = LogFactoryUtil.getLog(AssetCategoryPropertyPersistenceImpl.class);
2794 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2795 "key"
2796 });
2797 private static final AssetCategoryProperty _nullAssetCategoryProperty = new AssetCategoryPropertyImpl() {
2798 @Override
2799 public Object clone() {
2800 return this;
2801 }
2802
2803 @Override
2804 public CacheModel<AssetCategoryProperty> toCacheModel() {
2805 return _nullAssetCategoryPropertyCacheModel;
2806 }
2807 };
2808
2809 private static final CacheModel<AssetCategoryProperty> _nullAssetCategoryPropertyCacheModel =
2810 new CacheModel<AssetCategoryProperty>() {
2811 @Override
2812 public AssetCategoryProperty toEntityModel() {
2813 return _nullAssetCategoryProperty;
2814 }
2815 };
2816 }